Java Code Examples for org.openide.util.lookup.Lookups#forPath()

The following examples show how to use org.openide.util.lookup.Lookups#forPath() . 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: BugtrackingOptions.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public BugtrackingOptions() {
    if (initialized) return;
    initialized = true;
    tasksPanel = new DashboardOptions();
    panel = new BugtrackingOptionsPanel(tasksPanel);
    
    Lookup lookup = Lookups.forPath("BugtrackingOptionsDialog"); // NOI18N
    Iterator<? extends AdvancedOption> it = lookup.lookupAll(AdvancedOption.class).iterator();
    while (it.hasNext()) {
        AdvancedOption option = it.next();
        String category = option.getDisplayName();
        OptionsPanelController controller;
        try {
            controller = option.create();
        } catch (Throwable t) {
            BugtrackingManager.LOG.log(Level.WARNING, "Problems while creating option category : " + category, t);  // NOI18N
            continue;
        }
        categoryToController.put(category, controller);
    }
}
 
Example 2
Source File: NbToolTip.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Annotation[] getTipAnnotations() {
    Annotation[] annos;
    synchronized (NbToolTip.class) {
        annos = tipAnnotations;
    }
    
    if (annos == null) {
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Searching for tooltip annotations for mimeType = '" + mimeType + "'"); //NOI18N
        }
        Lookup l = Lookups.forPath("Editors/" + mimeType + "/ToolTips");  //NOI18N
        Collection<? extends Annotation> res = l.lookupAll(Annotation.class);
        if (res.contains(null)) {
            throw new IllegalStateException("Lookup returning null instance: " + l); // NOI18N
        }
        annos = res.toArray(new Annotation[res.size()]);
        synchronized (NbToolTip.class) {
            tipAnnotations = annos;
        }
    }
    
    return annos;
}
 
Example 3
Source File: TabbedController.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void readPanels() {
    Lookup lookup = Lookups.forPath(tabFolder);
    options = lookup.lookup(new Lookup.Template<AdvancedOption>( AdvancedOption.class ));
    tabTitle2controller = new HashMap<String, OptionsPanelController>();
    id2tabTitle = new HashMap<String, String>();
    synchronized (tabTitle2Option) {
        for (Lookup.Item<AdvancedOption> item : options.allItems()) {
            AdvancedOption option = item.getInstance();
            String displayName = option.getDisplayName();
            if (displayName != null) {
                tabTitle2Option.put(displayName, option);
                String id = item.getId().substring(item.getId().lastIndexOf('/') + 1);  //NOI18N
                id2tabTitle.put(id, displayName);
            } else {
                LOGGER.log(Level.WARNING, "Display name not defined: {0}", item.toString());  //NOI18N
            }
        }
    }
}
 
Example 4
Source File: NodeRegistry.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize the registry
 * @param folder the name of the xml layer folder to use
 * @param dataLookup the lookup to use when creating providers
 */
private void init(String folder, final Lookup dataLookup) {
    Lookup lookup = Lookups.forPath(PATH + folder + NODEPROVIDERS);
    lookupResult = lookup.lookupResult(NodeProviderFactory.class);

    initProviders(dataLookup);
    
    // listen for changes and re-init the providers when the lookup changes
    lookupResult.addLookupListener(WeakListeners.create(LookupListener.class,
        lookupListener = new LookupListener() {
            @Override
            public void resultChanged(LookupEvent ev) {
                initProviders(dataLookup);
                changeSupport.fireChange();
            }
        },
        lookupResult)
    );
}
 
Example 5
Source File: CodeCompletionOptionsSelector.java    From netbeans with Apache License 2.0 6 votes vote down vote up
String getSavedValue(String mimeType, String key) {
    PreferencesCustomizer prefsCustomizer = getCustomizer(mimeType);
    if (prefsCustomizer != null) {
        Lookup l = Lookups.forPath(CODE_COMPLETION_CUSTOMIZERS_FOLDER + mimeType);
        PreferencesCustomizer.CustomCustomizer customizer;
        if (mimeType.isEmpty()) {
            customizer = l.lookup(GeneralCompletionOptionsPanelController.CustomCustomizerImpl.class);
        } else {
            customizer = l.lookup(PreferencesCustomizer.CustomCustomizer.class);
        }
        if (customizer != null) {
            return customizer.getSavedValue(prefsCustomizer, key);
        }
    }
    return null;
}
 
Example 6
Source File: LayerLookupTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testLookupConsulted() throws IOException {
    FileObject servers = FileUtil.createFolder(FileUtil.getConfigRoot(),
            TEST_FOLDER);
    FileObject testLookup = FileUtil.createData(servers, "TestLookup.instance"); // NOI18N

    Map<Class<?>, Object> lookups = new HashMap<Class<?>, Object>();
    lookups.put(String.class, "Test"); // NOI18N
    lookups.put(Integer.class, Integer.valueOf(0));
    lookups.put(Character.class, Character.valueOf('a')); // NOI18N
    lookups.put(Double.class, Double.valueOf(0.0));

    TestLookup lookupInstance = new TestLookup(lookups);

    testLookup.setAttribute("instanceOf", Lookup.class.getName()); // NOI18N
    testLookup.setAttribute("instanceCreate", lookupInstance); // NOI18N

    Lookup lookup = Lookups.forPath(TEST_FOLDER);

    lookup(lookup, (String) lookups.get(String.class), String.class);
    lookup(lookup, (Integer) lookups.get(Integer.class), Integer.class);
    lookup(lookup, (Character) lookups.get(Character.class), Character.class);
    lookup(lookup, (Double) lookups.get(Double.class), Double.class);
    lookup(lookup, (String) lookups.get(String.class), String.class);
}
 
