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

The following examples show how to use org.eclipse.core.commands.operations.OperationHistoryFactory. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
@Override
public boolean test() throws Exception {
  boolean _xblockexpression = false;
  {
    final IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
    IUndoableOperation _xifexpression = null;
    if (this.isRedo) {
      _xifexpression = operationHistory.getRedoOperation(this.getUndoContext());
    } else {
      _xifexpression = operationHistory.getUndoOperation(this.getUndoContext());
    }
    String _label = null;
    if (_xifexpression!=null) {
      _label=_xifexpression.getLabel();
    }
    final String label = _label;
    _xblockexpression = label.startsWith("Rename ");
  }
  return _xblockexpression;
}
 
Example 2
Source Project: statecharts   Source File: SetEntryKindCommand.java    License: Eclipse Public License 1.0 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
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
Source Project: tmxeditor8   Source File: AddTuHandler.java    License: GNU General Public License v2.0 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 5
Source Project: tmxeditor8   Source File: DeleteTuHandler.java    License: GNU General Public License v2.0 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 6
Source Project: tmxeditor8   Source File: TmxEditorViewer.java    License: GNU General Public License v2.0 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 7
protected Button createMoveConnectorButton(final Composite buttonsComposite) {
    final Button moveButton = getWidgetFactory().createButton(
            buttonsComposite, Messages.copyMove, SWT.FLAT);
    moveButton.setLayoutData(GridDataFactory.fillDefaults()
            .minSize(IDialogConstants.BUTTON_WIDTH, SWT.DEFAULT).create());
    moveButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(final Event event) {
            final WizardDialog dialog = new WizardDialog(Display.getDefault()
                    .getActiveShell(),
                    new MoveConnectorWizard(OperationHistoryFactory.getOperationHistory(),
                            getEditingDomain(),
                            ((IStructuredSelection) tableViewer.getSelection()).toList()));
            if (dialog.open() == Dialog.OK) {
                tableViewer.refresh();
            }
        }
    });
    return moveButton;
}
 
Example 8
@Override
protected void doSave(final Object content) {
    final Resource resource = getEMFResource();
    final TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(resource);
    try {
        OperationHistoryFactory.getOperationHistory().execute(
                new SaveDiagramResourceCommand(content, editingDomain, resource),
                Repository.NULL_PROGRESS_MONITOR,
                null);
    } catch (final ExecutionException e1) {
        BonitaStudioLog.error(e1);
    }
    if (content instanceof DiagramDocumentEditor) {
        ((DiagramDocumentEditor) content).doSave(Repository.NULL_PROGRESS_MONITOR);
    }

    try {
        resource.save(ProcessDiagramEditorUtil.getSaveOptions());
    } catch (final IOException e) {
        BonitaStudioLog.error(e);
    }
}
 
Example 9
@Override
public Object start(final IApplicationContext context) {
    START_TIME = System.currentTimeMillis();
    //avoid the execution of AutoBuild job during startup
    addBuildJobListener();
    if (display == null) {
        display = PlatformUI.createDisplay();
    }
    if (!isJavaVersionSupported(display)) {
        return IApplication.EXIT_OK;
    }
    initWorkspaceLocation();
    executePreStartupContributions();

    //set our custom operation factory
    OperationHistoryFactory.setOperationHistory(new BonitaOperationHistory());
    return createAndRunWorkbench(display);
}
 
