Java Code Examples for org.openide.util.Lookup#lookupResult()

The following examples show how to use org.openide.util.Lookup#lookupResult() . 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: FolderLookupBrokenListenersDontPreventQueriesTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@RandomlyFails // NB-Core-Build #2892
public void testIssue163315() throws Exception {
    FileObject ioe = FileUtil.createData(fo, "java-io-IOException.instance");
    FileObject iae = FileUtil.createData(fo, "java-lang-IllegalArgumentException.instance");

    @SuppressWarnings("deprecation")
    Lookup lkp = new FolderLookup(DataFolder.findFolder(fo)).getLookup();
    res = lkp.lookupResult(Exception.class);
    assertEquals("Two items found", 2, res.allInstances().size());
    res.addLookupListener(this);

    FileObject ise = FileUtil.createData(fo, "java-lang-IllegalStateException.instance");
    assertEquals("Three now", 3, res.allInstances().size());

    FileObject npe = FileUtil.createData(fo, "java-lang-NullPointerException.instance");
    assertEquals("Four now", 4, res.allInstances().size());

    if (listenerVisited == 0) {
        fail("Listener shall be notified at least once, well only once");
    }
}
 
Example 2
Source File: FolderLookupTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void checkTheLookupForSubfolders (Lookup lookup, DataFolder folder) throws Exception {
    addListener(lookup);

    Class toFind = java.awt.Component.class;
    Class toCreate = javax.swing.JButton.class;

    Lookup.Result res = lookup.lookupResult(toFind);
    assertEquals("no Component's in " + res.allInstances(), 0, res.allInstances().size());

    DataObject obj = InstanceDataObject.create (folder, "Test", toCreate);
    assertNotNull(obj.getPrimaryFile() + " not found",
        folder.getPrimaryFile().getFileSystem().findResource(obj.getPrimaryFile().getPath()));
    Collection all = res.allInstances();
    assertEquals("just one Component in " + all, 1, all.size());

    DataFolder subfolder = DataFolder.create(folder, "BB");
    assertNotNull(subfolder.getPrimaryFile() + " not found",
        folder.getPrimaryFile().getFileSystem().findResource(subfolder.getPrimaryFile().getPath()));

    obj = InstanceDataObject.create (subfolder, "Test", toCreate);
    assertNotNull(obj.getPrimaryFile() + " not found",
        folder.getPrimaryFile().getFileSystem().findResource(obj.getPrimaryFile().getPath()));
    assertEquals("now two Component's in " + res.allInstances(), 2, res.allInstances().size());
}
 
Example 3
Source File: SyntaxHighlighting.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * @param innerLanguage
 * @param mimePath note it may start with mimeTypeForOptions
 */
public FCSInfo(String mimePath, Language<T> innerLanguage) {
    this.innerLanguage = innerLanguage;
    this.mimePath = mimePath;
    this.listeners = new ListenerList<ChangeListener>();
    Lookup lookup = MimeLookup.getLookup("text/textmate");
    result = lookup.lookupResult(FontColorSettings.class);
    // Do not listen on font color settings changes in tests
    // since "random" lookup events translate into highlight change events
    // that are monitored by tests and so the tests may then fail
    if (TEST_FALLBACK_COLORING == null) {
        result.addLookupListener(WeakListeners.create(LookupListener.class, this, result));
    }
    updateFCS();
}
 
Example 4
Source File: DetachPixelGeoCodingAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public DetachPixelGeoCodingAction(Lookup lkp) {
    super(Bundle.CTL_DetachPixelGeoCodingActionText());
    this.lookup = lkp;
    Lookup.Result<ProductNode> lkpContext = lkp.lookupResult(ProductNode.class);
    lkpContext.addLookupListener(WeakListeners.create(LookupListener.class, this, lkpContext));
    putValue(Action.SHORT_DESCRIPTION, "Detach a pixel based geo-coding from the selected product");
    setEnableState();
}
 
