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();
}
}
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();
}
});
}
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"));
}
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"));
}
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;
}
Aggregations