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

项目:bts    文件:EmbeddedEditorFactory.java   
protected OperationHistoryListener installUndoRedoSupport(SourceViewer viewer, IDocument document, final EmbeddedEditorActions actions) {
            IDocumentUndoManager undoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(document);
            final IUndoContext context = undoManager.getUndoContext();

            // XXX cp uncommented

//          IOperationHistory operationHistory = PlatformUI.getWorkbench().getOperationSupport().getOperationHistory();
            OperationHistoryListener operationHistoryListener = new OperationHistoryListener(context, new IUpdate() {
                public void update() {
                    actions.updateAction(ITextEditorActionConstants.REDO);
                    actions.updateAction(ITextEditorActionConstants.UNDO);
                }
            });
            viewer.addTextListener(new ITextListener() {

                public void textChanged(TextEvent event) {
                    actions.updateAction(ITextEditorActionConstants.REDO);
                    actions.updateAction(ITextEditorActionConstants.UNDO);

                }
            });
//          
//          operationHistory.addOperationHistoryListener(operationHistoryListener);
            return operationHistoryListener;
        }
项目: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);
    }
}
项目:che    文件:RefactoringCorePlugin.java   
public void stop(BundleContext context) throws Exception {
  if (fRefactoringUndoContext != null) {
    IUndoContext workspaceContext =
        (IUndoContext) ResourcesPlugin.getWorkspace().getAdapter(IUndoContext.class);
    if (workspaceContext instanceof ObjectUndoContext) {
      ((ObjectUndoContext) workspaceContext).removeMatch(fRefactoringUndoContext);
    }
  }
  if (fgUndoManager != null) fgUndoManager.shutdown();
  final RefactoringHistoryService service = RefactoringHistoryService.getInstance();
  service.disconnect();
  if (fRefactoringHistoryListener != null)
    service.removeHistoryListener(fRefactoringHistoryListener);
  RefactoringContributionManager.getInstance().disconnect();
  super.stop(context);
}
项目: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    文件:ScheduledOperation.java   
public static void toggleScheduledness(EPlanElement element) {
    IPlanEditApprover registry = PlanEditApproverRegistry.getInstance();
    if (!registry.canModify(element)) {
        return;
    }
    TriState oldValue = SpifePlanUtils.getScheduled(element);
    boolean value = (oldValue == TriState.FALSE);
    ScheduledOperation op = new ScheduledOperation(element, value);
    IUndoContext undoContext = TransactionUtils.getUndoContext(element);
    op.addContext(undoContext);
    try {
        OperationHistoryFactory.getOperationHistory().execute(op, null, null);
    } catch (ExecutionException e) {
        // should never occur
        LogUtil.error(e);
    }
}
项目:OpenSPIFe    文件:StartTimeParameterColumn.java   
@Override
public void modify(ParameterFacet<Date> parameter, Object date, IUndoContext undoContext) {
    Date newStart = (Date)date;
    EPlanElement planElement = parameter.getElement();
    EPlan plan = EPlanUtils.getPlan(planElement);
    TemporalMember temporal = planElement.getMember(TemporalMember.class);
    Date startTime = temporal.getStartTime();
    IPlanModifier modifier = PlanModifierMember.get(plan).getModifier();
    if (modifier == null) {
        ParameterFacet<Date> facet = new ParameterFacet<Date>(parameter.getObject(), START_TIME_FEATURE, startTime);
        super.modify(facet, newStart, undoContext);
        return;
    }
    TemporalExtentsCache cache = new TemporalExtentsCache(plan);
    Map<EPlanElement, TemporalExtent> changedTimes = modifier.moveToStart(planElement, newStart, cache);
    IUndoableOperation operation = new SetExtentsOperation("set start times", plan, changedTimes, cache);
    operation = EMFUtils.addContributorOperations(operation, temporal, START_TIME_FEATURE, startTime, newStart);
    CommonUtils.execute(operation, undoContext);
}
项目:OpenSPIFe    文件:TemporalMemberItemProvider.java   
@Override
public void doExecute() {
    TemporalMember member = (TemporalMember)getOwner();
    if ((member.getStartTime() == null) && (member.getEndTime() == null)) {
        operation = new FeatureTransactionChangeOperation("update duration", member, getFeature(), value);
    } else {
        operation = TemporalModifier.getInstance().set(member, getFeature(), value);
    }
    IUndoContext undoContext = TransactionUtils.getUndoContext(member);
    if (undoContext != null) {
        operation.addContext(undoContext);
    }
    try {
        operation.execute(MONITOR, null);
    } catch (ExecutionException e) {
        LogUtil.error(e);
    }
}
项目: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    文件:EMFTreeTableColumn.java   
@Override
public boolean editOnActivate(T facet, IUndoContext undoContext, TreeItem item, int index) {
    Object feature = itemPropertyDescriptor.getFeature(facet);
    if (feature instanceof EAttribute) {
        EDataType eDataType = ((EAttribute)feature).getEAttributeType();
        if (eDataType != null
                && (eDataType.getInstanceClass() == Boolean.class
                    || eDataType.getInstanceClass() == Boolean.TYPE)) {
            Boolean value = (Boolean) getValue(facet);
            boolean newValue = (value == null ? true : !value);
            modify(facet, newValue, undoContext);
            return true;
        }
    }
    return false;
}
项目: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    文件:ConstraintDialog.java   
/**
 * Create a constraint dialog that will create a new constraint between the two plan elements.
 * The dialog is set up so that it is possible to constrain A to be before, but not vice versa. 
 * 
 * @param parent
 * @param undoContext
 * @param elementA
 * @param elementB
 */
