Java Code Examples for org.openide.filesystems.FileObject.canRevert()

The following are Jave code examples for showing how to use canRevert() of the org.openide.filesystems.FileObject class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: LayersBridge.java   View Source Code Vote up 6 votes
/**
 * Custom profile is present if:
 * a/ the profile's folder can be reverted (=> was materialized on writable layer)
 * b/ there's no "reveal" entry for it in its parent => was not present
 * @param profileName
 * @return C
 */
public boolean isCustomProfile(String profileName) {
    DataFolder profileFolder = getExistingProfile(profileName);
    if (profileFolder == null) {
        return true;
    }
    FileObject f = profileFolder.getPrimaryFile();
    if (!f.canRevert()) {
        return false;
    }
    FileObject parentF = profileFolder.getPrimaryFile().getParent();
    if (parentF == null) {
        // very very unlikely
        return true;
    }
    Collection<FileObject> col = (Collection<FileObject>)parentF.getAttribute("revealEntries");
    if (col == null) {
        return true;
    }
    for (FileObject f2 : col) {
        if (f2.getNameExt().equals(profileName)) {
            return false;
        }
    }
    return true;
}
 
Example 2
Project: incubator-netbeans   File: ShortcutWizard.java   View Source Code Vote up 5 votes
private static void delete(FileObject file) throws IOException { // cf. #162526
    if (file.canRevert()) {
        file.revert();
    } else {
        throw new IOException("Could not delete " + file);
    }
}
 
Example 3
Project: incubator-netbeans   File: LayersBridge.java   View Source Code Vote up 5 votes
/**
 * Returns instance of GlobalAction encapsulating action, or null.
 */
private GlobalAction createAction (DataObject dataObject, String prefix, String name, boolean ignoreUserRemoves) {
    InstanceCookie ic = dataObject.getCookie(InstanceCookie.class);
    // handle any non-IC file as instruction to remove the action
    FileObject pf = dataObject.getPrimaryFile();
    if (ignoreUserRemoves && pf.canRevert()) {
        return null;
    }
    if (ic == null) {
        if (!EXT_REMOVED.equals(pf.getExt())) {
            LOG.log(Level.WARNING, "Invalid shortcut: {0}", dataObject);
            return null;
        }
        // ignore the 'remove' file, if there's a shadow (= real action) present
        if (FileUtil.findBrother(pf, "shadow") != null) {
            // handle redefinition + removal: ignore the removal.
            return null;
        }
        return REMOVED;
    }
    try {
        Object action = ic.instanceCreate ();
        if (action == null) return null;
        if (!(action instanceof Action)) return null;
        return createAction((Action) action, prefix, name);
    } catch (Exception ex) {
        ex.printStackTrace ();
        return null;
    }
}
 
Example 4
Project: incubator-netbeans   File: TemplatesPanel.java   View Source Code Vote up 5 votes
private static boolean canRevert(Node[] nodes) {
    if (nodes == null) {
        return false;
    }
    boolean can = false;
    for (Node node : nodes) {
        FileObject fo = node.getLookup().lookup(FileObject.class);
        if (fo != null && fo.canRevert()) {
            can = true;
        } else {
            return false;
        }
    }
    return can;
}
 
Example 5
Project: incubator-netbeans   File: TemplatesPanel.java   View Source Code Vote up 5 votes
/** Test if the file physically exists on disk and thus was created by user and can be renamed. */
private static boolean isUserFile(FileObject fo) {
    // A layer-defined folder with a user-added file (or subfolder) should not be renamable:
    for (FileObject child : fo.getChildren()) {
        if (!isUserFile(child)) {
            return false;
        }
    }
    return fo.canRevert();
}