本文整理汇总了Java中org.openide.cookies.SaveCookie类的典型用法代码示例。如果您正苦于以下问题:Java SaveCookie类的具体用法?Java SaveCookie怎么用?Java SaveCookie使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SaveCookie类属于org.openide.cookies包,在下文中一共展示了SaveCookie类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveDocumentIfNotOpened
import org.openide.cookies.SaveCookie; //导入依赖的package包/类
/**
* Saves the given document to its underlying {@link FileObject} if the
* document is not opened in the nb editor, more formally if
* EditorCookie.getOpenedPanes() == null.
*
* @param document
* @throws IOException
*/
private static void saveDocumentIfNotOpened(Document document) throws IOException {
Object o = document.getProperty(Document.StreamDescriptionProperty);
if (o == null || !(o instanceof DataObject)) {
return;
}
DataObject dobj = (DataObject) o;
EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class);
if (ec != null && ec.getOpenedPanes() == null) {
//file not open in any editor
SaveCookie save = dobj.getLookup().lookup(SaveCookie.class);
if (save != null) {
save.save();
}
}
}
示例2: save
import org.openide.cookies.SaveCookie; //导入依赖的package包/类
/** Tries to save given data object using its save cookie.
* Notifies user if excetions appear.
*/
private void save (DataObject dataObject) {
try {
SaveCookie sc = dataObject.getLookup().lookup(SaveCookie.class);
if (sc != null) {
sc.save();
}
listModel.removeElement(dataObject);
} catch (IOException exc) {
ErrorManager em = ErrorManager.getDefault();
Throwable t = em.annotate(
exc, NbBundle.getBundle(ExitDialog.class).getString("EXC_Save")
);
em.notify(ErrorManager.EXCEPTION, t);
}
}
示例3: instantiate
import org.openide.cookies.SaveCookie; //导入依赖的package包/类
/**
* This is where, the schema gets instantiated from the template.
*/
public Set instantiate (TemplateWizard wizard) throws IOException {
FileObject dir = Templates.getTargetFolder( wizard );
DataFolder df = DataFolder.findFolder( dir );
FileObject template = Templates.getTemplate( wizard );
DataObject dTemplate = DataObject.find( template );
DataObject dobj = dTemplate.createFromTemplate(df, Templates.getTargetName(wizard));
if (dobj == null)
return Collections.emptySet();
encoding = EncodingUtil.getProjectEncoding(df.getPrimaryFile());
if(!EncodingUtil.isValidEncoding(encoding))
encoding = "UTF-8"; //NOI18N
EditCookie edit = dobj.getCookie(EditCookie.class);
if (edit != null) {
EditorCookie editorCookie = dobj.getCookie(EditorCookie.class);
Document doc = (Document)editorCookie.openDocument();
fixEncoding(doc, encoding);
SaveCookie save = dobj.getCookie(SaveCookie.class);
if (save!=null) save.save();
}
return Collections.singleton(dobj.getPrimaryFile());
}
示例4: FilesModifiedConfirmation
import org.openide.cookies.SaveCookie; //导入依赖的package包/类
public FilesModifiedConfirmation(SaveCookie[] saveCookies) {
btnSaveAll = createSaveAllButton();
btnSave = createSaveButton();
Mnemonics.setLocalizedText(btnSaveAll, getInitialSaveAllButtonText());
Mnemonics.setLocalizedText(btnSave, getInitialSaveButtonText());
JScrollPane scrollPane
= new JScrollPane(list = createFilesList(saveCookies));
if (!listModel.isEmpty()) {
list.setSelectedIndex(0);
} else {
updateSaveButtonState();
}
JComponent panel = new JPanel(new GridLayout(1, 1));
panel.add(scrollPane);
panel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
mainComponent = panel;
}
示例5: autoSave
import org.openide.cookies.SaveCookie; //导入依赖的package包/类
/**
* Saves properties files edited for given source object (form). This method
* is called when a form is being saved - so the corresponding bundle is
* saved as well.
*/
@Override
public void autoSave(DataObject srcDataObject) {
Map/*<DataObject, ChangeInfo>*/ relatedMap = (Map) changesMap.remove(srcDataObject);
if (relatedMap != null) {
for (Iterator it=relatedMap.keySet().iterator(); it.hasNext(); ) {
DataObject propertiesDO = (DataObject) it.next();
// [not sure: should we auto-save only bundles not opened in the editor?
// perhaps it's OK to save always...]
SaveCookie save = (SaveCookie) propertiesDO.getCookie(SaveCookie.class);
if (save != null) {
try {
save.save();
}
catch (IOException ex) {
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
}
}
}
}
}
示例6: TLDataObject
import org.openide.cookies.SaveCookie; //导入依赖的package包/类
public TLDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
super(pf, loader);
getCookieSet().assign(SaveCookie.class, saveDB);
setModified(true);
if (pf.getSize() > 0) {
database = getDBFromFile(pf);
} else {
database = new TLDatabase();
}
CookieSet cookies = getCookieSet();
cookies.assign(TLDatabase.class, database);
cookies.add(new TLOpenSupport(this.getPrimaryEntry()));
cookies.assign(Node.class, this.getNodeDelegate());
// Set modified if current time of db changes
database.addDBListener(changeListener);
}
示例7: setModified
import org.openide.cookies.SaveCookie; //导入依赖的package包/类
/**
* Set whether the object is considered modified.
* Also fires a change event.
* If the new value is <code>true</code>, the data object is added into a {@link #getRegistry registry} of opened data objects.
* If the new value is <code>false</code>,
* the data object is removed from the registry.
*/
public void setModified(boolean modif) {
super.setModified(modif);
//getEditorSupport().updateDisplayName();
if (modif) {
// Add save cookie
if (getCookie(SaveCookie.class) == null) {
getCookieSet().add(saveCookie);
}
} else {
// Remove save cookie
if(saveCookie.equals(getCookie(SaveCookie.class))) {
getCookieSet().remove(saveCookie);
}
}
}
示例8: testChangeModel
import org.openide.cookies.SaveCookie; //导入依赖的package包/类
public void testChangeModel() throws IOException {
BookDataObject bookDO = initDataObject();
try {
Book book = bookDO.getBook();
book.setAttributeValue("chapter", 0, "length", "110");
bookDO.modelUpdatedFromUI();
} catch (Exception ex) {
throw new AssertionFailedErrorException("Failed to change book model",ex);
}
// test if data object was modified
SaveCookie cookie = Helper.getSaveCookie(bookDO);
assertNotNull("Data Object Not Modified", cookie);
cookie.save();
// test to golden file
File original = Helper.getBookFile(getDataDir(), getWorkDir());
assertTrue("File doesn't contain the text : <chapter length=\"110\">",
Helper.isTextInFile("<chapter length=\"110\">",original));
}
示例9: shouldAskSave
import org.openide.cookies.SaveCookie; //导入依赖的package包/类
/**
* Helper method. Should be called only if the object has SaveCookie
* @return true if closing this editor whithout saving would result in loss of data
* because al least one of the modified files is not open in the code editor
*/
private boolean shouldAskSave() {
// for each entry : if there is a SaveCookie and no open editor component, return true.
// if passed for all entries, return false
BundleStructure structure = bundleStructure;
PropertiesFileEntry entry;
SaveCookie savec;
for (int i = 0; i < structure.getEntryCount(); i++) {
entry = structure.getNthEntry(i);
savec = entry.getCookie(SaveCookie.class);
if ((savec != null) && !entry.getPropertiesEditor().hasOpenedEditorComponent()) {
return true;
}
}
return false;
}
示例10: save
import org.openide.cookies.SaveCookie; //导入依赖的package包/类
@Override
public void save() throws IOException {
XStream xstream = new XStream();
FileLock lock = getPrimaryFile().lock();
OutputStream stream = null;
try {
stream = getPrimaryFile().getOutputStream(lock);
xstream.toXML(getDatabase(), stream);
} finally {
if (stream != null)
stream.close();
lock.releaseLock();
}
/*
ObjectOutputStream out = new ObjectOutputStream(getPrimaryFile().getOutputStream());
out.writeObject(getDatabase());
out.close();
*/
// We are don, database is saved
getCookieSet().assign(SaveCookie.class);
setModified(false);
}
示例11: removeSaveCookie
import org.openide.cookies.SaveCookie; //导入依赖的package包/类
/** Helper method. Removes save cookie from the entry. */
private void removeSaveCookie() {
LOG.finer("Environment.removeSaveCookie(...)"); //NOI18N
// remove Save cookie from the entry
SaveCookie sc = entry.getCookie(SaveCookie.class);
if (sc != null && sc.equals(this)) {
entry.getCookieSet().remove(this);
}
final SaveCookie cookie = this;
PropertiesRequestProcessor.getInstance().post(new Runnable() {
public void run() {
PropertiesDataObject dataObject = (PropertiesDataObject) getDataObject();
dataObject.updateModificationStatus();
dataObject.getCookieSet0().remove(cookie);
}
});
}
示例12: refreshName
import org.openide.cookies.SaveCookie; //导入依赖的package包/类
private void refreshName () {
Mutex.EVENT.readAccess(new Runnable() {
@Override
public void run () {
String name = org.openide.util.NbBundle.getMessage(MergeDialogComponent.class, "MergeDialogComponent.title");
Component[] panels;
synchronized (MergeDialogComponent.this) {
panels = mergeTabbedPane.getComponents();
}
for (int i = 0; i < panels.length; i++) {
MergePanel panel = (MergePanel) panels[i];
MergeNode node = nodesForPanels.get(panel);
if (node.getLookup().lookup(SaveCookie.class) != null) {
name = "<html><b>" + name + "*</b></html>"; //NOI18N
break;
}
}
setName(name);
}
});
}
示例13: provideSaveCookie
import org.openide.cookies.SaveCookie; //导入依赖的package包/类
private void provideSaveCookie() {
SaveCookie scNew = saver.getSaveCookie();
if (scCache != null) {
if (!saver.isChanged()) {
if (LOG.isLoggable(Level.FINE)) LOG.fine("remove save cookie: " + dobj); // NOI18N
lkpContent.remove(scCache);
scCache = null;
return;
}
} else {
if (saver.isChanged()) {
scCache = scNew;
if (LOG.isLoggable(Level.FINE)) LOG.fine("add save cookie: " + dobj + " cookie: " + scNew); // NOI18N
lkpContent.add(scNew);
return;
}
}
}
示例14: saveDocumentIfNotOpened
import org.openide.cookies.SaveCookie; //导入依赖的package包/类
/**
* Saves the given document to its underlying {@link FileObject} if the document
* is not opened in the nb editor, more formally if EditorCookie.getOpenedPanes() == null.
*
* @param document
* @throws IOException
*/
public static void saveDocumentIfNotOpened(Document document) throws IOException {
Object o = document.getProperty(Document.StreamDescriptionProperty);
if (o == null || !(o instanceof DataObject)) {
return;
}
DataObject dobj = (DataObject) o;
EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class);
if (ec != null && ec.getOpenedPanes() == null) {
//file not open in any editor
SaveCookie save = dobj.getLookup().lookup(SaveCookie.class);
if (save != null) {
save.save();
}
}
}
示例15: removeSaveCookie
import org.openide.cookies.SaveCookie; //导入依赖的package包/类
public void removeSaveCookie() {
DataObject javaData = this.getDataObject();
if (javaData.getCookie(SaveCookie.class) != null) {
cookies.remove(saveCookie);
javaData.setModified(false);
}
}