Java Code Examples for org.openide.util.Lookup#Template

The following examples show how to use org.openide.util.Lookup#Template . 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: InheritanceTree.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public <T> Lookup.Result<T> findResult(Lookup.Template<T> t) {
    if (reg == null) {
        return null;
    }
    ReferenceToResult prev = reg.get(t.getType());
    if (prev != null) {
        AbstractLookup.ReferenceIterator it = new AbstractLookup.ReferenceIterator(prev);
        while (it.next()) {
            if (it.current().template.equals(t)) {
                return (Lookup.Result<T>) it.current().getResult();
            }
        }
    }
    return null;
}
 
Example 2
Source File: FilterNode.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private FilterNode(Filter filter, InstanceContent content) {
    super(Children.LEAF, new AbstractLookup(content));
    content.add(filter);

    content.add(filter.getEditor());
    this.filter = filter;
    filter.getChangedEvent().addListener(new ChangedListener<Filter>() {

        public void changed(Filter source) {
            update();
        }
    });

    update();

    Lookup.Template<FilterChain> tpl = new Lookup.Template<FilterChain>(FilterChain.class);
    result = Utilities.actionsGlobalContext().lookup(tpl);
    result.addLookupListener(this);

    FilterTopComponent.findInstance().getFilterSettingsChangedEvent().addListener(this);
    resultChanged(null);
}
 
Example 3
Source File: AbstractLookup.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static <T> Pair<T> findSmallest(Enumeration<Pair<T>> en, Lookup.Template<T> template, boolean deepCheck) {
    int smallest = InheritanceTree.unsorted(en) ? Integer.MAX_VALUE : Integer.MIN_VALUE;
    Pair<T> res = null;

    while (en.hasMoreElements()) {
        Pair<T> item = en.nextElement();

        if (matches(template, item, deepCheck)) {
            if (smallest == Integer.MIN_VALUE) {
                // ok, sorted enumeration the first that matches is fine
                return item;
            } else {
                // check for the smallest item
                if (smallest > item.getIndex()) {
                    smallest = item.getIndex();
                    res = item;
                }
            }
        }
    }

    return res;
}
 
Example 4
Source File: KomrskaLookupTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public TestLookupManager() {
    Lookup.Template<TestLookupItemA> templateA=
        new Lookup.Template<TestLookupItemA>(TestLookupItemA.class);
    resultA=abstractLookup.lookup(templateA);
    resultA.addLookupListener(listenerA);
    resultA.allInstances().size();
    //
    Lookup.Template<TestLookupItemB> templateB=
        new Lookup.Template<TestLookupItemB>(TestLookupItemB.class);
    resultB=abstractLookup.lookup(templateB);
    resultB.addLookupListener(listenerB);
    resultB.allInstances().size();
    // WORKAROUND
    // instanceContent.add(Boolean.TRUE);
}
 
Example 5
Source File: ScannerList.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Lookup.Result<T> initLookup() {
    Lookup lkp = Lookups.forPath( SCANNER_LIST_PATH );
    
    Lookup.Template<T> template = new Lookup.Template<T>( clazz );
    Lookup.Result<T> res = lkp.lookup( template );
    return res;
}
 
Example 6
Source File: ExcludingLookupTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void doBasicFilteringTest (Class theFilter, Class theQuery, int numberOfExcpectedEventsAfterOneChange) throws Exception {
    Lookup lookup = Lookups.exclude (this.instanceLookup, new Class[] { theFilter });
    Lookup.Template t = new Lookup.Template (theQuery);
    Lookup.Result res = lookup.lookup (t);
    
    LL ll = new LL ();
    res.addLookupListener (ll);
    assertEquals ("Nothing is there", 0, res.allItems ().size ());
    
    Object inst = new Integer (3);
    ic.add (inst);
    
    assertEquals ("Filtered out", null, lookup.lookup (theQuery));
    assertEquals ("Filtered out2", null, lookup.lookupItem (t));
    assertEquals ("Nothing is there - 2", 0, res.allItems ().size ());
    assertEquals ("Nothing is there - 2a", 0, res.allInstances ().size ());
    assertEquals ("Nothing is there - 2b", 0, res.allClasses ().size ());
    assertEquals ("Right # of events", numberOfExcpectedEventsAfterOneChange, ll.getCount ());
    
    ic.remove (inst);
    assertEquals ("Filtered out3", null, lookup.lookupItem (t));
    assertEquals ("Nothing is there - 3", 0, res.allItems ().size ());
    assertEquals ("Nothing is there - 3a", 0, res.allInstances ().size ());
    assertEquals ("Nothing is there - 3b", 0, res.allClasses ().size ());
    assertEquals ("Of course it is not there", null, lookup.lookup (theQuery));
    assertEquals ("Right # of events", numberOfExcpectedEventsAfterOneChange, ll.getCount ());
    
}
 