public ConstraintDialog(Shell parent, IUndoContext undoContext, EPlanElement elementA, EPlanElement elementB) {
    super(parent);
    setShellStyle(SWT.DIALOG_TRIM | getDefaultOrientation());
    setBlockOnOpen(false);
    if (undoContext == null) {
        throw new NullPointerException("null undo context");
    }
    if (elementA == null) {
        throw new NullPointerException("null elementA");
    }
    if (elementB == null) {
        throw new NullPointerException("null elementB");
    }
    this.undoContext = undoContext;
    this.elementA = elementA;
    this.elementB = elementB;
    this.oldConstraint = null;
}
项目:OpenSPIFe    文件:ConstraintDialog.java   
/**
 * Create a constraint dialog that will edit an existing constraint. (remove it and add a new one)
 * The constraint should be ordered as if it were constructed by this dialog, or the results
 * may be odd.  For example, if the constraint is "the start of A must occur after the end of B",
 * then this constraint will probably be displayed as a weird-looking 'between' option in dialog.  
 * 
 * @param parent
 * @param undoContext
 * @param oldConstraint
 */
public ConstraintDialog(Shell parent, IUndoContext undoContext, BinaryTemporalConstraint oldConstraint) {
    super(parent);
    setShellStyle(SWT.DIALOG_TRIM | getDefaultOrientation());
    setBlockOnOpen(false);
    if (undoContext == null) {
        throw new NullPointerException("null undo context");
    }
    if (oldConstraint.getPointA().getElement() == null) {
        throw new NullPointerException("null elementA on oldConstraint");
    }
    if (oldConstraint.getPointB().getElement() == null) {
        throw new NullPointerException("null elementB on oldConstraint");
    }
    this.undoContext = undoContext;
    this.elementA = oldConstraint.getPointA().getElement();
    this.elementB = oldConstraint.getPointB().getElement();
    this.oldConstraint = oldConstraint;
}
项目:OpenSPIFe    文件:DrudgerySavingHandler.java   
@Override
public Object execute(ExecutionEvent event) {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    EList<EPlanElement> elements = getSelectedTemporalElements(selection);
    ECollections.sort(elements, TemporalChainUtils.CHAIN_ORDER);
    EPlan plan = EPlanUtils.getPlan(elements.get(0));
    Map<EPlanElement, Date> startTimes = getChangedTimes(elements);
    // create moves for children            
    IPlanModifier modifier = PlanModifierMember.get(plan).getModifier();
    TemporalExtentsCache cache = new TemporalExtentsCache(plan);
    Map<EPlanElement, TemporalExtent> changedTimes = new LinkedHashMap<EPlanElement, TemporalExtent>();
    for (EPlanElement element: startTimes.keySet()) {
        Date start = startTimes.get(element);
        Map<EPlanElement, TemporalExtent> extents = modifier.moveToStart(element, start, cache);
        changedTimes.putAll(extents);
        if (!extents.containsKey(element)) {
            TemporalMember member = element.getMember(TemporalMember.class);
            TemporalExtent extent = member.getExtent();
            changedTimes.put(element, extent.moveToStart(start));
        }
    }
    IUndoableOperation op = new SetExtentsOperation(actionVerb, plan, changedTimes, cache);
    IUndoContext undoContext = TransactionUtils.getUndoContext(plan);
    CommonUtils.execute(op, undoContext);
    return null;
}
项目:OpenSPIFe    文件:TimeOfDayConstraintHandler.java   
private TemporalBoundEditOperation createPeriodicTemporalConstraintOperation(EPlanElement planElement, Amount<Duration> offset, IUndoContext undoContext) {
    ConstraintsMember facet = planElement.getMember(ConstraintsMember.class, true);
    Set<PeriodicTemporalConstraint> oldConstraints = getRelevantConstraints(facet);
    PeriodicTemporalConstraint newConstraint = null;
    for (PeriodicTemporalConstraint oldConstraint : oldConstraints) {
        Amount<Duration> time = getRelevantPartOfConstraint(oldConstraint);
        if (time.compareTo(offset) == 0) {
            return null; // same as an existing pin
        }
    }           
    newConstraint = createPeriodicTemporalConstraint(planElement, offset);
    TemporalBoundEditOperation operation = new TemporalBoundEditOperation(getEarliestOrLatestName(), planElement, oldConstraints, newConstraint);
    if (undoContext != null) {
        operation.addContext(undoContext);
    }
    operation.addContext(undoContext);
    return operation;
}
项目: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    文件:DefaultOperationHistory.java   
@Override
public void setLimit(IUndoContext context, int limit) {
    Assert.isTrue(limit >= 0);
    /*
     * The limit checking methods interpret a null context as a global limit
     * to be enforced. We do not wish to support a global limit in this
     * implementation, so we throw an exception for a null context. The rest
     * of the implementation can handle a null context, so subclasses can
     * override this if a global limit is desired.
     */
    Assert.isNotNull(context);
    limits.put(context, new Integer(limit));
    synchronized (undoRedoHistoryLock) {
        forceUndoLimit(context, limit);
        forceRedoLimit(context, limit);
    }

}
项目: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    文件:BooleanAction.java   
@Override
public void runWithEvent(Event event) {
    MenuItem item = (MenuItem) event.widget;
    boolean selected = item.getSelection();
    String label = "Edit " + getDisplayName();
    CompositeOperation op = new CompositeOperation(label);
    for (EObject object : getObjects()) {
        if (object instanceof EPlanElement) {
            IItemPropertySource source = EMFUtils.adapt(object, IItemPropertySource.class);
            if (source != null) {
                IItemPropertyDescriptor pd = source.getPropertyDescriptor(object, getFeature());
                op.add(getOperation(object, pd, selected, !selected));
            }
        }
    }
    IUndoContext undoContext = getUndoContext();
    CommonUtils.execute(op, undoContext);
}
项目:tlaplus    文件:TLAEditor.java   
private IUndoContext getUndoContext() {
    if (getSourceViewer() instanceof ITextViewerExtension6) {
        IUndoManager undoManager = ((ITextViewerExtension6) getSourceViewer()).getUndoManager();
        if (undoManager instanceof IUndoManagerExtension)
            return ((IUndoManagerExtension) undoManager).getUndoContext();
    }
    return null;
}
项目: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);
        }
    }
}
项目:VariantSync    文件:ConstraintDialog.java   
/**
 * closes the shell and adds new constraint to the feature model if possible
 * 
 * @param featureModel
 * @param constraint
 */
