Java Code Examples for org.eclipse.core.commands.operations.IUndoableOperation

The following examples show how to use org.eclipse.core.commands.operations.IUndoableOperation. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: xtext-eclipse   Source File: ProblemHoverTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@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 2
/**
 * 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
@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 4
@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 5
Source Project: gef   Source File: AbstractCompositeOperation.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@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 6
private IUndoableOperation getMostRecentDirtyRelevantOperation(
		IUndoableOperation[] undoHistory) {
	for (int i = undoHistory.length - 1; i >= 0; i--) {
		if (isContentsRelated(undoHistory[i])) {
			return undoHistory[i];
		}
	}
	return null;
}
 
Example 7
@Override
public void markNonDirty() {
	IUndoableOperation[] undoHistory = getOperationHistory()
			.getUndoHistory(getUndoContext());
	saveLocation = getMostRecentDirtyRelevantOperation(undoHistory);
	dirtyProperty.set(false);
}
 
Example 8
protected void executeCommand(IUndoableOperation command, Resource resource) {
	IOperationHistory history = OperationHistoryFactory.getOperationHistory();
	try {
		history.execute(command, new NullProgressMonitor(), null);
	} catch (ExecutionException e) {
		e.printStackTrace();
	}
}
 
Example 9
Source Project: birt   Source File: JSEditor.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 10
Source Project: saros   Source File: UndoManager.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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 11
Source Project: saros   Source File: UndoManager.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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 Project: saros   Source File: UndoManager.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 13
@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 14
@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 15
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 16
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 17
@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 18
Source Project: gef   Source File: AbstractCompositeOperation.java    License: Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void remove(IUndoableOperation operation) {
	operations.remove(operation);
}
 
Example 19
Source Project: statecharts   Source File: CommandUtil.java    License: Eclipse Public License 1.0 4 votes vote down vote up
public static IStatus executeUndoableOperation(IUndoableOperation undoableOperation)
		throws ExecutionException {
	IOperationHistory history = PlatformUI.getWorkbench().getOperationSupport().getOperationHistory();
	return history.execute(undoableOperation, new NullProgressMonitor(), null);
}
 
Example 20
Source Project: saros   Source File: UndoManager.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected String opInfo(IUndoableOperation operation) {
  return ("new " + operation.getLabel() + ": " + operation);
}
 
Example 21
protected IUndoableOperation getSwitchLaneCommand(String type) {
	IUndoableOperation c = new SwitchLaneCommand<CustomLaneEditPart>((IGraphicalEditPart) getHost(), type);
	return c;
}
 
Example 22
@Override
public void add(final IUndoableOperation operation) {
    defaultOperationHistory.add(operation);
}
 
Example 23
@Override
public IStatus execute(final IUndoableOperation operation,
        final IProgressMonitor monitor, final IAdaptable info)
        throws ExecutionException {
    return defaultOperationHistory.execute(operation, monitor, info);
}
 
Example 24
@Override
public IUndoableOperation[] getRedoHistory(final IUndoContext context) {
    return defaultOperationHistory.getRedoHistory(context);
}
 
Example 25
@Override
public IUndoableOperation getRedoOperation(final IUndoContext context) {
    return defaultOperationHistory.getRedoOperation(context);
}
 
Example 26
@Override
public IUndoableOperation[] getUndoHistory(final IUndoContext context) {
    return defaultOperationHistory.getUndoHistory(context);
}
 
Example 27
@Override
public void operationChanged(final IUndoableOperation operation) {
    defaultOperationHistory.operationChanged(operation);
}
 
Example 28
@Override
public IUndoableOperation getUndoOperation(final IUndoContext context) {
    return defaultOperationHistory.getUndoOperation(context);
}
 
Example 29
@Override
public IStatus redoOperation(final IUndoableOperation operation,
        final IProgressMonitor monitor, final IAdaptable info)
        throws ExecutionException {
    return defaultOperationHistory.redoOperation(operation, monitor, info);
}
 
Example 30
@Override
public void replaceOperation(final IUndoableOperation operation,
        final IUndoableOperation[] replacements) {
    defaultOperationHistory.replaceOperation(operation, replacements);
}