Example 7
Source File: SaveAsAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void refreshEnabled() {
    if (lkpInfo == null) {
        //The thing we want to listen for the presence or absence of
        //on the global selection
        Lookup.Template<SaveAsCapable> tpl = new Lookup.Template<SaveAsCapable>(SaveAsCapable.class);
        lkpInfo = context.lookup (tpl);
    }
    
    TopComponent tc = TopComponent.getRegistry().getActivated();
    boolean isEditorWindowActivated = null != tc && WindowManager.getDefault().isEditorTopComponent(tc);
    setEnabled(null != lkpInfo && lkpInfo.allItems().size() != 0 && isEditorWindowActivated);
    isDirty = false;
}
 
Example 8
Source File: AbstractLookupBaseHid.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testModificationArePreventedWhenDoingModificationsResultAndItem () throws Exception {
    BrokenPair broken = new BrokenPair (false, true);
    ic.addPair (broken);
    
    Lookup.Template<BrokenPair> templ = new Lookup.Template<BrokenPair>(BrokenPair.class);
    Collection<? extends BrokenPair> c = lookup.lookup(templ).allInstances();
    assertEquals ("One item", 1, c.size ());
    assertEquals ("Broken is found again", broken, c.iterator().next ());
    
    Object item = lookup.lookupItem (templ);
    assertEquals ("Broken is found", broken, item);
}
 
Example 9
Source File: ControlFlowTopComponent.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void componentOpened() {
    Lookup.Template tpl = new Lookup.Template(Object.class);
    result = Utilities.actionsGlobalContext().lookup(tpl);
    result.addLookupListener(this);
}
 
Example 10
Source File: SwitchLookup.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public <T> Lookup.Result<T> lookup(Lookup.Template<T> template) {
    return findLookup(template.getType()).lookup(template);
}
 
Example 11
Source File: ScanningScopeList.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private Lookup.Result<TaskScanningScope> initLookup() {
    Lookup lkp = Lookups.forPath( SCOPE_LIST_PATH );
    Lookup.Template<TaskScanningScope> template = new Lookup.Template<TaskScanningScope>( TaskScanningScope.class );
    Lookup.Result<TaskScanningScope> res = lkp.lookup( template );
    return res;
}
 
Example 12
Source File: FilterTopComponent.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void componentOpened() {
    Lookup.Template<FilterChain> tpl = new Lookup.Template<FilterChain>(FilterChain.class);
    result = Utilities.actionsGlobalContext().lookup(tpl);
    result.addLookupListener(this);
}
 
Example 13
Source File: BytecodeViewTopComponent.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void componentOpened() {
    Lookup.Template tpl = new Lookup.Template(Object.class);
    result = Utilities.actionsGlobalContext().lookup(tpl);
    result.addLookupListener(this);
}
 
Example 14
Source File: ControlFlowTopComponent.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void componentOpened() {
    Lookup.Template tpl = new Lookup.Template(Object.class);
    result = Utilities.actionsGlobalContext().lookup(tpl);
    result.addLookupListener(this);
}
 
Example 15
Source File: FilterTopComponent.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void componentOpened() {
    Lookup.Template<FilterChain> tpl = new Lookup.Template<FilterChain>(FilterChain.class);
    result = Utilities.actionsGlobalContext().lookup(tpl);
    result.addLookupListener(this);
}
 
Example 16
Source File: BytecodeViewTopComponent.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void componentOpened() {
    Lookup.Template tpl = new Lookup.Template(Object.class);
    result = Utilities.actionsGlobalContext().lookup(tpl);
    result.addLookupListener(this);
}
 
Example 17
Source File: ControlFlowTopComponent.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void componentOpened() {
    Lookup.Template tpl = new Lookup.Template(Object.class);
    result = Utilities.actionsGlobalContext().lookup(tpl);
    result.addLookupListener(this);
}
 
Example 18
Source File: FilterTopComponent.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void componentOpened() {
    Lookup.Template<FilterChain> tpl = new Lookup.Template<FilterChain>(FilterChain.class);
    result = Utilities.actionsGlobalContext().lookup(tpl);
    result.addLookupListener(this);
}
 
Example 19
Source File: WaitableResult.java    From netbeans with Apache License 2.0 2 votes vote down vote up
/** Used by proxy results to synchronize before lookup.
 */
protected abstract void beforeLookup(Lookup.Template t);
 
Example 20
Source File: AbstractLookup.java    From netbeans with Apache License 2.0 2 votes vote down vote up
/** Given the provided template, Do cleanup the results.
 * @param templ template of a result(s) that should be checked
 * @return null if all references for this template were cleared or one of them
 */
public ReferenceToResult<?> cleanUpResult(Lookup.Template<?> templ);