Example 7
Source File: NbMavenProjectImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
PackagingTypeDependentLookup(NbMavenProject watcher) {
    this.watcherRef = new WeakReference<NbMavenProject>(watcher);
    //needs to be kept around to prevent recreating instances
    general = Lookups.forPath("Projects/org-netbeans-modules-maven/Lookup"); //NOI18N
    check();
    watcher.addPropertyChangeListener(WeakListeners.propertyChange(this, watcher));
}
 
Example 8
Source File: DecoratedFileSystem.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private static synchronized Lookup consumerVisualVM () {
    if (consumerVisualVM != null) {
        return consumerVisualVM;
    }
    return consumerVisualVM = Lookups.forPath ("ConsumerVisualVM"); // NOI18N

}
 
Example 9
Source File: FolderBasedController.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Map<String, OptionsPanelController> getMimeType2delegates () {
    if (mimeType2delegates == null) {
        mimeType2delegates = new LinkedHashMap<String, OptionsPanelController>();
        for (String mimeType : EditorSettings.getDefault().getAllMimeTypes()) {
            Lookup l = Lookups.forPath(folder + mimeType);
            OptionsPanelController controller = l.lookup(OptionsPanelController.class);
            if (controller != null) {
                mimeType2delegates.put(mimeType, controller);
            }
        }
    }
    return mimeType2delegates;
}
 
Example 10
Source File: OnShowingHandler.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private synchronized Lookup.Result<Runnable> onShowing() {
    if (resShow == null) {
        Lookup lkp = lkpShowing != null ? lkpShowing : Lookups.forPath("Modules/UIReady"); // NOI18N
        resShow = lkp.lookupResult(Runnable.class);
        resShow.addLookupListener(this);
    }
    return resShow;
}
 
Example 11
Source File: RecognizeInstanceFilesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testNumericOrdering() throws Exception {
    class Tst implements FileSystem.AtomicAction {
        public void run() throws IOException {
            init();
        }
        
        void init() throws IOException {
            FileObject inst = FileUtil.createData(root, "inst/positional/X.instance");
            inst.setAttribute("instanceCreate", Long.valueOf(1000));
            inst.setAttribute("position", 3);
            FileObject inst2 = FileUtil.createData(root, "inst/positional/A.instance");
            inst2.setAttribute("instanceCreate", Long.valueOf(500));
            inst2.setAttribute("position", 1);
            FileObject inst3 = FileUtil.createData(root, "inst/positional/B.instance");
            inst3.setAttribute("instanceCreate", Long.valueOf(1500));
            inst3.setAttribute("position", 4);
            FileObject inst4 = FileUtil.createData(root, "inst/positional/C.instance");
            inst4.setAttribute("instanceCreate", Long.valueOf(700));
            inst4.setAttribute("position", 2);
        }
        
        void verify() {
            Lookup l = Lookups.forPath("inst/positional");
            Iterator<? extends Long> lng = l.lookupAll(Long.class).iterator();
            assertEquals(Long.valueOf(500), lng.next());
            assertEquals(Long.valueOf(700), lng.next());
            assertEquals(Long.valueOf(1000), lng.next());
            assertEquals(Long.valueOf(1500), lng.next());
            Iterator<? extends Lookup.Item<Long>> items = l.lookupResult(Long.class).allItems().iterator();
            assertEquals("inst/positional/A", items.next().getId());
            assertEquals("inst/positional/C", items.next().getId());
            assertEquals("inst/positional/X", items.next().getId());
            assertEquals("inst/positional/B", items.next().getId());
        }
    }
    
    Tst tst = new Tst();
    root.getFileSystem().runAtomicAction(tst);
    tst.verify();
}
 
Example 12
Source File: VcsAdvancedOptions.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void init(Lookup masterLookup) {
    if (initialized) return;
    initialized = true;
    panel = new VcsAdvancedOptionsPanel();

    Lookup lookup = Lookups.forPath("VersioningOptionsDialog"); // NOI18N
    Iterator<? extends AdvancedOption> it = lookup.lookup(new Lookup.Template<AdvancedOption> (AdvancedOption.class)).
            allInstances().iterator();
    while (it.hasNext()) {
        AdvancedOption option = it.next();
        registerOption(option, masterLookup);
    }
}
 
Example 13
Source File: EditorActionUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static Lookup.Result<Action> createActionsLookupResult(String mimeType) {
    if (!MimePath.validate(mimeType)) {
        throw new IllegalArgumentException("Ïnvalid mimeType=\"" + mimeType + "\"");
    }
    Lookup lookup = Lookups.forPath(getPath(mimeType, "Actions"));
    return lookup.lookupResult(Action.class);
}
 
