Search in sources :

Example 76 with CommandStack

use of org.eclipse.gef.commands.CommandStack in project whole by wholeplatform.

the class TextualFunctionRunnable method run.

@Override
public void run(IOperationProgressMonitor pm) throws InvocationTargetException, InterruptedException {
    // FIXME workaround for missing caret update events (no selection update is performed)
    E4Utils.defineCaretBindings(bm);
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    IEntity text = bm.wGet("focusEntity");
    boolean enableAnimation = AnimableRunnable.enableAnimation(false);
    ModelTextCommand mtc = new ModelTextCommand(text);
    try {
        mtc.setLabel(label);
        mtc.setViewer(viewer);
        mtc.begin();
        try {
            bm.wEnterScope();
            IEntity newText = BehaviorUtils.apply(functionUri, bm.wGet("self"), bm);
            mtc.setNewSelectedEntity(newText);
            mtc.setNewPosition(bm.wIntValue("caretPosition"));
        // FIXME add textual selection viariables updates
        // see E4Utils.defineCaretBindings()
        } catch (OperationCanceledException e) {
            throw e;
        } finally {
            bm.wExitScope();
        }
        mtc.commit();
        if (mtc.canUndo()) {
            CommandStack commandStack = viewer.getEditDomain().getCommandStack();
            commandStack.execute(mtc);
        }
    } catch (OperationCanceledException e) {
        mtc.rollbackIfNeeded();
    } catch (RuntimeException e) {
        mtc.rollbackIfNeeded();
        throw e;
    } finally {
        AnimableRunnable.enableAnimation(enableAnimation);
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) IEntity(org.whole.lang.model.IEntity) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) ModelTextCommand(org.whole.lang.ui.commands.ModelTextCommand) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 77 with CommandStack

use of org.eclipse.gef.commands.CommandStack in project whole by wholeplatform.

the class ActionCallRunnable method run.

@Override
public void run(IOperationProgressMonitor pm) throws InvocationTargetException {
    IEntity model = bm.wGet("self");
    boolean analyzing = bm.wBooleanValue("analyzing");
    if (analyzing) {
        // clone model if is analyzing
        model = EntityUtils.clone(model);
        CommonsEntityFactory.instance.createRootFragment(model.wGetAdapter(CommonsEntityDescriptorEnum.Any));
        ReflectionFactory.getHistoryManager(model).setHistoryEnabled(true);
        // map selected entities if analyzing
        IEntity tuple = bm.wGet("selectedEntities");
        int size = tuple.wSize();
        for (int i = 0; i < size; i++) tuple.wSet(i, EntityUtils.mapEntity(tuple.wGet(i), model));
        bm.wSet("primarySelectedEntity", EntityUtils.mapEntity(bm.wGet("primarySelectedEntity"), model));
        bm.wSet("focusEntity", EntityUtils.mapEntity(bm.wGet("focusEntity"), model));
    }
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    final CommandStack commandStack = viewer.getEditDomain().getCommandStack();
    final ModelTransactionCommand mtc = new ModelTransactionCommand(model, label);
    pm.beginTask("executing action", 90, IOperationProgressMonitor.TOTAL_WORK);
    try {
        mtc.begin();
        HandlersBehavior.actionCall(bm);
        mtc.commit();
        if (analyzing) {
            E4Utils.revealPart(context, RESULTS_PART_ID);
            IEventBroker eventBroker = context.get(IEventBroker.class);
            eventBroker.post(IE4UIConstants.TOPIC_UPDATE_RESULTS, bm.getResult());
        } else if (mtc.canUndo()) {
            context.get(UISynchronize.class).syncExec(new Runnable() {

                public void run() {
                    commandStack.execute(mtc);
                }
            });
        }
    } catch (OperationCanceledException e) {
        mtc.rollbackIfNeeded();
    } catch (RuntimeException e) {
        mtc.rollbackIfNeeded();
        throw e;
    } finally {
        pm.endTask();
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand) IEntity(org.whole.lang.model.IEntity) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) IEventBroker(org.eclipse.e4.core.services.events.IEventBroker)

Example 78 with CommandStack

use of org.eclipse.gef.commands.CommandStack in project whole by wholeplatform.