Example 10
protected void moveData(final IStructuredSelection structuredSelection) {
    final DataAware container = (DataAware) getDataContainerObservable().getValue();
    final MoveDataWizard moveDataWizard = new MoveDataWizard(container);
    if (createWizardDialog(moveDataWizard, IDialogConstants.FINISH_LABEL).open() == Dialog.OK) {
        final DataAware dataAware = moveDataWizard.getSelectedDataAwareElement();
        try {
            final MoveDataCommand cmd = new MoveDataCommand(TransactionUtil.getEditingDomain(dataAware), container,
                    structuredSelection.toList(), dataAware);
            OperationHistoryFactory.getOperationHistory().execute(cmd, null, null);

            if (!(cmd.getCommandResult().getStatus().getSeverity() == Status.OK)) {
                final List<Object> data = (List<Object>) cmd.getCommandResult().getReturnValue();
                String dataNames = "";
                for (final Object d : data) {
                    dataNames = dataNames + ((Element) d).getName() + ",";
                }
                dataNames = dataNames.substring(0, dataNames.length() - 1);
                MessageDialog.openWarning(Display.getDefault().getActiveShell(), Messages.PromoteDataWarningTitle,
                        Messages.bind(Messages.PromoteDataWarningMessage, dataNames));
            }

        } catch (final ExecutionException e1) {
            BonitaStudioLog.error(e1);
        }
    }
}
 
Example 11
@SuppressWarnings("unchecked")
protected void moveData(final IStructuredSelection structuredSelection) {
    final MoveDataWizard moveDataWizard = new MoveDataWizard((DataAware) getEObject());
    if (new WizardDialog(Display.getDefault().getActiveShell(), moveDataWizard).open() == Dialog.OK) {
        final DataAware dataAware = moveDataWizard.getSelectedDataAwareElement();
        try {
            final MoveDataCommand cmd = new MoveDataCommand(getEditingDomain(), (DataAware) getEObject(), structuredSelection.toList(), dataAware);
            OperationHistoryFactory.getOperationHistory().execute(cmd, null, null);

            if (!(cmd.getCommandResult().getStatus().getSeverity() == Status.OK)) {
                final List<Object> data = (List<Object>) cmd.getCommandResult().getReturnValue();
                String dataNames = "";
                for (final Object d : data) {
                    dataNames = dataNames + ((Element) d).getName() + ",";
                }
                dataNames = dataNames.substring(0, dataNames.length() - 1);
                MessageDialog.openWarning(Display.getDefault().getActiveShell(), Messages.PromoteDataWarningTitle,
                        Messages.bind(Messages.PromoteDataWarningMessage, dataNames));
            }

        } catch (final ExecutionException e1) {
            BonitaStudioLog.error(e1);
        }
        refresh();
    }
}
 
Example 12
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 13
Source Project: ermasterr   Source File: TestEditor.java    License: Apache License 2.0 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 14
protected void executeCommand(AbstractTransactionalCommand operation) {
	IOperationHistory history = OperationHistoryFactory.getOperationHistory();
	try {
		history.execute(operation, new NullProgressMonitor(), null);
	} catch (ExecutionException e) {
		e.printStackTrace();
	}
}
 
Example 15
public static void executeCommand(ICommand cmd) {
	try {
		OperationHistoryFactory.getOperationHistory().execute(cmd, new NullProgressMonitor(), null);
	} catch (ExecutionException e) {
		e.printStackTrace();
	}
}
 
Example 16
protected void executeCommand(IUndoableOperation command, Resource resource) {
	IOperationHistory history = OperationHistoryFactory.getOperationHistory();
	try {
		history.execute(command, new NullProgressMonitor(), null);
	} catch (ExecutionException e) {
		e.printStackTrace();
	}
}
 
Example 17
Source Project: statecharts   Source File: OrderElementControl.java    License: Eclipse Public License 1.0 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 18
/**
 * 添加或者取消疑问
 * @param selectedRowIds
 * @param state
 *            ;
 */
public void changIsQuestionState(List<String> selectedRowIds, String state) {
	IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
	try {
		operationHistory.execute(new NeedsReviewOperation("need-review", xliffEditor.getTable(), selectedRowIds,
				xliffEditor.getXLFHandler(), state), null, null);
	} catch (ExecutionException e) {
		LOGGER.error("", e);
		MessageDialog.openError(xliffEditor.getSite().getShell(),
				Messages.getString("utils.NattableUtil.msgTitle2"), e.getMessage());
		e.printStackTrace();
	}
}
 
Example 19
/**
 * 设置是否添加到记忆库
 * @param selectedRowIds
 * @param state
 *            "yes" or "no";
 */
