java.awt.event.HierarchyBoundsListener#org.openide.util.lookup.InstanceContent源码实例Demo

下面列出了java.awt.event.HierarchyBoundsListener#org.openide.util.lookup.InstanceContent 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: ContextManagerTest.java
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);
}
 
源代码2 项目: netbeans   文件: ContextActionInjectTest.java
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);
}
 
源代码3 项目: openjdk-8   文件: FilterNode.java
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>() {

        public void changed(Filter source) {
            update();
        }
    });

    update();

    Lookup.Template<FilterChain> tpl = new Lookup.Template<FilterChain>(FilterChain.class);
    result = Utilities.actionsGlobalContext().lookup(tpl);
    result.addLookupListener(this);

    FilterTopComponent.findInstance().getFilterSettingsChangedEvent().addListener(this);
    resultChanged(null);
}
 
源代码4 项目: hottub   文件: FolderNode.java
private FolderNode(String name, GroupOrganizer organizer, List<String> oldSubFolders, final List<Group> groups, FolderChildren children, InstanceContent content) {
    super(children, new AbstractLookup(content));
    children.setParent(this);
    this.content = content;
    this.children = children;
    content.add(new RemoveCookie() {

        public void remove() {
            for (Group g : groups) {
                if (g.getDocument() != null) {
                    g.getDocument().removeGroup(g);
                }
            }
        }
    });
    init(name, organizer, oldSubFolders, groups);
}
 
源代码5 项目: netbeans   文件: ActionInvocationTest.java
public void testMoveAction() throws InterruptedException, InvocationTargetException, DataObjectNotFoundException, IOException {
    DataObject testdo = DataObject.find(f);
    final Node node = testdo.getNodeDelegate();

    InstanceContent ic = new InstanceContent();
    Lookup lookup = new AbstractLookup(ic);
    ic.add(node);
    final Action move = RefactoringActionsFactory.moveAction().createContextAwareInstance(lookup);
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            if (move.isEnabled()) {
                move.actionPerformed(RefactoringActionsFactory.DEFAULT_EVENT);
                if (!((MoveRefactoring) DD.rui.getRefactoring()).getRefactoringSource().lookup(FileObject.class).equals(f))
                    fail("MoveClass was opened with wrong data");
            } else {
                fail("Action is not enabled.");
            }
        }
    });
}
 
源代码6 项目: openjdk-jdk8u   文件: FolderNode.java
private FolderNode(String name, GroupOrganizer organizer, List<String> oldSubFolders, final List<Group> groups, FolderChildren children, InstanceContent content) {
    super(children, new AbstractLookup(content));
    children.setParent(this);
    this.content = content;
    this.children = children;
    content.add(new RemoveCookie() {

        public void remove() {
            for (Group g : groups) {
                if (g.getDocument() != null) {
                    g.getDocument().removeGroup(g);
                }
            }
        }
    });
    init(name, organizer, oldSubFolders, groups);
}
 
源代码7 项目: openjdk-jdk8u   文件: FilterNode.java
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>() {

        public void changed(Filter source) {
            update();
        }
    });

    update();

    Lookup.Template<FilterChain> tpl = new Lookup.Template<FilterChain>(FilterChain.class);
    result = Utilities.actionsGlobalContext().lookup(tpl);
    result.addLookupListener(this);

    FilterTopComponent.findInstance().getFilterSettingsChangedEvent().addListener(this);
    resultChanged(null);
}
 
源代码8 项目: netbeans   文件: CMPFieldNode.java
private CMPFieldNode(CmpField field, EntityMethodController controller, FileObject ddFile, InstanceContent instanceContent) {
        super(Children.LEAF, new AbstractLookup(instanceContent));
        instanceContent.add(this); // for enabling Open action
        
        //TODO: RETOUCHE
//        try {
//            ic.add(DataObject.find(JavaModel.getFileObject(controller.getBeanClass().getResource()))); // for enabling SafeDelete action
//        } catch (DataObjectNotFoundException ex) {
//            // ignore
//        }
//        Method getterMethod = controller.getGetterMethod(controller.getBeanClass(), field.getFieldName());
//        if (getterMethod != null) {
//            ic.add(getterMethod); // for SafeDelete refactoring to find Method element
//        }
        this.field = field;
        this.ddFile = ddFile;
        this.controller = controller;
        field.addPropertyChangeListener(WeakListeners.propertyChange(this, field));
    }
 
