use of org.whole.lang.ui.commands.ModelTransactionCommand in project whole by wholeplatform.
the class DataEntityDirectEditPolicy method getDirectEditCommand.
protected Command getDirectEditCommand(IEntity hostEntity, String value, IDataTypeParser parser) {
ModelTransactionCommand command = new ModelTransactionCommand(hostEntity);
try {
command.begin();
hostEntity.wSetValue(parser.parse(hostEntity.wGetEntityDescriptor(), value));
command.commit();
return command;
} catch (Exception e) {
command.rollbackIfNeeded();
return UnexecutableCommand.INSTANCE;
}
}
use of org.whole.lang.ui.commands.ModelTransactionCommand in project whole by wholeplatform.
the class TreeDirectEditPolicy method getDirectEditCommand.
private Command getDirectEditCommand(TreeDirectEditRequest request) {
IEntity entity = getTreeEntityPart().getModelEntity();
ModelTransactionCommand mtc = new ModelTransactionCommand(entity);
try {
mtc.setLabel("edit");
mtc.begin();
DataTypeUtils.setFromPersistenceString(entity, request.getValue());
mtc.commit();
if (mtc.canUndo())
getTreeEntityPart().getViewer().getEditDomain().getCommandStack().execute(mtc);
} catch (RuntimeException e) {
mtc.rollbackIfNeeded();
} finally {
}
return null;
}
use of org.whole.lang.ui.commands.ModelTransactionCommand in project whole by wholeplatform.
the class E4FindReplaceDialog method doReplace.
protected void doReplace(boolean updateSelection) {
if (!hasFoundEntity())
return;
final RootFragment replacementWrapper = CommonsEntityFactory.instance.createRootFragment(EntityUtils.clone(replaceViewer.getEntityContents()).wGetAdapter(CommonsEntityDescriptorEnum.Any));
Matcher.substitute(replacementWrapper.getRootEntity(), bindings, false);
ModelTransactionCommand command = new ModelTransactionCommand();
try {
command.setModel(getFoundEntity());
command.begin();
iterator.set(EntityUtils.remove(replacementWrapper.getRootEntity()));
command.commit();
} catch (Exception e) {
command.rollbackIfNeeded();
} finally {
clearFoundEntity();
}
IEntityPartViewer viewer = (IEntityPartViewer) selection.wGetValue("viewer");
viewer.getCommandStack().execute(command);
if (updateSelection) {
Control control = viewer.getControl();
control.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
boolean state = enableSelectionTracking(false);
selectAndReveal(replacementWrapper);
enableSelectionTracking(state);
}
});
}
}
use of org.whole.lang.ui.commands.ModelTransactionCommand 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.ui.commands.ModelTransactionCommand in project whole by wholeplatform.
the class ActionCallRunnable method run.
@Override
public void run(IOperationProgressMonitor pm) throws InvocationTargetException {
IEntity model = bm.wGet("self");
boolean analyzing = bm.wBooleanValue("analyzing");
if (analyzing) {
// clone model if is analyzing
model = EntityUtils.clone(model);
CommonsEntityFactory.instance.createRootFragment(model.wGetAdapter(CommonsEntityDescriptorEnum.Any));
ReflectionFactory.getHistoryManager(model).setHistoryEnabled(true);
// map selected entities if analyzing
IEntity tuple = bm.wGet("selectedEntities");
int size = tuple.wSize();
for (int i = 0; i < size; i++) tuple.wSet(i, EntityUtils.mapEntity(tuple.wGet(i), model));
bm.wSet("primarySelectedEntity", EntityUtils.mapEntity(bm.wGet("primarySelectedEntity"), model));
bm.wSet("focusEntity", EntityUtils.mapEntity(bm.wGet("focusEntity"), model));
}
IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
final CommandStack commandStack = viewer.getEditDomain().getCommandStack();
final ModelTransactionCommand mtc = new ModelTransactionCommand(model, label);
pm.beginTask("executing action", 90, IOperationProgressMonitor.TOTAL_WORK);
try {
mtc.begin();
HandlersBehavior.actionCall(bm);
mtc.commit();
if (analyzing) {
E4Utils.revealPart(context, RESULTS_PART_ID);
IEventBroker eventBroker = context.get(IEventBroker.class);
eventBroker.post(IE4UIConstants.TOPIC_UPDATE_RESULTS, bm.getResult());
} else if (mtc.canUndo()) {
context.get(UISynchronize.class).syncExec(new Runnable() {
public void run() {
commandStack.execute(mtc);
}
});
}
} catch (OperationCanceledException e) {
mtc.rollbackIfNeeded();
} catch (RuntimeException e) {
mtc.rollbackIfNeeded();
throw e;
} finally {
pm.endTask();
}
}
Aggregations