Search in sources :

Example 11 with IEntityPartViewer

use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.

the class TestPart method createFigure.

protected IFigure createFigure() {
    return new TestFigure((event) -> {
        String location = (String) ((Clickable) event.getSource()).getModel().getUserData();
        Test test = getModelEntity();
        IEntity root = EntityUtils.getFragmentRoot(test);
        IEntityPartViewer viewer = getViewer();
        viewer.getControl().getDisplay().asyncExec(() -> viewer.selectAndReveal(EntityUtils.getEntity(root, location)));
    });
}
Also used : Clickable(org.eclipse.draw2d.Clickable) Test(org.whole.lang.tests.model.Test) IEntity(org.whole.lang.model.IEntity) TestFigure(org.whole.lang.tests.ui.figures.TestFigure) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 12 with IEntityPartViewer

use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.

the class E4Utils method suspendOperation.

public static void suspendOperation(SuspensionKind kind, Throwable throwable, IEntity sourceEntity, final IBindingManager bindings, Set<String> includeNames) {
    if (bindings.wIsSet("debug#reportModeEnabled") && !bindings.wBooleanValue("debug#reportModeEnabled"))
        return;
    if (bindings.wIsSet("debug#debugModeEnabled") && !bindings.wBooleanValue("debug#debugModeEnabled")) {
        if (kind.isError())
            E4Utils.reportError((IEclipseContext) bindings.wGetValue("eclipse#eclipseContext"), "Domain behavior error", "Error while executing domain behavior", throwable);
        return;
    }
    if (kind.isBreak() && bindings.wIsSet("debug#breakpointsEnabled") && !bindings.wBooleanValue("debug#breakpointsEnabled"))
        return;
    if (bindings.wIsSet("viewer") && ((IEntityPartViewer) bindings.wGetValue("viewer")).getControl().getDisplay().getThread() == Thread.currentThread()) {
        E4Utils.reportError((IEclipseContext) bindings.wGetValue("eclipse#eclipseContext"), "Domain behavior error", "Attempted suspension in UI thread", throwable);
        return;
    }
    final IEclipseContext context = (IEclipseContext) bindings.wGetValue("eclipse#eclipseContext");
    context.get(UISynchronize.class).syncExec(new Runnable() {

        public void run() {
            try {
                ClassLoader cl = ReflectionFactory.getPlatformClassLoader();
                Class<?> uiPluginClass = Class.forName("org.whole.lang.e4.ui.E4CompatibilityPlugin", true, cl);
                Method method = uiPluginClass.getMethod("revealPerspective", String.class);
                method.invoke(null, "org.whole.lang.ui.perspectives.LanguageWorkbenchDebugPerspectiveFactory");
            } catch (Exception e) {
                throw new IllegalStateException(e);
            }
            E4Utils.revealPart(context, IE4UIConstants.DEBUG_PART_ID);
            E4Utils.revealPart(context, IE4UIConstants.VARIABLES_PART_ID);
            if (bindings.wIsSet("self") && bindings.wIsSet("viewer")) {
                IEntity selfEntity = bindings.wGet("self");
                ((IEntityPartViewer) bindings.wGetValue("viewer")).selectAndReveal(selfEntity);
            }
            if (throwable instanceof IWholeFrameworkException) {
                IEntity messageModel = ((IWholeFrameworkException) throwable).getMessageModel();
                E4Utils.revealPart(context, IE4UIConstants.RESULTS_PART_ID);
                IEventBroker eventBroker = context.get(IEventBroker.class);
                eventBroker.post(IE4UIConstants.TOPIC_UPDATE_RESULTS, messageModel);
            }
        }
    });
    IEventBroker eventBroker = context.get(IEventBroker.class);
    ExecutionState execution = new ExecutionState(kind, throwable, sourceEntity, bindings, includeNames);
    eventBroker.post(IE4UIConstants.TOPIC_UPDATE_DEBUG, execution);
    execution.pause();
}
Also used : ExecutionState(org.whole.lang.e4.ui.jobs.ExecutionState) IEntity(org.whole.lang.model.IEntity) Method(java.lang.reflect.Method) WholeRuntimeException(org.whole.lang.exceptions.WholeRuntimeException) IWholeFrameworkException(org.whole.lang.exceptions.IWholeFrameworkException) IWholeRuntimeException(org.whole.lang.exceptions.IWholeRuntimeException) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) IWholeFrameworkException(org.whole.lang.exceptions.IWholeFrameworkException) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) UISynchronize(org.eclipse.e4.ui.di.UISynchronize) IEventBroker(org.eclipse.e4.core.services.events.IEventBroker)

Example 13 with IEntityPartViewer

