org.eclipse.core.commands.operations.OperationHistoryEvent Java Examples

The following examples show how to use org.eclipse.core.commands.operations.OperationHistoryEvent. 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: HistoricizingDomain.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void historyNotification(OperationHistoryEvent event) {
	if (event.getEventType() == OperationHistoryEvent.ABOUT_TO_UNDO) {
		if (!transactionContext.isEmpty() && transaction != null) {
			if (transaction.getOperations().isEmpty()) {
				// XXX: Copy transaction context to prevent CME when an
				// interaction is started while performing undo.
				for (IGesture gesture : new ArrayList<>(
						transactionContext)) {
					closeExecutionTransaction(gesture);
				}
			} else {
				// XXX: Need a test case. I think it might be fine to
				// perform undo even though a handler already
				// contributed an operation.
				throw new IllegalStateException(
						"Cannot perform UNDO while a currently open execution transaction contains operations.");
			}
		}
	}
}
 
Example #2
Source File: HistoryBasedDirtyStateProvider.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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: UndoablePropertySheetEntry.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Constructs a new root entry.
 *
 * @param workbenchPart
 *            The {@link IWorkbenchPart} to adapt for an
 *            {@link IPropertySource}, in case no values are provided.
 * @param operationHistory
 *            The {@link IOperationHistory} to use.
 * @param undoContext
 *            The {@link IUndoContext} to use.
 */
public UndoablePropertySheetEntry(IWorkbenchPart workbenchPart,
		IOperationHistory operationHistory, IUndoContext undoContext) {
	this.workbenchPart = workbenchPart;
	this.operationHistory = operationHistory;
	this.undoContext = undoContext;
	this.operationHistoryListener = new IOperationHistoryListener() {

		@Override
		public void historyNotification(OperationHistoryEvent event) {
			refreshFromRoot();
		}
	};
	this.operationHistory
			.addOperationHistoryListener(operationHistoryListener);
}
 
Example #4
Source File: UndoablePropertySheetPage.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Constructs a new {@link UndoablePropertySheetPage} using the provided
 * {@link IOperationHistory}.
 *
 * @param operationHistory
 *            The {@link IOperationHistory} shared with the editor/view.
 * @param undoContext
 *            The {@link IUndoContext} shared with the editor/view.
 * @param workbenchPart
 *            The {@link IWorkbenchPart} this
 *            {@link UndoablePropertySheetPage} is related to. .
 *
 */
@Inject
public UndoablePropertySheetPage(@Assisted IWorkbenchPart workbenchPart,
		IOperationHistory operationHistory, IUndoContext undoContext) {
	this.workbenchPart = workbenchPart;
	this.operationHistory = operationHistory;
	this.undoContext = undoContext;
	this.operationHistoryListener = new IOperationHistoryListener() {

		@Override
		public void historyNotification(OperationHistoryEvent event) {
			if (event.getEventType() == OperationHistoryEvent.ABOUT_TO_REDO
					|| event.getEventType() == OperationHistoryEvent.ABOUT_TO_UNDO) {
				refresh();
			}
		}
	};
	operationHistory.addOperationHistoryListener(operationHistoryListener);
	setRootEntry(createRootEntry());
}
 
Example #5
Source File: UndoManager.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void historyNotification(OperationHistoryEvent event) {

  if (!enabled) return;

  /*
   * OPERATION_ADDED is triggered when Eclipse adds a new operation to
   * its history. We do the same on this event.
   */
  if (event.getEventType() == OperationHistoryEvent.OPERATION_ADDED) {
    storeCurrentLocalOperation();
    updateCurrentLocalAtomicOperation(null);
  }

  /*
   * OPERATION_CHANGED is triggered when Eclipse changes the operation
   * that is recently added to its history. For example: Eclipse adds
   * Insert(3,"A") to its operation and later on the user enters B at
   * position 4. If Eclipse decides not to add a new Undo step it
   * changes the most recent operation in history to Insert(3, "AB")
   */
  if (event.getEventType() == OperationHistoryEvent.OPERATION_CHANGED) {
    updateCurrentLocalAtomicOperation(null);
  }
}
 
Example #6
Source File: OperationHistoryListener.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void historyNotification(OperationHistoryEvent event) {
	final int type = event.getEventType();
	switch (type) {
		case OperationHistoryEvent.UNDONE:
		case OperationHistoryEvent.REDONE:
		case OperationHistoryEvent.OPERATION_ADDED:
		case OperationHistoryEvent.OPERATION_REMOVED:
		case OperationHistoryEvent.OPERATION_NOT_OK:
			// if this is one of our operations
			if (event.getOperation().hasContext(this.context)) {
				this.update.update();
			}
	}
}