Search in sources :

Example 6 with IOperationProgressMonitor

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

IOperationProgressMonitor (org.whole.lang.operations.IOperationProgressMonitor)6 OperationProgressMonitorAdapter (org.whole.lang.operations.OperationProgressMonitorAdapter)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IEntity (org.whole.lang.model.IEntity)2 OperationCanceledException (org.whole.lang.operations.OperationCanceledException)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)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 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)1 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)1 IOConsole (org.eclipse.ui.console.IOConsole)1 ActionCallIterator (org.whole.lang.actions.iterators.ActionCallIterator)1