Search in sources :

Example 21 with CheckBox

use of com.vaadin.v7.ui.CheckBox in project SORMAS-Project by hzi-braunschweig.

the class BulkTaskDataForm method addFields.

@Override
protected void addFields() {
    if (!initialized) {
        return;
    }
    taskStatusCheckbox = new CheckBox(I18nProperties.getCaption(Captions.bulkTaskStatus));
    getContent().addComponent(taskStatusCheckbox, STATUS_CHECKBOX);
    NullableOptionGroup status = addField(TaskBulkEditData.TASK_STATUS, NullableOptionGroup.class);
    status.setEnabled(false);
    FieldHelper.setRequiredWhen(getFieldGroup(), taskStatusCheckbox, Arrays.asList(TaskBulkEditData.TASK_STATUS), Arrays.asList(true));
    taskStatusCheckbox.addValueChangeListener(e -> {
        status.setEnabled((boolean) e.getProperty().getValue());
    });
    priorityCheckbox = new CheckBox(I18nProperties.getCaption(Captions.bulkTaskPriority));
    getContent().addComponent(priorityCheckbox, PRORITY_CHECKBOX);
    NullableOptionGroup priority = addField(TaskBulkEditData.TASK_PRIORITY, NullableOptionGroup.class);
    priority.setEnabled(false);
    FieldHelper.setRequiredWhen(getFieldGroup(), priorityCheckbox, Arrays.asList(TaskBulkEditData.TASK_PRIORITY), Arrays.asList(true));
    priorityCheckbox.addValueChangeListener(e -> {
        priority.setEnabled((boolean) e.getProperty().getValue());
    });
    assigneeCheckbox = new CheckBox(I18nProperties.getCaption(Captions.bulkTaskAssignee));
    getContent().addComponent(assigneeCheckbox, ASSIGNEE_CHECKBOX);
    ComboBox assignee = addField(TaskBulkEditData.TASK_ASSIGNEE, ComboBox.class);
    assignee.setEnabled(false);
    FieldHelper.addSoftRequiredStyleWhen(getFieldGroup(), assigneeCheckbox, Arrays.asList(TaskBulkEditData.TASK_ASSIGNEE), Arrays.asList(true), null);
    List<UserReferenceDto> users = getUsers();
    Map<String, Long> userTaskCounts = FacadeProvider.getTaskFacade().getPendingTaskCountPerUser(users.stream().map(ReferenceDto::getUuid).collect(Collectors.toList()));
    for (UserReferenceDto user : users) {
        assignee.addItem(user);
        Long userTaskCount = userTaskCounts.get(user.getUuid());
        assignee.setItemCaption(user, user.getCaption() + " (" + (userTaskCount != null ? userTaskCount.toString() : "0") + ")");
    }
    assigneeCheckbox.addValueChangeListener(e -> {
        boolean changeAssignee = (boolean) e.getProperty().getValue();
        assignee.setEnabled(changeAssignee);
        assignee.setRequired(changeAssignee);
    });
}
Also used : NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) ReferenceDto(de.symeda.sormas.api.ReferenceDto) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) CheckBox(com.vaadin.v7.ui.CheckBox) ComboBox(com.vaadin.v7.ui.ComboBox)

Example 22 with CheckBox

use of com.vaadin.v7.ui.CheckBox in project SORMAS-Project by hzi-braunschweig.

the class DatabaseExportView method createDatabaseTablesLayout.

