本文整理汇总了Java中org.eclipse.core.commands.operations.IUndoableOperation.getContexts方法的典型用法代码示例。如果您正苦于以下问题:Java IUndoableOperation.getContexts方法的具体用法?Java IUndoableOperation.getContexts怎么用?Java IUndoableOperation.getContexts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.core.commands.operations.IUndoableOperation
的用法示例。
在下文中一共展示了IUndoableOperation.getContexts方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: historyNotification
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
@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();
}
});
}
}
}
示例3: checkReadOnly
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
protected IStatus checkReadOnly(IUndoableOperation operation) {
for (IUndoContext context : operation.getContexts()) {
if (context instanceof ObjectUndoContext) {
ObjectUndoContext objectUndoContext = (ObjectUndoContext) context;
if (objectUndoContext.getObject() instanceof EditingDomain) {
EditingDomain domain = (EditingDomain) objectUndoContext.getObject();
ResourceSet resourceSet = domain.getResourceSet();
List<Resource> resources = new ArrayList<Resource>(resourceSet.getResources());
for (Resource resource : resources) {
if (resource instanceof PlanResourceImpl) {
for (EObject content : resource.getContents()) {
if (content instanceof EPlan && !EPlanUtils.isTemplatePlan(content)) {
EPlan plan = (EPlan) content;
if (domain.isReadOnly(resource)
|| (!registry.canModify(plan)
&& !registry.canModifyStructure(plan))) {
Throwable exception = new IllegalStateException("checkReadOnly failed: " + operation);
LogUtil.error(exception);
return new Status(IStatus.ERROR, "gov.nasa.ensemble.core.plan.editor", 7, "plan is read only", exception);
}
}
}
}
}
}
}
}
return Status.OK_STATUS;
}
示例4: add
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
@Override
public void add(IUndoableOperation operation) {
Assert.isNotNull(operation);
/*
* If we are in the middle of executing an open batching operation, and
* this is not that operation, then we need only add the context of the
* new operation to the batch. The operation itself is disposed since we
* will never undo or redo it. We consider it to be triggered by the
* batching operation and assume that its undo will be triggered by the
* batching operation undo.
*/
synchronized (openCompositeLock) {
if (openComposite != null && openComposite != operation) {
openComposite.add(operation);
return;
}
}
if (checkUndoLimit(operation)) {
synchronized (undoRedoHistoryLock) {
undoList.add(operation);
}
notifyAdd(operation);
// flush redo stack for related contexts
IUndoContext[] contexts = operation.getContexts();
for (int i = 0; i < contexts.length; i++) {
flushRedo(contexts[i]);
}
} else {
// Dispose the operation since we will not have a reference to it.
operation.dispose();
}
}
示例5: checkRedoLimit
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
/**
* 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;
}
示例6: checkUndoLimit
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
/**
* 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;
}
示例7: flushRedo
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
private void flushRedo(IUndoContext context) {
if (DEBUG_OPERATION_HISTORY_DISPOSE) {
Tracing.printTrace("OPERATIONHISTORY", "Flushing redo history for " //$NON-NLS-1$ //$NON-NLS-2$
+ context);
}
synchronized (undoRedoHistoryLock) {
Object[] filtered = filter(redoList, context);
for (int i = 0; i < filtered.length; i++) {
IUndoableOperation operation = (IUndoableOperation) filtered[i];
if (context == GLOBAL_UNDO_CONTEXT
|| operation.getContexts().length == 1) {
// remove the operation if it only has the context or we are
// flushing all
redoList.remove(operation);
internalRemove(operation);
} else {
// remove the reference to the context.
// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=161786
// It is not enough to simply remove the context. There could
// be one or more contexts that match the one we are trying to
// dispose.
IUndoContext[] contexts = operation.getContexts();
for (int j = 0; j < contexts.length; j++) {
if (contexts[j].matches(context)) {
operation.removeContext(contexts[j]);
}
}
if (operation.getContexts().length == 0) {
redoList.remove(operation);
internalRemove(operation);
}
}
}
}
}
示例8: forceRedoLimit
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
private void forceRedoLimit(IUndoContext context, int max) {
synchronized (undoRedoHistoryLock) {
Object[] filtered = filter(redoList, context);
int size = filtered.length;
if (size > 0) {
int index = 0;
while (size > max) {
IUndoableOperation removed = (IUndoableOperation) filtered[index];
if (context == GLOBAL_UNDO_CONTEXT
|| removed.getContexts().length == 1) {
/*
* remove the operation if we are enforcing a global limit
* or if the operation only has the specified context
*/
redoList.remove(removed);
internalRemove(removed);
} else {
/*
* if the operation has multiple contexts and we've reached
* the limit for only one of them, then just remove the
* context, not the operation.
*/
removed.removeContext(context);
}
size--;
index++;
}
}
}
}
示例9: forceUndoLimit
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
private void forceUndoLimit(IUndoContext context, int max) {
synchronized (undoRedoHistoryLock) {
Object[] filtered = filter(undoList, context);
int size = filtered.length;
if (size > 0) {
int index = 0;
while (size > max) {
IUndoableOperation removed = (IUndoableOperation) filtered[index];
if (context == GLOBAL_UNDO_CONTEXT
|| removed.getContexts().length == 1) {
/*
* remove the operation if we are enforcing a global limit
* or if the operation only has the specified context
*/
undoList.remove(removed);
internalRemove(removed);
} else {
/*
* if the operation has multiple contexts and we've reached
* the limit for only one of them, then just remove the
* context, not the operation.
*/
removed.removeContext(context);
}
size--;
index++;
}
}
}
}
示例10: getSchedulingRule
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
/**
* 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;
}
示例11: historyNotification
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
@Override
public void historyNotification(OperationHistoryEvent event) {
IUndoableOperation eventOperation = event.getOperation();
IUndoContext inputUndoContext = getUndoContext();
IUndoContext[] operationContexts = eventOperation.getContexts();
boolean matches = false;
for (IUndoContext operationContext : operationContexts) {
matches = operationContext.matches(inputUndoContext);
if (matches) {
break;
}
}
if (!matches) {
return;
}
switch (event.getEventType()) {
case OperationHistoryEvent.REDONE: {
if (eventOperation == cleanStateOperation) {
dirty = false;
fireDirtyStateChanged();
} else if (!dirty) {
dirty = true;
fireDirtyStateChanged();
}
break;
}
case OperationHistoryEvent.DONE: {
if (!dirty) {
dirty = true;
fireDirtyStateChanged();
}
break;
}
case OperationHistoryEvent.UNDONE: {
IUndoableOperation undoOperation = event.getHistory().getUndoOperation(inputUndoContext);
if (undoOperation == cleanStateOperation) {
dirty = false;
fireDirtyStateChanged();
} else if (!dirty) {
dirty = true;
fireDirtyStateChanged();
}
break;
}
default:
// nothing to do yet
break;
}
}
示例12: flushUndo
import org.eclipse.core.commands.operations.IUndoableOperation; //导入方法依赖的package包/类
private void flushUndo(IUndoContext context) {
if (DEBUG_OPERATION_HISTORY_DISPOSE) {
Tracing.printTrace("OPERATIONHISTORY", "Flushing undo history for " //$NON-NLS-1$ //$NON-NLS-2$
+ context);
}
synchronized (undoRedoHistoryLock) {
// Get all operations that have the context (or one that matches)
Object[] filtered = filter(undoList, context);
for (int i = 0; i < filtered.length; i++) {
IUndoableOperation operation = (IUndoableOperation) filtered[i];
if (context == GLOBAL_UNDO_CONTEXT
|| operation.getContexts().length == 1) {
// remove the operation if it only has the context or we are
// flushing all
undoList.remove(operation);
internalRemove(operation);
} else {
// remove the reference to the context.
// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=161786
// It is not enough to simply remove the context. There could
// be one or more contexts that match the one we are trying to
// dispose.
IUndoContext[] contexts = operation.getContexts();
for (int j = 0; j < contexts.length; j++) {
if (contexts[j].matches(context)) {
operation.removeContext(contexts[j]);
}
}
if (operation.getContexts().length == 0) {
undoList.remove(operation);
internalRemove(operation);
}
}
}
}
/*
* There may be an open composite. If it has this context, then the
* context must be removed. If it has only this context or we are
* flushing all operations, then null it out and notify that we are
* ending it. We don't remove it since it was never added.
*/
ICompositeOperation endedComposite = null;
synchronized (openCompositeLock) {
if (openComposite != null) {
if (openComposite.hasContext(context)) {
if (context == GLOBAL_UNDO_CONTEXT
|| openComposite.getContexts().length == 1) {
endedComposite = openComposite;
openComposite = null;
} else {
openComposite.removeContext(context);
}
}
}
}
// notify outside of the synchronized block.
if (endedComposite != null) {
notifyNotOK(endedComposite);
}
}