Search in sources :

Example 6 with OperationCanceledException

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

the class DeriveModelRunnable method run.

@Override
public void run(IOperationProgressMonitor pm) throws InvocationTargetException, InterruptedException {
    pm.beginTask("Deriving...", IOperationProgressMonitor.TOTAL_WORK);
    try {
        bm.wEnterScope();
        bm.wDefValue("debug#reportModeEnabled", false);
        final IEntity result = BehaviorUtils.apply(functionUri, bm.wGet("self"), bm);
        UISynchronize synchronize = context.get(UISynchronize.class);
        if (synchronize == null)
            return;
        synchronize.asyncExec(new Runnable() {

            public void run() {
                updateUI(result);
            }
        });
    } catch (OperationCanceledException e) {
    // gracefully terminate execution
    } finally {
        bm.wExitScope();
        pm.endTask();
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) UISynchronize(org.eclipse.e4.ui.di.UISynchronize)

Example 7 with OperationCanceledException

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

the class ExecuteSampleModelRunnable method run.

@Override
public void run(IOperationProgressMonitor pm) throws InvocationTargetException, InterruptedException {
    IEntity selfEntity = EntityUtils.mapEntity(selfModel, EntityUtils.clone(EntityUtils.getCompoundRoot(selfModel)));
    Set<String> initialNames = bm.wNames();
    pm.beginTask("Executing sample...", IOperationProgressMonitor.TOTAL_WORK);
    behaviorModel = BehaviorUtils.apply("whole:org.whole.lang.ui.views:SamplePerspectiveSemantics#SampleViewBehavior", behaviorModel, bm);
    IEntity derivedModel = null;
    try {
        IEntityIterator<?> iterator = BehaviorUtils.lazyEvaluate(behaviorModel, 0, bm);
        iterator.setBindings(selfBindings);
        iterator.reset(selfEntity);
        if (iterator.getClass().equals(ConstantIterator.class)) {
            IEntity result = iterator.next();
            if (result == null || !EntityUtils.isData(result))
                derivedModel = result;
            else {
                Object resultValue = result.wGetValue();
                derivedModel = IVisitor.class.isInstance(resultValue) ? BindingManagerFactory.instance.createValue(Matcher.match((IVisitor) resultValue, selfEntity)) : result;
            }
        } else if (iterator.hasNext()) {
            derivedModel = MiscEntityFactory.instance.createMisc(0);
            ITransactionScope transactionScope = BindingManagerFactory.instance.createTransactionScope();
            bm.wEnterScope(transactionScope);
            try {
                for (IEntity result : iterator) {
                    transactionScope.commit();
                    derivedModel.wAdd(GenericEntityFactory.instance.create(CommonsEntityDescriptorEnum.SameStageFragment, // CommonsEntityFactory.instance.createSameStageFragment(
                    EntityUtils.clone(// TODO substitute with a no containment fragment
                    result)));
                }
            } finally {
                transactionScope.rollback();
                bm.wExitScope();
            }
        }
    } catch (MissingVariableException e) {
        addMissingVariables(contextModel, e);
    } catch (OperationCanceledException e) {
    // gracefully terminate execution
    } catch (Exception e) {
        if (e.getCause() instanceof MissingVariableException)
            addMissingVariables(contextModel, (MissingVariableException) e.getCause());
    } finally {
        pm.endTask();
    }
    IEntity variablesModel = null;
    if (derivedModel != null) {
        EnvironmentEntityFactory ef = EnvironmentEntityFactory.instance;
        variablesModel = ef.createBindings(0);
        for (String name : new TreeSet<String>(bm.wLocalNames())) if (!initialNames.contains(name))
            variablesModel.wAdd(ef.createBinding(ef.createName(name), ef.createValue(BindingUtils.wGet(bm, name))));
        final IEntity contents = derivedModel;
        final IEntity variables = variablesModel;
        context.get(UISynchronize.class).asyncExec(new Runnable() {

            public void run() {
                context.get(IEntityPartViewer.class).setContents(null, contents);
                context.get(IEventBroker.class).post(IE4UIConstants.TOPIC_UPDATE_VARIABLES, variables);
            }
        });
    }
}
Also used : ITransactionScope(org.whole.lang.bindings.ITransactionScope) IEntity(org.whole.lang.model.IEntity) IVisitor(org.whole.lang.visitors.IVisitor) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) EnvironmentEntityFactory(org.whole.lang.environment.factories.EnvironmentEntityFactory) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MissingVariableException(org.whole.lang.visitors.MissingVariableException) MissingVariableException(org.whole.lang.visitors.MissingVariableException) TreeSet(java.util.TreeSet) UISynchronize(org.eclipse.e4.ui.di.UISynchronize)

