Java Code Examples for org.openide.loaders.DataFolder#children()

The following examples show how to use org.openide.loaders.DataFolder#children() . 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: LayersBridge.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void initActions (String folder, String category) {
    if (loadedFromFolders != null) {
        for (FileObject f : loadedFromFolders) {
            f.removeFileChangeListener(weakFolderL);
        }
    }
    FileObject fo = FileUtil.getConfigFile(folder);
    if (fo == null) return;
    DataFolder root = DataFolder.findFolder (fo);
    if (loadedFromFolders == null) {
        // the root must exist all the time, attach just once:
        root.getPrimaryFile().addFileChangeListener(weakFolderL);
    }
    Enumeration<DataObject> en = root.children ();
    Collection<FileObject> newFolders = new ArrayList<>(7);
    while (en.hasMoreElements ()) {
        DataObject dataObject = en.nextElement ();
        if (dataObject instanceof DataFolder) {
            initActions ((DataFolder) dataObject, null, category, newFolders);
        }
    }
    this.loadedFromFolders = newFolders;
}
 
Example 2
Source File: LayersBridge.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void refreshKeymapNames() {
    DataFolder root = getRootFolder(KEYMAPS_FOLDER, null);
    Enumeration en = root.children(false);
    List<String> names = new ArrayList<String>();
    Map<String, String> displayNames = new HashMap<String, String>();
    while (en.hasMoreElements()) {
        FileObject f = ((DataObject) en.nextElement()).getPrimaryFile();
        if (f.isFolder()) {
            String name = f.getNameExt();
            String displayName;

            try {
                displayName = f.getFileSystem().getDecorator().annotateName(name, Collections.singleton(f));
            } catch (FileStateInvalidException fsie) {
                // ignore
                displayName = name;
            }
            names.add(name);
            displayNames.put(name, displayName);
        }
    }
    if (names.isEmpty()) {
        names.add("NetBeans"); //NOI18N
    }
    synchronized (this) {
        this.keymapNames = names;
        this.keymapDisplayNames = displayNames;
    }
}
 
Example 3
Source File: LayersBridge.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Read keymap from one folder Map (GlobalAction > Set (String (shortcut))).
 */
private Map<ShortcutAction, Set<String>> readKeymap (DataFolder root, boolean ignoreUserRemoves) {
    LOG.log(Level.FINEST, "Reading keymap from: {0}", root);
    Map<ShortcutAction, Set<String>> keymap = 
            new HashMap<ShortcutAction, Set<String>> ();
    if (root == null) return keymap;
    Enumeration<DataObject> en = root.children (false);
    while (en.hasMoreElements ()) {
        DataObject dataObject = en.nextElement ();
        if (dataObject instanceof DataFolder) continue;
        GlobalAction action = createActionWithLookup (dataObject, null, dataObject.getPrimaryFile().getName(), ignoreUserRemoves);
        if (action == null) continue;
        String shortcut = dataObject.getPrimaryFile().getName().toUpperCase();
        
        LOG.log(Level.FINEST, "Action {0}: {1}, by {2}", new Object[] {
            action.getId(),
            shortcut,
            dataObject.getPrimaryFile().getPath()
        });
        Set<String> s = keymap.get (action);
        if (s == null) {
            s = new HashSet<String> ();
            keymap.put (action, s);
        }
        s.add (shortcut);
    }
    return keymap;
}
 
Example 4
Source File: LayersBridge.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void initActions (
    DataFolder folder, 
    String folderName, 
    String category, 
    Collection<FileObject> folders
) {
    
    // 1) reslove name
    String name = folder.getName ();
    if (category != null)
        name = category;
    else {
        String bundleName = (String) folder.getPrimaryFile ().getAttribute 
            ("SystemFileSystem.localizingBundle");
        if (bundleName != null)
            try {
                name = NbBundle.getBundle (bundleName).getString (
                    folder.getPrimaryFile ().getPath ()
                );
            } catch (MissingResourceException ex) {
                ErrorManager.getDefault ().notify (ex);
            }
        if (folderName != null) 
            name = folderName + '/' + name;
    }
    folders.add(folder.getPrimaryFile());
    // watch out for changes
    folder.getPrimaryFile().addFileChangeListener(weakFolderL);
    Enumeration en = folder.children ();
    while (en.hasMoreElements ()) {
        DataObject dataObject = (DataObject) en.nextElement ();
        if (dataObject instanceof DataFolder) {
            initActions ((DataFolder) dataObject, name, category, folders);
            continue;
        }
        GlobalAction action = createAction (dataObject, name, dataObject.getPrimaryFile().getName(), false);
        if (action == null) continue;
        if (actions.containsKey (action)) continue;
        actions.put (action, action);
        
        // add to actions (Map (String (folderName) > Set (GlobalAction))).
        Set<ShortcutAction> a = categoryToActions.get (name);
        if (a == null) {
            a = new HashSet<ShortcutAction> ();
            categoryToActions.put (name, a);
        }
        a.add (action);
        
        while (dataObject instanceof DataShadow)
            dataObject = ((DataShadow) dataObject).getOriginal ();
        
        actionToDataObject.put (action, dataObject);
    }
}