use of org.whole.lang.codebase.IPersistenceKit 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.codebase.IPersistenceKit in project whole by wholeplatform.
the class OpenAsModelDialog method addPersistenceCombo.
protected void addPersistenceCombo(Composite group, String label) {
new Label(group, SWT.NONE).setText(label);
persistenceCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY);
persistenceCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
persistenceKits = new ArrayList<IPersistenceKit>(ReflectionFactory.getPersistenceKits());
Iterator<IPersistenceKit> i = persistenceKits.iterator();
persistenceCombo.setItems(new String[0]);
while (i.hasNext()) {
IPersistenceKit persistenceKit = i.next();
persistenceCombo.add(persistenceKit.getDescription());
}
persistenceCombo.select(persistenceKits.indexOf(persistenceKit));
persistenceCombo.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
persistenceKit = persistenceKits.get(persistenceCombo.getSelectionIndex());
updateOKStatus();
}
});
}
use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.
the class FragmentModelTransactionHandler method defineBindings.
protected void defineBindings(String fragmentXwl, String predicateXwl, IBindingManager bm) throws Exception {
IPersistenceKit persistenceKit = ReflectionFactory.getDefaultPersistenceKit();
bm.wDef("fragmentEntity", persistenceKit.readModel(new StringPersistenceProvider(fragmentXwl)));
bm.wDef("predicateEntity", persistenceKit.readModel(new StringPersistenceProvider(predicateXwl)));
}
use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.
the class AbstractWizardWholeModelImportPage method initOptionsGroup.
private void initOptionsGroup() {
ILanguageKit languageKit = ReflectionFactory.getLanguageKit(PojoLanguageKit.URI, false, null);
setFilename("ModelExample" + filenameCount + "." + languageKit.getDefaultFileExtension());
persistenceKits = new ArrayList<IPersistenceKit>(languageKit.getPersistenceKits());
Iterator<IPersistenceKit> iterator = persistenceKits.iterator();
presistenceTypes.setItems(new String[0]);
while (iterator.hasNext()) presistenceTypes.add(iterator.next().getDescription());
int selectionIndex = persistenceKits.indexOf(languageKit.getDefaultPersistenceKit());
presistenceTypes.select(selectionIndex);
presistenceTypes.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
String name = getFilename();
name = StringUtils.replaceExtension(name, getPersistenceKit(presistenceTypes).getFileExtension());
setFilename(name);
}
});
}
use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.
the class AbstractImportAsModelDialogFactory method addPersistenceCombo.
public Combo addPersistenceCombo(final IImportAsModelDialog dialog, Composite group, String label) {
new Label(group, SWT.NONE).setText(label);
final Combo persistenceCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY);
persistenceCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
final List<IPersistenceKit> persistenceKits = new ArrayList<IPersistenceKit>(ReflectionFactory.getPersistenceKits());
Iterator<IPersistenceKit> i = persistenceKits.iterator();
persistenceCombo.setItems(new String[0]);
while (i.hasNext()) persistenceCombo.add(i.next().getDescription());
persistenceCombo.select(persistenceKits.indexOf(dialog.getPersistenceKit()));
persistenceCombo.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
IPersistenceKit persistenceKit = persistenceKits.get(persistenceCombo.getSelectionIndex());
dialog.setPersistenceKit(persistenceKit);
dialog.validate();
}
});
return persistenceCombo;
}
Aggregations