Search in sources :

Example 1 with MenuItem

use of com.sencha.gxt.widget.core.client.menu.MenuItem in project activityinfo by bedatadriven.

the class MeasurePane method showMenu.

private void showMenu(Element element, MeasureListItem item) {
    MeasureModel measure = item.getModel();
    Menu contextMenu = new Menu();
    // Edit the alias
    MenuItem editLabel = new MenuItem();
    editLabel.setText("Edit Label...");
    editLabel.addSelectionHandler(event -> editLabel(measure));
    contextMenu.add(editLabel);
    // Edit the formula...
    MenuItem editFormula = new MenuItem();
    editFormula.setText("Edit Formula...");
    editFormula.addSelectionHandler(event -> editFormula(measure));
    contextMenu.add(editFormula);
    contextMenu.add(new SeparatorMenuItem());
    // Choose the aggregation
    for (Statistic statistic : Statistic.values()) {
        CheckMenuItem aggregationItem = new CheckMenuItem(statistic.getLabel());
        aggregationItem.setChecked(measure.getStatistics().contains(statistic));
        aggregationItem.addCheckChangeHandler(event -> updateStatistic(measure, statistic, event.getChecked()));
        contextMenu.add(aggregationItem);
    }
    contextMenu.add(new SeparatorMenuItem());
    // Remove the dimension
    MenuItem remove = new MenuItem();
    remove.setText(I18N.CONSTANTS.remove());
    remove.addSelectionHandler(event -> removeMeasure(measure.getId()));
    contextMenu.add(remove);
    contextMenu.show(element, new Style.AnchorAlignment(Style.Anchor.BOTTOM, Style.Anchor.BOTTOM, true));
}
Also used : CheckMenuItem(com.sencha.gxt.widget.core.client.menu.CheckMenuItem) Statistic(org.activityinfo.ui.client.analysis.model.Statistic) Style(com.sencha.gxt.core.client.Style) SeparatorMenuItem(com.sencha.gxt.widget.core.client.menu.SeparatorMenuItem) CheckMenuItem(com.sencha.gxt.widget.core.client.menu.CheckMenuItem) MenuItem(com.sencha.gxt.widget.core.client.menu.MenuItem) Menu(com.sencha.gxt.widget.core.client.menu.Menu) SeparatorMenuItem(com.sencha.gxt.widget.core.client.menu.SeparatorMenuItem) MeasureModel(org.activityinfo.ui.client.analysis.model.MeasureModel) ImmutableMeasureModel(org.activityinfo.ui.client.analysis.model.ImmutableMeasureModel)

Example 2 with MenuItem

use of com.sencha.gxt.widget.core.client.menu.MenuItem in project activityinfo by bedatadriven.

the class DimensionPane method onDimensionMenu.

private void onDimensionMenu(Element element, EffectiveDimension dim) {
    Menu contextMenu = new Menu();
    MenuItem editLabel = new MenuItem();
    editLabel.setText("Edit Label...");
    editLabel.addSelectionHandler(event -> editLabel(dim.getModel()));
    contextMenu.add(editLabel);
    contextMenu.add(new SeparatorMenuItem());
    // Allow choosing the date part to show
    if (dim.isDate()) {
        DateLevel currentLevel = dim.getModel().getDateLevel().orElse(null);
        for (DateLevel dateLevel : DateLevel.values()) {
            CheckMenuItem item = new CheckMenuItem(dateLevel.getLabel());
            item.setChecked(currentLevel == dateLevel);
            item.addSelectionHandler(event -> updateDateLevel(dim, dateLevel));
            contextMenu.add(item);
        }
        contextMenu.add(new SeparatorMenuItem());
    }
    boolean canTotal = canTotal(dim);
    // Choose to include totals or not.
    CheckMenuItem totalsItem = new CheckMenuItem("Include Totals");
    totalsItem.setChecked(dim.getModel().getTotals());
    totalsItem.addCheckChangeHandler(event -> updateTotals(dim, event.getChecked()));
    totalsItem.setEnabled(canTotal);
    contextMenu.add(totalsItem);
    CheckMenuItem missingItem = new CheckMenuItem("Include Missing");
    missingItem.setChecked(dim.getModel().getMissingIncluded());
    missingItem.addCheckChangeHandler(event -> updateMissing(dim, event.getChecked()));
    missingItem.setEnabled(canTotal);
    contextMenu.add(missingItem);
    CheckMenuItem percentagesItem = new CheckMenuItem("Include Percentages");
    percentagesItem.setChecked(dim.getModel().getPercentage());
    percentagesItem.addCheckChangeHandler(event -> updatePercentages(dim, event.getChecked()));
    percentagesItem.setEnabled(canTotal);
    contextMenu.add(percentagesItem);
    MenuItem totalsLabel = new MenuItem("Total Label...");
    totalsLabel.addSelectionHandler(event -> editTotalLabel(dim));
    totalsLabel.setEnabled(canTotal);
    contextMenu.add(totalsLabel);
    contextMenu.add(new SeparatorMenuItem());
    // Remove the dimension
    MenuItem remove = new MenuItem();
    remove.setText(I18N.CONSTANTS.remove());
    remove.addSelectionHandler(event -> removeDimension(dim.getId()));
    // Special handling for "Measures" and "Statistics" dimension
    if (dim.getId().equals(DimensionModel.MEASURE_ID)) {
        if (viewModel.getWorkingModel().getMeasures().size() > 1) {
            remove.setEnabled(false);
        }
    }
    if (dim.getId().equals(DimensionModel.STATISTIC_ID)) {
        if (viewModel.getWorkingModel().isMeasureDefinedWithMultipleStatistics()) {
            remove.setEnabled(false);
        }
    }
    contextMenu.add(remove);
    contextMenu.show(element, new Style.AnchorAlignment(Style.Anchor.BOTTOM, Style.Anchor.BOTTOM, true));
}
Also used : CheckMenuItem(com.sencha.gxt.widget.core.client.menu.CheckMenuItem) Style(com.sencha.gxt.core.client.Style) SeparatorMenuItem(com.sencha.gxt.widget.core.client.menu.SeparatorMenuItem) CheckMenuItem(com.sencha.gxt.widget.core.client.menu.CheckMenuItem) MenuItem(com.sencha.gxt.widget.core.client.menu.MenuItem) Menu(com.sencha.gxt.widget.core.client.menu.Menu) SeparatorMenuItem(com.sencha.gxt.widget.core.client.menu.SeparatorMenuItem) DateLevel(org.activityinfo.ui.client.analysis.model.DateLevel)

