@Test
  public void testInjectWildCard() {
    IEclipseContext context = EclipseContextFactory.create();
    final Display d = Display.getDefault();

    context.set(Realm.class, DisplayRealm.getRealm(d));
    context.set(
        UISynchronize.class,
        new UISynchronize() {

          @Override
          public void syncExec(Runnable runnable) {
            d.syncExec(runnable);
          }

          @Override
          public void asyncExec(Runnable runnable) {
            d.asyncExec(runnable);
          }
        });

    InjectStarEvent target = ContextInjectionFactory.make(InjectStarEvent.class, context);

    // initial state
    assertEquals(0, target.counter1);
    assertNull(target.data);

    // send event
    helper.sendEvent("e4/test/eventInjection", "sample");

    assertEquals(1, target.counter1);
    assertEquals("sample", target.data);
  }
 @PostConstruct
 public void init(MApplication application, IEclipseContext context) {
   IEclipseContext appContext = application.getContext();
   appContext.set(Preferences.class, ContextInjectionFactory.make(Preferences.class, appContext));
   appContext.set(
       PreferenceStore.class, ContextInjectionFactory.make(PreferenceStore.class, appContext));
   ContextInjectionFactory.make(Services.class, context);
   ProgressManager progressManager = ContextInjectionFactory.make(ProgressManager.class, context);
   appContext.set(ProgressManager.class, progressManager);
 }
