Search in sources :

Example 31 with IPersistenceKit

use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.

the class WorkflowsIDEContentAssistVisitor method chooseResource.

protected boolean chooseResource(IEntity entity) {
    Object customAction = null;
    if (WorkflowsUtils.isResourceInPersistenceActivity(entity)) {
        PersistenceActivity parent = (PersistenceActivity) entity.wGetParent();
        Expression expression = parent.getPersistence();
        IPersistenceKit persistenceKit = Matcher.match(WorkflowsEntityDescriptorEnum.StringLiteral, expression) ? (ReflectionFactory.hasPersistenceKit(expression.wStringValue()) ? ReflectionFactory.getPersistenceKit(expression.wStringValue()) : null) : ReflectionFactory.getDefaultPersistenceKit();
        customAction = new ReplaceWithResourceAndPersistenceAction((IEclipseContext) getBindings().wGetValue("eclipse#eclipseContext"), WorkflowsEntityDescriptorEnum.StringLiteral, entity.wStringValue(), persistenceKit, "Select resource...") {

            protected boolean isLoading(IEntity entity) {
                return Matcher.match(WorkflowsEntityDescriptorEnum.LoadModel, entity.wGetParent());
            }

            protected ResourceKind getResourceKind(IEntity selectedEntity) {
                switch(selectedEntity.wGetParent().wGet(WorkflowsFeatureDescriptorEnum.resourceKind).wEnumValue().getOrdinal()) {
                    default:
                    case ResourceKindEnum.WORKSPACE_ord:
                        return ResourceKind.WORKSPACE;
                    case ResourceKindEnum.FILE_SYSTEM_ord:
                        return ResourceKind.FILE_SYSTEM;
                    case ResourceKindEnum.CLASSPATH_ord:
                        return ResourceKind.CLASSPATH;
                    case ResourceKindEnum.URL_ord:
                        return ResourceKind.URL;
                }
            }

            protected void performReplacePersistence(IEntity parent) {
                ((PersistenceActivity) parent).setPersistence(WorkflowsEntityFactory.instance.createStringLiteral(persistenceKit.getId()));
            }
        };
    } else if (WorkflowsUtils.isResourceInArtifactsActivity(entity)) {
        customAction = new ReplaceWithResourceAction((IEclipseContext) getBindings().wGetValue("eclipse#eclipseContext"), WorkflowsEntityDescriptorEnum.StringLiteral, entity.wStringValue(), "Select resource...") {

            protected boolean isLoading(IEntity entity) {
                return Matcher.match(WorkflowsEntityDescriptorEnum.LoadArtifacts, entity.wGetParent());
            }

            protected ResourceKind getResourceKind(IEntity selectedEntity) {
                switch(selectedEntity.wGetParent().wGet(WorkflowsFeatureDescriptorEnum.rootResourceKind).wEnumValue().getOrdinal()) {
                    default:
                    case ResourceKindEnum.WORKSPACE_ord:
                        return ResourceKind.WORKSPACE;
                    case ResourceKindEnum.FILE_SYSTEM_ord:
                        return ResourceKind.FILE_SYSTEM;
                    case ResourceKindEnum.CLASSPATH_ord:
                        return ResourceKind.CLASSPATH;
                    case ResourceKindEnum.URL_ord:
                        return ResourceKind.URL;
                }
            }
        };
    } else
        return false;
    ActionsEntityFactory aef = ActionsEntityFactory.instance;
    GroupAction customGroup = aef.createGroupAction();
    customGroup.setFillStrategy(aef.createFlat());
    customGroup.getText().setValue("workflows.custom");
    customGroup.setActions(aef.createActions(aef.createCustomAction(customAction)));
    return EntityUtils.isResolver(entity) ? mergeResult(StringLiteral, customGroup) : mergeResult(customGroup);
}
Also used : ReplaceWithResourceAction(org.whole.lang.ui.actions.ReplaceWithResourceAction) GroupAction(org.whole.lang.actions.model.GroupAction) PersistenceActivity(org.whole.lang.workflows.model.PersistenceActivity) ReplaceWithResourceAndPersistenceAction(org.whole.lang.ui.actions.ReplaceWithResourceAndPersistenceAction) Expression(org.whole.lang.workflows.model.Expression) IEntity(org.whole.lang.model.IEntity) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) ActionsEntityFactory(org.whole.lang.actions.factories.ActionsEntityFactory)

Example 32 with IPersistenceKit

use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.

the class TextTransferDropTargetListener method getCommand.

