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


Java InstanceContent类代码示例

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


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

示例1: doTestNodesWithChangesInLookup

import org.openide.util.lookup.InstanceContent; //导入依赖的package包/类
private void doTestNodesWithChangesInLookup (Class c) {
    InstanceContent ic = new InstanceContent();
    
    Node[] arr = new Node[] {
        new AbstractNode(Children.LEAF, new AbstractLookup(ic)),
        new AbstractNode(Children.LEAF, Lookup.EMPTY),
    };
    arr[0].setName("cookie-container-node");
    arr[1].setName("node-as-cookie");
    //doTestNodes(arr, AbstractNode.class);
    doTestNodes (arr, c, 2);
    
    ic.add (arr[1]);
    
    /* Huh? There should be both [0] and [1], how can you say which one will be returned?
    assertEquals ("Now the [1] is in lookup of [0]", arr[1], lookup.lookup (c));
     */
    Collection all = lookup.lookup(new Lookup.Template(c)).allInstances();
    assertEquals("Two nodes are in TC lookup", 2, all.size());
    assertEquals("They are the ones we expect", new HashSet(Arrays.asList(arr)), new HashSet(all));
    assertTrue("Lookup simple query gives one or the other", new HashSet(Arrays.asList(arr)).contains(lookup.lookup(c)));
    assertEquals("Have two lookup items", 2, lookup.lookup(new Lookup.Template(c)).allItems().size());

    doTestNodes (null, c, 2);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:TopComponentGetLookupTest.java

示例2: FilterNode

import org.openide.util.lookup.InstanceContent; //导入依赖的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");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:FilterNode.java

示例3: FilterNode

import org.openide.util.lookup.InstanceContent; //导入依赖的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");
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:26,代码来源:FilterNode.java

示例4: testLookupInitializedForCloneable

import org.openide.util.lookup.InstanceContent; //导入依赖的package包/类
public void testLookupInitializedForCloneable() {
    InstanceContent ic = new InstanceContent();
    Lookup lookup = new AbstractLookup(ic);
    ic.add(10);

    CloneableTopComponent cmv = MultiViews.createCloneableMultiView("text/context", new LP(lookup));
    assertEquals("10 now", Integer.valueOf(10), cmv.getLookup().lookup(Integer.class));
    
    assertNotNull("MultiViewComponent created", cmv);
    TopComponent mvc = cmv.cloneTopComponent();
    
    assertNotNull("MultiViewComponent cloned", mvc);
    MultiViewHandler handler = MultiViews.findMultiViewHandler(mvc);
    assertNotNull("Handler found", handler);
    
    assertEquals("10 now", Integer.valueOf(10), mvc.getLookup().lookup(Integer.class));
    ic.remove(10);
    ic.add(1);
    assertEquals("1 now", Integer.valueOf(1), mvc.getLookup().lookup(Integer.class));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:MultiViewProcessorTest.java

示例5: checkInstanceInGetLookup

import org.openide.util.lookup.InstanceContent; //导入依赖的package包/类
private void checkInstanceInGetLookup (Object obj, InstanceContent ic, Node node, boolean shouldBeThere) {
    Listener listener = new Listener ();
    Lookup.Result res = node.getLookup().lookupResult(obj.getClass());
    Collection ignore = res.allItems ();
    res.addLookupListener(listener);

    ic.add (obj);
    if (shouldBeThere) {
        listener.assertEvents ("One change in node's lookup", -1, 1);
        assertEquals ("Can access object in content via lookup", obj, node.getLookup ().lookup (obj.getClass ()));
    } else {
        assertNull ("Cannot access object in content via lookup", node.getLookup ().lookup (obj.getClass ()));
    }
        
    
    ic.remove (obj);
    if (shouldBeThere) {
        listener.assertEvents ("One change in node's lookup", -1, 1);
    }
    assertNull ("Cookie is removed", node.getLookup ().lookup (obj.getClass ()));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:NodeLookupTest.java

示例6: handleRename

import org.openide.util.lookup.InstanceContent; //导入依赖的package包/类
@Override
public void handleRename(DataFolder folder, String newName) {
    InstanceContent ic = new InstanceContent();
    ic.add(folder.getNodeDelegate());
    ExplorerContext d = new ExplorerContext();
    d.setNewName(newName);
    ic.add(d);
    final Lookup l = new AbstractLookup(ic);
    if (ActionsImplementationFactory.canRename(l)) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                Action a = RefactoringActionsFactory.renameAction().createContextAwareInstance(l);
                a.actionPerformed(RefactoringActionsFactory.DEFAULT_EVENT);
            }
        });
    } else {
        FileObject fo = folder.getPrimaryFile();
        try {
            folder.rename(newName);
        } catch (IOException ioe) {
            ErrorManager.getDefault().notify(ioe);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:FolderRenameHandlerImpl.java

示例7: testSurviveFocusChange

import org.openide.util.lookup.InstanceContent; //导入依赖的package包/类
public void testSurviveFocusChange() throws Exception {
    InstanceContent ic = new InstanceContent();
    Lookup lkp = new AbstractLookup(ic);

    Action clone = ((ContextAwareAction) Actions.forID("cat", "survive")).createContextAwareInstance(lkp);
    L listener = new L();
    clone.addPropertyChangeListener(listener);

    assertFalse("Disabled", clone.isEnabled());
    Object val = Integer.valueOf(1);
    ic.add(val);
    assertTrue("Enabled now", clone.isEnabled());
    assertEquals("One change", 1, listener.cnt);
    ic.remove(val);
    assertTrue("Still Enabled", clone.isEnabled());

    Survival.value = 0;
    clone.actionPerformed(new ActionEvent(this, 0, ""));
    assertEquals("Added one", 1, Survival.value);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ContextManagerTest.java

示例8: testChangeOfDefaultLookupAppliedToRPTask

import org.openide.util.lookup.InstanceContent; //导入依赖的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

示例9: testCopyLikeProblem

import org.openide.util.lookup.InstanceContent; //导入依赖的package包/类
public void testCopyLikeProblem() throws Exception {
    FileObject fo = folder.getFileObject("testCopyLike.instance");

    Object obj = fo.getAttribute("instanceCreate");
    if (!(obj instanceof Action)) {
        fail("Shall create an action: " + obj);
    }

    InstanceContent ic = new InstanceContent();
    AbstractLookup l = new AbstractLookup(ic);
    ActionMap map = new ActionMap();
    map.put("copy-to-clipboard", new MyAction());
    ic.add(map);

    CntListener list = new CntListener();
    Action clone = ((ContextAwareAction)obj).createContextAwareInstance(l);
    clone.addPropertyChangeListener(list);
    assertTrue("Enabled", clone.isEnabled());

    ic.remove(map);
    assertFalse("Disabled", clone.isEnabled());
    list.assertCnt("one change", 1);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:CallbackActionTest.java

示例10: testOwnContextAction

import org.openide.util.lookup.InstanceContent; //导入依赖的package包/类
public void testOwnContextAction() throws Exception {
    MultiContext.cnt = 0;
    
    FileObject fo = FileUtil.getConfigFile(
        "actions/support/test/testOwnContext.instance"
    );
    assertNotNull("File found", fo);
    Object obj = fo.getAttribute("instanceCreate");
    assertNotNull("Attribute present", obj);
    assertTrue("It is action", obj instanceof Action);
    assertFalse("It is not context aware action: " + obj, obj instanceof ContextAwareAction);
    Action a = (Action)obj;

    InstanceContent ic = contextI;
    ic.add(10);

    assertEquals("Number lover!", a.getValue(Action.NAME));
    a.actionPerformed(new ActionEvent(this, 300, ""));
    assertEquals("Global Action not called", 10, MultiContext.cnt);

    ic.remove(10);
    a.actionPerformed(new ActionEvent(this, 200, ""));
    assertEquals("Global Action stays same", 10, MultiContext.cnt);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:ContextActionInjectTest.java

示例11: PhotoNode

import org.openide.util.lookup.InstanceContent; //导入依赖的package包/类
private PhotoNode(String photo, InstanceContent ic) {
    super(Children.LEAF, new AbstractLookup(ic));
    final String name = new File(photo).getName();
    setName(name);
    setDisplayName(name);
    setShortDescription(photo);

    ic.add((OpenCookie) () -> {
        TopComponent tc = findTopComponent(photo);
        if (tc == null) {
            tc = new PhotoViewerTopComponent(photo);
            tc.open();
        }
        tc.requestActive();
    });
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:17,代码来源:PhotoNode.java

示例12: CompilationNode

import org.openide.util.lookup.InstanceContent; //导入依赖的package包/类
private CompilationNode(final Folder folder, Children children, InstanceContent content) {
    super(children, new AbstractLookup(content));
    this.setDisplayName(folder.getName());

    if (folder instanceof Group) {
        content.add(new OpenCookie() {

            @Override
            public void open() {
                final List<InputGraph> graphs = ((Group) folder).getGraphs();
                if (graphs.isEmpty()) {
                    JOptionPane.showMessageDialog(null, "Cannot open compilation, because there was no snapshots recorded!");
                } else {
                    Lookup.getDefault().lookup(GraphViewer.class).view(graphs.get(0));
                }
            }
        });
    }
    content.add(folder);
    folder.getChangedEvent().addListener(this);
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:22,代码来源:CompilationNode.java

示例13: testActionStatusUpdatedOnLookupChange

import org.openide.util.lookup.InstanceContent; //导入依赖的package包/类
public void testActionStatusUpdatedOnLookupChange() throws Exception {
    final InstanceContent content = new InstanceContent();
    Lookup lkp = new AbstractLookup( content );
    final SaveAsCapable saveAsImpl = new SaveAsCapable() {
        public void saveAs(FileObject folder, String name) throws IOException {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    };
    
    TopComponent tc = new TopComponent( lkp );
    editorMode.dockInto( tc );
    tc.open();
    tc.requestActive();
    assertTrue(Arrays.asList(WindowManager.getDefault().getOpenedTopComponents(editorMode)).contains(tc));
    
    ContextAwareAction action = SaveAsAction.create();
    assertFalse( "action is disabled for editor windows without SaveAsCapable in their Lookup", action.isEnabled() );
    
    Action a = action.createContextAwareInstance( tc.getLookup() );
    
    content.add( saveAsImpl );
    assertTrue( "action is enabled for editor windows with SaveAsCapable in their Lookup", a.isEnabled() );
    content.remove( saveAsImpl );
    assertFalse( "action is disabled for editor windows without SaveAsCapable in their Lookup", a.isEnabled() );
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:SaveAsActionTest.java

示例14: FolderNode

import org.openide.util.lookup.InstanceContent; //导入依赖的package包/类
private FolderNode(final Folder folder, FolderChildren children, InstanceContent content) {
    super(children, new AbstractLookup(content));
    this.content = content;
    this.children = children;
    if (folder instanceof FolderElement) {
        final FolderElement folderElement = (FolderElement) folder;
        this.setDisplayName(folderElement.getName());
        content.add(new RemoveCookie() {
            @Override
            public void remove() {
                folderElement.getParent().removeElement(folderElement);
            }
        });
    }
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:16,代码来源:FolderNode.java

示例15: CustomMethodNode

import org.openide.util.lookup.InstanceContent; //导入依赖的package包/类
public CustomMethodNode(CustomSaasMethod method, InstanceContent content) {
    super(Children.LEAF, new AbstractLookup(content));
    this.method = method;
    content.add(method);
    transferable = ExTransferable.create(
        new SaasTransferable<SaasMethod>(method, SaasTransferable.CUSTOM_METHOD_FLAVORS));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:CustomMethodNode.java


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