Search in sources :

Example 1 with OperationProgressMonitorAdapter

use of org.whole.lang.operations.OperationProgressMonitorAdapter in project whole by wholeplatform.

the class WholePluginProjectWizard method performFinish.

public boolean performFinish() {
    // outside WorkspaceModifyOperation.execute() due to a concurrency bug of OSGI
    final IBindingManager params = BindingManagerFactory.instance.createArguments();
    params.wDefValue("projectName", newProjectCreationPage.getProjectName());
    params.wDefValue("pluginId", newProjectCreationPage.getPluginId());
    params.wDefValue("pluginVersion", newProjectCreationPage.getPluginVersion());
    params.wDefValue("pluginName", newProjectCreationPage.getPluginName());
    params.wDefValue("pluginProvider", newProjectCreationPage.getPluginProvider());
    if (!newProjectCreationPage.useDefaults())
        params.wDefValue("locationURI", newProjectCreationPage.getLocationURI());
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {

        protected void execute(IProgressMonitor progressMonitor) {
            try {
                progressMonitor.beginTask("Generating...", IOperationProgressMonitor.TOTAL_WORK);
                params.wDefValue("progressMonitor", new OperationProgressMonitorAdapter(progressMonitor));
                IEntity projectTemplate = ProjectsArtifactsTemplateManager.instance().create("WholePluginProject");
                projectTemplate = BehaviorUtils.evaluate(projectTemplate, 1, params);
                Matcher.removeVars(projectTemplate, false);
                ArtifactsGeneratorOperation.generate(projectTemplate, params);
            } catch (Exception exception) {
                E4CompatibilityPlugin.log(exception);
            } finally {
                progressMonitor.done();
            }
        }
    };
    try {
        getContainer().run(false, false, operation);
    } catch (Exception exception) {
        E4CompatibilityPlugin.log(exception);
        return false;
    }
    if (project != null) {
        IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
        final IWorkbenchPart activePart = page.getActivePart();
        if (activePart instanceof ISetSelectionTarget) {
            final ISelection targetSelection = new StructuredSelection(project);
            getShell().getDisplay().asyncExec(new Runnable() {

                public void run() {
                    ((ISetSelectionTarget) activePart).selectReveal(targetSelection);
                }
            });
        }
    }
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IEntity(org.whole.lang.model.IEntity) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) IBindingManager(org.whole.lang.bindings.IBindingManager) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ISetSelectionTarget(org.eclipse.ui.part.ISetSelectionTarget) OperationProgressMonitorAdapter(org.whole.lang.operations.OperationProgressMonitorAdapter)

Example 2 with OperationProgressMonitorAdapter

use of org.whole.lang.operations.OperationProgressMonitorAdapter in project whole by wholeplatform.

the class WholeProjectWizard method performFinish.

public boolean performFinish() {
    // outside WorkspaceModifyOperation.execute() due to a concurrency bug of OSGI
    final IBindingManager params = BindingManagerFactory.instance.createArguments();
    params.wDefValue("projectName", projectName);
    if (!newProjectCreationPage.useDefaults())
        params.wDefValue("locationURI", newProjectCreationPage.getLocationURI());
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {

        protected void execute(IProgressMonitor progressMonitor) {
            try {
                progressMonitor.beginTask("Generating...", IOperationProgressMonitor.TOTAL_WORK);
                params.wDefValue("progressMonitor", new OperationProgressMonitorAdapter(progressMonitor));
                IEntity projectTemplate = ProjectsArtifactsTemplateManager.instance().create("WholeProject");
                projectTemplate = BehaviorUtils.evaluate(projectTemplate, 1, params);
                Matcher.removeVars(projectTemplate, false);
                ArtifactsGeneratorOperation.generate(projectTemplate, params);
            } catch (Exception exception) {
                E4CompatibilityPlugin.log(exception);
            } finally {
                progressMonitor.done();
            }
        }
    };
    try {
        getContainer().run(false, false, operation);
    } catch (Exception exception) {
        E4CompatibilityPlugin.log(exception);
        return false;
    }
    if (project != null) {
        IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
        final IWorkbenchPart activePart = page.getActivePart();
        if (activePart instanceof ISetSelectionTarget) {
            final ISelection targetSelection = new StructuredSelection(project);
            getShell().getDisplay().asyncExec(new Runnable() {

                public void run() {
                    ((ISetSelectionTarget) activePart).selectReveal(targetSelection);
                }
            });
        }
    }
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IEntity(org.whole.lang.model.IEntity) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) IBindingManager(org.whole.lang.bindings.IBindingManager) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ISetSelectionTarget(org.eclipse.ui.part.ISetSelectionTarget) OperationProgressMonitorAdapter(org.whole.lang.operations.OperationProgressMonitorAdapter)

