Package org.eclipse.e4.core.contexts

Examples of org.eclipse.e4.core.contexts.IEclipseContext


  }

  @Override
  public ServerResource create(Class<? extends ServerResource> clazz, Request request, Response response)
  {
    IEclipseContext childContext = serviceContext.createChild("ResourceContext");
    diLock.lock(); // The lock is required because ContextInjectionFactory.make() is not thread safe

    try
    {
      InjectedResource serverResource = (InjectedResource) ContextInjectionFactory.make(clazz, childContext);
View Full Code Here


    @Optional
    public void registerCustomSaveHandler(
                    @UIEventTopic(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE) MApplication application)
    {
        MWindow window = application.getSelectedElement();
        IEclipseContext windowContext = window.getContext();

        windowContext.set(ISaveHandler.class, new CustomSaveHandler());
    }
View Full Code Here

        GridDataFactory.fillDefaults().hint(180, SWT.DEFAULT).grab(false, true).applyTo(control);

        book = new PageBook(container, SWT.NONE);
        GridDataFactory.fillDefaults().grab(true, true).span(1, 2).applyTo(book);

        IEclipseContext childContext = context.createChild();
        childContext.set(Composite.class, container);
        childContext.set(Client.class, client);
        ClientProgressProvider provider = ContextInjectionFactory.make(ClientProgressProvider.class, childContext);
        GridDataFactory.fillDefaults().hint(180, SWT.DEFAULT).applyTo(provider.getControl());

        sidebar.selectDefaultView();
View Full Code Here

      }
    } else {
      // failed to create the widget, dispose its context if necessary
      if (element instanceof MContext) {
        MContext ctxt = (MContext) element;
        IEclipseContext lclContext = ctxt.getContext();
        if (lclContext != null) {
          lclContext.dispose();
          ctxt.setContext(null);
        }
      }
    }
   