예제 #3
0
 private IEclipseContext prepareContext() {
   final IEclipseContext parentContext =
       (IEclipseContext) getSite().getService(IEclipseContext.class);
   final IEclipseContext context = parentContext.getActiveLeaf();
   context.set(RedProjectEditorInput.class, editorInput);
   context.set(IEditorSite.class, getEditorSite());
   context.set(RedProjectEditor.class, this);
   ContextInjectionFactory.inject(this, context);
   return context;
 }
 /**
  * Fill in a temporary static context for execution.
  *
  * @param command
  * @return a context not part of the normal hierarchy
  */
 private void addParms(ParameterizedCommand command, IEclipseContext staticContext) {
   final Map parms = command.getParameterMap();
   Iterator i = parms.entrySet().iterator();
   while (i.hasNext()) {
     Map.Entry entry = (Map.Entry) i.next();
     String parameterId = (String) entry.getKey();
     staticContext.set(
         parameterId,
         convertParameterValue(command.getCommand(), parameterId, (String) entry.getValue()));
   }
   staticContext.set(PARM_MAP, parms);
   staticContext.set(ParameterizedCommand.class, command);
 }
  /**
   * Tests setting a value in a context that a RAT is listening to. This test mimics what occurs
   * when handlers change in e4. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=305038
   */
  public void testSetValueRunAndTrack() {
    context.set(
        "somefunction",
        new ContextFunction() {
          @Override
          public Object compute(IEclipseContext context, String contextKey) {
            // make sure this function has a large number of dependencies
            for (int i = 0; i < 1000; i++) {
              context.get("NonExistentValue-" + i);
            }
            return context.get("something");
          }
        });
    context.runAndTrack(
        new RunAndTrack() {
          @Override
          public boolean changed(IEclipseContext context) {
            context.get("somefunction");
            return true;
          }
        });
    new PerformanceTestRunner() {
      int i = 0;

      @Override
      protected void test() {
        context.set("something", "value-" + i++);
      }
    }.run(this, 10, 400);
  }
  public void testCreateView() {
    final MWindow window = createWindowWithOneView("Part Name");

    MApplication application = ApplicationFactoryImpl.eINSTANCE.createApplication();
    application.getChildren().add(window);
    application.setContext(appContext);
    appContext.set(MApplication.class.getName(), application);

    wb = new E4Workbench(application, appContext);
    wb.createAndRunUI(window);

    MPartSashContainer container = (MPartSashContainer) window.getChildren().get(0);
    MPartStack stack = (MPartStack) container.getChildren().get(0);
    MPart part = (MPart) stack.getChildren().get(0);

    CTabFolder folder = (CTabFolder) stack.getWidget();
    CTabItem item = folder.getItem(0);
    assertEquals("Part Name", item.getText());

    assertFalse(part.isDirty());

    part.setDirty(true);
    assertEquals("*Part Name", item.getText());

    part.setDirty(false);
    assertEquals("Part Name", item.getText());
  }
  public static void initializeApplicationServices(IEclipseContext appContext) {
    final IEclipseContext theContext = appContext;
    // we add a special tracker to bring up current selection from
    // the active window to the application level
    appContext.runAndTrack(
        new RunAndTrack() {
          @Override
          public boolean changed(IEclipseContext context) {
            IEclipseContext activeChildContext = context.getActiveChild();
            if (activeChildContext != null) {
              Object selection = activeChildContext.get(IServiceConstants.ACTIVE_SELECTION);
              theContext.set(IServiceConstants.ACTIVE_SELECTION, selection);
            }
            return true;
          }
        });

    // we create a selection service handle on every node that we are asked
    // about as handle needs to know its context
    appContext.set(
        ESelectionService.class.getName(),
        new ContextFunction() {
          @Override
          public Object compute(IEclipseContext context, String contextKey) {
            return ContextInjectionFactory.make(SelectionServiceImpl.class, context);
          }
        });
  }
  @Override
  public Object compute(IEclipseContext context, String contextKey) {
    // look for the top-most MWindow in the context chain:

    // 1st: go up the tree to find topmost MWindow
    MWindow window = null;
    IEclipseContext current = context;
    do {
      MContext model = current.get(MContext.class);
      if (model instanceof MWindow) window = (MWindow) model;
      current = current.getParent();
    } while (current != null);

    if (window == null) {
      if (context.get(MApplication.class) != null) {
        // called from Application scope
        return ContextInjectionFactory.make(ApplicationPartServiceImpl.class, context);
      }
      return IInjector.NOT_A_VALUE;
    }

    IEclipseContext windowContext = window.getContext();
    PartServiceImpl service = windowContext.getLocal(PartServiceImpl.class);
    if (service == null) {
      service = ContextInjectionFactory.make(PartServiceImpl.class, windowContext);
      windowContext.set(PartServiceImpl.class, service);
    }
    return service;
  }
  @Test
  public void testU() throws Exception {
    IEclipseContext parentContext = EclipseContextFactory.create();
    parentContext.set("aString", "");
    parentContext.set(MyTest.class.getName(), new TestFunction());
    IEclipseContext context = parentContext.createChild();

    MyTest test = (MyTest) context.get(MyTest.class.getName());

    assertEquals(0, test.getCount());
    context.dispose();
    assertEquals("Context disposed, @PreDestroy should've been called", 1, test.getCount());
    parentContext.dispose();
    assertEquals(
        "Parent context disposed, @PreDestroy should not have been called again",
        1,
        test.getCount());
  }
  /**
   * Initialize a part renderer from the extension point.
   *
   * @param context the context for the part factories
   */
  @PostConstruct
  void initialize(IEclipseContext context) {
    this.appContext = context;

    // initialize the correct key-binding display formatter
    KeyFormatterFactory.setDefault(SWTKeySupport.getKeyFormatterForPlatform());

    // Add the renderer to the context
    context.set(IPresentationEngine.class.getName(), this);

    IRendererFactory factory = null;
    IContributionFactory contribFactory = context.get(IContributionFactory.class);
    try {
      factory = (IRendererFactory) contribFactory.create(factoryUrl, context);
    } catch (Exception e) {
      logger.warn(e, "Could not create rendering factory");
    }

    // Try to load the default one
    if (factory == null) {
      try {
        factory = (IRendererFactory) contribFactory.create(defaultFactoryUrl, context);
      } catch (Exception e) {
        logger.error(e, "Could not create default rendering factory");
      }
    }

    if (factory == null) {
      throw new IllegalStateException("Could not create any rendering factory. Aborting ...");
    }

    curFactory = factory;
    context.set(IRendererFactory.class, curFactory);

    // Hook up the widget life-cycle subscriber
    if (eventBroker != null) {
      eventBroker.subscribe(UIEvents.UIElement.TOPIC_TOBERENDERED, toBeRenderedHandler);
      eventBroker.subscribe(UIEvents.UIElement.TOPIC_VISIBLE, visibilityHandler);
      eventBroker.subscribe(UIEvents.ElementContainer.TOPIC_CHILDREN, childrenHandler);
      eventBroker.subscribe(UIEvents.Window.TOPIC_WINDOWS, windowsHandler);
      eventBroker.subscribe(UIEvents.Perspective.TOPIC_WINDOWS, windowsHandler);
      eventBroker.subscribe(UIEvents.TrimmedWindow.TOPIC_TRIMBARS, trimHandler);
    }
  }
