use of org.whole.lang.ui.commands.ModelTransactionCommand in project whole by wholeplatform.
the class InterpretModelRunnable 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("Interpreting...", IOperationProgressMonitor.TOTAL_WORK);
try {
mtc.begin();
HandlersBehavior.interpretModel(bm);
mtc.commit();
if (mtc.canUndo())
commandStack.execute(mtc);
} catch (OperationCanceledException e) {
mtc.rollbackIfNeeded();
} catch (RuntimeException e) {
mtc.rollbackIfNeeded();
throw e;
} finally {
pm.endTask();
}
}
use of org.whole.lang.ui.commands.ModelTransactionCommand in project whole by wholeplatform.
the class MergeResourcesAction method run.
@Override
public void run() {
ESelectionService selectionService = getContext().get(ESelectionService.class);
IBindingManager bm = (IBindingManager) selectionService.getSelection();
IEntity focusEntity = bm.wGet("focusEntity");
Shell shell = (Shell) getContext().get(IServiceConstants.ACTIVE_SHELL);
IEntity result = performWorkspaceResourceSelection(shell, focusEntity);
if (!EntityUtils.isNull(result)) {
ModelTransactionCommand mtc = new ModelTransactionCommand(focusEntity);
try {
mtc.setLabel("add Artifacts");
mtc.begin();
EntityUtils.merge(focusEntity, result, createEntityComparator(), false);
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 ReplaceWithClassNameAction method run.
@Override
public void run() {
Shell shell = (Shell) getContext().get(IServiceConstants.ACTIVE_SHELL);
FilteredItemsSelectionDialog dialog = new OpenTypeSelectionDialog(shell, true, PlatformUI.getWorkbench().getProgressService(), null, IJavaSearchConstants.TYPE);
dialog.setTitle("Select a class");
dialog.setMessage("Choose a class or a compilation unit");
dialog.setInitialPattern(StringUtils.toSimpleName(className));
if (dialog.open() != IDialogConstants.OK_ID)
return;
IType primaryType = (IType) dialog.getResult()[0];
if (primaryType == null)
return;
className = primaryType.getFullyQualifiedName();
ESelectionService selectionService = getContext().get(ESelectionService.class);
IBindingManager bm = (IBindingManager) selectionService.getSelection();
IEntity focusEntity = bm.wGet("focusEntity");
IEntity replacement = GenericEntityFactory.instance.create(ed, className);
ModelTransactionCommand mtc = new ModelTransactionCommand(focusEntity);
try {
mtc.setLabel("replace with class name");
mtc.begin();
focusEntity.wGetParent().wSet(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 EnvironmentPart method createFigure.
protected IFigure createFigure() {
Environment entity = getModelEntity();
return new EnvironmentFigure(new ActionListener() {
public void actionPerformed(ActionEvent event) {
Environment entity = getModelEntity();
ModelTransactionCommand command = new ModelTransactionCommand(entity);
try {
command.begin();
IBindingManager bm = entity.getBindingManager().getValue();
if (Matcher.match(EnvironmentEntityDescriptorEnum.Bindings, entity.getBindings()))
entity.setBindings((BindingsModel) BindingManagerFactory.instance.createFlatScopedBindingsModel(bm));
else
entity.setBindings((BindingsModel) BindingManagerFactory.instance.createFlatBindingsModel(bm));
command.commit();
getViewer().getEditDomain().getCommandStack().execute(command);
} catch (Exception e) {
command.rollbackIfNeeded();
}
}
}, Matcher.matchImpl(EnvironmentEntityDescriptorEnum.ScopedBindings, entity.getBindings()));
}
Aggregations