@Override public void dispose(IUndoContext context, boolean flushUndo, boolean flushRedo, boolean flushContext) { // dispose of any limit that was set for the context if it is not to be // used again. if (flushContext) { if (DEBUG_OPERATION_HISTORY_DISPOSE) { Tracing.printTrace("OPERATIONHISTORY", "Flushing context " //$NON-NLS-1$//$NON-NLS-2$ + context); } flushUndo(context); flushRedo(context); limits.remove(context); return; } if (flushUndo) { flushUndo(context); } if (flushRedo) { flushRedo(context); } }
private IStatus getRedoApproval(IUndoableOperation operation, IAdaptable info) { final Object[] approverArray = approvers.getListeners(); for (int i = 0; i < approverArray.length; i++) { IOperationApprover approver = (IOperationApprover) approverArray[i]; IStatus approval = approver.proceedRedoing(operation, this, info); if (!approval.isOK()) { if (DEBUG_OPERATION_HISTORY_APPROVAL) { Tracing.printTrace("OPERATIONHISTORY", //$NON-NLS-1$ "Redo not approved by " + approver //$NON-NLS-1$ + "for operation " + operation //$NON-NLS-1$ + " approved by " + approval); //$NON-NLS-1$ } return approval; } } return Status.OK_STATUS; }
private IStatus getUndoApproval(IUndoableOperation operation, IAdaptable info) { final Object[] approverArray = approvers.getListeners(); for (int i = 0; i < approverArray.length; i++) { IOperationApprover approver = (IOperationApprover) approverArray[i]; IStatus approval = approver.proceedUndoing(operation, this, info); if (!approval.isOK()) { if (DEBUG_OPERATION_HISTORY_APPROVAL) { Tracing.printTrace("OPERATIONHISTORY", //$NON-NLS-1$ "Undo not approved by " + approver //$NON-NLS-1$ + "for operation " + operation //$NON-NLS-1$ + " with status " + approval); //$NON-NLS-1$ } return approval; } } return Status.OK_STATUS; }
private IStatus getExecuteApproval(IUndoableOperation operation, IAdaptable info) { final Object[] approverArray = approvers.getListeners(); for (int i = 0; i < approverArray.length; i++) { if (approverArray[i] instanceof IOperationApprover2) { IOperationApprover2 approver = (IOperationApprover2) approverArray[i]; IStatus approval = approver.proceedExecuting(operation, this, info); if (!approval.isOK()) { if (DEBUG_OPERATION_HISTORY_APPROVAL) { Tracing.printTrace("OPERATIONHISTORY", //$NON-NLS-1$ "Execute not approved by " + approver //$NON-NLS-1$ + "for operation " + operation //$NON-NLS-1$ + " with status " + approval); //$NON-NLS-1$ } return approval; } } } return Status.OK_STATUS; }
@Override public IStatus redo(IUndoContext context, IProgressMonitor monitor, IAdaptable info) throws ExecutionException { Assert.isNotNull(context); IUndoableOperation operation = getRedoOperation(context); // info if there is no operation if (operation == null) { return IOperationHistory.NOTHING_TO_REDO_STATUS; } // error if operation is invalid if (!operation.canRedo()) { if (DEBUG_OPERATION_HISTORY_UNEXPECTED) { Tracing.printTrace("OPERATIONHISTORY", //$NON-NLS-1$ "Redo operation not valid - " + operation); //$NON-NLS-1$ } return IOperationHistory.OPERATION_INVALID_STATUS; } return doRedo(monitor, info, operation); }
@Override public IStatus redoOperation(IUndoableOperation operation, IProgressMonitor monitor, IAdaptable info) throws ExecutionException { Assert.isNotNull(operation); IStatus status; if (operation.canRedo()) { status = doRedo(monitor, info, operation); } else { if (DEBUG_OPERATION_HISTORY_UNEXPECTED) { Tracing.printTrace("OPERATIONHISTORY", //$NON-NLS-1$ "Redo operation not valid - " + operation); //$NON-NLS-1$ } status = IOperationHistory.OPERATION_INVALID_STATUS; } return status; }
@Override public IStatus undo(IUndoContext context, IProgressMonitor monitor, IAdaptable info) throws ExecutionException { Assert.isNotNull(context); IUndoableOperation operation = getUndoOperation(context); // info if there is no operation if (operation == null) { return IOperationHistory.NOTHING_TO_UNDO_STATUS; } // error if operation is invalid if (!operation.canUndo()) { if (DEBUG_OPERATION_HISTORY_UNEXPECTED) { Tracing.printTrace("OPERATIONHISTORY", //$NON-NLS-1$ "Undo operation not valid - " + operation); //$NON-NLS-1$ } return IOperationHistory.OPERATION_INVALID_STATUS; } return doUndo(monitor, info, operation); }
@Override public IStatus undoOperation(IUndoableOperation operation, IProgressMonitor monitor, IAdaptable info) throws ExecutionException { Assert.isNotNull(operation); IStatus status; if (operation.canUndo()) { status = doUndo(monitor, info, operation); } else { if (DEBUG_OPERATION_HISTORY_UNEXPECTED) { Tracing.printTrace("OPERATIONHISTORY", //$NON-NLS-1$ "Undo operation not valid - " + operation); //$NON-NLS-1$ } status = IOperationHistory.OPERATION_INVALID_STATUS; } return status; }
@Override public void openOperation(ICompositeOperation operation, int mode) { synchronized (openCompositeLock) { if (openComposite != null && openComposite != operation) { // unexpected nesting of operations. if (DEBUG_OPERATION_HISTORY_UNEXPECTED) { Tracing.printTrace("OPERATIONHISTORY", //$NON-NLS-1$ "Open operation called while another operation is open. old: " //$NON-NLS-1$ + openComposite + "; new: " + operation); //$NON-NLS-1$ } throw new IllegalStateException( "Cannot open an operation while one is already open"); //$NON-NLS-1$ } openComposite = operation; } if (DEBUG_OPERATION_HISTORY_OPENOPERATION) { Tracing.printTrace("OPERATIONHISTORY", "Opening operation " //$NON-NLS-1$ //$NON-NLS-2$ + openComposite); } if (mode == EXECUTE) { notifyAboutToExecute(openComposite); } }
public void dispose(IUndoContext context, boolean flushUndo, boolean flushRedo, boolean flushContext) { // dispose of any limit that was set for the context if it is not to be // used again. if (flushContext) { if (DEBUG_OPERATION_HISTORY_DISPOSE) { Tracing.printTrace("OPERATIONHISTORY", "Flushing context " //$NON-NLS-1$//$NON-NLS-2$ + context); } flushUndo(context); flushRedo(context); limits.remove(context); return; } if (flushUndo) { flushUndo(context); } if (flushRedo) { flushRedo(context); } }
public IStatus redo(IUndoContext context, IProgressMonitor monitor, IAdaptable info) throws ExecutionException { Assert.isNotNull(context); IUndoableOperation operation = getRedoOperation(context); // info if there is no operation if (operation == null) { return IOperationHistory.NOTHING_TO_REDO_STATUS; } // error if operation is invalid if (!operation.canRedo()) { if (DEBUG_OPERATION_HISTORY_UNEXPECTED) { Tracing.printTrace("OPERATIONHISTORY", //$NON-NLS-1$ "Redo operation not valid - " + operation); //$NON-NLS-1$ } return IOperationHistory.OPERATION_INVALID_STATUS; } return doRedo(monitor, info, operation); }
public IStatus redoOperation(IUndoableOperation operation, IProgressMonitor monitor, IAdaptable info) throws ExecutionException { Assert.isNotNull(operation); IStatus status; if (operation.canRedo()) { status = doRedo(monitor, info, operation); } else { if (DEBUG_OPERATION_HISTORY_UNEXPECTED) { Tracing.printTrace("OPERATIONHISTORY", //$NON-NLS-1$ "Redo operation not valid - " + operation); //$NON-NLS-1$ } status = IOperationHistory.OPERATION_INVALID_STATUS; } return status; }
public IStatus undo(IUndoContext context, IProgressMonitor monitor, IAdaptable info) throws ExecutionException { Assert.isNotNull(context); IUndoableOperation operation = getUndoOperation(context); // info if there is no operation if (operation == null) { return IOperationHistory.NOTHING_TO_UNDO_STATUS; } // error if operation is invalid if (!operation.canUndo()) { if (DEBUG_OPERATION_HISTORY_UNEXPECTED) { Tracing.printTrace("OPERATIONHISTORY", //$NON-NLS-1$ "Undo operation not valid - " + operation); //$NON-NLS-1$ } return IOperationHistory.OPERATION_INVALID_STATUS; } return doUndo(monitor, info, operation); }
public IStatus undoOperation(IUndoableOperation operation, IProgressMonitor monitor, IAdaptable info) throws ExecutionException { Assert.isNotNull(operation); IStatus status; if (operation.canUndo()) { status = doUndo(monitor, info, operation); } else { if (DEBUG_OPERATION_HISTORY_UNEXPECTED) { Tracing.printTrace("OPERATIONHISTORY", //$NON-NLS-1$ "Undo operation not valid - " + operation); //$NON-NLS-1$ } status = IOperationHistory.OPERATION_INVALID_STATUS; } return status; }
public void openOperation(ICompositeOperation operation, int mode) { synchronized (openCompositeLock) { if (openComposite != null && openComposite != operation) { // unexpected nesting of operations. if (DEBUG_OPERATION_HISTORY_UNEXPECTED) { Tracing.printTrace("OPERATIONHISTORY", //$NON-NLS-1$ "Open operation called while another operation is open. old: " //$NON-NLS-1$ + openComposite + "; new: " + operation); //$NON-NLS-1$ } throw new IllegalStateException( "Cannot open an operation while one is already open"); //$NON-NLS-1$ } openComposite = operation; } if (DEBUG_OPERATION_HISTORY_OPENOPERATION) { Tracing.printTrace("OPERATIONHISTORY", "Opening operation " //$NON-NLS-1$ //$NON-NLS-2$ + openComposite); } if (mode == EXECUTE) { notifyAboutToExecute(openComposite); } }
/** * Notifies the execution listeners for this command that an attempt to * execute has failed because the command is not defined. * * @param e * The exception that is about to be thrown; never * <code>null</code>. * @since 3.2 */ private final void fireNotDefined(final NotDefinedException e) { // Debugging output if (DEBUG_COMMAND_EXECUTION) { Tracing.printTrace("COMMANDS", "execute" + Tracing.SEPARATOR //$NON-NLS-1$ //$NON-NLS-2$ + "not defined: id=" + getId() + "; exception=" + e); //$NON-NLS-1$ //$NON-NLS-2$ } if (executionListeners != null) { final Object[] listeners = executionListeners.getListeners(); for (int i = 0; i < listeners.length; i++) { final Object object = listeners[i]; if (object instanceof IExecutionListenerWithChecks) { final IExecutionListenerWithChecks listener = (IExecutionListenerWithChecks) object; listener.notDefined(getId(), e); } } } }
/** * Notifies the execution listeners for this command that an attempt to * execute has failed because there is no handler. * * @param e * The exception that is about to be thrown; never * <code>null</code>. * @since 3.2 */ private final void fireNotEnabled(final NotEnabledException e) { // Debugging output if (DEBUG_COMMAND_EXECUTION) { Tracing.printTrace("COMMANDS", "execute" + Tracing.SEPARATOR //$NON-NLS-1$ //$NON-NLS-2$ + "not enabled: id=" + getId() + "; exception=" + e); //$NON-NLS-1$ //$NON-NLS-2$ } if (executionListeners != null) { final Object[] listeners = executionListeners.getListeners(); for (int i = 0; i < listeners.length; i++) { final Object object = listeners[i]; if (object instanceof IExecutionListenerWithChecks) { final IExecutionListenerWithChecks listener = (IExecutionListenerWithChecks) object; listener.notEnabled(getId(), e); } } } }
/** * Notifies the execution listeners for this command that an attempt to * execute has failed because there is no handler. * * @param e * The exception that is about to be thrown; never * <code>null</code>. */ private final void fireNotHandled(final NotHandledException e) { // Debugging output if (DEBUG_COMMAND_EXECUTION) { Tracing.printTrace("COMMANDS", "execute" + Tracing.SEPARATOR //$NON-NLS-1$ //$NON-NLS-2$ + "not handled: id=" + getId() + "; exception=" + e); //$NON-NLS-1$ //$NON-NLS-2$ } if (executionListeners != null) { final Object[] listeners = executionListeners.getListeners(); for (int i = 0; i < listeners.length; i++) { final IExecutionListener listener = (IExecutionListener) listeners[i]; listener.notHandled(getId(), e); } } }
/** * Notifies the execution listeners for this command that an attempt to * execute has failed during the execution. * * @param e * The exception that has been thrown; never <code>null</code>. * After this method completes, the exception will be thrown * again. */ private final void firePostExecuteFailure(final ExecutionException e) { // Debugging output if (DEBUG_COMMAND_EXECUTION) { Tracing.printTrace("COMMANDS", "execute" + Tracing.SEPARATOR //$NON-NLS-1$ //$NON-NLS-2$ + "failure: id=" + getId() + "; exception=" + e); //$NON-NLS-1$ //$NON-NLS-2$ } if (executionListeners != null) { final Object[] listeners = executionListeners.getListeners(); for (int i = 0; i < listeners.length; i++) { final IExecutionListener listener = (IExecutionListener) listeners[i]; listener.postExecuteFailure(getId(), e); } } }
/** * Notifies the execution listeners for this command that an execution has * completed successfully. * * @param returnValue * The return value from the command; may be <code>null</code>. */ private final void firePostExecuteSuccess(final Object returnValue) { // Debugging output if (DEBUG_COMMAND_EXECUTION) { Tracing.printTrace("COMMANDS", "execute" + Tracing.SEPARATOR //$NON-NLS-1$ //$NON-NLS-2$ + "success: id=" + getId() + "; returnValue=" //$NON-NLS-1$ //$NON-NLS-2$ + returnValue); } if (executionListeners != null) { final Object[] listeners = executionListeners.getListeners(); for (int i = 0; i < listeners.length; i++) { final IExecutionListener listener = (IExecutionListener) listeners[i]; listener.postExecuteSuccess(getId(), returnValue); } } }
/** * Notifies the execution listeners for this command that an attempt to * execute is about to start. * * @param event * The execution event that will be used; never <code>null</code>. */ private final void firePreExecute(final ExecutionEvent event) { // Debugging output if (DEBUG_COMMAND_EXECUTION) { Tracing.printTrace("COMMANDS", "execute" + Tracing.SEPARATOR //$NON-NLS-1$ //$NON-NLS-2$ + "starting: id=" + getId() + "; event=" + event); //$NON-NLS-1$ //$NON-NLS-2$ } if (executionListeners != null) { final Object[] listeners = executionListeners.getListeners(); for (int i = 0; i < listeners.length; i++) { final IExecutionListener listener = (IExecutionListener) listeners[i]; listener.preExecute(getId(), event); } } }
/** * Returns whether this command has a handler, and whether this handler is * also handled and enabled. * * @return <code>true</code> if the command is handled; <code>false</code> * otherwise. */ public final boolean isEnabled() { if (handler == null) { return false; } try { return handler.isEnabled(); } catch (Exception e) { if (DEBUG_HANDLERS) { // since this has the ability to generate megs of logs, only // provide information if tracing Tracing.printTrace("HANDLERS", "Handler " + handler + " for " //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + id + " threw unexpected exception"); //$NON-NLS-1$ e.printStackTrace(System.out); } } return false; }
/** * Activates a context in this context manager. * * @param contextId * The identifier of the context to activate; must not be * <code>null</code>. */ public final void addActiveContext(final String contextId) { if (activeContextIds.contains(contextId)) { return; } activeContextsChange = true; if (caching) { activeContextIds.add(contextId); } else { final Set previouslyActiveContextIds = new HashSet(activeContextIds); activeContextIds.add(contextId); fireContextManagerChanged(new ContextManagerEvent(this, null, false, true, previouslyActiveContextIds)); } if (DEBUG) { Tracing.printTrace("CONTEXTS", activeContextIds.toString()); //$NON-NLS-1$ } }
/** * Deactivates a context in this context manager. * * @param contextId * The identifier of the context to deactivate; must not be * <code>null</code>. */ public final void removeActiveContext(final String contextId) { if (!activeContextIds.contains(contextId)) { return; } activeContextsChange = true; if (caching) { activeContextIds.remove(contextId); } else { final Set previouslyActiveContextIds = new HashSet(activeContextIds); activeContextIds.remove(contextId); fireContextManagerChanged(new ContextManagerEvent(this, null, false, true, previouslyActiveContextIds)); } if (DEBUG) { Tracing.printTrace("CONTEXTS", activeContextIds.toString()); //$NON-NLS-1$ } }
/** * Changes the set of active contexts for this context manager. The whole * set is required so that internal consistency can be maintained and so * that excessive recomputations do nothing occur. * * @param activeContextIds * The new set of active context identifiers; may be * <code>null</code>. */ public final void setActiveContextIds(final Set activeContextIds) { if (Util.equals(this.activeContextIds, activeContextIds)) { return; } activeContextsChange = true; final Set previouslyActiveContextIds = this.activeContextIds; if (activeContextIds != null) { this.activeContextIds = new HashSet(); this.activeContextIds.addAll(activeContextIds); } else { this.activeContextIds = null; } if (DEBUG) { Tracing.printTrace("CONTEXTS", (activeContextIds == null) ? "none" //$NON-NLS-1$ //$NON-NLS-2$ : activeContextIds.toString()); } if (!caching) { fireContextManagerChanged(new ContextManagerEvent(this, null, false, true, previouslyActiveContextIds)); } }
private void flushRedo(IUndoContext context) { if (DEBUG_OPERATION_HISTORY_DISPOSE) { Tracing.printTrace("OPERATIONHISTORY", "Flushing redo history for " //$NON-NLS-1$ //$NON-NLS-2$ + context); } synchronized (undoRedoHistoryLock) { Object[] filtered = filter(redoList, context); for (int i = 0; i < filtered.length; i++) { IUndoableOperation operation = (IUndoableOperation) filtered[i]; if (context == GLOBAL_UNDO_CONTEXT || operation.getContexts().length == 1) { // remove the operation if it only has the context or we are // flushing all redoList.remove(operation); internalRemove(operation); } else { // remove the reference to the context. // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=161786 // It is not enough to simply remove the context. There could // be one or more contexts that match the one we are trying to // dispose. IUndoContext[] contexts = operation.getContexts(); for (int j = 0; j < contexts.length; j++) { if (contexts[j].matches(context)) { operation.removeContext(contexts[j]); } } if (operation.getContexts().length == 0) { redoList.remove(operation); internalRemove(operation); } } } } }
private void notifyAboutToExecute(IUndoableOperation operation) { if (DEBUG_OPERATION_HISTORY_NOTIFICATION) { Tracing.printTrace("OPERATIONHISTORY", "ABOUT_TO_EXECUTE " //$NON-NLS-1$ //$NON-NLS-2$ + operation); } notifyListeners(new OperationHistoryEvent( OperationHistoryEvent.ABOUT_TO_EXECUTE, this, operation)); }
private void notifyAboutToRedo(IUndoableOperation operation) { if (DEBUG_OPERATION_HISTORY_NOTIFICATION) { Tracing.printTrace("OPERATIONHISTORY", "ABOUT_TO_REDO " //$NON-NLS-1$ //$NON-NLS-2$ + operation); } notifyListeners(new OperationHistoryEvent( OperationHistoryEvent.ABOUT_TO_REDO, this, operation)); }
private void notifyAboutToUndo(IUndoableOperation operation) { if (DEBUG_OPERATION_HISTORY_NOTIFICATION) { Tracing.printTrace("OPERATIONHISTORY", "ABOUT_TO_UNDO " //$NON-NLS-1$ //$NON-NLS-2$ + operation); } notifyListeners(new OperationHistoryEvent( OperationHistoryEvent.ABOUT_TO_UNDO, this, operation)); }
private void notifyAdd(IUndoableOperation operation) { if (DEBUG_OPERATION_HISTORY_NOTIFICATION) { Tracing.printTrace("OPERATIONHISTORY", "OPERATION_ADDED " //$NON-NLS-1$ //$NON-NLS-2$ + operation); } notifyListeners(new OperationHistoryEvent( OperationHistoryEvent.OPERATION_ADDED, this, operation)); }
private void notifyDone(IUndoableOperation operation) { if (DEBUG_OPERATION_HISTORY_NOTIFICATION) { Tracing.printTrace("OPERATIONHISTORY", "DONE " + operation); //$NON-NLS-1$ //$NON-NLS-2$ } notifyListeners(new OperationHistoryEvent(OperationHistoryEvent.DONE, this, operation)); }
private void notifyNotOK(IUndoableOperation operation, IStatus status) { if (DEBUG_OPERATION_HISTORY_NOTIFICATION) { Tracing.printTrace("OPERATIONHISTORY", "OPERATION_NOT_OK " //$NON-NLS-1$ //$NON-NLS-2$ + operation); } notifyListeners(new OperationHistoryEvent( OperationHistoryEvent.OPERATION_NOT_OK, this, operation, status)); }
private void notifyRedone(IUndoableOperation operation) { if (DEBUG_OPERATION_HISTORY_NOTIFICATION) { Tracing.printTrace("OPERATIONHISTORY", "REDONE " + operation); //$NON-NLS-1$ //$NON-NLS-2$ } notifyListeners(new OperationHistoryEvent(OperationHistoryEvent.REDONE, this, operation)); }
private void notifyRemoved(IUndoableOperation operation) { if (DEBUG_OPERATION_HISTORY_NOTIFICATION) { Tracing.printTrace("OPERATIONHISTORY", "OPERATION_REMOVED " //$NON-NLS-1$ //$NON-NLS-2$ + operation); } notifyListeners(new OperationHistoryEvent( OperationHistoryEvent.OPERATION_REMOVED, this, operation)); }
private void notifyUndone(IUndoableOperation operation) { if (DEBUG_OPERATION_HISTORY_NOTIFICATION) { Tracing.printTrace("OPERATIONHISTORY", "UNDONE " + operation); //$NON-NLS-1$ //$NON-NLS-2$ } notifyListeners(new OperationHistoryEvent(OperationHistoryEvent.UNDONE, this, operation)); }
private void notifyChanged(IUndoableOperation operation) { if (DEBUG_OPERATION_HISTORY_NOTIFICATION) { Tracing.printTrace("OPERATIONHISTORY", "OPERATION_CHANGED " //$NON-NLS-1$//$NON-NLS-2$ + operation); } notifyListeners(new OperationHistoryEvent( OperationHistoryEvent.OPERATION_CHANGED, this, operation)); }
@Override public IStatus undo(final IUndoContext context, final IProgressMonitor operationMonitor, final IAdaptable info) throws ExecutionException { if (!isJobContext(context)) { return super.undo(context, operationMonitor, info); } OperationJob job = new OperationJob(context, "undo") { @Override protected IStatus run(IProgressMonitor jobMonitor) { IUndoableOperation operation = getUndoOperation(context); // info if there is no operation if (operation == null) { return IOperationHistory.NOTHING_TO_UNDO_STATUS; } // error if operation is invalid if (!operation.canUndo()) { if (DEBUG_OPERATION_HISTORY_UNEXPECTED) { Tracing.printTrace("OPERATIONHISTORY", //$NON-NLS-1$ "Undo operation not valid - " + operation); //$NON-NLS-1$ } return IOperationHistory.OPERATION_INVALID_STATUS; } setName("undo " + operation.getLabel()); IProgressMonitor monitor = DoubleProgressMonitor.combine(operationMonitor, jobMonitor); return inJobEnforceRule(info, monitor, operation, true); } }; job.schedule(); return new JobOperationStatus(job); }