当前位置: 首页>>代码示例>>Java>>正文


Java Lookups类代码示例

本文整理汇总了Java中org.openide.util.lookup.Lookups的典型用法代码示例。如果您正苦于以下问题:Java Lookups类的具体用法?Java Lookups怎么用?Java Lookups使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Lookups类属于org.openide.util.lookup包,在下文中一共展示了Lookups类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUp

import org.openide.util.lookup.Lookups; //导入依赖的package包/类
protected @Override void setUp() throws Exception {
    super.setUp();
    MockLookup.init();
    assertEquals("No factory has been used yet", 0, AnnotatedProject.factoryCalls);
    Collection<? extends AntBasedProjectType> all = Lookups.forPath("Services/AntBasedProjectTypes").lookupAll(AntBasedProjectType.class);
    assertEquals("Two found", 2, all.size());
    Iterator<? extends AntBasedProjectType> it = all.iterator();
    if ("testFactory".equals(getName())) {
        it.next();
    }
    AntBasedProjectType t = it.next();
    MockLookup.setInstances(t);
    scratch = TestUtil.makeScratchDir(this);
    projdir = scratch.createFolder("proj");
    ProjectGenerator.createProject(projdir, t.getType());
    pm = ProjectManager.getDefault();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:AntBasedProjectRegistrationTest.java

示例2: setUp

import org.openide.util.lookup.Lookups; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
    lookup = Lookup.EMPTY;
    lookupProxy = Lookups.proxy(this);
    
    a1 = context(new SimpleCookieAction(), null, ContextSelection.EXACTLY_ONE, lookupProxy, Openable.class);
    a2 = context(new SimpleCookieAction(), this, ContextSelection.ANY, lookupProxy, Openable.class);
    any = context(new SimpleCookieAction(), null, ContextSelection.ANY, lookupProxy, Openable.class);
    each = context(new SimpleCookieAction(), null, ContextSelection.EACH, lookupProxy, Openable.class);
    all = context(new SimpleCookieAction(), null, ContextSelection.ALL, lookupProxy, Openable.class);
    n1 = new LookupWithOpenable();
    n2 = new LookupWithOpenable();
    n3 = new LookupWithOpenable(false);
    n4 = new LookupWithOpenable(n1.lookup(Openable.class)); // share the same cookie instance with n1
    
    SimpleCookieAction.runOn.clear();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:ContextActionTest.java

示例3: testArgsChanges

import org.openide.util.lookup.Lookups; //导入依赖的package包/类
public void testArgsChanges() {
    final CompilerOptionsQueryImpl impl1 = new CompilerOptionsQueryImpl();
    final CompilerOptionsQueryImpl impl2 = new CompilerOptionsQueryImpl();
    impl1.addRoot(root1).addArgs("a1");   //NOI18N
    impl2.addRoot(root1).addArgs("b1");   //NOI18N
    final Lookup baseLkp = Lookups.fixed(
            impl1,
            impl2);
    final CompilerOptionsQueryImplementation merged =
            LookupMergerSupport.createCompilerOptionsQueryMerger()
            .merge(baseLkp);
    final CompilerOptionsQueryImplementation.Result res = merged.getOptions(root1);
    assertEquals(
            Arrays.asList("a1","b1"), //NOI18N
            res.getArguments());
    impl1.addArgs("a2");    //NOI18N
    assertEquals(
            Arrays.asList("a1","a2","b1"), //NOI18N
            res.getArguments());
    impl2.addArgs("b2");    //NOI18N
    assertEquals(
            Arrays.asList("a1","a2","b1","b2"), //NOI18N
            res.getArguments());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:CompilerOptionsQueryMergerTest.java

示例4: test200843

import org.openide.util.lookup.Lookups; //导入依赖的package包/类
public void test200843() throws IOException, InterruptedException, ExecutionException {
    FileObject testFile = projectDir.getFileObject("/src/simplej2seapp/D.java");
    JavaSource src = JavaSource.forFileObject(testFile);
    final WhereUsedQuery[] wuq = new WhereUsedQuery[1];
    src.runWhenScanFinished(new Task<CompilationController>() {

        @Override
        public void run(CompilationController controller) throws Exception {
            controller.toPhase(JavaSource.Phase.RESOLVED);
            ClassTree klass = (ClassTree) controller.getCompilationUnit().getTypeDecls().get(0);
            MethodTree runTree = (MethodTree) klass.getMembers().get(1);
            TreePath path = controller.getTrees().getPath(controller.getCompilationUnit(), runTree);
            TreePathHandle element = TreePathHandle.create(path, controller);
            Element method = controller.getTrees().getElement(path);
            Collection<ExecutableElement> overridens = JavaRefactoringUtils.getOverriddenMethods((ExecutableElement)method, controller);
            wuq[0] = new WhereUsedQuery(Lookups.singleton(TreePathHandle.create(overridens.iterator().next(), controller)));
            wuq[0].getContext().add(element);
        }
    }, false).get();
    setParameters(wuq, true, false, false, false, false, true);

    doRefactoring("test200843", wuq, 1);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:FindUsagesTest.java

示例5: testChangeOfDefaultLookupAppliedToRPTask

import org.openide.util.lookup.Lookups; //导入依赖的package包/类
public void testChangeOfDefaultLookupAppliedToRPTask() throws Exception {
    Lookup prev = Lookup.getDefault();
    final Lookup my = new AbstractLookup(new InstanceContent());
    final Thread myThread = Thread.currentThread();
    final RequestProcessor.Task[] task = { null };
    final boolean[] ok = { false };
    
    Lookups.executeWith(my, new Runnable() {
        @Override
        public void run() {
            assertSame("Default lookup has been changed", my, Lookup.getDefault());

            if (task[0] == null) {
                assertSame("We are being executed in the same thread", myThread, Thread.currentThread());
                // once again in the RP
                task[0] = RequestProcessor.getDefault().post(this, 500);
            } else {
                ok[0] = true;
            }
        }
    });
    assertNotNull("In my lookup code executed OK", task[0]);
    assertEquals("Current lookup back to normal", prev, Lookup.getDefault());
    task[0].waitFinished();
    assertTrue("Even RP task had the right lookup", ok[0]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:RequestProcessorLookupGetDefaultTest.java

示例6: testDatabaseNotExtractedToExistingDirectoryIssue80122

import org.openide.util.lookup.Lookups; //导入依赖的package包/类
public void testDatabaseNotExtractedToExistingDirectoryIssue80122() {
    final Holder<Boolean> exceptionHappend = new Holder<>(false);
    
    Lookups.executeWith(sampleDBLookup, new Runnable() {

        @Override
        public void run() {
            try {
                File sampleDir = new File(systemHome, "sample");
                sampleDir.mkdirs();
                
                FileUtil.toFileObject(sampleDir).createData("test.file");

                assertEquals("There should be no files in the sample directory", 1, sampleDir.listFiles().length);

                DerbyDatabasesImpl.getDefault().extractSampleDatabase("sample", false);
            } catch (IOException ex) {
                exceptionHappend.value = true;
            }
        }
    });
    
    assertTrue("Extracting sample db was interrupted", exceptionHappend.value);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:DerbyDatabasesTest.java

示例7: testDatabaseNotExtractedIfDBExists

import org.openide.util.lookup.Lookups; //导入依赖的package包/类
public void testDatabaseNotExtractedIfDBExists() {
    final Holder<Boolean> exceptionHappend = new Holder<>(false);
    
    Lookups.executeWith(sampleDBLookup, new Runnable() {

        @Override
        public void run() {
            try {
                DerbyDatabasesImpl.getDefault().extractSampleDatabase("sample1", true);
                DerbyDatabasesImpl.getDefault().extractSampleDatabase("sample1", true);
            } catch (IOException ex) {
                exceptionHappend.value = true;
            }
        }
    });
    
    assertTrue("Extracting sample db was interrupted", exceptionHappend.value);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:DerbyDatabasesTest.java

示例8: mousePressed

import org.openide.util.lookup.Lookups; //导入依赖的package包/类
public void mousePressed(MouseEvent ev) {
    if (ev.isPopupTrigger()) {
        int x = ev.getX();
        int y = ev.getY();
        TreePath path = view.getClosestPathForLocation(x, y);
        if (path != null) {
            LookTreeNode n = (LookTreeNode)path.getLastPathComponent();
            clicked = new WeakReference<LookTreeNode>(n);
            @SuppressWarnings("unchecked")
            Action[] actions = n.getLook().getActions(n.getData(), n.getLookup() );
            // XXX handle multiselects...
            Node selection = makeNode( n );
            Lookup context = Lookups.fixed(new Object[] {selection, actionMap});
            JPopupMenu menu = Utilities.actionsToPopup(actions, context);
            menu.show(view, x, y);
            // XXX selection does not appear to be collected... do we need to
            // also destroy the popup menu?
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:PopupHandler.java

示例9: getMimeTypes

import org.openide.util.lookup.Lookups; //导入依赖的package包/类
public synchronized Collection<? extends String> getMimeTypes() {
    if (mimeTypes == null) {
        mimeTypes = new HashSet<String>();
        mimeTypes.add(""); //NOI18N

        // filter out mime types that don't supply customizers
        for(String mimeType : EditorSettings.getDefault().getAllMimeTypes()) {
            Lookup l = Lookups.forPath(FORMATTING_CUSTOMIZERS_FOLDER + mimeType);
            Collection<? extends PreferencesCustomizer.Factory> factories = l.lookupAll(PreferencesCustomizer.Factory.class);
            if (!factories.isEmpty()) {
                if (allowedMimeTypes == null || allowedMimeTypes.contains(mimeType)) {
                    mimeTypes.add(mimeType);
                }
            } else if (acceptOldControllers) {
                Collection<? extends OptionsPanelController> controllers = l.lookupAll(OptionsPanelController.class);
                if (!controllers.isEmpty()) {
                    if (allowedMimeTypes == null || allowedMimeTypes.contains(mimeType)) {
                        mimeTypes.add(mimeType);
                    }
                }
            }
        }
    }
    return mimeTypes;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:CustomizerSelector.java

示例10: createTestModelSource

import org.openide.util.lookup.Lookups; //导入依赖的package包/类
public ModelSource createTestModelSource(FileObject fo, boolean editable) throws CatalogModelException{
    final DataObject dobj;
    final CatalogModel catalogModel = createCatalogModel(fo);
    try {
        dobj = DataObject.find(fo);
    } catch (DataObjectNotFoundException ex) {
        throw new CatalogModelException(ex);
    }
    Lookup lookup = Lookups.proxy(new Lookup.Provider() {
        public Lookup getLookup() {
                    return Lookups.fixed(new Object[] {
                        dobj.getPrimaryFile(),
                        getDocument(dobj.getPrimaryFile()),
                        dobj,
                        catalogModel
                    });
        }
    } );
    return new ModelSource(lookup, editable);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:TestCatalogModel.java

示例11: setParameters

import org.openide.util.lookup.Lookups; //导入依赖的package包/类
private Problem setParameters(boolean checkOnly) {
    if (panel == null) {
        return null;
    }
    URL url = URLMapper.findURL(panel.getRootFolder(), URLMapper.EXTERNAL);
    try {
        refactoring.setTarget(Lookups.singleton(new URL(url.toExternalForm() + panel.getPackageName().replace('.', '/')))); // NOI18N
    } catch (MalformedURLException ex) {
        Exceptions.printStackTrace(ex);
    }
    if (checkOnly) {
        return refactoring.fastCheckParameters();
    } else {
        return refactoring.checkParameters();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:CopyClassesUI.java

示例12: testCanBeReclaimedWithSimpleLookup

import org.openide.util.lookup.Lookups; //导入依赖的package包/类
public void testCanBeReclaimedWithSimpleLookup() throws Exception {
    Project prj1 = new DummyProject();
    Project prj2 = new DummyProject();
    Lookup projects = Lookups.fixed(new Object[] {
        prj1,
        prj2,
    });
    
    ActionsUtil.getProjectsFromLookup(projects, null);
    
    WeakReference<?> ref1 = new WeakReference<Object>(prj1);
    WeakReference<?> ref2 = new WeakReference<Object>(prj2);
    WeakReference<?> lookup = new WeakReference<Object>(projects);
    
    prj1 = null;
    prj2 = null;
    projects = null;
    
    assertGC("the projects can be reclaimed", ref1);
    assertGC("the projects can be reclaimed", ref2);
    assertGC("the lookup can be reclaimed", lookup);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:ActionsUtilTest.java

示例13: FixNode

import org.openide.util.lookup.Lookups; //导入依赖的package包/类
public FixNode(ErrorDescription ed, FixDescription fix) {
    super(Children.LEAF, Lookups.fixed(new OpenCookieImpl(ed), fix));
    this.fix = fix;

    int line = -1;
    try {
        line = ed.getRange().getBegin().getLine();
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    
    setDisplayName((line != (-1) ? (line + ":") : "") + fix.getText() + "(" + ed.getDescription() + ")");
    setIconBaseWithExtension("org/netbeans/modules/java/hints/analyzer/ui/suggestion.png");
    
    fix.addChangeListener(this);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:Nodes.java

示例14: run

import org.openide.util.lookup.Lookups; //导入依赖的package包/类
@Override
public void run() {
    err.fine("Warmup starting..."); // NOI18N
    StartLog.logStart("Warmup"); // NOI18N
    try {

    Collection<? extends Lookup.Item<Runnable>> warmObjects =
        Lookups.forPath("WarmUp").lookupResult(Runnable.class).allItems(); // NOI18N
    err.log(Level.FINE, "Found {0} warm up task(s)", warmObjects.size()); // NOI18N

    for (Lookup.Item<Runnable> warmer : warmObjects) {
        try {
            Runnable r = warmer.getInstance();
            r.run();
            StartLog.logProgress("Warmup task executed " + warmer.getId()); // NOI18N
        } catch (Exception ex) {
            Logger.getLogger(WarmUpSupport.class.getName()).log(Level.WARNING, null, ex);
        }
    }
    err.fine("Warmup done."); // NOI18N
    } finally {
    StartLog.logEnd("Warmup"); // NOI18N
    StartLog.impl.flush();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:WarmUpSupport.java

示例15: testContextInstancesDoNotInterfereWithEachOtherOrParent

import org.openide.util.lookup.Lookups; //导入依赖的package包/类
public void testContextInstancesDoNotInterfereWithEachOtherOrParent() throws Exception {
    System.out.println("testContextInstancesDoNotInterfereWithEachOtherOrParent");
    A a = new A();
    assertNull(Utilities.actionsGlobalContext().lookup(String.class)); //sanity check
    assertEquals("A", a.getValue(Action.NAME));
    Action a1 = a.createContextAwareInstance(Lookup.EMPTY);
    assertFalse(a.isEnabled());
    assertEquals("A", a1.getValue(Action.NAME));
    Action a2 = a.createContextAwareInstance(Lookups.fixed("testGeneralBehavior"));
    assertTrue(a2.isEnabled());
    assertFalse(a.isEnabled());
    setContent("foo");
    assertTrue(a.isEnabled());
    assertFalse(a1.isEnabled());
    assertTrue(a2.isEnabled());
    clearContent();
    assertFalse(a.isEnabled());
    assertTrue(a2.isEnabled());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:ContextActionTest.java


注:本文中的org.openide.util.lookup.Lookups类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。