Search in sources :

Example 6 with IFilePersistenceProvider

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

the class WorkspaceArtifactsGeneratorVisitor method visitFileArtifact.

public void visitFileArtifact(FileArtifact entity) {
    env().wEnterScope();
    entity.getName().accept(this);
    if (!env().wIsSet("name"))
        throw new VisitException("No File name");
    String fileNameWithExtension = env().wStringValue("name");
    if (!ResourcesPlugin.getWorkspace().validateName(fileNameWithExtension, IResource.FILE).isOK())
        throw new VisitException("Invalid File name");
    env().wDefValue("fileNameWithExtension", fileNameWithExtension);
    env().wDefValue("fileName", StringUtils.stripFileExtension(fileNameWithExtension));
    env().wDefValue("fileExtension", StringUtils.getFileExtension(fileNameWithExtension));
    entity.getMetadata().accept(this);
    IFile file;
    if (env().wIsSet("folder")) {
        IFolder folder = (IFolder) env().wGetValue("folder");
        file = folder.getFile(fileNameWithExtension);
    } else {
        IProject project = (IProject) env().wGetValue("project");
        file = project.getFile(fileNameWithExtension);
    }
    env().wDefValue("persistenceProvider", new IFilePersistenceProvider(file, env()));
    IEntity result = InterpreterOperation.interpret(entity.getContent(), env()).getResult();
    try {
        if (result != null)
            writeContents(result);
    } catch (Exception e) {
        throw new VisitException(e);
    }
    env().wExitScope();
}
Also used : IFile(org.eclipse.core.resources.IFile) IEntity(org.whole.lang.model.IEntity) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IFolder(org.eclipse.core.resources.IFolder)

Example 7 with IFilePersistenceProvider

use of org.whole.lang.codebase.IFilePersistenceProvider 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 8 with IFilePersistenceProvider

use of org.whole.lang.codebase.IFilePersistenceProvider 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 9 with IFilePersistenceProvider

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

the class ArtifactsWorkspaceUtils method getContents.

public static IEntity getContents(FileArtifact fileArtifact, String persistenceKitId) {
    IBindingManager bindings = BindingManagerFactory.instance.createBindingManager();
    bindPath(fileArtifact, bindings, false);
    IFile file = (IFile) bindings.wGetValue("file");
    final IPersistenceProvider pp = new IFilePersistenceProvider(file);
    final Resolver resolver = CommonsEntityFactory.instance.createResolver();
    final Content fragment = CommonsEntityAdapterFactory.createStageUpFragment(ArtifactsEntityDescriptorEnum.Content, resolver);
    try {
        fragment.wSet(0, ReflectionFactory.getPersistenceKit(persistenceKitId).readModel(pp));
    } catch (Exception e) {
    }
    return fragment;
}
Also used : IFile(org.eclipse.core.resources.IFile) Resolver(org.whole.lang.commons.model.Resolver) Content(org.whole.lang.artifacts.model.Content) IBindingManager(org.whole.lang.bindings.IBindingManager) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) CoreException(org.eclipse.core.runtime.CoreException)

Example 10 with IFilePersistenceProvider

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

the class AbstractWizardWholeModelImportPage method createNewFile.

protected boolean createNewFile(IFile fileHandle) {
    IEntity model = buildModel();
    persistenceKit = getPersistenceKit(presistenceTypes);
    try {
        persistenceKit.writeModel(model, new IFilePersistenceProvider(fileHandle));
        return true;
    } catch (Exception e) {
        IEclipseContext context = (IEclipseContext) PlatformUI.getWorkbench().getService(IEclipseContext.class);
        E4Utils.reportError(context, "Write Model errors", StringUtils.errorMessage(e), e);
        return false;
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

IFilePersistenceProvider (org.whole.lang.codebase.IFilePersistenceProvider)11 IEntity (org.whole.lang.model.IEntity)8 IFile (org.eclipse.core.resources.IFile)7 CoreException (org.eclipse.core.runtime.CoreException)4 IBindingManager (org.whole.lang.bindings.IBindingManager)4 IPersistenceKit (org.whole.lang.codebase.IPersistenceKit)4 File (java.io.File)3 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)3 FilePersistenceProvider (org.whole.lang.codebase.FilePersistenceProvider)3 IPersistenceProvider (org.whole.lang.codebase.IPersistenceProvider)3 Shell (org.eclipse.swt.widgets.Shell)2 IFileEditorInput (org.eclipse.ui.IFileEditorInput)2 ModelInput (org.whole.lang.e4.ui.input.ModelInput)2 IImportAsModelDialog (org.whole.lang.ui.dialogs.IImportAsModelDialog)2 IModelInput (org.whole.lang.ui.input.IModelInput)2 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1