Example 14
Source File: FontAndColorsPanelController.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public FontAndColorsPanelController() {
    Lookup lookup = Lookups.forPath("org-netbeans-modules-options-editor/OptionsDialogCategories/FontsColors"); //NOI18N
    lookupResult = lookup.lookupResult(FontsColorsController.class);
    lookupResult.addLookupListener(WeakListeners.create(
        LookupListener.class,
        lookupListener,
        lookupResult
    ));
    rebuild();
}
 
Example 15
Source File: CoreBridge.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Lookup lookupCacheLoad () {
    return Lookups.forPath("Services");
}
 
Example 16
Source File: NodeFactorySupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected Lookup createLookup() {
    return Lookups.forPath(folderPath);
}
 
Example 17
Source File: RootNode.java    From netbeans with Apache License 2.0 4 votes vote down vote up
static void enableActionsOnExpand(ServerRegistry registry) {
    FileObject fo = FileUtil.getConfigFile(registry.getPath()+"/Actions"); // NOI18N
    Enumeration<String> en;
    if (fo != null) {
        for (FileObject o : fo.getChildren()) {
            en = o.getAttributes();
            while (en.hasMoreElements()) {
                String attr = en.nextElement();
                boolean enable = false;
                final String prefix = "property-"; // NOI18N
                if (attr.startsWith(prefix)) {
                    attr = attr.substring(prefix.length());
                    if (System.getProperty(attr) != null) {
                        enable = true;
                    }
                } else {
                    final String config = "config-"; // NOI18N
                    if (attr.startsWith(config)) {
                        attr = attr.substring(config.length());
                        FileObject configFile = FileUtil.getConfigFile(attr);
                        if (configFile != null) {
                            if (!configFile.isFolder() || configFile.getChildren().length > 0) {
                                enable = true;
                            }
                        }
                    }
                }

                if (enable) {
                    Lookup l = Lookups.forPath(registry.getPath()+"/Actions"); // NOI18N
                    for (Lookup.Item<Action> item : l.lookupResult(Action.class).allItems()) {
                        if (item.getId().contains(o.getName())) {
                            Action a = item.getInstance();
                            a.actionPerformed(new ActionEvent(getInstance(), 0, "noui")); // NOI18N
                        }
                    }
                }
            }
        }
    }
}
 
Example 18
Source File: RecognizeInstanceFilesTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testOrderingAttributes() throws Exception {
    LOG.info("creating instances");
    
    FileObject inst = FileUtil.createData(root, "inst/ordering/X.instance");
    inst.setAttribute("instanceCreate", Long.valueOf(1000));
    FileObject inst2 = FileUtil.createData(root, "inst/ordering/A.instance");
    inst2.setAttribute("instanceCreate", Long.valueOf(500));
    FileObject inst3 = FileUtil.createData(root, "inst/ordering/B.instance");
    inst3.setAttribute("instanceCreate", Long.valueOf(1500));
    FileObject inst4 = FileUtil.createData(root, "inst/ordering/C.instance");
    inst4.setAttribute("instanceCreate", Long.valueOf(700));
    
    LOG.info("Adding attributes to parrent");
    FileObject parent = inst.getParent();
    parent.setAttribute("A.instance/C.instance", Boolean.TRUE);
    parent.setAttribute("C.instance/X.instance", Boolean.TRUE);
    parent.setAttribute("X.instance/B.instance", Boolean.TRUE);
    
    
    LOG.info("About to create lookup");
    Lookup l = Lookups.forPath("inst/ordering");
    LOG.info("querying lookup");
    Collection<? extends Long> lngAll = l.lookupAll(Long.class);
    assertEquals(4, lngAll.size());
    Iterator<? extends Long> lng = lngAll.iterator();
    LOG.info("checking results");
    
    assertEquals(Long.valueOf(500), lng.next());
    assertEquals(Long.valueOf(700), lng.next());
    assertEquals(Long.valueOf(1000), lng.next());
    assertEquals(Long.valueOf(1500), lng.next());
    
    LOG.info("Order is correct");

    Iterator<? extends Lookup.Item<Long>> items = l.lookupResult(Long.class).allItems().iterator();
    
    LOG.info("Checking IDs");
    assertEquals("inst/ordering/A", items.next().getId());
    assertEquals("inst/ordering/C", items.next().getId());
    assertEquals("inst/ordering/X", items.next().getId());
    assertEquals("inst/ordering/B", items.next().getId());
    
    LOG.info("Ids ok");
}
 
Example 19
Source File: LookupProviderSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public DelegatingLookupImpl(Lookup base, String path) {
    this(base, Lookups.forPath(path), path);
}
 
Example 20
Source File: ServerRegistry.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private ServerRegistry(String path, boolean cloud) {
    this.path = path;
    this.cloud = cloud;
    lookup = Lookups.forPath(path);
    result = lookup.lookupResult(ServerInstanceProvider.class);
}