Example 5
Source File: TasksNavigationPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void panelActivated(Lookup context) {
    getNavigatorUI().showWaitNode();
    selection = context.lookupResult(DataObject.class);
    selection.addLookupListener(selectionListener);
    selectionListener.resultChanged(null);
}
 
Example 6
Source File: SearchMetadataAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public SearchMetadataAction(Lookup lkp) {
    super(Bundle.CTL_SearchMetadataAction_MenuText());
    this.lkp = lkp;
    Lookup.Result<ProductNode> lkpContext = lkp.lookupResult(ProductNode.class);
    lkpContext.addLookupListener(WeakListeners.create(LookupListener.class, this, lkpContext));
    setEnableState();
    putValue(Action.SHORT_DESCRIPTION, Bundle.CTL_SearchMetadataAction_ShortDescription());
}
 
Example 7
Source File: AbstractLookupExecutorTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates an lookup for given lookup. This class just returns 
 * the object passed in, but subclasses can be different.
 * @param lookup in lookup
 * @return a lookup to use
 */
@Override
public Lookup createLookup (Lookup lookup) {
    res = lookup.lookupResult(Object.class);
    res.addLookupListener(this);
    return lookup;
}
 
Example 8
Source File: LanguagesNavigator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void panelActivated (Lookup context) {
    getComponent ();
    Result<DataObject> result = context.<DataObject>lookupResult (DataObject.class);
    DataObject dataObject = result.allInstances ().iterator ().next ();
    
    if (lookupListener != null)
        lookupListener.remove ();
    lookupListener = new MyLookupListener (result);
    
    setDataObject (dataObject);
}
 
Example 9
Source File: ImportVectorDataNodeFromCsvAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public ImportVectorDataNodeFromCsvAction(Lookup lookup) {
    this.lookup = lookup;
    result = lookup.lookupResult(Product.class);
    result.addLookupListener(
            WeakListeners.create(LookupListener.class, this, result));
    setEnableState();
    setHelpId(Bundle.CTL_ImportVectorDataNodeFromCsvActionHelp());
    putValue(Action.NAME, Bundle.CTL_ImportVectorDataNodeFromCsvActionText());
    putValue(Action.SHORT_DESCRIPTION, Bundle.CTL_ImportVectorDataNodeFromCsvActionDescription());
}
 
Example 10
Source File: ConvertComputedBandIntoBandAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public ConvertComputedBandIntoBandAction(Lookup lookup) {
    super(Bundle.CTL_ConvertComputedBandIntoBandAction_MenuText());
    this.lookup = lookup;
    vbResult = lookup.lookupResult(VirtualBand.class);
    vbResult.addLookupListener(WeakListeners.create(LookupListener.class, this, vbResult));
    fbResult = lookup.lookupResult(FilterBand.class);
    fbResult.addLookupListener(WeakListeners.create(LookupListener.class, this, fbResult));
    setEnableState();
}
 
Example 11
Source File: SnippetNavigationPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void panelActivated(Lookup context) {
    lkp = context.lookupResult(FileObject.class);
    lkp.addLookupListener(lookupL);
    Collection<? extends FileObject> l = lkp.allInstances();
    FileObject file = l.isEmpty()? null : l.iterator().next();
    navigateToFile(file);
    this.context = context;
    INSTANCE = this;
}
 
Example 12
Source File: LinearTodBAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public LinearTodBAction(Lookup lkp) {
    this.lkp = lkp;
    Lookup.Result<ProductNode> lkpContext = lkp.lookupResult(ProductNode.class);
    lkpContext.addLookupListener(WeakListeners.create(LookupListener.class, this, lkpContext));
    setEnableState();

    putValue(NAME, Bundle.CTL_LinearTodBAction_Text());
    putValue(SHORT_DESCRIPTION, Bundle.CTL_LinearTodBAction_Description());
}
 