View Full Code Here

  protected <R extends AbstractRenderer<? extends M,Object>, M extends MUIElement> R getRendererFor(MUIElement element) {
    return (R) element.getRenderer();
  }
 
  private IEclipseContext createContext(MContext model, IEclipseContext parentContext) {
    IEclipseContext lclContext = parentContext.createChild(getContextName((MApplicationElement) model));
    populateModelInterfaces(model, lclContext, model.getClass().getInterfaces());
    model.setContext(lclContext);
   
    for (String variable : model.getVariables()) {
      lclContext.declareModifiable(variable);
    }

    Map<String, String> props = model.getProperties();
    for (String key : props.keySet()) {
      lclContext.set(key, props.get(key));
    }
   
    E4Workbench.processHierarchy(model);
   
    return lclContext;
View Full Code Here

  }
 
  public Object createGui(MUIElement element) {
   
    // Obtain the necessary parent context
    IEclipseContext parentContext = null;
    if (element.getCurSharedRef() != null) {
      MPlaceholder ph = element.getCurSharedRef();
      parentContext = getContext(ph.getParent());
    } else if (parentContext == null && element.getParent() != null) {
      parentContext = getContext(element.getParent());
View Full Code Here

        }
       
        if (element instanceof MContribution) {
          MContribution contribution = (MContribution) element;
          Object client = contribution.getObject();
          IEclipseContext parentContext = renderer.getModelContext(element);
          if (parentContext != null && client != null) {
            try {
              ContextInjectionFactory.invoke(client,
                  PersistState.class, parentContext, null);
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        }
       
        renderer.destroyWidget(element);
       
        if (element instanceof MContribution) {
          MContribution contribution = (MContribution) element;
          Object client = contribution.getObject();
          IEclipseContext parentContext = renderer.getModelContext(element);
          if (parentContext != null && client != null) {
            try {
              ContextInjectionFactory.uninject(client, parentContext);
            } catch (Exception e) {
              e.printStackTrace();
View Full Code Here

    }
  }
 
  private void clearContext(MContext contextME) {
    MContext ctxt = (MContext) contextME;
    IEclipseContext lclContext = ctxt.getContext();
    if (lclContext != null) {
      IEclipseContext parentContext = lclContext.getParent();
      IEclipseContext child = parentContext.getActiveChild();
      if (child == lclContext) {
        child.deactivate();
      }

      ctxt.setContext(null);
      lclContext.dispose();
    }
View Full Code Here

  }

  public E4Workbench createE4Workbench(IApplicationContext applicationContext, Application jfxApplication, Stage primaryStage) {
    args = (String[]) applicationContext.getArguments().get(IApplicationContext.APPLICATION_ARGS);

    IEclipseContext appContext = createDefaultContext();
   
    //FIXME We need to fix this later on see ticket 256
//    ContextInjectionFactory.setDefault(appContext);
    try {
      Method m = ContextInjectionFactory.class.getMethod("setDefault", IEclipseContext.class);
      m.invoke(null, appContext);
    } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e1) {
      System.err.println("WARNING: You are running on an old and buggy DI container which is fixed in 4.2.2 builds. Consider upgradeing.");
    }
   

   
    appContext.set(Application.class, jfxApplication);
    appContext.set("primaryStage", primaryStage);
    // appContext.set(Realm.class, SWTObservables.getRealm(display));
    appContext.set(UISynchronize.class, new UISynchronize() {

      public void syncExec(final Runnable runnable) {
        if (javafx.application.Platform.isFxApplicationThread()) {
          runnable.run();
        } else {
          RunnableFuture<?> task = new FutureTask<Void>(runnable, null);
         
          javafx.application.Platform.runLater(task);

          try {
            // wait for task to complete
            task.get();
          } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          } catch (ExecutionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          } finally {
            task.cancel(true);
          }
        }
      }

      public void asyncExec(Runnable runnable) {
        javafx.application.Platform.runLater(runnable);
      }
    });
    appContext.set(IApplicationContext.class, applicationContext);
    appContext.set(IResourceUtilities.class, new IResourceUtilities<Image>() {
      private WeakHashMap<URI, WeakReference<Image>> imageCache = new WeakHashMap<URI, WeakReference<Image>>();
     
      public Image imageDescriptorFromURI(URI iconPath) {
        WeakReference<Image> r = imageCache.get(iconPath);
        Image img = null;
        if( r != null ) {
          img = r.get();
        }
       
        if( img == null ) {
          try {
            InputStream in = new URL(iconPath.toString()).openStream();
            img = new Image(in);
            in.close();
            imageCache.put(iconPath, new WeakReference<Image>(img));
          } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          } catch (IOException e) {
            logger.warning("could not find icon at: " + iconPath,e);
          }
        }
       
        return img;
      }
    });

    // Check if DS is running
    if (!appContext.containsKey("org.eclipse.e4.ui.workbench.modeling.EModelService")) {
      throw new IllegalStateException("Core services not available. Please make sure that a declarative service implementation (such as the bundle 'org.eclipse.equinox.ds') is available!");
    }

    // Get the factory to create DI instances with
    IContributionFactory factory = (IContributionFactory) appContext.get(IContributionFactory.class.getName());

    // Install the life-cycle manager for this session if there's one
    // defined
    String lifeCycleURI = getArgValue(E4Workbench.LIFE_CYCLE_URI_ARG, applicationContext, false);
    if (lifeCycleURI != null) {
      lcManager = factory.create(lifeCycleURI, appContext);
      if (lcManager != null) {
        // Let the manager manipulate the appContext if desired
        Boolean rv = (Boolean) ContextInjectionFactory.invoke(lcManager, PostContextCreate.class, appContext, Boolean.TRUE);
        if( rv != null && ! rv.booleanValue() ) {
          return null;
        }
      }
    }
    // Create the app model and its context
    MApplication appModel = loadApplicationModel(applicationContext, appContext);
    appModel.setContext(appContext);

    // Set the app's context after adding itself
    appContext.set(MApplication.class.getName(), appModel);

    // let the life cycle manager add to the model
    if (lcManager != null) {
      ContextInjectionFactory.invoke(lcManager, ProcessAdditions.class, appContext, null);
      ContextInjectionFactory.invoke(lcManager, ProcessRemovals.class, appContext, null);
    }

    // Create the addons
    IEclipseContext addonStaticContext = EclipseContextFactory.create();
    for (MAddon addon : appModel.getAddons()) {
      addonStaticContext.set(MAddon.class, addon);
      Object obj = factory.create(addon.getContributionURI(), appContext, addonStaticContext);
      addon.setObject(obj);
    }

    // Parse out parameters from both the command line and/or the product
View Full Code Here

    return brandingProperty == null ? System.getProperty(argName) : brandingProperty;
  }

  // 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);

      // translation
      String locale = Locale.getDefault().toString();
      serviceContext.set(TranslationService.LOCALE, locale);
      TranslationService bundleTranslationProvider = TranslationProviderFactory
          .bundleTranslationService(serviceContext);
      serviceContext.set(TranslationService.class, bundleTranslationProvider);

      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(LoggerProviderImpl.class, serviceContext));
      }

      return serviceContext;
  }
View Full Code Here

TOP

Related Classes of org.eclipse.e4.core.contexts.IEclipseContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.