コード例 #1
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)
            }
          }
        }
コード例 #2
0
  private void changeShowText(boolean showText) {
    ToolItem[] items = psTB.getItems();
    for (int i = 0; i < items.length; i++) {
      MPerspective persp = (MPerspective) items[i].getData();
      if (persp != null)
        if (showText) {
          if (persp.getLabel() != null) items[i].setText(persp.getLocalizedLabel());
          items[i].setToolTipText(persp.getLocalizedTooltip());
        } else {
          Image image = items[i].getImage();
          if (image != null) {
            items[i].setText(""); // $NON-NLS-1$
            items[i].setToolTipText(persp.getLocalizedLabel());
          }
        }
    }

    // update the size
    fixSize();
  }
コード例 #3
0
  private Component createPerspectiveButton(final MPerspective perspective) {
    if (!perspective.isVisible()) return null;
    boolean iconsOnly = perspectiveStackForSwitcher.getTags().contains(Tags.ICONS_ONLY);
    String label = iconsOnly ? null : Commons.trim(perspective.getLabel());
    String iconURI = Commons.trim(perspective.getIconURI());

    final TwoStateToolbarButton button = new TwoStateToolbarButton(label, iconURI);

    if (perspective.getTooltip() != null) {
      button.setDescription(perspective.getLocalizedTooltip());
    }

    button.addListener(
        new ClickListener() {

          public void buttonClick(ClickEvent event) {
            MPerspectiveStack perspectiveStack =
                (MPerspectiveStack) (MElementContainer<?>) perspective.getParent();
            switchPerspective(perspective);
          }
        });

    // TODO: replace VerticalLayout on more thin layout (for example SimpleLayout addon which
    // consist of just one div)
    //		 VerticalLayout wrapperLayout = new VerticalLayout();
    //		 wrapperLayout.setSizeUndefined();
    //		 wrapperLayout.addComponent(button);
    //		 wrapperLayout.addListener(new LayoutEvents.LayoutClickListener() {
    //
    //			 @Override
    //			 public void layoutClick(LayoutClickEvent event)
    //			 {
    //				 if (LayoutClickEvent.BUTTON_RIGHT == event.getButton())
    //				 {
    //					 lastClickedPerspective = perspective;
    ////					 menu.open(event.getClientX(), event.getClientY());
    //				 }
    //			 }
    //		 });

    // Create context menu
    // Context menu
    ContextMenu menu = new ContextMenu();
    contextMenu2Button.put(menu, button);
    button2ContextMenu.put(button, menu);

    final ContextMenuItem showTextItem;

    final ContextMenuItem closeItem = menu.addItem("Close");
    // closeItem.setSeparatorVisible(true);

    if (iconsOnly) showTextItem = menu.addItem("Show Text");
    else showTextItem = menu.addItem("Hide Text");

    // showTextItem.addStyleName("close-perspective-item"); //bugfixing style for ie9 (context menu
    // addon has bug for ie9)

    menu.addItemClickListener(
        new ContextMenu.ContextMenuItemClickListener() {

          @Override
          public void contextMenuItemClicked(ContextMenuItemClickEvent event) {
            ContextMenuItem clickedItem = (ContextMenuItem) event.getSource();

            if (clickedItem == closeItem) {
              if (perspective == activePerspective) {
                MPerspective prevRenderableAndVisiblePerspective = null,
                    nextRenderableAndVisiblePerspective = null;
                boolean startSearch = false;
                for (MPerspective p : perspectiveStackForSwitcher.getChildren()) {
                  if (startSearch && p.isToBeRendered() && p.isVisible()) {
                    nextRenderableAndVisiblePerspective = p;
                    break;
                  }

                  if (p == perspective) startSearch = true;

                  if (!startSearch && p.isToBeRendered() && p.isVisible()) {
                    prevRenderableAndVisiblePerspective = p;
                  }
                }

                MPerspective newSelectedPerspective =
                    nextRenderableAndVisiblePerspective != null
                        ? nextRenderableAndVisiblePerspective
                        : prevRenderableAndVisiblePerspective;

                if (newSelectedPerspective != null) switchPerspective(newSelectedPerspective);
              }

              perspective.setToBeRendered(false);
            } else if (clickedItem == showTextItem) {
              if (perspectiveStackForSwitcher.getTags().contains(Tags.ICONS_ONLY))
                perspectiveStackForSwitcher.getTags().remove(Tags.ICONS_ONLY);
              else perspectiveStackForSwitcher.getTags().add(Tags.ICONS_ONLY);
            }
          }
        });

    menu.setAsContextMenuOf(button);

    perspective_button.put(perspective, button);
    // return wrapperLayout;
    return button;
  }