Java 类org.openide.util.Lookup.Template 实例源码

项目:incubator-netbeans    文件:MimeLookupPerformanceTest.java   
public void testTemplateLookuping() throws IOException{
    MimePath mp = MimePath.parse("text/x-java/text/html/text/xml");
    Lookup lookup = MimeLookup.getLookup(mp);
    Result result = lookup.lookup(new Template(PopupActions.class));
    Collection col = result.allInstances();
    checkPopupItemPresence(lookup, RenameAction.class, true);
    gc();
    int size = assertSize("", Arrays.asList( new Object[] {lookup} ), 10000000,  getFilter());
    for (int i=0; i<30; i++){
        result = lookup.lookup(new Template(PopupActions.class));
        col = result.allInstances();
        checkPopupItemPresence(lookup, RenameAction.class, true);
    }
    gc();
    assertSize("", size, lookup);
}
项目:incubator-netbeans    文件:NavigatorController.java   
@Override
protected void beforeLookup(Template<?> template) {
    super.beforeLookup(template);

    Lookup[] curNodesLookups;

    synchronized (CUR_NODES_LOCK) {
        curNodesLookups = new Lookup[curNodes.size()];
        int i = 0;
        for (Iterator<? extends Node> it = curNodes.iterator(); it.hasNext(); i++) {
            curNodesLookups[i] = it.next().getLookup();
        }
    }

    setLookups(curNodesLookups);
}
项目:incubator-netbeans    文件:AbstractLookupBaseHid.java   
public void testCompareUsingEquals() {
    Integer i1 = new Integer(10);
    Integer i2 = new Integer(10);
    assertEquals(i1, i2);
    assertNotSame(i1, i2);

    ic.add(i1);

    Template<Integer> t1 = new Lookup.Template<Integer>(Integer.class, null, i1);
    Template<Integer> t2 = new Lookup.Template<Integer>(Integer.class, null, i2);

    Lookup.Result<Integer> r2 = lookup.lookup(t2);
    assertEquals("One item", 1, r2.allInstances().size());
    assertEquals(i1, r2.allInstances().iterator().next());

    Lookup.Result<Integer> r1 = lookup.lookup(t1);

    assertEquals("One item", 1, r1.allInstances().size());
    assertEquals(i1, r1.allInstances().iterator().next());
}
项目:incubator-netbeans    文件:AbstractLookupBaseHid.java   
public void testAfterDeserializationNoQueryIsPeformedOnAlreadyQueriedObjects() throws Exception {
    if (! (lookup instanceof Serializable)) {
        // well this test works only for serializable lookups
        return;
    }

    SerialPair my = new SerialPair ("no");
    ic.addPair (my);

    Lookup.Result res = lookup.lookup (new Lookup.Template (String.class));
    assertEquals ("One instance", 1, res.allInstances().size ());
    assertEquals ("my.instanceOf called once", 1, my.countInstanceOf);

    Lookup serial = (Lookup)reserialize(lookup);

    Lookup.Result r2 = serial.lookup(new Lookup.Template(String.class));

    assertEquals ("One item", 1, r2.allItems ().size ());
    Object one = r2.allItems().iterator().next ();
    assertEquals ("The right class", SerialPair.class, one.getClass());
    SerialPair p = (SerialPair)one;

    assertEquals ("p.instanceOf has not been queried", 0, p.countInstanceOf);
}
项目:incubator-netbeans    文件:AbstractLookupBaseHid.java   
public void testMultipleListeners() {
    Object object = new ImplementationObject();
    ic.add(object);

    Listener[] listeners = new Listener[4];
    Lookup.Result result = lookup.lookup(new Lookup.Template(LookupObject.class));
    for(int i = 0; i < listeners.length; ++i) {
        listeners[i] = new Listener();
        result.addLookupListener(listeners[i]);
    }
    // initialize listening
    result.allItems().toArray();

    ic.remove(object);

    // Apparently, only odd-numbered listeners get called when there are multiple LookupListeners on a result
    //for(int i = 0; i < listeners.length; ++i) {
    //    System.out.println("Listener " + i + ": " + listeners[i].wasCalled());            
    //}
    for(int i = 0; i < listeners.length; ++i) {
        assertTrue("Listener " + i + " called", listeners[i].wasCalled());
    }
}
项目:incubator-netbeans    文件:AbstractLookupBaseHid.java   
protected boolean instanceOf(Class c) { 

    // behaviour gets broken only after deserialization
    if (IN != null && IN.get () == null) {
        try {
            IN.set (this);

            // creation of new result has to survive as well
            Lookup.Result myQuery = running.lookup.lookup (new Lookup.Template (java.awt.List.class));
            Collection all = myQuery.allItems ();
        } finally {
            IN.set (null);
        }
    }

    return c.isAssignableFrom(getType ()); 
}
项目:incubator-netbeans    文件:MetaInfServicesLookupTest.java   
public void testDontCallMeUnderLock() throws Exception {
    final Lookup l = getTestedLookup(c2);
    ProxyLookup pl = new ProxyLookup(l) {
        @Override
        void beforeLookup(boolean call, Template<?> template) {
            super.beforeLookup(call, template);
            assertFalse("Don't hold MetaInfServicesLookup lock", Thread.holdsLock(l));
        }
    };
    Class<?> xface = c1.loadClass("org.foo.Interface");
    Result<?> res = pl.lookupResult(Object.class);
    res.addLookupListener(new LookupListener() {
        @Override
        public void resultChanged(LookupEvent ev) {
        }
    });
    assertTrue("Empty now", res.allItems().isEmpty());

    Object first = l.lookup(xface);
    assertEquals(first, l.lookupAll(xface).iterator().next());
    Object second = pl.lookup(xface);
    assertEquals(first, second);
}
项目:incubator-netbeans    文件:MimePathLookup.java   
/** Creates a new instance of MimePathLookup */
public MimePathLookup(MimePath mimePath) {
    super();

    if (mimePath == null) {
        throw new NullPointerException("Mime path can't be null."); //NOI18N
    }

    this.mimePath = mimePath;
    this.mimePathBanned = mimePath.size() > 0 && mimePath.getMimeType(0).contains("text/base"); //NOI18N

    class R implements Runnable {
        Lookup.Result<MimeDataProvider> dataProviders;
        Lookup.Result<MimeLookupInitializer> mimeInitializers;

        public void run() {
            dataProviders = Lookup.getDefault().lookup(new Lookup.Template<MimeDataProvider>(MimeDataProvider.class));
            dataProviders.addLookupListener(WeakListeners.create(LookupListener.class, MimePathLookup.this, dataProviders));

            mimeInitializers = Lookup.getDefault().lookup(new Lookup.Template<MimeLookupInitializer>(MimeLookupInitializer.class));
            mimeInitializers.addLookupListener(WeakListeners.create(LookupListener.class, MimePathLookup.this, mimeInitializers));
        }
    }
    R r = new R();
    Lookups.executeWith(null, r);
    this.dataProviders = r.dataProviders;
    this.mimeInitializers = r.mimeInitializers;
}
项目:incubator-netbeans    文件:MimePathLookup.java   
@Override
protected void beforeLookup(Template<?> template) {
    synchronized (this) {
        if (!initialized) {
            initialized = true;
            rebuild();
        }
    }
}
项目:incubator-netbeans    文件:ProjectsRootNodeNotRecognizedTest.java   
@Override
protected void beforeLookup(Template<?> template) {
    if (template.getType() == Sources.class) {
        try {
            //state.notifyDeleted();
            projectDirectory.delete();
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
}
项目:incubator-netbeans    文件:IssuesTest.java   
/** 
 * Issues of changes in layer
 */
public void testForChangeInLayer() throws IOException{

    // issue #63338
    // http://www.netbeans.org/issues/show_bug.cgi?id=63338
    // Subj: deadlock during showing annotations
    // fix: deadlock occured in after inproper firing of lookup changed event.
    //      event was fired even in cases, the lookup listener should be quiet.
    MimeLookup lookup = MimeLookup.getMimeLookup("text/jsp"); //NOI18N
    Result result = lookup.lookup(new Template(TestLookupObject.class));
    result.allInstances().size(); // remove this line if issue #60010 is fixed
    LookupListener listener = new LookupListener(){
        public void resultChanged(LookupEvent ev){
            resultChangedCount[0]++;
        }
    };
    result.addLookupListener(listener);

    //simulate module installation, new file will be added
    createFile("Editors/text/jsp/testLookup/org-openide-actions-PasteAction.instance"); //NOI18N        

    checkResultChange(0);

    TestUtilities.deleteFile(getWorkDir(),
            "Editors/text/jsp/testLookup/org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance");

    checkResultChange(1);

    result.removeLookupListener(listener);
    resultChangedCount[0] = 0;
    // end of issue #63338 ------------------------------------------------



}
项目:incubator-netbeans    文件:IssuesTest.java   
/** Issue #72873 
 *  MimeLookup duplicates objects from default mimetype folder
 */
public void testDoubleItems(){
    MimeLookup lookup = MimeLookup.getMimeLookup("text/x-java"); //NOI18N
    Result result = lookup.lookup(new Template(TestLookupObjectTwo.class));
    Collection col = result.allInstances();
    assertTrue(col.size() == 1);

    lookup = MimeLookup.getMimeLookup(""); //NOI18N
    result = lookup.lookup(new Template(TestLookupObjectTwo.class));
    col = result.allInstances();
    assertTrue(col.size() == 1);

}
项目:incubator-netbeans    文件:AbstractTestUtil.java   
/**
 * Switch on all XML modules and returns <code>true</code> if change state of any module else <code>false</code>.
 */
public static boolean switchAllXMLModules(boolean enable) throws Exception {
    boolean result = false;
    Iterator it = Lookup.getDefault().lookup(new Template(ModuleInfo.class)).allInstances().iterator();

    while (it.hasNext()) {
        ModuleInfo mi = (ModuleInfo) it.next();
        if (mi.getCodeNameBase().startsWith("org.netbeans.modules.xml.") && (mi.isEnabled() != enable)) {
            switchModule(mi.getCodeNameBase(), enable);
            result = true;
        }
    }
    return result;
}
项目:incubator-netbeans    文件:AbstractTestUtil.java   
/**
 * Returns module's info or <code>null</null>.
 */
public static ModuleInfo getModuleInfo(String codeName) {
    Iterator it = Lookup.getDefault().lookup(new Template(ModuleInfo.class)).allInstances().iterator();

    while (it.hasNext()) {
        ModuleInfo mi = (ModuleInfo) it.next();
        //            if (mi.getCodeNameBase().equals(codeName) && mi.isEnabled()) {
        if (mi.getCodeNameBase().equals(codeName)) {
            return mi;
        }
    }
    return null;
}
项目:incubator-netbeans    文件:LegacyFormattersProvider.java   
@Override
public Lookup getLookup(final MimePath mimePath) {
    if (mimePath.size() == 1) {
        return new ProxyLookup() {
            private final AtomicBoolean initialized = new AtomicBoolean();
            @Override
            protected void beforeLookup(Template<?> template) {
                super.beforeLookup(template);
                final Class<?> clz = template.getType();
                if (IndentTask.Factory.class.isAssignableFrom(clz) ||
                    ReformatTask.Factory.class.isAssignableFrom(clz) ||
                    TypedTextInterceptor.Factory.class.isAssignableFrom(clz)) {
                    if (!initialized.getAndSet(true)) {
                        final IndentReformatTaskFactoriesProvider provider = IndentReformatTaskFactoriesProvider.get(mimePath);
                        if (provider != null) {
                            final IndentTask.Factory legacyIndenter = provider.getIndentTaskFactory();
                            final ReformatTask.Factory legacyFormatter = provider.getReformatTaskFactory();
                            final TypedTextInterceptor.Factory legacyAutoIndenter = provider.getTypedTextInterceptorFactory();
                            if (LOG.isLoggable(Level.FINE)) {
                                LOG.log(
                                    Level.FINE,
                                    "''{0}'' uses legacyIndenter={1}, legacyFormatter={2}, legacyAutoIndenter={3}",   //NOI18N
                                    new Object[]{
                                        mimePath.getPath(),
                                        legacyIndenter,
                                        legacyFormatter,
                                        legacyAutoIndenter});
                            }
                            setLookups(Lookups.fixed(legacyIndenter, legacyFormatter, legacyAutoIndenter));
                        }
                    }
                }
            }
        };
    }

    return null;
}
项目:incubator-netbeans    文件:PreventNeedlessChangesOfActionMapTest.java   
protected void setUp() throws Exception {
    tc = new TopComponent();
    res = tc.getLookup().lookup(new Lookup.Template<ActionMap> (ActionMap.class));
    assertEquals("One instance", 1, res.allItems().size());

    res.addLookupListener(this);
}
项目:incubator-netbeans    文件:NodeLookup.java   
/** Notifies subclasses that a query is about to be processed.
 * @param template the template
 */
@Override
protected final void beforeLookup(Template template) {
    Class type = template.getType();
    Set<Node> nds = Node.blockEvents();
    try {
        blockingBeforeLookup(type);
    } finally {
        Node.unblockEvents(nds);
    }
}
项目:incubator-netbeans    文件:AbstractLookupBaseHid.java   
public void testBeforeLookupIsCalledToInvalidateCaches() {
    class Before extends ProxyLookup {
        Object toAdd;

        Before() {
            super(instanceLookup);
        }

        @Override
        protected void beforeLookup(Template<?> template) {
            if (toAdd != null) {
                ic.add(toAdd);
                toAdd = null;
            }
        }

    }
    Before before = new Before();

    Lookup query = createLookup(before);

    before.toAdd = Integer.valueOf(10);

    Lookup.Result<Long> res = query.lookupResult(Long.class);
    assertTrue("empty", res.allItems().isEmpty());

    assertNull("beforeLookup called", before.toAdd);

    before.toAdd = Long.valueOf(3L);

    Collection<? extends Lookup.Item<Long>> c = res.allItems();
    assertEquals("There is One: ", 1, c.size());

    assertEquals(Long.valueOf(3L), c.iterator().next().getInstance());
}
项目:incubator-netbeans    文件:AbstractLookupBaseHid.java   
/** Checks search for interface.
 */
public void testSearchForInterface () {
    Lookup.Template<Serializable> t = new Lookup.Template<Serializable>(Serializable.class, null, null);

    assertNull("Nothing to find", lookup.lookupItem (t));

    Serializable s = new Serializable () {};
    ic.add (s);

    Lookup.Item item = lookup.lookupItem (t);
    assertNotNull ("Something found", item);
}
项目:incubator-netbeans    文件:AbstractLookupBaseHid.java   
/** Checks whether the AbstractLookup is guarded against modifications
 * while doing some kind of modification.
 */
public void testModificationArePreventedWhenDoingModifications () throws Exception {
    BrokenPair broken = new BrokenPair (true, false);
    ic.addPair (broken);

    Lookup.Template<BrokenPair> templ = new Lookup.Template<BrokenPair>(BrokenPair.class);
    Lookup.Item<BrokenPair> item = lookup.lookupItem (templ);
    assertEquals ("Broken is found", broken, item);
}
项目:incubator-netbeans    文件:AbstractLookupBaseHid.java   
public void testModificationArePreventedWhenDoingModificationsResult () 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 ());
}
项目:incubator-netbeans    文件:AbstractLookupBaseHid.java   
public void testModificationArePreventedWhenDoingModificationsItemAndResult () throws Exception {
    BrokenPair broken = new BrokenPair (false, true);
    ic.addPair (broken);

    Lookup.Template<BrokenPair> templ = new Lookup.Template<BrokenPair>(BrokenPair.class);
    Lookup.Item<BrokenPair> item = lookup.lookupItem (templ);
    assertEquals ("Broken is found", broken, item);

    Collection<? extends BrokenPair> c = lookup.lookup(templ).allInstances();
    assertEquals ("One item", 1, c.size ());
    assertEquals ("Broken is found again", broken, c.iterator().next ());
}
项目:incubator-netbeans    文件:AbstractLookupBaseHid.java   
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);
}
项目:incubator-netbeans    文件:AbstractLookupBaseHid.java   
/** Test of reorder and item change which used to fail on interfaces.
 */
