Java Code Examples for org.openide.cookies.EditorCookie#isModified()

The following examples show how to use org.openide.cookies.EditorCookie#isModified() . 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: DiffUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void cleanThoseUnmodified(EditorCookie[] editorCookies) {
    for (int i = 0; i < editorCookies.length; i++) {
        EditorCookie editorCookie = editorCookies[i];
        if (editorCookie == null) {
            continue;
        }
        if (!editorCookie.isModified()) {
            editorCookies[i] = null;
        }
    }
}
 
Example 2
Source File: SaveDocumentTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Tests the #17714. */
public void testSaveDocument() throws Exception {
    System.err.println("Test Save Document");
    
    FileObject fo = FileUtil.getConfigRoot().createData("test", "txt");

    DataObject data = DataObject.find(fo);
    
    EditorCookie ec = data.getCookie(EditorCookie.class);
    
    if(!(ec instanceof CloneableEditorSupport)) {
        throw new IllegalStateException("Bad editor cookie type");
    }

    CloneableEditorSupport ces = (CloneableEditorSupport)ec;
    System.err.println("CloneableEditorSupport="+ces);

    if(ces.isModified()) {
        throw new IllegalStateException("Cloneable editor support should be marked as unmodified!");
    }
    System.err.println("Saving unmodified document");
    ces.saveDocument();
    
    final StyledDocument doc = ces.openDocument();
    
    NbDocument.runAtomicAsUser(doc, new Runnable() {
        public void run() {
            try {
                doc.insertString(0, "Inserted string", null);
            } catch(BadLocationException ble) {
                ble.printStackTrace();
            }
        }
    });

    System.err.println("doc="+ces.getDocument());
    
    System.err.println("ec isModified="+ces.isModified());
    if(!ec.isModified()) {
        throw new IllegalStateException("CloneableEditorSupport should be marked as modified already!");
    }
    System.err.println("Saving modified document");
    
    ces.saveDocument();
}
 
Example 3
Source File: DiffFileTable.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private boolean isModified (File file) {
    EditorCookie editorCookie = editorCookies.get(file);
    return (editorCookie != null) ? editorCookie.isModified() : false;
}
 
Example 4
Source File: DiffFileTable.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private boolean isModified(int row) {
    EditorCookie editorCookie = editorCookies[row];
    return (editorCookie != null) ? editorCookie.isModified() : false;
}
 
Example 5
Source File: FileTreeView.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private boolean isModified (T node) {
    int index = Arrays.asList(nodes).indexOf(node);
    EditorCookie editorCookie = index >= 0 && index < editorCookies.length ? editorCookies[index] : null;
    return (editorCookie != null) ? editorCookie.isModified() : false;
}
 
Example 6
Source File: DiffFileTable.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private boolean isModified(int row) {
    EditorCookie editorCookie = editorCookies[row];
    return (editorCookie != null) ? editorCookie.isModified() : false;
}