Java Code Examples for org.openide.util.lookup.InstanceContent

The following examples show how to use org.openide.util.lookup.InstanceContent. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: netbeans   Source File: ContextManagerTest.java    License: Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 2
Source Project: netbeans   Source File: ContextActionInjectTest.java    License: Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 3
Source Project: openjdk-8   Source File: FilterNode.java    License: GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example 4
Source Project: hottub   Source File: FolderNode.java    License: GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example 5
Source Project: netbeans   Source File: ActionInvocationTest.java    License: Apache License 2.0 6 votes vote down vote up
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.");
            }
        }
    });
}
 
Example 6
Source Project: openjdk-jdk8u   Source File: FolderNode.java    License: GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example 7
Source Project: openjdk-jdk8u   Source File: FilterNode.java    License: GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example 8
Source Project: netbeans   Source File: CMPFieldNode.java    License: Apache License 2.0 6 votes vote down vote up
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));
    }
 
Example 9
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);
}
 
Example 10
@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>();
}
 
Example 11
Source Project: netbeans   Source File: StatefulActionProcessorTest.java    License: Apache License 2.0 6 votes vote down vote up
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));
}
 
Example 12
@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>();
}
 
Example 13
Source Project: netbeans   Source File: NbLookupBenchmark.java    License: Apache License 2.0 6 votes vote down vote up
/** 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]);
            }
        }
    }
}
 
Example 14
Source Project: nb-springboot   Source File: GlobalActionContextProxy.java    License: Apache License 2.0 6 votes vote down vote up
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();
            }
        }
    });
}
 
Example 15
Source Project: netbeans   Source File: AngularJsDelcarationFinderTest.java    License: Apache License 2.0 5 votes vote down vote up
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);

}
 
Example 16
Source Project: openjdk-jdk9   Source File: FolderNode.java    License: GNU General Public License v2.0 5 votes vote down vote up
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);
            }
        });
    }
}
 
Example 17
Source Project: netbeans   Source File: ELTestBase.java    License: Apache License 2.0 5 votes vote down vote up
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);

}
 
Example 18
Source Project: jeddict   Source File: NamedNativeQueryPanel.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 19
Source Project: netbeans   Source File: GlobalSharabilityQueryImplTest.java    License: Apache License 2.0 5 votes vote down vote up
private Lookup getInstanceLookup() {
    InstanceContent instanceContent = new InstanceContent();
    instanceContent.add(sq);
    instanceContent.add(vq);
    Lookup instanceLookup = new AbstractLookup(instanceContent);
    return instanceLookup;
}
 
Example 20
Source Project: BART   Source File: DependenciesEditorTopComponent.java    License: MIT License 5 votes vote down vote up
public DependenciesEditorTopComponent() {
    setName(Bundle.CTL_DependenciesEditorTopComponent());
    setToolTipText(Bundle.HINT_DependenciesEditorTopComponent());
    setLayout(new BorderLayout());
    init();
    content = new InstanceContent();
    lookup = new AbstractLookup(content);
    associateLookup(lookup);
}
 
Example 21
Source Project: netbeans   Source File: JAXBWizardRootNode.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 22
Source Project: netbeans   Source File: PlatformNode.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 23
Source Project: netbeans   Source File: FeatureManager.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 24
Source Project: netbeans   Source File: JavaRefactoringGlobalAction.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 25
Source Project: netbeans   Source File: MultiViewProcessorTest.java    License: Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 26
Source Project: netbeans   Source File: ElementNode.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 27
Source Project: netbeans   Source File: ChangeParametersFix.java    License: Apache License 2.0 5 votes vote down vote up
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);
        }
    });
}
 
Example 28
Source Project: netbeans   Source File: SettingsProvider.java    License: Apache License 2.0 5 votes vote down vote up
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]));
    }
}
 
Example 29
Source Project: netbeans   Source File: HistoryComponent.java    License: Apache License 2.0 5 votes vote down vote up
public HistoryComponent() {
    activatedNodesContent = new InstanceContent();
    lookup = new ProxyLookup(new Lookup[] {
        new AbstractLookup(activatedNodesContent)
    });
    init();
}
 
Example 30
Source Project: netbeans   Source File: ContextActionTest.java    License: Apache License 2.0 5 votes vote down vote up
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());
}