Search in sources :

Example 11 with IEclipseContext

use of org.eclipse.e4.core.contexts.IEclipseContext 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 12 with IEclipseContext

use of org.eclipse.e4.core.contexts.IEclipseContext in project whole by wholeplatform.

the class AbstractE4DerivedGraphicalPart method createSelectionLinkable.

protected ILinkableSelectionListener createSelectionLinkable(IEntityPartViewer viewer) {
    IEclipseContext params = EclipseContextFactory.create();
    // we need to pass the viewer because it has not been set in the active context
    params.set(IEntityPartViewer.class, viewer);
    return ContextInjectionFactory.make(DerivedLinkableSelectionListener.class, context, configureSelectionLinkable(params));
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext)

Example 13 with IEclipseContext

use of org.eclipse.e4.core.contexts.IEclipseContext in project whole by wholeplatform.

the class E4PaletteGraphicalPart method createEntityViewer.

protected IEntityPartViewer createEntityViewer(Composite parent) {
    IEclipseContext params = EclipseContextFactory.create();
    params.set("parent", parent);
    IEntityPartViewer viewer = ContextInjectionFactory.make(E4PaletteGraphicalViewer.class, context, params);
    setSelectionLinkable(createSelectionLinkable(viewer));
    return viewer;
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 14 with IEclipseContext

use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.

the class InjectionMixedSuppliersTest method testPreferencesQualifier.

@Test
public void testPreferencesQualifier() throws BackingStoreException, InvocationTargetException, InstantiationException {
    IEclipseContext context = EclipseContextFactory.create();
    setPreference("injectedPrefs", "abc");
    context.set("testMixed", "other");
    InjectTarget target = ContextInjectionFactory.make(InjectTarget.class, context);
    // test
    assertEquals("abc", target.pref);
    assertEquals("other", target.other);
    // change
    setPreference("injectedPrefs", "xyz");
    context.set("testMixed", "bingo");
    // re-test
    assertEquals("xyz", target.pref);
    assertEquals("bingo", target.other);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 15 with IEclipseContext

use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.

the class InjectionPreferencesTest method testPreferencesQualifier.

@Test
public void testPreferencesQualifier() throws BackingStoreException {
    setPreference(TEST_PREFS_KEY, "abc");
    setPreference(TEST_PREFS_KEY, TEST_PREFS_NODE, "123");
    IEclipseContext context = EclipseContextFactory.create();
    InjectTarget target = ContextInjectionFactory.make(InjectTarget.class, context);
    // default node
    assertEquals(1, target.counter);
    assertEquals("abc", target.pref);
    // specific node
    assertEquals(1, target.counterNode);
    assertEquals("123", target.prefNode);
    // optional preference
    assertEquals(1, target.counterOptional);
    assertNull(target.prefOptional1);
    assertEquals("abc", target.prefOptional2);
    // change
    setPreference(TEST_PREFS_KEY, "xyz");
    setPreference(TEST_PREFS_KEY, TEST_PREFS_NODE, "456");
    // default node
    assertEquals(2, target.counter);
    assertEquals("xyz", target.pref);
    // specific node
    assertEquals(2, target.counterNode);
    assertEquals("456", target.prefNode);
    // optional preference
    assertEquals(2, target.counterOptional);
    assertNull(target.prefOptional1);
    assertEquals("xyz", target.prefOptional2);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Aggregations

IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)195 Test (org.junit.Test)142 RunAndTrack (org.eclipse.e4.core.contexts.RunAndTrack)18 ContextFunction (org.eclipse.e4.core.contexts.ContextFunction)17 BundleContext (org.osgi.framework.BundleContext)15 IEntity (org.whole.lang.model.IEntity)11 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)9 Execute (org.eclipse.e4.core.di.annotations.Execute)7 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)6 IImportAsModelDialogFactory (org.whole.lang.ui.dialogs.IImportAsModelDialogFactory)6 Hashtable (java.util.Hashtable)5 PrimaryObjectSupplier (org.eclipse.e4.core.di.suppliers.PrimaryObjectSupplier)4 Named (javax.inject.Named)3 PerformanceTestRunner (org.eclipse.core.tests.harness.PerformanceTestRunner)3 InjectionException (org.eclipse.e4.core.di.InjectionException)3 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)3 Optional (org.eclipse.e4.core.di.annotations.Optional)3 UISynchronize (org.eclipse.e4.ui.di.UISynchronize)3 ContextMenuProvider (org.eclipse.gef.ContextMenuProvider)3 IMenuManager (org.eclipse.jface.action.IMenuManager)3