Search in sources :

Example 21 with IPersistenceKit

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();
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IFile(org.eclipse.core.resources.IFile) IEntity(org.whole.lang.model.IEntity) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) IOperationProgressMonitor(org.whole.lang.operations.IOperationProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IBindingScope(org.whole.lang.bindings.IBindingScope) IBindingManager(org.whole.lang.bindings.IBindingManager) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) OperationProgressMonitorAdapter(org.whole.lang.operations.OperationProgressMonitorAdapter) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) IOConsole(org.eclipse.ui.console.IOConsole)

Example 22 with IPersistenceKit

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;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Text(org.eclipse.swt.widgets.Text) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 23 with IPersistenceKit

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

Example 24 with IPersistenceKit

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

Example 25 with IPersistenceKit

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);
        }
    }
}
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) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

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