private void fillArgs(Object[] actualArgs, String[] keys, boolean[] active) {
   for (int i = 0; i < keys.length; i++) {
     if (keys[i] == null) continue;
     IEclipseContext targetContext = (active[i]) ? context.getActiveLeaf() : context;
     if (ECLIPSE_CONTEXT_NAME.equals(keys[i])) actualArgs[i] = targetContext;
     else if (targetContext.containsKey(keys[i])) actualArgs[i] = targetContext.get(keys[i]);
   }
 }
    @Override
    public boolean update(IEclipseContext eventsContext, int eventType, Object[] extraArguments) {
      if (eventType == ContextChangeEvent.INITIAL) {
        // needs to be done inside runnable to establish dependencies
        for (int i = 0; i < keys.length; i++) {
          if (keys[i] == null) continue;
          IEclipseContext targetContext = (active[i]) ? context.getActiveLeaf() : context;
          if (ECLIPSE_CONTEXT_NAME.equals(keys[i])) {
            result[i] = targetContext;
            IEclipseContext parent = targetContext.getParent(); // creates pseudo-link
            if (parent == null)
              targetContext.get(ECLIPSE_CONTEXT_NAME); // pseudo-link in case there is no parent
          } else if (targetContext.containsKey(keys[i])) result[i] = targetContext.get(keys[i]);
        }
        return true;
      }

      if (eventType == ContextChangeEvent.DISPOSE) {
        if (eventsContext == context) {
          ContextObjectSupplier originatingSupplier =
              eventsContext.getLocal(ContextObjectSupplier.class);
          requestor.disposed(originatingSupplier);
          return false;
        }
      } else if (eventType == ContextChangeEvent.UNINJECTED) {
        if (eventsContext == context) {
          ContextObjectSupplier originatingSupplier =
              eventsContext.getLocal(ContextObjectSupplier.class);
          return requestor.uninject(extraArguments[0], originatingSupplier);
        }
      } else {
        if (!requestor.isValid()) return false; // remove this listener
        requestor.resolveArguments(false);
        requestor.execute();
      }
      return true;
    }
Ejemplo n.º 3
0
 public static void initializeServices(MApplication appModel) {
   IEclipseContext appContext = appModel.getContext();
   // make sure we only add trackers once
   if (appContext.containsKey(CONTEXT_INITIALIZED)) return;
   appContext.set(CONTEXT_INITIALIZED, "true");
   initializeApplicationServices(appContext);
   List<MWindow> windows = appModel.getChildren();
   for (MWindow childWindow : windows) {
     initializeWindowServices(childWindow);
   }
   ((EObject) appModel)
       .eAdapters()
       .add(
           new AdapterImpl() {
             @Override
             public void notifyChanged(Notification notification) {
               if (notification.getFeatureID(MApplication.class)
                   != UiPackageImpl.ELEMENT_CONTAINER__CHILDREN) return;
               if (notification.getEventType() != Notification.ADD) return;
               MWindow childWindow = (MWindow) notification.getNewValue();
               initializeWindowServices(childWindow);
             }
           });
 }