Java Code Examples for org.openide.nodes.Node.getActions()

The following are Jave code examples for showing how to use getActions() of the org.openide.nodes.Node class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: UnitTestLibrariesNodeTest.java   Source Code and License Vote up 6 votes
public void testActions() throws Exception{
    assertNotNull("have the Libraries node", libsNode);
    //test removedep action
    addTestDependency(p);
    String depName = p.getModuleList().getEntry(DEP_CNB).getCodeNameBase();
    forceChildrenUpdate(libsNode);
    Node depNode = libsNode.getChildren().findChild(depName);
    assertNotNull("have a node with dependency", depNode);
    Action[] act = depNode.getActions(false);
    assertEquals("have three actions", 3, act.length);
    RemoveDependencyAction removeAct = (RemoveDependencyAction) act[2];
    assertEquals("nc+1 nodes now", nc+1, libsNode.getChildren().getNodes().length);
    removeAct.performAction(new Node[] {depNode});
    forceChildrenUpdate(libsNode);
    assertEquals("nc nodes now, dep removed", nc, libsNode.getChildren().getNodes().length);
}
 
Example 2
Project: incubator-netbeans   File: DefaultDataObjectHasOpenActionTest.java   Source Code and License Vote up 6 votes
public void testOpenActionIsAlwaysFirst() throws Exception {
    Node n = obj.getNodeDelegate();

    Action openAction = Actions.forID("System", "org.openide.actions.OpenAction");

    assertEquals(
            "Open action is the default one",
            openAction,
            n.getPreferredAction()
            );

    Action[] actions = n.getActions(false);
    assertTrue("There are some actions", actions.length > 1);

    assertEquals(
            "First one is open",
            openAction,
            actions[0]
            );
}
 
Example 3
Project: incubator-netbeans   File: BasicTest.java   Source Code and License Vote up 6 votes
private void checkNode (Node n, String name, RequestProcessor rp) {
    // init
    //assertEquals (null, n.getShortDescription ());
    Node[] ns = n.getChildren ().getNodes ();
    waitFinished (rp);
    
    ns = n.getChildren ().getNodes ();
    if (name.length () < 4) {
        assertEquals (name, 3, ns.length);
        checkNode (ns [0], name + "a", rp);
        checkNode (ns [1], name + "b", rp);
        checkNode (ns [2], name + "c", rp);
    } else
        assertEquals (ns.length, 0);
    
    if (name.length () > 0) {
        //assertEquals (name, n.getName ());
        n.getDisplayName ();
        String sd = n.getShortDescription ();
        n.getActions (false);
        waitFinished (rp);
        assertEquals (name, n.getDisplayName ());
        assertEquals (name + "WWW", sd);
        assertEquals (1, n.getActions (false).length);
    }
}
 
Example 4
Project: incubator-netbeans   File: DataLoaderGetActionsTest.java   Source Code and License Vote up 5 votes
/**
 * This test checks whether the JSeparator added from the configuration
 * file is reflected in the resulting popup.
 * The tests performs following steps:
 * <OL><LI> Create an instance of ExtensibleNode with folder set to "test"
 *     <LI> No actions should be returned by getActions since the "test" folder
 *          is not there
 *     <LI> Create two actions in the testing folder separated by JSeparator
 *     <LI> getActions should return 3 elements - null element for the separator
 *     <LI> Popup is created from the actions array - the null element
 *              should be replaced by a JSeparator again
 * </OL>
 */
public void testAddingSeparators() throws Exception {
    Node en1 = node;
    assertEquals("No actions at the start", 0, en1.getActions(false).length);
    FileObject test = root;
    FileObject a1 = test.createData("1[org-openide-actions-PropertiesAction].instance");
    FileObject sep = test.createData("2[javax-swing-JSeparator].instance");
    FileObject a2 = test.createData("3[org-openide-actions-CutAction].instance");
    Action[] actions = en1.getActions(false);
    assertEquals("Actions array should contain 3 elements: "+Arrays.asList(actions), 3, actions.length);
    assertNull("separator should create null element in the array", actions[1]);
    javax.swing.JPopupMenu jp = Utilities.actionsToPopup(actions, Lookups.singleton(en1));
    assertEquals("Popup should contain 3 components", 3, jp.getComponentCount());
    assertTrue("Separator should be second", jp.getComponent(1) instanceof JSeparator);
}
 
Example 5
Project: incubator-netbeans   File: AsynchronousTest.java   Source Code and License Vote up 5 votes
private void inspectNode(Node n) {
    n.getDisplayName();
    n.getHtmlDisplayName();
    n.getShortDescription();
    n.getIcon(BeanInfo.ICON_COLOR_16x16);
    n.canCopy();
    n.canCut();
    n.canRename();
    n.getNewTypes();
    n.getActions(true);
    n.getPreferredAction();
    inspectProperties(n);
}
 
