Search in sources :

Example 1 with CompoundCommand

use of org.eclipse.emf.common.command.CompoundCommand in project webtools.sourceediting by eclipse.

the class StructuredTextUndoManager method redo.

public void redo(IDocumentSelectionMediator requester) {
    IStructuredModel model = findStructuredModel(fDocument);
    if (redoable()) {
        IDocumentExtension4 docExt4 = null;
        DocumentRewriteSession rewriteSession = null;
        try {
            if (model != null)
                model.aboutToChangeModel();
            Command redoCommand = getRedoCommand();
            if (redoCommand instanceof CompoundCommand && model.getStructuredDocument() instanceof IDocumentExtension4) {
                docExt4 = (IDocumentExtension4) model.getStructuredDocument();
            }
            rewriteSession = (docExt4 == null) ? null : docExt4.startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED);
            // make sure to redo before setting document selection
            fCommandStack.redo();
            // set document selection
            setRedoDocumentSelection(requester, redoCommand);
        } finally {
            if (docExt4 != null && rewriteSession != null)
                docExt4.stopRewriteSession(rewriteSession);
            if (model != null) {
                model.changedModel();
                model.releaseFromRead();
            }
        }
    }
}
Also used : DocumentRewriteSession(org.eclipse.jface.text.DocumentRewriteSession) IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) CompoundCommand(org.eclipse.emf.common.command.CompoundCommand) Command(org.eclipse.emf.common.command.Command) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) CompoundCommand(org.eclipse.emf.common.command.CompoundCommand)

Example 2 with CompoundCommand

use of org.eclipse.emf.common.command.CompoundCommand in project webtools.sourceediting by eclipse.

the class StructuredTextUndoManager method undo.

public void undo(IDocumentSelectionMediator requester) {
    // Therefore, this force ending of recording is not needed in redo.
    if (fRecording)
        endRecording(this);
    if (undoable()) {
        IStructuredModel model = findStructuredModel(fDocument);
        IDocumentExtension4 docExt4 = null;
        DocumentRewriteSession rewriteSession = null;
        try {
            if (model != null)
                model.aboutToChangeModel();
            Command undoCommand = getUndoCommand();
            if (undoCommand instanceof CompoundCommand && model.getStructuredDocument() instanceof IDocumentExtension4) {
                docExt4 = (IDocumentExtension4) model.getStructuredDocument();
            }
            rewriteSession = (docExt4 == null) ? null : docExt4.startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED);
            // make sure to undo before setting document selection
            fCommandStack.undo();
            // set document selection
            setUndoDocumentSelection(requester, undoCommand);
        } finally {
            if (docExt4 != null && rewriteSession != null)
                docExt4.stopRewriteSession(rewriteSession);
            if (model != null) {
                model.changedModel();
                model.releaseFromRead();
            }
        }
    }
}
Also used : DocumentRewriteSession(org.eclipse.jface.text.DocumentRewriteSession) IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) CompoundCommand(org.eclipse.emf.common.command.CompoundCommand) Command(org.eclipse.emf.common.command.Command) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) CompoundCommand(org.eclipse.emf.common.command.CompoundCommand)

Example 3 with CompoundCommand

use of org.eclipse.emf.common.command.CompoundCommand in project InformationSystem by ObeoNetwork.

the class EditUserStoryHandler method execute.

/**
 * {@inheritDoc}
 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    if (activePart instanceof UserStoriesView) {
        UserStoriesView view = (UserStoriesView) activePart;
        EditingDomain editingDomain = view.getEditingDomain();
        if (editingDomain != null) {
            UserStory userStory = view.getSelectedStories().get(0);
            UserStoryDialog dialog = new UserStoryDialog(HandlerUtil.getActiveShell(event), userStory);
            int open = dialog.open();
            if (open == Window.OK) {
                CompoundCommand cc = new CompoundCommand();
                cc.append(SetCommand.create(editingDomain, userStory, GraalPackage.eINSTANCE.getNamedElement_Name(), dialog.getName()));
                cc.append(SetCommand.create(editingDomain, userStory, EnvironmentPackage.eINSTANCE.getObeoDSMObject_Description(), dialog.getDescription()));
                editingDomain.getCommandStack().execute(cc);
                view.refresh();
            }
        }
    }
    return null;
}
Also used : UserStoriesView(org.obeonetwork.graal.design.ui.view.UserStoriesView) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) EditingDomain(org.eclipse.emf.edit.domain.EditingDomain) UserStoryDialog(org.obeonetwork.graal.design.ui.dialog.UserStoryDialog) UserStory(org.obeonetwork.graal.UserStory) CompoundCommand(org.eclipse.emf.common.command.CompoundCommand)

Aggregations

CompoundCommand (org.eclipse.emf.common.command.CompoundCommand)3 Command (org.eclipse.emf.common.command.Command)2 DocumentRewriteSession (org.eclipse.jface.text.DocumentRewriteSession)2 IDocumentExtension4 (org.eclipse.jface.text.IDocumentExtension4)2 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)2 EditingDomain (org.eclipse.emf.edit.domain.EditingDomain)1 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)1 UserStory (org.obeonetwork.graal.UserStory)1 UserStoryDialog (org.obeonetwork.graal.design.ui.dialog.UserStoryDialog)1 UserStoriesView (org.obeonetwork.graal.design.ui.view.UserStoriesView)1