Java 类org.eclipse.core.commands.operations.IOperationHistory 实例源码

项目:bts    文件:LinkedEditingUndoSupport.java   
public void undoDocumentChanges() {
    final ISourceViewer viewer = editor.getInternalSourceViewer();
    try {
        editor.getSite().getWorkbenchWindow().run(false, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                if (viewer instanceof ITextViewerExtension6) {
                    IUndoManager undoManager = ((ITextViewerExtension6) viewer).getUndoManager();
                    if (undoManager instanceof IUndoManagerExtension) {
                        IUndoManagerExtension undoManagerExtension = (IUndoManagerExtension) undoManager;
                        IUndoContext undoContext = undoManagerExtension.getUndoContext();
                        IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
                        while (undoManager.undoable()) {
                            if (startingUndoOperation != null
                                    && startingUndoOperation.equals(operationHistory.getUndoOperation(undoContext)))
                                return;
                            undoManager.undo();
                        }
                    }
                }
            }
        });
        syncUtil.waitForReconciler(editor);
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    }
}
项目:statecharts    文件:SetEntryKindCommand.java   
public Object execute(ExecutionEvent event) throws ExecutionException {
    entry = unwrap(HandlerUtil.getCurrentSelection(event));

    if (entry == null)
        return null;
    SetValueCommand setCommand = new SetValueCommand(new SetRequest(entry,
            SGraphPackage.Literals.ENTRY__KIND, getEntryKind()));
    IOperationHistory history = OperationHistoryFactory
            .getOperationHistory();
    try {
        history.execute(setCommand, new NullProgressMonitor(), null);
    } catch (ExecutionException e) {
        e.printStackTrace();
    }

    return null;
}
项目:che    文件:UndoManager2.java   
public void flush() {
  if (fActiveOperation != null) {
    if (fIsOpen) {
      fOperationHistory.closeOperation(false, false, IOperationHistory.EXECUTE);
    }
    /* the triggering operation is invalid, but we must ensure that any
     * other operations executed while it was open remain in the undo
     * history.  We accomplish this by adding the invalid operation,
     * since disposing the context later will cause it to be broken up into
     * its atomic parts.
     */
    fOperationHistory.add(fActiveOperation);
  }
  fActiveOperation = null;
  fIsOpen = false;
  fOperationHistory.dispose(RefactoringCorePlugin.getUndoContext(), true, true, false);
}
项目:OpenSPIFe    文件:UndoableOperationTestUtil.java   
/**
 * Execute the given operation in the supplied undo context
 * Tests that the operation can be executed, 
 * that the execute result isOK() and that no ExecutionException is thrown.
 * @param operation
 * @param undoContext
 */
