use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.
the class WholeOperationLaunchConfigurationDelegate method launch.
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
if (!"run".equals(mode))
throw new CoreException(new Status(Status.CANCEL, PLUGIN_ID, 1, "Only 'run' mode supported by this launcher", null));
String operationId = configuration.getAttribute(OPERATION_ID, (String) null);
if (operationId == null)
throw new CoreException(new Status(Status.CANCEL, PLUGIN_ID, 1, "No operation selected", null));
String targetModelPath = configuration.getAttribute(TARGET_MODEL_PATH, (String) null);
if (targetModelPath == null)
throw new CoreException(new Status(Status.CANCEL, PLUGIN_ID, 1, "No target model selected", null));
String targetModelPersistence = configuration.getAttribute(TARGET_MODEL_PERSISTENCE, (String) null);
if (targetModelPersistence == null)
throw new CoreException(new Status(Status.CANCEL, PLUGIN_ID, 1, "No persistence selected", null));
try {
monitor.beginTask("Executing " + operationId + " operation...", 100);
if (monitor.isCanceled())
return;
IOperationProgressMonitor operationProgressMonitor = new OperationProgressMonitorAdapter(monitor);
IFile targetModelFile = ResourcesPlugin.getWorkspace().getRoot().getFile(Path.fromPortableString(targetModelPath));
IBindingManager bindings = BindingManagerFactory.instance.createBindingManager();
ResourceUtils.defineResourceBindings(bindings, targetModelFile);
IBindingScope scope = LaunchConfigurationUtils.loadBindingScope(configuration);
bindings.wEnterScope(scope, true);
IPersistenceKit persistenceKit = ReflectionFactory.getPersistenceKit(targetModelPersistence);
IEntity model = persistenceKit.readModel(new IFilePersistenceProvider(targetModelFile));
IOperationLauncher operationLauncher = OperationLauncherRegistry.instance.getOperationLauncher(operationId);
InputStream is = System.in;
OutputStream os = System.out;
if (configuration.getAttribute(CONSOLE_VIEW, false)) {
IOConsole ioConsole = WholeConsoleFactory.getIOConsole();
is = ioConsole.getInputStream();
os = ioConsole.newOutputStream();
}
operationLauncher.launch(model, bindings, is, os, operationProgressMonitor);
if (configuration.getAttribute(PERSIST_CHANGES, false))
persistenceKit.writeModel(model, new IFilePersistenceProvider(targetModelFile));
} catch (Throwable t) {
WholePlugin.log(t);
} finally {
monitor.done();
}
}
use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.
the class SaveAsModelDialog method createDialogArea.
protected Control createDialogArea(Composite parent) {
Composite parentComposite = (Composite) super.createDialogArea(parent);
// workaround to get the file name Text
Control[] children = parentComposite.getChildren();
Control c1 = children[1];
Text cText = null;
if (c1 instanceof Composite) {
children = ((Composite) c1).getChildren();
Control c2 = children[0];
if (c2 instanceof Composite) {
children = ((Composite) c2).getChildren();
Control c3 = children[1];
if (c3 instanceof Composite) {
children = ((Composite) c3).getChildren();
Control c4 = children[1];
if (c4 instanceof Text)
cText = (Text) c4;
}
}
}
final Text textControl = cText;
Composite group = new Composite(parentComposite, SWT.NONE);
group.setLayout(new GridLayout());
group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
gridLayout.marginWidth = 10;
group.setLayout(gridLayout);
new Label(group, SWT.NONE).setText("Save As:");
saveAsCombo = new ComboViewer(group, SWT.DROP_DOWN | SWT.READ_ONLY);
saveAsCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
saveAsCombo.setContentProvider(new ArrayContentProvider());
saveAsCombo.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
return ((IPersistenceKit) element).getDescription();
}
});
saveAsCombo.setSorter(new ViewerSorter());
saveAsCombo.setFilters(new ViewerFilter[] { new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
return !BeansPersistenceKit.instance().equals(element) && !DataTypePersistenceKit.instance().equals(element);
}
} });
saveAsCombo.setInput(persistenceKits);
saveAsCombo.setSelection(new StructuredSelection(getModelInput().getPersistenceKit()), true);
saveAsCombo.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
if (textControl != null) {
persistenceKit = (IPersistenceKit) ((IStructuredSelection) event.getSelection()).iterator().next();
String name = textControl.getText();
name = StringUtils.replaceExtension(name, getPersistenceKit().getFileExtension());
textControl.setText(name);
}
}
});
return parentComposite;
}
use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.
the class WholeModelWizardPage1 method fireLanguageSelected.
protected void fireLanguageSelected(ILanguageKit languageKit) {
String name = getFileName();
if (name == null || name.isEmpty())
name = "ModelExample" + exampleCount;
setFileName(StringUtils.replaceExtension(name, languageKit.getDefaultFileExtension()));
templateFactory = languageKit.getTemplateManager();
templates = templateFactory.names().toArray(new String[0]);
templateCombo.setItems(templates);
templateCombo.select(templates.length - 1);
persistenceKits = new ArrayList<IPersistenceKit>(languageKit.getPersistenceKits());
saveAsCombo.setItems(new String[0]);
for (IPersistenceKit persistenceKit : persistenceKits) saveAsCombo.add(persistenceKit.getDescription());
int selectionIndex = persistenceKits.indexOf(languageKit.getDefaultPersistenceKit());
saveAsCombo.select(selectionIndex);
}
use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.
the class ActionCallHandler method defineBindings.
protected void defineBindings(String functionUri, String predicateXwl, String analyzing, IBindingManager bm) throws Exception {
IPersistenceKit persistenceKit = ReflectionFactory.getDefaultPersistenceKit();
bm.wDefValue("analyzing", Boolean.parseBoolean(analyzing));
bm.wDefValue("functionUri", functionUri);
bm.wDef("predicateEntity", persistenceKit.readModel(new StringPersistenceProvider(predicateXwl)));
}
use of org.whole.lang.codebase.IPersistenceKit 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