Package com.sencha.gxt.widget.core.client.menu

Examples of com.sencha.gxt.widget.core.client.menu.MenuItem$MenuItemAppearance


    if (w instanceof SeparatorToolItem) {
      menu.add(new SeparatorMenuItem());

    } else if (w instanceof SplitButton) {
      final SplitButton sb = (SplitButton) w;
      MenuItem item = new MenuItem(sb.getText(), sb.getIcon());
      item.setEnabled(sb.isEnabled());
      item.setItemId(sb.getItemId());
      if (sb.getData("gxt-menutext") != null) {
        item.setText(sb.getData("gxt-menutext").toString());
      }
      if (sb.getMenu() != null) {
        item.setSubMenu(sb.getMenu());
      }

      item.addSelectionHandler(new SelectionHandler<Item>() {

        @Override
        public void onSelection(SelectionEvent<Item> event) {
          sb.fireEvent(new SelectEvent());
        }
      });
      menu.add(item);

    } else if (w instanceof TextButton) {
      final TextButton b = (TextButton) w;

      MenuItem item = new MenuItem(b.getText(), b.getIcon());
      item.setItemId(b.getItemId());

      if (b.getData("gxt-menutext") != null) {
        item.setText(b.getData("gxt-menutext").toString());
      }
      if (b.getMenu() != null) {
        item.setHideOnClick(false);
        item.setSubMenu(b.getMenu());
      }
      item.setEnabled(b.isEnabled());

      item.addSelectionHandler(new SelectionHandler<Item>() {

        @Override
        public void onSelection(SelectionEvent<Item> event) {
          b.fireEvent(new SelectEvent());
        }
      });

      menu.add(item);
    } else if (w instanceof ButtonGroup) {
      ButtonGroup g = (ButtonGroup) w;
      g.setItemId(g.getItemId());
      menu.add(new SeparatorMenuItem());
      String heading = g.getHeadingText();
      if (heading != null && heading.length() > 0 && !heading.equals("&#160;")) {
        menu.add(new HeaderMenuItem(heading));
      }

      Widget con = g.getWidget();
      if (con != null && con instanceof HasWidgets) {
        HasWidgets widgets = (HasWidgets) con;
        Iterator<Widget> it = widgets.iterator();
        while (it.hasNext()) {
          addWidgetToMenu(menu, it.next());
        }
      }

      menu.add(new SeparatorMenuItem());
    } else if (w instanceof ToggleButton) {
      final ToggleButton b = (ToggleButton) w;

      final CheckMenuItem item = new CheckMenuItem(b.getText());
      item.setItemId(b.getItemId());
      item.setChecked(b.getValue());

      if (b.getData("gxt-menutext") != null) {
        item.setText(b.getData("gxt-menutext").toString());
      }

      item.setEnabled(b.isEnabled());

      item.addCheckChangeHandler(new CheckChangeHandler<CheckMenuItem>() {

        @Override
        public void onCheckChange(CheckChangeEvent<CheckMenuItem> event) {
          // must pass true to cause value change event to fire
          b.setValue(event.getItem().isChecked(), true);
View Full Code Here


          public void onHide(HideEvent event) {
            contextMenuItem = null;
          }
        });

        closeContextMenu.add(new MenuItem(getMessages().closeTab(), new SelectionHandler<MenuItem>() {
          @Override
          public void onSelection(SelectionEvent<MenuItem> event) {
            close(contextMenuItem);
          }
        }));

        closeContextMenu.add(new MenuItem(getMessages().closeOtherTabs(), new SelectionHandler<MenuItem>() {
          @Override
          public void onSelection(SelectionEvent<MenuItem> event) {
            List<Widget> widgets = new ArrayList<Widget>();
            for (int i = 0, len = getWidgetCount(); i < len; i++) {
              widgets.add(getWidget(i));
            }

            for (Widget w : widgets) {
              TabItemConfig config = getConfig(w);
              if (w != contextMenuItem && config.isClosable()) {
                close(w);
              }
            }
          }

        }));
      }
      TabItemConfig c = configMap.get(item);
      MenuItem mi = (MenuItem) closeContextMenu.getWidget(0);
      mi.setEnabled(c.isClosable());
      contextMenuItem = item;
      boolean hasClosable = false;

      for (int i = 0, len = getWidgetCount(); i < len; i++) {
        Widget item2 = container.getWidget(i);
        TabItemConfig config = configMap.get(item2);
        if (config.isClosable() && item2 != item) {
          hasClosable = true;
          break;
        }
      }
      MenuItem m = (MenuItem) closeContextMenu.getWidget(1);
      m.setEnabled(hasClosable);
      closeContextMenu.showAt(x, y);
    }
  }
