org.openide.util.lookup.AbstractLookup Java Examples

The following examples show how to use org.openide.util.lookup.AbstractLookup. 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 check out the related API usage on the sidebar.
Example #1
Source File: ContextManagerTest.java    From netbeans with Apache License 2.0 7 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 File: ExternalChangeOfModifiedContentTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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 #3
Source File: GraphNode.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private GraphNode(final InputGraph graph, InstanceContent content) {
    super(Children.LEAF, new AbstractLookup(content));
    this.graph = graph;
    this.setDisplayName(graph.getName());
    content.add(graph);

    final GraphViewer viewer = Lookup.getDefault().lookup(GraphViewer.class);

    if (viewer != null) {
        // Action for opening the graph
        content.add(new OpenCookie() {

            public void open() {
                viewer.view(graph);
            }
        });
    }

    // Action for removing a graph
    content.add(new RemoveCookie() {

        public void remove() {
            graph.getGroup().removeGraph(graph);
        }
    });
}
 
Example #4
Source File: JaxWsClientNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private JaxWsClientNode(JaxWsModel jaxWsModel, Client client, FileObject srcRoot, InstanceContent content) {
    super(new JaxWsClientChildren(client, srcRoot),new AbstractLookup(content));
    this.jaxWsModel=jaxWsModel;
    this.client=client;
    this.srcRoot=srcRoot;
    this.content = content;
    setName(client.getName());
    setDisplayName(client.getName());
    content.add(this);
    content.add(client);
    content.add(srcRoot);
    WsdlModeler modeler = getWsdlModeler();
    if (modeler!=null) {
        changeIcon();
        modeler.generateWsdlModel(new WsdlModelListener(){
            public void modelCreated(WsdlModel model) {
                modelGenerationFinished=true;
                changeIcon();
            }
        });
    }
    content.add(new EditWSAttributesCookieImpl(this, jaxWsModel));
    setValue("wsdl-url",client.getWsdlUrl());
}
 
Example #5
Source File: SessionNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private SessionNode(InstanceContent instanceContent, EjbViewController controller, String ejbName) {
    super(new SessionChildren(controller), new AbstractLookup(instanceContent));
    ejbViewController = controller;
    setIconBaseWithExtension("org/netbeans/modules/j2ee/ejbcore/ui/logicalview/ejb/session/SessionNodeIcon.gif");
    setName(ejbName + "");
    setDisplayName();
    instanceContent.add(this);
    ElementHandle<TypeElement> beanClassHandle = ejbViewController.getBeanClass();
    if (beanClassHandle != null) {
        instanceContent.add(beanClassHandle);
    }
    DataObject dataObject = ejbViewController.getBeanDo();
    if (dataObject != null && dataObject.getPrimaryFile() != null) {
        instanceContent.add(dataObject.getPrimaryFile());
    }
    try {
        instanceContent.add(ejbViewController.createEjbReference());
    } catch (IOException ioe) {
        Exceptions.printStackTrace(ioe);
    }
}
 
Example #6
Source File: ExternalDeleteOfModifiedContentTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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 #7
Source File: FilterNode.java    From TencentKona-8 with 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 File: CMPFieldNode.java    From netbeans with 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
Source File: GraphNode.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private GraphNode(final InputGraph graph, InstanceContent content) {
    super(Children.LEAF, new AbstractLookup(content));
    this.graph = graph;
    this.setDisplayName(graph.getName());
    content.add(graph);

    final GraphViewer viewer = Lookup.getDefault().lookup(GraphViewer.class);

    if (viewer != null) {
        // Action for opening the graph
        content.add(new OpenCookie() {

            public void open() {
                viewer.view(graph);
            }
        });
    }

    // Action for removing a graph
    content.add(new RemoveCookie() {

        public void remove() {
            graph.getGroup().removeGraph(graph);
        }
    });
}
 
Example #10
Source File: StatefulActionProcessorTest.java    From netbeans with 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 #11
Source File: FolderNode.java    From openjdk-jdk8u-backup with 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 #12
Source File: ContextActionInjectTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testContextAction() throws Exception {
    Context.cnt = 0;
    
    FileObject fo = FileUtil.getConfigFile(
        "actions/support/test/testInjectContext.instance"
    );
    assertNotNull("File found", fo);
    Object obj = fo.getAttribute("instanceCreate");
    assertNotNull("Attribute present", obj);
    assertTrue("It is context aware action", obj instanceof ContextAwareAction);
    ContextAwareAction a = (ContextAwareAction)obj;

    InstanceContent ic = new InstanceContent();
    AbstractLookup lkp = new AbstractLookup(ic);
    Action clone = a.createContextAwareInstance(lkp);
    ic.add(10);

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

    ic.remove(10);
    clone.actionPerformed(new ActionEvent(this, 200, ""));
    assertEquals("Global Action stays same", 10, Context.cnt);
}
 
