本文整理汇总了Java中org.openide.util.Lookup.Result方法的典型用法代码示例。如果您正苦于以下问题:Java Lookup.Result方法的具体用法?Java Lookup.Result怎么用?Java Lookup.Result使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.util.Lookup
的用法示例。
在下文中一共展示了Lookup.Result方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSetPairsFire
import org.openide.util.Lookup; //导入方法依赖的package包/类
/** Checks whether setPairs fires correct events.
*/
public void testSetPairsFire () {
// test setPairs method
List<Object> li = new ArrayList<Object>();
li.addAll (Arrays.asList (INSTANCES));
ic.set (li, null);
Lookup.Result<Integer> res = lookup.lookupResult(Integer.class);
Iterator<?> all = res.allInstances().iterator();
checkIterator ("Integer is not there", all, Collections.nCopies (1, INSTANCES[0]));
// change the pairs
LL listener = new LL (res);
res.addLookupListener (listener);
List<Object> l2 = new ArrayList<Object>(li);
l2.remove (INSTANCES[0]);
ic.set (l2, null);
all = lookup.lookupAll(Object.class).iterator();
checkIterator ("The removed integer is not noticed", all, l2);
if (listener.getCount () != 1) {
fail ("Nothing has not been fired");
}
}
示例2: getModelSourceFromSystemWideCatalog
import org.openide.util.Lookup; //导入方法依赖的package包/类
private ModelSource getModelSourceFromSystemWideCatalog(URI locationURI,
ModelSource modelSourceOfSourceDocument) {
if( locationURI == null)
return null;
try {
Lookup.Template templ = new Lookup.Template(CatalogModel.class);
Lookup.Result res = Lookup.getDefault().lookup(templ);
Collection impls = res.allInstances();
for(Object obj : impls){
CatalogModel cm = (CatalogModel) obj;
return cm.getModelSource(locationURI,
modelSourceOfSourceDocument);
}
} catch (CatalogModelException ex) {
//return null
}
return null;
}
示例3: listFromResult
import org.openide.util.Lookup; //导入方法依赖的package包/类
private <T> List<? extends T> listFromResult(Lookup.Result<T> result) {
Collection<? extends T> col = result.allInstances();
Collection<T> tmp = new LinkedHashSet<T>(col);
if (tmp.size() != col.size()) {
Collection<T> nt = new ArrayList<T>(tmp.size());
nt.addAll(tmp);
col = nt;
}
List<? extends T> all;
if (col instanceof List) {
all = (List<? extends T>)col;
} else {
ArrayList<T> arr = new ArrayList<T>();
arr.addAll(col);
all = arr;
}
return all;
}
示例4: getTags
import org.openide.util.Lookup; //导入方法依赖的package包/类
public java.lang.String[] getTags () {
ArrayList<String> list = new ArrayList<String> (6);
Lookup.Result<org.openide.awt.HtmlBrowser.Factory> r = Lookup.getDefault().lookupResult(org.openide.awt.HtmlBrowser.Factory.class);
for (Lookup.Item<org.openide.awt.HtmlBrowser.Factory> i: r.allItems()) {
list.add(i.getDisplayName());
}
// PENDING need to get rid of this filtering
FileObject fo = FileUtil.getConfigFile (BROWSER_FOLDER);
if (fo != null) {
DataFolder folder = DataFolder.findFolder (fo);
DataObject [] dobjs = folder.getChildren ();
for (int i = 0; i<dobjs.length; i++) {
// Must not be hidden and have to provide instances (we assume instance is HtmlBrowser.Factory)
if (Boolean.TRUE.equals(dobjs[i].getPrimaryFile().getAttribute(EA_HIDDEN)) ||
dobjs[i].getCookie(InstanceCookie.class) == null) {
FileObject fo2 = dobjs[i].getPrimaryFile();
String n = fo2.getName();
try {
n = fo2.getFileSystem().getDecorator().annotateName(n, dobjs[i].files());
} catch (FileStateInvalidException e) {
// Never mind.
}
list.remove(n);
}
}
}
String[] retValue = new String[list.size ()];
list.toArray (retValue);
return retValue;
}
示例5: beforeLookup
import org.openide.util.Lookup; //导入方法依赖的package包/类
@Override
protected void beforeLookup (org.openide.util.Lookup.Template template) {
super.beforeLookup (template);
if (allQueries != null && in.get () == null) {
in.set (this);
Lookup.Result res = lookup (template);
allQueries.add (res);
in.set (null);
}
}
示例6: doTestNodes
import org.openide.util.Lookup; //导入方法依赖的package包/类
/** Test to find nodes.
*/
private <T> void doTestNodes(Node[] arr, Class<T> c, int cnt) {
LOG.fine("setActivatedNodes: " + arr);
if (arr != null) {
top.setActivatedNodes(arr);
}
assertNotNull("At least one node is registered", lookup.lookup(c));
LOG.fine("before lookup");
Lookup.Result<T> res = lookup.lookup(new Lookup.Template<T>(c));
Collection<? extends Lookup.Item<T>> coll = res.allItems();
LOG.fine("after lookup");
assertEquals("Two registered: " + coll, cnt, coll.size());
}
示例7: getTypesResult
import org.openide.util.Lookup; //导入方法依赖的package包/类
/** Result containing all current services. */
private Lookup.Result<ServiceType> getTypesResult() {
boolean init = false;
synchronized (this) {
if (allTypes == null) {
allTypes = Lookup.getDefault().lookupResult(ServiceType.class);
allTypes.addLookupListener(this);
init = true;
}
}
if (init) resultChanged(null);
return allTypes;
}
示例8: collectIndexerFactoriesRegisteredForAllLanguages
import org.openide.util.Lookup; //导入方法依赖的package包/类
/**
* This method should not be called when holding any lock since it calls
* Lookup.Result.allInstances which can block.
* @param factories - non null map for collecting results
*/
private void collectIndexerFactoriesRegisteredForAllLanguages(Map<T, Set<String>> factories) {
Lookup.Result<T> r = tracker.getLookupData(ALL_MIME_TYPES);
for (T factory : r.allInstances()) {
Set<String> mimeTypes = factories.get(factory);
if (mimeTypes == null) {
mimeTypes = new HashSet<String>();
mimeTypes.add(ALL_MIME_TYPES);
factories.put(factory, mimeTypes);
} // else the factory is already in the map (this should not happen unless ill configured in the layer)
}
}
示例9: testLookupListener
import org.openide.util.Lookup; //导入方法依赖的package包/类
/** Test of firing events. */
public void testLookupListener() {
Object inst = 10;
Lookup.Result<?> res = lookup.lookupResult(inst.getClass());
res.allInstances ();
LL listener = new LL(res);
res.addLookupListener(listener);
ic.add(inst);
if (listener.getCount() == 0) {
fail("None event fired during NbLookup.addPair()");
}
ic.remove(inst);
if (listener.getCount() == 0) {
fail("None event fired during NbLookup.removePair()");
}
ic.add(inst);
if (listener.getCount() == 0) {
fail("None event fired during second NbLookup.addPair()");
}
ic.remove(inst);
if (listener.getCount() == 0) {
fail("None event fired during second NbLookup.removePair()");
}
}
示例10: isEnabled
import org.openide.util.Lookup; //导入方法依赖的package包/类
/** Checks whether a type is enabled.
*/
public <T> boolean isEnabled(Class<T> type, ContextSelection selectMode, ContextAction.Performer<? super T> enabler) {
Lookup.Result<T> result = findResult(type);
boolean e = isEnabledOnData(result, type, selectMode);
if (e && enabler != null) {
e = enabler.enabled(listFromResult(result));
}
return e;
}
示例11: registerLookupListenerAndAddSomething
import org.openide.util.Lookup; //导入方法依赖的package包/类
private void registerLookupListenerAndAddSomething(boolean useProxy, boolean callAllInstances, boolean inheritanceTree) {
called = false;
InstanceContent aInstanceContent = new InstanceContent();
Storage<?> s = inheritanceTree ? new InheritanceTree() : new ArrayStorage();
Lookup aLookup = new AbstractLookup(aInstanceContent, s);
if (useProxy) {
aLookup = new ProxyLookup(aLookup);
}
Lookup.Result<ObjectInLookup> result = aLookup.lookupResult(ObjectInLookup.class);
if (callAllInstances) {
result.allInstances(); // TO GET SUCCESS
}
result.addLookupListener(new LookupListener() {
public void resultChanged(LookupEvent ev) {
Lookup.Result aResult = (Lookup.Result) ev.getSource();
Collection c = aResult.allInstances();
if (!c.isEmpty()) {
called = true;
}
}
});
aInstanceContent.set(Collections.singleton(
new ObjectInLookup("Set Object in Lookup)")), null);
Assert.assertTrue("Listener was notified", called);
}
示例12: lookup
import org.openide.util.Lookup; //导入方法依赖的package包/类
public Lookup.Result lookup(Lookup.Template template) {
if (template.getType() == ActionMap.class || (template.getId() != null && template.getId().equals("javax.swing.ActionMap"))) {
return initial.lookup(template);
}
Lookup.Result retValue;
retValue = proxy.lookup(template);
retValue = new ExclusionResult(retValue);
return retValue;
}
示例13: updateLookups
import org.openide.util.Lookup; //导入方法依赖的package包/类
/** Extracts activated nodes from a top component and
* returns their lookups.
*/
public void updateLookups(Node[] arr) {
if (arr == null) {
arr = new Node[0];
}
Lookup[] lookups = new Lookup[arr.length];
Map<Lookup, Lookup.Result> copy;
synchronized (this) {
if (attachedTo == null) {
copy = Collections.<Lookup, Lookup.Result>emptyMap();
} else {
copy = new HashMap<Lookup, Lookup.Result>(attachedTo);
}
}
for (int i = 0; i < arr.length; i++) {
lookups[i] = arr[i].getLookup();
if (copy != null) {
// node arr[i] remains there, so do not remove it
copy.remove(arr[i]);
}
}
for (Iterator<Lookup.Result> it = copy.values().iterator(); it.hasNext();) {
Lookup.Result res = it.next();
res.removeLookupListener(listener);
}
synchronized (this) {
attachedTo = null;
}
setLookups(new Lookup[] { new NoNodeLookup(new ProxyLookup(lookups), arr), Lookups.fixed((Object[])arr), actionMap, });
}
示例14: resultChanged
import org.openide.util.Lookup; //导入方法依赖的package包/类
@Override
public final void resultChanged(LookupEvent ev) {
PageInspector pageInspector = PageInspector.getDefault();
if (pageInspector != null) {
Lookup.Result lookupResult = (Lookup.Result) ev.getSource();
lookupResult.removeLookupListener(this);
pageInspector.addPropertyChangeListener(this);
}
}
示例15: testRemovingMimePath
import org.openide.util.Lookup; //导入方法依赖的package包/类
public void testRemovingMimePath() throws Exception {
// Create the mime path folders and add some instance
TestUtilities.createFile(getWorkDir(), "Editors/text/x-jsp/text/x-java/org-netbeans-modules-editor-mimelookup-impl-DummySettingImpl.instance");
TestUtilities.sleepForWhile();
// Create lookup over an existing mime path
Lookup lookup = new SwitchLookup(MimePath.parse("text/x-jsp/text/x-java"));
Lookup.Result result = lookup.lookupResult(DummySetting.class);
L listener = new L();
result.addLookupListener(listener);
Collection instances = result.allInstances();
assertEquals("There should be no change events", 0, listener.resultChangedCnt);
assertEquals("Wrong number of instances", 1, instances.size());
assertEquals("Wrong instance", DummySettingImpl.class, instances.iterator().next().getClass());
// Delete the mime path folder
TestUtilities.deleteFile(getWorkDir(), "Editors/text/x-jsp/text");
TestUtilities.sleepForWhile();
// Lookup the instances again
instances = lookup.lookupAll(DummySetting.class);
assertEquals("Wrong number of change events", 1, listener.resultChangedCnt);
assertEquals("Wrong number of instances", 0, instances.size());
}