Search in sources :

Example 26 with IPersistenceKit

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
        }
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) IImportAsModelDialogFactory(org.whole.lang.ui.dialogs.IImportAsModelDialogFactory) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) Shell(org.eclipse.swt.widgets.Shell) IImportAsModelDialog(org.whole.lang.ui.dialogs.IImportAsModelDialog) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 27 with IPersistenceKit

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();
        }
    });
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Combo(org.eclipse.swt.widgets.Combo) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit)

Example 28 with IPersistenceKit

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)));
}
Also used : StringPersistenceProvider(org.whole.lang.codebase.StringPersistenceProvider) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit)

Example 29 with IPersistenceKit

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);
        }
    });
}
Also used : SelectionEvent(org.eclipse.swt.events.SelectionEvent) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) ILanguageKit(org.whole.lang.reflect.ILanguageKit) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 30 with IPersistenceKit

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;
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) ArrayList(java.util.ArrayList) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Combo(org.eclipse.swt.widgets.Combo) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit)

Aggregations

IPersistenceKit (org.whole.lang.codebase.IPersistenceKit)33 IEntity (org.whole.lang.model.IEntity)13 IPersistenceProvider (org.whole.lang.codebase.IPersistenceProvider)7 StringPersistenceProvider (org.whole.lang.codebase.StringPersistenceProvider)6 IOException (java.io.IOException)4 IFile (org.eclipse.core.resources.IFile)4 GridData (org.eclipse.swt.layout.GridData)4 Shell (org.eclipse.swt.widgets.Shell)4 IBindingManager (org.whole.lang.bindings.IBindingManager)4 IFilePersistenceProvider (org.whole.lang.codebase.IFilePersistenceProvider)4 IWholeRuntimeException (org.whole.lang.exceptions.IWholeRuntimeException)4 WholeIllegalArgumentException (org.whole.lang.exceptions.WholeIllegalArgumentException)4 ParseException (org.whole.lang.parsers.ParseException)4 IImportAsModelDialog (org.whole.lang.ui.dialogs.IImportAsModelDialog)4 MissingVariableException (org.whole.lang.visitors.MissingVariableException)4 VisitException (org.whole.lang.visitors.VisitException)4 ArrayList (java.util.ArrayList)3 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 Label (org.eclipse.swt.widgets.Label)3