Java Code Examples for org.openide.nodes.Node#getPreferredAction()

The following examples show how to use org.openide.nodes.Node#getPreferredAction() . 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: DefaultActionTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void invokeDefaultAction (final TopComponent tc) {
    performed = false;
    try {
        Node[] nodes = tc.getActivatedNodes ();
        assertNotNull ("View has the active nodes.", nodes);
        Node n = nodes.length > 0 ? nodes[0] : null;
        assertNotNull ("View has a active node.", n);
        
        final Action action = n.getPreferredAction ();
        action.actionPerformed (new ActionEvent (n, ActionEvent.ACTION_PERFORMED, ""));
        
        // wait to invoke action is propagated
        Thread.sleep (300);
    } catch (Exception x) {
        fail (x.getMessage ());
    }
}
 
Example 2
Source File: HandleLayer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean processDoubleClick(MouseEvent e) {
    if (e.isShiftDown() || e.isControlDown() || e.isMetaDown()) {
        return false;
    }

    RADComponent metacomp = getMetaComponentAt(e.getPoint(), COMP_SELECTED);
    if (metacomp == null) {
        return true;
    }

    if (e.isAltDown()) {
        if (metacomp == formDesigner.getTopDesignComponent()) {
            metacomp = metacomp.getParentComponent();
            if (metacomp == null) {
                return true;
            }
        } else {
             return false;
        }
    }

    Node node = metacomp.getNodeReference();
    if (node != null) {
        Action action = node.getPreferredAction();
        if (action != null) {// && action.isEnabled()) {
            action.actionPerformed(new ActionEvent(
                    node, ActionEvent.ACTION_PERFORMED, "")); // NOI18N
            prevLeftMousePoint = null; // to prevent inplace editing on mouse release
            return true;
        }
    }

    return false;
}
 
Example 3
Source File: Installer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void showProfilerSnapshot(ActionEvent e){
     File tempFile = null;
     try { 
         tempFile = File.createTempFile("selfsampler", ".npss"); // NOI18N
         tempFile = FileUtil.normalizeFile(tempFile);
         try (OutputStream os = new FileOutputStream(tempFile)) {
             os.write(slownData.getNpsContent());
         }

         File varLogs = logsDirectory();
         File gestures = (varLogs != null) ? new File(varLogs, "uigestures") : null; // NOI18N

         SelfSampleVFS fs;
         if (gestures != null && gestures.exists()) {
             fs = new SelfSampleVFS(
                     new String[]{"selfsampler.npss", "selfsampler.log"},
                     new File[]{tempFile, gestures});
         } else {
             fs = new SelfSampleVFS(
                     new String[]{"selfsampler.npss"},
                     new File[]{tempFile});
         }
         FileObject fo = fs.findResource("selfsampler.npss");
         final Node obj = DataObject.find(fo).getNodeDelegate();
         Action a = obj.getPreferredAction();
         if (a instanceof ContextAwareAction) {
             a = ((ContextAwareAction)a).createContextAwareInstance(obj.getLookup());
         }
         a.actionPerformed(e);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    } finally {
        if (tempFile != null) tempFile.deleteOnExit();
    }
}
 
Example 4
Source File: TemplateWizard.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Instantiates the template using informations provided by
* the wizard.
*
* @param wiz the wizard
* @return set of data objects that has been created (should contain
*   at least one) 
* @exception IOException if the instantiation fails
*/
public Set<DataObject> instantiate(TemplateWizard wiz) throws IOException {
    String n = wiz.getTargetName ();
    DataFolder folder = wiz.getTargetFolder ();
    DataObject template = wiz.getTemplate ();
    Map<String,Object> wizardProps = new HashMap<String, Object>();
    for (Map.Entry<String, ? extends Object> entry : wiz.getProperties().entrySet()) {
        wizardProps.put("wizard." + entry.getKey(), entry.getValue()); // NOI18N
    }
    
    DataObject obj = template.createFromTemplate (folder, n, wizardProps);

    // run default action (hopefully should be here)
    final Node node = obj.getNodeDelegate ();
    Action _a = node.getPreferredAction();
    if (_a instanceof ContextAwareAction) {
        _a = ((ContextAwareAction) _a).createContextAwareInstance(node.getLookup());
    }
    final Action a = _a;
    if (a != null) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                a.actionPerformed(new ActionEvent(node, ActionEvent.ACTION_PERFORMED, "")); // NOI18N
            }
        });
    }

    return Collections.singleton(obj);
}
 
Example 5
Source File: UpdateResultsTable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void performOpenInEditorAction(Node node) {
    // XXX how is this supposed to work ???
    Action action = node.getPreferredAction();
    if (action == null || !action.isEnabled()) action = new OpenInEditorAction();
    if (action.isEnabled()) {
        action.actionPerformed(new ActionEvent(this, 0, "")); // NOI18N
    }
}
 