protected void setUp () {
    ic = new InstanceContent ();
    CES support = new CES (this, new AbstractLookup(ic));
    
    MockServices.setServices(Redirector.class, DD.class);
    red = Lookup.getDefault().lookup(Redirector.class);
    assertNotNull(red);
    dd = Lookup.getDefault().lookup(DD.class);
    assertNotNull(dd);

    CloneableEditorSupportCOSRedirectorTest t = new CloneableEditorSupportCOSRedirectorTest(this.content);
    red.master = support;
    InstanceContent slave = new InstanceContent();
    red.slave = new CES(t, new AbstractLookup (slave));
    slave.add(red.master);
}
 
@Override
protected void setUp () throws Exception {
    MockServices.setServices(DD.class);
    
    
    clearWorkDir();
    LocalFileSystem fs = new LocalFileSystem();
    fs.setRootDirectory(getWorkDir());
    
    FileObject fo = fs.getRoot().createData("Ahoj", "txt");

    ic = new InstanceContent();
    support = new CES(this, new AbstractLookup(ic));
    edit = support;
    assertNotNull("we have editor", edit);

    DD.type = -1;
    DD.toReturn = new Stack<Object>();
}
 
源代码11 项目: netbeans   文件: StatefulActionProcessorTest.java
public void testCustomContextAwareInstance() {
    Action a = Actions.forID("Foo", "test.ListAction");
    DefaultListSelectionModel model = new DefaultListSelectionModel();
    
    InstanceContent localContent1 = new InstanceContent();
    AbstractLookup localLookup1 = new AbstractLookup(localContent1);
    
    Action la = ((ContextAwareAction)a).createContextAwareInstance(localLookup1);
    
    assertFalse(a.isEnabled());
    assertFalse(la.isEnabled());
    
    localContent1.add(model);
    
    assertFalse(a.isEnabled());
    assertTrue(la.isEnabled());
    assertFalse((Boolean)la.getValue(Action.SELECTED_KEY));
    
    // checks that the context-bound instance changes its selected state
    // if the model changes (relevant property change event is fired)
    model.setSelectionInterval(1, 2);
    assertTrue((Boolean)la.getValue(Action.SELECTED_KEY));
}
 
@Override
protected void setUp() throws Exception {
    MockServices.setServices(DD.class);


    clearWorkDir();
    LocalFileSystem fs = new LocalFileSystem();
    fs.setRootDirectory(getWorkDir());

    FileObject fo = fs.getRoot().createData("Ahoj", "txt");

    ic = new InstanceContent();
    support = new CES(this, new AbstractLookup(ic));
    edit = support;
    assertNotNull("we have editor", edit);

    DD.type = -1;
    DD.toReturn = new Stack<Object>();
}
 
源代码13 项目: netbeans   文件: NbLookupBenchmark.java
/** Fills the lookup with instances */
protected void setUp () {
    Integer integer = (Integer)getArgument ();
    int cnt = integer.intValue ();
    
    boolean reverse = cnt < 0;
    if (reverse) cnt = -cnt;
    
    InstanceContent iContent = new InstanceContent();
    
    lookup = new AbstractLookup(iContent);
    
    while (cnt-- > 0) {
        for (int i = 0; i < INSTANCES.length; i++) {
            if (reverse) {
                iContent.add (INSTANCES[INSTANCES.length - i - 1]);
            } else {
                iContent.add (INSTANCES[i]);
            }
        }
    }
}
 
源代码14 项目: nb-springboot   文件: GlobalActionContextProxy.java
public GlobalActionContextProxy() {
    try {
        this.content = new InstanceContent();
        // The default GlobalContextProvider
        this.globalContextProvider = new GlobalActionContextImpl();
        this.globalContextLookup = this.globalContextProvider.createGlobalContext();
        // Monitor the activation of the Projects Tab TopComponent
        TopComponent.getRegistry().addPropertyChangeListener(this.registryListener);
        // Monitor the existance of a Project in the principle lookup
        this.resultProjects = globalContextLookup.lookupResult(Project.class);
        this.resultProjects.addLookupListener(this.resultListener);
    } catch (Exception e) {
        Exceptions.printStackTrace(e);
    }
    WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
        @Override
        public void run() {
            // Hack to force the current Project selection when the application starts up
            TopComponent tc = WindowManager.getDefault().findTopComponent(PROJECT_LOGICAL_TAB_ID);
            if (tc != null) {
                tc.requestActive();
            }
        }
    });
}
 