private HorizontalLayout createDatabaseTablesLayout() {
    HorizontalLayout databaseTablesLayout = new HorizontalLayout();
    databaseTablesLayout.setMargin(false);
    databaseTablesLayout.setSpacing(true);
    VerticalLayout sormasDataLayout = new VerticalLayout();
    sormasDataLayout.setMargin(false);
    sormasDataLayout.setSpacing(false);
    Label sormasDataHeadline = new Label(I18nProperties.getCaption(Captions.exportSormasData));
    CssStyles.style(sormasDataHeadline, CssStyles.H4);
    sormasDataLayout.addComponent(sormasDataHeadline);
    VerticalLayout infrastructureDataLayout = new VerticalLayout();
    infrastructureDataLayout.setMargin(false);
    infrastructureDataLayout.setSpacing(false);
    Label infrastructureDataHeadline = new Label(I18nProperties.getCaption(Captions.exportInfrastructureData));
    CssStyles.style(infrastructureDataHeadline, CssStyles.H4);
    infrastructureDataLayout.addComponent(infrastructureDataHeadline);
    VerticalLayout configurationDataLayout = new VerticalLayout();
    configurationDataLayout.setMargin(false);
    configurationDataLayout.setSpacing(false);
    Label configurationDataHeadline = new Label(I18nProperties.getCaption(Captions.exportConfigurationData));
    CssStyles.style(configurationDataHeadline, CssStyles.H4);
    configurationDataLayout.addComponent(configurationDataHeadline);
    VerticalLayout externalDataLayout = new VerticalLayout();
    externalDataLayout.setMargin(false);
    externalDataLayout.setSpacing(false);
    Label externalDataHeadline = new Label(I18nProperties.getCaption(Captions.exportExternalData));
    CssStyles.style(externalDataHeadline, CssStyles.H4);
    externalDataLayout.addComponent(externalDataHeadline);
    List<FeatureConfigurationDto> featureConfigurations = FacadeProvider.getFeatureConfigurationFacade().getActiveServerFeatureConfigurations();
    ConfigFacade configFacade = FacadeProvider.getConfigFacade();
    for (DatabaseTable databaseTable : DatabaseTable.values()) {
        if (!databaseTable.isEnabled(featureConfigurations, configFacade)) {
            continue;
        }
        CheckBox checkBox = new CheckBox(databaseTable.toString());
        int indent = getIndent(databaseTable);
        if (indent == 1) {
            CssStyles.style(checkBox, CssStyles.INDENT_LEFT_1);
        } else if (indent == 2) {
            CssStyles.style(checkBox, CssStyles.INDENT_LEFT_2);
        } else if (indent == 3) {
            CssStyles.style(checkBox, CssStyles.INDENT_LEFT_3);
        }
        switch(databaseTable.getDatabaseTableType()) {
            case SORMAS:
                sormasDataLayout.addComponent(checkBox);
                break;
            case INFRASTRUCTURE:
                infrastructureDataLayout.addComponent(checkBox);
                break;
            case CONFIGURATION:
                configurationDataLayout.addComponent(checkBox);
                break;
            case EXTERNAL:
                externalDataLayout.addComponent(checkBox);
                break;
            default:
                throw new IllegalArgumentException(databaseTable.getDatabaseTableType().toString());
        }
        databaseTableToggles.put(checkBox, databaseTable);
    }
    databaseTablesLayout.addComponent(sormasDataLayout);
    databaseTablesLayout.addComponent(infrastructureDataLayout);
    databaseTablesLayout.addComponent(configurationDataLayout);
    databaseTablesLayout.addComponent(externalDataLayout);
    return databaseTablesLayout;
}
Also used : CheckBox(com.vaadin.v7.ui.CheckBox) Label(com.vaadin.ui.Label) VerticalLayout(com.vaadin.ui.VerticalLayout) DatabaseTable(de.symeda.sormas.api.importexport.DatabaseTable) FeatureConfigurationDto(de.symeda.sormas.api.feature.FeatureConfigurationDto) ConfigFacade(de.symeda.sormas.api.ConfigFacade) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Example 23 with CheckBox

use of com.vaadin.v7.ui.CheckBox in project SORMAS-Project by hzi-braunschweig.

the class DownloadUtil method createDatabaseExportStreamResource.

public static StreamResource createDatabaseExportStreamResource(DatabaseExportView databaseExportView, String fileName, String mimeType) {
    StreamResource streamResource = new StreamResource(() -> {
        Map<CheckBox, DatabaseTable> databaseToggles = databaseExportView.getDatabaseTableToggles();
        List<DatabaseTable> tablesToExport = new ArrayList<>();
        for (CheckBox checkBox : databaseToggles.keySet()) {
            if (checkBox.getValue()) {
                tablesToExport.add(databaseToggles.get(checkBox));
            }
        }
        return new DelayedInputStream(() -> {
            try {
                String zipPath = FacadeProvider.getExportFacade().generateDatabaseExportArchive(tablesToExport);
                return new BufferedInputStream(Files.newInputStream(new File(zipPath).toPath()));
            } catch (IOException | ExportErrorException e) {
                LoggerFactory.getLogger(DownloadUtil.class).error(e.getMessage(), e);
                // TODO This currently requires the user to click the "Export" button again or reload the page as the UI
                // is not automatically updated; this should be changed once Vaadin push is enabled (see #516)
                databaseExportView.showExportErrorNotification();
                return null;
            }
        });
    }, fileName);
    streamResource.setMIMEType(mimeType);
    streamResource.setCacheTime(0);
    return streamResource;
}
Also used : ArrayList(java.util.ArrayList) ExportErrorException(de.symeda.sormas.api.utils.ExportErrorException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) StreamResource(com.vaadin.server.StreamResource) BufferedInputStream(java.io.BufferedInputStream) CheckBox(com.vaadin.v7.ui.CheckBox) DatabaseTable(de.symeda.sormas.api.importexport.DatabaseTable) File(java.io.File)