public void testReoderingIssue13779 () throws Exception {
    LinkedList arr = new LinkedList ();

    class R extends Exception implements Cloneable {
    }
    Object o1 = new R ();
    Object o2 = new R ();
    Object o3 = new R ();

    arr.add (o1);
    arr.add (o2);

    ic.set (arr, null);

    Lookup.Result objectResult = lookup.lookup (new Lookup.Template (Exception.class));
    Lookup.Result interfaceResult = lookup.lookup (new Lookup.Template (Cloneable.class));
    objectResult.allItems ();
    interfaceResult.allItems ();

    LL l1 = new LL (objectResult);
    LL l2 = new LL (interfaceResult);

    objectResult.addLookupListener(l1);
    interfaceResult.addLookupListener(l2);

    arr.addFirst (o3);

    ic.set (arr, null);

    assertEquals ("One change on objects", 1, l1.getCount ());
    assertEquals ("One change on interfaces", 1, l2.getCount ());

    arr.addFirst (new Cloneable () { });
    ic.set (arr, null);

    assertEquals ("No change on objects", 0, l1.getCount ());
    assertEquals ("But one change on interfaces", 1, l2.getCount ());

}
项目:incubator-netbeans    文件:AbstractLookupBaseHid.java   
public void testAWayToGenerateProblem13779 () {
    ic.add (new Integer (1));
    ic.add (new Integer (2));
    ic.add (new Integer (1));
    ic.add (new Integer (2));

    Collection c = lookup.lookup (new Lookup.Template (Integer.class)).allInstances ();
    assertEquals ("There are two objects", 2, c.size ());

}
项目:incubator-netbeans    文件:AbstractSavable.java   
/** Implementation of {@link Savable#save} contract. Calls
 * {@link #handleSave} and {@link #unregister}.
 * 
 * @throws IOException if call to {@link #handleSave} throws IOException
 */