Example 3 with OperationProgressMonitorAdapter

use of org.whole.lang.operations.OperationProgressMonitorAdapter in project whole by wholeplatform.

the class AbstractRunnableWithProgress method run.

@Override
public void run(IProgressMonitor monitor) {
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    try {
        final IOperationProgressMonitor pm = new OperationProgressMonitorAdapter(monitor);
        bm.wDefValue("progressMonitor", pm);
        run(pm);
    } catch (Exception e) {
        E4Utils.suspendOrReportException(context, SuspensionKind.ERROR, "Model operation error", "Error while executing " + label + " operation", e, bm);
    } finally {
        monitor.done();
        if (isTransactional())
            context.get(UISynchronize.class).syncExec(() -> viewer.getEditDomain().setDisabled(false));
    }
    return;
}
Also used : OperationProgressMonitorAdapter(org.whole.lang.operations.OperationProgressMonitorAdapter) IOperationProgressMonitor(org.whole.lang.operations.IOperationProgressMonitor) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with OperationProgressMonitorAdapter

use of org.whole.lang.operations.OperationProgressMonitorAdapter in project whole by wholeplatform.

the class JavaModelGeneratorAction method generate.

public static void generate(IProgressMonitor monitor, final IEntity program, IBindingManager bm) throws InterruptedException, CoreException {
    IPackageFragmentRoot packageFragmentRoot = JDTUtils.getPackageFragmentRoot(bm.wStringValue("sourceLocationName"));
    IEclipseContext context = (IEclipseContext) bm.wGetValue("eclipse#eclipseContext");
    IWorkspace workspace = context.get(IWorkspace.class);
    IWorkspaceRunnable operation = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            monitor.beginTask("Generating...", 100);
            final IOperationProgressMonitor operationProgressMonitor = new OperationProgressMonitorAdapter(monitor);
            bm.wDefValue("progressMonitor", operationProgressMonitor);
            operationProgressMonitor.beginTask("models", 10, IOperationProgressMonitor.TOTAL_WORK);
            final List<CompilationUnit> cuList = JavaCompilerOperation.compile(program, bm);
            operationProgressMonitor.endTask();
            operationProgressMonitor.beginTask("classes", 90, cuList.size());
            if (packageFragmentRoot != null && !cuList.isEmpty()) {
                Iterator<CompilationUnit> i = new ArrayList<CompilationUnit>(cuList).iterator();
                while (i.hasNext()) {
                    try {
                        CompilationUnit cu = i.next();
                        operationProgressMonitor.beginTask(JDTUtils.getTypeName(cu), 1);
                        JDTUtils.save(cu, packageFragmentRoot, null);
                        operationProgressMonitor.endTask();
                    } catch (JavaModelException e) {
                        throw new RuntimeException(e);
                    }
                    if (operationProgressMonitor.isCanceled())
                        throw new OperationCanceledException();
                }
            }
            operationProgressMonitor.endTask();
        }
    };
    workspace.run(operation, workspace.getRoot(), IResource.NONE, monitor);
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) JavaModelException(org.eclipse.jdt.core.JavaModelException) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) IOperationProgressMonitor(org.whole.lang.operations.IOperationProgressMonitor) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspace(org.eclipse.core.resources.IWorkspace) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) OperationProgressMonitorAdapter(org.whole.lang.operations.OperationProgressMonitorAdapter)

Example 5 with OperationProgressMonitorAdapter

use of org.whole.lang.operations.OperationProgressMonitorAdapter 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)

Aggregations

OperationProgressMonitorAdapter (org.whole.lang.operations.OperationProgressMonitorAdapter)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 IBindingManager (org.whole.lang.bindings.IBindingManager)3 IEntity (org.whole.lang.model.IEntity)3 IOperationProgressMonitor (org.whole.lang.operations.IOperationProgressMonitor)3 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)2 WorkspaceModifyOperation (org.eclipse.ui.actions.WorkspaceModifyOperation)2 ISetSelectionTarget (org.eclipse.ui.part.ISetSelectionTarget)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IFile (org.eclipse.core.resources.IFile)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 CoreException (org.eclipse.core.runtime.CoreException)1 Status (org.eclipse.core.runtime.Status)1