예제 #11
0
  private void setCSSContextVariables(
      IApplicationContext applicationContext, IEclipseContext context) {
    boolean highContrastMode = getApplicationDisplay().getHighContrast();

    Optional<String> cssURI =
        highContrastMode
            ? Optional.empty()
            : getArgValue(IWorkbench.CSS_URI_ARG, applicationContext, false);

    cssURI.ifPresent(
        cssURIValue -> {
          context.set(IWorkbench.CSS_URI_ARG, cssURIValue);
        });

    Optional<String> themeId =
        highContrastMode
            ? Optional.of(HIGH_CONTRAST_THEME_ID)
            : getArgValue(E4Application.THEME_ID, applicationContext, false);

    if (!themeId.isPresent() && !cssURI.isPresent()) {
      context.set(E4Application.THEME_ID, DEFAULT_THEME_ID);
    } else {
      context.set(E4Application.THEME_ID, themeId.orElseGet(() -> null));
    }

    // validate static CSS URI
    cssURI
        .filter(cssURIValue -> !cssURIValue.startsWith("platform:/plugin/"))
        .ifPresent(
            cssURIValue -> {
              System.err.println(
                  "Warning. Use the \"platform:/plugin/Bundle-SymbolicName/path/filename.extension\" URI for the  parameter:   "
                      + IWorkbench.CSS_URI_ARG); // $NON-NLS-1$
              context.set(E4Application.THEME_ID, cssURIValue);
            });

    Optional<String> cssResourcesURI =
        getArgValue(IWorkbench.CSS_RESOURCE_URI_ARG, applicationContext, false);
    cssResourcesURI.ifPresent(
        cssResourcesURIValue -> {
          context.set(IWorkbench.CSS_RESOURCE_URI_ARG, cssResourcesURIValue);
        });
  }
 public static ContextObjectSupplier getObjectSupplier(
     IEclipseContext context, IInjector injector) {
   if (context == null) return null;
   // don't track this dependency if we are called in RaT
   ContextObjectSupplier supplier =
       (ContextObjectSupplier)
           ((EclipseContext) context)
               .internalGet((EclipseContext) context, ContextObjectSupplier.class.getName(), true);
   if (supplier != null) return supplier;
   ContextObjectSupplier objectSupplier = new ContextObjectSupplier(context, injector);
   context.set(ContextObjectSupplier.class, objectSupplier);
   return objectSupplier;
 }