@Override
public final void save() throws IOException {
    Template<AbstractSavable> t = new Template<AbstractSavable>(AbstractSavable.class, null, this);
    for (Savable s : Savable.REGISTRY.lookup(t).allInstances()) {
        if (s == this) {
            handleSave();
            unregister();
            return;
        }
    }
    LOG.log(Level.WARNING, "Savable {0} is not in Savable.REGISTRY! " // NOI18N
            + "Have not you forgotten to call register() in constructor?", getClass()); // NOI18N
}
项目:nb-springboot    文件:GlobalActionContextProxy.java   
/**
 * Replaces the project lookup content.
 *
 * @param project to place in the project lookup.
 */
private void updateProjectLookup(Project project) {
    if (project == null) {
        throw new IllegalArgumentException("project cannot be null.");
    }
    // Add the project if an instance of it is not already in the lookup
    Template<Project> template = new Template<>(Project.class, null, project);
    if (projectLookup != null && projectLookup.lookupItem(template) == null) {
        clearProjectLookup();
        content.add(project);
        logger.log(FINE, "updateProjectLookup: added [{0}] to the proxy lookup.",
                ProjectUtils.getInformation(lastProject).getDisplayName());
    }
}
项目:Joeffice    文件:OfficeUIUtils.java   
/**
 * Retrieves an action instance
 * @param category e.g., "Maps"
 * @param id e.g., "com-emxsys-worldwind-ribbon-actions-ToggleLayerAction"
 * @return the Action instance or null
 * @see http://forums.netbeans.org/topic44790.html
 */
