예제 #1
0
  private void initializedPerspectiveSwticherPanel(MPerspectiveStack perspectiveStack) {
    if (perspectiveSwitcherPanel != null) return;
    // initialize perspective switcher panel
    perspectiveStackForSwitcher = perspectiveStack;
    boolean iconsOnly = perspectiveStackForSwitcher.getTags().contains(Tags.ICONS_ONLY);

    perspectiveSwitcherPanel = new HorizontalLayout();
    perspectiveSwitcherPanel.setStyleName("perspectivepanel");
    perspectiveSwitcherPanel.setSizeUndefined();

    Button openPerspectiveButton = new Button("Open");
    openPerspectiveButton.addStyleName("vaaclipsebutton");
    openPerspectiveButton.addStyleName("icononly");
    openPerspectiveButton.setIcon(
        new ThemeResource("../vaaclipse_default_theme/img/open_perspective.png"));
    perspectiveSwitcherPanel.addComponent(openPerspectiveButton);

    openPerspectiveButton.addListener(
        new Button.ClickListener() {

          @Override
          public void buttonClick(ClickEvent event) {
            openOpenPerspectiveWindow();

            // change focus
            Component parent = event.getButton().getParent();
            while (parent != null) {
              if (parent instanceof Component.Focusable) {
                ((Component.Focusable) parent).focus();
                break;
              } else {
                parent = parent.getParent();
              }
            }
          }
        });

    // add separator between openPerspectiveButton and perspective's buttons
    Label separator = new Label();
    separator.setSizeUndefined();
    separator.addStyleName("horizontalseparator");
    separator.setHeight("100%");
    perspectiveSwitcherPanel.addComponent(separator);

    // add buttons to perspective switch panel
    for (final MPerspective perspective : perspectiveStackForSwitcher.getChildren()) {
      Component button = createPerspectiveButton(perspective);
      if (button != null) perspectiveSwitcherPanel.addComponent(button);
    }
  }
예제 #2
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;
  }