예제 #13
0
  // TODO This should go into a different bundle
  public static IEclipseContext createDefaultHeadlessContext() {
    IEclipseContext serviceContext = E4Workbench.getServiceContext();

    IExtensionRegistry registry = RegistryFactory.getRegistry();
    ExceptionHandler exceptionHandler = new ExceptionHandler();
    ReflectionContributionFactory contributionFactory = new ReflectionContributionFactory(registry);
    serviceContext.set(IContributionFactory.class, contributionFactory);
    serviceContext.set(IExceptionHandler.class, exceptionHandler);
    serviceContext.set(IExtensionRegistry.class, registry);

    serviceContext.set(
        Adapter.class, ContextInjectionFactory.make(EclipseAdapter.class, serviceContext));

    // No default log provider available
    if (serviceContext.get(ILoggerProvider.class) == null) {
      serviceContext.set(
          ILoggerProvider.class,
          ContextInjectionFactory.make(DefaultLoggerProvider.class, serviceContext));
    }

    return serviceContext;
  }
 public Object executeHandler(ParameterizedCommand command, IEclipseContext staticContext) {
   final IEclipseContext executionContext = getExecutionContext();
   addParms(command, staticContext);
   // executionContext.set(STATIC_CONTEXT, staticContext);
   push(executionContext, staticContext);
   try {
     // Command cmd = command.getCommand();
     return command.executeWithChecks(null, new ExpressionContext(peek().context));
   } catch (ExecutionException e) {
     staticContext.set(HANDLER_EXCEPTION, e);
   } catch (NotDefinedException e) {
     staticContext.set(HANDLER_EXCEPTION, e);
   } catch (NotEnabledException e) {
     staticContext.set(HANDLER_EXCEPTION, e);
   } catch (NotHandledException e) {
     staticContext.set(HANDLER_EXCEPTION, e);
   } finally {
     pop();
     // executionContext.remove(STATIC_CONTEXT);
   }
   return null;
 }
  /** Tests the Registration of an Event Hanlder in the event broker of the eclpse context. */
  @Test
  public void testEventBrokerEventHanlderRegistration() {
    TestProtocolService protocolService = new TestProtocolService();
    IEclipseContext context = EclipseContextFactory.create();
    final Map<String, EventHandler> topics = new HashMap<String, EventHandler>();
    context.set(
        IEventBroker.class,
        new IEventBroker() {

          @Override
          public boolean send(String topic, Object data) {
            return false;
          }

          @Override
          public boolean post(String topic, Object data) {
            return false;
          }

          @Override
          public boolean subscribe(String topic, EventHandler eventHandler) {
            topics.put(topic, eventHandler);
            return true;
          }

          @Override
          public boolean subscribe(
              String topic, String filter, EventHandler eventHandler, boolean headless) {
            return false;
          }

          @Override
          public boolean unsubscribe(EventHandler eventHandler) {
            return false;
          }
        });
    protocolService.compute(context, null);
    EventHandler handler =
        topics.get(TestEditorCoreEventConstants.TESTSTRUCTURE_MODEL_CHANGED_DELETED);
    assertNotNull("Hanlder should be registered", handler);
    TestCase testCase = new TestCase();
    testCase.setName("TestCase1");
    protocolService.set(testCase, new TestResult());
    assertNotNull(protocolService.get(testCase));
    Map<String, String> properties = new HashMap<String, String>();
    properties.put("org.eclipse.e4.data", testCase.getFullName());
    Event event =
        new Event(TestEditorCoreEventConstants.TESTSTRUCTURE_MODEL_CHANGED_DELETED, properties);
    handler.handleEvent(event);
    assertNull(protocolService.get(testCase));
  }
 private void simulateMenuSelection(MMenuItem item) {
   // FIXME: pity this code isn't available through the MMenuItem instance
   // somehow
   IEclipseContext lclContext = getContext(item);
   if (item instanceof MDirectMenuItem) {
     MDirectMenuItem dmi = (MDirectMenuItem) item;
     if (dmi.getObject() == null) {
       IContributionFactory cf =
           (IContributionFactory) lclContext.get(IContributionFactory.class.getName());
       dmi.setObject(cf.create(dmi.getContributionURI(), lclContext));
     }
     lclContext.set(MItem.class.getName(), item);
     ContextInjectionFactory.invoke(dmi.getObject(), Execute.class, lclContext);
     lclContext.remove(MItem.class.getName());
   } else if (item instanceof MHandledMenuItem) {
     MHandledMenuItem hmi = (MHandledMenuItem) item;
     EHandlerService service = (EHandlerService) lclContext.get(EHandlerService.class.getName());
     ParameterizedCommand cmd = hmi.getWbCommand();
     if (cmd == null) {
       cmd = HandledMenuItemRenderer.generateParameterizedCommand(hmi, lclContext);
     }
     lclContext.set(MItem.class.getName(), item);
     service.executeHandler(cmd);
     lclContext.remove(MItem.class.getName());
   } else {
     statusReporter
         .get()
         .report(
             new Status(
                 IStatus.WARNING,
                 CocoaUIProcessor.FRAGMENT_ID,
                 "Unhandled menu type: "
                     + item.getClass()
                     + ": "
                     + item), //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$
             StatusReporter.LOG);
   }
 }
  @Test
  public void testExtraDependencies() throws InvocationTargetException, InstantiationException {
    IEclipseContext context = EclipseContextFactory.create();
    context.set("arg1", "abc");
    context.set("arg2", Integer.valueOf(123));

    IEclipseContext otherContext = EclipseContextFactory.create();
    otherContext.set("arg3", "other");

    context.set("otherContext", otherContext);

    TestObject object = ContextInjectionFactory.make(TestObject.class, context);

    // check that initial values are properly injected
    assertEquals("abc", object.string);
    assertEquals(Integer.valueOf(123), object.integer);
    assertEquals("other", object.other);

    // modify argument value to cause update - bug 308650
    context.set("arg2", Integer.valueOf(789));

    // change the "other" value; should not be propagated
    otherContext.set("arg3", "wrong");
    assertEquals("other", object.other);

    // dispose the other context; should not cause disposal of the test object
    otherContext.dispose();
    assertEquals("other", object.other);
    assertFalse(object.disposed);

    // remove "other" context, should not be propagated
    context.remove("otherContext");
    assertEquals("other", object.other);

    // check that changes in the method arguments are propagated
    context.set("arg1", "xyz");
    context.set("arg2", Integer.valueOf(456));
    assertEquals("xyz", object.string);
    assertEquals(Integer.valueOf(456), object.integer);
    assertNull(object.other);

    // check that disposal of the injected context causes disposal of the injected object
    context.dispose();
    assertTrue(object.disposed);
    assertNotNull(object.string);
    assertNotNull(object.integer);
    assertNull(object.other);
  }
 private IEclipseContext getStaticContext() {
   if (infoContext == null) {
     IEclipseContext parentContext = renderer.getContext(toolbarModel);
     if (parentContext != null) {
       infoContext = parentContext.createChild(STATIC_CONTEXT);
     } else {
       infoContext = EclipseContextFactory.create(STATIC_CONTEXT);
     }
     ContributionsAnalyzer.populateModelInterfaces(
         toolbarModel, infoContext, toolbarModel.getClass().getInterfaces());
     infoContext.set(ToolBarRenderer.class, renderer);
   }
   return infoContext;
 }
        public void selectionChanged(MPart part, Object selection) {
          selection = createCompatibilitySelection(selection);
          context.set(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);

          IEclipseContext applicationContext = application.getContext();
          if (applicationContext.getActiveChild() == context) {
            application.getContext().set(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
          }

          Object client = part.getObject();
          if (client instanceof CompatibilityPart) {
            IWorkbenchPart workbenchPart = ((CompatibilityPart) client).getPart();
            notifyListeners(part.getElementId(), workbenchPart, (ISelection) selection);
          }
        }
  public static void populateModelInterfaces(
      Object modelObject, IEclipseContext context, Class<?>[] interfaces) {
    for (Class<?> intf : interfaces) {
      Activator.trace(
          Policy.DEBUG_CONTEXTS,
          "Adding "
              + intf.getName()
              + " for " //$NON-NLS-1$ //$NON-NLS-2$
              + modelObject.getClass().getName(),
          null);
      context.set(intf.getName(), modelObject);

      populateModelInterfaces(modelObject, context, intf.getInterfaces());
    }
  }
  private static void populateModelInterfaces(
      MContext contextModel, IEclipseContext context, Class<?>[] interfaces) {
    for (Class<?> intf : interfaces) {
      Activator.trace(
          Policy.DEBUG_CONTEXTS,
          "Adding "
              + intf.getName()
              + " for " //$NON-NLS-1$ //$NON-NLS-2$
              + contextModel.getClass().getName(),
          null);
      context.set(intf.getName(), contextModel);

      populateModelInterfaces(contextModel, context, intf.getInterfaces());
    }
  }
 public void testLookupContextFunction() {
   context.set(
       "somefunction",
       new ContextFunction() {
         @Override
         public Object compute(IEclipseContext context, String contextKey) {
           return "result";
         }
       });
   new PerformanceTestRunner() {
     @Override
     protected void test() {
       context.get("somefunction");
     }
   }.run(this, 10, 5000000);
 }
  /**
   * Updates the selection of the workbench window with that of the active part's.
   *
   * @param activePart the currently active part
   */
  public void updateSelection(IWorkbenchPart activePart) {
    if (activePart != null) {
      ISelectionProvider selectionProvider = activePart.getSite().getSelectionProvider();
      if (selectionProvider != null) {
        ISelection selection = selectionProvider.getSelection();
        context.set(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);

        IEclipseContext applicationContext = application.getContext();
        if (applicationContext.getActiveChild() == context) {
          application.getContext().set(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
        }

        notifyListeners(activePart.getSite().getId(), activePart, selection);
        notifyPostSelectionListeners(activePart.getSite().getId(), activePart, selection);
      }
    }
  }
  @Test
  public void testBug310027() {
    MApplication application = ApplicationFactoryImpl.eINSTANCE.createApplication();
    MWindow window = BasicFactoryImpl.eINSTANCE.createWindow();
    MPartSashContainer container = BasicFactoryImpl.eINSTANCE.createPartSashContainer();
    MPartStack partStackA = BasicFactoryImpl.eINSTANCE.createPartStack();
    MPartStack partStackB = BasicFactoryImpl.eINSTANCE.createPartStack();
    MPart partA = BasicFactoryImpl.eINSTANCE.createPart();
    MPart partB = BasicFactoryImpl.eINSTANCE.createPart();

    window.setWidth(600);
    window.setHeight(400);

    partStackA.setContainerData("50");
    partStackB.setContainerData("50");

    application.getChildren().add(window);
    application.setSelectedElement(window);

    window.getChildren().add(container);
    window.setSelectedElement(container);

    container.getChildren().add(partStackA);
    container.getChildren().add(partStackB);
    container.setSelectedElement(partStackA);

    partStackA.getChildren().add(partA);
    partStackA.setSelectedElement(partA);
    partStackA.getChildren().add(partB);
    partStackA.setSelectedElement(partB);

    application.setContext(appContext);
    appContext.set(MApplication.class, application);

    wb = new E4Workbench(application, appContext);
    wb.createAndRunUI(window);

    assertEquals("50", partStackA.getContainerData());
    assertEquals("50", partStackB.getContainerData());

    partStackB.setToBeRendered(false);

    while (Display.getDefault().readAndDispatch()) ;

    assertEquals("50", partStackA.getContainerData());
  }
  public void testSetContextFunction() {
    context.set(
        "somefunction",
        new ContextFunction() {
          @Override
          public Object compute(IEclipseContext context, String contextKey) {
            return context.get("something");
          }
        });
    new PerformanceTestRunner() {
      int i = 0;

      @Override
      protected void test() {
        context.set("something", "value-" + i++);
      }
    }.run(this, 10, 600000);
  }
  @Test
  public void testW() throws Exception {
    IEclipseContext parentContext = EclipseContextFactory.create();
    parentContext.set("aString", "");
    IEclipseContext context = parentContext.createChild();

    MyTest test = new MyTest();
    ContextInjectionFactory.inject(test, context);

    assertEquals(0, test.getCount());
    context.dispose();
    assertEquals("Context disposed, @PreDestroy should've been called", 1, test.getCount());
    parentContext.dispose();
    assertEquals(
        "Parent context disposed, @PreDestroy should not have been called again",
        1,
        test.getCount());
  }
예제 #27
0
  // TODO This should go into a different bundle
  public static IEclipseContext createDefaultContext() {

    IEclipseContext serviceContext = createDefaultHeadlessContext();
    final IEclipseContext appContext =
        serviceContext.createChild("WorkbenchContext"); // $NON-NLS-1$
    // make application context available for dependency injection under the
    // E4Application.APPLICATION_CONTEXT_KEY key
    appContext.set(IWorkbench.APPLICATION_CONTEXT_KEY, appContext);

    appContext.set(Logger.class, ContextInjectionFactory.make(WorkbenchLogger.class, appContext));
    appContext.set(EModelService.class, new ModelServiceImpl(appContext));
    appContext.set(EPlaceholderResolver.class, new PlaceholderResolver());

    // setup for commands and handlers
    appContext.set(IServiceConstants.ACTIVE_PART, new ActivePartLookupFunction());

    appContext.set(
        IServiceConstants.ACTIVE_SHELL,
        new ActiveChildLookupFunction(
            IServiceConstants.ACTIVE_SHELL, E4Workbench.LOCAL_ACTIVE_SHELL));

    appContext.set(
        IStylingEngine.class,
        new IStylingEngine() {
          @Override
          public void setClassname(Object widget, String classname) {}

          @Override
          public void setId(Object widget, String id) {}

          @Override
          public void style(Object widget) {}

          @Override
          public CSSStyleDeclaration getStyle(Object widget) {
            return null;
          }

          @Override
          public void setClassnameAndId(Object widget, String classname, String id) {}
        });

    // translation
    initializeLocalization(appContext);

    return appContext;
  }
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    parentContext =
        EclipseContextFactory.getServiceContext(CoreTestsActivator.getDefault().getBundleContext());
    context = parentContext.createChild(getName());

    // add some values to the contexts
    for (int i = 0; i < 100; i++) {
      context.set("Value-" + i, Integer.valueOf(i));
    }
    // do some additional service lookups on non-existent keys
    for (int i = 0; i < 1000; i++) {
      context.get("NonExistentValue-" + i);
    }

    // lookup some OSGi services
    context.get(DebugOptions.class.getName());
    context.get(IAdapterManager.class.getName());
    context.get(IExtensionRegistry.class.getName());
    context.get(IPreferencesService.class.getName());
    context.get(Location.class.getName());
  }
예제 #29
0
  private MApplication loadApplicationModel(
      IApplicationContext appContext, IEclipseContext eclipseContext) {
    MApplication theApp = null;

    Location instanceLocation = WorkbenchSWTActivator.getDefault().getInstanceLocation();

    URI applicationModelURI = determineApplicationModelURI(appContext);
    eclipseContext.set(E4Workbench.INITIAL_WORKBENCH_MODEL_URI, applicationModelURI);

    // Save and restore
    Boolean saveAndRestore =
        getArgValue(IWorkbench.PERSIST_STATE, appContext, false)
            .map(value -> Boolean.parseBoolean(value))
            .orElse(Boolean.TRUE);

    eclipseContext.set(IWorkbench.PERSIST_STATE, saveAndRestore);

    // when -data @none or -data @noDefault options
    if (instanceLocation != null && instanceLocation.getURL() != null) {
      eclipseContext.set(E4Workbench.INSTANCE_LOCATION, instanceLocation);
    } else {
      eclipseContext.set(IWorkbench.PERSIST_STATE, false);
    }

    // Persisted state
    Boolean clearPersistedState =
        getArgValue(IWorkbench.CLEAR_PERSISTED_STATE, appContext, true)
            .map(value -> Boolean.parseBoolean(value))
            .orElse(Boolean.FALSE);
    eclipseContext.set(IWorkbench.CLEAR_PERSISTED_STATE, clearPersistedState);

    String resourceHandler =
        getArgValue(IWorkbench.MODEL_RESOURCE_HANDLER, appContext, false)
            .orElse("bundleclass://org.eclipse.e4.ui.workbench/" + ResourceHandler.class.getName());

    IContributionFactory factory = eclipseContext.get(IContributionFactory.class);

    handler = (IModelResourceHandler) factory.create(resourceHandler, eclipseContext);
    eclipseContext.set(IModelResourceHandler.class, handler);

    Resource resource = handler.loadMostRecentModel();
    theApp = (MApplication) resource.getContents().get(0);

    return theApp;
  }
예제 #30
0
  @Override
  public boolean load() {
    if (sessionService == null) {
      // we abort
      logger.info("Aborting catalog " + params.getName() + " loading : session is not set yet");
      return false;
    }
    Session session = sessionService.getSession();
    logger.info(
        "[PadreCatalog] Session service instanciated. Session username is "
            + sessionService.getSession().getUsername());
    this.layertreeAsJsonNode = getLayertree();

    // if null, then it failed. We exit the function.
    if (this.layertreeAsJsonNode == null) {
      logger.error("ERROR parsing layertree (" + this.getClass().getName() + ")");
      return false;
    }

    // create a new local_ context
    IEclipseContext catalogContext = EclipseContextFactory.create();
    catalogState = new PadreCatalogState();
    catalogContext.set(PadreCatalogState.class, catalogState);

    // connect new local context with context hierarchy
    catalogContext.setParent(context);

    this.rootNode = ContextInjectionFactory.make(FolderNode.class, catalogContext);
    // this.rootNode = new FolderNode();
    this.rootNode.setName(params.getName());
    this.catalogState.addExpandedNode(this.rootNode);
    this.rootNode.loadFromJson(this.layertreeAsJsonNode);

    this.checkInitialNodes(this.catalogState.getCheckedNodes());

    return true;
  }