@Deprecated
public static Action getAction(String category, String id) {
    String folder = "Actions/" + category + "/";
    Lookup pathLookup = Lookups.forPath(folder);

    Template<Action> actionTemplate = new Template<>(Action.class, folder + id, null);
    Item<Action> item = pathLookup.lookupItem(actionTemplate);
    if (item != null) {
        return item.getInstance();
    }
    return null;
}
项目:incubator-netbeans    文件:Context.java   
@Override
public <T> Result<T> lookup(Template<T> template) {
    return delegate.lookup(template);
}
项目:incubator-netbeans    文件:MimeLookupPopupItemsChangeTest.java   
/** Testing Base level popup items lookup and sorting */
@RandomlyFails // NB-Core-Build #4599: resultChangedCount is:2 instead of 1
public void testDynamicChangeInPopupFolders() throws Exception {
    final int resultChangedCount[] = new int[1];
    resultChangedCount[0] = 0;

    MimePath mp = MimePath.parse("text/x-java/text/xml/text/html");
    Lookup lookup = getLookup(mp);
    Lookup.Result result = lookup.lookup(new Template(PopupActions.class));
    result.allInstances(); // remove this line if issue #60010 is fixed
    LookupListener listener = new LookupListener(){
        public void resultChanged(LookupEvent ev){
            resultChangedCount[0]++;
        }
    };
    result.addLookupListener(listener);
    PopupActions actions = (PopupActions) lookup.lookup(PopupActions.class);
    assertTrue("PopupActions should be found", actions != null);
    List popupActions = actions.getPopupActions();
    int size = popupActions.size();
    assertTrue("Number of PopupActions found:"+size+" and should be:"+fsstruct.length, size == fsstruct.length);

    //delete RenameAction
    TestUtilities.deleteFile(getWorkDir(),
            "Editors/text/html/Popup/org-openide-actions-RenameAction.instance");
    checkPopupItemPresence(lookup, RenameAction.class, false);

    // check firing the change
    assertTrue(("resultChangedCount is:"+resultChangedCount[0]+" instead of 1"),resultChangedCount[0] == 1);
    resultChangedCount[0] = 0;

    //delete base CutAction
    TestUtilities.deleteFile(getWorkDir(),
            "Editors/Popup/org-openide-actions-CutAction.instance");

    checkPopupItemPresence(lookup, CutAction.class, false);

    // check firing the change
    assertTrue(("resultChangedCount is:"+resultChangedCount[0]+" instead of 1"),resultChangedCount[0] == 1);
    resultChangedCount[0] = 0;

    //simulate module installation, new action will be added
    TestUtilities.createFile(getWorkDir(), 
            "Editors/Popup/org-openide-actions-FindAction.instance"); //NOI18N      

    checkPopupItemPresence(lookup, FindAction.class, true);

    // check firing the change
    assertTrue(("resultChangedCount is:"+resultChangedCount[0]+" instead of 1"),resultChangedCount[0] == 1);
    resultChangedCount[0] = 0;

    //simulate module installation, new action will be added
    TestUtilities.createFile(getWorkDir(), 
            "Editors/text/x-java/text/xml/text/html/Popup/org-openide-actions-ReplaceAction.instance"); //NOI18N      

    checkPopupItemPresence(lookup, ReplaceAction.class, true);

    //ReplaceAction was created in the uppermost folder
    // let's try it is missing in the lower lookup
    mp = MimePath.get(MimePath.get("text/x-java"), "text/xml");
    lookup = getLookup(mp);
    checkPopupItemPresence(lookup, ReplaceAction.class, false);        
    checkPopupItemPresence(lookup, FindAction.class, true);

    // lookup for ReplaceAction in the folder that doesn't exist
    lookup = MimeLookup.getLookup("text/html"); //NOI18N
    checkPopupItemPresence(lookup, ReplaceAction.class, false); 
    // create folder with ReplaceAction
    TestUtilities.createFile(getWorkDir(), 
            "Editors/text/html/Popup/org-openide-actions-ReplaceAction.instance"); //NOI18N      

    checkPopupItemPresence(lookup, ReplaceAction.class, true);

}
项目:incubator-netbeans    文件:Depr_MimeLookupPopupItemsChangeTest.java   
/** Testing Base level popup items lookup and sorting */
@RandomlyFails // NB-Core-Build #3718
public void testDynamicChangeInPopupFolders() throws IOException{
    final int resultChangedCount[] = new int[1];
    resultChangedCount[0] = 0;

    MimeLookup lookup = MimeLookup.getMimeLookup("text/x-java").childLookup("text/xml"). //NOI18N
            childLookup("text/html"); //NOI18N
    Lookup.Result result = lookup.lookup(new Template(PopupActions.class));
    result.allInstances(); // remove this line if issue #60010 is fixed
    LookupListener listener = new LookupListener(){
        public void resultChanged(LookupEvent ev){
            resultChangedCount[0]++;
        }
    };
    result.addLookupListener(listener);
    PopupActions actions = (PopupActions) lookup.lookup(PopupActions.class);
    assertTrue("PopupActions should be found", actions != null);
    List popupActions = actions.getPopupActions();
    int size = popupActions.size();
    assertTrue("Number of PopupActions found:"+size+" and should be:"+fsstruct.length, size == fsstruct.length);

    //delete RenameAction
    TestUtilities.deleteFile(getWorkDir(),
            "Editors/text/html/Popup/org-openide-actions-RenameAction.instance");
    checkPopupItemPresence(lookup, RenameAction.class, false);

    // check firing the change
    assertTrue(("resultChangedCount is:"+resultChangedCount[0]+" instead of 1"),resultChangedCount[0] == 1);
    resultChangedCount[0] = 0;

    //delete base CutAction
    TestUtilities.deleteFile(getWorkDir(),
            "Editors/Popup/org-openide-actions-CutAction.instance");

    checkPopupItemPresence(lookup, CutAction.class, false);

    // check firing the change
    assertTrue(("resultChangedCount is:"+resultChangedCount[0]+" instead of 1"),resultChangedCount[0] == 1);
    resultChangedCount[0] = 0;

    //simulate module installation, new action will be added
    TestUtilities.createFile(getWorkDir(), 
            "Editors/Popup/org-openide-actions-FindAction.instance"); //NOI18N      

    checkPopupItemPresence(lookup, FindAction.class, true);

    // check firing the change
    assertTrue(("resultChangedCount is:"+resultChangedCount[0]+" instead of 1"),resultChangedCount[0] == 1);
    resultChangedCount[0] = 0;

    //simulate module installation, new action will be added
    TestUtilities.createFile(getWorkDir(), 
            "Editors/text/x-java/text/xml/text/html/Popup/org-openide-actions-ReplaceAction.instance"); //NOI18N      

    checkPopupItemPresence(lookup, ReplaceAction.class, true);

    //ReplaceAction was created in the uppermost folder
    // let's try it is missing in the lower lookup
    lookup = MimeLookup.getMimeLookup("text/x-java").childLookup("text/xml"); //NOI18N
    checkPopupItemPresence(lookup, ReplaceAction.class, false);        
    checkPopupItemPresence(lookup, FindAction.class, true);

    // lookup for ReplaceAction in the folder that doesn't exist
    lookup = MimeLookup.getMimeLookup("text/html"); //NOI18N
    checkPopupItemPresence(lookup, ReplaceAction.class, false); 
    // create folder with ReplaceAction
    TestUtilities.createFile(getWorkDir(), 
            "Editors/text/html/Popup/org-openide-actions-ReplaceAction.instance"); //NOI18N

    checkPopupItemPresence(lookup, ReplaceAction.class, true);

}
项目:incubator-netbeans    文件:NbURLStreamHandlerFactoryDeadlockTest.java   
@Override
protected  void beforeLookup(Template<?> template) {
    RequestProcessor.getDefault().post(this).waitFinished();
}
项目:incubator-netbeans    文件:AbstractLookupBaseHid.java   
/** Testing identity of the lookup.
 */