Example 13
Source File: FilterNodeTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testBuggyIsWrongInFavoritesIssue119727() {
    class ProjectFilterNode extends FilterNode {
        public ProjectFilterNode (Node node, org.openide.nodes.Children children) {
            super (node, children);
        }
    }
    
    CookieSet set = CookieSet.createGeneric(null);
    
    Node pfn = new AbstractNode(Children.LEAF, set.getLookup());
    FilterNode n = new ProjectFilterNode(pfn, Children.LEAF);

    
    Lookup contextLookup = n.getLookup();
    Object o;
    
    o = contextLookup.lookup(ProjectFilterNode.class);
    assertEquals("found self", n, o);
    
    o = contextLookup.lookup(n.getClass());
    assertEquals("found sefl2", n, o);
    
    o = contextLookup.lookup(Node.class);
    assertEquals("found node", n, o);
    
    Result<Node> res = contextLookup.lookupResult(Node.class);
    Collection<? extends Node> all = res.allInstances();
    assertEquals("One found: " + all, 1, all.size());
    assertEquals("It is the filter node", n, all.iterator().next());
}
 
Example 14
Source File: ComputeMaskAreaAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public ComputeMaskAreaAction(Lookup lookup) {

        super(Bundle.CTL_ComputeMaskAreaAction_MenuText());
        this.lookup = lookup;
        result = lookup.lookupResult(ProductSceneView.class);
        result.addLookupListener(WeakListeners.create(LookupListener.class, this, result));
        setEnableState();
    }
 
Example 15
Source File: FoldViewFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public FoldViewFactory(View documentView) {
    super(documentView);
    foldHierarchy = FoldHierarchy.get(textComponent());
    // the view factory may get eventually GCed, but the FoldHierarchy can survive, snce it is tied to the component.
    weakL = WeakListeners.create(FoldHierarchyListener.class, this, foldHierarchy);
    foldHierarchy.addFoldHierarchyListener(weakL);
    // Go through folds and search for collapsed fold.
    foldHierarchy.lock();
    try {
        @SuppressWarnings("unchecked")
        Iterator<Fold> it = FoldUtilities.collapsedFoldIterator(foldHierarchy, 0, Integer.MAX_VALUE);
        collapsedFoldEncountered = it.hasNext();
    } finally {
        foldHierarchy.unlock();
    }

    displayAllFoldsExpanded = Boolean.TRUE.equals(textComponent().getClientProperty(DISPLAY_ALL_FOLDS_EXPANDED_PROPERTY));
    
    String mime = DocumentUtilities.getMimeType(document());
    
    Lookup lkp = MimeLookup.getLookup(mime);
    colorSource = lkp.lookupResult(FontColorSettings.class);
    colorSource.addLookupListener(WeakListeners.create(LookupListener.class, this, colorSource));
    colorSettings = (FontColorSettings)colorSource.allInstances().iterator().next();
    prefs = lkp.lookup(Preferences.class);
    prefs.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, this, prefs));
    
    initViewFlags();
}
 
Example 16
Source File: QuickSearchProvider.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private Iterable<? extends Lookup.Item<OptionsCategory>> getODCategories() {
    Lookup lookup = Lookups.forPath(CategoryModel.OD_LAYER_FOLDER_NAME);
    Lookup.Result<OptionsCategory> result = lookup.lookupResult(OptionsCategory.class);
    return result.allItems();
}
 
Example 17
Source File: LookupProviderSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
SourcesImpl(Lookup lookup) {
    delegates = lookup.lookupResult(Sources.class);
    delegates.addLookupListener(this);
}
 
Example 18
Source File: GlobalManager.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private GlobalManager(Lookup lookup) {
    this.listeners = new HashMap<Object,Set<GeneralAction.BaseDelAction>>();
    this.result = lookup.lookupResult(ActionMap.class);
    result.addLookupListener(this);
    resultChanged(null);
}
 
Example 19
Source File: ContextAction.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private void init(Lookup context) {
    this.context = context;
    result = context.lookupResult(contextClass());
    result.addLookupListener(this);
    resultChanged(null);
}
 
Example 20
Source File: LookupProviderSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
private MergedActionProvider(final Lookup lkp) {
    this.lkpResult = lkp.lookupResult(ActionProvider.class);
    this.lkpResult.addLookupListener(this);
}