Java Code Examples for org.eclipse.core.commands.operations.OperationHistoryFactory

The following are top voted examples for showing how to use org.eclipse.core.commands.operations.OperationHistoryFactory. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: bts   File: LinkedEditingUndoSupport.java   Source Code and License 6 votes vote down vote up
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);
	}
}
 
Example 2
Project: statecharts   File: SetEntryKindCommand.java   Source Code and License 6 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	entry = unwrap(HandlerUtil.getCurrentSelection(event));
	
	if (entry == null)
		return null;
	SetValueCommand setCommand = new SetValueCommand(new SetRequest(entry,
			SGraphPackage.Literals.ENTRY__KIND, getEntryKind()));
	IOperationHistory history = OperationHistoryFactory
			.getOperationHistory();
	try {
		history.execute(setCommand, new NullProgressMonitor(), null);
	} catch (ExecutionException e) {
		e.printStackTrace();
	}
	
	return null;
}
 
Example 3
Project: statecharts   File: ToggleSubRegionLayoutCommand.java   Source Code and License 6 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	view = unwrap(HandlerUtil.getCurrentSelection(event));

	TransactionalEditingDomain editingDomain = TransactionUtil
			.getEditingDomain(view);
	ToggleCommand toggleCommand = new ToggleCommand(editingDomain, view);

	try {
		OperationHistoryFactory.getOperationHistory().execute(
				toggleCommand, new NullProgressMonitor(), null);
	} catch (ExecutionException e) {
		e.printStackTrace();
	}

	return null;
}
 
