本文整理汇总了Java中org.openide.cookies.SaveCookie.save方法的典型用法代码示例。如果您正苦于以下问题:Java SaveCookie.save方法的具体用法?Java SaveCookie.save怎么用?Java SaveCookie.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.cookies.SaveCookie
的用法示例。
在下文中一共展示了SaveCookie.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: 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);
}
}
}
}
}
示例3: 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();
}
}
}
示例4: modifySourceElement
import org.openide.cookies.SaveCookie; //导入方法依赖的package包/类
/**
* Changes the class and id attributes of the active html source element.
*/
private void modifySourceElement() throws DataObjectNotFoundException, IOException {
final BaseDocument doc = (BaseDocument) getDocument(activeElement.getFile());
final AtomicBoolean success = new AtomicBoolean();
DataObject dataObject = DataObject.find(activeElement.getFile());
boolean modified = dataObject.getLookup().lookup(SaveCookie.class) != null;
pos = Integer.MAX_VALUE;
diff = -1;
doc.runAtomicAsUser(new Runnable() {
@Override
public void run() {
try {
if (selectedClazz != null) {
updateAttribute(doc, getSelectedElementClass(), selectedClazz.getItemName(), "class");
}
if (selectedId != null) {
updateAttribute(doc, getSelectedElementId(), selectedId.getItemName(), "id");
}
success.set(true); //better not to do the save from within the atomic modification task
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
}
}
});
//possibly save the document if not opened in editor
if (success.get()) {
if (!modified) { //wasn't modified before applying the changes, save...
SaveCookie saveCookie = dataObject.getLookup().lookup(SaveCookie.class);
if (saveCookie != null) { //the "changes" may not modify the document
saveCookie.save();
}
}
}
}
示例5: generate
import org.openide.cookies.SaveCookie; //导入方法依赖的package包/类
/**
* Performs a dialog with a user and generates the DTD
*/
public void generate() {
try {
//save the XML document before DTD generation
SaveCookie save = (SaveCookie)template.getCookie(SaveCookie.class);
if (save!=null) save.save();
FileObject primFile = template.getPrimaryFile();
String name = primFile.getName();
FileObject folder = primFile.getParent();
//use same name as the XML for default DTD name
FileObject generFile = (new SelectFileDialog(folder, name, DTD_EXT, Util.NONEMPTY_CHECK)).getFileObject();
//new name as per user
name = generFile.getName();
// get project's encoding
String encoding = EncodingUtil.getProjectEncoding(primFile);
//generate DTD content
generateDTDContent(encoding, name, generFile);
GuiUtil.performDefaultAction(generFile);
} catch (UserCancelException e) {
} catch (Exception exc) {
GuiUtil.notifyException(exc);
}
}
示例6: doSave
import org.openide.cookies.SaveCookie; //导入方法依赖的package包/类
public static void doSave (DataObject dataObject) {
try {
SaveCookie sc = dataObject.getLookup().lookup(SaveCookie.class);
if (sc != null) {
sc.save();
}
} catch (IOException exc) {
ErrorManager em = ErrorManager.getDefault();
Throwable t = em.annotate(
exc, NbBundle.getBundle(ExitDialog.class).getString("EXC_Save")
);
em.notify(ErrorManager.EXCEPTION, t);
}
}
示例7: saveBySaveCookie
import org.openide.cookies.SaveCookie; //导入方法依赖的package包/类
boolean saveBySaveCookie(){
try {
DataObject dobj = DataObject.find(backendCatalogFileObj);
SaveCookie saveCookie = (SaveCookie) dobj.getCookie(SaveCookie.class);
assert(saveCookie != null);
saveCookie.save();
} catch (IOException ex) {
return false;
}
return true;
}
示例8: save
import org.openide.cookies.SaveCookie; //导入方法依赖的package包/类
protected void save() {
FileObject fo = (FileObject) getCatalogModel().getModelSource().getLookup().lookup(FileObject.class);
try {
DataObject dobj = DataObject.find(fo);
SaveCookie saveCookie = (SaveCookie) dobj.getCookie(SaveCookie.class);
if(saveCookie != null)
saveCookie.save();
} catch (IOException ex) {
}
}
示例9: cancel
import org.openide.cookies.SaveCookie; //导入方法依赖的package包/类
/** Cancels current internationalizing session and re-layout top component to original layout. */
public void cancel() {
if (replaceCount>0) {
//Need to save resource
DataObject resource = support.getResourceHolder().getResource();
if (resource != null) {
SaveCookie save = resource.getCookie(SaveCookie.class);
if (save!=null) {
try {
save.save();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
}
}
replaceCount = 0;
// No memory leaks.
support = null;
if(LOG.isLoggable(Level.FINEST)) {
LOG.logp(Level.FINEST, getClass().getName(), "cancel()",
"Sets the I18nSupport to null"); // NOI18N
}
closeDialog();
}
示例10: saveAll
import org.openide.cookies.SaveCookie; //导入方法依赖的package包/类
private void saveAll(Node[] activatedNodes) {
for(Node node : activatedNodes) {
SaveCookie saveCookie = node.getLookup().lookup(SaveCookie.class);
if (saveCookie != null) {
try {
saveCookie.save();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
}
}
示例11: saveSource
import org.openide.cookies.SaveCookie; //导入方法依赖的package包/类
public static void saveSource(FileObject[] files) throws IOException {
for (FileObject f : files) {
try {
DataObject dobj = DataObject.find(f);
SaveCookie sc = dobj.getCookie(SaveCookie.class);
if (sc != null) {
sc.save();
}
} catch (DataObjectNotFoundException dex) {
// something really wrong but continue trying to save others
}
}
}
示例12: saveDocuments
import org.openide.cookies.SaveCookie; //导入方法依赖的package包/类
private void saveDocuments(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveDocuments
// Add your handling code here:
Node[] selNodes = explorer.getSelectedNodes();
if (selNodes.length == 0) {
return;
}
for (int i = 0; i < selNodes.length; i++) {
TopComponent tc = ((TopComponentNode) selNodes[i]).getTopComponent();
Lookup l = tc.getLookup();
SaveCookie sc = (SaveCookie) l.lookup(SaveCookie.class);
if (sc != null) {
try {
sc.save();
} catch (IOException exc) {
Logger.getAnonymousLogger().log(Level.WARNING,
"[WinSys.DocumentsDlg.saveDocuments]" // NOI18N
+ " Warning: Cannot save content of TopComponent: [" // NOI18N
+ WindowManagerImpl.getInstance().getTopComponentDisplayName(tc) + "]" // NOI18N
+ " [" + tc.getClass().getName() + "]", exc); // NOI18N
}
//Refresh name of node because TopComponent name is probably changed too
//('*' is removed)
((TopComponentNode) selNodes[i]).refresh();
}
}
jButtonSave.setEnabled(false);
}
示例13: saveDocument
import org.openide.cookies.SaveCookie; //导入方法依赖的package包/类
private static void saveDocument(TopComponent tc) {
SaveCookie sc = getSaveCookie(tc);
if(sc != null) {
try {
sc.save();
} catch(IOException ioe) {
Exceptions.printStackTrace(ioe);
}
}
}
示例14: saveDocument
import org.openide.cookies.SaveCookie; //导入方法依赖的package包/类
/** Save the document in this thread.
* Create "orig" document for the case that the save would fail.
* @exception IOException on I/O error
*/
public void saveDocument() throws IOException {
BundleStructure structure = bundleStructure;
SaveCookie save;
for (int i=0; i<structure.getEntryCount();i++) {
PropertiesFileEntry pfe = structure.getNthEntry(i);
if(pfe != null) { // #184927
save = pfe.getCookie(SaveCookie.class);
if (save != null) {
save.save();
}
}
}
}
示例15: ensureSavingFirst
import org.openide.cookies.SaveCookie; //导入方法依赖的package包/类
private void ensureSavingFirst() throws IOException {
//#65420 it can happen the manifest is currently being edited. save it
// and cross fingers because it can be in inconsistent state
try {
DataObject dobj = DataObject.find(manifestFile);
SaveCookie safe = dobj.getLookup().lookup(SaveCookie.class);
if (safe != null) {
safe.save();
}
} catch (DataObjectNotFoundException ex) {
Util.err.notify(ErrorManager.WARNING, ex);
}
}