Search in sources :

Example 6 with ModelTransactionCommand

use of org.whole.lang.ui.commands.ModelTransactionCommand in project whole by wholeplatform.

the class PerformHandler method execute.

@Execute
public void execute(@Named(BEHAVIOR_XWL_PARAMETER_ID) String behaviorXwl, @Named(PREDICATE_XWL_PARAMETER_ID) String predicateXwl, @Optional @Named(DESCRIPTION_PARAMETER_ID) String label, @Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm, IEntityPartViewer viewer) throws Exception {
    ModelTransactionCommand mtc = new ModelTransactionCommand(bm.wGet("focusEntity"), label);
    CommandStack commandStack = viewer.getEditDomain().getCommandStack();
    ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
    try {
        bm.wEnterScope(ts);
        defineBindings(behaviorXwl, predicateXwl, bm);
        mtc.begin();
        HandlersBehavior.perform(bm);
        mtc.commit();
        if (mtc.canUndo())
            commandStack.execute(mtc);
    } catch (RuntimeException e) {
        mtc.rollbackIfNeeded();
        throw e;
    } finally {
        ts.rollback();
        bm.wExitScope();
    }
}
Also used : ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand) CommandStack(org.eclipse.gef.commands.CommandStack) ITransactionScope(org.whole.lang.bindings.ITransactionScope) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 7 with ModelTransactionCommand

use of org.whole.lang.ui.commands.ModelTransactionCommand in project whole by wholeplatform.

the class TypedModelTransactionHandler method execute.

@Execute
public void execute(@Named(ED_URI_PARAMETER_ID) String edUri, @Optional @Named(FD_URI_PARAMETER_ID) String fdUri, @Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm, IEntityPartViewer viewer) throws Exception {
    EntityEditDomainJob.asyncExec("replacing entity...", viewer.getEditDomain(), (monitor) -> {
        CommandStack commandStack = viewer.getEditDomain().getCommandStack();
        ModelTransactionCommand mtc = new ModelTransactionCommand(bm.wGet("focusEntity"));
        ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
        try {
            bm.wEnterScope(ts);
            defineBindings(edUri, fdUri, bm);
            mtc.setLabel(getLabel(bm));
            mtc.begin();
            TypedModelTransactionHandler.this.run(bm);
            mtc.commit();
            if (mtc.canUndo())
                commandStack.execute(mtc);
        } catch (RollbackException e) {
        // rollback done
        } catch (RuntimeException e) {
            mtc.rollbackIfNeeded();
            throw e;
        } finally {
            ts.rollback();
            bm.wExitScope();
        }
    });
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand) ITransactionScope(org.whole.lang.bindings.ITransactionScope) RollbackException(org.whole.lang.lifecycle.RollbackException) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 8 with ModelTransactionCommand

use of org.whole.lang.ui.commands.ModelTransactionCommand in project whole by wholeplatform.

the class SelectNotationHandler method execute.

@Execute
public void execute(@Optional @Named(EDITORKIT_ID_PARAMETER_ID) String editorKitId, @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm, final IEntityPartViewer viewer, UISynchronize synchronize) {
    IEditorKit editorKit = ReflectionFactory.getEditorKit(editorKitId);
    final IEntity focusEntity = bm.wGet("focusEntity");
    focusEntity.wGetModel().setEditorKit(editorKit);
    ModelTransactionCommand command = new ModelTransactionCommand(focusEntity);
    try {
        command.begin();
        IEntity fragmentRoot = EntityUtils.getLanguageFragmentRoot(focusEntity);
        viewer.rebuildNotation(fragmentRoot);
        command.commit();
        if (command.canUndo())
            viewer.getEditDomain().getCommandStack().execute(command);
    } catch (Exception e) {
        command.rollbackIfNeeded();
    }
    synchronize.asyncExec(new Runnable() {

        public void run() {
            viewer.selectAndReveal(focusEntity);
        }
    });
}
Also used : ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand) IEntity(org.whole.lang.model.IEntity) IEditorKit(org.whole.lang.reflect.IEditorKit) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 9 with ModelTransactionCommand

use of org.whole.lang.ui.commands.ModelTransactionCommand in project whole by wholeplatform.

the class FunctionRunnable 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");
    CommandStack commandStack = viewer.getEditDomain().getCommandStack();
    ModelTransactionCommand mtc = new ModelTransactionCommand(bm.wGet("self"), label);
    IEntity result = null;
    pm.beginTask("Executing function " + functionUri + "...", IOperationProgressMonitor.TOTAL_WORK);
    try {
        mtc.begin();
        result = BehaviorUtils.apply(functionUri, bm.wGet("self"), bm);
        mtc.commit();
        if (mtc.canUndo())
            commandStack.execute(mtc);
    } catch (OperationCanceledException e) {
        mtc.rollbackIfNeeded();
    } catch (RuntimeException e) {
        mtc.rollbackIfNeeded();
        throw e;
    } finally {
        bm.setResult(result);
        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)

Example 10 with ModelTransactionCommand

use of org.whole.lang.ui.commands.ModelTransactionCommand in project whole by wholeplatform.

the class ContentAssistRunnable 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);
    IEntity[] contentAssist = null;
    pm.beginTask("Content assit generation...", IOperationProgressMonitor.TOTAL_WORK);
    try {
        mtc.begin();
        contentAssist = ContentAssistOperation.getContentAssist(bm.wGet("focusEntity"), bm);
        mtc.commit();
        if (mtc.canUndo())
            commandStack.execute(mtc);
    } catch (OperationCanceledException e) {
        mtc.rollbackIfNeeded();
    } catch (RuntimeException e) {
        mtc.rollbackIfNeeded();
        throw e;
    } finally {
        bm.setResult(BindingManagerFactory.instance.createValue(contentAssist));
        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)

Aggregations

ModelTransactionCommand (org.whole.lang.ui.commands.ModelTransactionCommand)19 CommandStack (org.eclipse.gef.commands.CommandStack)12 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)11 IEntity (org.whole.lang.model.IEntity)9 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)5 Execute (org.eclipse.e4.core.di.annotations.Execute)5 OperationCanceledException (org.whole.lang.operations.OperationCanceledException)5 IBindingManager (org.whole.lang.bindings.IBindingManager)4 ITransactionScope (org.whole.lang.bindings.ITransactionScope)4 ESelectionService (org.eclipse.e4.ui.workbench.modeling.ESelectionService)3 Shell (org.eclipse.swt.widgets.Shell)3 Control (org.eclipse.swt.widgets.Control)2 RollbackException (org.whole.lang.lifecycle.RollbackException)2 ActionEvent (org.eclipse.draw2d.ActionEvent)1 ActionListener (org.eclipse.draw2d.ActionListener)1 IEventBroker (org.eclipse.e4.core.services.events.IEventBroker)1 IType (org.eclipse.jdt.core.IType)1 OpenTypeSelectionDialog (org.eclipse.jdt.internal.ui.dialogs.OpenTypeSelectionDialog)1 FilteredItemsSelectionDialog (org.eclipse.ui.dialogs.FilteredItemsSelectionDialog)1 RootFragment (org.whole.lang.commons.model.RootFragment)1