Search in sources :

Example 1 with ModelTextCommand

use of org.whole.lang.ui.commands.ModelTextCommand 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)

Aggregations

CommandStack (org.eclipse.gef.commands.CommandStack)1 IEntity (org.whole.lang.model.IEntity)1 OperationCanceledException (org.whole.lang.operations.OperationCanceledException)1 ModelTextCommand (org.whole.lang.ui.commands.ModelTextCommand)1 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)1