private void addConstraint() {
    final NodeReader nodeReader = new NodeReader();
    final String input = constraintText.getText().trim();
    final FeatureModel featureModel = featureController.getFeatureModel();
    final Node propNode = nodeReader.stringToNode(input,
            featureModel.getFeatureNames());

    AbstractOperation op = null;
    if (constraint != null
            && featureModel.getConstraints().contains(constraint)) {
        int index = 0;
        for (Constraint c : featureModel.getConstraints()) {
            if (c == constraint) {
                op = new ConstraintEditOperation(propNode, featureModel,
                        index);
                break;
            }
            index++;
        }
    }
    if (op == null) {
        op = new ConstraintCreateOperation(propNode, featureModel);
    }
    op.addContext((IUndoContext) featureModel.getUndoContext());

    featureController.addFeatureExpression(input);
}
项目:che    文件:Workspace.java   
@Override
public Object getAdapter(Class aClass) {
  if (aClass == IUndoContext.class) {
    return undoContext;
  }
  throw new UnsupportedOperationException();
}
项目:che    文件:RefactoringUndoContext.java   
public boolean matches(IUndoContext context) {
  if (this == context) return true;
  IUndoContext workspaceContext =
      (IUndoContext) ResourcesPlugin.getWorkspace().getAdapter(IUndoContext.class);
  if (workspaceContext == null) return false;
  return workspaceContext.matches(context);
}
项目: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;
}
项目:che    文件:UndoableOperation2ChangeAdapter.java   
public boolean hasContext(IUndoContext context) {
  if (context == null) return false;
  for (int i = 0; i < fContexts.size(); i++) {
    IUndoContext otherContext = (IUndoContext) fContexts.get(i);
    // have to check both ways because one context may be more general in
    // its matching rules than another.
    if (context.matches(otherContext) || otherContext.matches(context)) return true;
  }
  return false;
}
项目:OpenSPIFe    文件:UndoableOperationTestUtil.java   
/**
 * @param plan
 * @param operation
 */
