use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.
the class HandlersBehavior method copyAsImage.
public static void copyAsImage(IBindingManager bm) {
E4Utils.syncExec(bm, () -> {
IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
IEntity focusEntity = bm.wGet("focusEntity");
IEntityPart part = viewer.getEditPartRegistry().get(focusEntity);
String fileName = bm.wIsSet("fileName") ? bm.wStringValue("fileName") : ClipboardUtils.DEFAULT_OUTPUT_FILENAME;
Clipboard.instance().setImageContents(fileName, (IGraphicalEntityPart) part);
});
}
use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.
the class HandlersBehavior method importEntity.
public static void importEntity(IBindingManager bm) {
IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
IEntity focusEntity = bm.wGet("focusEntity");
RunnableWithResult<IImportAsModelDialog> runnable = RunnableWithResult.create(() -> {
Shell shell = viewer.getControl().getShell();
IEclipseContext eclipseContext = (IEclipseContext) bm.wGetValue("eclipse#eclipseContext");
IImportAsModelDialog dialog = eclipseContext.get(IImportAsModelDialogFactory.class).createImportAsModelDialog(shell, "Import model", EntityUtils.isComposite(focusEntity));
dialog.show();
return dialog;
});
E4Utils.syncExec(bm, runnable);
IImportAsModelDialog dialog = runnable.get();
if (!dialog.isConfirmed())
return;
Object[] files = dialog.getSelection();
IPersistenceKit persistenceKit = dialog.getPersistenceKit();
EntityDescriptor<?> stage = dialog.getStage();
boolean adding = dialog.isForceAdding() || files.length > 1;
for (int i = files.length - 1; i >= 0; i--) {
IPersistenceProvider pp = new IFilePersistenceProvider((IFile) files[i]);
try {
IEntity importedEntity = persistenceKit.readModel(pp);
if (!adding) {
if (!CommonsEntityDescriptorEnum.SameStageFragment.equals(stage) || !EntityUtils.isReplaceable(focusEntity, importedEntity))
importedEntity = CommonsEntityFactory.instance.create(stage, importedEntity);
IEntity parent = focusEntity.wGetParent();
parent.wSet(focusEntity, importedEntity);
break;
} else {
if (!CommonsEntityDescriptorEnum.SameStageFragment.equals(stage) || !EntityUtils.isAddable(focusEntity, importedEntity))
importedEntity = CommonsEntityFactory.instance.create(stage, importedEntity);
if (bm.wIsSet("hilightPosition"))
focusEntity.wAdd(bm.wIntValue("hilightPosition"), importedEntity);
else
focusEntity.wAdd(importedEntity);
}
} catch (Exception e) {
// fail silently
}
}
}
use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.
the class ClearContentsAction method run.
@Override
public void run() {
IEntityPartViewer viewer = getContext().get(IEntityPartViewer.class);
viewer.setContents(null, createDefaultContents());
update();
}
use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.
the class ClearContentsAction method update.
@Override
public void update() {
IEntityPartViewer viewer = getContext().get(IEntityPartViewer.class);
setEnabled(viewer.hasContents());
}
use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.
the class AbstractModelTextAction method calculateEnabled.
protected boolean calculateEnabled(IBindingManager bm) {
IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
if (!Tools.TEXTUAL.isActive(viewer) || !(ModelObserver.getObserver(bm.wGet("focusEntity"), viewer.getEditPartRegistry()) instanceof ITextualEntityPart))
return false;
IEclipseContext context = (IEclipseContext) bm.wGetValue("eclipse#eclipseContext");
ISynchronizableRunnable runnable = new FunctionRunnable(context, bm, getText(), getEnablementUri());
IEntity result = runnable.syncExec(3000).getResult();
return result != null && result.wBooleanValue();
}
Aggregations