View Full Code Here

   */
  protected Menu createContextMenu(final int colIndex) {
    final Menu menu = new Menu();

    if (cm.isSortable(colIndex)) {
      MenuItem item = new MenuItem();
      item.setText(DefaultMessages.getMessages().gridView_sortAscText());
      item.setIcon(header.getAppearance().sortAscendingIcon());
      item.addSelectionHandler(new SelectionHandler<Item>() {

        @Override
        public void onSelection(SelectionEvent<Item> event) {
          doSort(colIndex, SortDir.ASC);

        }
      });
      menu.add(item);

      item = new MenuItem();
      item.setText(DefaultMessages.getMessages().gridView_sortDescText());
      item.setIcon(header.getAppearance().sortDescendingIcon());
      item.addSelectionHandler(new SelectionHandler<Item>() {

        @Override
        public void onSelection(SelectionEvent<Item> event) {
          doSort(colIndex, SortDir.DESC);

        }
      });
      menu.add(item);
    }

    MenuItem columns = new MenuItem();
    columns.setText(DefaultMessages.getMessages().gridView_columnsText());
    columns.setIcon(header.getAppearance().columnsIcon());
    columns.setData("gxt-columns", "true");

    final Menu columnMenu = new Menu();

    int cols = cm.getColumnCount();
    for (int i = 0; i < cols; i++) {
      ColumnConfig<M, ?> config = cm.getColumn(i);
      // ignore columns with no header text
      if (!hasHeaderValue(i)) {
        continue;
      }
      final int fcol = i;
      final CheckMenuItem check = new CheckMenuItem();
      check.setHideOnClick(false);
      check.setHTML(cm.getColumnHeader(i));
      check.setChecked(!cm.isHidden(i));

      if (!config.isHideable()) {
        check.disable();
      }

      check.addCheckChangeHandler(new CheckChangeHandler<CheckMenuItem>() {

        @Override
        public void onCheckChange(CheckChangeEvent<CheckMenuItem> event) {
          cm.setHidden(fcol, !cm.isHidden(fcol));
          restrictMenu(cm, columnMenu);

        }
      });
      columnMenu.add(check);
    }

    restrictMenu(cm, columnMenu);
    columns.setEnabled(columnMenu.getWidgetCount() > 0);
    columns.setSubMenu(columnMenu);
    menu.add(columns);
    return menu;
  }