public static final void executeOperation(IUndoableOperation operation, IUndoContext undoContext) {
    operation.addContext(undoContext);
    TestCase.assertTrue("Operation can't execute.", operation.canExecute());
    try {
        IOperationHistory history = OperationHistoryFactory.getOperationHistory();
        IStatus result = history.execute(operation, null, null);
        TestCase.assertTrue("failed to execute: " + operation.getLabel(), result.isOK());
    } catch (ExecutionException ee) {
        TestCase.fail("failed to execute");
    }
    TestCase.assertFalse(operation.canExecute());
    IUndoContext[] contexts = operation.getContexts();
    if ((contexts != null) && (contexts.length > 0)) { 
        // Operations that don't accept contexts don't need to be undoable.
        // An example such operation is ClipboardCopyOperation, 
        // or any other AbstractEnsembleDoableOperation
        TestCase.assertTrue("Operation is not undoable.", operation.canUndo());
    }
}
项目:OpenSPIFe    文件:OneOfEachAction.java   
private void createAddOperation(PlanEditorModel model, final EPlanElement parent, final EPlanElement child) {
    IStructureModifier modifier = PlanStructureModifier.INSTANCE;
    PlanTransferable transferable = new PlanTransferable();
    transferable.setPlanElements(Collections.singletonList(child));
    IStructureLocation location = modifier.getInsertionLocation(transferable, new StructuredSelection(parent), InsertionSemantics.ON);
    AddOperation operation = new PlanAddOperation(transferable, modifier, location);
    IUndoContext undoContext = model.getUndoContext();
    operation.addContext(undoContext);
    try {
        IOperationHistory history = OperationHistoryFactory.getOperationHistory();
        IStatus status = history.execute(operation, null, null);
        if (status instanceof JobOperationStatus) {
            ((JobOperationStatus) status).getJob().join();
        }
    } catch (Exception e) {
        trace.error("OneOfEachAction.createAddGroupOperation:operation", e);
    }
}
项目:OpenSPIFe    文件:ProfileDataPointColumnProvider.java   
@Override
public void modify(DataPoint oldDataPoint, Object value, IUndoContext undoContext) {
    if (value instanceof Date) {
        DataPoint newDataPoint = JScienceFactory.eINSTANCE.createEDataPoint((Date) value, oldDataPoint.getValue());
        SwapProfileDataPointOperation op = new SwapProfileDataPointOperation(profile, oldDataPoint, newDataPoint);
        if (undoContext != null) {
            op.addContext(undoContext);
        }
        IOperationHistory history = OperationHistoryFactory.getOperationHistory();
        try {
            history.execute(op, null, null);
        } catch (ExecutionException e) {
            LogUtil.error(e);
        }
    }
}
项目:OpenSPIFe    文件:TemporalDetailProvider.java   
private void setCalculatedVariable(TemporalMember target, CalculatedVariable calculatedVariable) {
    Object oldValue = target.eGet(CALCULATED_VARIABLE_FEATURE);
    if (oldValue == calculatedVariable) {
        if (oldValue != CalculatedVariable.END) {
            calculatedVariable = CalculatedVariable.END;
        } else if (TemporalMemberUtils.hasDurationFormula(target)) {
            calculatedVariable = CalculatedVariable.START;
        } else {
            calculatedVariable = CalculatedVariable.DURATION;
        }
    }
    IUndoableOperation operation = new FeatureTransactionChangeOperation("Set calculated variable", target, CALCULATED_VARIABLE_FEATURE, oldValue, calculatedVariable);
    operation.addContext(EMFUtils.getUndoContext(target));
    IOperationHistory history = OperationHistoryFactory.getOperationHistory();
    try {
        history.execute(operation, null, null);
    } catch (ExecutionException e) {
        LogUtil.error("failed to set calculated variable", e);
    }
}
项目:OpenSPIFe    文件:PlanElementRowEditPart.java   
private void addVisibleLabel(IFigure figure) {
    visibleLabel = new Label();
    visibleLabel.setBorder(new SimpleRaisedBorder());
    visibleLabel.addMouseListener(new MouseListener.Stub() {
        @Override
        public void mousePressed(MouseEvent me) {
            EPlanElement node = getModel();
            TriState oldValue = SpifePlanUtils.getVisible(node);
            if (!PlanEditApproverRegistry.getInstance().canModify(node)) {
                return;
            }
            try {
                VisibleOperation op = new VisibleOperation(node, oldValue == TriState.FALSE);
                op.addContext(TransactionUtils.getUndoContext(node));
                IOperationHistory history = OperationHistoryFactory.getOperationHistory();
                history.execute(op, null, null);
            } catch (Exception e) {
                trace.error(e.getMessage(), e);
            }
        }
    });
    updateVisibleVisual();
    figure.add(visibleLabel);
}
项目:OpenSPIFe    文件:OrderEventsAscendingHandler.java   
protected void runImpl(MultiPagePlanEditor editor, EPlan plan) {
    EPlanElement parent = getSelection(editor);
    if (parent==null){
        parent=plan;
    }
    List<EPlanChild> childList = new ArrayList<EPlanChild>();
    for (EPlanChild child : parent.getChildren()) {
        childList.add(child);
    }
    Collections.sort(childList, new ScheduledActivtyComparator());
    IStructureModifier modifier = PlanStructureModifier.INSTANCE;
    PlanTransferable transferable = new PlanTransferable();
    transferable.setPlanElements(childList);
    IStructureLocation location = modifier.getInsertionLocation(transferable, new StructuredSelection(parent), InsertionSemantics.ON);
    PlanEditorModel model = editor.getPlanEditorModel();
    MoveOperation operation = new PlanMoveOperation(transferable, modifier, location);
    IUndoContext undoContext = model.getUndoContext();
    operation.addContext(undoContext);
    try {
        IOperationHistory history = OperationHistoryFactory.getOperationHistory();
        history.execute(operation, null, null);
    } catch (Exception e) {
        LogUtil.error(OrderEventsAscendingHandler.class.getName(), e);
    }
}
项目:OpenSPIFe    文件:UndoableObservableValue.java   
@Override
protected void doSetValue(final Object value) {
    Object oldValue = doGetValue();
    if (CommonUtils.equals(value, oldValue)) {
        return; // nothing to do
    }
    EStructuralFeature feature = (EStructuralFeature) pd.getFeature(target);
    String name = EMFUtils.getDisplayName(target, feature);
    IUndoableOperation operation = new ChangeObservableOperation("Edit " + name, value);
    EObject observed = (EObject) getObserved();
    operation = EMFUtils.addContributorOperations(operation, observed, feature, oldValue, value);
    IUndoContext context = gov.nasa.ensemble.emf.transaction.TransactionUtils.getUndoContext(observed);
    IOperationHistory history = OperationHistoryFactory.getOperationHistory();
    IUndoableOperation previous = history.getUndoOperation(context);
    if (previous instanceof TextModifyUndoableObservableValue.TextModifyObservableOperation) {
        // Reset the TextModifyObservableOperation to clear the dirty flag on its TextModifyUndoableObservableValue
        ((TextModifyUndoableObservableValue.TextModifyObservableOperation) previous).reset();
        // Remove the TextModifyObservableOperation operation from the operation history as it should be replaced by the new operation
        history.replaceOperation(previous, new IUndoableOperation[0]);
    }
    CommonUtils.execute(operation, context);
}
项目:OpenSPIFe    文件:EMFTreeTableColumn.java   
@Override
public void modify(T facet, Object value, IUndoContext undoContext) {
    IUndoableOperation operation = new PropertyDescriptorUpdateOperation("Set value", facet, itemPropertyDescriptor, value);
    operation = EMFDetailUtils.addContributorOperations(operation, facet, itemPropertyDescriptor, value);
    operation.addContext(undoContext);
    IWorkbenchOperationSupport operationSupport = PlatformUI.getWorkbench().getOperationSupport();
    IOperationHistory operationHistory = operationSupport.getOperationHistory();
    try {
        IStatus execute = operationHistory.execute(operation, null, null);
        if(execute.matches(IStatus.ERROR)) {
            throw new ExecutionException(execute.getMessage());
        }
    } catch (ExecutionException e) {
        LogUtil.error(e);
    }
}
项目:OpenSPIFe    文件:WidgetUtils.java   
/**
 * Execute the operation in the undo context, in a job.
 * 
 * If the operation is an IDisplayOperation, and both the widget and site are provided,
 * then the job will be created as a DisplayOperationJob.
 * 
 * If the operation can not be executed, it will be disposed.
 * 
 * @param operation
 * @param undoContext
 * @param widget
 * @param site
 */