public void changeSendToTmState(List<String> selectedRowIds, String state) {
	IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
	try {
		operationHistory.execute(new SendTOTmOperation("send-to-tm", xliffEditor.getTable(), selectedRowIds,
				xliffEditor.getXLFHandler(), state), null, null);
	} catch (ExecutionException e) {
		LOGGER.error("", e);
		MessageDialog.openError(xliffEditor.getSite().getShell(),
				Messages.getString("utils.NattableUtil.msgTitle2"), e.getMessage());
		e.printStackTrace();
	}
}
 
Example 20
@Override
public void runWithEvent(Event event) {
	if (viewer != null && !viewer.getTextWidget().isDisposed()) {
		XLIFFEditorImplWithNatTable xliffEditor = XLIFFEditorImplWithNatTable.getCurrent();
		// 先保存在撤销,除非以后取消两种模式,否则不要删除此判断
		if (viewer.canDoOperation(ITextOperationTarget.UNDO)) {
			HsMultiActiveCellEditor.commit(true);
		}
		IOperationHistory history = OperationHistoryFactory.getOperationHistory();
		IUndoContext undoContext = (IUndoContext) xliffEditor.getTable().getData(IUndoContext.class.getName());
		if (history.canUndo(undoContext)) {
			try {
				history.undo(undoContext, null, null);
				undoBean.setCrosseStep(undoBean.getCrosseStep() + 1);
			} catch (ExecutionException e) {
				e.printStackTrace();
			}
		}
		XLIFFEditorImplWithNatTable.getCurrent().redraw();
		updateActionsEnableState();
		return;
	}
	if (undoAction != null) {
		undoAction.runWithEvent(event);
		return;
	}
}
 
Example 21
public void runWithEvent(Event event) {
	if (viewer != null && !viewer.getTextWidget().isDisposed()) {
		// 如果跨越焦点撤销,则先撤销非焦点
		try {
			IOperationHistory history = OperationHistoryFactory.getOperationHistory();
			IUndoContext undoContext = (IUndoContext) XLIFFEditorImplWithNatTable.getCurrent().getTable()
					.getData(IUndoContext.class.getName());
			history.redo(undoContext, null, null);
			// int crossSegment = undoBean.getCrosseStep();
			// if (crossSegment > 0) {
			// history.redo(undoContext, null, null);
			// undoBean.setCrosseStep(crossSegment - 1);
			// undoBean.setSaveStatus(-1);
			// } else if (undoBean.getSaveStatus() == -1) {
			// XLIFFEditorImplWithNatTable.getCurrent().jumpToRow(undoBean.getUnSaveRow());
			// viewer.setText(undoBean.getUnSaveText());
			// undoBean.setCrosseStep(0);
			// undoBean.setSaveStatus(0);
			// } else {
			// viewer.doOperation(ITextOperationTarget.REDO);
			// }
		} catch (ExecutionException e) {
			e.printStackTrace();
		}
		System.out.println(undoBean.getCrosseStep());
		updateActionsEnableState();
		return;
	}
	if (redoAction != null) {
		redoAction.runWithEvent(event);
		return;
	}
}
 
Example 22
@Override
protected boolean doCommand(UpdateDataCommand command) {
	IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
	try {
		UpdateDataOperation op = new UpdateDataOperation(table, bodyLayerStack, command);
		op.addContext(PlatformUI.getWorkbench().getOperationSupport().getUndoContext());
		operationHistory.execute(op, null, null);
	} catch (ExecutionException e) {
		e.printStackTrace();
	}
	return true;
}
 
Example 23
public void runWithEvent(Event event) {
	TeActiveCellEditor.commit();
	IOperationHistory history = OperationHistoryFactory.getOperationHistory();
	IUndoContext context = PlatformUI.getWorkbench().getOperationSupport().getUndoContext();
	if (history.canUndo(context)) {
		try {
			history.undo(context, null, null);
			updateActionsEnableState();
		} catch (ExecutionException e) {
			e.printStackTrace();
		}
	}
}
 