use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.

the class E4Utils method defineCaretBindings.

public static void defineCaretBindings(IBindingManager bm) {
    IEntity text = bm.wGet("focusEntity");
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    ITextualEntityPart targetPart = (ITextualEntityPart) ModelObserver.getObserver(text, viewer.getEditPartRegistry());
    String textToSplit = DataTypeUtils.getAsPresentationString(targetPart.getModelTextEntity());
    int start = targetPart.getSelectionStart();
    int end = targetPart.getSelectionEnd();
    if (start == -1 || end == -1)
        start = end = targetPart.getCaretPosition();
    String leftText = textToSplit.substring(0, start);
    String selectedText = textToSplit.substring(start, end);
    String rightText = textToSplit.substring(end);
    bm.wDefValue("leftText", leftText);
    bm.wDefValue("selectedText", selectedText);
    bm.wDefValue("rightText", rightText);
    bm.wDefValue("caretPositions", targetPart.getCaretPositions());
    bm.wDefValue("caretPosition", targetPart.getCaretPosition());
    bm.wDefValue("caretPositionStart", start);
    bm.wDefValue("caretPositionEnd", end);
    Rectangle caretBounds = CaretUtils.getAbsoluteCaretBounds(viewer, targetPart);
    bm.wDefValue("caretBounds", caretBounds);
    bm.wDefValue("caretVerticalLocation", caretBounds.y);
    bm.wDefValue("caretHorizontalLocation", caretBounds.x);
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IEntity(org.whole.lang.model.IEntity) Rectangle(org.eclipse.draw2d.geometry.Rectangle) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 14 with IEntityPartViewer

use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.

the class E4ContextGraphicalPart method createSelectionLinkable.

@Override
protected ILinkableSelectionListener createSelectionLinkable(IEntityPartViewer viewer) {
    ILinkableSelectionListener listener = super.createSelectionLinkable(viewer);
    listener.addLinkViewerListener(new LinkViewerAdapter() {

        @Override
        public void contentsDerived(IEntityPartViewer viewer, IBindingManager selection, IEntity result) {
            if (selection.wIsSet("primarySelectedEntity")) {
                IEntity primarySelectedEntity = selection.wGet("primarySelectedEntity");
                IEntity model = EntityUtils.getCompoundRoot(primarySelectedEntity);
                IEntity selfModel = EntityUtils.mapEntity(primarySelectedEntity, EntityUtils.clone(model));
                IEntity selfBindings = BindingManagerFactory.instance.createValue(selection.clone());
                IEntity sampleContext = BindingManagerFactory.instance.createTuple(result, selfModel, selfBindings);
                // TODO test
                // if (Matcher.matchImpl(EnvironmentEntityDescriptorEnum.Bindings, result))
                // result.wAdd(BindingManagerFactory.instance.createBinding("self", selfModel));
                eventBroker.post(IE4UIConstants.TOPIC_UPDATE_SAMPLE_CONTEXT, sampleContext);
            } else
                getViewer().setContents(null, createDefaultContents());
        }
    });
    return listener;
}
Also used : ILinkableSelectionListener(org.whole.lang.e4.ui.actions.ILinkableSelectionListener) LinkViewerAdapter(org.whole.lang.e4.ui.actions.LinkViewerAdapter) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 15 with IEntityPartViewer

use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.

the class NormalizeModelRunnable 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("Normalizing...", IOperationProgressMonitor.TOTAL_WORK);
    try {
        mtc.begin();
        HandlersBehavior.normalizeModel(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)

Aggregations

IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)55 IEntity (org.whole.lang.model.IEntity)29 IBindingManager (org.whole.lang.bindings.IBindingManager)13 CommandStack (org.eclipse.gef.commands.CommandStack)12 ModelTransactionCommand (org.whole.lang.ui.commands.ModelTransactionCommand)11 OperationCanceledException (org.whole.lang.operations.OperationCanceledException)8 IEntityPart (org.whole.lang.ui.editparts.IEntityPart)8 ESelectionService (org.eclipse.e4.ui.workbench.modeling.ESelectionService)7 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)6 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)6 Execute (org.eclipse.e4.core.di.annotations.Execute)6 Shell (org.eclipse.swt.widgets.Shell)5 ITextualEntityPart (org.whole.lang.ui.editparts.ITextualEntityPart)5 ITransactionScope (org.whole.lang.bindings.ITransactionScope)3 IEventBroker (org.eclipse.e4.core.services.events.IEventBroker)2 UISynchronize (org.eclipse.e4.ui.di.UISynchronize)2 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)2 Command (org.eclipse.gef.commands.Command)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 Control (org.eclipse.swt.widgets.Control)2