Example 6
Project: incubator-netbeans   File: DataLoaderInLayerTest.java   Source Code and License Vote up 4 votes
public void testFactoryInstanceRegistrationWorksAsWell() throws Exception {
    URL u = DataLoaderInLayerTest.class.getResource("/org/openide/loaders/saveAll.gif");
    Image img = Toolkit.getDefaultToolkit().createImage(u);
    
    DataObject.Factory f = DataLoaderPool.factory(SimpleDataObject.class, "text/simplefactory", img);
    
    addRemove("text/plain", f, true);
    try {
        FileSystem lfs = createFS("folderFKK/file.simple");
        FileObject fo = lfs.findResource("folderFKK");
        DataFolder df = DataFolder.findFolder(fo);
        DataObject[] arr = df.getChildren();
        assertEquals("One object: " + Arrays.toString(arr), 1, arr.length);
        DataObject dob = arr[0];
        assertEquals(SimpleDataObject.class, dob.getClass());
        
        FileObject root = FileUtil.getConfigRoot();
        FileObject edit = FileUtil.createData(root, "/Loaders/text/simplefactory/Actions/org-openide-actions-EditAction.instance");
        
        Node node = dob.getNodeDelegate();
        Action[] actions = node.getActions(true);
        assertEquals("One action is present: " + Arrays.asList(actions), 1, actions.length);
        assertEquals("It is the edit one", EditAction.class, actions[0].getClass());
        
        assertSame("Icon is propagated for open", img, node.getOpenedIcon(0));
        assertSame("Icon is propagated", img, node.getIcon(0));
        
        Reference<DataFolder> ref = new WeakReference<DataFolder>(df);
        df = null;
        assertGC("Folder can go away", ref);
        
        df = DataFolder.findFolder(fo);
        arr = df.getChildren();
        assertEquals("One object", 1, arr.length);
        assertEquals("Object is the same", dob, arr[0]);

        DataObject copied = dob.copy(df);
        assertEquals(SimpleDataObject.class, copied.getClass());

        DataObject templ = dob.createFromTemplate(df, "ahoj");
        assertEquals(SimpleDataObject.class, templ.getClass());
        assertEquals("ahoj", templ.getName());

        DataObject ren = dob.copyRename(df, "kuk", "simple");
        assertEquals(SimpleDataObject.class, ren.getClass());
        assertEquals("kuk", ren.getName());
    } finally {
        addRemove("text/plain", f, false);
    }
}
 
Example 7
Project: incubator-netbeans   File: DataLoaderInLayerTest.java   Source Code and License Vote up 4 votes
public void testFactoryInstanceRegistrationWorksAsWellNowFromLayer() throws Exception {
    URL u = DataLoaderInLayerTest.class.getResource("/org/openide/loaders/saveAll.gif");
    FileObject root = FileUtil.getConfigRoot();
    FileObject instance = FileUtil.createData(root, "TestLoaders/text/L.instance");
    instance.setAttribute("dataObjectClass", SimpleDataObject.class.getName());
    instance.setAttribute("mimeType", "text/simplefactory");
    instance.setAttribute("SystemFileSystem.icon", u);
    
    
    Image img = ImageUtilities.loadImage("org/openide/loaders/saveAll.gif");
    
    DataObject.Factory f = DataLoaderPool.factory(instance);
    
    addRemove("text/plain", f, true);
    try {
        FileSystem lfs = createFS("folderQ/file.simple");
        FileObject fo = lfs.findResource("folderQ");
        DataFolder df = DataFolder.findFolder(fo);
        DataObject[] arr = df.getChildren();
        assertEquals("One object", 1, arr.length);
        DataObject dob = arr[0];
        assertEquals(SimpleDataObject.class, dob.getClass());
        
        FileObject edit = FileUtil.createData(root, "/Loaders/text/simplefactory/Actions/org-openide-actions-EditAction.instance");
        
        Node node = dob.getNodeDelegate();
        Action[] actions = node.getActions(true);
        assertEquals("One action is present: " + Arrays.asList(actions), 1, actions.length);
        assertEquals("It is the edit one", EditAction.class, actions[0].getClass());
        
        assertImage("Icon is propagated for open", img, node.getOpenedIcon(0));
        assertImage("Icon is propagated", img, node.getIcon(0));
        
        Reference<DataFolder> ref = new WeakReference<DataFolder>(df);
        df = null;
        assertGC("Folder can go away", ref);
        
        df = DataFolder.findFolder(fo);
        arr = df.getChildren();
        assertEquals("One object", 1, arr.length);
        assertEquals("Object is the same", dob, arr[0]);
    } finally {
        addRemove("text/plain", f, false);
    }
}