public static void execute(final IUndoableOperation operation, IUndoContext undoContext, final Widget widget, final IWorkbenchSite site) {
    IOperationHistory history = OperationHistoryFactory.getOperationHistory();
    IAdaptable adaptable = null;
    if ((operation instanceof IDisplayOperation) && (widget != null) && (site != null)) {
        IDisplayOperation displayOperation = (IDisplayOperation) operation;
        adaptable = new IDisplayOperation.Adaptable(displayOperation, widget, site);
    }
    if (undoContext != null) {
        operation.addContext(undoContext);
    }
    try {
        history.execute(operation, null, adaptable);
    } catch (ExecutionException e) {
        // should never occur
        LogUtil.error(e);
    }
}
项目:OpenSPIFe    文件:TestCutPasteOperation.java   
/**
 * @param plan
 * @param selectedElements
 * @param targetElements
 * @param assertPostconditions
 */
private void cutPasteElements(final OperationTestPlanRecord plan, final EPlanElement[] selectedElements, final EPlanElement[] targetElements, Runnable assertPostconditions) {
    final IStructuredSelection selection = new StructuredSelection(selectedElements);
    final IStructureModifier modifier = PlanStructureModifier.INSTANCE;
    ITransferable transferable = modifier.getTransferable(selection);
    IUndoableOperation cut = new PlanClipboardCutOperation(transferable, modifier);
    cut.addContext(TransactionUtils.getUndoContext(plan.plan));
    // cut
    try {
        IOperationHistory history = OperationHistoryFactory.getOperationHistory();
        IStatus result = history.execute(cut, null, null);
        assertTrue("failed to execute: " + cut.getLabel(), result.isOK());
    } catch (ExecutionException ee) {
        fail("failed to execute");
    }

    final IStructuredSelection targetSelection = new StructuredSelection(targetElements);
    IUndoableOperation paste = new PlanClipboardPasteOperation(targetSelection, modifier);
    testUndoableOperation(plan.plan, paste, assertPostconditions);
}
项目:OpenSPIFe    文件:TestCopyPasteOperation.java   
/**
 * @param plan
 * @param selectedElements
 * @param targetElements
 * @param assertPostconditions
 */