public void testId () {
    Lookup.Template<?> templ;
    int cnt;

    addInstances (INSTANCES);

    Lookup.Result<?> res = lookup.lookupResult(Object.class);
    for (AbstractLookup.Item<?> item : res.allItems()) {

        templ = new Lookup.Template<Object>(null, item.getId(), null);
        cnt = lookup.lookup (templ).allInstances ().size ();
        if (cnt != 1) {
            fail ("Identity lookup failed. Instances = " + cnt);
        }

        templ = makeTemplate(item.getType(), item.getId());
        cnt = lookup.lookup (templ).allInstances ().size ();
        if (cnt != 1) {
            fail ("Identity lookup with type failed. Instances = " + cnt);
        }

        templ = makeTemplate(this.getClass(), item.getId());
        cnt = lookup.lookup (templ).allInstances ().size ();
        if (cnt != 0) {
            fail ("Identity lookup with wrong type failed. Instances = " + cnt);
        }

        templ = new Lookup.Template<Object>(null, null, item.getInstance());
        cnt = lookup.lookup (templ).allInstances ().size ();
        if (cnt != 1) {
            fail ("Instance lookup failed. Instances = " + cnt);
        }

        templ = new Lookup.Template<Object>(null, item.getId(), item.getInstance());
        cnt = lookup.lookup (templ).allInstances ().size ();
        if (cnt != 1) {
            fail ("Instance & identity lookup failed. Instances = " + cnt);
        }

    }
}
项目:incubator-netbeans    文件:AbstractLookupBaseHid.java   
private static <T> Lookup.Template<T> makeTemplate(Class<T> clazz, String id) { // captures type parameter
    return new Lookup.Template<T>(clazz, id, null);
}
项目:btrace.nb    文件:AbstractToolbarAction.java   
public <T> Item<T> lookupItem(Template<T> template) {
    return lookup.lookupItem(template);
}
项目:btrace.nb    文件:AbstractToolbarAction.java   
public <T> Result<T> lookup(Template<T> template) {
    return lookup.lookup(template);
}
项目:btrace.nb    文件:AbstractToolbarAction.java   
public <T> Item<T> lookupItem(Template<T> template) {
    return lookup.lookupItem(template);
}
项目:btrace.nb    文件:AbstractToolbarAction.java   
public <T> Result<T> lookup(Template<T> template) {
    return lookup.lookup(template);
}
项目:JRLib    文件:IconService.java   
private IconService() {
    iconLookup       = Lookup.getDefault();
    providerTemplate = new Template<IconProvider>(IconProvider.class);
    providerResult   = iconLookup.lookup(providerTemplate);
    providers        = providerResult.allInstances();
}
项目:incubator-netbeans    文件:MimeLookup.java   
/**
 * Looks up objects in this mime path lookup.
 *
 * @param template The template describing the objects to look for.
 *
 * @return The search result.
 * @deprecated Use {@link #getLookup(MimePath)} and the methods provided by
 * the ordinary <code>Lookup</code> instance returned.
 */
public <T> Result<T> lookup(Template<T> template) {
    return mimePathLookup.lookup(template);
}