List of usage examples for org.eclipse.jface.action IAction isEnabled
boolean isEnabled();
From source file:ca.usask.cs.srlab.simclipse.clone.comparison.CloneCompareAction.java
License:Open Source License
public void run(IAction action) { if (!action.isEnabled() || comparatorInput == null || view == null || selection == null) return;//from w ww.java2 s . c o m if (!(selection instanceof StructuredSelection)) return; if (!(((StructuredSelection) selection).getFirstElement() instanceof CloneSetDisplayModel)) return; IProject project = ((CloneSetDisplayModel) ((StructuredSelection) selection).getFirstElement()) .getParentProject().getProject(); List<IFile> tmpFileList = new ArrayList<IFile>( ((CloneSetDisplayModel) ((StructuredSelection) selection).getFirstElement()).size()); IFolder simclipseDataFolder = (IFolder) project.findMember(SimClipseConstants.SIMCLIPSE_DATA_FOLDER); IFolder simclipseTmpFolder = simclipseDataFolder.getFolder(SimClipseConstants.SIMCLIPSE_TMP_SRC_FOLDER); FileUtil.deleteDirectory(simclipseTmpFolder.getLocation().toFile()); for (ICloneViewItem cvi : ((CloneSetDisplayModel) ((StructuredSelection) selection).getFirstElement()) .getCloneFragmentModels()) { CloneFragmentDisplayModel clonefragment = (CloneFragmentDisplayModel) cvi; IFile originalIFile = (IFile) clonefragment.getResource(); LineNumberReader lineNumberReader = null; PrintWriter pwr = null; try { IPath originalIFilePath = originalIFile.getProjectRelativePath(); IFolder virtualForderToCreate = simclipseTmpFolder .getFolder(originalIFilePath.removeLastSegments(1)); IFile linkedVistualFile = (IFile) virtualForderToCreate.getFile(originalIFilePath .addFileExtension( "part(" + clonefragment.getFromLine() + "-" + clonefragment.getToLine() + ")") .lastSegment()); prepareVirtualFolder(virtualForderToCreate, true); //local filesystem IPath linkedActualFile = project.getLocation().removeLastSegments(1) .append(linkedVistualFile.getFullPath()); if (!linkedActualFile.removeLastSegments(1).toFile().exists()) { linkedActualFile.removeLastSegments(1).toFile().mkdirs(); } File partFile = linkedActualFile.toFile(); if (partFile.exists()) { partFile.delete(); } pwr = new PrintWriter(partFile); pwr.println(clonefragment.toShortString()); String line = null; lineNumberReader = new LineNumberReader(new FileReader(originalIFile.getLocation().toFile())); while ((line = lineNumberReader.readLine()) != null) { int lineNumber = lineNumberReader.getLineNumber(); if (lineNumber >= clonefragment.getFromLine() && lineNumber <= clonefragment.getToLine()) { pwr.println(line); } } pwr.close(); partFile.setReadOnly(); partFile.setWritable(false); partFile.deleteOnExit(); try { linkedVistualFile.createLink(partFile.toURI(), IResource.REPLACE | IResource.HIDDEN, null); } catch (CoreException e) { e.printStackTrace(); } IFile newIFile = (IFile) project.findMember(linkedActualFile.makeRelativeTo(project.getLocation())); tmpFileList.add(newIFile); } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } finally { //Close the BufferedWriter try { if (lineNumberReader != null) { lineNumberReader.close(); } if (pwr != null) pwr.close(); } catch (IOException ex) { ex.printStackTrace(); } } } selection = new StructuredSelection(tmpFileList); boolean ok = comparatorInput.setSelection(selection, view.getSite().getShell(), showSelectAncestorDialog); if (!ok) return; try { comparatorInput.initializeCompareConfiguration(); CompareUI.openCompareEditorOnPage(comparatorInput, fWorkbenchPage); comparatorInput = null; // don't reuse this input! } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } }
From source file:com.aptana.ide.debug.internal.ui.actions.WatchAction.java
License:Open Source License
/** * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, * org.eclipse.jface.viewers.ISelection) *///ww w . ja v a 2 s .c o m public void selectionChanged(IAction action, ISelection selection) { fSelection = null; if (!action.isEnabled()) { return; } int enabled = 0; int size = -1; if (selection instanceof IStructuredSelection) { fSelection = selection; IStructuredSelection sSelection = (IStructuredSelection) selection; size = sSelection.size(); IExpressionManager manager = DebugPlugin.getDefault().getExpressionManager(); Iterator iterator = sSelection.iterator(); while (iterator.hasNext()) { IVariable variable = (IVariable) iterator.next(); if (manager.hasWatchExpressionDelegate(variable.getModelIdentifier())) { enabled++; } else { break; } } if (enabled != size) { action.setEnabled(false); } } else if (selection instanceof ITextSelection) { fSelection = selection; ITextSelection tSelection = (ITextSelection) selection; if (tSelection.getLength() == 0) { action.setEnabled(false); } } }
From source file:com.aptana.ide.server.ui.views.GenericServersView.java
License:Open Source License
/** * Creates and registers the context menu *///w w w . ja v a2 s . co m private void createPopupMenu() { deleteAction = ActionFactory.DELETE.create(getViewSite().getWorkbenchWindow()); MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ menuMgr.setRemoveAllWhenShown(true); getViewSite().getActionBars().setGlobalActionHandler(ActionFactory.DELETE.getId(), new Action() { public void run() { doDelete(); } }); menuMgr.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager manager) { IContributionItem[] items = getViewSite().getActionBars().getToolBarManager().getItems(); for (int i = 0; i < items.length; i++) { if (items[i] instanceof ActionContributionItem) { ActionContributionItem aci = (ActionContributionItem) items[i]; IAction action = aci.getAction(); if (action == openLog) { // adds the Open Log action to the context menu as a push button instead of // drop-down boolean enabled = action.isEnabled(); action = new OpenLogAction(serverViewer, Action.AS_PUSH_BUTTON); action.setEnabled(enabled); } if (action.isEnabled() && action.getStyle() != Action.AS_DROP_DOWN_MENU) { if (action.getText() == null || action.getText().length() == 0) { action.setText(action.getToolTipText()); } manager.add(action); } } else { if (items[i] instanceof Separator) { manager.add(new Separator()); } } } manager.add(new Separator()); IStructuredSelection selection = (IStructuredSelection) serverViewer.getSelection(); final IServer server = (IServer) selection.getFirstElement(); if (server != null) { deleteAction.setText(StringUtils.format(Messages.ServersView_DELETE, getShortenName(server))); // deleteAction.setEnabled(server.getServerState() == IServer.STATE_STOPPED); deleteAction.setEnabled(server.canDelete().isOK()); manager.add(deleteAction); Action action = new Action() { public void run() { doEdit(server); } }; action.setText(StringUtils.format(Messages.ServersView_EDIT, getShortenName(server))); IStatus canModify = server.canModify(); IStatus canModifyInStoppedStateOnly = server.canModifyInStoppedStateOnly(); action.setEnabled(((canModifyInStoppedStateOnly == null || canModifyInStoppedStateOnly.getCode() == IStatus.OK) ? server.getServerState() == IServer.STATE_STOPPED : true) && (canModify == null || canModify.getCode() == IStatus.OK)); manager.add(action); } // deleteAction.setEnabled(!selection.isEmpty()); manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); // Allow } private String getShortenName(final IServer server) { String name = server.getName(); int length = name.length(); if (length > MAX_SHOWN_SERVER_NAME) { int delta = (length - 15) / 2; int pivot = length / 2; int start = pivot - delta; int end = pivot + delta; String s1 = name.substring(0, start); String s2 = name.substring(end, length); String s = s1 + ELLIPSIS + s2; return s; } return name; } }); Menu menu = menuMgr.createContextMenu(serverViewer.getControl()); serverViewer.getControl().setMenu(menu); getSite().registerContextMenu(menuMgr, serverViewer); }
From source file:com.aptana.js.debug.ui.internal.actions.WatchAction.java
License:Open Source License
@SuppressWarnings("rawtypes") public void selectionChanged(IAction action, ISelection selection) { fSelection = null;// w w w .j a va 2 s . c o m if (!action.isEnabled()) { return; } int enabled = 0; int size = -1; if (selection instanceof IStructuredSelection) { fSelection = selection; IStructuredSelection sSelection = (IStructuredSelection) selection; size = sSelection.size(); IExpressionManager manager = DebugPlugin.getDefault().getExpressionManager(); IVariable variable; for (Iterator iterator = sSelection.iterator(); iterator.hasNext();) { variable = (IVariable) iterator.next(); if (manager.hasWatchExpressionDelegate(variable.getModelIdentifier())) { enabled++; } else { break; } } if (enabled != size) { action.setEnabled(false); } } else if (selection instanceof ITextSelection) { fSelection = selection; ITextSelection tSelection = (ITextSelection) selection; if (tSelection.getLength() == 0) { action.setEnabled(false); } } }
From source file:com.arc.cdt.debug.seecode.internal.ui.action.AbstractDebugActionDelegate.java
License:Open Source License
@Override public void run(IAction action) { if (action.isEnabled()) { IStructuredSelection selection = getSelection(); // disable the action so it cannot be run again until an event or selection change // updates the enablement action.setEnabled(false);//from w w w.j a va 2 s . com if (isRunInBackground()) { runInBackground(action, selection); } else { runInForeground(selection); } } }
From source file:com.archimatetool.editor.diagram.AbstractDiagramEditorContextMenuProvider.java
License:Open Source License
/** * @see ContextMenuProvider#buildContextMenu(org.eclipse.jface.action.IMenuManager) *///w ww .ja v a2s.c o m @Override public void buildContextMenu(IMenuManager menu) { IAction action; menu.add(new Separator(GROUP_UNDO)); action = actionRegistry.getAction(ActionFactory.UNDO.getId()); menu.appendToGroup(GROUP_UNDO, action); action = actionRegistry.getAction(ActionFactory.REDO.getId()); menu.appendToGroup(GROUP_UNDO, action); menu.add(new Separator(GROUP_EDIT)); action = actionRegistry.getAction(ActionFactory.CUT.getId()); menu.appendToGroup(GROUP_EDIT, action); action = actionRegistry.getAction(ActionFactory.COPY.getId()); menu.appendToGroup(GROUP_EDIT, action); action = actionRegistry.getAction(ActionFactory.PASTE.getId()); menu.appendToGroup(GROUP_EDIT, action); action = actionRegistry.getAction(ActionFactory.DELETE.getId()); menu.appendToGroup(GROUP_EDIT, action); action = actionRegistry.getAction(LockObjectAction.ID); if (action.isEnabled()) { menu.appendToGroup(GROUP_EDIT, new Separator()); menu.appendToGroup(GROUP_EDIT, action); } menu.add(new Separator(GROUP_RENAME)); action = actionRegistry.getAction(ActionFactory.RENAME.getId()); menu.appendToGroup(GROUP_RENAME, action); // Select Element in Tree menu.appendToGroup(GROUP_RENAME, new Separator()); menu.appendToGroup(GROUP_RENAME, actionRegistry.getAction(SelectElementInTreeAction.ID)); menu.add(new Separator(GROUP_EXPORT)); IMenuManager exportMenu = new MenuManager(Messages.AbstractDiagramEditorContextMenuProvider_0, "menu_export"); //$NON-NLS-1$ menu.add(exportMenu); exportMenu.add(actionRegistry.getAction(ExportAsImageAction.ID)); exportMenu.add(actionRegistry.getAction(ExportAsImageToClipboardAction.ID)); menu.add(new Separator(GROUP_ORDER)); IMenuManager orderMenu = new MenuManager(Messages.AbstractDiagramEditorContextMenuProvider_1, "menu_order"); //$NON-NLS-1$ menu.add(orderMenu); orderMenu.add(actionRegistry.getAction(BringToFrontAction.ID)); orderMenu.add(actionRegistry.getAction(BringForwardAction.ID)); orderMenu.add(actionRegistry.getAction(SendToBackAction.ID)); orderMenu.add(actionRegistry.getAction(SendBackwardAction.ID)); menu.add(new GroupMarker(GROUP_POSITION)); IMenuManager alignmentMenu = new MenuManager(Messages.AbstractDiagramEditorContextMenuProvider_2, "menu_position"); //$NON-NLS-1$ menu.add(alignmentMenu); alignmentMenu.add(actionRegistry.getAction(GEFActionConstants.ALIGN_LEFT)); alignmentMenu.add(actionRegistry.getAction(GEFActionConstants.ALIGN_CENTER)); alignmentMenu.add(actionRegistry.getAction(GEFActionConstants.ALIGN_RIGHT)); alignmentMenu.add(new Separator()); alignmentMenu.add(actionRegistry.getAction(GEFActionConstants.ALIGN_TOP)); alignmentMenu.add(actionRegistry.getAction(GEFActionConstants.ALIGN_MIDDLE)); alignmentMenu.add(actionRegistry.getAction(GEFActionConstants.ALIGN_BOTTOM)); alignmentMenu.add(new Separator()); alignmentMenu.add(actionRegistry.getAction(GEFActionConstants.MATCH_WIDTH)); alignmentMenu.add(actionRegistry.getAction(GEFActionConstants.MATCH_HEIGHT)); alignmentMenu.add(new Separator()); alignmentMenu.add(actionRegistry.getAction(DefaultEditPartSizeAction.ID)); menu.add(new Separator(GROUP_CONNECTIONS)); IMenuManager connectionMenu = new MenuManager(Messages.AbstractDiagramEditorContextMenuProvider_3, "menu_connection_router"); //$NON-NLS-1$ menu.appendToGroup(GROUP_CONNECTIONS, connectionMenu); connectionMenu.add(actionRegistry.getAction(ConnectionRouterAction.BendPointConnectionRouterAction.ID)); connectionMenu.add(actionRegistry.getAction(ConnectionRouterAction.ShortestPathConnectionRouterAction.ID)); connectionMenu.add(actionRegistry.getAction(ConnectionRouterAction.ManhattanConnectionRouterAction.ID)); menu.add(new Separator(GROUP_PROPERTIES)); action = actionRegistry.getAction(ActionFactory.PROPERTIES.getId()); menu.add(action); }
From source file:com.architexa.diagrams.relo.jdt.actions.Script2Action.java
License:Open Source License
/** * @see IActionDelegate#run(IAction)//from w ww .ja v a 2 s.c o m */ public void run(IAction action) { try { //dumpMethodBody((IMethod) selList.get(0)); //System.err.println( // "trying to execute action: " // + action.getClass() // + " -- " // + action.getText()); //ReloPlugin // .getDefault() // .getWorkbench() // .getActiveWorkbenchWindow() // .getActivePage() // .openEditor(new ListEditorInput(selList), "com.architexa.diagrams.relo.editor"); IMethod method = (IMethod) selList.get(0); IFile file = (IFile) ((IMember) method).getCompilationUnit().getResource(); IWorkbenchPage page = getActivePage(); //IEditorDescriptor editorDesc = IDE.getEditorDescriptor(file); JavaEditorlet jelet = (JavaEditorlet) page.openEditor(new FileEditorInput(file), "com.architexa.diagrams.relo.jdt.JavaEditorlet", true); /* String editorId = "com.architexa.diagrams.relo.jdt.JavaEditorlet"; FileEditorInput input = new FileEditorInput(file); JavaEditorlet jelet = null; IEditorPart editor = null; // Remember the old visible editor IEditorPart oldVisibleEditor = page.getActiveEditor(); // Otherwise, create a new one. This may cause the new editor to // become the visible (i.e top) editor. IEditorReference ref = null; IEditorRegistry reg = WorkbenchPlugin.getDefault().getEditorRegistry(); EditorDescriptor desc = (EditorDescriptor) reg.findEditor(editorId); if (desc == null) { throw new PartInitException(WorkbenchMessages.format("EditorManager.unknownEditorIDMessage", new Object[] { editorId })); //$NON-NLS-1$ } //ref = getEditorManager().openEditor(editorID, input, true); //ref = openEditorFromDescriptor(new Editor(), desc, input); //if (ref != null) { // editor = ref.getEditor(true); // addPart(ref); //} // Open the instance. editor = createPart(desc); EditorSite site = new EditorSite(ref, editor, (WorkbenchPage) page, desc); if (desc != null) site.setActionBars(createEditorActionBars(desc)); else site.setActionBars(createEmptyEditorActionBars()); part.init(site, input); createEditorTab(ref, desc, input, setVisible); /* //firePartOpened(editor); setEditorAreaVisible(true); activate(editor); window.firePerspectiveChanged( this, getPerspective(), ref, CHANGE_EDITOR_OPEN); window.firePerspectiveChanged( this, getPerspective(), CHANGE_EDITOR_OPEN); */ //jelet = (JavaEditorlet) editor; //*/ IAction toggleAction = jelet.getEditorSite().getActionBars() .getGlobalActionHandler(ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY); if (toggleAction != null && toggleAction.isEnabled() && toggleAction.isChecked()) { if (toggleAction instanceof TextEditorAction) { // Reset the action ((TextEditorAction) toggleAction).setEditor(null); // Restore the action ((TextEditorAction) toggleAction).setEditor(jelet); } else { // Uncheck toggleAction.run(); // Check toggleAction.run(); } } // launched editor!! //ISourceRange srcRange = ParseUtilities.getBodyRange(method); //jelet.setShowRange(srcRange); //ConsoleView.setVariable("lm", jelet); } catch (Exception e) { e.printStackTrace(); } /* Shell shell = new Shell(); MessageDialog.openInformation( shell, "JBrowse Plug-in", "New Action was executed."); */ }
From source file:com.architexa.org.eclipse.gef.KeyHandler.java
License:Open Source License
private boolean performStroke(KeyStroke key) { if (actions == null) return false; IAction action = (IAction) actions.get(key); if (action == null) return false; if (action.isEnabled()) action.run();//from w w w .j a va 2 s. c o m return true; }
From source file:com.bluexml.side.Class.modeler.editor.ModelerContextMenuProvider.java
License:Open Source License
@Override public void buildContextMenu(IMenuManager manager) { org.topcased.modeler.editor.ModelerContextMenuProvider p = new org.topcased.modeler.editor.ModelerContextMenuProvider( getViewer(), actionRegistry); p.buildContextMenu(manager);/* w w w .j a va2 s . c o m*/ IAction action; action = actionRegistry.getAction(ShowFormAction.ID); if (action.isEnabled()) manager.appendToGroup(GEFActionConstants.GROUP_VIEW, action); action = actionRegistry.getAction(ShowViewAction.ID); if (action.isEnabled()) manager.appendToGroup(GEFActionConstants.GROUP_VIEW, action); action = actionRegistry.getAction(ImportEumFromTSV.ID); if (action.isEnabled()) manager.appendToGroup(GEFActionConstants.GROUP_VIEW, action); // HasAspect if (checkAllElements(getViewer().getSelection(), hasAspectEditPart.class)) { action = actionRegistry.getAction(DeleteLinkClassAspectAction.ID); if (action.isEnabled()) { manager.prependToGroup(GEFActionConstants.GROUP_EDIT, action); } } // Depends of if (checkAllElements(getViewer().getSelection(), dependsEditPart.class)) { action = actionRegistry.getAction(DeleteLinkEnumerationDependsAction.ID); if (action.isEnabled()) { manager.prependToGroup(GEFActionConstants.GROUP_EDIT, action); } } // Unlink Generalization if (checkAllElements(getViewer().getSelection(), GeneralizationEditPart.class)) { action = actionRegistry.getAction(DeleteLinkClassGeneralizationAction.ID); if (action.isEnabled()) { manager.prependToGroup(GEFActionConstants.GROUP_EDIT, action); } } }
From source file:com.bluexml.side.Class.modeler.SideClassContextMenuProvider.java
License:Open Source License
/** * Called when the menu is about to show. Construct the context menu by * adding actions common to all editparts. * /* w w w. j av a 2 s. c o m*/ * @see org.eclipse.gef.ContextMenuProvider#buildContextMenu(org.eclipse.jface.action.IMenuManager) */ public void buildContextMenu(IMenuManager manager) { super.buildContextMenu(manager); // HasAspect if (checkAllElements(getViewer().getSelection(), hasAspectEditPart.class)) { IAction action = getActionRegistry().getAction(DeleteLinkClassAspectAction.ID); if (action.isEnabled()) { manager.appendToGroup(GEFActionConstants.GROUP_EDIT, action); } } // Depends of if (checkAllElements(getViewer().getSelection(), dependsEditPart.class)) { IAction action = getActionRegistry().getAction(DeleteLinkEnumerationDependsAction.ID); if (action.isEnabled()) { manager.appendToGroup(GEFActionConstants.GROUP_EDIT, action); } } // Unlink Generalization if (checkAllElements(getViewer().getSelection(), GeneralizationEditPart.class)) { IAction action = getActionRegistry().getAction(DeleteLinkClassGeneralizationAction.ID); if (action.isEnabled()) { manager.appendToGroup(GEFActionConstants.GROUP_EDIT, action); } } }