Example 24
/**
 * Update the state.
 */
public void updateEnabledState() {
	IOperationHistory opHisotry = OperationHistoryFactory.getOperationHistory();
	IUndoContext context = PlatformUI.getWorkbench().getOperationSupport().getUndoContext();
	if (opHisotry.canUndo(context)) {
		setEnabled(true);
		return;
	}
	if (viewer != null && !viewer.getTextWidget().isDisposed()) {
		setEnabled(viewer.canDoOperation(ITextOperationTarget.UNDO));
		return;
	}
	setEnabled(false);
}
 
Example 25
public void runWithEvent(Event event) {
	TeActiveCellEditor.commit();
	IOperationHistory history = OperationHistoryFactory.getOperationHistory();
	IUndoContext context = PlatformUI.getWorkbench().getOperationSupport().getUndoContext();
	if (history.canRedo(context)) {
		try {
			history.redo(context, null, null);
			updateActionsEnableState();
		} catch (ExecutionException e) {
			e.printStackTrace();
		}
	}
}
 
Example 26
/**
 * Update the state.
 */
public void updateEnabledState() {
	IOperationHistory opHisotry = OperationHistoryFactory.getOperationHistory();
	IUndoContext context = PlatformUI.getWorkbench().getOperationSupport().getUndoContext();
	if (opHisotry.canRedo(context)) {
		setEnabled(true);
		return;
	}
	if (viewer != null && !viewer.getTextWidget().isDisposed()) {
		setEnabled(viewer.canDoOperation(ITextOperationTarget.REDO));
		return;
	}
	setEnabled(false);
}
 
Example 27
Source Project: tmxeditor8   Source File: NattableUtil.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 添加或者取消疑问
 * @param selectedRowIds
 * @param state
 *            ;
 */
public void changIsQuestionState(List<String> selectedRowIds, String state) {
	IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
	try {
		operationHistory.execute(new NeedsReviewOperation("need-review", xliffEditor.getTable(), selectedRowIds,
				xliffEditor.getXLFHandler(), state), null, null);
	} catch (ExecutionException e) {
		LOGGER.error("", e);
		MessageDialog.openError(xliffEditor.getSite().getShell(),
				Messages.getString("utils.NattableUtil.msgTitle2"), e.getMessage());
		e.printStackTrace();
	}
}
 
Example 28
Source Project: tmxeditor8   Source File: NattableUtil.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 设置是否添加到记忆库
 * @param selectedRowIds
 * @param state
 *            "yes" or "no";
 */
public void changeSendToTmState(List<String> selectedRowIds, String state) {
	IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
	try {
		operationHistory.execute(new SendTOTmOperation("send-to-tm", xliffEditor.getTable(), selectedRowIds,
				xliffEditor.getXLFHandler(), state), null, null);
	} catch (ExecutionException e) {
		LOGGER.error("", e);
		MessageDialog.openError(xliffEditor.getSite().getShell(),
				Messages.getString("utils.NattableUtil.msgTitle2"), e.getMessage());
		e.printStackTrace();
	}
}
 
Example 29
Source Project: birt   Source File: JSEditor.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns current undo level.
 * 
 * @return current undo level.
 */
private int getUndoLevel( )
{
	SourceViewer viewer = getViewer( );
	IUndoableOperation[] history = viewer == null ? null
			: OperationHistoryFactory.getOperationHistory( )
					.getUndoHistory( new ObjectUndoContext( viewer.getDocument( ) ) );

	return history == null ? -1 : history.length;
}
 
Example 30
Source Project: saros   Source File: UndoManager.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void dispose() {
  OperationHistoryFactory.getOperationHistory().removeOperationHistoryListener(historyListener);
  sessionManager.removeSessionLifecycleListener(sessionLifecycleListener);
  editorManager.getActivityProducer().removeActivityListener(activityListener);
  enabled = false;
  eclipseHistory.removeOperationApprover(operationBlocker);
  editorManager.removeSharedEditorListener(sharedEditorListener);
}