Java Code Examples for org.openide.filesystems.FileUtil#getOrder()

The following examples show how to use org.openide.filesystems.FileUtil#getOrder() . 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: LayersCheck.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testNoWarningsAboutOrderingForLoaders() {
    FileObject root = FileUtil.getConfigFile("Loaders");
    assertNotNull("Loader's root found", root);
    CharSequence log = Log.enable("org.openide.filesystems", Level.WARNING);

    Enumeration<? extends FileObject> en = root.getChildren(true);
    int cnt = 0;
    while (en.hasMoreElements()) {
        FileObject fo = en.nextElement();
        if (!fo.isFolder()) {
            continue;
        }
        FileUtil.getOrder(Arrays.asList(fo.getChildren()), true);
        cnt++;
    }
    if (cnt < 10) {
        fail("There shall be at least 10 files in loaders. Was: " + cnt);
    }

    String msg = log.toString();
    if (msg.contains(("Found same position"))) {
        fail("There shall be no same position loaders!\n" + msg);
    }
}
 
Example 2
Source File: ActionFileSystem.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
public static FileObject findOperatorFile(final String opName) {
    final FileObject fileObj = FileUtil.getConfigFile("Actions/Operators");
    if (fileObj == null) {
        SystemUtils.LOG.warning("No Operator Actions found.");
        return null;
    }
    final FileObject[] files = fileObj.getChildren();
    final List<FileObject> orderedFiles = FileUtil.getOrder(Arrays.asList(files), true);
    for (FileObject file : orderedFiles) {
        final String operatorName = (String) file.getAttribute("operatorName");
        if(opName.equals(operatorName)) {
            return file;
        }
    }
    return null;
}
 
Example 3
Source File: LayerManager.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
private static Map<String, LayerSourceDescriptor> lookupLayerSourceDescriptors() {
    Map<String, LayerSourceDescriptor> layerSourceDescriptors = new LinkedHashMap<>();
    FileObject[] files = FileUtil.getConfigFile("LayerSources").getChildren();
    //System.out.println("Files in SNAP/LayerSources: " + Arrays.toString(files));
    List<FileObject> orderedFiles = FileUtil.getOrder(Arrays.asList(files), true);
    for (FileObject file : orderedFiles) {
        LayerSourceDescriptor layerSourceDescriptor = null;
        try {
            layerSourceDescriptor = createLayerSourceDescriptor(file);
        } catch (Exception e) {
            LOG.log(Level.SEVERE, String.format("Failed to create layer source from layer.xml path '%s'", file.getPath()), e);
        }
        if (layerSourceDescriptor != null) {
            layerSourceDescriptors.put(layerSourceDescriptor.getId(), layerSourceDescriptor);
            LOG.info(String.format("New layer source added from layer.xml path '%s': %s",
                                   file.getPath(), layerSourceDescriptor.getName()));
        }
    }
    return layerSourceDescriptors;
}
 
Example 4
Source File: ValidateLayerConsistencyTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void loadChildren(FileObject folder) {
    List<FileObject> kids = new ArrayList<FileObject>();
    for (DataObject kid : DataFolder.findFolder(folder).getChildren()) {
        kids.add(kid.getPrimaryFile());
    }
    FileUtil.getOrder(kids, true);
}
 
Example 5
Source File: ProviderModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static List<Category> loadCategories () {
    FileObject[] categoryFOs = FileUtil.getConfigFile(SEARCH_PROVIDERS_FOLDER).getChildren();

    // respect ordering defined in layers
    List<FileObject> sortedCats = FileUtil.getOrder(Arrays.asList(categoryFOs), false);

    List<ProviderModel.Category> categories = new ArrayList<ProviderModel.Category>(sortedCats.size());

    for (FileObject curFO : sortedCats) {
        String displayName = null;
        try {
            displayName = curFO.getFileSystem().getDecorator().annotateName(
                    curFO.getNameExt(), Collections.singleton(curFO));
        } catch (FileStateInvalidException ex) {
            Logger.getLogger(ProviderModel.class.getName()).log(Level.WARNING,
                    "Obtaining display name for " + curFO + " failed.", ex);
        }

        String commandPrefix = null;
        Object cpAttr = curFO.getAttribute(COMMAND_PREFIX);
        if (cpAttr instanceof String) {
            commandPrefix = (String)cpAttr;
        }

        categories.add(new Category(curFO, displayName, commandPrefix));
    }

    return categories;
}
 
Example 6
Source File: RecognizeInstanceFiles.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static List<FOItem> order(List<FOItem> items) {
    Map<FileObject,FOItem> m = new LinkedHashMap<FileObject,FOItem>();
    for (FOItem item : items) {
        m.put(item.fo, item);
    }
    List<FileObject> files = FileUtil.getOrder(m.keySet(), true);
    List<FOItem> r = new ArrayList<FOItem>(files.size());
    for (FileObject f : files) {
        r.add(m.get(f));
    }
    return r;
}
 