public static void testUndoableOperation(EPlan plan, IUndoableOperation operation, Runnable assertPostconditions) {
    String initialPlanState = EMFUtils.convertToXML(plan);
    IUndoContext undoContext = TransactionUtils.getUndoContext(plan);

    // perform the operation
    executeOperation(operation, undoContext);

    assertPostconditions.run();
    String operationExecutedState = EMFUtils.convertToXML(plan);
    TestCase.assertFalse("Should be different:\nState 1:\n" + initialPlanState 
            + "State 2:\n" + operationExecutedState, initialPlanState.equals(operationExecutedState));

    // undo the operation
    undoOperation(operation, undoContext, false);

    String operationUndoneState = EMFUtils.convertToXML(plan);
    TestCase.assertEquals("undo didn't", initialPlanState, operationUndoneState);

    // redo the operation
    redoOperation(operation, undoContext);

    assertPostconditions.run();
    String operationRedoneState = EMFUtils.convertToXML(plan);
    TestCase.assertEquals("redo didn't", operationExecutedState, operationRedoneState);

    // undo the redo
    undoOperation(operation, undoContext, true);

    String redoUndoneState = EMFUtils.convertToXML(plan);
    TestCase.assertEquals("undo of redo didn't", initialPlanState, redoUndoneState);
}
项目: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    文件:DefaultOperationHistory.java   
/**
 * Check the undo limit before adding an operation. Return a boolean
 * indicating whether the undo should proceed.
 */
private boolean checkUndoLimit(IUndoableOperation operation) {
    IUndoContext[] contexts = operation.getContexts();
    for (int i = 0; i < contexts.length; i++) {
        int limit = getLimit(contexts[i]);
        if (limit > 0) {
            forceUndoLimit(contexts[i], limit - 1);
        } else {
            // this context has a 0 limit
            operation.removeContext(contexts[i]);
        }
    }
    return operation.getContexts().length > 0;
}
项目:OpenSPIFe    文件:Suggestion.java   
/**
 * Perform this suggestion
 * 
 * @param undoContext 
 * @param widget 
 * @param site 
 */