private void copyPasteElements(final OperationTestPlanRecord plan, final EPlanElement[] selectedElements, final EPlanElement[] targetElements, final PasteOperationRunnable assertPostconditions) {
    final IStructuredSelection selection = new StructuredSelection(selectedElements);
    final IStructureModifier modifier = PlanStructureModifier.INSTANCE;
    ITransferable transferable = modifier.getTransferable(selection);
    IUndoableOperation copy = new ClipboardCopyOperation(transferable, modifier);

    // copy
    try {
        IOperationHistory history = OperationHistoryFactory.getOperationHistory();
        history.execute(copy, null, null);
    } catch (ExecutionException ee) {
        fail("failed to execute");
    }

    final IStructuredSelection targetSelection = new StructuredSelection(targetElements);
    final PlanClipboardPasteOperation paste = new PlanClipboardPasteOperation(targetSelection, modifier);

    testUndoableOperation(plan.plan, paste, 
            new Runnable() {
                @Override
                public void run() {
                    assertPostconditions.run(paste);
                }
            });
}
项目:OpenSPIFe    文件:FeatureTransactionAddOperation.java   
public static <T> void execute(String label, EcoreEList<T> list, T object) {
    if (list.getEStructuralFeature().isUnique() && list.contains(object)) {
        return;
    }
    IUndoableOperation op = new FeatureTransactionAddOperation<T>(label, list, object);
    IUndoContext context = TransactionUtils.getUndoContext(list);
    if (context != null) {
        op.addContext(context);
        try {
            IOperationHistory history = OperationHistoryFactory.getOperationHistory();
            history.execute(op, null, null);
        } catch (Exception e) {
            LogUtil.error("execute", e);
        }
    }
}
项目:OpenSPIFe    文件:FeatureTransactionRemoveAllOperation.java   
public static <T> void execute(String label, EcoreEList<T> list, List<T> objects) {
    boolean containsOne = false;
    for (T item : list) {
        if (objects.contains(item)) {
            containsOne = true;
            break;
        }
    }
    if (!containsOne) {
        return;
    }
    IUndoableOperation op = new FeatureTransactionRemoveAllOperation<T>(label, list, objects);
    IUndoContext context = TransactionUtils.getUndoContext(list);
    if (context != null) {
        op.addContext(context);
        try {
            IOperationHistory history = OperationHistoryFactory.getOperationHistory();
            history.execute(op, null, null);
        } catch (Exception e) {
            LogUtil.error("execute", e);
        }
    }
}
项目:OpenSPIFe    文件:FeatureTransactionAddAllOperation.java   
public static <T> void execute(String label, EcoreEList<T> list, List<T> objects) {
    if (list.getEStructuralFeature().isUnique() && list.containsAll(objects)) {
        return;
    }
    IUndoableOperation op = new FeatureTransactionAddAllOperation<T>(label, list, objects);
    IUndoContext context = TransactionUtils.getUndoContext(list);
    if (context != null) {
        op.addContext(context);
        try {
            IOperationHistory history = OperationHistoryFactory.getOperationHistory();
            history.execute(op, null, null);
        } catch (Exception e) {
            LogUtil.error("execute", e);
        }
    }
}
项目:OpenSPIFe    文件:FeatureTransactionChangeOperation.java   
public static void execute(EObject object, EStructuralFeature feature, Object newValue) {
    Object oldValue = object.eGet(feature);
    if (CommonUtils.equals(oldValue, newValue)) {
        return;
    }
    String featureName = EMFUtils.getDisplayName(object, feature);
    String label = "Edit " + featureName;
    IUndoableOperation op = new FeatureTransactionChangeOperation(label, object, feature, oldValue, newValue);
    op = EMFUtils.addContributorOperations(op, object, feature, oldValue, newValue);
    IUndoContext context = TransactionUtils.getUndoContext(object);
    if (context != null) {
        op.addContext(context);
        try {
            IOperationHistory history = OperationHistoryFactory.getOperationHistory();
            history.execute(op, null, null);
        } catch (Exception e) {
            LogUtil.error("execute", e);
        }
    }
}
项目:OpenSPIFe    文件:FeatureTransactionRemoveOperation.java   
public static <T> void execute(String label, EcoreEList<T> list, T object) {
    if (!list.contains(object)) {
        return;
    }
    IUndoableOperation op = new FeatureTransactionRemoveOperation<T>(label, list, object);
    IUndoContext context = TransactionUtils.getUndoContext(list);
    if (context != null) {
        op.addContext(context);
        try {
            IOperationHistory history = OperationHistoryFactory.getOperationHistory();
            history.execute(op, null, null);
        } catch (Exception e) {
            LogUtil.error("execute", e);
        }
    }
}
项目:OpenSPIFe    文件:FixViolationsOperation.java   
private void doAddOperation(PlanEditorModel model, final EPlanElement parent, final List<EActivity> activities) {
    IStructureModifier modifier = PlanStructureModifier.INSTANCE;
    PlanTransferable transferable = new PlanTransferable();
    transferable.setPlanElements(activities);
    IStructureLocation location = modifier.getInsertionLocation(transferable, new StructuredSelection(parent), InsertionSemantics.ON);
    AddOperation operation = new PlanAddOperation(transferable, modifier, location);
    //IUndoContext undoContext = model.getUndoContext();
    //operation.addContext(undoContext);
    try {
        IOperationHistory history = OperationHistoryFactory.getOperationHistory();
        @SuppressWarnings("unused")
        IStatus status = history.execute(operation, null, null);
    } catch (Exception e) {
        trace.error("FixViolationsOperation.doAddOperation:operation", e);
    }
}
项目:OpenSPIFe    文件:DefaultOperationHistory.java   
@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);
}
项目:OpenSPIFe    文件:DefaultOperationHistory.java   
@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;
}
项目:OpenSPIFe    文件:DefaultOperationHistory.java   
@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);
}
项目:OpenSPIFe    文件:DefaultOperationHistory.java   
@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;
}
项目:OpenSPIFe    文件:TestTemporalBoundColumn.java   
public void assertDeleteConstraint(PeriodicTemporalConstraint constraint, Timepoint timepoint) {
    TemporalBoundColumn column = new TemporalBoundColumn(TEST_PROVIDER, timepoint);
    EActivity a = constructBoundedActivity(constraint);
    ConstraintsMember originalFacet = column.getFacet(a);
    String originalText = column.getText(originalFacet);
    column.modify(originalFacet, "", undoContext);

    ConstraintsMember constraintsMember = a.getMember(ConstraintsMember.class, true);
    List<PeriodicTemporalConstraint> bounds = constraintsMember.getPeriodicTemporalConstraints();
    assertEquals("Number mismatch in bounds count after editing", 0, bounds.size());
    ConstraintsMember changedFacet = column.getFacet(a);
    assertEquals("Column text not equal", column.getText(changedFacet), "");

    try {
        IOperationHistory history = OperationHistoryFactory.getOperationHistory();
        history.undo(undoContext, null, null);
    } catch (Exception e) {
        fail(e.getMessage());
    }

    ConstraintsMember finalFacet = column.getFacet(a);
    assertEquals("Error in undo operation", originalText, column.getText(finalFacet));
}
项目:tmxeditor8    文件:AddTuHandler.java   
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    TmxEditorViewer viewer = TmxEditorViewer.getInstance();
    if(viewer == null){
        return null;
    }
    TmxEditor editor = viewer.getTmxEditor();
    if(editor == null){
        return null;
    }
    String srcLang = editor.getSrcLang();
    String tgtLang = editor.getTgtLang();
    TmxTU tu = TmxEditorUtils.createTmxTu(srcLang, tgtLang);
    editor.addTu(tu);
    IOperationHistory histor = OperationHistoryFactory.getOperationHistory();
    histor.dispose(PlatformUI.getWorkbench().getOperationSupport().getUndoContext(), true, true, true);
    return null;
}
项目:tmxeditor8    文件:DeleteTuHandler.java   
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    TmxEditorViewer viewer = TmxEditorViewer.getInstance();
    if (viewer == null) {
        return null;
    }
    TmxEditor editor = viewer.getTmxEditor();
    if (editor == null) {
        return null;
    }
    if (editor.getTmxDataAccess().getDisplayTuCount() == 0
            || editor.getTmxEditorImpWithNattable().getSelectedRows().length == 0) {
        OpenMessageUtils.openMessage(IStatus.INFO, Messages.getString("tmxeditor.deleteTuHandler.noSelectedMsg"));
        return null;
    }
    boolean confirm = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event),
            Messages.getString("tmxeditor.deleteTuHandler.warn.msg"),
            Messages.getString("tmxeditor.deleteTuHandler.warn.desc"));
    if (!confirm) {
        return null;
    }
    editor.deleteSelectedTu();
    IOperationHistory histor = OperationHistoryFactory.getOperationHistory();
    histor.dispose(PlatformUI.getWorkbench().getOperationSupport().getUndoContext(), true, true, true);
    return null;
}
项目:tmxeditor8    文件:TmxEditorViewer.java   
/**
 * 关闭TmxEditor,同时关闭AbstractDataAccess
 **/