Example 24 with CheckBox

use of com.vaadin.v7.ui.CheckBox in project charts by vaadin.

the class ServerSideEvents method createControls.

private Layout createControls() {
    visibilityToggling = new CheckBox("Disable series visibility toggling");
    visibilityToggling.addValueChangeListener(e -> {
        chart.setSeriesVisibilityTogglingDisabled(visibilityToggling.getValue());
    });
    final Button firstSeriesVisible = new Button("Hide first series");
    firstSeriesVisible.setId("hideFirstSeries");
    firstSeriesVisible.addClickListener(new Button.ClickListener() {

        boolean hideSeries = true;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            Series firstSeries = chart.getConfiguration().getSeries().get(0);
            ((AbstractSeries) firstSeries).setVisible(!hideSeries);
            hideSeries = !hideSeries;
            String caption = hideSeries ? "Hide first series" : "Show first series";
            firstSeriesVisible.setCaption(caption);
        }
    });
    Button setExtremes = new Button("Toggle extremes");
    setExtremes.setId("setExtremes");
    setExtremes.addClickListener(new Button.ClickListener() {

        public boolean extremesSet;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (extremesSet) {
                chart.getConfiguration().getxAxis().setExtremes(10, 90);
            } else {
                chart.getConfiguration().getxAxis().setExtremes(20, 80);
            }
            extremesSet = !extremesSet;
        }
    });
    final OptionGroup zoomLevels = new OptionGroup("Zoom Type");
    zoomLevels.addItem(ZoomType.XY);
    zoomLevels.addItem(ZoomType.X);
    zoomLevels.addItem(ZoomType.Y);
    zoomLevels.setValue(ZoomType.XY);
    zoomLevels.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            ZoomType zoom = (ZoomType) zoomLevels.getValue();
            chart.getConfiguration().getChart().setZoomType(zoom);
            chart.drawChart();
        }
    });
    Button resetHistory = new Button("Reset history");
    resetHistory.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            lastEvent.setValue(null);
            eventDetails.setValue(null);
            historyLayout.removeAllComponents();
        }
    });
    HorizontalLayout controls = new HorizontalLayout();
    controls.setId("controls");
    controls.setSpacing(true);
    controls.addComponent(visibilityToggling);
    controls.addComponent(firstSeriesVisible);
    controls.addComponent(setExtremes);
    controls.addComponent(zoomLevels);
    controls.addComponent(resetHistory);
    return controls;
}
Also used : ZoomType(com.vaadin.addon.charts.model.ZoomType) HorizontalLayout(com.vaadin.ui.HorizontalLayout) PlotOptionsSeries(com.vaadin.addon.charts.model.PlotOptionsSeries) Series(com.vaadin.addon.charts.model.Series) AbstractSeries(com.vaadin.addon.charts.model.AbstractSeries) DataSeries(com.vaadin.addon.charts.model.DataSeries) OptionGroup(com.vaadin.v7.ui.OptionGroup) Button(com.vaadin.ui.Button) CheckBox(com.vaadin.ui.CheckBox) Property(com.vaadin.v7.data.Property)

Example 25 with CheckBox

use of com.vaadin.v7.ui.CheckBox in project CodenameOne by codenameone.

the class InstantUI method createEntryForProperty.