Example #13
Source File: JPQLExternalEditorController.java    From jeddict with Apache License 2.0 6 votes vote down vote up
public void init() {
    JPQLEditorTopComponent editorTopComponent = new JPQLEditorTopComponent(this);
    editorTopComponent.open();
    editorTopComponent.requestActive();
    editorTopComponent.setFocusToEditor();

    try {
        InstanceContent lookupContent = new InstanceContent();
        lookupContent.add(pud);
        AbstractLookup lookup = new AbstractLookup(lookupContent);
        AbstractNode node = new AbstractNode(Children.LEAF, lookup);
        editorTopComponent.fillPersistenceConfigurations(new Node[]{node});
    } catch (Exception ex) {
        modelerFile.handleException(ex);
    }
}
 
Example #14
Source File: ActionInvocationTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testRenameAction() throws InterruptedException, InvocationTargetException, 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 rename = RefactoringActionsFactory.renameAction().createContextAwareInstance(lookup);
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            if (rename.isEnabled()) {
                rename.actionPerformed(RefactoringActionsFactory.DEFAULT_EVENT);
                if (!((RenameRefactoring) DD.rui.getRefactoring()).getRefactoringSource().lookup(FileObject.class).equals(f))
                    fail("Rename dialog was opened with wrong data");
            } else {
                fail("Action is not enabled.");
            }
        }
    });
}
 
Example #15
Source File: ContextManagerTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@RandomlyFails
public void testListenerGCedAfterActionGCed () throws Exception {
    InstanceContent ic = new InstanceContent();
    lkp = new AbstractLookup(ic);
    Lookup.Result<Integer> lookupResult = lkp.lookupResult(Integer.class);

    Action action = ((ContextAwareAction) Actions.forID("cat", "survive")).createContextAwareInstance(lkp);
    Action fallbackAction = ((GeneralAction.DelegateAction) action).fallback;
    WeakReference<Action> fallbackActionRef = new WeakReference<Action>(fallbackAction);
    WeakReference<Action> clone = new WeakReference<Action>(action);
    cm = ContextManager.findManager(lkp, true);
    WeakReference lsetRef = new WeakReference<Object>(cm.findLSet(Integer.class));

    // both delegate and delegating actions are GCed before WeakListenerSupport is triggered in ActiveRefQueue:
    // fallbackAction.removePropertyChangeListener(delegating.weakL);
    fallbackAction = null;
    action = null;
    assertGC("Action should be GCed", clone);

    assertGC("Fallback action should be GCed", fallbackActionRef);
    assertGC("Action LSet Should be GCed", lsetRef);
    lookupResult.allInstances();
}
 
Example #16
Source File: RestServiceNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private RestServiceNode(Project project, RestServicesModel model,
        final RestServiceDescription desc, InstanceContent content) {
    super(new RestServiceChildren(project, model, desc.getName()), new AbstractLookup(content));
    this.serviceName = desc.getName();
    this.uriTemplate = desc.getUriTemplate();
    this.className = desc.getClassName();
    
    content.add(this);
    content.add(desc);
    content.add(new ResourceUriProvider() {
        public String getResourceUri() {
            return desc.getUriTemplate();
        }           
    });
    content.add(project);
    content.add(OpenCookieFactory.create(project, className));
    editorDrop = new ResourceToEditorDrop(this);
}
 
Example #17
Source File: ActionProcessorTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testContextAction() throws Exception {
    Action a = Actions.forID("Tools", "on.int");
    assertTrue("It is context aware action", a instanceof ContextAwareAction);

    InstanceContent ic = new InstanceContent();
    AbstractLookup lkp = new AbstractLookup(ic);
    Action clone = ((ContextAwareAction) a).createContextAwareInstance(lkp);
    NumberLike ten = new NumberLike(10);
    ic.add(ten);

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

    ic.remove(ten);
    clone.actionPerformed(new ActionEvent(this, 200, ""));
    assertEquals("Global Action stays same", 10, Context.cnt);
}
 
