Search in sources :

Example 11 with OperationCanceledException

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

the class TextualFunctionRunnable 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");
    IEntity text = bm.wGet("focusEntity");
    boolean enableAnimation = AnimableRunnable.enableAnimation(false);
    ModelTextCommand mtc = new ModelTextCommand(text);
    try {
        mtc.setLabel(label);
        mtc.setViewer(viewer);
        mtc.begin();
        try {
            bm.wEnterScope();
            IEntity newText = BehaviorUtils.apply(functionUri, bm.wGet("self"), bm);
            mtc.setNewSelectedEntity(newText);
            mtc.setNewPosition(bm.wIntValue("caretPosition"));
        // FIXME add textual selection viariables updates
        // see E4Utils.defineCaretBindings()
        } catch (OperationCanceledException e) {
            throw e;
        } finally {
            bm.wExitScope();
        }
        mtc.commit();
        if (mtc.canUndo()) {
            CommandStack commandStack = viewer.getEditDomain().getCommandStack();
            commandStack.execute(mtc);
        }
    } catch (OperationCanceledException e) {
        mtc.rollbackIfNeeded();
    } catch (RuntimeException e) {
        mtc.rollbackIfNeeded();
        throw e;
    } finally {
        AnimableRunnable.enableAnimation(enableAnimation);
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) IEntity(org.whole.lang.model.IEntity) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) ModelTextCommand(org.whole.lang.ui.commands.ModelTextCommand) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 12 with OperationCanceledException

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

the class ActionCallRunnable method run.

@Override
public void run(IOperationProgressMonitor pm) throws InvocationTargetException {
    IEntity model = bm.wGet("self");
    boolean analyzing = bm.wBooleanValue("analyzing");
    if (analyzing) {
        // clone model if is analyzing
        model = EntityUtils.clone(model);
        CommonsEntityFactory.instance.createRootFragment(model.wGetAdapter(CommonsEntityDescriptorEnum.Any));
        ReflectionFactory.getHistoryManager(model).setHistoryEnabled(true);
        // map selected entities if analyzing
        IEntity tuple = bm.wGet("selectedEntities");
        int size = tuple.wSize();
        for (int i = 0; i < size; i++) tuple.wSet(i, EntityUtils.mapEntity(tuple.wGet(i), model));
        bm.wSet("primarySelectedEntity", EntityUtils.mapEntity(bm.wGet("primarySelectedEntity"), model));
        bm.wSet("focusEntity", EntityUtils.mapEntity(bm.wGet("focusEntity"), model));
    }
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    final CommandStack commandStack = viewer.getEditDomain().getCommandStack();
    final ModelTransactionCommand mtc = new ModelTransactionCommand(model, label);
    pm.beginTask("executing action", 90, IOperationProgressMonitor.TOTAL_WORK);
    try {
        mtc.begin();
        HandlersBehavior.actionCall(bm);
        mtc.commit();
        if (analyzing) {
            E4Utils.revealPart(context, RESULTS_PART_ID);
            IEventBroker eventBroker = context.get(IEventBroker.class);
            eventBroker.post(IE4UIConstants.TOPIC_UPDATE_RESULTS, bm.getResult());
        } else if (mtc.canUndo()) {
            context.get(UISynchronize.class).syncExec(new Runnable() {

                public void run() {
                    commandStack.execute(mtc);
                }
            });
        }
    } catch (OperationCanceledException e) {
        mtc.rollbackIfNeeded();
    } catch (RuntimeException e) {
        mtc.rollbackIfNeeded();
        throw e;
    } finally {
        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) IEventBroker(org.eclipse.e4.core.services.events.IEventBroker)

Example 13 with OperationCanceledException

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

the class InterpretModelRunnable 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);
    pm.beginTask("Interpreting...", IOperationProgressMonitor.TOTAL_WORK);
    try {
        mtc.begin();
        HandlersBehavior.interpretModel(bm);
        mtc.commit();
        if (mtc.canUndo())
            commandStack.execute(mtc);
    } catch (OperationCanceledException e) {
        mtc.rollbackIfNeeded();
    } catch (RuntimeException e) {
        mtc.rollbackIfNeeded();
        throw e;
    } finally {
        pm.endTask();
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 14 with OperationCanceledException

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

the class ValidateModelRunnable method run.

@Override
public void run(IOperationProgressMonitor pm) throws InvocationTargetException, InterruptedException {
    pm.beginTask("Validating...", IOperationProgressMonitor.TOTAL_WORK);
    try {
        UISynchronize synchronize = context.get(UISynchronize.class);
        bm.wDefValue("decorationManager", new E4UIDecorationManager(synchronize, bm));
        HandlersBehavior.validateModel(bm);
        if (MarkerUtils.findMarkers((IResource) bm.wGetValue("file"), true).length > 0)
            E4Utils.revealPart(context, "org.eclipse.ui.views.ProblemView");
    } catch (OperationCanceledException e) {
    // gracefully terminate execution
    } finally {
        pm.endTask();
    }
}
Also used : E4UIDecorationManager(org.whole.lang.e4.ui.operations.E4UIDecorationManager) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) UISynchronize(org.eclipse.e4.ui.di.UISynchronize)

