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