Example 4
Project: OpenSPIFe   File: UndoableOperationTestUtil.java   Source Code and License 6 votes vote down vote up
/**
 * 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());
	}
}
 
Example 5
Project: OpenSPIFe   File: ScheduledOperation.java   Source Code and License 6 votes vote down vote up
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);
	}
}
 
Example 6
Project: OpenSPIFe   File: OneOfEachAction.java   Source Code and License 6 votes vote down vote up
private void createAddOperation(PlanEditorModel model, final EPlanElement parent, final EPlanElement child) {
	IStructureModifier modifier = PlanStructureModifier.INSTANCE;
	PlanTransferable transferable = new PlanTransferable();
	transferable.setPlanElements(Collections.singletonList(child));
	IStructureLocation location = modifier.getInsertionLocation(transferable, new StructuredSelection(parent), InsertionSemantics.ON);
	AddOperation operation = new PlanAddOperation(transferable, modifier, location);
	IUndoContext undoContext = model.getUndoContext();
	operation.addContext(undoContext);
	try {
		IOperationHistory history = OperationHistoryFactory.getOperationHistory();
		IStatus status = history.execute(operation, null, null);
		if (status instanceof JobOperationStatus) {
			((JobOperationStatus) status).getJob().join();
		}
	} catch (Exception e) {
		trace.error("OneOfEachAction.createAddGroupOperation:operation", e);
	}
}
 
Example 7
Project: OpenSPIFe   File: ProfileDataPointColumnProvider.java   Source Code and License 6 votes vote down vote up
@Override
public void modify(DataPoint oldDataPoint, Object value, IUndoContext undoContext) {
	if (value instanceof Date) {
		DataPoint newDataPoint = JScienceFactory.eINSTANCE.createEDataPoint((Date) value, oldDataPoint.getValue());
		SwapProfileDataPointOperation op = new SwapProfileDataPointOperation(profile, oldDataPoint, newDataPoint);
		if (undoContext != null) {
			op.addContext(undoContext);
		}
		IOperationHistory history = OperationHistoryFactory.getOperationHistory();
		try {
			history.execute(op, null, null);
		} catch (ExecutionException e) {
			LogUtil.error(e);
		}
	}
}
 
Example 8
Project: OpenSPIFe   File: TemporalDetailProvider.java   Source Code and License 6 votes vote down vote up
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);
	}
}
 
Example 9
Project: OpenSPIFe   File: PlanElementRowEditPart.java   Source Code and License 6 votes vote down vote up
private void addVisibleLabel(IFigure figure) {
	visibleLabel = new Label();
	visibleLabel.setBorder(new SimpleRaisedBorder());
	visibleLabel.addMouseListener(new MouseListener.Stub() {
		@Override
		public void mousePressed(MouseEvent me) {
			EPlanElement node = getModel();
			TriState oldValue = SpifePlanUtils.getVisible(node);
			if (!PlanEditApproverRegistry.getInstance().canModify(node)) {
				return;
			}
			try {
				VisibleOperation op = new VisibleOperation(node, oldValue == TriState.FALSE);
				op.addContext(TransactionUtils.getUndoContext(node));
				IOperationHistory history = OperationHistoryFactory.getOperationHistory();
				history.execute(op, null, null);
			} catch (Exception e) {
				trace.error(e.getMessage(), e);
			}
		}
	});
	updateVisibleVisual();
	figure.add(visibleLabel);
}
 
Example 10
Project: OpenSPIFe   File: OrderEventsAscendingHandler.java   Source Code and License 6 votes vote down vote up
protected void runImpl(MultiPagePlanEditor editor, EPlan plan) {
	EPlanElement parent = getSelection(editor);
	if (parent==null){
		parent=plan;
	}
	List<EPlanChild> childList = new ArrayList<EPlanChild>();
	for (EPlanChild child : parent.getChildren()) {
		childList.add(child);
	}
	Collections.sort(childList, new ScheduledActivtyComparator());
	IStructureModifier modifier = PlanStructureModifier.INSTANCE;
	PlanTransferable transferable = new PlanTransferable();
	transferable.setPlanElements(childList);
	IStructureLocation location = modifier.getInsertionLocation(transferable, new StructuredSelection(parent), InsertionSemantics.ON);
	PlanEditorModel model = editor.getPlanEditorModel();
	MoveOperation operation = new PlanMoveOperation(transferable, modifier, location);
	IUndoContext undoContext = model.getUndoContext();
	operation.addContext(undoContext);
	try {
		IOperationHistory history = OperationHistoryFactory.getOperationHistory();
		history.execute(operation, null, null);
	} catch (Exception e) {
		LogUtil.error(OrderEventsAscendingHandler.class.getName(), e);
	}
}
 
Example 11
Project: OpenSPIFe   File: UndoableObservableValue.java   Source Code and License 6 votes vote down vote up
@Override
protected void doSetValue(final Object value) {
	Object oldValue = doGetValue();
	if (CommonUtils.equals(value, oldValue)) {
		return; // nothing to do
	}
	EStructuralFeature feature = (EStructuralFeature) pd.getFeature(target);
	String name = EMFUtils.getDisplayName(target, feature);
	IUndoableOperation operation = new ChangeObservableOperation("Edit " + name, value);
	EObject observed = (EObject) getObserved();
	operation = EMFUtils.addContributorOperations(operation, observed, feature, oldValue, value);
	IUndoContext context = gov.nasa.ensemble.emf.transaction.TransactionUtils.getUndoContext(observed);
	IOperationHistory history = OperationHistoryFactory.getOperationHistory();
	IUndoableOperation previous = history.getUndoOperation(context);
	if (previous instanceof TextModifyUndoableObservableValue.TextModifyObservableOperation) {
		// Reset the TextModifyObservableOperation to clear the dirty flag on its TextModifyUndoableObservableValue
		((TextModifyUndoableObservableValue.TextModifyObservableOperation) previous).reset();
		// Remove the TextModifyObservableOperation operation from the operation history as it should be replaced by the new operation
		history.replaceOperation(previous, new IUndoableOperation[0]);
	}
	CommonUtils.execute(operation, context);
}
 
Example 12
Project: OpenSPIFe   File: WidgetUtils.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 13
Project: OpenSPIFe   File: TestCutPasteOperation.java   Source Code and License 6 votes vote down vote up
/**
 * @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);
}
 
Example 14
Project: OpenSPIFe   File: TestCopyPasteOperation.java   Source Code and License 6 votes vote down vote up
/**
 * @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);
				}
			});
}
 
Example 15
Project: OpenSPIFe   File: FeatureTransactionAddOperation.java   Source Code and License 6 votes vote down vote up
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);
	    }
	}
}
 
Example 16
Project: OpenSPIFe   File: FeatureTransactionRemoveAllOperation.java   Source Code and License 6 votes vote down vote up
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);
	    }
	}
}
 
Example 17
Project: OpenSPIFe   File: FeatureTransactionAddAllOperation.java   Source Code and License 6 votes vote down vote up
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);
	    }
	}
}
 
Example 18
Project: OpenSPIFe   File: FeatureTransactionChangeOperation.java   Source Code and License 6 votes vote down vote up
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);
	    }
	}
}
 
Example 19
Project: OpenSPIFe   File: FeatureTransactionRemoveOperation.java   Source Code and License 6 votes vote down vote up
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);
	    }
	}
}
 
Example 20
Project: OpenSPIFe   File: FixViolationsOperation.java   Source Code and License 6 votes vote down vote up
private void doAddOperation(PlanEditorModel model, final EPlanElement parent, final List<EActivity> activities) {
	IStructureModifier modifier = PlanStructureModifier.INSTANCE;
	PlanTransferable transferable = new PlanTransferable();
	transferable.setPlanElements(activities);
	IStructureLocation location = modifier.getInsertionLocation(transferable, new StructuredSelection(parent), InsertionSemantics.ON);
	AddOperation operation = new PlanAddOperation(transferable, modifier, location);
	//IUndoContext undoContext = model.getUndoContext();
	//operation.addContext(undoContext);
	try {
		IOperationHistory history = OperationHistoryFactory.getOperationHistory();
		@SuppressWarnings("unused")
		IStatus status = history.execute(operation, null, null);
	} catch (Exception e) {
		trace.error("FixViolationsOperation.doAddOperation:operation", e);
	}
}
 
Example 21
Project: OpenSPIFe   File: CommonPlugin.java   Source Code and License 6 votes vote down vote up
/**
	 * This method is called upon plug-in activation
	 */
	@Override
	public void start(BundleContext context) throws Exception {
		super.start(context);
		OperationHistoryFactory.setOperationHistory(JobOperationHistory.INSTANCE);
		// configure logging
		// TODO this may cease working once the EnsembleLoggingConfigurator is extended
		ensembleProperties = initializeEnsembleProperties();
//		EnsemblePropertiesSurveyor.initialize();
		EnsembleLoggingConfigurator construct = MissionExtender.construct(EnsembleLoggingConfigurator.class);
		if (construct != null) {
			construct.configureLogging();
		} else {
			// logging not initialized
			System.err.println("EnsembleLoggingConfigurator == null");
		}
        
	}
 
