本文整理汇总了Java中org.openide.util.Lookup.Template方法的典型用法代码示例。如果您正苦于以下问题:Java Lookup.Template方法的具体用法?Java Lookup.Template怎么用?Java Lookup.Template使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.util.Lookup
的用法示例。
在下文中一共展示了Lookup.Template方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: FilterNode
import org.openide.util.Lookup; //导入方法依赖的package包/类
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>() {
@Override
public void changed(Filter source) {
update();
}
});
update();
Lookup.Template<FilterChain> tpl = new Lookup.Template<>(FilterChain.class);
result = Utilities.actionsGlobalContext().lookup(tpl);
result.addLookupListener(this);
FilterTopComponent.findInstance().getFilterSettingsChangedEvent().addListener(this);
resultChanged(null);
setShortDescription("Double-click to open filter");
}
示例2: testConverting
import org.openide.util.Lookup; //导入方法依赖的package包/类
/**
* Simple tests testing converting lookup.
*/
public void testConverting() {
//
String[] orig = new String[] { TestConvertor.TEST1, TestConvertor.TEST2 };
TestConvertor convertor = new TestConvertor();
Lookup p1 = Lookups.fixed(orig, convertor);
assertNull("Converting from String to Integer - it should not find String in result", p1.lookup(String.class));
assertNotNull(p1.lookup(Integer.class));
assertNotNull(p1.lookup(Integer.class));
assertTrue("Convertor should be called only once.", convertor.getNumberOfConvertCalls() == 1);
Lookup.Template<Integer> t = new Lookup.Template<Integer>(Integer.class);
Lookup.Result<Integer> r = p1.lookup(t);
Collection<? extends Integer> all = r.allInstances();
assertTrue(all.size() == 2);
for (int i : all) {
assertTrue("allInstances contains wrong objects", i == TestConvertor.t1 || i == TestConvertor.t2);
}
}
示例3: getIndentEngine
import org.openide.util.Lookup; //导入方法依赖的package包/类
public static final IndentEngine getIndentEngine(MimePath mimePath) {
IndentEngine eng = null;
Preferences prefs = MimeLookup.getLookup(mimePath).lookup(Preferences.class);
String handle = prefs.get(NbEditorDocument.INDENT_ENGINE, null);
if (handle != null && handle.indexOf('.') == -1) { //NOI18N
// looks like Lookup handle from previous version
Lookup.Template<IndentEngine> query = new Lookup.Template(IndentEngine.class, handle, null);
Collection<? extends IndentEngine> all = Lookup.getDefault().lookup(query).allInstances();
if (!all.isEmpty()) {
eng = all.iterator().next();
}
} else {
eng = (IndentEngine) SettingsConversions.callFactory(prefs, mimePath, NbEditorDocument.INDENT_ENGINE, null);
}
if (eng == null) {
EditorKit kit = MimeLookup.getLookup(mimePath).lookup(EditorKit.class);
Object legacyFormatter = null;
if (kit != null) {
try {
Method createFormatterMethod = kit.getClass().getDeclaredMethod("createFormatter"); //NOI18N
legacyFormatter = createFormatterMethod.invoke(kit);
} catch (Exception e) {
}
}
if (legacyFormatter == null) {
eng = new DefaultIndentEngine();
}
}
return eng;
}
示例4: doFilteringOfSomething
import org.openide.util.Lookup; //导入方法依赖的package包/类
private void doFilteringOfSomething (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 ("Accepted", inst, lookup.lookup (theQuery));
assertNotNull ("Accepted too", lookup.lookupItem (t));
assertEquals ("One is there - 2", 1, res.allItems ().size ());
assertEquals ("One is there - 2a", 1, res.allInstances ().size ());
assertEquals ("One is there - 2b", 1, res.allClasses ().size ());
assertEquals ("Right # of events", numberOfExcpectedEventsAfterOneChange, ll.getCount ());
Object inst2 = new Thread (); // implements Runnable
ic.add (inst2);
assertEquals ("Accepted - 2", inst, lookup.lookup (theQuery));
assertNotNull ("Accepted too -2", lookup.lookupItem (t));
assertEquals ("One is there - 3", 1, res.allItems ().size ());
assertEquals ("One is there - 3a", 1, res.allInstances ().size ());
assertEquals ("One is there - 3b", 1, res.allClasses ().size ());
assertEquals ("Right # of events", 0, 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 ());
}
示例5: testWeCanGetInstanceOfSerializableEvenItIsExcludedIfWeAskForClassNotExtendingIt
import org.openide.util.Lookup; //导入方法依赖的package包/类
public void testWeCanGetInstanceOfSerializableEvenItIsExcludedIfWeAskForClassNotExtendingIt () throws Exception {
Lookup lookup = Lookups.exclude (this.instanceLookup, new Class[] { java.io.Serializable.class });
Lookup.Template t = new Lookup.Template (Object.class);
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 ("Not Filtered out", inst, lookup.lookup (Object.class));
assertEquals ("Not Filtered out2", inst, lookup.lookupItem (t).getInstance ());
assertEquals ("One is there - 2", 1, res.allItems ().size ());
assertEquals ("One is there - 2a", 1, res.allInstances ().size ());
assertEquals ("One is there - 2b", 1, res.allClasses ().size ());
assertEquals ("Right # of events", 1, 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 (Object.class));
assertEquals ("Right # of events", 1, ll.getCount ());
}
示例6: doBasicFilteringTest
import org.openide.util.Lookup; //导入方法依赖的package包/类
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 ());
}
示例7: template
import org.openide.util.Lookup; //导入方法依赖的package包/类
/** A template to use.
*/
protected Lookup.Template<Object> template () {
if (template == null) {
template = new Lookup.Template<Object> (Object.class);
}
return template;
}
示例8: testFindInstanceNotCreatedByYouIssue24986
import org.openide.util.Lookup; //导入方法依赖的package包/类
public void testFindInstanceNotCreatedByYouIssue24986 () throws Exception {
String fsstruct [] = new String [] {
"AA/",
};
TestUtilHid.destroyLocalFileSystem (getName());
FileSystem lfs = TestUtilHid.createLocalFileSystem (getWorkDir(), fsstruct);
FileObject bb = lfs.findResource("/AA");
String inst = "My instnace";
DataFolder folder = DataFolder.findFolder (bb);
FileObject fo = FileUtil.createData (folder.getPrimaryFile (), "test.ser");
FileLock lock = fo.lock ();
ObjectOutputStream oss = new ObjectOutputStream (fo.getOutputStream (lock));
oss.writeObject (inst);
oss.close ();
lock.releaseLock ();
DataObject o = DataObject.find (fo);
assertTrue ("Is IDO: " + o, o instanceof InstanceDataObject);
InstanceDataObject obj = (InstanceDataObject)o;
assertEquals ("The instance is created", inst, obj.instanceCreate ());
assertNotSame ("But is not the same", inst, obj.instanceCreate ());
inst = (String)obj.instanceCreate ();
Lookup lookup = new org.openide.loaders.FolderLookup (folder).getLookup ();
Lookup.Template t = new Lookup.Template (null, null, inst);
Collection found = lookup.lookup (t).allInstances ();
assertEquals ("Lookup finds it as well", 1, found.size ());
assertEquals ("Lookup finds it as well", inst, found.iterator ().next());
}
示例9: initLookup
import org.openide.util.Lookup; //导入方法依赖的package包/类
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;
}
示例10: initLookup
import org.openide.util.Lookup; //导入方法依赖的package包/类
private Lookup.Result<TaskGroup> initLookup() {
Lookup lkp = Lookups.forPath( GROUP_LIST_PATH );
Lookup.Template<TaskGroup> template = new Lookup.Template<TaskGroup>( TaskGroup.class );
Lookup.Result<TaskGroup> res = lkp.lookup( template );
return res;
}
示例11: cleanUpResult
import org.openide.util.Lookup; //导入方法依赖的package包/类
public ReferenceToResult cleanUpResult(Lookup.Template templ) {
collectListeners(null, templ.getType());
return (reg == null) ? null : reg.get(templ.getType());
}
示例12: testNoListenersProxyListener
import org.openide.util.Lookup; //导入方法依赖的package包/类
public void testNoListenersProxyListener () {
ProxyLookup lookup = new ProxyLookup (new Lookup[0]);
class E implements Executor {
Runnable r;
public void execute(Runnable command) {
assertNull("NO previous", r);
r = command;
}
public void perform() {
assertNotNull("We shall have a runnable", r);
r.run();
r = null;
}
}
E executor = new E();
final Lookup.Template<Object> template = new Lookup.Template<Object>(Object.class);
final Object[] IGNORE = {
ProxyLookup.ImmutableInternalData.EMPTY,
ProxyLookup.ImmutableInternalData.EMPTY_ARR,
ActiveQueue.queue(),
Collections.emptyMap(),
Collections.emptyList(),
Collections.emptySet()
};
assertSize("Pretty small", Collections.singleton(lookup), 16, IGNORE);
Lookup.Result<Object> res = lookup.lookup (template);
assertSize("Bigger", Collections.singleton(lookup), 216, IGNORE);
LL ll = new LL ();
res.addLookupListener (ll);
Collection allRes = res.allInstances ();
lookup.setLookups (executor, new Lookup[0]);
if (ll.getCount () != 0) {
fail ("Calling setLookups (emptyarray) fired a change");
}
InstanceContent t = new InstanceContent();
Lookup del = new AbstractLookup (t);
t.add("Ahoj");
lookup.setLookups (executor, new Lookup[] { del });
assertEquals("No change yet", 0, ll.getCount());
executor.perform();
if (ll.getCount () != 1) {
fail ("Changing lookups did not generate an event");
}
lookup.setLookups (executor, new Lookup[] { del });
if (ll.getCount () != 0) {
fail ("Calling setLookups (thesamearray) fired a change");
}
}
示例13: findResult
import org.openide.util.Lookup; //导入方法依赖的package包/类
@Override
public <T> Lookup.Result<T> findResult(Lookup.Template<T> template) {
return delegate.findResult(template);
}
示例14: lookup
import org.openide.util.Lookup; //导入方法依赖的package包/类
public <T> Lookup.Result<T> lookup(Lookup.Template<T> template) {
return findLookup(template.getType()).lookup(template);
}
示例15: beforeLookup
import org.openide.util.Lookup; //导入方法依赖的package包/类
protected void beforeLookup (Lookup.Template t) {
super.beforeLookup (t);
queries.add (t.getType ());
}