Example 8 with OperationCanceledException

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

the class FunctionRunnable method run.

@Override
public void run(IOperationProgressMonitor pm) throws InvocationTargetException, InterruptedException {
    // FIXME workaround for missing caret update events (no selection update is performed)
    E4Utils.defineCaretBindings(bm);
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    CommandStack commandStack = viewer.getEditDomain().getCommandStack();
    ModelTransactionCommand mtc = new ModelTransactionCommand(bm.wGet("self"), label);
    IEntity result = null;
    pm.beginTask("Executing function " + functionUri + "...", IOperationProgressMonitor.TOTAL_WORK);
    try {
        mtc.begin();
        result = BehaviorUtils.apply(functionUri, bm.wGet("self"), bm);
        mtc.commit();
        if (mtc.canUndo())
            commandStack.execute(mtc);
    } catch (OperationCanceledException e) {
        mtc.rollbackIfNeeded();
    } catch (RuntimeException e) {
        mtc.rollbackIfNeeded();
        throw e;
    } finally {
        bm.setResult(result);
        pm.endTask();
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand) IEntity(org.whole.lang.model.IEntity) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 9 with OperationCanceledException

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

the class ContentAssistRunnable method run.

@Override
public void run(IOperationProgressMonitor pm) throws InvocationTargetException, InterruptedException {
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    CommandStack commandStack = viewer.getEditDomain().getCommandStack();
    ModelTransactionCommand mtc = new ModelTransactionCommand(bm.wGet("self"), label);
    IEntity[] contentAssist = null;
    pm.beginTask("Content assit generation...", IOperationProgressMonitor.TOTAL_WORK);
    try {
        mtc.begin();
        contentAssist = ContentAssistOperation.getContentAssist(bm.wGet("focusEntity"), bm);
        mtc.commit();
        if (mtc.canUndo())
            commandStack.execute(mtc);
    } catch (OperationCanceledException e) {
        mtc.rollbackIfNeeded();
    } catch (RuntimeException e) {
        mtc.rollbackIfNeeded();
        throw e;
    } finally {
        bm.setResult(BindingManagerFactory.instance.createValue(contentAssist));
        pm.endTask();
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand) IEntity(org.whole.lang.model.IEntity) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 10 with OperationCanceledException

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

Aggregations

OperationCanceledException (org.whole.lang.operations.OperationCanceledException)16 IEntity (org.whole.lang.model.IEntity)8 CommandStack (org.eclipse.gef.commands.CommandStack)6 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)6 ModelTransactionCommand (org.whole.lang.ui.commands.ModelTransactionCommand)5 UISynchronize (org.eclipse.e4.ui.di.UISynchronize)3 ITransactionScope (org.whole.lang.bindings.ITransactionScope)3 IWholeRuntimeException (org.whole.lang.exceptions.IWholeRuntimeException)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IOperationProgressMonitor (org.whole.lang.operations.IOperationProgressMonitor)2 AfterTest (org.whole.lang.tests.model.AfterTest)2 BeforeTest (org.whole.lang.tests.model.BeforeTest)2 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 TreeSet (java.util.TreeSet)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 CoreException (org.eclipse.core.runtime.CoreException)1