Search in sources :

Example 21 with ITransactionScope

use of org.whole.lang.bindings.ITransactionScope in project whole by wholeplatform.

the class ModelTransactionHandler method canExecute.

@CanExecute
public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) {
    ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
    try {
        bm.wEnterScope(ts);
        return isEnabled(bm);
    } catch (Exception e) {
        return false;
    } finally {
        ts.rollback();
        bm.wExitScope();
    }
}
Also used : ITransactionScope(org.whole.lang.bindings.ITransactionScope) RollbackException(org.whole.lang.lifecycle.RollbackException) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute)

Example 22 with ITransactionScope

use of org.whole.lang.bindings.ITransactionScope in project whole by wholeplatform.

the class ModelTransactionHandler method execute.

@Execute
public void execute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) {
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    EntityEditDomainJob.asyncExec(getLabel(bm), viewer.getEditDomain(), (monitor) -> {
        CommandStack commandStack = viewer.getEditDomain().getCommandStack();
        ModelTransactionCommand mtc = new ModelTransactionCommand(bm.wGet("focusEntity"));
        ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
        try {
            bm.wEnterScope(ts);
            mtc.setLabel(getLabel(bm));
            mtc.begin();
            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) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 23 with ITransactionScope

use of org.whole.lang.bindings.ITransactionScope in project whole by wholeplatform.

the class HandlersBehavior method canAddFragment.

public static boolean canAddFragment(IBindingManager bm) {
    if (!isValidFocusEntityPart(bm))
        return false;
    IEntity focusEntity = bm.wGet("focusEntity");
    IEntity predicateEntity = bm.wGet("predicateEntity");
    ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
    bm.wEnterScope(ts);
    // FIXME workaround for domain content assist that assume self initialized with primarySelectedEntity
    bm.wDefValue("self", focusEntity);
    boolean predicateResult = BehaviorUtils.evaluatePredicate(predicateEntity, 0, bm);
    ts.rollback();
    bm.wExitScope();
    if (!predicateResult)
        return false;
    return EntityUtils.isAddable(focusEntity, bm.wGet("fragmentEntity"));
}
Also used : ITransactionScope(org.whole.lang.bindings.ITransactionScope) IEntity(org.whole.lang.model.IEntity)

Example 24 with ITransactionScope

use of org.whole.lang.bindings.ITransactionScope in project whole by wholeplatform.

the class HandlersBehavior method canReplaceFragment.

public static boolean canReplaceFragment(IBindingManager bm) {
    if (!isValidFocusEntityPart(bm))
        return false;
    IEntity focusEntity = bm.wGet("focusEntity");
    IEntity predicateEntity = bm.wGet("predicateEntity");
    ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
    bm.wEnterScope(ts);
    // FIXME workaround for domain content assist that assume self initialized with primarySelectedEntity
    bm.wDefValue("self", focusEntity);
    boolean predicateResult = BehaviorUtils.evaluatePredicate(predicateEntity, 0, bm);
    ts.rollback();
    bm.wExitScope();
    if (!predicateResult)
        return false;
    return EntityUtils.isReplaceable(focusEntity, bm.wGet("fragmentEntity"));
}
Also used : ITransactionScope(org.whole.lang.bindings.ITransactionScope) IEntity(org.whole.lang.model.IEntity)

Example 25 with ITransactionScope

use of org.whole.lang.bindings.ITransactionScope in project whole by wholeplatform.

the class E4SampleGraphicalPart method createSelectionLinkable.

@Override
protected ILinkableSelectionListener createSelectionLinkable(IEntityPartViewer viewer) {
    ILinkableSelectionListener listener = super.createSelectionLinkable(viewer);
    listener.addLinkViewerListener(new LinkViewerAdapter() {

        @Override
        public void contentsDerived(IEntityPartViewer viewer, IBindingManager selection, IEntity result) {
            boolean canExecute = EntityUtils.safeBooleanValue(result, false);
            if (canExecute) {
                IEntity primarySelectedEntity = selection.wGet("primarySelectedEntity");
                IEntity model = EntityUtils.getCompoundRoot(primarySelectedEntity);
                bm = selection.clone();
                bm.wDefValue("debug#reportModeEnabled", false);
                BehaviorUtils.evaluate(contextModel, 0, bm);
                ITransactionScope transactionScope = BindingManagerFactory.instance.createTransactionScope();
                bm.wEnterScope(transactionScope);
                try {
                    behaviorModel = EntityUtils.mapEntity(primarySelectedEntity, EntityUtils.clone(model));
                    behaviorLabel = BehaviorUtils.apply("whole:org.whole.lang.ui.views:SamplePerspectiveSemantics#SampleViewBehaviorLabel", behaviorModel, bm).wStringValue();
                } finally {
                    transactionScope.rollback();
                    bm.wExitScope();
                }
                execute();
            } else {
                bm = null;
                behaviorModel = null;
                behaviorLabel = null;
                getViewer().setContents(null, createDefaultContents());
            }
        }
    });
    return listener;
}
Also used : ILinkableSelectionListener(org.whole.lang.e4.ui.actions.ILinkableSelectionListener) ITransactionScope(org.whole.lang.bindings.ITransactionScope) LinkViewerAdapter(org.whole.lang.e4.ui.actions.LinkViewerAdapter) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Aggregations

ITransactionScope (org.whole.lang.bindings.ITransactionScope)27 IEntity (org.whole.lang.model.IEntity)14 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)10 Execute (org.eclipse.e4.core.di.annotations.Execute)4 CommandStack (org.eclipse.gef.commands.CommandStack)4 IBindingManager (org.whole.lang.bindings.IBindingManager)4 RollbackException (org.whole.lang.lifecycle.RollbackException)4 ModelTransactionCommand (org.whole.lang.ui.commands.ModelTransactionCommand)4 OperationCanceledException (org.whole.lang.operations.OperationCanceledException)3 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)3 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)3 IWholeRuntimeException (org.whole.lang.exceptions.IWholeRuntimeException)2 InternalIEntity (org.whole.lang.model.InternalIEntity)2 IVisitor (org.whole.lang.visitors.IVisitor)2 MissingVariableException (org.whole.lang.visitors.MissingVariableException)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1