Example #18
Source File: CompilerOptionsQueryMergerTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testLkpEvents() {
    final CompilerOptionsQueryImpl impl1 = new CompilerOptionsQueryImpl();
    final CompilerOptionsQueryImpl impl2 = new CompilerOptionsQueryImpl();
    impl1.addRoot(root1).addArgs("a1", "a2");   //NOI18N
    impl2.addRoot(root1).addArgs("b1", "b2");   //NOI18N

    final InstanceContent ic = new InstanceContent();
    final Lookup baseLkp = new AbstractLookup(ic);
    final CompilerOptionsQueryImplementation merged =
            LookupMergerSupport.createCompilerOptionsQueryMerger()
            .merge(baseLkp);
    assertNull(merged.getOptions(root1));
    ic.add(impl1);
    final CompilerOptionsQueryImplementation.Result res = merged.getOptions(root1);
    assertEquals(
            Arrays.asList("a1","a2"), //NOI18N
            res.getArguments());
    final MockChangeListener listener = new MockChangeListener();
    res.addChangeListener(listener);
    ic.add(impl2);
    listener.assertEventCount(1);
    assertEquals(
            Arrays.asList("a1","a2","b1","b2"), //NOI18N
            res.getArguments());
}
 
Example #19
Source File: FolderRenameHandlerImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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);
        }
    }
}
 
Example #20
Source File: GraphNode.java    From constellation with Apache License 2.0 6 votes vote down vote up
/**
 * Private constructor: recommended pattern for using InstanceContent.
 *
 * @param content This object's Lookup.
 * @param graph The Graph.
 * @param gdo The GraphDataObject.
 * @param visual The visual interface to the graph.
 * @param tc The graph's TopComponent.
 */
private GraphNode(final InstanceContent content, final Graph graph, final GraphDataObject gdo, final TopComponent tc, final VisualManager visualManager) {
    super(Children.LEAF, new AbstractLookup(content));
    content.add(graph);
    content.add(this);
    this.graph = graph;
    this.visualManager = visualManager;
    this.gdo = gdo;
    this.undoRedoManager = new UndoRedo.Manager();
    this.tc = tc;

    graph.setUndoManager(undoRedoManager);

    GRAPHS.put(graph.getId(), GraphNode.this);

    for (GraphManagerListener listener : LISTENERS) {
        listener.graphOpened(graph);
    }

    MemoryManager.newObject(GraphNode.class);
}
 
Example #21
Source File: ClassPathProviderMergerTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testMissingEvents() throws Exception {
    InstanceContent ic = new InstanceContent();
    Lookup lookup = new AbstractLookup(ic);
    ProviderImpl defaultCP = new ProviderImpl();

    final URL root1 = FileUtil.urlForArchiveOrDir(FileUtil.normalizeFile(new File(getWorkDir(),"root1")));
    final URL root2 = FileUtil.urlForArchiveOrDir(FileUtil.normalizeFile(new File(getWorkDir(),"root2")));
    final MutableCPImpl cpImpl = new MutableCPImpl(root1);

    defaultCP.paths.put(ClassPath.COMPILE, ClassPathFactory.createClassPath(cpImpl));
    ClassPathProviderMerger instance = new ClassPathProviderMerger(defaultCP);
    ClassPathProvider result = instance.merge(lookup);

    ClassPath compile = result.findClassPath(null, ClassPath.COMPILE);
    assertNotNull(compile);
    assertEquals(1, compile.entries().size());

    cpImpl.add(root2);
    assertEquals(2, compile.entries().size());
}
 
Example #22
Source File: MultiViewEditorElementTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testLookupProvidersAreConsistent() throws Exception {
    InstanceContent ic = new InstanceContent();
    Lookup context = new AbstractLookup(ic);

    CloneableEditorSupport ces = createSupport(context);
    ic.add(ces);
    ic.add(10);

    final CloneableTopComponent tc = MultiViews.createCloneableMultiView("text/plaintest", new LP(context));
    final CloneableEditorSupport.Pane p = (CloneableEditorSupport.Pane) tc;
    EventQueue.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            tc.open();
            tc.requestActive();
            p.updateName();
        }
    });

    assertNull("No icon yet", tc.getIcon());
    MultiViewHandler handler = MultiViews.findMultiViewHandler(tc);
    final MultiViewPerspective[] one = handler.getPerspectives();
    assertEquals("Two elements only" + Arrays.asList(one), 2, handler.getPerspectives().length);
    assertEquals("First one is source", "source", one[0].preferredID());
    assertEquals("Second one is also source", "source", one[1].preferredID());
    handler.requestVisible(one[0]);
    
    List<Lookup.Provider> arr = new ArrayList<Provider>();
    findProviders(tc, arr);
    assertEquals("Two providers: " + arr, 2, arr.size());

    assertSame("Both return same lookup", arr.get(0).getLookup(), arr.get(1).getLookup());
}
 