Example 7
Source File: OperatorUIRegistry.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void registerOperatorUIs() {
    FileObject fileObj = FileUtil.getConfigFile("OperatorUIs");
    if(fileObj == null) {
        SystemUtils.LOG.warning("No operatorUIs found.");
        return;
    }
    final FileObject[] files = fileObj.getChildren();
    final List<FileObject> orderedFiles = FileUtil.getOrder(Arrays.asList(files), true);
    for (FileObject file : orderedFiles) {
        OperatorUIDescriptor operatorUIDescriptor = null;
        try {
            operatorUIDescriptor = createOperatorUIDescriptor(file);
        } catch (Exception e) {
            SystemUtils.LOG.severe(String.format("Failed to create operatorUI from layer.xml path '%s'", file.getPath()));
        }
        if (operatorUIDescriptor != null) {
            // must have only one operatorUI per operator
            final OperatorUIDescriptor existingDescriptor = operatorUIDescriptors.get(operatorUIDescriptor.getOperatorName());
            if (existingDescriptor != null) {
                SystemUtils.LOG.info(String.format("OperatorUI [%s] has been redeclared for [%s]!\n",
                                                   operatorUIDescriptor.getId(), operatorUIDescriptor.getOperatorName()));
            }

            operatorUIDescriptors.put(operatorUIDescriptor.getOperatorName(), operatorUIDescriptor);
            SystemUtils.LOG.fine(String.format("New operatorUI added from layer.xml path '%s': %s",
                                               file.getPath(), operatorUIDescriptor.getOperatorName()));
        }
    }
}
 
Example 8
Source File: ProductLibraryActionExtRegistry.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void registerActions() {
    final FileObject fileObj = FileUtil.getConfigFile("ProductLibraryActions");
    if (fileObj == null) {
        SystemUtils.LOG.warning("No ProductLibrary Action found.");
        return;
    }
    final FileObject[] files = fileObj.getChildren();
    final List<FileObject> orderedFiles = FileUtil.getOrder(Arrays.asList(files), true);
    for (FileObject file : orderedFiles) {
        ProductLibraryActionExtDescriptor actionExtDescriptor = null;
        try {
            actionExtDescriptor = createDescriptor(file);
        } catch (Exception e) {
            SystemUtils.LOG.severe(String.format("Failed to create ProductLibrary action from layer.xml path '%s'", file.getPath()));
        }
        if (actionExtDescriptor != null) {
            if(!actionExtDescriptor.isSeperator()) {
                final ProductLibraryActionExtDescriptor existingDescriptor = actionExtDescriptors.get(actionExtDescriptor.getId());
                if (existingDescriptor != null) {
                    SystemUtils.LOG.warning(String.format("ProductLibrary action [%s] has been redeclared!\n",
                            actionExtDescriptor.getId()));
                }
            }

            actionExtDescriptors.put(actionExtDescriptor.getId(), actionExtDescriptor);
            SystemUtils.LOG.fine(String.format("New ProductLibrary action added from layer.xml path '%s': %s",
                    file.getPath(), actionExtDescriptor.getId()));
        }
    }
}
 
Example 9
Source File: WWLayerRegistry.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void registerWWLayers() {
    final FileObject fileObj = FileUtil.getConfigFile("WorldWindLayers");
    if (fileObj == null) {
        SystemUtils.LOG.warning("No World Wind layers found.");
        return;
    }
    final FileObject[] files = fileObj.getChildren();
    final List<FileObject> orderedFiles = FileUtil.getOrder(Arrays.asList(files), true);
    for (FileObject file : orderedFiles) {
        WWLayerDescriptor WWLayerDescriptor = null;
        try {
            WWLayerDescriptor = createWWLayerDescriptor(file);
        } catch (Exception e) {
            SystemUtils.LOG.severe(String.format("Failed to create WWLayerDescriptor from layer.xml path '%s'", file.getPath()));
        }
        if (WWLayerDescriptor != null) {
            final WWLayerDescriptor existingDescriptor = wwLayerDescriptors.get(WWLayerDescriptor.getId());
            if (existingDescriptor != null) {
                SystemUtils.LOG.warning(String.format("WWLayer [%s] has been redeclared!\n",
                                                   WWLayerDescriptor.getId()));
            }

            wwLayerDescriptors.put(WWLayerDescriptor.getId(), WWLayerDescriptor);

            SystemUtils.LOG.fine(String.format("New WWLayer added from layer.xml path '%s': %s",
                                               file.getPath(), WWLayerDescriptor.getId()));
        }
    }
}
 
Example 10
Source File: LayerManager.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private static void registerLayerEditors() {
    FileObject[] files = FileUtil.getConfigFile("LayerEditors").getChildren();
    //System.out.println("Files in SNAP/LayerEditors: " + Arrays.toString(files));
    List<FileObject> orderedFiles = FileUtil.getOrder(Arrays.asList(files), true);
    for (FileObject file : orderedFiles) {
        try {
            registerLayerEditorDescriptor(file);
            LOG.info(String.format("New layer editor registered from layer.xml path '%s'", file.getPath()));
        } catch (Exception e) {
            LOG.log(Level.SEVERE, String.format("Failed to register layer editor from layer.xml path '%s'", file.getPath()), e);
        }
    }
}
 
Example 11
Source File: OQLQueryRepository.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static List<FileObject> sortedFOs(Enumeration<? extends FileObject> fos) {
    List<FileObject> list = new ArrayList<>();
    while(fos.hasMoreElements()) list.add(fos.nextElement());
    return FileUtil.getOrder(list, false);
}
 
Example 12
Source File: NbEditorKit.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static List<FileObject> sort( FileObject[] children ) {
    List<FileObject> fos = Arrays.asList(children);
    fos = FileUtil.getOrder(fos, true);
    return fos;
}
 
Example 13
Source File: NbEditorKit.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static List<FileObject> sort( FileObject[] children ) {
    List<FileObject> fos = Arrays.asList(children);
    fos = FileUtil.getOrder(fos, true);
    return fos;
}
 
Example 14
Source File: OQLQueryRepository.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
private static List<FileObject> sortedFOs(Enumeration<? extends FileObject> fos) {
    List<FileObject> list = new ArrayList();
    while(fos.hasMoreElements()) list.add(fos.nextElement());
    return FileUtil.getOrder(list, false);
}