Example 22
Project: OpenSPIFe   File: TestTemporalBoundColumn.java   Source Code and License 6 votes vote down vote up
public void assertDeleteConstraint(PeriodicTemporalConstraint constraint, Timepoint timepoint) {
	TemporalBoundColumn column = new TemporalBoundColumn(TEST_PROVIDER, timepoint);
	EActivity a = constructBoundedActivity(constraint);
	ConstraintsMember originalFacet = column.getFacet(a);
	String originalText = column.getText(originalFacet);
	column.modify(originalFacet, "", undoContext);
	
	ConstraintsMember constraintsMember = a.getMember(ConstraintsMember.class, true);
	List<PeriodicTemporalConstraint> bounds = constraintsMember.getPeriodicTemporalConstraints();
	assertEquals("Number mismatch in bounds count after editing", 0, bounds.size());
	ConstraintsMember changedFacet = column.getFacet(a);
	assertEquals("Column text not equal", column.getText(changedFacet), "");
	
	try {
		IOperationHistory history = OperationHistoryFactory.getOperationHistory();
		history.undo(undoContext, null, null);
	} catch (Exception e) {
		fail(e.getMessage());
	}
	
	ConstraintsMember finalFacet = column.getFacet(a);
	assertEquals("Error in undo operation", originalText, column.getText(finalFacet));
}
 
Example 23
Project: tmxeditor8   File: AddTuHandler.java   Source Code and License 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	TmxEditorViewer viewer = TmxEditorViewer.getInstance();
	if(viewer == null){
		return null;
	}
	TmxEditor editor = viewer.getTmxEditor();
	if(editor == null){
		return null;
	}
	String srcLang = editor.getSrcLang();
	String tgtLang = editor.getTgtLang();
	TmxTU tu = TmxEditorUtils.createTmxTu(srcLang, tgtLang);
	editor.addTu(tu);
	IOperationHistory histor = OperationHistoryFactory.getOperationHistory();
	histor.dispose(PlatformUI.getWorkbench().getOperationSupport().getUndoContext(), true, true, true);
	return null;
}
 
