/** * Generic method to invoke commands available from the menu bar. The actionName passed in is usually * the concatentaion of the words making the menu items: * e.g. performAction("FileOpen") is equivalent to picking the cascade menu File->Open Model * * @param actionName */ static public void performAction(String actionName) { FileObject myActionsFolder = FileUtil.getConfigFile("Actions/Edit"); FileObject[] myActionsFolderKids = myActionsFolder.getChildren(); for (FileObject fileObject : myActionsFolderKids) { //Probably want to make this more robust, //but the point is that here we find a particular Action: if (fileObject.getName().contains(actionName)) { try { DataObject dob = DataObject.find(fileObject); InstanceCookie ic = dob.getLookup().lookup(InstanceCookie.class); if (ic != null) { Object instance = ic.instanceCreate(); if (instance instanceof CallableSystemAction) { CallableSystemAction a = (CallableSystemAction) instance; a.performAction(); } } break; } catch (Exception e) { ErrorManager.getDefault().notify(ErrorManager.WARNING, e); } } } }
private boolean isMethodOverridden(NodeAction d, String name) { try { Method m = d.getClass().getMethod(name, new Class[0]); return m.getDeclaringClass() != CallableSystemAction.class; } catch (java.lang.NoSuchMethodException ex) { ex.printStackTrace(); throw new IllegalStateException("Error searching for method " + name + " in " + d); // NOI18N } }
private static JPopupMenu createPopupMenu(MergePanel panel) { JPopupMenu popup = new JPopupMenuPlus(); SystemAction[] actions = panel.getSystemActions(); for (int i = 0; i < actions.length; i++) { if (actions[i] == null) { popup.addSeparator(); } else if (actions[i] instanceof CallableSystemAction) { popup.add(((CallableSystemAction)actions[i]).getPopupPresenter()); //add FileSystemAction to pop-up menu } else if (actions[i] instanceof FileSystemAction) { popup.add(((FileSystemAction)actions[i]).getPopupPresenter()); } } return popup; }