public void execute(IUndoContext undoContext, Widget widget, IWorkbenchPartSite site) {
    if (operation instanceof ISuggestionOperation) {
        ISuggestionOperation suggestionOperation = (ISuggestionOperation) operation;
        if (!suggestionOperation.preExecute()) {
            return;
        }
    }
    WidgetUtils.execute(operation, undoContext, widget, site);
}
项目:OpenSPIFe    文件:DefaultOperationHistory.java   
/**
 * Check the redo limit before adding an operation. In theory the redo limit
 * should never be reached, because the redo items are transferred from the
 * undo history, which has the same limit. The redo history is cleared
 * whenever a new operation is added. We check for completeness since
 * implementations may change over time.
 * 
 * Return a boolean indicating whether the redo should proceed.
 */
private boolean checkRedoLimit(IUndoableOperation operation) {
    IUndoContext[] contexts = operation.getContexts();
    for (int i = 0; i < contexts.length; i++) {
        int limit = getLimit(contexts[i]);
        if (limit > 0) {
            forceRedoLimit(contexts[i], limit - 1);
        } else {
            // this context has a 0 limit
            operation.removeContext(contexts[i]);
        }
    }
    return operation.getContexts().length > 0;
}
项目:OpenSPIFe    文件:OperationJob.java   
/**
 * This rule ensures the operation will run exclusively with the undo contexts it uses.
 * 
 * @param operation
 * @return
 */
protected final static ISchedulingRule getSchedulingRule(IUndoableOperation operation) {
    IUndoContext[] contexts = operation.getContexts();
    ISchedulingRule[] rules = new ISchedulingRule[contexts.length];
    for (int i = 0 ; i < contexts.length ; i++) {
        IUndoContext context = contexts[i];
        rules[i] = new UndoContextRule(context);
    }
    ISchedulingRule rule = MultiRule.combine(rules);
    return rule;
}
项目:translationstudio8    文件:UpdateDataOperation.java   
public UpdateDataOperation(NatTable table, DataLayer dataLayer, UpdateDataAndAutoResizeCommand command) {
        super("Typing");
        IUndoContext undoContext = (IUndoContext) table.getData(IUndoContext.class.getName());
        addContext(undoContext);
        Object currentValue = dataLayer.getDataProvider().getDataValue(command.getColumnPosition(), command.getRowPosition());
//      Object currentValue = dataLayer.getDataValueByPosition(command2.getColumnPosition(), command2.getRowPosition());
        oldValue = currentValue == null ? new UpdateDataBean() : new UpdateDataBean((String) currentValue, null, null);
        this.dataLayer = dataLayer;
        this.command = command;
        this.table = table;
        viewportLayer = LayerUtil.getLayer(table, ViewportLayer.class);
    }
项目:OpenSPIFe    文件:TransactionUtils.java   
public static IUndoContext getUndoContext(Object object) {
    EditingDomain d = EMFUtils.getAnyDomain(object);
    if (d instanceof FixedTransactionEditingDomain) {
        FixedTransactionEditingDomain domain = (FixedTransactionEditingDomain) d;
        return domain.getUndoContext();
    }
    if (object instanceof EObject) {
        return EMFUtils.getUndoContext((EObject) object, d);
    }
    return null;
}
项目:tmxeditor8    文件:CellEditorGlobalActionHanlder.java   
/**
 * Update the state.
 */
public void updateEnabledState() {
    IOperationHistory opHisotry = OperationHistoryFactory.getOperationHistory();
    IUndoContext context = PlatformUI.getWorkbench().getOperationSupport().getUndoContext();
    if (opHisotry.canUndo(context)) {
        setEnabled(true);
        return;
    }
    if (viewer != null && !viewer.getTextWidget().isDisposed()) {
        setEnabled(viewer.canDoOperation(ITextOperationTarget.UNDO));
        return;
    }
    setEnabled(false);
}
项目:OpenSPIFe    文件:CommonUtils.java   
/**
 * Execute the operation in the undo context, in a job.
 * 
 * If the operation can not be executed, it will be disposed.
 * 
 * @param operation
 * @param undoContext
 */
