List of usage examples for org.eclipse.jface.action Action isEnabled
@Override
public boolean isEnabled()
From source file:com.ebmwebsourcing.petals.services.eip.designer.EipChainDiagramEditor.java
License:Open Source License
@Override public void createPartControl(Composite parent) { Composite container = new Composite(parent, SWT.NONE); // Create this composite final GridLayout layout = new GridLayout(); layout.marginHeight = 0;//from w w w.ja v a 2 s . c o m layout.marginWidth = 0; container.setLayout(layout); container.setBackground(container.getDisplay().getSystemColor(SWT.COLOR_WHITE)); // Create the palette PaletteViewerProvider paletteProvider = new PaletteViewerProvider(this.editingDomain) { @Override public PaletteViewer createPaletteViewer(Composite parent) { final PaletteViewer result = new EipPaletteViewer(); result.createControl(parent); configurePaletteViewer(result); hookPaletteViewer(result); return result; } }; FlyoutPaletteComposite paletteComposite = new FlyoutPaletteComposite(container, SWT.NONE, getSite().getPage(), paletteProvider, new EipPalettePreferences()); paletteComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); createPaletteRoot(); // Create the viewer this.graphicalViewer = new ScrollingGraphicalViewer(); this.graphicalViewer.setEditPartFactory(new EipEditPartFactory()); List<String> zoomLevels = new ArrayList<String>(3); zoomLevels.add(ZoomManager.FIT_ALL); zoomLevels.add(ZoomManager.FIT_WIDTH); zoomLevels.add(ZoomManager.FIT_HEIGHT); ScalableFreeformRootEditPart root = new ScalableFreeformRootEditPart(); root.getZoomManager().setZoomLevelContributions(zoomLevels); this.graphicalViewer.setRootEditPart(root); this.editingDomain.addViewer(this.graphicalViewer); Control viewerControl = this.graphicalViewer.createControl(paletteComposite); paletteComposite.setGraphicalControl(viewerControl); // Handle selections this.selectionSynchronizer.addViewer(this.graphicalViewer); getSite().setSelectionProvider(this.graphicalViewer); // Show a grid on the viewer this.graphicalViewer.setProperty(SnapToGrid.PROPERTY_GRID_ENABLED, true); this.graphicalViewer.setProperty(SnapToGrid.PROPERTY_GRID_VISIBLE, false); this.graphicalViewer.setProperty(SnapToGrid.PROPERTY_GRID_SPACING, new Dimension(110, 110)); // Handle mouse scroll for ZOOM this.graphicalViewer.setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.MOD1), MouseWheelZoomHandler.SINGLETON); // Support for DnD - from the palette this.graphicalViewer.addDropTargetListener(new TemplateTransferDropTargetListener(this.graphicalViewer) { @Override protected CreationFactory getFactory(Object template) { if (template instanceof EIPtype) return new EipNodeCreationFactory((EIPtype) template); else if (template instanceof Class<?>) return new EndpointCreationFactory(); return null; } }); // Support for DnD - from the Petals services view this.graphicalViewer.addDropTargetListener(new PetalsEndpointDropTargetListener(this.graphicalViewer)); // Initialize the viewer this.graphicalViewer.setContents(this.eipChain); // Add a contextual menu final MenuManager menuMgr = new MenuManager("com.ebmwebsourcing.petals.services.eip.contextmenu"); this.graphicalViewer.setContextMenu(menuMgr); menuMgr.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager manager) { manager.removeAll(); Action action = new SwitchNodesAction(EipChainDiagramEditor.this); if (action.isEnabled()) { manager.add(action); } action = new ConnectionToAction(EipChainDiagramEditor.this); if (action.isEnabled()) { manager.add(action); } menuMgr.add(new ShowPropertiesAction()); manager.add(new Separator()); menuMgr.add(new ArrangeAllAction(EipChainDiagramEditor.this)); menuMgr.add(new ExportDiagramAction(EipChainDiagramEditor.this.graphicalViewer, EipChainDiagramEditor.this.eipChain)); } }); // Create the actions createActions(); // Refresh markers validate(); }
From source file:com.google.dart.tools.ui.callhierarchy.SearchScopeActionGroup.java
License:Open Source License
protected void fillSearchActions(IMenuManager searchMM) { Action[] actions = getActions(); for (int i = 0; i < actions.length; i++) { Action action = actions[i]; if (action.isEnabled()) { searchMM.add(action);// w w w .ja va 2s . c o m } } searchMM.setVisible(!searchMM.isEmpty()); }
From source file:com.mentor.nucleus.bp.core.test.UndoRedoTestGenerics.java
License:Open Source License
/** * Tests that the undo and redo stacks are cleared for a model-root * whose persistence file has been changed outside of normal tool use. *///from w w w. j av a2s . c o m public void testClearingOfUndoRedoStacksOnFileChange() throws CoreException { // undo the movement of the class done during the last test, // to get both the undo and redo actions enabled transactionManager.getUndoAction().run(); // check that both the undo and redo actions are enabled Action undoAction = transactionManager.getUndoAction(); Action redoAction = transactionManager.getRedoAction(); assertTrue("Undo and redo actions aren't both enabled", undoAction.isEnabled() && redoAction.isEnabled()); // touch the model's persistence file, to get Eclipse to think it's // changed somehow ((IFile) modelRoot.getPersistenceFile()).touch(null); // check that both the undo and redo actions are disabled assertTrue("Undo and redo actions aren't both disabled", !undoAction.isEnabled() && !redoAction.isEnabled()); }
From source file:com.nokia.tools.media.utils.editor.frameanimation.FrameAnimationContainer.java
License:Open Source License
public FrameAnimationContainer(AbstractMediaEditorPart graphicsEditor, Composite parent, int style) { super(parent, style); this.graphicsEditor = graphicsEditor; setLayoutData(new GridData(GridData.FILL_BOTH)); setLayout(new GridLayout(1, false)); // create SCROLLING COMPOSITE // set its layout sc = new ScrolledComposite(this, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); // sc.setSize(400, 400); sc.setLayout(new GridLayout()); // create scrolled composite'contents which will be scrolled c = new Composite(sc, SWT.NONE); RowLayout rl = new RowLayout(); rl.wrap = false;//from w ww . j a v a 2 s . co m c.setLayout(rl); // SET CONTENTS WHICH WILL BE SCROLLED BY SCROLLED COMPOSITE sc.setContent(c); sc.setExpandHorizontal(true); sc.setExpandVertical(true); sc.setMinSize(c.computeSize(SWT.DEFAULT, SWT.DEFAULT)); Composite bC = new Composite(this, SWT.NONE); RowLayout bcRl = new RowLayout(SWT.HORIZONTAL); bcRl.wrap = false; bC.setLayout(bcRl); undoButton = new Button(bC, SWT.FLAT); undoButton.setEnabled(false); undoButton.setToolTipText( graphicsEditor.getActionRegistry().getAction(ActionFactory.UNDO.getId()).getToolTipText()); undoButton.setImage(graphicsEditor.getActionRegistry().getAction(ActionFactory.UNDO.getId()) .getDisabledImageDescriptor().createImage()); // listener for adding new image to the animation list undoButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { UndoAction undoAction = (UndoAction) FrameAnimationContainer.this.graphicsEditor.getActionRegistry() .getAction(ActionFactory.UNDO.getId()); if (undoAction.isEnabled()) { undoAction.run(); } } }); redoButton = new Button(bC, SWT.FLAT); redoButton.setEnabled(false); redoButton.setToolTipText( graphicsEditor.getActionRegistry().getAction(ActionFactory.REDO.getId()).getToolTipText()); redoButton.setImage(graphicsEditor.getActionRegistry().getAction(ActionFactory.REDO.getId()) .getDisabledImageDescriptor().createImage()); // listener for redo operation redoButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { RedoAction redoAction = (RedoAction) FrameAnimationContainer.this.graphicsEditor.getActionRegistry() .getAction(ActionFactory.REDO.getId()); if (redoAction.isEnabled()) { redoAction.run(); } } }); Label separator = new Label(bC, SWT.SEPARATOR); addButton = new Button(bC, SWT.FLAT); addButton.setToolTipText(Messages.AddFrameToolTip); addButton.setImage(NEW_IMAGE); // listener for adding new image to the animation list addButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { getDisplay().asyncExec(new Runnable() { public void run() { ISelectionProvider provider = new ISelectionProvider() { public void addSelectionChangedListener(ISelectionChangedListener listener) { }; public void removeSelectionChangedListener(ISelectionChangedListener listener) { }; public ISelection getSelection() { return new StructuredSelection(curImage); }; public void setSelection(ISelection selection) { }; }; Action newFrameAction = getActionFactory().getNewFrameAction(provider); if (newFrameAction.isEnabled()) { newFrameAction.run(); } } }); } }); removeButton = new Button(bC, SWT.FLAT); removeButton.setToolTipText(Messages.DeleteFrameToolTip); removeButton.setImage(DELETE_IMAGE); // listener for image delete operation removeButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { // test if selected image has // remove selected image from animation'images'list if (selectedAnimationFrameButton != null) { final IAnimationFrame sourceImg = (IAnimationFrame) selectedAnimationFrameButton .getData(IAnimationFrame.class.getName()); ISelectionProvider provider = new ISelectionProvider() { public ISelection getSelection() { return new StructuredSelection(sourceImg); } public void setSelection(ISelection selection) { } public void addSelectionChangedListener(ISelectionChangedListener listener) { } public void removeSelectionChangedListener(ISelectionChangedListener listener) { } }; Action removeFrameAction = getActionFactory().getRemoveFrameAction(provider); if (removeFrameAction.isEnabled()) { removeFrameAction.run(); } } } }); separator.setLayoutData(new RowData(SWT.DEFAULT, removeButton.computeSize(SWT.DEFAULT, SWT.DEFAULT).y)); separator = new Label(bC, SWT.SEPARATOR); separator.setLayoutData(new RowData(SWT.DEFAULT, removeButton.computeSize(SWT.DEFAULT, SWT.DEFAULT).y)); moveToBegin = new Button(bC, SWT.FLAT); moveToBegin.setToolTipText(Messages.MoveFrameToBeginToolTip); moveToBegin.setImage(MOVE_TO_BEGIN_IMAGE); // listener for image delete operation moveToBegin.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { // test if selected image has // remove selected image from animation'images'list if (selectedAnimationFrameButton != null) { final IAnimationFrame sourceImg = (IAnimationFrame) selectedAnimationFrameButton .getData(IAnimationFrame.class.getName()); Command command = new Command(Messages.AnimationImageContainer_moveFrameToBegin) { int oldSeqNo; public boolean canExecute() { return curImage != null && sourceImg != null; }; public boolean canUndo() { return true; }; public void redo() { oldSeqNo = sourceImg.getSeqNo(); if (curImage != null && oldSeqNo > 0) { curImage.moveAnimationFrame(sourceImg, 0); notityPropertyChangedListeners(IMAGE_MOVED, null, sourceImg); } }; public void undo() { if (curImage != null) { if (sourceImg.getSeqNo() < oldSeqNo) { curImage.moveAnimationFrame(sourceImg, oldSeqNo + 1); } else { curImage.moveAnimationFrame(sourceImg, oldSeqNo); } notityPropertyChangedListeners(IMAGE_MOVED, null, sourceImg); } }; public void execute() { redo(); }; }; FrameAnimationContainer.this.graphicsEditor.getCommandStack().execute(command); } } }); moveToLeft = new Button(bC, SWT.FLAT); moveToLeft.setToolTipText(Messages.MoveFrameToLeftToolTip); moveToLeft.setImage(MOVE_TO_LEFT_IMAGE); // listener for image delete operation moveToLeft.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { // test if selected image has // remove selected image from animation'images'list if (selectedAnimationFrameButton != null) { final IAnimationFrame sourceImg = (IAnimationFrame) selectedAnimationFrameButton .getData(IAnimationFrame.class.getName()); Command command = new Command(Messages.AnimationImageContainer_moveFrameToLeft) { boolean moved; public boolean canExecute() { return curImage != null && sourceImg != null; }; public boolean canUndo() { return moved; }; public void redo() { if (curImage != null && sourceImg.getSeqNo() > 0) { curImage.moveAnimationFrame(sourceImg, sourceImg.getSeqNo() - 1); notityPropertyChangedListeners(IMAGE_MOVED, null, sourceImg); moved = true; } }; public void undo() { if (curImage != null && sourceImg.getSeqNo() < curImage.getAnimationFrames().length - 1) { curImage.moveAnimationFrame(sourceImg, sourceImg.getSeqNo() + 2); notityPropertyChangedListeners(IMAGE_MOVED, null, sourceImg); } }; public void execute() { redo(); }; }; FrameAnimationContainer.this.graphicsEditor.getCommandStack().execute(command); } } }); moveToRight = new Button(bC, SWT.FLAT); moveToRight.setToolTipText(Messages.MoveFrameToRightToolTip); moveToRight.setImage(MOVE_TO_RIGHT_IMAGE); // listener for image delete operation moveToRight.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { // test if selected image has // remove selected image from animation'images'list if (selectedAnimationFrameButton != null) { final IAnimationFrame sourceImg = (IAnimationFrame) selectedAnimationFrameButton .getData(IAnimationFrame.class.getName()); Command command = new Command(Messages.AnimationImageContainer_moveFrameToRight) { boolean moved; public boolean canExecute() { return curImage != null && sourceImg != null; }; public boolean canUndo() { return moved; }; public void redo() { if (curImage != null && sourceImg.getSeqNo() < curImage.getAnimationFrames().length - 1) { curImage.moveAnimationFrame(sourceImg, sourceImg.getSeqNo() + 2); notityPropertyChangedListeners(IMAGE_MOVED, null, sourceImg); moved = true; } }; public void undo() { if (curImage != null && sourceImg.getSeqNo() > 0) { curImage.moveAnimationFrame(sourceImg, sourceImg.getSeqNo() - 1); notityPropertyChangedListeners(IMAGE_MOVED, null, sourceImg); } }; public void execute() { redo(); }; }; FrameAnimationContainer.this.graphicsEditor.getCommandStack().execute(command); } } }); moveToEnd = new Button(bC, SWT.FLAT); moveToEnd.setToolTipText(Messages.MoveFrameToEndToolTip); moveToEnd.setImage(MOVE_TO_END_IMAGE); // listener for image delete operation moveToEnd.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { // test if selected image has // remove selected image from animation'images'list if (selectedAnimationFrameButton != null) { final IAnimationFrame sourceImg = (IAnimationFrame) selectedAnimationFrameButton .getData(IAnimationFrame.class.getName()); Command command = new Command(Messages.AnimationImageContainer_moveFrameToEnd) { int oldSeqNo; public boolean canExecute() { return curImage != null && sourceImg != null; }; public boolean canUndo() { return true; }; public void redo() { oldSeqNo = sourceImg.getSeqNo(); if (curImage != null && sourceImg.getSeqNo() < curImage.getAnimationFrames().length - 1) { curImage.moveAnimationFrame(sourceImg, curImage.getAnimationFrames().length + 1); notityPropertyChangedListeners(IMAGE_MOVED, null, sourceImg); } }; public void undo() { if (curImage != null) { if (sourceImg.getSeqNo() < oldSeqNo) { curImage.moveAnimationFrame(sourceImg, oldSeqNo + 1); } else { curImage.moveAnimationFrame(sourceImg, oldSeqNo); } notityPropertyChangedListeners(IMAGE_MOVED, null, sourceImg); } }; public void execute() { redo(); }; }; FrameAnimationContainer.this.graphicsEditor.getCommandStack().execute(command); } } }); Label separator2 = new Label(bC, SWT.SEPARATOR); separator2.setLayoutData(new RowData(SWT.DEFAULT, removeButton.computeSize(SWT.DEFAULT, SWT.DEFAULT).y)); Button setAnimateTime = new Button(bC, SWT.FLAT); setAnimateTime.setToolTipText(Messages.DistributeAnimateTimeToolTip); setAnimateTime.setImage(CASCADE_IMAGE); // listener for image delete operation setAnimateTime.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { ISelectionProvider provider = new ISelectionProvider() { public ISelection getSelection() { return new StructuredSelection(curImage); } public void setSelection(ISelection selection) { } public void addSelectionChangedListener(ISelectionChangedListener listener) { } public void removeSelectionChangedListener(ISelectionChangedListener listener) { } }; Action distributeAnimateTimeAction = getActionFactory().getDistributeAnimationTimeAction(provider); distributeAnimateTimeAction.run(); if (timeLine != null) { timeLine.repaint(); } } }); updateButtonsState(false); this.graphicsEditor.getCommandStack().addCommandStackListener(this); }
From source file:com.nokia.tools.media.utils.editor.frameanimation.FrameAnimationContainer.java
License:Open Source License
private void registerKeyListener(final Button b) { b.addKeyListener(new KeyAdapter() { @Override/* w w w .j a v a 2 s . c o m*/ public void keyPressed(KeyEvent e) { final IAnimationFrame animationFrame = (IAnimationFrame) b.getData(IAnimationFrame.class.getName()); ISelectionProvider provider = new ISelectionProvider() { public ISelection getSelection() { return new StructuredSelection(animationFrame); } public void setSelection(ISelection selection) { } public void addSelectionChangedListener(ISelectionChangedListener listener) { } public void removeSelectionChangedListener(ISelectionChangedListener listener) { } }; if (e.keyCode == 99 && e.stateMask == 262144) { // CTRL+C try { Action copyAction = getActionFactory().getCopyFrameAction(provider); if (copyAction.isEnabled()) { copyAction.run(); } } catch (Exception e1) { e1.printStackTrace(); } } else if (e.keyCode == 118 && e.stateMask == 262144) { Action pasteAction = getActionFactory().getPasteFrameAction(provider); if (pasteAction.isEnabled()) { pasteAction.run(); } } else if (e.keyCode == SWT.DEL && e.stateMask == 0) { // Del Action removeAction = getActionFactory().getRemoveFrameAction(provider); if (removeAction.isEnabled()) { removeAction.run(); } } else if (e.keyCode == SWT.ARROW_LEFT && e.stateMask == 0) { IAnimationFrame[] frames = curImage.getAnimationFrames(); for (int idx = 0; idx < frames.length; idx++) { if (frames[idx] == selectedAnimationFrame) { int leftIdx = Math.max(0, idx - 1); setFocus(frames[leftIdx]); break; } } } else if (e.keyCode == SWT.ARROW_RIGHT && e.stateMask == 0) { IAnimationFrame[] frames = curImage.getAnimationFrames(); for (int idx = 0; idx < frames.length; idx++) { if (frames[idx] == selectedAnimationFrame) { int rightIdx = Math.min(frames.length - 1, idx + 1); setFocus(frames[rightIdx]); break; } } } } }); }
From source file:com.nokia.tools.s60.editor.Series60ContentOutlinePage.java
License:Open Source License
/** * adds action to manager if enabled and add separator if not null. * @param manager//from ww w . j av a 2 s. co m * @param action * @param spr * @return NULL or separator, if was not used */ private Separator internalAddAction(IMenuManager manager, Action action, Separator spr) { if (action.isEnabled()) { if (spr != null) { manager.add(spr); spr = null; } manager.add(action); } return spr; }
From source file:com.nokia.tools.s60.views.contributions.ThemeResourceViewerSection.java
License:Open Source License
public IMenuListener createResourceViewerMenuListener(final ISelectionProvider selectionProvider, final CommandStack stack) { return new IMenuListener() { public void menuAboutToShow(IMenuManager mmgr) { AbstractAction action = new CopyContentDataAction(selectionProvider, null); action.update();//from www. j a v a 2 s.c o m // mmgr.add(action); HideableMenuManager cpCpy = new HideableMenuManager(action.getText()); try { action.setText("Skinned Only"); cpCpy.add(action); action = new CopyContentDataAction(selectionProvider, null); ((CopyContentDataAction) action).setCopySkinnedOnly(false); action.update(); action.setText("All"); cpCpy.add(action); } catch (Exception e) { e.printStackTrace(); } // if (cpSubmenu.isEnabled()) { mmgr.add(new Separator()); mmgr.add(cpCpy); // } action = new PasteContentDataAction(selectionProvider, stack, null); action.update(); if (action.isEnabled()) mmgr.add(action); // skin by similar actions { IStructuredSelection sel = (IStructuredSelection) selectionProvider.getSelection(); if (sel.getFirstElement() instanceof ToolEntryEditPart) { ToolEntryEditPart tEditP = (ToolEntryEditPart) sel.getFirstElement(); CombinedTemplateCreationEntry entry = (CombinedTemplateCreationEntry) tEditP.getModel(); IContentData cData = (IContentData) entry.getTemplate(); String lbl = ViewMessages.bind( com.nokia.tools.screen.ui.views.ViewMessages.ResourceView_SkinBySubmenu, cData.getName()); HideableMenuManager cpSubmenu = new HideableMenuManager(lbl); try { for (String name : ComponentStoreFactory.getComponentPool().getThemeNames()) { if (ComponentStoreFactory.getComponentPool().isSkinned(cData.getId(), cData.getParent().getId(), name)) { action = new SkinBySimilarAction(selectionProvider, null, name); cpSubmenu.add(action); } } } catch (Exception e) { e.printStackTrace(); } if (cpSubmenu.isEnabled()) { mmgr.add(new Separator()); Action customize = new AdjustThemeListAction(selectionProvider); if (customize.isEnabled()) { cpSubmenu.add(new Separator()); cpSubmenu.add(customize); } mmgr.add(cpSubmenu); } } } } }; }
From source file:com.nokia.tools.variant.resourcelibrary.actions.ResourceLibraryActionGroup.java
License:Open Source License
protected void addIfEnabled(IMenuManager menu, Action action) { if (action.isEnabled()) { menu.add(action); } }
From source file:com.vectrace.MercurialEclipse.history.MercurialHistoryPage.java
License:Open Source License
private void contributeActions() { final Action updateAction = new Action(Messages.getString("MercurialHistoryPage.updateAction.name")) { //$NON-NLS-1$ private MercurialRevision rev; @Override//from ww w. j av a 2 s.c o m public void run() { if (rev == null) { return; } try { HgRoot root = resource != null ? MercurialTeamProvider.getHgRoot(resource) : hgRoot; Assert.isNotNull(root); UpdateJob job = new UpdateJob(rev.getContentIdentifier(), true, root, false); if (!job.confirmDataLoss(getControl().getShell())) { return; } JobChangeAdapter adap = new JobChangeAdapter() { @Override public void done(IJobChangeEvent event) { refresh(); } }; job.addJobChangeListener(adap); job.schedule(); } catch (HgException e) { MercurialEclipsePlugin.logError(e); } } @Override public boolean isEnabled() { MercurialRevision[] revs = getSelectedRevisions(); if (revs != null && revs.length == 1) { rev = revs[0]; return true; } rev = null; return false; } }; updateAction.setImageDescriptor(MercurialEclipsePlugin.getImageDescriptor("actions/update.gif")); //$NON-NLS-1$ stripAction = new Action() { { setText("Strip..."); setImageDescriptor(MercurialEclipsePlugin.getImageDescriptor("actions/revert.gif")); } @Override public void run() { final Shell shell = MercurialEclipsePlugin.getActiveShell(); shell.getDisplay().asyncExec(new Runnable() { public void run() { ChangeSet changeSet = null; MercurialRevision[] revisions = getSelectedRevisions(); if (revisions == null || revisions.length != 1) { return; } changeSet = revisions[0].getChangeSet(); StripHandler.openWizard(changeSet.getHgRoot(), shell, changeSet); } }); } @Override public boolean isEnabled() { MercurialRevision[] revs = getSelectedRevisions(); if (revs != null && revs.length == 1) { return true; } return false; } }; backoutAction = new Action() { { setText("Backout..."); setImageDescriptor(MercurialEclipsePlugin.getImageDescriptor("actions/revert.gif")); } @Override public void run() { final Shell shell = MercurialEclipsePlugin.getActiveShell(); shell.getDisplay().asyncExec(new Runnable() { public void run() { ChangeSet changeSet = null; MercurialRevision[] revisions = getSelectedRevisions(); if (revisions == null || revisions.length != 1) { return; } changeSet = revisions[0].getChangeSet(); BackoutWizard backoutWizard = new BackoutWizard(changeSet.getHgRoot(), changeSet); WizardDialog dialog = new WizardDialog(shell, backoutWizard); dialog.setBlockOnOpen(true); int result = dialog.open(); if (result == Window.OK) { new RefreshWorkspaceStatusJob(changeSet.getHgRoot(), RefreshRootJob.ALL).schedule(); } } }); } @Override public boolean isEnabled() { MercurialRevision[] revs = getSelectedRevisions(); if (revs != null && revs.length == 1) { return true; } return false; } }; // Contribute actions to popup menu final MenuManager menuMgr = new MenuManager(); final MenuManager bisectMenu = new MenuManager("Bisect"); final MenuManager undoMenu = new MenuManager("Undo", MercurialEclipsePlugin.getImageDescriptor("undo_edit.gif"), null); undoMenu.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager manager) { undoMenu.add(backoutAction); undoMenu.add(stripAction); } }); bisectMenu.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager menuMgr1) { bisectMenu.add(bisectMarkBadAction); bisectMenu.add(bisectMarkGoodAction); bisectMenu.add(bisectResetAction); } }); menuMgr.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager menuMgr1) { // enablement updateAction.setEnabled(updateAction.isEnabled()); bisectMarkBadAction.setEnabled(bisectMarkBadAction.isEnabled()); bisectMarkGoodAction.setEnabled(bisectMarkGoodAction.isEnabled()); bisectResetAction.setEnabled(bisectResetAction.isEnabled()); exportAsBundleAction.setEnabled(true); mergeWithCurrentChangesetAction.setEnabled(true); stripAction.setEnabled(stripAction.isEnabled()); backoutAction.setEnabled(backoutAction.isEnabled()); undoMenu.setVisible(stripAction.isEnabled() || backoutAction.isEnabled()); // layout if (resource instanceof IFile) { IStructuredSelection sel = updateActionEnablement(); menuMgr1.add(openAction); menuMgr1.add(openEditorAction); menuMgr1.add(new Separator(IWorkbenchActionConstants.GROUP_FILE)); if (sel.size() == 2) { menuMgr1.add(compareTwo); } else { menuMgr1.add(compareWithPrevAction); menuMgr1.add(compareWithCurrAction); menuMgr1.add(compareWithOtherAction); menuMgr1.add(new Separator()); menuMgr1.add(revertAction); } } menuMgr1.add(mergeWithCurrentChangesetAction); menuMgr1.add(undoMenu); menuMgr1.add(new Separator()); menuMgr1.add(updateAction); menuMgr1.add(bisectMenu); menuMgr1.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); menuMgr1.add(exportAsBundleAction); } }); bisectMenu.setRemoveAllWhenShown(true); undoMenu.setRemoveAllWhenShown(true); menuMgr.setRemoveAllWhenShown(true); viewer.getTable().setMenu(menuMgr.createContextMenu(viewer.getTable())); getSite().registerContextMenu(MercurialEclipsePlugin.ID + ".hgHistoryPage", menuMgr, viewer); }
From source file:de.loskutov.anyedit.actions.compare.CompareWithAction.java
License:Open Source License
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { IWorkbenchPart activePart = HandlerUtil.getActivePart(event); Action dummyAction = new Action() { @Override/*from ww w. j a v a 2s. c o m*/ public String getId() { return event.getCommand().getId(); } }; setActivePart(dummyAction, activePart); ISelection currentSelection = HandlerUtil.getCurrentSelection(event); selectionChanged(dummyAction, currentSelection); if (dummyAction.isEnabled()) { run(dummyAction); } return null; }