源代码15 项目: netbeans   文件: AngularJsDelcarationFinderTest.java
public TestProject(FileObject dir, ProjectState state, ClassPathProvider classpathProvider, Sources sources) {
    this.dir = dir;
    this.state = state;

    InstanceContent ic = new InstanceContent();
    ic.add(classpathProvider);
    ic.add(sources);

    this.lookup = new AbstractLookup(ic);

}
 
源代码16 项目: openjdk-jdk9   文件: FolderNode.java
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);
            }
        });
    }
}
 
源代码17 项目: netbeans   文件: ELTestBase.java
public TestProject(FileObject dir, ProjectState state, ClassPathProvider classpathProvider, Sources sources) {
    this.dir = dir;
    this.state = state;

    InstanceContent ic = new InstanceContent();
    ic.add(classpathProvider);
    ic.add(sources);

    this.lookup = new AbstractLookup(ic);

}
 
源代码18 项目: jeddict   文件: NamedNativeQueryPanel.java
@Override
public Lookup getLookup() {
    if (lookup == null) {
        InstanceContent lookupContent = new InstanceContent();
        lookupContent.add(new SQLExecutionImpl(modelerFile));
        Lookup[] content = {new AbstractLookup(lookupContent)};
        lookup = new ProxyLookup(content);
    }
    return lookup;
}
 
源代码19 项目: netbeans   文件: GlobalSharabilityQueryImplTest.java
private Lookup getInstanceLookup() {
    InstanceContent instanceContent = new InstanceContent();
    instanceContent.add(sq);
    instanceContent.add(vq);
    Lookup instanceLookup = new AbstractLookup(instanceContent);
    return instanceLookup;
}
 
源代码20 项目: BART   文件: DependenciesEditorTopComponent.java
public DependenciesEditorTopComponent() {
    setName(Bundle.CTL_DependenciesEditorTopComponent());
    setToolTipText(Bundle.HINT_DependenciesEditorTopComponent());
    setLayout(new BorderLayout());
    init();
    content = new InstanceContent();
    lookup = new AbstractLookup(content);
    associateLookup(lookup);
}
 
源代码21 项目: netbeans   文件: JAXBWizardRootNode.java
private JAXBWizardRootNode(Project prj, InstanceContent content) {
    super(new JAXBWizardRootNodeChildren(prj), 
            new AbstractLookup(content));
    // adds the node to our own lookup
    content.add (this);
    // adds additional items to the lookup
    content.add (prj);
}
 
源代码22 项目: netbeans   文件: PlatformNode.java
private PlatformNode(PlatformProvider pp, ClassPathSupport cs) {
    super (new PlatformContentChildren (cs), new ProxyLookup(new Lookup[]{
        Lookups.fixed(new PlatformEditable(pp), new JavadocProvider(pp),  new PathFinder()),
                new PlatformFolderLookup(new InstanceContent(), pp)
        }));
    this.pp = pp;
    this.pp.addChangeListener(this);
    setIconBaseWithExtension(PLATFORM_ICON);
}
 
源代码23 项目: netbeans   文件: FeatureManager.java
private static synchronized Lookup featureTypesLookup() {
    if (featureTypesLookup != null) {
        return featureTypesLookup;
    }

    String clusters = System.getProperty("netbeans.dirs");
    if (clusters == null) {
        featureTypesLookup = Lookup.EMPTY;
    } else {
        InstanceContent ic = new InstanceContent();
        AbstractLookup l = new AbstractLookup(ic);
        String[] paths = clusters.split(File.pathSeparator);
        for (String c : paths) {
            int last = c.lastIndexOf(File.separatorChar);
            String clusterName = c.substring(last + 1).replaceFirst("[0-9\\.]*$", "");
            String basename = "/org/netbeans/modules/ide/ergonomics/" + clusterName;
            String layerName = basename + "/layer.xml";
            String bundleName = basename + "/Bundle.properties";
            URL layer = FeatureManager.class.getResource(layerName);
            URL bundle = FeatureManager.class.getResource(bundleName);
            if (layer != null && bundle != null) {
                FeatureInfo info;
                try {
                    info = FeatureInfo.create(clusterName, layer, bundle);
                    ic.add(info);
                } catch (IOException ex) {
                    Exceptions.printStackTrace(ex);
                }
            }
        }
        featureTypesLookup = l;
    }
    return featureTypesLookup;
}
 
