Java Code Examples for org.openide.loaders.DataObject#setModified()
The following examples show how to use
org.openide.loaders.DataObject#setModified() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HtmlDataObjectTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testSetModifiedNestedChange() throws Exception { FileSystem fs = FileUtil.createMemoryFileSystem(); FileObject f = fs.getRoot().createData("modify.html"); final DataObject dob = DataObject.find(f); assertEquals("The right object", HtmlDataObject.class, dob.getClass()); dob.getLookup().lookup(EditorCookie.class).openDocument().insertString(0, "modified", null); assertTrue("Should be modified.", dob.isModified()); dob.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { String s = evt.getPropertyName(); if (DataObject.PROP_MODIFIED.equals(s) && !dob.isModified()) { dob.setModified(true); } } }); dob.setModified(false); assertTrue("Should be still modified.", dob.isModified()); assertNotNull("Still should have save cookie.", dob.getLookup().lookup(SaveCookie.class)); }
Example 2
Source File: SaveAllActionGCTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testIssue162686() throws IOException { SaveAllAction a = SaveAllAction.get(SaveAllAction.class); assertNotNull("Action found", a); assertFalse("Nothing is modified", a.isEnabled()); FileObject fo = FileUtil.createData(FileUtil.createMemoryFileSystem().getRoot(), "Folder/JR.txt"); DataObject obj = DataObject.find(fo); assertFalse("Nothing is modified2", a.isEnabled()); obj.setModified(true); assertTrue("SaveAll enabled now", a.isEnabled()); obj.setModified(false); assertFalse("SaveAll disabled now", a.isEnabled()); WeakReference<?> ref = new WeakReference<Object>(a); a = null; assertGC("The action can be GCed", ref); a = SaveAllAction.get(SaveAllAction.class); assertNotNull("But we can always create new one", a); assertFalse("It is disbabled initially", a.isEnabled()); obj.setModified(true); assertTrue("But enables as soon an object is modified", a.isEnabled()); }
Example 3
Source File: DataEditorSupportSaveAsTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testModifiedDocumentSaveAs() throws IOException { FileUtil.createData(FileUtil.getConfigRoot(), "someFolder/someFile.obj"); DataObject obj = DataObject.find(FileUtil.getConfigFile("someFolder/someFile.obj")); assertEquals( MyDataObject.class, obj.getClass()); assertTrue( "we need UniFileLoader", obj.getLoader() instanceof UniFileLoader ); obj.setModified( true ); MyEnv env = new MyEnv( obj ); MyDataEditorSupport des = new MyDataEditorSupport( obj, env ); FileObject newFolder = FileUtil.createFolder(FileUtil.getConfigRoot(), "otherFolder"); des.saveAs( newFolder, "newFile.newExt" ); DataObject newObj = DataObject.find(FileUtil.getConfigFile("otherFolder/newFile.newExt")); assertEquals( MyDataObject.class, newObj.getClass()); MyDataObject myObj = (MyDataObject)newObj; assertEquals("the original StyledDocument was rendered (no file copy)", 1, des.renderCounter); assertFalse("the original document is no longer modified", obj.isModified() ); assertEquals("the original document was closed", 1, des.closeCounter ); assertEquals("we don't ask before closing the original document", 0, des.canCloseCounter ); assertTrue("new document was opened", myObj.openCookieCalls > 0); }
Example 4
Source File: SetModifiedTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testUnmodifyViaSetModified() throws IOException, BadLocationException { FileSystem fs = FileUtil.createMemoryFileSystem(); FileObject fo = fs.getRoot().createData("test.jsp"); assertNotNull(fo); DataObject obj = DataObject.find(fo); assertNotNull(obj); assertFalse(obj.isModified()); assertNull(obj.getCookie(SaveCookie.class)); obj.getCookie(EditorCookie.class).openDocument().insertString(0, "hello", null); assertTrue(obj.isModified()); assertNotNull(obj.getCookie(SaveCookie.class)); //some QE unit tests needs to silently discard the changed made to the editor document obj.setModified(false); assertFalse(obj.isModified()); assertNull(obj.getCookie(SaveCookie.class)); }
Example 5
Source File: GsfDataObjectTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testSetModifiedNestedChange() throws Exception { FileSystem fs = FileUtil.createMemoryFileSystem(); FileObject f = fs.getRoot().createData("index.test"); DataObject dob = DataObject.find(f); assertEquals("The right object", GsfDataObject.class, dob.getClass()); dob.getLookup().lookup(EditorCookie.class).openDocument().insertString(0, "modified", null); assertTrue("Should be modified.", dob.isModified()); dob.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { String s = evt.getPropertyName(); if (DataObject.PROP_MODIFIED.equals(s) && !dob.isModified()) { dob.setModified(true); } } }); dob.setModified(false); assertTrue("Should be still modified.", dob.isModified()); assertNotNull("Still should have save cookie.", dob.getLookup().lookup(SaveCookie.class)); }
Example 6
Source File: CustomizationWSEditor.java From netbeans with Apache License 2.0 | 6 votes |
public void cancel(Node node) { if (undoManager != null) { while (undoManager.canUndo()) { undoManager.undo(); } } try { Set<WSDLModel> modelSet = wsdlModels.keySet(); for (WSDLModel wsdlModel : modelSet) { ModelSource ms = wsdlModel.getModelSource(); FileObject fo = (FileObject) ms.getLookup().lookup(FileObject.class); DataObject wsdlDobj = DataObject.find(fo); wsdlDobj.setModified(wsdlModels.get(wsdlModel)); } } catch (DataObjectNotFoundException e) { ErrorManager.getDefault().notify(e); } removeListeners(); }
Example 7
Source File: CustomizationWSEditor.java From netbeans with Apache License 2.0 | 6 votes |
public void cancel(Node node) { if (undoManager != null) { while (undoManager.canUndo()) { undoManager.undo(); } } try { Set<WSDLModel> modelSet = wsdlModels.keySet(); for (WSDLModel wsdlModel : modelSet) { ModelSource ms = wsdlModel.getModelSource(); FileObject fo = (FileObject) ms.getLookup().lookup(FileObject.class); DataObject wsdlDobj = DataObject.find(fo); wsdlDobj.setModified(wsdlModels.get(wsdlModel)); } } catch (DataObjectNotFoundException e) { ErrorManager.getDefault().notify(e); } removeListeners(); }
Example 8
Source File: SaveableSectionInnerPanel.java From netbeans with Apache License 2.0 | 5 votes |
protected void setModelDirty(WSDLModel model) { try { ModelSource ms = model.getModelSource(); FileObject fo = (FileObject) ms.getLookup().lookup(FileObject.class); DataObject wsdlDO = DataObject.find(fo); if (!wsdlDO.isModified()) { wsdlDO.setModified(true); } } catch (Exception e) { ErrorManager.getDefault().notify(e); } }
Example 9
Source File: GsfDataObjectTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testSetModifiedRemovesSaveCookie() throws Exception { FileSystem fs = FileUtil.createMemoryFileSystem(); FileObject f = fs.getRoot().createData("index.test"); DataObject dob = DataObject.find(f); assertEquals("The right object", GsfDataObject.class, dob.getClass()); dob.getLookup().lookup(EditorCookie.class).openDocument().insertString(0, "modified", null); assertTrue("Should be modified.", dob.isModified()); dob.setModified(false); assertFalse("Should not be modified.", dob.isModified()); assertNull("Should not have SaveCookie.", dob.getLookup().lookup(SaveCookie.class)); }
Example 10
Source File: HtmlDataObjectTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testUnmodifyViaSetModified() throws IOException, BadLocationException { FileObject fo = FileUtil.createData(FileUtil.getConfigRoot(), "test2.html"); assertNotNull(fo); final DataObject obj = DataObject.find(fo); assertNotNull(obj); assertFalse(obj.isModified()); assertNull(obj.getLookup().lookup(SaveCookie.class)); final StyledDocument doc = obj.getLookup().lookup(EditorCookie.class).openDocument(); assertTrue(doc instanceof BaseDocument); ((BaseDocument) doc).runAtomic(new Runnable() { @Override public void run() { try { doc.insertString(0, "hello", null); } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } } }); ((BaseDocument) doc).runAtomic(new Runnable() { @Override public void run() { assertTrue(obj.isModified()); } }); assertNotNull(obj.getLookup().lookup(SaveCookie.class)); //some QE unit tests needs to silently discard the changed made to the editor document obj.setModified(false); assertFalse(obj.isModified()); assertNull(obj.getLookup().lookup(SaveCookie.class)); }
Example 11
Source File: ExitDialog.java From netbeans with Apache License 2.0 | 5 votes |
/** Exit the IDE */ private void theEnd() { // XXX(-ttran) result must be set before calling setVisible(false) // because this will unblock the thread which called Dialog.show() for (int i = listModel.size() - 1; i >= 0; i--) { DataObject obj = (DataObject) listModel.getElementAt(i); obj.setModified(false); } result = true; exitDialog.setVisible (false); exitDialog.dispose(); }
Example 12
Source File: WSITModelSupport.java From netbeans with Apache License 2.0 | 5 votes |
private static void save(WSDLModel model, Set<FileObject> traversedModels) { if (model == null) { logger.log(Level.INFO, "Model cannot be null."); return; } FileObject modelFO = Util.getFOForModel(model); if (modelFO == null) { logger.log(Level.INFO, "Cannot find fileobject in lookup for: " + model.getModelSource()); } // avoid neverending recursion for recursive imports if (traversedModels.contains(modelFO)) { return; } traversedModels.add(modelFO); try { Definitions defs = model.getDefinitions(); if (defs != null) { Collection<Import> imports = defs.getImports(); for (Import i : imports) { WSDLModel importedModel = i.getImportedWSDLModel(); save(importedModel, traversedModels); } DataObject wsdlDO = DataObject.find(modelFO); if ((wsdlDO != null) && (wsdlDO.isModified())) { SaveCookie wsdlSaveCookie = wsdlDO.getCookie(SaveCookie.class); if(wsdlSaveCookie != null){ wsdlSaveCookie.save(); } wsdlDO.setModified(false); } } } catch (Exception e) { logger.log(Level.SEVERE, null, e); } }
Example 13
Source File: PHPDataObjectTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testSetModifiedRemovesSaveCookie() throws Exception { FileSystem fs = FileUtil.createMemoryFileSystem(); FileObject f = fs.getRoot().createData("index.php"); DataObject dob = DataObject.find(f); dob.getLookup().lookup(EditorCookie.class).openDocument().insertString(0, "modified", null); assertTrue("Should be modified.", dob.isModified()); dob.setModified(false); assertFalse("Should not be modified.", dob.isModified()); assertNull("Should not have SaveCookie.", dob.getLookup().lookup(SaveCookie.class)); }
Example 14
Source File: TopComponentOperator.java From netbeans with Apache License 2.0 | 5 votes |
/** Finds DataObject for the content of this TopComponent and set it * unmodified. Used in closeDiscard method. */ public void setUnmodified() { DataObject dob = ((TopComponent) getSource()).getLookup().lookup(DataObject.class); if (dob == null) { // try to find possible enclosing MultiviewTopComponent TopComponentOperator parentTco = findParentTopComponent(); if (parentTco != null) { parentTco.setUnmodified(); } } else { dob.setModified(false); } }
Example 15
Source File: SimpleES.java From netbeans with Apache License 2.0 | 5 votes |
/** Helper method. Removes save cookie from the data object. */ private void removeSaveCookie(boolean setModified) { DataObject obj = getDataObject(); // Remove save cookie from the data object. Cookie cookie = obj.getCookie(SaveCookie.class); if(cookie != null && cookie.equals(saveCookie)) { set.remove(saveCookie); if (setModified) { obj.setModified(false); } } }
Example 16
Source File: SimpleES.java From netbeans with Apache License 2.0 | 5 votes |
/** Helper method. Adds save cookie to the data object. */ private void addSaveCookie() { DataObject obj = getDataObject(); // Adds save cookie to the data object. if(obj.getCookie(SaveCookie.class) == null) { set.add(saveCookie); obj.setModified(true); } }
Example 17
Source File: FormEditorSupport.java From netbeans with Apache License 2.0 | 5 votes |
public void addSaveCookie() { DataObject javaData = this.getDataObject(); if (javaData.getCookie(SaveCookie.class) == null) { cookies.add(saveCookie); javaData.setModified(true); } }
Example 18
Source File: BIEditorSupport.java From netbeans with Apache License 2.0 | 5 votes |
public void removeSaveCookie() { DataObject javaData = this.getDataObject(); if (javaData.getCookie(SaveCookie.class) != null) { this.cookieSet.remove(this.saveCookie); javaData.setModified(false); } }
Example 19
Source File: BIEditorSupport.java From netbeans with Apache License 2.0 | 5 votes |
public void addSaveCookie() { DataObject javaData = this.getDataObject(); if (javaData.getCookie(SaveCookie.class) == null) { if (this.saveCookie == null) this.saveCookie = new SaveSupport(); this.cookieSet.add(this.saveCookie); javaData.setModified(true); } }
Example 20
Source File: BIEditorSupport.java From netbeans with Apache License 2.0 | 4 votes |
public void save() throws java.io.IOException { DataObject dobj = getDataObject(); ((DataEditorSupport) findCloneableOpenSupport()).saveDocument(); dobj.setModified(false); }