public boolean closeTmx() {
    if (tmxEditor == null) {
        return true;
    }
    if (!tmxEditor.closeTmxEditor()) {
        return false;
    }
    tmxEditor = null;
    Control[] childs = container.getChildren();
    for (Control c : childs) {
        if (c != null && !c.isDisposed()) {
            c.dispose();
        }
    }
    fireCloseEvent();
    IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
    operationHistory.dispose(getSite().getWorkbenchWindow().getWorkbench().getOperationSupport().getUndoContext(),
            true, true, true);
    setFocus();
    String title = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getText();
    String[] s = title.split("-");
    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().setText(s[0]);
    return true;
}
项目:ermasterr    文件:TestEditor.java   
/**
 * The <code>AbstractTextEditor</code> implementation of this
 * <code>IWorkbenchPart</code> method may be extended by subclasses.
 * Subclasses must call <code>super.dispose()</code>.
 * <p>
 * Note that many methods may return <code>null</code> after the editor is
 * disposed.
 * </p>
 */
@Override
public void dispose() {

    if (fTitleImage != null) {
        fTitleImage.dispose();
        fTitleImage = null;
    }

    disposeDocumentProvider();

    if (fSourceViewer != null) {
        fSourceViewer = null;
    }

    if (fConfiguration != null)
        fConfiguration = null;

    final IOperationHistory history = OperationHistoryFactory.getOperationHistory();
    if (history != null) {
        if (fNonLocalOperationApprover != null)
            history.removeOperationApprover(fNonLocalOperationApprover);
        if (fLinearUndoViolationApprover != null)
            history.removeOperationApprover(fLinearUndoViolationApprover);
    }
    fNonLocalOperationApprover = null;
    fLinearUndoViolationApprover = null;

    super.dispose();
}
项目:ermaster-k    文件:TestEditor.java   
/**
 * The <code>AbstractTextEditor</code> implementation of this
 * <code>IWorkbenchPart</code> method may be extended by subclasses.
 * Subclasses must call <code>super.dispose()</code>.
 * <p>
 * Note that many methods may return <code>null</code> after the editor is
 * disposed.
 * </p>
 */