源代码24 项目: netbeans   文件: JavaRefactoringGlobalAction.java
protected Lookup getLookup(Node[] n) {
    InstanceContent ic = new InstanceContent();
    for (Node node:n) {
        ic.add(node);
    }
    if (n.length>0) {
        EditorCookie tc = getTextComponent(n[0]);
        if (tc != null) {
            ic.add(tc);
        }
    }
    ic.add(new Hashtable(0));
    return new AbstractLookup(ic);
}
 
源代码25 项目: netbeans   文件: MultiViewProcessorTest.java
public void testLookupInitialized() {
    InstanceContent ic = new InstanceContent();
    Lookup lookup = new AbstractLookup(ic);
    ic.add(10);

    TopComponent mvc = MultiViews.createMultiView("text/context", new LP(lookup));
    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));
}
 
源代码26 项目: netbeans   文件: ElementNode.java
@NonNull
private static Lookup prepareLookup(@NonNull final Description d) {
    final InstanceContent ic = new InstanceContent();
    ic.add(d, ConvertDescription2FileObject);
    ic.add(d, ConvertDescription2DataObject);
    if (d.handle != null) {
        ic.add(d, ConvertDescription2TreePathHandle);
    }
    return new AbstractLookup(ic);
}
 
源代码27 项目: netbeans   文件: ChangeParametersFix.java
private static void doFullChangeMethodParameters(TreePathHandle tph, ParameterInfo[] newParameterInfo) {
    InstanceContent ic = new InstanceContent();
    ic.add(tph);
    ic.add(new AbstractNode(Children.LEAF, Lookups.singleton(tph)));
    for (ParameterInfo parameterInfo : newParameterInfo) {
        ic.add(parameterInfo);
    }
    Lookup actionContext = new AbstractLookup(ic);
    final Action a = JavaRefactoringActionsFactory.changeParametersAction().createContextAwareInstance(actionContext);
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            a.actionPerformed(RefactoringActionsFactory.DEFAULT_EVENT);
        }
    });
}
 
源代码28 项目: netbeans   文件: SettingsProvider.java
private MyLookup(MimePath mimePath, InstanceContent ic) {
    super(ic);

    this.mimePath = mimePath;
    this.ic = ic;
    
    // Start listening
    List<MimePath> allPaths = mimePath.getIncludedPaths();
    this.allCtsi = new CodeTemplateSettingsImpl[allPaths.size()];
    
    for(int i = 0; i < allPaths.size(); i++) {
        this.allCtsi[i] = CodeTemplateSettingsImpl.get(allPaths.get(i));
        this.allCtsi[i].addPropertyChangeListener(WeakListeners.propertyChange(this, this.allCtsi[i]));
    }
}
 
源代码29 项目: netbeans   文件: HistoryComponent.java
public HistoryComponent() {
    activatedNodesContent = new InstanceContent();
    lookup = new ProxyLookup(new Lookup[] {
        new AbstractLookup(activatedNodesContent)
    });
    init();
}
 
源代码30 项目: netbeans   文件: ContextActionTest.java
public void testContextInstancesAreIndependent() throws Exception {
    System.out.println("testContextInstancesAreIndependent");
    A a = new A();
    assertNull(Utilities.actionsGlobalContext().lookup(String.class)); //sanity check
    InstanceContent ic = new InstanceContent();
    Lookup l = new AbstractLookup(ic);
    Action a3 = a.createContextAwareInstance(l);
    assertFalse(a3.isEnabled());
    PCL pcl = new PCL();
    a3.addPropertyChangeListener(pcl);
    setContent("fuddle");
    a.assertNotPerformed();
    assertTrue(a.isEnabled());
    assertFalse(a3.isEnabled());
    synchronized (a3) {
        //should time out if test is going to pass
        a3.wait(TIMEOUT);
    }
    synchronized (pcl) {
        pcl.wait(TIMEOUT);
    }
    pcl.assertNotFired();
    ic.set(Collections.singleton("boo"), null);
    synchronized (a3) {
        a3.wait(TIMEOUT);
    }
    synchronized (pcl) {
        pcl.wait(TIMEOUT);
    }
    pcl.assertEnabledChangedTo(true);
    clearContent();
    assertTrue(a3.isEnabled());
    assertFalse(a.isEnabled());
}