public static void execute(final IUndoableOperation operation, IUndoContext undoContext) {
    IOperationHistory history = OperationHistoryFactory.getOperationHistory();
    if (undoContext != null) {
        operation.addContext(undoContext);
    }
    try {
        history.execute(operation, null, null);
    } catch (ExecutionException e) {
        // should never occur
        LogUtil.error(e);
    }
}
项目:tmxeditor8    文件:UpdateDataOperation.java   
public UpdateDataOperation(NatTable table, DataLayer dataLayer, UpdateDataCommand command) {
    super("Typing");
    IUndoContext undoContext = (IUndoContext) table.getData(IUndoContext.class.getName());
    addContext(undoContext);
    Object currentValue = dataLayer.getDataValueByPosition(command.getColumnPosition(), command.getRowPosition());
    oldValue = currentValue == null ? new UpdateDataBean() : new UpdateDataBean((String) currentValue, null, null);
    this.dataLayer = dataLayer;
    this.command = command;
    this.table = table;
    viewportLayer = LayerUtil.getLayer(table, ViewportLayer.class);
}
项目:translationstudio8    文件:LockOperation.java   
/**
 * 
 * @param label
 * @param natTable
 * @param rowIdList
 * @param handler
 * @param lock
 */
public LockOperation(String label, NatTable natTable, List<String> rowIdList, XLFHandler handler,
        boolean lock) {
    super(label);
    IUndoContext context = (IUndoContext) natTable.getData(IUndoContext.class.getName());
    addContext(context);
    this.table = natTable;
    this.rowIdList = rowIdList;
    this.handler = handler;
    this.lock = lock;
}
项目:tmxeditor8    文件:UpdateSegmentsOperation.java   
private UpdateSegmentsOperation(XLIFFEditorImplWithNatTable xliffEditor, XLFHandler handler, List<String> rowIds,
        int column, boolean approved, String matchType, String quality) {
    super("Update Segments");
    this.xliffEditor = xliffEditor;
    this.table = xliffEditor.getTable();
    IUndoContext undoContext = (IUndoContext) table.getData(IUndoContext.class.getName());
    addContext(undoContext); // 绑定上下文
    this.handler = handler;
    this.rowIds = rowIds;
    this.approved = approved;
    segmentCache = handler.getTuNodes(rowIds); // 缓存未修改前的文本段
    this.matchType = matchType;
    this.quality = quality;
}
项目:translationstudio8    文件:XLIFFEditorActionHandler.java   
@Override
public void runWithEvent(Event event) {
    if (viewer != null && !viewer.getTextWidget().isDisposed()) {
        XLIFFEditorImplWithNatTable xliffEditor = XLIFFEditorImplWithNatTable.getCurrent();
        // 先保存在撤销,除非以后取消两种模式,否则不要删除此判断
        if (viewer.canDoOperation(ITextOperationTarget.UNDO)) {
            HsMultiActiveCellEditor.commit(true);
        }
        IOperationHistory history = OperationHistoryFactory.getOperationHistory();
        IUndoContext undoContext = (IUndoContext) xliffEditor.getTable().getData(IUndoContext.class.getName());
        if (history.canUndo(undoContext)) {
            try {
                history.undo(undoContext, null, null);
                undoBean.setCrosseStep(undoBean.getCrosseStep() + 1);
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }
        XLIFFEditorImplWithNatTable.getCurrent().redraw();
        updateActionsEnableState();
        return;
    }
    if (undoAction != null) {
        undoAction.runWithEvent(event);
        return;
    }
}
项目:OpenSPIFe    文件:ProfileDataPointColumnProvider.java   
@Override
public void modify(DataPoint oldDataPoint, Object value, IUndoContext undoContext) {
    DataPoint newDataPoint = JScienceFactory.eINSTANCE.createEDataPoint(oldDataPoint.getDate(), value);
    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);
    }
}