the class InterpretModelRunnable method run.

@Override
public void run(IOperationProgressMonitor pm) throws InvocationTargetException, InterruptedException {
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    CommandStack commandStack = viewer.getEditDomain().getCommandStack();
    ModelTransactionCommand mtc = new ModelTransactionCommand(bm.wGet("self"), label);
    pm.beginTask("Interpreting...", IOperationProgressMonitor.TOTAL_WORK);
    try {
        mtc.begin();
        HandlersBehavior.interpretModel(bm);
        mtc.commit();
        if (mtc.canUndo())
            commandStack.execute(mtc);
    } catch (OperationCanceledException e) {
        mtc.rollbackIfNeeded();
    } catch (RuntimeException e) {
        mtc.rollbackIfNeeded();
        throw e;
    } finally {
        pm.endTask();
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 79 with CommandStack

use of org.eclipse.gef.commands.CommandStack in project dbeaver by dbeaver.

the class ExtendedDirectEditManager method commit.

/**
 * Commits the current value of the cell editor by getting a {@link Command}
 * from the source edit part and executing it via the {@link CommandStack}.
 * Finally, {@link #bringDown()}is called to perform and necessary cleanup.
 */
@Override
protected void commit() {
    if (committing)
        return;
    committing = true;
    try {
        // we set the cell editor control to invisible to remove any
        // possible flicker
        getCellEditor().getControl().setVisible(false);
        if (isDirty()) {
            CommandStack stack = getEditPart().getViewer().getEditDomain().getCommandStack();
            EditPolicy editPolicy = getEditPart().getEditPolicy(EditPolicy.DIRECT_EDIT_ROLE);
            Command command;
            if (editPolicy != null) {
                command = editPolicy.getCommand(getDirectEditRequest());
            } else {
                command = getEditPart().getCommand(getDirectEditRequest());
            }
            if (command != null && command.canExecute()) {
                stack.execute(command);
            }
        }
    } finally {
        bringDown();
        committing = false;
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) Command(org.eclipse.gef.commands.Command) EditPolicy(org.eclipse.gef.EditPolicy)

Example 80 with CommandStack

use of org.eclipse.gef.commands.CommandStack in project archi by archimatetool.

the class CSVImporter method doImport.

/**
 * Do the actual import given the file
 * @param file
 */
public void doImport(File file) throws IOException, CSVParseException {
    // What file is it?
    File elementsFile = getMatchingFile(file, ELEMENTS_FILENAME);
    if (elementsFile != null && elementsFile.exists()) {
        importElements(elementsFile);
    }
    File relationsFile = getMatchingFile(file, RELATIONS_FILENAME);
    if (relationsFile != null && relationsFile.exists()) {
        importRelations(relationsFile);
    }
    File propertiesFile = getMatchingFile(file, PROPERTIES_FILENAME);
    if (propertiesFile != null && propertiesFile.exists()) {
        importProperties(propertiesFile);
    }
    // Execute the Commands
    CommandStack stack = (CommandStack) fModel.getAdapter(CommandStack.class);
    stack.execute(createCommands());
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) File(java.io.File)

Aggregations

CommandStack (org.eclipse.gef.commands.CommandStack)105 Command (org.eclipse.gef.commands.Command)32 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)14 IArchiveManager (com.archimatetool.editor.model.IArchiveManager)13 AbstractMultiPageTalendEditor (org.talend.designer.core.ui.AbstractMultiPageTalendEditor)13 IArchimateModel (com.archimatetool.model.IArchimateModel)12 ModelTransactionCommand (org.whole.lang.ui.commands.ModelTransactionCommand)12 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)12 NonNotifyingCompoundCommand (com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand)10 EditPart (org.eclipse.gef.EditPart)10 INode (org.talend.core.model.process.INode)10 Node (org.talend.designer.core.ui.editor.nodes.Node)9 IEntity (org.whole.lang.model.IEntity)9 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 PersistenceException (org.talend.commons.exception.PersistenceException)8 EObjectFeatureCommand (com.archimatetool.editor.model.commands.EObjectFeatureCommand)7 IFolder (com.archimatetool.model.IFolder)6 IOException (java.io.IOException)6 IEditorPart (org.eclipse.ui.IEditorPart)6