org.eclipse.core.commands.operations.IUndoableOperation Java Examples
The following examples show how to use
org.eclipse.core.commands.operations.IUndoableOperation.
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: UndoCommandHandler.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
@Override public boolean isEnabled() { final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor() ; if(editor != null){ final IOperationHistory history = (IOperationHistory) editor.getAdapter(IOperationHistory.class); final IUndoContext context = (IUndoContext) editor.getAdapter(IUndoContext.class); if(history != null && context != null){ final IUndoableOperation[] undoHistory = history.getUndoHistory(context); if (undoHistory != null && undoHistory.length != 0) { final IUndoableOperation ctxt = undoHistory[undoHistory.length - 1]; final String ctxtLabel = ctxt.getLabel(); if(ctxtLabel != null && ctxtLabel.contains("Lane")){//Avoid Exception on undo //$NON-NLS-1$ return false ; } else { return ctxt.canUndo(); } } } else { return false; } } return false; }
Example #2
Source File: HistoryBasedDirtyStateProvider.java From gef with Eclipse Public License 2.0 | 6 votes |
/** * Returns the {@link IOperationHistoryListener} that is to be used to * update the dirty state of this editor. * * @return The {@link IOperationHistoryListener} that is to be used to * update the dirty state of this editor. */ protected IOperationHistoryListener createOperationHistoryListener() { return new IOperationHistoryListener() { @Override public void historyNotification(final OperationHistoryEvent event) { // XXX: Only react to a subset of the history event // notifications. OPERATION_ADDED is issued when a transaction // is committed on the domain or an operation without a // transaction is executed on the domain; in the latter // case, we would also obtain a DONE notification (which we // ignore here). OPERATION_REMOVED is issued then flushing the // history IUndoableOperation[] undoHistory = event.getHistory() .getUndoHistory(getUndoContext()); if (event.getEventType() == OperationHistoryEvent.UNDONE || event.getEventType() == OperationHistoryEvent.REDONE || event.getEventType() == OperationHistoryEvent.OPERATION_ADDED || event.getEventType() == OperationHistoryEvent.OPERATION_REMOVED) { dirtyProperty.set(getMostRecentDirtyRelevantOperation( undoHistory) != saveLocation); } } }; }
Example #3
Source File: ProblemHoverTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testBug357516_bookmark() throws Exception { IResource resource = editor.getResource(); HashMap<String, Object> attributes = new HashMap<String, Object>(); attributes.put(IMarker.MESSAGE, CUSTOM_MARKER_TEST_MESSAGE); attributes.put(IMarker.LINE_NUMBER, 1); attributes.put(IMarker.LOCATION, resource.getFullPath().toPortableString()); IUndoableOperation operation= new CreateMarkersOperation(IMarker.BOOKMARK, attributes, resource, CUSTOM_MARKER_TEST_MESSAGE); IOperationHistory operationHistory= PlatformUI.getWorkbench().getOperationSupport().getOperationHistory(); try { operationHistory.execute(operation, null, null); } catch (ExecutionException x) { fail(x.getMessage()); } String hoverInfo = hover.getHoverInfo(editor.getInternalSourceViewer(), 0); assertNotNull(hoverInfo); assertTrue(hoverInfo.contains(CUSTOM_MARKER_TEST_MESSAGE)); }
Example #4
Source File: WaitForRefactoringCondition.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override public boolean test() throws Exception { boolean _xblockexpression = false; { final IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory(); IUndoableOperation _xifexpression = null; if (this.isRedo) { _xifexpression = operationHistory.getRedoOperation(this.getUndoContext()); } else { _xifexpression = operationHistory.getUndoOperation(this.getUndoContext()); } String _label = null; if (_xifexpression!=null) { _label=_xifexpression.getLabel(); } final String label = _label; _xblockexpression = label.startsWith("Rename "); } return _xblockexpression; }
Example #5
Source File: UpdateSizeLaneSelectionEditPolicy.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override public void mousePressed(final MouseEvent me) { try { final IFigure f = ((CustomMainProcessEditPart) laneEditPart.getParent().getParent().getParent()).getFigure() ; IFigure p = f ; while(!(p instanceof Viewport)){ p = p.getParent(); } final int y = ((Viewport)p).getVerticalRangeModel().getValue() ; IGraphicalEditPart targetEp = laneEditPart; if(type.equals(UpdateSizePoolSelectionEditPolicy.ADD_RIGHT)||type.equals(UpdateSizePoolSelectionEditPolicy.REMOVE_RIGHT)){ targetEp = getPoolEditPart(); } final IUndoableOperation c = new UpdatePoolSizeCommand(targetEp, type); OperationHistoryFactory.getOperationHistory().execute(c,null,null); me.consume(); laneEditPart.getViewer().setSelection(new StructuredSelection(targetEp)); refresh(); laneEditPart.getViewer().setSelection(new StructuredSelection(getHost())); ((Viewport)p).setVerticalLocation(y); } catch (final ExecutionException e) { e.printStackTrace(); } }
Example #6
Source File: UpdateSizePoolSelectionEditPolicy.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override public void mousePressed(MouseEvent me) { try { IFigure f = ((CustomMainProcessEditPart) poolEditPart.getParent()).getFigure() ; IFigure p = f ; while(!(p instanceof Viewport)){ p = p.getParent(); } int y = ((Viewport)p).getVerticalRangeModel().getValue() ; int x = ((Viewport)p).getHorizontalRangeModel().getValue() ; IUndoableOperation c = new UpdatePoolSizeCommand(poolEditPart, type); OperationHistoryFactory.getOperationHistory().execute(c,null,null); me.consume(); poolEditPart.getViewer().setSelection(new StructuredSelection(poolEditPart)); refresh(); poolEditPart.getViewer().setSelection(new StructuredSelection(getHost())); if(type.equals(ADD_RIGHT)){ ((Viewport)p).setHorizontalLocation(x+150); } ((Viewport)p).setVerticalLocation(y); } catch (ExecutionException e) { e.printStackTrace(); } }
Example #7
Source File: SwitchPoolSelectionEditPolicy.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
public void mousePressed(MouseEvent me) { try { IUndoableOperation c = new SwitchPoolOrderCommand((IGraphicalEditPart) getHost(), type); OperationHistoryFactory.getOperationHistory().execute(c,null,null); me.consume(); refresh(); } catch (ExecutionException e) { e.printStackTrace(); } }
Example #8
Source File: AbstractSwitchLaneSelectionEditPolicy.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
public void mousePressed(MouseEvent me) { try { IUndoableOperation c = getSwitchLaneCommand(type); OperationHistoryFactory.getOperationHistory().execute(c,null,null); me.consume(); refresh(); } catch (ExecutionException e) { e.printStackTrace(); } }
Example #9
Source File: MoveConnectorWizardTest.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Test public void should_execute_ChangeConnectorContainerCommand_on_finish() throws Exception { final IOperationHistory operationHistory = mock(IOperationHistory.class); final MoveConnectorWizard wizard = new MoveConnectorWizard(operationHistory, mock(InternalTransactionalEditingDomain.class), newArrayList(aConnector().in(aPool()).build())); wizard.addPages(); wizard.performFinish(); verify(operationHistory).execute(notNull(IUndoableOperation.class), any(IProgressMonitor.class), any(IAdaptable.class)); }
Example #10
Source File: UndoManager.java From saros with GNU General Public License v2.0 | 5 votes |
/** * Adds an undone NullOperation (i.e. has no effects on executing, undoing or redoing) to the * Eclipse IOperationHistory to be sure that redoing is possible. This is necessary for the UI * Redo possibility being activated. */ protected void simulateUndo() { IUndoableOperation auxOp = new NullOperation(); try { auxOp.addContext(context); eclipseHistory.execute(auxOp, null, null); eclipseHistory.undo(context, null, null); if (!eclipseHistory.canRedo(context)) log.error("Simulating Undo failed"); } catch (ExecutionException e) { log.error("Simulating Undo failed"); } }
Example #11
Source File: UndoManager.java From saros with GNU General Public License v2.0 | 5 votes |
@Override public IStatus proceedUndoing( final IUndoableOperation operation, IOperationHistory history, IAdaptable info) { if (!enabled) return Status.OK_STATUS; if (currentActiveEditor == null) { log.info("Undo called on an unknown editor"); return Status.OK_STATUS; } if (log.isDebugEnabled()) log.debug(opInfo(operation)); if (operation.getLabel().equals(TYPING_LABEL)) { updateCurrentLocalAtomicOperation(null); storeCurrentLocalOperation(); SWTUtils.runSafeSWTSync( log, new Runnable() { @Override public void run() { log.debug("undoing operation " + operation); undo(currentActiveEditor); if (undoHistory.canRedo(currentActiveEditor)) simulateUndo(); } }); return Status.CANCEL_STATUS; } return Status.OK_STATUS; }
Example #12
Source File: UndoManager.java From saros with GNU General Public License v2.0 | 5 votes |
@Override public IStatus proceedRedoing( final IUndoableOperation operation, IOperationHistory history, IAdaptable info) { if (!enabled) return Status.OK_STATUS; if (currentActiveEditor == null) { log.info("Redo called on an unknown editor"); return Status.OK_STATUS; } if (log.isDebugEnabled()) log.debug(opInfo(operation)); if (operation.getLabel().equals(TYPING_LABEL) || operation.getLabel().equals(NullOperation.LABEL)) { updateCurrentLocalAtomicOperation(null); storeCurrentLocalOperation(); SWTUtils.runSafeSWTSync( log, new Runnable() { @Override public void run() { log.debug("redoing operation " + operation); redo(currentActiveEditor); /* * For reactivating redo an undo has to be simulated, so * the Eclipse history knows, there is something to * redo. */ if (undoHistory.canRedo(currentActiveEditor)) simulateUndo(); } }); return Status.CANCEL_STATUS; } return Status.OK_STATUS; }
Example #13
Source File: JSEditor.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * Returns current undo level. * * @return current undo level. */ private int getUndoLevel( ) { SourceViewer viewer = getViewer( ); IUndoableOperation[] history = viewer == null ? null : OperationHistoryFactory.getOperationHistory( ) .getUndoHistory( new ObjectUndoContext( viewer.getDocument( ) ) ); return history == null ? -1 : history.length; }
Example #14
Source File: AbstractCompositeOperation.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public void add(IUndoableOperation operation) { if (operation instanceof ITransactionalOperation) { operations.add((ITransactionalOperation) operation); } else { throw new IllegalArgumentException( "The given operation may not be null and must implement ITransactionalOperation."); } }
Example #15
Source File: HistoryBasedDirtyStateProvider.java From gef with Eclipse Public License 2.0 | 5 votes |
private IUndoableOperation getMostRecentDirtyRelevantOperation( IUndoableOperation[] undoHistory) { for (int i = undoHistory.length - 1; i >= 0; i--) { if (isContentsRelated(undoHistory[i])) { return undoHistory[i]; } } return null; }
Example #16
Source File: HistoryBasedDirtyStateProvider.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public void markNonDirty() { IUndoableOperation[] undoHistory = getOperationHistory() .getUndoHistory(getUndoContext()); saveLocation = getMostRecentDirtyRelevantOperation(undoHistory); dirtyProperty.set(false); }
Example #17
Source File: AbstractSemanticModification.java From statecharts with Eclipse Public License 1.0 | 5 votes |
protected void executeCommand(IUndoableOperation command, Resource resource) { IOperationHistory history = OperationHistoryFactory.getOperationHistory(); try { history.execute(command, new NullProgressMonitor(), null); } catch (ExecutionException e) { e.printStackTrace(); } }
Example #18
Source File: BonitaOperationHistory.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
@Override public IUndoableOperation[] getRedoHistory(final IUndoContext context) { return defaultOperationHistory.getRedoHistory(context); }
Example #19
Source File: UndoManager.java From saros with GNU General Public License v2.0 | 4 votes |
protected String opInfo(IUndoableOperation operation) { return ("new " + operation.getLabel() + ": " + operation); }
Example #20
Source File: BonitaOperationHistory.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
@Override public IStatus undoOperation(final IUndoableOperation operation, final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { return defaultOperationHistory.undoOperation(operation, monitor, info); }
Example #21
Source File: BonitaOperationHistory.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
@Override public void replaceOperation(final IUndoableOperation operation, final IUndoableOperation[] replacements) { defaultOperationHistory.replaceOperation(operation, replacements); }
Example #22
Source File: BonitaOperationHistory.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
@Override public IStatus redoOperation(final IUndoableOperation operation, final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { return defaultOperationHistory.redoOperation(operation, monitor, info); }
Example #23
Source File: BonitaOperationHistory.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
@Override public IUndoableOperation getUndoOperation(final IUndoContext context) { return defaultOperationHistory.getUndoOperation(context); }
Example #24
Source File: BonitaOperationHistory.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
@Override public void operationChanged(final IUndoableOperation operation) { defaultOperationHistory.operationChanged(operation); }
Example #25
Source File: BonitaOperationHistory.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
@Override public IUndoableOperation[] getUndoHistory(final IUndoContext context) { return defaultOperationHistory.getUndoHistory(context); }
Example #26
Source File: BonitaOperationHistory.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
@Override public IUndoableOperation getRedoOperation(final IUndoContext context) { return defaultOperationHistory.getRedoOperation(context); }
Example #27
Source File: BonitaOperationHistory.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
@Override public IStatus execute(final IUndoableOperation operation, final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { return defaultOperationHistory.execute(operation, monitor, info); }
Example #28
Source File: BonitaOperationHistory.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
@Override public void add(final IUndoableOperation operation) { defaultOperationHistory.add(operation); }
Example #29
Source File: SwitchLaneSelectionEditpolicy.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
protected IUndoableOperation getSwitchLaneCommand(String type) { IUndoableOperation c = new SwitchLaneCommand<CustomLaneEditPart>((IGraphicalEditPart) getHost(), type); return c; }
Example #30
Source File: AbstractCompositeOperation.java From gef with Eclipse Public License 2.0 | 4 votes |
@Override public void remove(IUndoableOperation operation) { operations.remove(operation); }