View Full Code Here

  protected Menu createContextMenu(final int colIndex) {
    Menu menu = super.createContextMenu(colIndex);

    if (menu != null && enableGroupingMenu) {
      if (cm.isGroupable(colIndex)) {
        MenuItem groupBy = new MenuItem(DefaultMessages.getMessages().groupingView_groupByText());
        groupBy.setIcon(groupAppearance.groupByIcon());
        groupBy.addSelectionHandler(new SelectionHandler<Item>() {
          @Override
          public void onSelection(SelectionEvent<Item> event) {
            groupBy(cm.getColumn(colIndex));
          }
        });
        menu.add(new SeparatorMenuItem());
        menu.add(groupBy);

        groupBy.setEnabled(cm.getColumnCount(true) > 1);

        initMenuColumnShowHideHandling(menu, groupBy);
      }
      if (enableGrouping && enableNoGroups) {
        final CheckMenuItem showInGroups = new CheckMenuItem(
View Full Code Here

    // Loop through the menu and find the columns
    for (int i = 0; i < menu.getWidgetCount(); i++) {
      Widget subMenuWidget = menu.getWidget(i);
      // Only work with the columns MenuItem instances
      if (subMenuWidget instanceof MenuItem) {
        MenuItem columnsMenu = (MenuItem) subMenuWidget;
        String hasColumns = columnsMenu.getData("gxt-columns");
        // Find the columns and add handlers onto the CheckMenuItems columns
        if (hasColumns != null && hasColumns.equals("true")) {
          Menu colMenu = columnsMenu.getSubMenu();
          for (int b = 0; b < colMenu.getWidgetCount(); b++) {
            CheckMenuItem colItem = (CheckMenuItem) colMenu.getWidget(b);
            // Observe column events 'showing' and 'hiding' events
            colItem.addCheckChangeHandler(new CheckChangeHandler<CheckMenuItem>() {
              @Override
View Full Code Here

          icon = CommonIcons.get().equals();
          eq = field;
          break;
      }

      MenuItem menuItem = new MenuItem();
      menuItem.setCanActivate(false);
      menuItem.setHideOnClick(false);
      menuItem.setIcon(icon);
      menuItem.setWidget(field);

      menuItem.getElement().removeClassName(CommonStyles.get().unselectable());
      menuItem.getElement().getStyle().setCursor(Cursor.DEFAULT);

      add(menuItem);
    }
  }
View Full Code Here

          public void onHide(HideEvent event) {
            contextMenuItem = null;
          }
        });

        closeContextMenu.add(new MenuItem(getMessages().closeTab(), new SelectionHandler<MenuItem>() {
          @Override
          public void onSelection(SelectionEvent<MenuItem> event) {
            close(contextMenuItem);
          }
        }));

        closeContextMenu.add(new MenuItem(getMessages().closeOtherTabs(), new SelectionHandler<MenuItem>() {
          @Override
          public void onSelection(SelectionEvent<MenuItem> event) {
            List<Widget> widgets = new ArrayList<Widget>();
            for (int i = 0, len = getWidgetCount(); i < len; i++) {
              widgets.add(getWidget(i));
            }

            for (Widget w : widgets) {
              TabItemConfig config = getConfig(w);
              if (w != contextMenuItem && config.isClosable()) {
                close(w);
              }
            }
          }

        }));
      }
      TabItemConfig c = configMap.get(item);
      MenuItem mi = (MenuItem) closeContextMenu.getWidget(0);
      mi.setEnabled(c.isClosable());
      contextMenuItem = item;
      boolean hasClosable = false;

      for (int i = 0, len = getWidgetCount(); i < len; i++) {
        Widget item2 = container.getWidget(i);
        TabItemConfig config = configMap.get(item2);
        if (config.isClosable() && item2 != item) {
          hasClosable = true;
          break;
        }
      }
      MenuItem m = (MenuItem) closeContextMenu.getWidget(1);
      m.setEnabled(hasClosable);
      closeContextMenu.showAt(x, y);
    }
  }
View Full Code Here

   */
  protected Menu createContextMenu(final int colIndex) {
    final Menu menu = new Menu();

    if (cm.isSortable(colIndex)) {
      MenuItem item = new MenuItem();
      item.setText(DefaultMessages.getMessages().gridView_sortAscText());
      item.setIcon(header.getAppearance().sortAscendingIcon());
      item.addSelectionHandler(new SelectionHandler<Item>() {

        @Override
        public void onSelection(SelectionEvent<Item> event) {
          doSort(colIndex, SortDir.ASC);

        }
      });
      menu.add(item);

      item = new MenuItem();
      item.setText(DefaultMessages.getMessages().gridView_sortDescText());
      item.setIcon(header.getAppearance().sortDescendingIcon());
      item.addSelectionHandler(new SelectionHandler<Item>() {

        @Override
        public void onSelection(SelectionEvent<Item> event) {
          doSort(colIndex, SortDir.DESC);

        }
      });
      menu.add(item);
    }

    MenuItem columns = new MenuItem();
    columns.setText(DefaultMessages.getMessages().gridView_columnsText());
    columns.setIcon(header.getAppearance().columnsIcon());
    columns.setData("gxt-columns", "true");

    final Menu columnMenu = new Menu();

    int cols = cm.getColumnCount();
    for (int i = 0; i < cols; i++) {
      ColumnConfig<M, ?> config = cm.getColumn(i);
      if (shouldNotCount(i, false)) {
        continue;
      }
      final int fcol = i;
      final CheckMenuItem check = new CheckMenuItem();
      check.setHideOnClick(false);
      check.setText(cm.getColumnHeader(i).asString());
      check.setChecked(!cm.isHidden(i));

      if (!config.isHideable()) {
        check.disable();
      }

      check.addCheckChangeHandler(new CheckChangeHandler<CheckMenuItem>() {

        @Override
        public void onCheckChange(CheckChangeEvent<CheckMenuItem> event) {
          cm.setHidden(fcol, !cm.isHidden(fcol));
          restrictMenu(columnMenu);

        }
      });
      columnMenu.add(check);
    }

    restrictMenu(columnMenu);
    columns.setEnabled(columnMenu.getWidgetCount() > 0);
    columns.setSubMenu(columnMenu);
    menu.add(columns);
    return menu;
  }
View Full Code Here

  protected Menu createContextMenu(final int colIndex) {
    Menu menu = super.createContextMenu(colIndex);

    if (menu != null && enableGroupingMenu) {
      if (cm.isGroupable(colIndex)) {
        MenuItem groupBy = new MenuItem(DefaultMessages.getMessages().groupingView_groupByText());
        groupBy.setIcon(groupAppearance.groupByIcon());
        groupBy.addSelectionHandler(new SelectionHandler<Item>() {
          @Override
          public void onSelection(SelectionEvent<Item> event) {
            groupBy(cm.getColumn(colIndex));
          }
        });
View Full Code Here

    if (w instanceof SeparatorToolItem) {
      menu.add(new SeparatorMenuItem());

    } else if (w instanceof SplitButton) {
      final SplitButton sb = (SplitButton) w;
      MenuItem item = new MenuItem(sb.getText(), sb.getIcon());
      item.setEnabled(sb.isEnabled());
      item.setItemId(sb.getItemId());
      if (sb.getData("gxt-menutext") != null) {
        item.setText(sb.getData("gxt-menutext").toString());
      }
      if (sb.getMenu() != null) {
        item.setSubMenu(sb.getMenu());
      }

      item.addSelectionHandler(new SelectionHandler<Item>() {

        @Override
        public void onSelection(SelectionEvent<Item> event) {
          sb.fireEvent(new SelectEvent());
        }
      });
      menu.add(item);

    } else if (w instanceof TextButton) {
      final TextButton b = (TextButton) w;

      MenuItem item = new MenuItem(b.getText(), b.getIcon());
      item.setItemId(b.getItemId());

      if (b.getData("gxt-menutext") != null) {
        item.setText(b.getData("gxt-menutext").toString());
      }
      if (b.getMenu() != null) {
        item.setHideOnClick(false);
        item.setSubMenu(b.getMenu());
      }
      item.setEnabled(b.isEnabled());

      item.addSelectionHandler(new SelectionHandler<Item>() {

        @Override
        public void onSelection(SelectionEvent<Item> event) {
          b.fireEvent(new SelectEvent());
        }
      });

      menu.add(item);
    } else if (w instanceof ButtonGroup) {
      ButtonGroup g = (ButtonGroup) w;
      g.setItemId(g.getItemId());
      menu.add(new SeparatorMenuItem());
      String heading = g.getHeadingText();
      if (heading != null && heading.length() > 0 && !heading.equals("&#160;")) {
        menu.add(new HeaderMenuItem(heading));
      }

      Widget con = g.getWidget();
      if (con != null && con instanceof HasWidgets) {
        HasWidgets widgets = (HasWidgets) con;
        Iterator<Widget> it = widgets.iterator();
        while (it.hasNext()) {
          addWidgetToMenu(menu, it.next());
        }
      }

      menu.add(new SeparatorMenuItem());
    } else if (w instanceof ToggleButton) {
      final ToggleButton b = (ToggleButton)w;
     
      final CheckMenuItem item = new CheckMenuItem(b.getText());
      item.setItemId(b.getItemId());
      item.setChecked(b.getValue());
     
      if (b.getData("gxt-menutext") != null) {
        item.setText(b.getData("gxt-menutext").toString());
      }

      item.setEnabled(b.isEnabled());
     
      item.addCheckChangeHandler(new CheckChangeHandler<CheckMenuItem>() {

        @Override
        public void onCheckChange(CheckChangeEvent<CheckMenuItem> event) {
          b.setValue(event.getItem().isChecked());
          b.fireEvent(new SelectEvent());
View Full Code Here

TOP

Related Classes of com.sencha.gxt.widget.core.client.menu.MenuItem$MenuItemAppearance

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.