本文整理汇总了Java中org.eclipse.core.commands.operations.IUndoableOperation.addContext方法的典型用法代码示例。如果您正苦于以下问题:Java IUndoableOperation.addContext方法的具体用法?Java IUndoableOperation.addContext怎么用?Java IUndoableOperation.addContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.core.commands.operations.IUndoableOperation
的用法示例。
在下文中一共展示了IUndoableOperation.addContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeOperation
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
/**
* 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());
}
}
示例2: setCalculatedVariable
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
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);
}
}
示例3: modify
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
@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);
}
}
示例4: execute
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
/**
* 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);
}
}
示例5: cutPasteElements
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
/**
* @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);
}
示例6: execute
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
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);
}
}
}
示例7: execute
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
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);
}
}
}
示例8: execute
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
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);
}
}
}
示例9: execute
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
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);
}
}
}
示例10: execute
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
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);
}
}
}
示例11: aboutToPerformChange
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
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;
}
示例12: execute
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
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");
}
}
示例13: execute
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
private void execute(IUndoableOperation operation, EPlanElement element) {
operation.addContext(TransactionUtils.getUndoContext(element));
try {
IOperationHistory history = OperationHistoryFactory.getOperationHistory();
history.execute(operation, null, null);
} catch (ExecutionException ee) {
fail("failed to execute");
}
}
示例14: integratePlan
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
/**
* Create the project described in record. If it is successful return true.
*
* @param projectToBeIntegratedRecord
* @return boolean <code>true</code> if successful
* @throws InterruptedException
*/
private boolean integratePlan(final ProjectRecord projectToBeIntegratedRecord,
IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
String projectName = projectToBeIntegratedRecord.getProjectName();
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IProject projectToBeIntegrated = workspace.getRoot().getProject(projectName);
EPlan schedule = null;
try {
monitor.beginTask("Integrating Plans",1);
// SPIFePlanIntegrationOperation op = new SPIFePlanIntegrationOperation(driverPlan, planToBeIntegrated);
// op.mergePlans();
schedule = SpifeProjectUtils.getOrLoadScheduleFromProject(projectToBeIntegrated);
IUndoableOperation operation = new SPIFePlanIntegrationOperation(driverPlan, schedule);
operation.addContext(TransactionUtils.getUndoContext(driverPlan));
IOperationHistory history = OperationHistoryFactory.getOperationHistory();
IStatus status = history.execute(operation, monitor, null);
if (status instanceof JobOperationStatus) {
JobOperationStatus jobStatus = (JobOperationStatus) status;
jobStatus.getJob().join();
}
} catch (Exception e) {
throw new InvocationTargetException(e);
} finally {
SpifeProjectUtils.disposeSchedule(schedule);
monitor.done();
}
return true;
}
示例15: execute
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
/**
* 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);
}
}