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

项目:che    文件:UndoManager2.java   
public void performUndo(IValidationCheckResultQuery query, IProgressMonitor pm)
    throws CoreException {
  IUndoableOperation undo =
      fOperationHistory.getUndoOperation(RefactoringCorePlugin.getUndoContext());
  UndoableOperation2ChangeAdapter changeOperation = getUnwrappedOperation(undo);
  if (changeOperation == null)
    throw new CoreException(
        new Status(
            IStatus.ERROR,
            RefactoringCorePlugin.getPluginId(),
            IStatus.ERROR,
            RefactoringCoreMessages.UndoManager2_no_change,
            null));
  if (query == null) query = new NullQuery();
  try {
    fOperationHistory.undoOperation(undo, pm, new QueryAdapter(query));
  } catch (ExecutionException e) {
    handleException(e);
  }
}
项目:che    文件:UndoManager2.java   
public void performRedo(IValidationCheckResultQuery query, IProgressMonitor pm)
    throws CoreException {
  IUndoableOperation redo =
      fOperationHistory.getRedoOperation(RefactoringCorePlugin.getUndoContext());
  UndoableOperation2ChangeAdapter changeOperation = getUnwrappedOperation(redo);
  if (changeOperation == null)
    throw new CoreException(
        new Status(
            IStatus.ERROR,
            RefactoringCorePlugin.getPluginId(),
            IStatus.ERROR,
            RefactoringCoreMessages.UndoManager2_no_change,
            null));
  if (query == null) query = new NullQuery();
  try {
    fOperationHistory.redoOperation(redo, pm, new QueryAdapter(query));
  } catch (ExecutionException e) {
    handleException(e);
  }
}
项目:OpenSPIFe    文件:DefaultOperationHistory.java   
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;
}
项目:OpenSPIFe    文件:PlanUtils.java   
public static void executeExpansionOperation(EPlanElement element, boolean expanded) {
    CommonMember member = element.getMember(CommonMember.class);
    String action = (expanded ? "expanded" : "collapsed");
    IUndoableOperation operation = new FeatureTransactionChangeOperation(action + " " + getElementNameForDisplay(element), member, PlanPackage.Literals.COMMON_MEMBER__EXPANDED, expanded);
    try {
        InternalTransaction existingTransaction = null;
        TransactionalEditingDomain te = TransactionUtils.getDomain(element);
        if (te instanceof FixedTransactionEditingDomain) {
            FixedTransactionEditingDomain domain = (FixedTransactionEditingDomain) te;
            existingTransaction = domain.getThreadTransaction();
        };
        if (existingTransaction != null && !existingTransaction.isReadOnly()) {
            LogUtil.warn("There is an existing transaction executing so the expansion operation cannot be executed at this point");
            return;
        }               
        operation.execute(new NullProgressMonitor(), null);
    } catch (ExecutionException e) {
        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    文件:DefaultOperationHistory.java   
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;
}
项目:OpenSPIFe    文件:TemporalViolation.java   
/**
 * Suggest moving the element's timepoint to the suggestedTime,
 * where oldExtent is the old extent of the element, or null if none.
 * 
 * @param element
 * @param timepoint
 * @param suggestedTime
 * @param oldExtent
 * @return
 */
protected Suggestion createMoveSuggestion(EPlanElement element, Timepoint timepoint,
        Date suggestedTime, TemporalExtent oldExtent) {
    String description = "Move the " + TemporalPrinter.getText(ConstraintUtils.createConstraintPoint(element, timepoint))
                       + " to " + DATE_STRINGIFIER.getDisplayString(suggestedTime);
    EPlan plan = EPlanUtils.getPlan(element);
    TemporalExtentsCache temporalExtentsCache = new TemporalExtentsCache(plan);
    IPlanModifier modifier = PlanModifierMember.get(plan).getModifier();
    TemporalExtentsCache cache = new TemporalExtentsCache(plan);
    Map<EPlanElement, TemporalExtent> changedTimes;
    if (timepoint == Timepoint.START) {
        changedTimes = modifier.moveToStart(element, suggestedTime, cache);
    } else {
        changedTimes = modifier.moveToEnd(element, suggestedTime, cache);
    }
    String operationDescription = "move the " + TemporalPrinter.getText(ConstraintUtils.createConstraintPoint(element, timepoint));
    IUndoableOperation operation = new SetExtentsOperation(operationDescription, plan, changedTimes, temporalExtentsCache);
    ImageDescriptor icon = ConstraintsPlugin.getImageDescriptor("icons/move_later.png");
    if ((oldExtent != null) && suggestedTime.before(oldExtent.getTimepointDate(timepoint))) {
        icon = ConstraintsPlugin.getImageDescriptor("icons/move_earlier.png");
    }
    return new Suggestion(icon, description, operation);
}
项目: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    文件:TestChainCuts.java   
private void testCuttingActivities(final ChainTestPlan plan, final EPlanElement[] planElementsToCut) {
    ISelection selection = new StructuredSelection(planElementsToCut);
    IStructureModifier modifier = PLAN_STRUCTURE_MODIFIER;
    ITransferable transferable = modifier.getTransferable(selection);
    IUndoableOperation operation = new PlanClipboardCutOperation(transferable, modifier);
    final Runnable postcondition1 = new RemovingChainActivitiesPostconditionRunnable("cut", plan, planElementsToCut);
    final Runnable postcondition2 = new ClipboardContentsPostconditionRunnable(planElementsToCut, false);
    testUndoableOperation(plan.plan, operation, new Runnable() {
        @Override
        public void run() {
            postcondition1.run();
            postcondition2.run();
        }
    });
    plan.clearHistory();
}
项目: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    文件:PlanDiffViolation.java   
private Suggestion createRemoveConstraintSuggestion() {
    IUndoableOperation operation = null;
    if (constraint instanceof ProfileConstraint) {
        EcoreEList<ProfileConstraint> currentConstraints = (EcoreEList)target.getMember(ProfileMember.class).getConstraints();
        operation = new FeatureTransactionRemoveOperation("Remove Profile Constraint", currentConstraints, constraint);
    } else if (constraint instanceof BinaryTemporalConstraint) {
        operation = new DeleteTemporalRelationOperation((BinaryTemporalConstraint)constraint);
    } else if (constraint instanceof PeriodicTemporalConstraint) {
        operation = new DeleteTemporalBoundOperation((PeriodicTemporalConstraint)constraint);
    } else if (constraint instanceof TemporalChain) {
        operation = new UnchainOperation(((TemporalChain)constraint).getElements());
    }
    if (operation != null) {
        return new Suggestion(UPDATE_ACTIVITY_ICON, "Remove Constraint from Plan", operation);
    }
    return null;
}
项目:OpenSPIFe    文件:Violation.java   
protected Suggestion createToggleWaiveSuggestion(String objectName, IWaivable waivable) {
    String waiverRationale = waivable.getWaiverRationale();
    String description;
    IUndoableOperation operation;
    ImageDescriptor icon;
    if (waiverRationale != null) {
        description = "Unwaive the " + objectName;
        operation = new RemoveWaiverOperation(description, waivable);
        icon = null;
    } else {
        description = "Waive the " + objectName;
        operation = new CreateWaiverOperation(description, waivable);
        icon = WAIVE_ICON;
    }
    return new Suggestion(icon, description, operation);
}
项目:OpenSPIFe    文件:OperationHistoryMonitor.java   
@Override
    public void historyNotification(OperationHistoryEvent event) {

        IUndoableOperation op = event.getOperation();
        String typeString = decodeEventType(event.getEventType());
//      System.out.println("type='"+typeString+"' operation='"+op+"' of type '"+op.getClass().getName()+"' e="+op.canExecute()+" u="+op.canUndo()+" r="+op.canRedo());
//      for(IUndoContext c : op.getContexts()) {
//          System.out.println("\t"+c.getLabel());
//      }

        switch(event.getEventType()) {
            case OperationHistoryEvent.OPERATION_ADDED:
            case OperationHistoryEvent.OPERATION_CHANGED:
            case OperationHistoryEvent.OPERATION_REMOVED:
            case OperationHistoryEvent.ABOUT_TO_EXECUTE:
            case OperationHistoryEvent.ABOUT_TO_REDO:
            case OperationHistoryEvent.ABOUT_TO_UNDO:
                break;
            default:
                EnsembleUsageLogger.logUsage(op.getLabel() + " - " + typeString + "\n" + op.toString());
        }

    }
项目:OpenSPIFe    文件:DeleteProfileMemberAction.java   
@Override
public void run(IAction action) {
    IWorkbench workbench = PlatformUI.getWorkbench();
    PlanEditorModel model = PlanEditorModelRegistry.getCurrent(workbench);
    EPlan plan = null;
    if (model != null) {
        plan = model.getEPlan();
    }
    if (model == null || plan == null) {
        LogUtil.error("Could not retrieve the current plan.");
        return;
    }
    // Delete the selected profiles
    ProfileTreeView profileTreeView = (ProfileTreeView)view;
    PlanProfileTreePage planProfileTreePage = (PlanProfileTreePage) profileTreeView.getCurrentPage();
    if (planProfileTreePage == null) {
        LogUtil.error("Could not retrieve current PlanProfileTreePage.");
        return;
    }
    // SPF-10328 -- Changed the call from removeRows to getSelectedProfiles as .condition files
    // should not be affected until the plan editor is saved in order for undo to work properly
    List<Profile> removedProfileList = planProfileTreePage.getSelectedProfiles();
    // Set the operation for undo/redo functionality
    final IUndoableOperation op = new RemoveProfileOperation(plan, removedProfileList);
    CommonUtils.execute(op, model.getUndoContext());
}
项目: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    文件:PlanDiffViolation.java   
private Suggestion createAddConstraintSuggestion() {
    IUndoableOperation operation = null;
    if (constraint instanceof ProfileConstraint) {
        EcoreEList<ProfileConstraint> currentConstraints = (EcoreEList)target.getMember(ProfileMember.class).getConstraints();
        // Need to make a copy so it doesn't get removed from the template
        ProfileConstraint constraintCopy = (ProfileConstraint) EMFUtils.copy(constraint);
        operation = new FeatureTransactionAddOperation("Add Profile Constraint", currentConstraints, constraintCopy);
    } else if (constraint instanceof BinaryTemporalConstraint) {
        operation = new CreateTemporalRelationOperation((BinaryTemporalConstraint)constraint);
    } else if (constraint instanceof PeriodicTemporalConstraint) {
        operation = new CreateTemporalBoundOperation((PeriodicTemporalConstraint)constraint);
    } else if (constraint instanceof TemporalChain) {
        List<EPlanChild> linked = CommonUtils.castList(EPlanChild.class, ((TemporalChain)constraint).getElements());
        operation = new ChainOperation(PlanStructureModifier.INSTANCE, linked, false);
    }
    if (operation != null) {
        return new Suggestion(UPDATE_ACTIVITY_ICON, "Add Constraint to Plan", operation);
    }
    return null;
}
项目:OpenSPIFe    文件:ChainHandler.java   
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Command command = event.getCommand();
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    Set<EPlanElement> allElements = PlanEditorUtil.emfFromSelection(selection);
    List<EPlanElement> elements = EPlanUtils.getConsolidatedPlanElements(allElements);
    boolean state = getCommandState(command);
    IEditorPart editor = getActiveEditor();
    final IUndoableOperation op;
    if (state) {
        op = new UnchainOperation(elements);
    } else {
        PlanStructureModifier modifier = PlanStructureModifier.INSTANCE;
        List<EPlanChild> children = CommonUtils.castList(EPlanChild.class, elements);
        op = new ChainOperation(modifier, children, true);
    }
    WidgetUtils.execute(op, getUndoContext(), null, editor.getSite());
    setCommandState(command, !state);
    return null;
}
项目:OpenSPIFe    文件:AbstractUndoableOperationAction.java   
@Override
public void historyNotification(OperationHistoryEvent event) {
    int type = event.getEventType();
    if ((type == OperationHistoryEvent.DONE)
        || (type == OperationHistoryEvent.REDONE)
        || (type == OperationHistoryEvent.UNDONE)) {
        IUndoableOperation operation = event.getOperation();
        if ((undoContext == null) || operation.hasContext(undoContext) || operation.getContexts().length == 0) {
            Display display = WidgetUtils.getDisplay();
            display.asyncExec(new Runnable() {
                @Override
                public void run() {
                    updateEnablement();
                }
            });
        }
    }
}
项目:OpenSPIFe    文件:TestCutPasteBetweenPlansOperation.java   
/**
 * @param selectedElements
 * @param destinationPlan
 * @param targetElements
 * @param assertPostconditions
 */
