示例#1
0
  public BaseView(PartStackUIResources resources) {
    container = new DockLayoutPanel(Style.Unit.PX);
    container.getElement().setAttribute("role", "part");
    container.setSize("100%", "100%");
    container.getElement().getStyle().setOutlineStyle(Style.OutlineStyle.NONE);
    initWidget(container);

    toolBar = new DockLayoutPanel(Style.Unit.PX);
    toolBar.addStyleName(resources.partStackCss().ideBasePartToolbar());
    toolBar.getElement().setAttribute("role", "toolbar");
    toolBar.addDomHandler(
        new MouseUpHandler() {
          @Override
          public void onMouseUp(MouseUpEvent event) {
            // activate last focused element if user clicked on part header
            if (lastFocused != null) {
              lastFocused.setFocus(true);
            }
          }
        },
        MouseUpEvent.getType());
    container.addNorth(toolBar, 23);

    // this hack used for adding box shadow effect to toolbar
    toolBar.getElement().getParentElement().getStyle().setOverflow(Style.Overflow.VISIBLE);

    toolbarHeader = new DockLayoutPanel(Style.Unit.PX);
    toolbarHeader.getElement().setAttribute("role", "toolbar-header");
    toolBar.addNorth(toolbarHeader, 22);

    titleLabel = new Label();
    titleLabel.setStyleName(resources.partStackCss().ideBasePartTitleLabel());
    toolbarHeader.addWest(titleLabel, 200);

    SVGImage minimize = new SVGImage(resources.collapseExpandIcon());
    minimize.getElement().setAttribute("name", "workBenchIconMinimize");
    minimizeButton = new ToolButton(minimize);

    minimizeButton.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            minimize();
          }
        });

    addToolButton(minimizeButton);

    if (minimizeButton.getElement() instanceof elemental.dom.Element) {
      Tooltip.create(
          (elemental.dom.Element) minimizeButton.getElement(),
          PositionController.VerticalAlign.BOTTOM,
          PositionController.HorizontalAlign.MIDDLE,
          "Hide");
    }
  }
示例#2
0
  /** Render Popup Menu component. */
  private void redraw() {
    String idPrefix = itemIdPrefix;
    if (idPrefix == null) {
      idPrefix = "";
    } else {
      idPrefix += "/";
    }

    table = new PopupMenuTable();
    table.setStyleName(POPUP_RESOURCES.popup().popupMenuTable());
    table.setCellPadding(0);
    table.setCellSpacing(0);

    for (int i = 0; i < list.size(); i++) {
      Action menuItem = list.get(i);

      if (menuItem instanceof Separator) {
        final String separatorText = ((Separator) menuItem).getText();
        if (separatorText == null) {
          table.getCellFormatter().setStyleName(i, 0, POPUP_RESOURCES.popup().popupMenuDelimiter());
        } else {
          table.setWidget(i, 0, new Label(separatorText));
          table
              .getCellFormatter()
              .setStyleName(i, 0, POPUP_RESOURCES.popup().popupMenuTextDelimiter());
        }
        table.getFlexCellFormatter().setColSpan(i, 0, hasCheckedItems ? 5 : 4);
      } else {
        Presentation presentation = presentationFactory.getPresentation(menuItem);

        if (presentation.getImageResource() != null) {
          Image image = new Image(presentation.getImageResource());
          table.setWidget(i, 0, image);

        } else if (presentation.getSVGResource() != null) {
          SVGImage image = new SVGImage(presentation.getSVGResource());
          table.setWidget(i, 0, image);
        } else if (presentation.getHTMLResource() != null) {
          table.setHTML(i, 0, presentation.getHTMLResource());
        }
        table
            .getCellFormatter()
            .setStyleName(
                i,
                0,
                presentation.isEnabled()
                    ? POPUP_RESOURCES.popup().popupMenuIconField()
                    : POPUP_RESOURCES.popup().popupMenuIconFieldDisabled());

        int work = 1;
        if (hasCheckedItems && menuItem instanceof ToggleAction) {
          ToggleAction toggleAction = (ToggleAction) menuItem;
          ActionEvent e =
              new ActionEvent(
                  presentationFactory.getPresentation(toggleAction),
                  actionManager,
                  managerProvider.get());

          if (toggleAction.isSelected(e)) {
            // Temporary solution
            table.setHTML(i, work, "<i class=\"fa fa-check\"></i>");
          }

          table
              .getCellFormatter()
              .setStyleName(
                  i,
                  work,
                  presentation.isEnabled()
                      ? POPUP_RESOURCES.popup().popupMenuCheckField()
                      : POPUP_RESOURCES.popup().popupMenuCheckFieldDisabled());
          work++;
        }

        table.setHTML(
            i,
            work,
            "<nobr id=\""
                + idPrefix
                + presentation.getText()
                + "\">"
                + presentation.getText()
                + "</nobr>");
        table
            .getCellFormatter()
            .setStyleName(
                i,
                work,
                presentation.isEnabled()
                    ? POPUP_RESOURCES.popup().popupMenuTitleField()
                    : POPUP_RESOURCES.popup().popupMenuTitleFieldDisabled());
        if (showTooltips) {
          Tooltip.create(
              (elemental.dom.Element) table.getCellFormatter().getElement(i, work),
              BOTTOM,
              MIDDLE,
              presentation.getText());
        }

        work++;
        String hotKey =
            KeyMapUtil.getShortcutText(
                keyBindingAgent.getKeyBinding(actionManager.getId(menuItem)));
        if (hotKey == null) {
          hotKey = "&nbsp;";
        } else {
          hotKey = "<nobr>&nbsp;" + hotKey + "&nbsp;</nobr>";
        }

        table.setHTML(i, work, hotKey);
        table
            .getCellFormatter()
            .setStyleName(
                i,
                work,
                presentation.isEnabled()
                    ? POPUP_RESOURCES.popup().popupMenuHotKeyField()
                    : POPUP_RESOURCES.popup().popupMenuHotKeyFieldDisabled());

        work++;

        if (menuItem instanceof ActionGroup
            && !(((ActionGroup) menuItem).canBePerformed()
                && !Utils.hasVisibleChildren(
                    (ActionGroup) menuItem,
                    presentationFactory,
                    actionManager,
                    managerProvider.get()))) {
          table.setWidget(i, work, new SVGImage(POPUP_RESOURCES.subMenu()));
          table
              .getCellFormatter()
              .setStyleName(
                  i,
                  work,
                  presentation.isEnabled()
                      ? POPUP_RESOURCES.popup().popupMenuSubMenuField()
                      : POPUP_RESOURCES.popup().popupMenuSubMenuFieldDisabled());
        } else {
          table
              .getCellFormatter()
              .setStyleName(
                  i,
                  work,
                  presentation.isEnabled()
                      ? POPUP_RESOURCES.popup().popupMenuSubMenuField()
                      : POPUP_RESOURCES.popup().popupMenuSubMenuFieldDisabled());
        }

        work++;

        table.getRowFormatter().getElement(i).setAttribute("item-index", Integer.toString(i));
        table
            .getRowFormatter()
            .getElement(i)
            .setAttribute("item-enabled", Boolean.toString(presentation.isEnabled()));

        String actionId = actionManager.getId(menuItem);
        String debugId;
        if (actionId == null) {
          debugId = idPrefix + menuItem.getTemplatePresentation().getText();
        } else {
          debugId = idPrefix + actionId;
        }
        UIObject.ensureDebugId(table.getRowFormatter().getElement(i), debugId);
      }
    }

    popupMenuPanel.add(table);
  }