use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.
the class CutHandler method execute.
@Override
@Execute
public void execute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) {
if (bm.wIsSet("viewer") && ClipboardUtils.hasTextSeletion((IEntityPartViewer) bm.wGetValue("viewer"))) {
HandlersBehavior.copy(bm);
IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
IEntity focusEntity = bm.wGet("focusEntity");
ITextualEntityPart focusPart = (ITextualEntityPart) viewer.getEditPartRegistry().get(focusEntity);
Command command = focusPart.getCommand(TextualRequest.createDeleteRequest());
command.setLabel(getLabel(bm) + " text");
CommandStack commandStack = viewer.getEditDomain().getCommandStack();
commandStack.execute(command);
return;
}
super.execute(bm);
}
use of org.whole.lang.ui.viewers.IEntityPartViewer 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.viewers.IEntityPartViewer 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.viewers.IEntityPartViewer in project whole by wholeplatform.
the class HandlersBehavior method selectAll.
public static void selectAll(IBindingManager bm) {
E4Utils.syncExec(bm, () -> {
IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
IEntity entityContents = viewer.getEntityContents();
IEntityPart contents = viewer.getEditPartRegistry().get(entityContents);
viewer.setSelection(new StructuredSelection(contents));
});
}
use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.
the class HandlersBehavior method pasteAs.
public static void pasteAs(IBindingManager bm) {
IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
IEntity focusEntity = bm.wGet("focusEntity");
RunnableWithResult<IImportAsModelDialog> dialogRunnable = RunnableWithResult.create(() -> {
Shell shell = viewer.getControl().getShell();
IEclipseContext eclipseContext = (IEclipseContext) bm.wGetValue("eclipse#eclipseContext");
IImportAsModelDialog dialog = eclipseContext.get(IImportAsModelDialogFactory.class).createImplicitElementImportAsModelDialog(shell, "Paste As", EntityUtils.isComposite(focusEntity));
dialog.show();
return dialog;
});
IImportAsModelDialog dialog = E4Utils.syncExec(bm, dialogRunnable).get();
if (!dialog.isConfirmed())
return;
IPersistenceKit persistenceKit = dialog.getPersistenceKit();
RunnableWithResult<IEntity> entityRunnable = RunnableWithResult.create(() -> {
try {
return ClipboardUtils.parseClipboardContents(persistenceKit, bm);
} catch (Exception e) {
IEclipseContext context = (IEclipseContext) bm.wGetValue("eclipse#eclipseContext");
E4Utils.reportError(context, "Write Model errors", "Parse failed using the selected persistence.", e);
return CommonsEntityFactory.instance.createResolver();
}
});
IEntity entity = E4Utils.syncExec(bm, entityRunnable).get();
boolean adding = dialog.isForceAdding();
IEntityIterator<IEntity> iterator;
if (bm.wIsSet("syntheticRoot")) {
IEntity syntheticRoot = bm.wGet("syntheticRoot");
adding |= syntheticRoot.wSize() > 1;
if (adding && !EntityUtils.isComposite(focusEntity)) {
adding = false;
iterator = IteratorFactory.selfIterator();
} else
iterator = IteratorFactory.childReverseIterator();
iterator.reset(syntheticRoot);
} else {
iterator = IteratorFactory.selfIterator();
iterator.reset(entity);
}
EntityDescriptor<?> stage = dialog.getStage();
while (iterator.hasNext()) {
IEntity clipboardEntity = EntityUtils.clone(iterator.next());
if (!adding) {
if (!CommonsEntityDescriptorEnum.SameStageFragment.equals(stage) || !EntityUtils.isReplaceable(focusEntity, clipboardEntity))
clipboardEntity = CommonsEntityFactory.instance.create(stage, clipboardEntity);
IEntity parent = focusEntity.wGetParent();
parent.wSet(focusEntity, clipboardEntity);
break;
} else {
if (!CommonsEntityDescriptorEnum.SameStageFragment.equals(stage) || !EntityUtils.isAddable(focusEntity, clipboardEntity))
clipboardEntity = CommonsEntityFactory.instance.create(stage, clipboardEntity);
if (bm.wIsSet("hilightPosition"))
focusEntity.wAdd(bm.wIntValue("hilightPosition"), clipboardEntity);
else
focusEntity.wAdd(clipboardEntity);
}
}
}
Aggregations