public void handleEvent(Event event) {
          Object changedObj = event.getProperty(UIEvents.EventTags.ELEMENT);
          if (!(changedObj instanceof MTrimmedWindow)) return;

          MTrimmedWindow window = (MTrimmedWindow) changedObj;
          if (window.getWidget() == null) return;

          String eventType = (String) event.getProperty(UIEvents.EventTags.TYPE);
          if (UIEvents.EventTypes.ADD.equals(eventType)) {
            MUIElement added = (MUIElement) event.getProperty(UIEvents.EventTags.NEW_VALUE);
            if (added.isToBeRendered()) createGui(added, window.getWidget(), window.getContext());
          } else if (UIEvents.EventTypes.REMOVE.equals(eventType)) {
            MUIElement removed = (MUIElement) event.getProperty(UIEvents.EventTags.OLD_VALUE);
            if (removed.getRenderer() != null) removeGui(removed);
          }
        }
Пример #2
0
        @Override
        public void handleEvent(Event event) {
          Object changedObj = event.getProperty(EventTags.ELEMENT);

          if (!(changedObj instanceof MPerspectiveStack)) {
            return;
          }

          final MPerspectiveStack changedElement = (MPerspectiveStack) changedObj;

          String eventType = (String) event.getProperty(UIEvents.EventTags.TYPE);
          String tag = (String) event.getProperty(UIEvents.EventTags.NEW_VALUE);
          String oldVal = (String) event.getProperty(UIEvents.EventTags.OLD_VALUE);

          if (UIEvents.EventTypes.ADD.equals(eventType) && Tags.ICONS_ONLY.equals(tag)) {
            for (Map.Entry<MPerspective, TwoStateToolbarButton> entry :
                perspective_button.entrySet()) {
              MPerspective perspective = entry.getKey();
              TwoStateToolbarButton button = entry.getValue();

              button.setLabelAndIcon(null, Commons.trim(perspective.getIconURI()));

              ContextMenu menu = button2ContextMenu.get(button);
              //					menu.removeItem(showTextItem);
              //					showTextItem = menu.addItem("Show Text");
              //					showTextItem.addStyleName("close-perspective-item"); //bugfixing style for ie9
              // (context menu addon has bug for ie9)
            }
          } else if (UIEvents.EventTypes.REMOVE.equals(eventType)
              && Tags.ICONS_ONLY.equals(oldVal)) {
            for (Map.Entry<MPerspective, TwoStateToolbarButton> entry :
                perspective_button.entrySet()) {
              MPerspective perspective = entry.getKey();
              TwoStateToolbarButton button = entry.getValue();
              button.setLabelAndIcon(
                  Commons.trim(perspective.getLabel()), Commons.trim(perspective.getIconURI()));

              ContextMenu menu = button2ContextMenu.get(button);
              //					menu.removeItem(showTextItem);
              //					showTextItem = menu.addItem("Hide Text");
              //					showTextItem.addStyleName("close-perspective-item"); //bugfixing style for ie9
              // (context menu addon has bug for ie9)
            }
          }
        }
        public void handleEvent(Event event) {

          Object changedObj = event.getProperty(UIEvents.EventTags.ELEMENT);
          if (!(changedObj instanceof MElementContainer<?>)) return;

          MElementContainer<MUIElement> changedElement = (MElementContainer<MUIElement>) changedObj;
          boolean isApplication = changedObj instanceof MApplication;

          boolean menuChild = changedObj instanceof MMenu;
          // If the parent isn't in the UI then who cares?
          AbstractPartRenderer renderer = getRendererFor(changedElement);
          if ((!isApplication && renderer == null) || menuChild) return;

          String eventType = (String) event.getProperty(UIEvents.EventTags.TYPE);
          if (UIEvents.EventTypes.ADD.equals(eventType)) {
            Activator.trace(Policy.DEBUG_RENDERER, "Child Added", null); // $NON-NLS-1$
            MUIElement added = (MUIElement) event.getProperty(UIEvents.EventTags.NEW_VALUE);

            // OK, we have a new -visible- part we either have to create
            // it or host it under the correct parent. Note that we
            // explicitly do *not* render non-selected elements in
            // stacks (to support lazy loading).
            boolean isStack = changedObj instanceof MGenericStack<?>;
            boolean hasWidget = added.getWidget() != null;
            boolean isSelected = added == changedElement.getSelectedElement();
            boolean renderIt = !isStack || hasWidget || isSelected;
            if (renderIt) {
              // NOTE: createGui will call 'childAdded' if successful
              Object w = createGui(added);
              if (w instanceof Control && !(w instanceof Shell)) {
                final Control ctrl = (Control) w;
                fixZOrder(added);
                if (!ctrl.isDisposed()) {
                  ctrl.getShell().layout(new Control[] {ctrl}, SWT.DEFER);
                }
              }
            } else {
              if (renderer != null && added.isToBeRendered())
                renderer.childRendered(changedElement, added);
            }

            // If the element being added is a placeholder, check to see if
            // it's 'globally visible' and, if so, remove all other
            // 'local' placeholders referencing the same element.
            int newLocation = modelService.getElementLocation(added);
            if (newLocation == EModelService.IN_SHARED_AREA
                || newLocation == EModelService.OUTSIDE_PERSPECTIVE) {
              MWindow topWin = modelService.getTopLevelWindowFor(added);
              modelService.hideLocalPlaceholders(topWin, null);
            }
          } else if (UIEvents.EventTypes.REMOVE.equals(eventType)) {
            Activator.trace(Policy.DEBUG_RENDERER, "Child Removed", null); // $NON-NLS-1$
            MUIElement removed = (MUIElement) event.getProperty(UIEvents.EventTags.OLD_VALUE);
            // Removing invisible elements is a NO-OP as far as the
            // renderer is concerned
            if (!removed.isToBeRendered()) return;

            if (removed.getWidget() instanceof Control) {
              Control ctrl = (Control) removed.getWidget();
              ctrl.setLayoutData(null);
              ctrl.getParent().layout(new Control[] {ctrl}, SWT.CHANGED | SWT.DEFER);
            }

            // Ensure that the element about to be removed is not the
            // selected element
            if (changedElement.getSelectedElement() == removed)
              changedElement.setSelectedElement(null);

            if (renderer != null) renderer.hideChild(changedElement, removed);
          }
        }