Example 24
Project: tmxeditor8   File: DeleteTuHandler.java   Source Code and License 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	TmxEditorViewer viewer = TmxEditorViewer.getInstance();
	if (viewer == null) {
		return null;
	}
	TmxEditor editor = viewer.getTmxEditor();
	if (editor == null) {
		return null;
	}
	if (editor.getTmxDataAccess().getDisplayTuCount() == 0
			|| editor.getTmxEditorImpWithNattable().getSelectedRows().length == 0) {
		OpenMessageUtils.openMessage(IStatus.INFO, Messages.getString("tmxeditor.deleteTuHandler.noSelectedMsg"));
		return null;
	}
	boolean confirm = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event),
			Messages.getString("tmxeditor.deleteTuHandler.warn.msg"),
			Messages.getString("tmxeditor.deleteTuHandler.warn.desc"));
	if (!confirm) {
		return null;
	}
	editor.deleteSelectedTu();
	IOperationHistory histor = OperationHistoryFactory.getOperationHistory();
	histor.dispose(PlatformUI.getWorkbench().getOperationSupport().getUndoContext(), true, true, true);
	return null;
}
 
Example 25
Project: tmxeditor8   File: TmxEditorViewer.java   Source Code and License 6 votes vote down vote up
/**
 * 关闭TmxEditor,同时关闭AbstractDataAccess
 **/
public boolean closeTmx() {
	if (tmxEditor == null) {
		return true;
	}
	if (!tmxEditor.closeTmxEditor()) {
		return false;
	}
	tmxEditor = null;
	Control[] childs = container.getChildren();
	for (Control c : childs) {
		if (c != null && !c.isDisposed()) {
			c.dispose();
		}
	}
	fireCloseEvent();
	IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
	operationHistory.dispose(getSite().getWorkbenchWindow().getWorkbench().getOperationSupport().getUndoContext(),
			true, true, true);
	setFocus();
	String title = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getText();
	String[] s = title.split("-");
	PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().setText(s[0]);
	return true;
}
 
Example 26
Project: ermasterr   File: TestEditor.java   Source Code and License 5 votes vote down vote up
/**
 * The <code>AbstractTextEditor</code> implementation of this
 * <code>IWorkbenchPart</code> method may be extended by subclasses.
 * Subclasses must call <code>super.dispose()</code>.
 * <p>
 * Note that many methods may return <code>null</code> after the editor is
 * disposed.
 * </p>
 */
@Override
public void dispose() {

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

    disposeDocumentProvider();

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

    if (fConfiguration != null)
        fConfiguration = null;

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

    super.dispose();
}
 
Example 27
Project: ermaster-k   File: TestEditor.java   Source Code and License 5 votes vote down vote up
/**
 * The <code>AbstractTextEditor</code> implementation of this
 * <code>IWorkbenchPart</code> method may be extended by subclasses.
 * Subclasses must call <code>super.dispose()</code>.
 * <p>
 * Note that many methods may return <code>null</code> after the editor is
 * disposed.
 * </p>
 */
@Override
public void dispose() {

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

	disposeDocumentProvider();

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

	if (fConfiguration != null)
		fConfiguration = null;

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

	super.dispose();
}
 
Example 28
Project: bts   File: LinkedEditingUndoSupport.java   Source Code and License 5 votes vote down vote up
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);
		}
	}
}
 
Example 29
Project: statecharts   File: CreateSubdiagramCommand.java   Source Code and License 5 votes vote down vote up
protected void executeCommand(AbstractTransactionalCommand operation) {
	IOperationHistory history = OperationHistoryFactory.getOperationHistory();
	try {
		history.execute(operation, new NullProgressMonitor(), null);
	} catch (ExecutionException e) {
		e.printStackTrace();
	}
}
 
Example 30
Project: statecharts   File: ToggleShowDocumentationCommand.java   Source Code and License 5 votes vote down vote up
public static void executeCommand(ICommand cmd) {
	try {
		OperationHistoryFactory.getOperationHistory().execute(cmd, new NullProgressMonitor(), null);
	} catch (ExecutionException e) {
		e.printStackTrace();
	}
}
 
Example 31
Project: statecharts   File: AbstractSemanticModification.java   Source Code and License 5 votes vote down vote up
protected void executeCommand(IUndoableOperation command, Resource resource) {
	IOperationHistory history = OperationHistoryFactory.getOperationHistory();
	try {
		history.execute(command, new NullProgressMonitor(), null);
	} catch (ExecutionException e) {
		e.printStackTrace();
	}
}
 
Example 32
Project: statecharts   File: OrderElementControl.java   Source Code and License 5 votes vote down vote up
public void widgetSelected(SelectionEvent e) {
	RepositionEObjectCommand command = new RepositionEObjectCommand(
			TransactionUtil.getEditingDomain(callback.getEObject()), "Reorder Elements", getListInput(),
			getSelectedObject(), displacement);
	try {
		OperationHistoryFactory.getOperationHistory().execute(command, new NullProgressMonitor(), null);
	} catch (ExecutionException e1) {
		e1.printStackTrace();
	}
	refreshInput();
}
 
