Search in sources :

Example 1 with DateLevel

use of org.activityinfo.ui.client.analysis.model.DateLevel 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)

Aggregations

Style (com.sencha.gxt.core.client.Style)1 CheckMenuItem (com.sencha.gxt.widget.core.client.menu.CheckMenuItem)1 Menu (com.sencha.gxt.widget.core.client.menu.Menu)1 MenuItem (com.sencha.gxt.widget.core.client.menu.MenuItem)1 SeparatorMenuItem (com.sencha.gxt.widget.core.client.menu.SeparatorMenuItem)1 DateLevel (org.activityinfo.ui.client.analysis.model.DateLevel)1