Example 6
Source File: AsynchronousTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 7
Source File: ListView.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** This method is called when user double-clicks on some object or
* presses Enter key.
* @param index Index of object in current explored context
*/
final void performObjectAt(int index, int modifiers) {
    if ((index < 0) || (index >= model.getSize())) {
        return;
    }

    VisualizerNode v = (VisualizerNode) model.getElementAt(index);
    Node node = v.node;

    // if DefaultProcessor is set, the default action is notified to it overriding the default action on nodes
    if (defaultProcessor != null) {
        defaultProcessor.actionPerformed(new ActionEvent(node, 0, null, modifiers));

        return;
    }

    if (showParentNode && NodeListModel.findVisualizerDepth(model, v) == -1) {
        try {
            manager.setExploredContextAndSelection(node.getParentNode(), new Node[] { node });
        } catch (PropertyVetoException ex) {
            // OK, let it be
        }
        return;
    }

    // on double click - invoke default action, if there is any
    // (unless user holds CTRL key what means that we should always dive into the context)
    Action a = node.getPreferredAction();

    if ((a != null) && ((modifiers & InputEvent.CTRL_MASK) == 0)) {
        a = TreeView.takeAction(a, node);

        if (a.isEnabled()) {
            a.actionPerformed(new ActionEvent(node, ActionEvent.ACTION_PERFORMED, "")); // NOI18N
        } else {
            Utilities.disabledActionBeep();
        }
    }
    // otherwise dive into the context
    else if (traversalAllowed && (!node.isLeaf())) {
        manager.setExploredContext(node, manager.getSelectedNodes());
    }
}
 
Example 8
Source File: DefaultOpenFileImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void openInEDT(FileObject fileObject, DataObject dataObject, int line) {
    Class<? extends Node.Cookie> cookieClass;        
    Node.Cookie cookie;
    
    if ((line != -1)
        && (   ((cookie = dataObject.getCookie(cookieClass = EditorCookie.Observable.class)) != null)
            || ((cookie = dataObject.getCookie(cookieClass = EditorCookie.class)) != null) )) {
        boolean ret = openByCookie(cookie, cookieClass, line);
        if (!ret) {
            showNotPlainFileWarning(fileObject);
        }
        return;
    } 
                        
    /* try to open the object using the default action */
    Node dataNode = dataObject.getNodeDelegate();        
    Action action = dataNode.getPreferredAction();
    if ((action != null)
            && !(action instanceof FileSystemAction)
            && !(action instanceof ToolsAction)) {
        if (log.isLoggable(FINEST)) {
            log.log(FINEST, " - using preferred action "            //NOI18N
                    + "(\"{0}\" - {1}) for opening the file",       //NOI18N
                    new Object[]{action.getValue(Action.NAME),
                        action.getClass().getName()});
        }

        if (action instanceof ContextAwareAction) {
            action = ((ContextAwareAction) action)
              .createContextAwareInstance(dataNode.getLookup());
            if (log.isLoggable(FINEST)) {
                log.finest("    - it is a ContextAwareAction");     //NOI18N
                log.log(FINEST, "    - using a context-aware "      //NOI18N
                        + "instance instead (\"{0}\" - {1})",       //NOI18N
                        new Object[]{action.getValue(Action.NAME),
                            action.getClass().getName()});
            }
        }

        log.finest("   - will call action.actionPerformed(...)");   //NOI18N
        final Action a = action;
        final Node n = dataNode;
        WindowManager.getDefault().invokeWhenUIReady(new Runnable() {

            @Override
            public void run() {
                a.actionPerformed(new ActionEvent(n, 0, ""));
            }
        });
        return;
    }             
    String fileName = fileObject.getNameExt();
    /* Try to grab an editor/open/edit/view cookie and open the object: */
    StatusDisplayer.getDefault().setStatusText(
            NbBundle.getMessage(DefaultOpenFileImpl.class,
                                "MSG_opening",                      //NOI18N
                                fileName));
    boolean success = openDataObjectByCookie(dataObject, line);
    if (success) {
        return;
    }        
    if (fileObject.isFolder() || FileUtil.isArchiveFile(fileObject)) {
        // select it in explorer:
        final Node node = dataObject.getNodeDelegate();
        if (node != null) {
            WindowManager.getDefault().invokeWhenUIReady(new Runnable() {

                @Override
                public void run() {
                    NodeOperation.getDefault().explore(node);
                }
            });
            return;
        }
    }
    showNotPlainFileWarning(fileObject);
}