Example 15 with OperationCanceledException

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

the class TestsInterpreterVisitor method visit.

@Override
public void visit(Test entity) {
    ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
    getBindings().wEnterScope(ts);
    String name = entity.getName().getValue();
    Outcome outcome = TestsEntityFactory.instance.createOutcome(OutcomeEnum.SUCCESS);
    StringLiteral location = CommonsEntityAdapterFactory.createResolver(StringLiteral);
    StringLiteral cause = CommonsEntityAdapterFactory.createResolver(StringLiteral);
    Result result = TestsEntityFactory.instance.createResult(outcome, location, cause);
    try {
        for (BeforeTest beforeTest : BehaviorUtils.<BeforeTest>compileAndLazyEvaluate(createAspectPath("BeforeTest"), entity)) {
            beforeTest.accept(this);
            getResult();
        }
        entity.getBody().accept(this);
        getResult();
        for (AfterTest afterTest : BehaviorUtils.<AfterTest>compileAndLazyEvaluate(createAspectPath("AfterTest"), entity)) {
            afterTest.accept(this);
            getResult();
        }
        printWriter().printf("    %32s(...) OK\n", name);
    } catch (OperationCanceledException e) {
        throw e;
    } catch (TestsException e) {
        outcome.wSetValue(OutcomeEnum.FAILURE);
        location.setValue(EntityUtils.getLocation(e.getSubjectStatement()));
        cause.setValue(e.getMessage());
        reportFailure(name, e);
    } catch (RuntimeException e) {
        outcome.wSetValue(OutcomeEnum.ERROR);
        IEntity sourceEntity = null;
        if (e instanceof IWholeRuntimeException) {
            sourceEntity = ((IWholeRuntimeException) e).getSourceEntity();
            if (EntityUtils.getCompoundRoot(sourceEntity) != EntityUtils.getCompoundRoot(entity))
                // FIXME replace with outer aspect or statement
                sourceEntity = null;
        }
        if (sourceEntity == null)
            sourceEntity = entity;
        location.setValue(EntityUtils.getLocation(sourceEntity));
        cause.setValue(e.getMessage());
        reportError(name, e);
    } finally {
        ts.rollback();
        getBindings().wExitScope();
    }
    if (EntityUtils.isResolver(entity.getExpectedResult()))
        entity.setExpectedResult(EntityUtils.clone(result));
    if (!Matcher.match(result, entity.getActualResult()))
        entity.setActualResult(result);
    setResult(result);
}
Also used : IWholeRuntimeException(org.whole.lang.exceptions.IWholeRuntimeException) ITransactionScope(org.whole.lang.bindings.ITransactionScope) StringLiteral(org.whole.lang.tests.model.StringLiteral) IWholeRuntimeException(org.whole.lang.exceptions.IWholeRuntimeException) IEntity(org.whole.lang.model.IEntity) Outcome(org.whole.lang.tests.model.Outcome) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) BeforeTest(org.whole.lang.tests.model.BeforeTest) AfterTest(org.whole.lang.tests.model.AfterTest) Result(org.whole.lang.tests.model.Result)

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