@Override
protected Command getCommand() {
    String text = (String) getCurrentEvent().data;
    Shell shell = getViewer().getControl().getShell();
    IImportAsModelDialog dialog = factory.createImplicitElementImportAsModelDialog(shell, "Drop As", false);
    if (!dialog.show())
        return null;
    IPersistenceKit persistenceKit = dialog.getPersistenceKit();
    EntityDescriptor<?> stage = dialog.getStage();
    try {
        IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
        bm.wDefValue("parseFragments", true);
        IEntity entity = persistenceKit.readModel(new StringPersistenceProvider(text, bm));
        // FIXME workaround for selections with multiple entities
        if (EntityUtils.isTuple(entity))
            bm.wDef("syntheticRoot", entity);
        boolean hasSyntheticRoot = bm.wIsSet("syntheticRoot");
        IEntityIterator<IEntity> iterator;
        boolean needsCompositeTarget = false;
        if (hasSyntheticRoot) {
            IEntity syntheticRoot = bm.wGet("syntheticRoot");
            iterator = IteratorFactory.childIterator();
            iterator.reset(syntheticRoot);
            needsCompositeTarget = syntheticRoot.wSize() > 1;
        } else {
            iterator = IteratorFactory.selfIterator();
            iterator.reset(entity);
        }
        List<IEntityPart> editParts = new ArrayList<IEntityPart>();
        while (iterator.hasNext()) {
            IEntity stageEntity = EntityUtils.clone(iterator.next());
            stageEntity = ClipboardUtils.conditionalStageAdd(getTargetEditPart(), stage, stageEntity, needsCompositeTarget);
            editParts.add(ClipboardUtils.createEditPart(getViewer().getEditPartFactory(), stageEntity));
        }
        ChangeBoundsRequest request = (ChangeBoundsRequest) getTargetRequest();
        request.setEditParts(editParts);
        return super.getCommand();
    } catch (Exception e) {
        return null;
    }
}
Also used : StringPersistenceProvider(org.whole.lang.codebase.StringPersistenceProvider) IEntity(org.whole.lang.model.IEntity) ArrayList(java.util.ArrayList) ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) Shell(org.eclipse.swt.widgets.Shell) IImportAsModelDialog(org.whole.lang.ui.dialogs.IImportAsModelDialog) IBindingManager(org.whole.lang.bindings.IBindingManager) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Example 33 with IPersistenceKit

use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.

the class FileTransferDropTargetListener method getCommand.

@Override
protected Command getCommand() {
    String[] filePaths = (String[]) getCurrentEvent().data;
    List<EditPart> editParts = new ArrayList<EditPart>();
    Shell shell = getViewer().getControl().getShell();
    IImportAsModelDialog dialog = factory.createElementListImportAsModelDialog(shell, "DnD Import", false);
    String[] fileNames = new String[filePaths.length];
    for (int i = 0; i < fileNames.length; i++) fileNames[i] = filePaths[i].substring(filePaths[i].lastIndexOf(File.separatorChar) + 1);
    dialog.setSelection(fileNames);
    if (!dialog.show())
        return null;
    IPersistenceKit persistenceKit = dialog.getPersistenceKit();
    EntityDescriptor<?> stage = dialog.getStage();
    boolean needsCompositeTarget = filePaths.length > 1;
    for (String filePath : filePaths) {
        try {
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            File file = new File(filePath);
            IFile[] files = workspace.getRoot().findFilesForLocationURI(file.toURI());
            IPersistenceProvider persistenceProvider = (files.length == 1) ? new IFilePersistenceProvider(files[0]) : new FilePersistenceProvider(file);
            IEntity entity = persistenceKit.readModel(persistenceProvider);
            entity = ClipboardUtils.conditionalStageAdd(getTargetEditPart(), stage, entity, needsCompositeTarget);
            editParts.add(ClipboardUtils.createEditPart(getViewer().getEditPartFactory(), entity));
        } catch (Exception e) {
        // fail silently
        }
    }
    if (!editParts.isEmpty()) {
        ChangeBoundsRequest request = (ChangeBoundsRequest) getTargetRequest();
        request.setEditParts(editParts);
    } else
        return null;
    return super.getCommand();
}
Also used : IFile(org.eclipse.core.resources.IFile) IEntity(org.whole.lang.model.IEntity) EditPart(org.eclipse.gef.EditPart) ArrayList(java.util.ArrayList) ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) Shell(org.eclipse.swt.widgets.Shell) IImportAsModelDialog(org.whole.lang.ui.dialogs.IImportAsModelDialog) FilePersistenceProvider(org.whole.lang.codebase.FilePersistenceProvider) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) IWorkspace(org.eclipse.core.resources.IWorkspace) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

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