private void cutPasteElements(final EPlanElement[] selectedElements, final EPlan destinationPlan, final EPlanElement[] targetElements, final PasteOperationRunnable assertPostconditions) {
    final IStructuredSelection selection = new StructuredSelection(selectedElements);
    final IStructureModifier sourceModifier = PlanStructureModifier.INSTANCE;
    ITransferable transferable = sourceModifier.getTransferable(selection);
    IUndoableOperation cut = new PlanClipboardCutOperation(transferable, sourceModifier);
    EPlan sourcePlan = EPlanUtils.getPlan(selectedElements[0]);
    testUndoableOperation(sourcePlan, cut, new Runnable() {
        @Override
        public void run() {
            final IStructuredSelection targetSelection = new StructuredSelection(targetElements);
            final IStructureModifier destinationModifier = PlanStructureModifier.INSTANCE;
            final PlanClipboardPasteOperation paste = new PlanClipboardPasteOperation(targetSelection, destinationModifier);
            testUndoableOperation(destinationPlan, paste, 
                new Runnable() {
                    @Override
                    public void run() {
                        assertPostconditions.run(paste);
                    }
                });
        }
    });
}
项目: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    文件:TestDeleteOperation.java   
public void testDeleteActivities() {
    final OperationTestPlanRecord plan = new OperationTestPlanRecord();
    ISelection selection = new StructuredSelection(new EActivity[] { 
            plan.activity1_2, 
            plan.activity2_1, 
            plan.activity3_3
            });
    IStructureModifier modifier = PlanStructureModifier.INSTANCE;
    ITransferable transferable = modifier.getTransferable(selection);
    IUndoableOperation operation = new DeleteOperation(transferable, modifier);
    testUndoableOperation(plan.plan, operation, new Runnable() {
        @Override
        public void run() {
            assertFalse(plan.group1.getChildren().contains(plan.activity1_2));
            assertFalse(plan.group2.getChildren().contains(plan.activity2_1));
            assertFalse(plan.group3.getChildren().contains(plan.activity3_3));
        }
    });
    WrapperUtils.dispose(plan.plan);
}
项目:OpenSPIFe    文件:TestDeleteOperation.java   
public void testDeleteActivityGroups() {
    final OperationTestPlanRecord plan = new OperationTestPlanRecord();
    ISelection selection = new StructuredSelection(new EActivityGroup[] { 
            plan.group1, plan.group3, 
            });
    IStructureModifier modifier = PlanStructureModifier.INSTANCE;
    ITransferable transferable = modifier.getTransferable(selection);
    IUndoableOperation operation = new DeleteOperation(transferable, modifier);
    testUndoableOperation(plan.plan, operation, new Runnable() {
        @Override
        public void run() {
            assertFalse(plan.plan.getChildren().contains(plan.group1));
            assertTrue(plan.plan.getChildren().contains(plan.group2));
            assertFalse(plan.plan.getChildren().contains(plan.group3));
        }
    });
    WrapperUtils.dispose(plan.plan);
}
项目: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    文件:DefaultOperationHistory.java   
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;
}
项目:OpenSPIFe    文件:FlightRuleViolation.java   
private void suggestTogglingWaiverOfRuleForElement(Set<Suggestion> suggestions, EPlanElement element) {
    EcoreEList<String> oldRuleNames = RuleUtils.getWaivedRuleNames(element);
    String name = rule.getName();
    if (!oldRuleNames.contains(name)) {
        String label;
        IUndoableOperation operation;
        String description;
        if (RuleUtils.isWaived(element, rule)) {
            label = "waive " + rule.getPrintName();
            operation = new FeatureTransactionAddOperation<String>(label, oldRuleNames, name);
            description = "Waive " + rule.getPrintName();
        } else {
            label = "unwaive " + rule.getPrintName();
            operation = new FeatureTransactionRemoveOperation<String>(label, oldRuleNames, name);
            description = "Unwaive " + rule.getPrintName();
        }
        if (element instanceof EPlan) {
            description += " for this plan";
        } else {
            description += " for " + element.getName();
        }
        suggestions.add(new Suggestion(description, operation));
    }
}
项目: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    文件: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);
        }
    }
}
项目: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 historyNotification(OperationHistoryEvent event) {
  IUndoableOperation op = event.getOperation();
  if (op instanceof TriggeredOperations) {
    op = ((TriggeredOperations) op).getTriggeringOperation();
  }
  UndoableOperation2ChangeAdapter changeOperation = null;
  if (op instanceof UndoableOperation2ChangeAdapter) {
    changeOperation = (UndoableOperation2ChangeAdapter) op;
  }
  if (changeOperation == null) return;
  Change change = changeOperation.getChange();
  switch (event.getEventType()) {
    case OperationHistoryEvent.ABOUT_TO_EXECUTE:
    case OperationHistoryEvent.ABOUT_TO_UNDO:
    case OperationHistoryEvent.ABOUT_TO_REDO:
      fireAboutToPerformChange(change);
      break;
    case OperationHistoryEvent.DONE:
    case OperationHistoryEvent.UNDONE:
    case OperationHistoryEvent.REDONE:
      fireChangePerformed(change);
      fireUndoStackChanged();
      fireRedoStackChanged();
      break;
    case OperationHistoryEvent.OPERATION_NOT_OK:
      fireChangePerformed(change);
      break;
    case OperationHistoryEvent.OPERATION_ADDED:
      // would be better to have different events for this
      fireUndoStackChanged();
      fireRedoStackChanged();
      break;
    case OperationHistoryEvent.OPERATION_REMOVED:
      // would be better to have different events for this
      fireUndoStackChanged();
      fireRedoStackChanged();
      break;
  }
}
项目: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    文件:UndoManager2.java   
private UndoableOperation2ChangeAdapter getUnwrappedOperation(IUndoableOperation operation) {
  IUndoableOperation result = operation;
  if (result instanceof TriggeredOperations) {
    result = ((TriggeredOperations) result).getTriggeringOperation();
  }
  if (result instanceof UndoableOperation2ChangeAdapter) {
    return (UndoableOperation2ChangeAdapter) result;
  }
  return null;
}
项目:che    文件:RefactoringHistoryService.java   
private boolean checkDescriptor(RefactoringDescriptor descriptor, IUndoableOperation operation) {
  Assert.isNotNull(descriptor);
  try {
    final Map arguments = RefactoringHistoryManager.getArgumentMap(descriptor);
    if (arguments != null) RefactoringHistoryManager.checkArgumentMap(arguments);
  } catch (CoreException exception) {
    final IStatus status = exception.getStatus();
    if (status.getCode() == IRefactoringCoreStatusCodes.REFACTORING_HISTORY_FORMAT_ERROR) {
      final String time =
          DateFormat.getDateTimeInstance().format(new Date(descriptor.getTimeStamp()));
      final String message =
          "The refactoring executed at "
              + time
              + " contributed a refactoring descriptor with invalid format:"; // $NON-NLS-1$//$NON-NLS-2$
      final IStatus comment =
          new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), descriptor.getComment());
      RefactoringCorePlugin.log(
          new MultiStatus(
              RefactoringCorePlugin.getPluginId(), 0, new IStatus[] {comment}, message, null));
    }
    RefactoringCorePlugin.log(exception);

    if (operation instanceof TriggeredOperations) {
      operation = ((TriggeredOperations) operation).getTriggeringOperation();
    }
    if (operation instanceof UndoableOperation2ChangeAdapter) {
      ((UndoableOperation2ChangeAdapter) operation).setChangeDescriptor(null);
    }
    return false;
  }
  return true;
}
项目:che    文件:RefactoringHistoryService.java   
private RefactoringDescriptor getRefactoringDescriptor(IUndoableOperation operation) {
  if (operation instanceof TriggeredOperations) {
    operation = ((TriggeredOperations) operation).getTriggeringOperation();
  }
  if (operation instanceof UndoableOperation2ChangeAdapter) {
    ChangeDescriptor changeDescriptor =
        ((UndoableOperation2ChangeAdapter) operation).getChangeDescriptor();
    if (changeDescriptor instanceof RefactoringChangeDescriptor) {
      return ((RefactoringChangeDescriptor) changeDescriptor).getRefactoringDescriptor();
    }
  }
  return null;
}
项目: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    文件:PlanDiffAdvisorUtils.java   
public static IUndoableOperation getFeatureModificationOperation(ChangedByModifyingParameterOrReference modification) {
    EStructuralFeature feature = modification.getParameter();
    EPlanElement target = modification.getOldCopyOfOwner();
    EObject object = modification.getRelevantPartOf(target);
    Object newValue = modification.getNewValue();
    Object oldValue = modification.getOldValue();
    if (feature instanceof EReference) {
        if (((EReference)feature).isContainment()) {
            // need to copy the contained objects so the old objects don't have their container changed
            if (newValue instanceof EObject) {
                newValue = EMFUtils.copy((EObject)newValue);
            } else if (newValue instanceof Collection<?>) {
                newValue = EcoreUtil.copyAll((Collection<? extends EObject>)newValue);
            }
        }
        if (oldValue instanceof Collection<?>) {
            // need to copy the old list of referenced objects for use by Undo as it is modified by the update
            oldValue = new ArrayList((Collection)oldValue);
        }
    }
    if (feature == TemporalPackage.Literals.TEMPORAL_MEMBER__START_TIME
            || feature == TemporalPackage.Literals.TEMPORAL_MEMBER__DURATION
            || feature == TemporalPackage.Literals.TEMPORAL_MEMBER__END_TIME) {
        TemporalModifier modifier = TemporalModifier.getInstance();
        if (modifier instanceof TemporalModifierImpl) {
            return ((TemporalModifierImpl)modifier).set((TemporalMember)object, feature, newValue, CalculatedVariable.END);
        }
        return modifier.set((TemporalMember)object, feature, newValue);
    }
    return new FeatureTransactionChangeOperation("Update " + feature.getName(), object, feature, oldValue, newValue);
}
项目:OpenSPIFe    文件:JobOperationHistory.java   
@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);
}
项目:OpenSPIFe    文件:TemporalModifierImpl.java   
public IUndoableOperation set(TemporalMember owner, EStructuralFeature feature, Object value, CalculatedVariable calculated) {
    EPlan plan = EPlanUtils.getPlan(owner);
    IPlanModifier modifier = PlanModifierMember.get(plan).getModifier();
    if (modifier != null) {
        TemporalExtentsCache cache = new TemporalExtentsCache(plan);
        EPlanElement element = owner.getPlanElement();
        Map<EPlanElement, TemporalExtent> changedTimes = null;
        if (feature == TemporalPackage.Literals.TEMPORAL_MEMBER__START_TIME) {
            Date startTime = (Date)value;
            if (calculated == CalculatedVariable.DURATION) {
                changedTimes = modifier.setStart(element, startTime, cache);
            } else {
                changedTimes = modifier.moveToStart(element, startTime, cache);
            }
        }
        if (feature == TemporalPackage.Literals.TEMPORAL_MEMBER__END_TIME) {
            Date endTime = (Date)value;
            if (calculated == CalculatedVariable.DURATION) {
                changedTimes = modifier.setEnd(element, endTime, cache);
            } else {
                changedTimes = modifier.moveToEnd(element, endTime, cache);
            }
        }
        if (feature == TemporalPackage.Literals.TEMPORAL_MEMBER__DURATION) {
            Amount<Duration> duration = (Amount<Duration>)value;
            if (calculated == CalculatedVariable.END) {
                changedTimes = modifier.setDuration(element, duration, cache, true);
            } else {
                changedTimes = modifier.setDuration(element, duration, cache, false);
            }
        }
        if (changedTimes != null) {
            return new SetExtentsOperation("set start times", plan, changedTimes, cache);
        }
    }
    return super.set(owner, feature, value);
}
项目: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    文件:TestTemporalModifier.java   
private void check(DirectPlanModifier modifier, final CalculatedVariable calculatedVariable, final EAttribute feature, final Object value) throws Exception {
    PlanModifierMember.get(plan).setModifier(modifier);
    TransactionUtils.checkedWriting(plan, new Runnable() {
        @Override
        public void run() {
            TemporalMember member = activity.getMember(TemporalMember.class);
            member.setCalculatedVariable(calculatedVariable);
            IUndoableOperation operation = TEMPORAL_MODIFIER.set(member, feature, value);
            CommonUtils.execute(operation, TransactionUtils.getUndoContext(member));
            Object newValue = member.eGet(feature);
            if (newValue instanceof Amount) {
                assertTrue(AmountUtils.equals((Amount)value, (Amount)newValue));
            } else if (newValue instanceof Date) {
                assertEquals(((Date)value).getTime(), ((Date)newValue).getTime());
            } else {
                fail("unexpected data type");
            }
            operation = TEMPORAL_MODIFIER.set(member, feature, null);
            CommonUtils.execute(operation, TransactionUtils.getUndoContext(member));
            if (feature == TemporalPackage.Literals.TEMPORAL_MEMBER__START_TIME) {
                operation = TEMPORAL_MODIFIER.set(member, feature, EXTENT.getStart());
                CommonUtils.execute(operation, TransactionUtils.getUndoContext(member));
            }
            if (feature == TemporalPackage.Literals.TEMPORAL_MEMBER__DURATION) {
                operation = TEMPORAL_MODIFIER.set(member, feature, EXTENT.getDuration());
                CommonUtils.execute(operation, TransactionUtils.getUndoContext(member));
            }
            if (feature == TemporalPackage.Literals.TEMPORAL_MEMBER__END_TIME) {
                operation = TEMPORAL_MODIFIER.set(member, feature, EXTENT.getEnd());
                CommonUtils.execute(operation, TransactionUtils.getUndoContext(member));
            }
        }
    });
}
项目:OpenSPIFe    文件:ConstraintAdvisorUtils.java   
public static Suggestion createRemoveConstraintSuggestion(PeriodicTemporalConstraint constraint) {
    String description = "Remove the constraint";
    IUndoableOperation operation = new DeleteTemporalBoundOperation(constraint);
    ImageDescriptor icon = null;
    ConstraintPoint point = constraint.getPoint();
    Object anchorElement = point.getAnchorElement();
    if (PinUtils.isPinConstraint(constraint)) {
        icon = ConstraintsPlugin.getImageDescriptor("icons/delete_pin.png");
    } else if (Timepoint.START == anchorElement) {
        icon = ConstraintsPlugin.getImageDescriptor("icons/delete_earliest.png");
    } else if (Timepoint.END == anchorElement) {
        icon = ConstraintsPlugin.getImageDescriptor("icons/delete_latest.png");
    }
    return new Suggestion(icon, description, operation);
}