private void createEntryForProperty(PropertyBase b, Container cnt, ArrayList<UiBinding.Binding> allBindings, UiBinding uib) throws RuntimeException {
    if (isExcludedProperty(b)) {
        return;
    }
    Class cls = (Class) b.getClientProperty("cn1$cmpCls");
    if (cls != null) {
        try {
            Component cmp = (Component) cls.newInstance();
            cmp.setName(b.getName());
            cnt.add(b.getLabel()).add(cmp);
            allBindings.add(uib.bind(b, cmp));
        } catch (Exception err) {
            Log.e(err);
            throw new RuntimeException("Custom property instant UI failed for " + b.getName() + " " + err);
        }
        return;
    }
    String[] multiLabels = (String[]) b.getClientProperty("cn1$multiChceLbl");
    if (multiLabels != null) {
        // multi choice component
        final Object[] multiValues = (Object[]) b.getClientProperty("cn1$multiChceVal");
        if (multiLabels.length < 5) {
            // toggle buttons
            ButtonGroup bg = new ButtonGroup();
            RadioButton[] rbs = new RadioButton[multiLabels.length];
            cnt.add(b.getLabel());
            Container radioBox = new Container(new GridLayout(multiLabels.length));
            for (int iter = 0; iter < multiLabels.length; iter++) {
                rbs[iter] = RadioButton.createToggle(multiLabels[iter], bg);
                radioBox.add(rbs[iter]);
            }
            cnt.add(radioBox);
            allBindings.add(uib.bindGroup(b, multiValues, rbs));
        } else {
            Picker stringPicker = new Picker();
            stringPicker.setStrings(multiLabels);
            Map<Object, Object> m1 = new HashMap<Object, Object>();
            Map<Object, Object> m2 = new HashMap<Object, Object>();
            for (int iter = 0; iter < multiLabels.length; iter++) {
                m1.put(multiLabels[iter], multiValues[iter]);
                m2.put(multiValues[iter], multiLabels[iter]);
            }
            cnt.add(b.getLabel()).add(stringPicker);
            allBindings.add(uib.bind(b, stringPicker, new UiBinding.PickerAdapter<Object>(new UiBinding.MappingConverter(m1), new UiBinding.MappingConverter(m2))));
        }
        return;
    }
    Class t = b.getGenericType();
    if (t != null) {
        if (t == Boolean.class) {
            CheckBox cb = new CheckBox();
            uib.bind(b, cb);
            cnt.add(b.getLabel()).add(cb);
            return;
        }
        if (t == Date.class) {
            Picker dp = new Picker();
            dp.setType(Display.PICKER_TYPE_DATE);
            uib.bind(b, dp);
            cnt.add(b.getLabel()).add(dp);
            return;
        }
    }
    TextField tf = new TextField();
    tf.setConstraint(getTextFieldConstraint(b));
    uib.bind(b, tf);
    cnt.add(b.getLabel()).add(tf);
}
Also used : HashMap(java.util.HashMap) RadioButton(com.codename1.ui.RadioButton) Container(com.codename1.ui.Container) GridLayout(com.codename1.ui.layouts.GridLayout) ButtonGroup(com.codename1.ui.ButtonGroup) CheckBox(com.codename1.ui.CheckBox) Picker(com.codename1.ui.spinner.Picker) TextField(com.codename1.ui.TextField) Component(com.codename1.ui.Component)

Aggregations

CheckBox (com.vaadin.v7.ui.CheckBox)40 CheckBox (com.codename1.ui.CheckBox)18 Label (com.vaadin.ui.Label)15 ComboBox (com.vaadin.v7.ui.ComboBox)14 Button (com.codename1.ui.Button)12 TextField (com.vaadin.v7.ui.TextField)12 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)12 Form (com.codename1.ui.Form)11 Disease (de.symeda.sormas.api.Disease)11 Captions (de.symeda.sormas.api.i18n.Captions)11 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)11 NullableOptionGroup (de.symeda.sormas.ui.utils.NullableOptionGroup)11 List (java.util.List)11 Container (com.codename1.ui.Container)10 FacadeProvider (de.symeda.sormas.api.FacadeProvider)10 Strings (de.symeda.sormas.api.i18n.Strings)10 Label (com.codename1.ui.Label)9 TextField (com.codename1.ui.TextField)9 HorizontalLayout (com.vaadin.ui.HorizontalLayout)9 AbstractEditForm (de.symeda.sormas.ui.utils.AbstractEditForm)9