Example #23
Source File: FeatureManager.java    From netbeans with 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 File: ContextActionInjectTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testMultiContextAction() throws Exception {
    MultiContext.cnt = 0;
    
    FileObject fo = FileUtil.getConfigFile(
        "actions/support/test/testInjectContextMulti.instance"
    );
    assertNotNull("File found", fo);
    Object obj = fo.getAttribute("instanceCreate");
    assertNotNull("Attribute present", obj);
    assertTrue("It is context aware action", obj instanceof ContextAwareAction);
    ContextAwareAction a = (ContextAwareAction)obj;

    InstanceContent ic = new InstanceContent();
    AbstractLookup lkp = new AbstractLookup(ic);
    Action clone = a.createContextAwareInstance(lkp);
    ic.add(10);
    ic.add(3L);

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

    ic.remove(10);
    clone.actionPerformed(new ActionEvent(this, 200, ""));
    assertEquals("Adds 3", 16, MultiContext.cnt);

    ic.remove(3L);
    assertFalse("It is disabled", clone.isEnabled());
    clone.actionPerformed(new ActionEvent(this, 200, ""));
    assertEquals("No change", 16, MultiContext.cnt);
}
 
Example #25
Source File: XMLCESTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    MockLookup.init();
    final InstanceContent ic = new InstanceContent();
    lkp = new AbstractLookup(ic);
    ic.add("", this);
}
 
Example #26
Source File: MIMESupportTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Lookup getInstanceLookup(final Object... instances) {
    InstanceContent instanceContent = new InstanceContent();
    for(Object i : instances) {
        instanceContent.add(i);
    }
    Lookup instanceLookup = new AbstractLookup(instanceContent);
    return instanceLookup;
}
 
Example #27
Source File: CategoryNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private CategoryNode( Node originalNode, InstanceContent content, Lookup lkp ) {
    super( originalNode, 
           new Children( originalNode, lkp ),
           new ProxyLookup( new Lookup[] { lkp, new AbstractLookup(content), originalNode.getLookup() } ) );
    
    DataFolder folder = (DataFolder)originalNode.getCookie( DataFolder.class );
    if( null != folder ) {
        content.add( new DataFolder.Index( folder, this ) );
        FileObject fob = folder.getPrimaryFile();
        Object catName = fob.getAttribute( CAT_NAME );
        if (catName instanceof String)
            setDisplayName((String)catName);
    }
    content.add( this );
}
 
Example #28
Source File: SubResourceLocatorNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private SubResourceLocatorNode(Project project, String className, SubResourceLocator method,
        InstanceContent content) {
    super(Children.LEAF, new AbstractLookup(content));
    this.methodName = method.getName();
    this.uriTemplate = method.getUriTemplate();
    this.returnType = method.getReturnType();
    
    content.add(this);
    content.add(OpenCookieFactory.create(project, className, methodName));
}
 
Example #29
Source File: InstantRenameAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void doFullRename(EditorCookie ec, Node n) {
    InstanceContent ic = new InstanceContent();
    ic.add(ec);
    ic.add(n);

    Lookup actionContext = new AbstractLookup(ic);

    Action a =
        RefactoringActionsFactory.renameAction().createContextAwareInstance(actionContext);
    a.actionPerformed(RefactoringActionsFactory.DEFAULT_EVENT);
}
 
Example #30
Source File: ClassPathProviderMergerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public final void testPropagatesFlags() throws IOException {
    InstanceContent ic = new InstanceContent();
    Lookup lookup = new AbstractLookup(ic);
    final URL root1 = FileUtil.urlForArchiveOrDir(FileUtil.normalizeFile(new File(getWorkDir(),"root1")));
    final URL root2 = FileUtil.urlForArchiveOrDir(FileUtil.normalizeFile(new File(getWorkDir(),"root2")));

    ProviderImpl defaultCP = new ProviderImpl();
    final MutableCPImpl cpImpl = new MutableCPImpl(root1);
    defaultCP.paths.put(ClassPath.COMPILE, ClassPathFactory.createClassPath(cpImpl));
    ClassPathProviderMerger instance = new ClassPathProviderMerger(defaultCP);
    ClassPathProvider result = instance.merge(lookup);

    ClassPath compile = result.findClassPath(null, ClassPath.COMPILE);
    assertNotNull(compile);
    assertEquals(0, compile.getFlags().size());

    final ProviderImpl additional = new ProviderImpl();
    final MutableCPImpl addCpImpl = new MutableCPImpl(root2);
    addCpImpl.add(ClassPath.Flag.INCOMPLETE);
    additional.paths.put(ClassPath.COMPILE, ClassPathFactory.createClassPath(addCpImpl));
    ic.add(additional);

    assertEquals(1, compile.getFlags().size());
    assertSame(compile, result.findClassPath(null, ClassPath.COMPILE));
    
    addCpImpl.remove(ClassPath.Flag.INCOMPLETE);
    assertEquals(0, compile.getFlags().size());
    addCpImpl.add(ClassPath.Flag.INCOMPLETE);
    assertEquals(1, compile.getFlags().size());
}