@PostConstruct
  void init() {
    eventBroker.subscribe(UIEvents.ElementContainer.TOPIC_CHILDREN, childrenHandler);
    eventBroker.subscribe(UIEvents.UIElement.TOPIC_TOBERENDERED, toBeRenderedHandler);
    eventBroker.subscribe(UIEvents.ElementContainer.TOPIC_SELECTEDELEMENT, selectionHandler);
    eventBroker.subscribe(UIEvents.UILabel.TOPIC_ALL, labelHandler);

    setPropertyChangeListener();
  }
 @PostConstruct
 void postConstruct() {
   eventBroker.subscribe(UIEvents.ElementContainer.TOPIC_SELECTEDELEMENT, selectedHandler);
   eventBroker.subscribe(UIEvents.ApplicationElement.TOPIC_TAGS, minimizedPartHandler);
   constructed = true;
   partActivationHistory = new PartActivationHistory(this, modelService);
   if (activePart != null) {
     partActivationHistory.prepend(activePart);
   }
 }
  @PostConstruct
  public void init() {
    eventBroker.subscribe(UIEvents.UILabel.TOPIC_ALL, itemUpdater);
    eventBroker.subscribe(UIEvents.Item.TOPIC_SELECTED, selectionUpdater);
    eventBroker.subscribe(UIEvents.Item.TOPIC_ENABLED, enabledUpdater);
    eventBroker.subscribe(UIEvents.UIElement.TOPIC_ALL, toBeRenderedUpdater);
    eventBroker.subscribe(ElementContainer.TOPIC_CHILDREN, childAdditionUpdater);

    context.set(ToolBarManagerRenderer.class, this);
  }
  @PostConstruct
  public void init() {
    eventBroker.subscribe(UIEvents.UILabel.TOPIC_ALL, itemUpdater);
    eventBroker.subscribe(UIEvents.Item.TOPIC_SELECTED, selectionUpdater);
    eventBroker.subscribe(UIEvents.Item.TOPIC_ENABLED, enabledUpdater);
    eventBroker.subscribe(UIEvents.UIElement.TOPIC_ALL, toBeRenderedUpdater);

    context.set(MenuManagerRenderer.class, this);
    Display display = context.get(Display.class);
    rendererFilter = ContextInjectionFactory.make(MenuManagerRendererFilter.class, context);
    display.addFilter(SWT.Show, rendererFilter);
    display.addFilter(SWT.Hide, rendererFilter);
    display.addFilter(SWT.Dispose, rendererFilter);
    context.set(MenuManagerRendererFilter.class, rendererFilter);
  }
 private void registerModelListeners() {
   additionHandler =
       new EventHandler() {
         public void handleEvent(Event event) {
           Object elementObj = event.getProperty(UIEvents.EventTags.ELEMENT);
           if (elementObj instanceof MBindingContext) {
             if (UIEvents.isADD(event)) {
               for (Object newObj : UIEvents.asIterable(event, UIEvents.EventTags.NEW_VALUE)) {
                 if (newObj instanceof MBindingContext) {
                   MBindingContext newCtx = (MBindingContext) newObj;
                   defineContexts((MBindingContext) elementObj, newCtx);
                 }
               }
             } else if (UIEvents.isREMOVE(event)) {
               for (Object oldObj : UIEvents.asIterable(event, UIEvents.EventTags.OLD_VALUE)) {
                 if (oldObj instanceof MBindingContext) {
                   MBindingContext oldCtx = (MBindingContext) oldObj;
                   undefineContext(oldCtx);
                 }
               }
             }
           }
         }
       };
   broker.subscribe(UIEvents.BindingContext.TOPIC_CHILDREN, additionHandler);
 }
  /**
   * 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);
    }
  }
  /**
   * This is a singleton service. One instance is used throughout the running application
   *
   * @param appContext The applicationContext to get the eventBroker from
   * @throws NullPointerException if the given appContext is <code>null</code>
   */
  public ModelServiceImpl(IEclipseContext appContext) {
    if (appContext == null) {
      throw new NullPointerException("No application context given!"); // $NON-NLS-1$
    }

    this.appContext = appContext;
    IEventBroker eventBroker = appContext.get(IEventBroker.class);
    eventBroker.subscribe(UIEvents.UIElement.TOPIC_WIDGET, hostedElementHandler);

    mApplicationElementFactory =
        new GenericMApplicationElementFactoryImpl(appContext.get(IExtensionRegistry.class));
  }
 private void registerModelListeners() {
   additionHandler =
       new EventHandler() {
         @Override
         public void handleEvent(Event event) {
           if (application == event.getProperty(UIEvents.EventTags.ELEMENT)) {
             if (UIEvents.isADD(event)) {
               for (Object obj : UIEvents.asIterable(event, UIEvents.EventTags.NEW_VALUE)) {
                 if (obj instanceof MCommand) {
                   createCommand((MCommand) obj);
                 } else if (obj instanceof MCategory) {
                   createCategory((MCategory) obj);
                 }
               }
             }
           }
         }
       };
   broker.subscribe(UIEvents.Application.TOPIC_COMMANDS, additionHandler);
   broker.subscribe(UIEvents.Application.TOPIC_CATEGORIES, additionHandler);
 }
 @Execute
 public void onExecute() {
   eventBroker.subscribe(
       IThemeEngine.Events.THEME_CHANGED,
       new EventHandler() {
         public void handleEvent(Event event) {
           ITheme currentTheme = (ITheme) event.getProperty(IThemeEngine.Events.THEME);
           //						if (!prefDarker.getBoolean(
           //								THEME_DARKER_PREF_THEMEENABLED, false))
           if (currentTheme.getId().equals(THEME_DARKER_ID)) {
             setupPreferences();
             isLastThemeDarker = true;
           } else if (isLastThemeDarker) {
             setToDefaultPreferences();
           }
         }
       });
 }
  /** Hooks a listener that tweaks newly opened workbench window shells with the proper OS flags. */
  protected void hookWorkbenchListeners() {
    // watch for a window's "widget" attribute being flipped to a shell
    shellListener =
        new EventHandler() {
          public void handleEvent(org.osgi.service.event.Event event) {
            if (event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MWindow
                && event.getProperty(UIEvents.EventTags.NEW_VALUE) != null) {
              MWindow window = (MWindow) event.getProperty(UIEvents.EventTags.ELEMENT);
              modifyWindowShell(window);
              updateFullScreenStatus(window);
            }
          }
        };
    eventBroker.subscribe(UIEvents.UIElement.TOPIC_WIDGET, shellListener);

    // this listener is handling the Eclipse 4.0 compatibility case,
    // where the window is created without a main menu or trim first,
    // and then later when the main menu is being set it is time
    // for us to do our work. It also handles dynamically created
    // windows too.
    menuListener =
        new EventHandler() {
          public void handleEvent(org.osgi.service.event.Event event) {
            Object newValue = event.getProperty(UIEvents.EventTags.NEW_VALUE);
            Object oldValue = event.getProperty(UIEvents.EventTags.OLD_VALUE);
            Object element = event.getProperty(UIEvents.EventTags.ELEMENT);
            if (element instanceof MWindow && oldValue == null && newValue instanceof MMenu) {
              modifyWindowShell((MWindow) element);
            }
          }
        };
    eventBroker.subscribe(UIEvents.Window.TOPIC_MAINMENU, menuListener);

    // watch for new menu contributions
    menuContributionListener =
        new EventHandler() {
          public void handleEvent(org.osgi.service.event.Event event) {
            if (event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MMenuContribution
                && event.getProperty(UIEvents.EventTags.NEW_VALUE) != null) {
              MMenuContribution contribution =
                  (MMenuContribution) event.getProperty(UIEvents.EventTags.ELEMENT);
              processMenuContribution(contribution);
            }
          }
        };
    eventBroker.subscribe(
        UIEvents.MenuContributions.TOPIC_MENUCONTRIBUTIONS, menuContributionListener);

    // watch for command changes
    commandListener =
        new EventHandler() {
          public void handleEvent(org.osgi.service.event.Event event) {
            if (event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MCommand) {
              MCommand cmd = (MCommand) event.getProperty(UIEvents.EventTags.ELEMENT);
              String id = cmd.getElementId();
              if (COMMAND_ID_ABOUT.equals(id)
                  || COMMAND_ID_PREFERENCES.equals(id)
                  || COMMAND_ID_QUIT.equals(id)) {
                hookApplicationMenu();
              }
            }
          }
        };
    eventBroker.subscribe(UIEvents.Application.TOPIC_COMMANDS, commandListener);

    // watch for a window's full-screen tag being flipped
    tagListener =
        new EventHandler() {
          public void handleEvent(org.osgi.service.event.Event event) {
            if (event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MWindow) {
              MWindow window = (MWindow) event.getProperty(UIEvents.EventTags.ELEMENT);
              updateFullScreenStatus(window);
            }
          }
        };
    eventBroker.subscribe(UIEvents.ApplicationElement.TOPIC_TAGS, tagListener);
  }
  @PostConstruct
  void init(IEventBroker eventBroker) {
    eventBroker.subscribe(
        UIEvents.ElementContainer.TOPIC_CHILDREN,
        new EventHandler() {

          @Override
          public void handleEvent(Event event) {
            Object changedObj = event.getProperty(UIEvents.EventTags.ELEMENT);
            if (changedObj instanceof MPerspectiveStack) {
              MPerspectiveStack parent = (MPerspectiveStack) changedObj;
              if (BasePerspectiveStackRenderer.this == parent.getRenderer()) {
                String eventType = (String) event.getProperty(UIEvents.EventTags.TYPE);

                if (UIEvents.EventTypes.ADD.equals(eventType)) {
                  MUIElement element = (MUIElement) event.getProperty(UIEvents.EventTags.NEW_VALUE);
                  handleChildAddition(parent, (MPerspective) element);
                } else if (UIEvents.EventTypes.REMOVE.equals(eventType)) {
                  MUIElement element = (MUIElement) event.getProperty(UIEvents.EventTags.OLD_VALUE);
                  handleChildRemove(parent, (MPerspective) element);
                }
              }
            }
          }
        });
    eventBroker.subscribe(
        UIEvents.ElementContainer.TOPIC_SELECTEDELEMENT,
        new EventHandler() {

          @Override
          public void handleEvent(Event event) {
            Object changedObj = event.getProperty(UIEvents.EventTags.ELEMENT);
            if (changedObj instanceof MPerspectiveStack) {
              MPerspectiveStack parent = (MPerspectiveStack) changedObj;
              if (BasePerspectiveStackRenderer.this == parent.getRenderer()) {
                String eventType = (String) event.getProperty(UIEvents.EventTags.TYPE);
                if (UIEvents.EventTypes.SET.equals(eventType)) {
                  MUIElement newValue =
                      (MUIElement) event.getProperty(UIEvents.EventTags.NEW_VALUE);
                  MUIElement oldValue =
                      (MUIElement) event.getProperty(UIEvents.EventTags.OLD_VALUE);
                  handleSelectedElement(parent, (MPerspective) oldValue, (MPerspective) newValue);
                }
              }
            }
          }
        });
    eventBroker.subscribe(
        UIEvents.UIElement.TOPIC_VISIBLE,
        new EventHandler() {

          @Override
          public void handleEvent(Event event) {
            MUIElement changedObj = (MUIElement) event.getProperty(UIEvents.EventTags.ELEMENT);
            if (changedObj.isToBeRendered()) {
              MUIElement parent = changedObj.getParent();
              // Can be null for e.g. detached windows!!!
              if (parent != null) {
                if (BasePerspectiveStackRenderer.this == parent.getRenderer()) {
                  MPerspectiveStack stack = (MPerspectiveStack) parent;
                  String eventType = (String) event.getProperty(UIEvents.EventTags.TYPE);
                  if (UIEvents.EventTypes.SET.equals(eventType)) {
                    Boolean newValue = (Boolean) event.getProperty(UIEvents.EventTags.NEW_VALUE);
                    if (newValue.booleanValue()) {
                      // TODO Is childRendered not dangerous to call
                      // here??
                      childRendered(stack, changedObj);
                    } else {
                      hideChild(stack, changedObj);
                    }
                  }
                }
              }
            }
          }
        });
  }
 @PostConstruct
 public void postConstruct() {
   eventBroker.subscribe(
       UIEvents.ElementContainer.TOPIC_SELECTEDELEMENT, selectPerspectiveHandler);
   eventBroker.subscribe(UIEvents.ApplicationElement.TOPIC_TAGS, tagListener);
 }
  @Override
  public void hookControllerLogic(final MUIElement element) {
    if (element instanceof MWindow) {
      final MWindow mWindow = (MWindow) element;
      final Shell shell = (Shell) mWindow.getWidget();

      EventHandler sizeHandler =
          new EventHandler() {
            @Override
            public void handleEvent(Event event) {

              // Ensure that this event is for a MMenuItem
              Object objElement = event.getProperty(UIEvents.EventTags.ELEMENT);
              if (!(objElement instanceof MWindow)) {
                return;
              }

              // Is this listener interested ?
              final MWindow window = (MWindow) objElement;
              if (window.getRenderer() != WorkbenchWindowRenderer.this) {
                return;
              }

              // No widget == nothing to update
              if (shell == null) {
                return;
              }

              String attName = (String) event.getProperty(UIEvents.EventTags.ATTNAME);

              if (UIEvents.Window.X.equals(attName)
                  || UIEvents.Window.Y.equals(attName)
                  || UIEvents.Window.WIDTH.equals(attName)
                  || UIEvents.Window.HEIGHT.equals(attName)) {
                shell
                    .getDisplay()
                    .asyncExec(
                        new Runnable() {

                          @Override
                          public void run() {
                            shell.setBounds(
                                window.getX(),
                                window.getY(),
                                window.getWidth(),
                                window.getHeight());
                          }
                        });
              }
            }
          };

      eventBroker.subscribe(UIEvents.Window.TOPIC_ALL, sizeHandler);

      shell.addControlListener(
          new ControlListener() {
            @Override
            public void controlResized(ControlEvent e) {
              // Don't store the maximized size in the model
              if (shell.getMaximized()) {
                return;
              }

              mWindow.setWidth(shell.getSize().x);
              mWindow.setHeight(shell.getSize().y);
            }

            @Override
            public void controlMoved(ControlEvent e) {
              // Don't store the maximized size in the model
              if (shell.getMaximized()) {
                return;
              }

              mWindow.setX(shell.getLocation().x);
              mWindow.setY(shell.getLocation().y);
            }
          });
    }
  }
 @PostConstruct
 public void pc(IEventBroker broker) {
   broker.subscribe(MediaConstants.mediaEntrySelected, meidaSelectedHandler);
   broker.subscribe(MediaConstants.mediaEntryChanged, mediaChangedHandler);
 }