Example 3 with MenuItem

use of com.sencha.gxt.widget.core.client.menu.MenuItem in project activityinfo by bedatadriven.

the class LogicalTabPanel method onItemContextMenu.

protected void onItemContextMenu(final M item, int x, int y) {
    if (closeMenu) {
        if (closeContextMenu == null) {
            closeContextMenu = new Menu();
            closeContextMenu.addHideHandler(new HideHandler() {

                @Override
                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<M> models = new ArrayList<M>();
                    for (int i = 0, len = getModelCount(); i < len; i++) {
                        models.add(getModel(i));
                    }
                    for (M w : models) {
                        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 = getModelCount(); 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);
    }
}
Also used : ArrayList(java.util.ArrayList) IsWidget(com.google.gwt.user.client.ui.IsWidget) Widget(com.google.gwt.user.client.ui.Widget) HasOneWidget(com.google.gwt.user.client.ui.HasOneWidget) MenuItem(com.sencha.gxt.widget.core.client.menu.MenuItem) XDOM(com.sencha.gxt.core.client.dom.XDOM) Point(com.sencha.gxt.core.client.util.Point) HideHandler(com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler) TabItemConfig(com.sencha.gxt.widget.core.client.TabItemConfig) Menu(com.sencha.gxt.widget.core.client.menu.Menu) HideEvent(com.sencha.gxt.widget.core.client.event.HideEvent)

Example 4 with MenuItem

use of com.sencha.gxt.widget.core.client.menu.MenuItem in project activityinfo by bedatadriven.

the class LiveRecordGridView method createContextMenu.

/**
 * Creates a context menu for the given column, including sort menu items and column visibility sub-menu.
 *
 * @param colIndex the column index
 * @return the context menu for the given column
 */
protected Menu createContextMenu(final int colIndex) {
    final Menu menu = new Menu();
    if (SORTING_IMPLEMENTED && 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);
    }
    return menu;
}
Also used : MenuItem(com.sencha.gxt.widget.core.client.menu.MenuItem) Item(com.sencha.gxt.widget.core.client.menu.Item) MenuItem(com.sencha.gxt.widget.core.client.menu.MenuItem) Menu(com.sencha.gxt.widget.core.client.menu.Menu)

Aggregations

Menu (com.sencha.gxt.widget.core.client.menu.Menu)4 MenuItem (com.sencha.gxt.widget.core.client.menu.MenuItem)4 Style (com.sencha.gxt.core.client.Style)2 CheckMenuItem (com.sencha.gxt.widget.core.client.menu.CheckMenuItem)2 SeparatorMenuItem (com.sencha.gxt.widget.core.client.menu.SeparatorMenuItem)2 HasOneWidget (com.google.gwt.user.client.ui.HasOneWidget)1 IsWidget (com.google.gwt.user.client.ui.IsWidget)1 Widget (com.google.gwt.user.client.ui.Widget)1 XDOM (com.sencha.gxt.core.client.dom.XDOM)1 Point (com.sencha.gxt.core.client.util.Point)1 TabItemConfig (com.sencha.gxt.widget.core.client.TabItemConfig)1 HideEvent (com.sencha.gxt.widget.core.client.event.HideEvent)1 HideHandler (com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler)1 Item (com.sencha.gxt.widget.core.client.menu.Item)1 ArrayList (java.util.ArrayList)1 DateLevel (org.activityinfo.ui.client.analysis.model.DateLevel)1 ImmutableMeasureModel (org.activityinfo.ui.client.analysis.model.ImmutableMeasureModel)1 MeasureModel (org.activityinfo.ui.client.analysis.model.MeasureModel)1 Statistic (org.activityinfo.ui.client.analysis.model.Statistic)1