use of org.whole.lang.ui.commands.ModelTransactionCommand in project whole by wholeplatform.
the class ReplaceWithResourceAction method run.
@Override
public void run() {
ESelectionService selectionService = getContext().get(ESelectionService.class);
IBindingManager bm = (IBindingManager) selectionService.getSelection();
IEntity focusEntity = bm.wGet("focusEntity");
ResourceKind resourceKind = getResourceKind(focusEntity);
Shell shell = (Shell) getContext().get(IServiceConstants.ACTIVE_SHELL);
boolean selectionPerformed = false;
switch(resourceKind) {
case WORKSPACE:
selectionPerformed = performWorkspaceResourceSelection(shell, focusEntity);
break;
case CLASSPATH:
selectionPerformed = performClasspathResourceSelection(shell, focusEntity);
break;
case FILE_SYSTEM:
case URL:
selectionPerformed = performFilesystemSelection(shell, focusEntity, resourceKind == ResourceKind.URL);
break;
}
if (!selectionPerformed)
return;
IEntity replacement = GenericEntityFactory.instance.create(ed, path);
ModelTransactionCommand mtc = new ModelTransactionCommand(focusEntity);
try {
mtc.setLabel("replace with class name");
mtc.begin();
performReplace(focusEntity, replacement);
mtc.commit();
if (mtc.canUndo()) {
IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
CommandStack commandStack = viewer.getEditDomain().getCommandStack();
commandStack.execute(mtc);
}
} catch (RuntimeException e) {
mtc.rollbackIfNeeded();
throw e;
}
}
use of org.whole.lang.ui.commands.ModelTransactionCommand in project whole by wholeplatform.
the class HistoryCommandStack method toModelTransactionCommand.
protected ModelTransactionCommand toModelTransactionCommand(Command command) {
ModelTransactionCommand mtCommand = new ModelTransactionCommand();
try {
mtCommand.setModel(getModel());
mtCommand.setLabel(command.getLabel());
mtCommand.begin();
command.execute();
mtCommand.commit();
return mtCommand;
} catch (Exception e) {
mtCommand.rollbackIfNeeded();
}
return mtCommand;
}
use of org.whole.lang.ui.commands.ModelTransactionCommand in project whole by wholeplatform.
the class E4FindReplaceDialog method doReplaceAll.
protected void doReplaceAll() {
IEntity self = selection.wGet("self");
iterator.reset(self);
if (!findNext(true))
return;
boolean state = enableSelectionTracking(false);
IEntity replacement = replaceViewer.getEntityContents();
IEntity lastReplaced = null;
ModelTransactionCommand command = new ModelTransactionCommand();
command.setModel(getFoundEntity());
try {
command.begin();
do {
lastReplaced = EntityUtils.clone(replacement);
Matcher.substitute(lastReplaced, bindings, false);
iterator.set(lastReplaced);
} while (findNext(true));
command.commit();
} catch (Exception e) {
command.rollbackIfNeeded();
} finally {
clearFoundEntity();
}
IEntityPartViewer viewer = (IEntityPartViewer) selection.wGetValue("viewer");
viewer.getCommandStack().execute(command);
Control control = viewer.getControl();
if (lastReplaced != null) {
final IEntity revealEntity = lastReplaced;
control.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
boolean state = enableSelectionTracking(false);
selectAndReveal(revealEntity);
enableSelectionTracking(state);
}
});
}
enableSelectionTracking(state);
}
use of org.whole.lang.ui.commands.ModelTransactionCommand in project whole by wholeplatform.
the class FragmentModelTransactionHandler method execute.
@Execute
public void execute(@Named(FRAGMENT_XWL_PARAMETER_ID) String fragmentXwl, @Named(PREDICATE_XWL_PARAMETER_ID) String predicateXwl, @Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm, IEntityPartViewer viewer) throws Exception {
CommandStack commandStack = viewer.getEditDomain().getCommandStack();
ModelTransactionCommand mtc = new ModelTransactionCommand(bm.wGet("focusEntity"));
ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
try {
bm.wEnterScope(ts);
defineBindings(fragmentXwl, predicateXwl, bm);
mtc.setLabel(getLabel(bm));
mtc.begin();
run(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 NormalizeModelRunnable 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);
pm.beginTask("Normalizing...", IOperationProgressMonitor.TOTAL_WORK);
try {
mtc.begin();
HandlersBehavior.normalizeModel(bm);
mtc.commit();
if (mtc.canUndo())
commandStack.execute(mtc);
} catch (OperationCanceledException e) {
mtc.rollbackIfNeeded();
} catch (RuntimeException e) {
mtc.rollbackIfNeeded();
throw e;
} finally {
pm.endTask();
}
}
Aggregations