@Override
public void dispose() {

    if (fTitleImage != null) {
        fTitleImage.dispose();
        fTitleImage = null;
    }

    disposeDocumentProvider();

    if (fSourceViewer != null) {
        fSourceViewer = null;
    }

    if (fConfiguration != null)
        fConfiguration = null;

    IOperationHistory history = OperationHistoryFactory
            .getOperationHistory();
    if (history != null) {
        if (fNonLocalOperationApprover != null)
            history.removeOperationApprover(fNonLocalOperationApprover);
        if (fLinearUndoViolationApprover != null)
            history.removeOperationApprover(fLinearUndoViolationApprover);
    }
    fNonLocalOperationApprover = null;
    fLinearUndoViolationApprover = null;

    super.dispose();
}
项目:bts    文件:LinkedEditingUndoSupport.java   
public void startRecording(XtextEditor editor) {
    this.editor = editor;
    ISourceViewer viewer = editor.getInternalSourceViewer();
    if (viewer instanceof ITextViewerExtension6) {
        IUndoManager undoManager = ((ITextViewerExtension6) viewer).getUndoManager();
        if (undoManager instanceof IUndoManagerExtension) {
            IUndoManagerExtension undoManagerExtension = (IUndoManagerExtension) undoManager;
            IUndoContext undoContext = undoManagerExtension.getUndoContext();
            IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
            startingUndoOperation = operationHistory.getUndoOperation(undoContext);
        }
    }
}
项目:statecharts    文件:CreateSubdiagramCommand.java   
protected void executeCommand(AbstractTransactionalCommand operation) {
    IOperationHistory history = OperationHistoryFactory.getOperationHistory();
    try {
        history.execute(operation, new NullProgressMonitor(), null);
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
}
项目:statecharts    文件:AbstractSemanticModification.java   
protected void executeCommand(IUndoableOperation command, Resource resource) {
    IOperationHistory history = OperationHistoryFactory.getOperationHistory();
    try {
        history.execute(command, new NullProgressMonitor(), null);
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
}
项目:che    文件:UndoManager2.java   
public void aboutToPerformChange(Change change) {
  IUndoableOperation operation = new UndoableOperation2ChangeAdapter(change);
  operation.addContext(RefactoringCorePlugin.getUndoContext());
  fActiveOperation = new TriggeredOperations(operation, fOperationHistory);
  fActiveOperation.addContext(RefactoringCorePlugin.getUndoContext());
  fOperationHistory.openOperation(fActiveOperation, IOperationHistory.EXECUTE);
  fIsOpen = true;
}
项目:che    文件:RefactoringCorePlugin.java   
public static IUndoContext getUndoContext() {
  if (fRefactoringUndoContext == null) {
    fRefactoringUndoContext = new RefactoringUndoContext();
    IUndoContext workspaceContext =
        (IUndoContext) ResourcesPlugin.getWorkspace().getAdapter(IUndoContext.class);
    if (workspaceContext instanceof ObjectUndoContext) {
      ((ObjectUndoContext) workspaceContext).addMatch(fRefactoringUndoContext);
    }
    IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
    operationHistory.setLimit(fRefactoringUndoContext, 5);
  }
  return fRefactoringUndoContext;
}
项目:OpenSPIFe    文件:UndoableOperationTestUtil.java   
/**
 * Undo the given operation, which should be the next operation in the undo context.
 * Tests that the operation can be undone, that it is the next in the undo context,
 * that the undo result isOK() and that no ExecutionException is thrown.
 * @param operation
 * @param undoContext
 * @param undoingRedo supply true if undoing a redo, to get a different error string during failure
 */
public static final void undoOperation(IUndoableOperation operation, IUndoContext undoContext, boolean undoingRedo) {
    TestCase.assertTrue(operation.canUndo());
    String string = "failed to undo" + (undoingRedo ? " the redo" : "");
    try {
        IOperationHistory history = OperationHistoryFactory.getOperationHistory();
        TestCase.assertSame("the supplied operation should be next on the undo stack", operation, history.getUndoOperation(undoContext));
        IStatus result = history.undo(undoContext, null, null);
        TestCase.assertTrue(string + ": " + operation.getLabel(), result.isOK());
    } catch (ExecutionException e) {
        TestCase.fail(string);
    }
    TestCase.assertFalse(operation.canUndo());
    TestCase.assertTrue(operation.canRedo());
}
项目:OpenSPIFe    文件:UndoableOperationTestUtil.java   
/**
 * Redo the given operation, which should be the next operation to redo in the undo context.
 * Tests that the operation can be redone, that it is the next to redo in the undo context,
 * that the redo result isOK() and that no ExecutionException is thrown.
 * @param operation
 * @param undoContext
 */
public static final void redoOperation(IUndoableOperation operation, IUndoContext undoContext) {
    TestCase.assertTrue(operation.canRedo());
    String string = "failed to redo";
    try {
        IOperationHistory history = OperationHistoryFactory.getOperationHistory();
        TestCase.assertSame("the supplied operation should be next on the redo stack", operation, history.getRedoOperation(undoContext));
        IStatus result = history.redo(undoContext, null, null);
        TestCase.assertTrue(string + ": " + operation.getLabel(), result.isOK());
    } catch (ExecutionException e) {
        TestCase.fail(string);
    }
    TestCase.assertFalse(operation.canRedo());
    TestCase.assertTrue(operation.canUndo());
}
项目:OpenSPIFe    文件:TestTemporalTransferableExtension.java   
private void execute(IUndoableOperation operation, EPlan plan) {
    operation.addContext(TransactionUtils.getUndoContext(plan));
    // perform the operation
    try {
        IOperationHistory history = OperationHistoryFactory.getOperationHistory();
        history.execute(operation, null, null);
    } catch (ExecutionException ee) {
        fail("failed to execute");
    }
}
项目:OpenSPIFe    文件:TestDirectPlanModifier.java   
private static void modifyStartTime(IPlanModifier modifier, EPlanElement element, Date newStart) throws ExecutionException {
    EPlan plan = EPlanUtils.getPlan(element);
    TemporalExtentsCache cache = new TemporalExtentsCache(plan);
    Map<EPlanElement, TemporalExtent> changedTimes = modifier.moveToStart(element, newStart, cache);
    SetExtentsOperation operation = new SetExtentsOperation("set start times", plan, changedTimes, cache);
    operation.addContext(TransactionUtils.getUndoContext(plan));
    IOperationHistory history = OperationHistoryFactory.getOperationHistory();
    history.execute(operation, null, null);
}
项目:OpenSPIFe    文件:OneOfEachAction.java   
private void createChainOperation(PlanEditorModel model, final List<EPlanChild> links) {
    IUndoContext undoContext = model.getUndoContext();
    PlanStructureModifier modifier = PlanStructureModifier.INSTANCE;
    ChainOperation operation = new ChainOperation(modifier, links, false);
    operation.addContext(undoContext);
    try {
        IOperationHistory history = OperationHistoryFactory.getOperationHistory();
        IStatus status = history.execute(operation, null, null);
        if (status instanceof JobOperationStatus) {
            ((JobOperationStatus) status).getJob().join();
        }
    } catch (Exception e) {
        trace.error("OneOfEachAction.createChainOperation:operation", e);
    }
}