Example 33
Project: che   File: RefactoringCorePlugin.java   Source Code and License 5 votes vote down vote up
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;
}
 
Example 34
Project: che   File: RefactoringHistoryService.java   Source Code and License 5 votes vote down vote up
/** {@inheritDoc} */
public void disconnect() {
  if (fReferenceCount > 0) {
    fManagerCache.clear();
    fReferenceCount--;
  }
  if (fReferenceCount == 0) {
    if (fOperationListener != null)
      OperationHistoryFactory.getOperationHistory()
          .removeOperationHistoryListener(fOperationListener);
    if (fResourceListener != null)
      ResourcesPlugin.getWorkspace().removeResourceChangeListener(fResourceListener);
    fOperationListener = null;
  }
}
 
Example 35
Project: OpenSPIFe   File: UndoableOperationTestUtil.java   Source Code and License 5 votes vote down vote up
/**
 * 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());
}
 
Example 36
Project: OpenSPIFe   File: UndoableOperationTestUtil.java   Source Code and License 5 votes vote down vote up
/**
 * Redo the given operation, which should be the next operation to redo in the undo context.
 * Tests that the operation can be redone, that it is the next to redo in the undo context,
 * that the redo result isOK() and that no ExecutionException is thrown.
 * @param operation
 * @param undoContext
 */
public static final void redoOperation(IUndoableOperation operation, IUndoContext undoContext) {
	TestCase.assertTrue(operation.canRedo());
	String string = "failed to redo";
	try {
		IOperationHistory history = OperationHistoryFactory.getOperationHistory();
		TestCase.assertSame("the supplied operation should be next on the redo stack", operation, history.getRedoOperation(undoContext));
		IStatus result = history.redo(undoContext, null, null);
		TestCase.assertTrue(string + ": " + operation.getLabel(), result.isOK());
	} catch (ExecutionException e) {
		TestCase.fail(string);
	}
	TestCase.assertFalse(operation.canRedo());
	TestCase.assertTrue(operation.canUndo());
}
 
Example 37
Project: OpenSPIFe   File: TestTemporalTransferableExtension.java   Source Code and License 5 votes vote down vote up
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");
	}
}
 
Example 38
Project: OpenSPIFe   File: TestDirectPlanModifier.java   Source Code and License 5 votes vote down vote up
private static void modifyStartTime(IPlanModifier modifier, EPlanElement element, Date newStart) throws ExecutionException {
	EPlan plan = EPlanUtils.getPlan(element);
	TemporalExtentsCache cache = new TemporalExtentsCache(plan);
	Map<EPlanElement, TemporalExtent> changedTimes = modifier.moveToStart(element, newStart, cache);
	SetExtentsOperation operation = new SetExtentsOperation("set start times", plan, changedTimes, cache);
	operation.addContext(TransactionUtils.getUndoContext(plan));
	IOperationHistory history = OperationHistoryFactory.getOperationHistory();
	history.execute(operation, null, null);
}
 
Example 39
Project: OpenSPIFe   File: OneOfEachAction.java   Source Code and License 5 votes vote down vote up
private void createChainOperation(PlanEditorModel model, final List<EPlanChild> links) {
	IUndoContext undoContext = model.getUndoContext();
	PlanStructureModifier modifier = PlanStructureModifier.INSTANCE;
	ChainOperation operation = new ChainOperation(modifier, links, false);
	operation.addContext(undoContext);
	try {
		IOperationHistory history = OperationHistoryFactory.getOperationHistory();
		IStatus status = history.execute(operation, null, null);
		if (status instanceof JobOperationStatus) {
			((JobOperationStatus) status).getJob().join();
		}
	} catch (Exception e) {
		trace.error("OneOfEachAction.createChainOperation:operation", e);
	}
}
 
Example 40
Project: OpenSPIFe   File: FixedTransactionEditingDomain.java   Source Code and License 5 votes vote down vote up
@Override
public void dispose() {
	OperationHistoryFactory.getOperationHistory().dispose(undoContext, true, true, true);
	EMFUtils.clearReachableObjectsOfType(getResourceSet());
    super.dispose();
    getResourceSet().getLoadOptions().clear(); // clear XMLResource.OPTION_USE_PARSER_POOL
    getResourceSet().getResources().clear(); // help limit memory leaks
}