Example usage for com.vaadin.ui FormLayout FormLayout

List of usage examples for com.vaadin.ui FormLayout FormLayout

Introduction

In this page you can find the example usage for com.vaadin.ui FormLayout FormLayout.

Prototype

public FormLayout() 

Source Link

Usage

From source file:com.peergreen.webconsole.scope.logs.LogsScope.java

License:Open Source License

public LogsScope() {
    setMargin(true);//w w  w .  ja v  a2  s  .  c  o  m
    setSpacing(true);
    setSizeFull();

    HorizontalLayout topBar = new HorizontalLayout();
    topBar.setWidth("100%");
    addComponent(topBar);
    FormLayout form = new FormLayout();
    form.setWidth("40%");
    topBar.addComponent(form);

    TextField textFieldFilter = new TextField();
    textFieldFilter.setCaption("Filter:");
    textFieldFilter.setInputPrompt("filter");
    textFieldFilter.setWidth("60%");
    textFieldFilter.addTextChangeListener(new TextChangeListener() {
        @Override
        public void textChange(final FieldEvents.TextChangeEvent event) {
            container.removeAllContainerFilters();
            Container.Filter or = new Or(new SimpleStringFilter("caller", event.getText().trim(), true, false),
                    new SimpleStringFilter("text", event.getText().trim(), true, false));
            Filter and = new And(or, filter);

            container.addContainerFilter(and);
        }
    });

    topBar.addComponent(textFieldFilter);

    //form.setWidth("100%");
    form.setSpacing(true);
    form.setMargin(true);
    HorizontalLayout systemLayout = new HorizontalLayout();
    systemLayout.setCaption("JVM System streams:");
    form.addComponent(systemLayout);
    HorizontalLayout loggerLayout = new HorizontalLayout();
    loggerLayout.setCaption("Loggers:");
    form.addComponent(loggerLayout);

    final CheckBox systemOut = new CheckBox("out");
    systemOut.setValue(true);
    systemLayout.addComponent(systemOut);

    this.container = new BeanItemContainer<TableEntry>(TableEntry.class);
    filter = new TypeFilter();
    container.addContainerFilter(filter);

    systemOut.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean value = (Boolean) event.getProperty().getValue();
            container.removeAllContainerFilters();
            filter.setAcceptSystemOut(value);
            container.addContainerFilter(filter);
        }
    });

    CheckBox systemErr = new CheckBox("err");
    systemLayout.addComponent(systemErr);
    systemErr.setValue(true);
    systemErr.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean value = (Boolean) event.getProperty().getValue();
            container.removeAllContainerFilters();
            filter.setAcceptSystemErr(value);
            container.addContainerFilter(filter);
        }
    });

    CheckBox loggerInfo = new CheckBox("Info");
    loggerLayout.addComponent(loggerInfo);
    loggerInfo.setValue(true);
    loggerInfo.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean value = (Boolean) event.getProperty().getValue();
            container.removeAllContainerFilters();
            filter.setAcceptLoggerInfo(value);
            container.addContainerFilter(filter);
        }
    });

    CheckBox loggerWarning = new CheckBox("Warning");
    loggerLayout.addComponent(loggerWarning);
    loggerWarning.setValue(true);
    loggerWarning.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean value = (Boolean) event.getProperty().getValue();
            container.removeAllContainerFilters();
            filter.setAcceptLoggerWarning(value);
            container.addContainerFilter(filter);
        }
    });

    CheckBox loggerError = new CheckBox("Error");
    loggerLayout.addComponent(loggerError);
    loggerError.setValue(true);
    loggerError.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean value = (Boolean) event.getProperty().getValue();
            container.removeAllContainerFilters();
            filter.setAcceptLoggerError(value);
            container.addContainerFilter(filter);
        }
    });

    Button clearButton = new Button("clear");
    //horizontalLayout.addComponent(clearButton);
    clearButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            container.removeAllItems();

        }
    });

    this.table = new Table();
    table.setSizeFull();
    table.setImmediate(true);

    // Define the names and data types of columns.
    table.addContainerProperty("date", Date.class, null);
    table.addContainerProperty("type", String.class, null);
    table.addContainerProperty("caller", String.class, null);
    table.addContainerProperty("text", String.class, "empty");

    table.setContainerDataSource(container);
    table.addGeneratedColumn("text", new TextColumnGenerator());

    table.setItemDescriptionGenerator(new ItemDescriptionGenerator() {
        @Override
        public String generateDescription(Component source, Object itemId, Object propertyId) {
            TableEntry tableEntry = (TableEntry) itemId;

            return simpleDateFormat.format(tableEntry.getDate()).concat(" : ").concat(tableEntry.getType())
                    .concat(" : ").concat(tableEntry.getCaller());

        }
    });

    table.setVisibleColumns(new Object[] { "text" });
    table.setColumnHeaderMode(ColumnHeaderMode.HIDDEN);
    table.setSortEnabled(true);
    addComponent(table);
    setExpandRatio(table, 1.5f);
}

From source file:com.save.employee.CreateNewAccountWindow.java

FormLayout getLayout() {
    FormLayout f = new FormLayout();
    f.setReadOnly(false);//from w w  w  . j a v  a 2 s.  c o m
    f.setSpacing(true);
    f.setMargin(true);

    final TextField employeeNo = new TextField("Employee No: ");
    employeeNo.setWidth("100%");
    employeeNo.setRequired(true);
    employeeNo.setNullSettingAllowed(false);
    f.addComponent(employeeNo);

    final TextField firstname = new TextField("Firstname: ");
    firstname.setWidth("100%");
    firstname.setRequired(true);
    firstname.setNullSettingAllowed(false);
    f.addComponent(firstname);

    final TextField middlename = new TextField("Middlename: ");
    middlename.setWidth("100%");
    middlename.setRequired(true);
    middlename.setNullSettingAllowed(false);
    f.addComponent(middlename);

    final TextField lastname = new TextField("Lastname: ");
    lastname.setWidth("100%");
    lastname.setRequired(true);
    lastname.setNullSettingAllowed(false);
    f.addComponent(lastname);

    final OptionGroup gender = new OptionGroup("Gender: ");
    gender.addItem("Female");
    gender.addItem("Male");
    gender.addStyleName("horizontal");
    gender.setValue("Female");
    f.addComponent(gender);

    final ComboBox status = new ComboBox("Status: ");
    status.setWidth("100%");
    status.setNullSelectionAllowed(false);
    status.addItem("Single");
    status.addItem("Married");
    status.addItem("Widow");
    status.addItem("Separated");
    f.addComponent(status);

    Button saveBtn = new Button("SAVE");
    saveBtn.setWidth("100%");
    saveBtn.addClickListener((Button.ClickEvent event) -> {
        //TODO
        if (employeeNo.getValue().isEmpty() || employeeNo.getValue() == null) {
            Notification.show("Requried Emloyee ID", Notification.Type.WARNING_MESSAGE);
            return;
        }

        if (firstname.getValue().isEmpty() || firstname.getValue() == null) {
            Notification.show("Requried Firstname", Notification.Type.WARNING_MESSAGE);
            return;
        }

        if (middlename.getValue().isEmpty() || middlename.getValue() == null) {
            Notification.show("Requried Middlename", Notification.Type.WARNING_MESSAGE);
            return;
        }

        if (lastname.getValue().isEmpty() || lastname.getValue() == null) {
            Notification.show("Requried Lastname", Notification.Type.WARNING_MESSAGE);
            return;
        }

        if (status.getValue() == null) {
            Notification.show("Requried Status", Notification.Type.WARNING_MESSAGE);
        }

        if (employeeService.checkIfEmployeeNoExist(employeeNo.getValue().trim().toLowerCase())) {
            Notification.show("EmployeeId already Exist!", Notification.Type.ERROR_MESSAGE);
            return;
        }

        Employee e = new Employee();
        e.setEmployeeNo(employeeNo.getValue().trim().toLowerCase());
        e.setFirstname(firstname.getValue().trim().toLowerCase());
        e.setMiddlename(middlename.getValue().trim().toLowerCase());
        e.setLastname(lastname.getValue().trim().toLowerCase());
        e.setGender(gender.getValue().toString().trim().toLowerCase());
        e.setPersonalStatus(status.getValue().toString());

        boolean result = employeeService.createNewAccount(e);
        if (result) {
            close();
            getHsplit().setFirstComponent(new EmployeesDataGridProperties(getHsplit(), "personal"));
        }
    });
    f.addComponent(saveBtn);

    return f;
}

From source file:com.save.employee.maintenance.MRFormWindow.java

FormLayout buildForms() {
    FormLayout form = new FormLayout();
    form.setWidth("100%");
    form.setMargin(true);/*  ww  w . java 2s  . com*/

    formType = CommonComboBox.getFormType("Select Form Type..");
    formType.setValue(1);
    formType.setWidth("60%");
    form.addComponent(formType);

    area = CommonComboBox.areas();
    area.setWidth("60%");
    form.addComponent(area);

    plateNo = new TextField("Plate No: ");
    plateNo.setWidth("60%");
    form.addComponent(plateNo);

    dateCovered = new DateField("Date Covered: ");
    dateCovered.setWidth("60%");
    form.addComponent(dateCovered);

    amount = new TextField("Amount: ");
    amount.setWidth("60%");
    amount.addStyleName("align-right");
    form.addComponent(amount);

    description = new TextArea("Description: ");
    description.setWidth("100%");
    description.setRows(3);
    form.addComponent(description);

    actionButton = new Button();
    actionButton.setCaption("SAVE");
    actionButton.setWidth("100%");
    actionButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
    actionButton.addClickListener(buttonClickListener);
    form.addComponent(actionButton);

    formType.addValueChangeListener((Property.ValueChangeEvent e) -> {
        if (e.getProperty().getValue().toString().equals("1")) {
            if (getMrId() != 0) {
                actionButton.setCaption("UPDATE");
            } else {
                actionButton.setCaption("SAVE");
            }
            panel.setCaption("MAINTENANCE FORM");
        } else {
            if (getMrId() != 0) {
                actionButton.setCaption("UPDATE");
            } else {
                actionButton.setCaption("SAVE");
            }
            panel.setCaption("REIMBURSEMENT FORM");
        }
    });

    editForm();
    viewForm(form);

    return form;
}

From source file:com.save.employee.request.ViewRLWindow.java

FormLayout buildFormLayout() {
    FormLayout f = new FormLayout();
    f.setWidth("100%");
    f.setMargin(true);//from ww w  .j av a2  s  . com

    LiquidationForm lf = rls.getRLById(getRequestId());

    controlNo = new TextField("Control No.");
    controlNo.setWidth("100%");
    controlNo.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    controlNo.setValue(String.valueOf(lf.getControlNo()));
    controlNo.setEnabled(false);
    f.addComponent(controlNo);

    dateOfActivity = new DateField("Date of Activity: ");
    dateOfActivity.setWidth("100%");
    dateOfActivity.addStyleName(ValoTheme.DATEFIELD_SMALL);
    dateOfActivity.setValue(lf.getDateOfActivity());
    dateOfActivity.setEnabled(false);
    f.addComponent(dateOfActivity);

    area = CommonComboBox.areas();
    area.setWidth("100%");
    area.setValue(lf.getAreaId());
    area.setEnabled(false);
    f.addComponent(area);

    activity = new TextField("Activity: ");
    activity.setWidth("100%");
    activity.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    activity.setValue(lf.getActivity());
    activity.setEnabled(false);
    f.addComponent(activity);

    venue = new TextField("Venue: ");
    venue.setWidth("100%");
    venue.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    venue.setValue(lf.getVenue());
    venue.setEnabled(false);
    f.addComponent(venue);

    requirements = new TextArea("Requirements: ");
    requirements.setWidth("100%");
    requirements.addStyleName(ValoTheme.TEXTAREA_SMALL);
    requirements.setValue(lf.getRequirements());
    requirements.setEnabled(false);
    f.addComponent(requirements);

    HorizontalLayout h1 = new HorizontalLayout();
    h1.setWidth("100%");
    h1.setCaption("Request Lodging");
    h1.addStyleName("light");
    //        h1.setReadOnly(true);

    requestLodgingPax = new TextField();
    requestLodgingPax.setWidth("100%");
    requestLodgingPax.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    requestLodgingPax.addStyleName("align-right");
    requestLodgingPax.setValue("Pax: " + String.valueOf(lf.getLodgingPax()));
    requestLodgingPax.setEnabled(false);
    h1.addComponent(requestLodgingPax);

    requestLodgingBudget = new TextField();
    requestLodgingBudget.setWidth("100%");
    requestLodgingBudget.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    requestLodgingBudget.addStyleName("align-right");
    requestLodgingBudget.setValue("Budget: " + String.valueOf(lf.getLodgingBudget()));
    requestLodgingBudget.setEnabled(false);
    h1.addComponent(requestLodgingBudget);

    requestLodgingAmount = new TextField();
    requestLodgingAmount.setWidth("100%");
    requestLodgingAmount.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    requestLodgingAmount.addStyleName("align-right");
    requestLodgingAmount.setValue("Amount: " + String.valueOf(lf.getLodgingAmount()));
    requestLodgingAmount.setEnabled(false);
    h1.addComponent(requestLodgingAmount);

    f.addComponent(h1);
    f.setComponentAlignment(h1, Alignment.MIDDLE_LEFT);

    HorizontalLayout h2 = new HorizontalLayout();
    h2.setWidth("100%");
    h2.setCaption("Request Meals");
    //        h2.setReadOnly(true);

    requestMealsPax = new TextField();
    requestMealsPax.setWidth("100%");
    requestMealsPax.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    requestMealsPax.addStyleName("align-right");
    requestMealsPax.setValue("Pax: " + String.valueOf(lf.getMealsPax()));
    requestMealsPax.setEnabled(false);
    h2.addComponent(requestMealsPax);

    requestMealsBudget = new TextField();
    requestMealsBudget.setWidth("100%");
    requestMealsBudget.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    requestMealsBudget.addStyleName("align-right");
    requestMealsBudget.setValue("Budget: " + String.valueOf(lf.getMealsBudget()));
    requestMealsBudget.setEnabled(false);
    h2.addComponent(requestMealsBudget);

    requestMealsAmount = new TextField();
    requestMealsAmount.setWidth("100%");
    requestMealsAmount.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    requestMealsAmount.addStyleName("align-right");
    requestMealsAmount.setValue("Amount: " + String.valueOf(lf.getMealsAmount()));
    requestMealsAmount.setEnabled(false);
    h2.addComponent(requestMealsAmount);

    f.addComponent(h2);
    f.setComponentAlignment(h2, Alignment.MIDDLE_LEFT);

    HorizontalLayout h3 = new HorizontalLayout();
    h3.setWidth("100%");
    h3.setCaption("Liquidated Lodging");
    //        h3.setReadOnly(true);

    liquidateLodgingPax = new TextField();
    liquidateLodgingPax.setWidth("100%");
    liquidateLodgingPax.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    liquidateLodgingPax.addStyleName("align-right");
    liquidateLodgingPax.setValue("Pax: " + String.valueOf(lf.getLiquidationLodgingPax()));
    liquidateLodgingPax.setEnabled(false);
    h3.addComponent(liquidateLodgingPax);

    liquidateLodgingBudget = new TextField();
    liquidateLodgingBudget.setWidth("100%");
    liquidateLodgingBudget.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    liquidateLodgingBudget.addStyleName("align-right");
    liquidateLodgingBudget.setValue("Budget: " + String.valueOf(lf.getLiquidationLodgingBudget()));
    liquidateLodgingBudget.setEnabled(false);
    h3.addComponent(liquidateLodgingBudget);

    liquidateLodgingAmount = new TextField();
    liquidateLodgingAmount.setWidth("100%");
    liquidateLodgingAmount.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    liquidateLodgingAmount.addStyleName("align-right");
    liquidateLodgingAmount.setValue("Amount: " + String.valueOf(lf.getLiquidationLodgingAmount()));
    liquidateLodgingAmount.setEnabled(false);
    h3.addComponent(liquidateLodgingAmount);

    f.addComponent(h3);
    f.setComponentAlignment(h3, Alignment.MIDDLE_LEFT);

    HorizontalLayout h4 = new HorizontalLayout();
    h4.setWidth("100%");
    h4.setCaption("Liquidated Meals");
    h4.setReadOnly(true);

    liquidateMealsPax = new TextField();
    liquidateMealsPax.setWidth("100%");
    liquidateMealsPax.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    liquidateMealsPax.addStyleName("align-right");
    liquidateMealsPax.setValue("Pax: " + String.valueOf(lf.getLiquidationMealsPax()));
    liquidateMealsPax.setEnabled(false);
    h4.addComponent(liquidateMealsPax);

    liquidateMealsBudget = new TextField();
    liquidateMealsBudget.setWidth("100%");
    liquidateMealsBudget.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    liquidateMealsBudget.addStyleName("align-right");
    liquidateMealsBudget.setValue("Budget: " + String.valueOf(lf.getLiquidationMealsBudget()));
    liquidateMealsBudget.setEnabled(false);
    h4.addComponent(liquidateMealsBudget);

    liquidateMealsAmount = new TextField();
    liquidateMealsAmount.setWidth("100%");
    liquidateMealsAmount.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    liquidateMealsAmount.addStyleName("align-right");
    liquidateMealsAmount.setValue("Amount: " + String.valueOf(lf.getLiquidationMealsAmount()));
    liquidateMealsAmount.setEnabled(false);
    h4.addComponent(liquidateMealsAmount);

    f.addComponent(h4);
    f.setComponentAlignment(h4, Alignment.MIDDLE_LEFT);

    reimbursement = new TextField("Reimbursement: ");
    reimbursement.setWidth("50%");
    reimbursement.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    reimbursement.setValue(String.valueOf(lf.getReimbursedAmount()));
    reimbursement.setEnabled(false);
    f.addComponent(reimbursement);

    f.addStyleName("light");
    f.setReadOnly(true);

    return f;
}

From source file:com.save.reports.maintenance.MaintenanceReportUI.java

private Window filterReport() {
    Window sub = new Window("FILTER REPORT");
    sub.setWidth("400px");
    sub.setModal(true);//from w ww.j  a  v  a2  s  .co  m
    sub.center();

    FormLayout f = new FormLayout();
    f.setWidth("100%");
    f.setMargin(true);
    f.setSpacing(true);

    CheckBox areaCheckBox = new CheckBox("Filter by Area");
    f.addComponent(areaCheckBox);

    CheckBox employeeCheckBox = new CheckBox("Filter by Employee");
    f.addComponent(employeeCheckBox);

    CheckBox amountCheckBox = new CheckBox("Filter by Amount");
    f.addComponent(amountCheckBox);

    CheckBox dateCheckBox = new CheckBox("Filter by Date");
    f.addComponent(dateCheckBox);

    ComboBox areaComboBox = CommonComboBox.areas();
    ComboBox employeeComboBox = CommonComboBox.getAllClients();

    areaComboBox.setEnabled(false);
    f.addComponent(areaComboBox);
    areaCheckBox.addValueChangeListener((Property.ValueChangeEvent event) -> {
        areaComboBox.setEnabled((boolean) event.getProperty().getValue());
        employeeComboBox.setEnabled(!(boolean) event.getProperty().getValue());
        employeeCheckBox.setValue(!(boolean) event.getProperty().getValue());
        isAreaSelect = (boolean) event.getProperty().getValue();
        isEmployeeSelect = !(boolean) event.getProperty().getValue();
    });

    employeeComboBox.setEnabled(false);
    f.addComponent(employeeComboBox);
    employeeCheckBox.addValueChangeListener((Property.ValueChangeEvent e) -> {
        employeeComboBox.setEnabled((boolean) e.getProperty().getValue());
        areaComboBox.setEnabled(!(boolean) e.getProperty().getValue());
        areaCheckBox.setValue(!(boolean) e.getProperty().getValue());
        isAreaSelect = !(boolean) e.getProperty().getValue();
        isEmployeeSelect = (boolean) e.getProperty().getValue();
    });

    TextField amountField = new CommonTextField("Amount: ");
    amountField.addStyleName("align-right");
    amountField.setEnabled(false);
    f.addComponent(amountField);
    amountCheckBox.addValueChangeListener((Property.ValueChangeEvent e) -> {
        amountField.setEnabled((boolean) e.getProperty().getValue());
        isAmountSelect = (boolean) e.getProperty().getValue();
    });

    HorizontalLayout h = new HorizontalLayout();
    h.setCaption("Date: ");
    h.setWidth("100%");
    h.setSpacing(true);

    DateField from = new DateField();
    from.setWidth("100%");
    from.setEnabled(false);
    h.addComponent(from);

    DateField to = new DateField();
    to.setWidth("100%");
    to.setEnabled(false);
    h.addComponent(to);

    dateCheckBox.addValueChangeListener((Property.ValueChangeEvent e) -> {
        from.setEnabled((boolean) e.getProperty().getValue());
        to.setEnabled((boolean) e.getProperty().getValue());
        isDateSelect = (boolean) e.getProperty().getValue();
    });

    f.addComponent(h);

    Button generate = new CommonButton("Generate Report");
    generate.addClickListener((Button.ClickEvent e) -> {
        if (!isEmployeeSelect && !isAmountSelect && !isDateSelect) {
            mrDataGrid.setContainerDataSource(new MaintenanceDataContainer());
            mrDataGrid.setFrozenColumnCount(2);
        }

        if (isAreaSelect && !isAmountSelect && !isDateSelect) {
            if (areaComboBox.getValue() == null) {
                Notification.show("Select an Area!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            mrDataGrid.setContainerDataSource(
                    new MaintenanceDataContainer(areaComboBox.getItemCaption(areaComboBox.getValue())));
            mrDataGrid.setFrozenColumnCount(2);
        }

        if (isEmployeeSelect && !isAmountSelect && !isDateSelect) {
            if (employeeComboBox.getValue() == null) {
                Notification.show("Select a Client!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            mrDataGrid.setContainerDataSource(new MaintenanceDataContainer((int) employeeComboBox.getValue()));
            mrDataGrid.setFrozenColumnCount(2);
        }

        if (!isEmployeeSelect && isAmountSelect && !isDateSelect) {
            if (amountField.getValue() == null || amountField.getValue().trim().isEmpty()) {
                Notification.show("Enter Amount!", Notification.Type.ERROR_MESSAGE);
                return;
            } else {
                if (!CommonUtilities.checkInputIfDouble(amountField.getValue().trim())) {
                    Notification.show("Enter numeric format for Amount!", Notification.Type.ERROR_MESSAGE);
                    return;
                }
            }

            mrDataGrid.setContainerDataSource(new MaintenanceDataContainer(
                    CommonUtilities.convertStringToDouble(amountField.getValue().trim())));
            mrDataGrid.setFrozenColumnCount(2);
        }

        if (!isEmployeeSelect && !isAmountSelect && isDateSelect) {
            if (from.getValue() == null) {
                Notification.show("Select first Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (to.getValue() == null) {
                Notification.show("Select 2nd Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            mrDataGrid.setContainerDataSource(new MaintenanceDataContainer(from.getValue(), to.getValue()));
            mrDataGrid.setFrozenColumnCount(2);
        }

        if (isAreaSelect && isAmountSelect && !isDateSelect) {
            if (areaComboBox.getValue() == null) {
                Notification.show("Select an Area!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (amountField.getValue() == null || amountField.getValue().trim().isEmpty()) {
                Notification.show("Enter Amount!", Notification.Type.ERROR_MESSAGE);
                return;
            } else {
                if (!CommonUtilities.checkInputIfDouble(amountField.getValue().trim())) {
                    Notification.show("Enter numeric format for Amount!", Notification.Type.ERROR_MESSAGE);
                    return;
                }
            }

            mrDataGrid.setContainerDataSource(
                    new MaintenanceDataContainer(areaComboBox.getItemCaption(areaComboBox.getValue()),
                            CommonUtilities.convertStringToDouble(amountField.getValue().trim())));
            mrDataGrid.setFrozenColumnCount(2);
        }

        if (isEmployeeSelect && isAmountSelect && !isDateSelect) {
            if (employeeComboBox.getValue() == null) {
                Notification.show("Select a Client!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (amountField.getValue() == null || amountField.getValue().trim().isEmpty()) {
                Notification.show("Enter Amount!", Notification.Type.ERROR_MESSAGE);
                return;
            } else {
                if (!CommonUtilities.checkInputIfDouble(amountField.getValue().trim())) {
                    Notification.show("Enter numeric format for Amount!", Notification.Type.ERROR_MESSAGE);
                    return;
                }
            }

            mrDataGrid.setContainerDataSource(new MaintenanceDataContainer((int) employeeComboBox.getValue(),
                    CommonUtilities.convertStringToDouble(amountField.getValue().trim())));
            mrDataGrid.setFrozenColumnCount(2);
        }

        if (isAreaSelect && !isAmountSelect && isDateSelect) {
            if (areaComboBox.getValue() == null) {
                Notification.show("Select an Area!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (from.getValue() == null) {
                Notification.show("Select first Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (to.getValue() == null) {
                Notification.show("Select 2nd Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            mrDataGrid.setContainerDataSource(new MaintenanceDataContainer(
                    areaComboBox.getItemCaption(areaComboBox.getValue()), from.getValue(), to.getValue()));
            mrDataGrid.setFrozenColumnCount(2);
        }

        if (isEmployeeSelect && !isAmountSelect && isDateSelect) {
            if (employeeComboBox.getValue() == null) {
                Notification.show("Select a Client!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (from.getValue() == null) {
                Notification.show("Select first Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (to.getValue() == null) {
                Notification.show("Select 2nd Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            mrDataGrid.setContainerDataSource(new MaintenanceDataContainer((int) employeeComboBox.getValue(),
                    from.getValue(), to.getValue()));
            mrDataGrid.setFrozenColumnCount(2);
        }

        if (!isEmployeeSelect && isAmountSelect && isDateSelect) {
            if (amountField.getValue() == null || amountField.getValue().trim().isEmpty()) {
                Notification.show("Enter Amount!", Notification.Type.ERROR_MESSAGE);
                return;
            } else {
                if (!CommonUtilities.checkInputIfDouble(amountField.getValue().trim())) {
                    Notification.show("Enter numeric format for Amount!", Notification.Type.ERROR_MESSAGE);
                    return;
                }
            }

            if (from.getValue() == null) {
                Notification.show("Select first Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (to.getValue() == null) {
                Notification.show("Select 2nd Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            mrDataGrid.setContainerDataSource(new MaintenanceDataContainer(
                    CommonUtilities.convertStringToDouble(amountField.getValue().trim()), from.getValue(),
                    to.getValue()));
            mrDataGrid.setFrozenColumnCount(2);
        }

        if (isAreaSelect && isAmountSelect && isDateSelect) {
            if (areaComboBox.getValue() == null) {
                Notification.show("Select an Area!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (amountField.getValue() == null || amountField.getValue().trim().isEmpty()) {
                Notification.show("Enter Amount!", Notification.Type.ERROR_MESSAGE);
                return;
            } else {
                if (!CommonUtilities.checkInputIfDouble(amountField.getValue().trim())) {
                    Notification.show("Enter numeric format for Amount!", Notification.Type.ERROR_MESSAGE);
                    return;
                }
            }

            if (from.getValue() == null) {
                Notification.show("Select first Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (to.getValue() == null) {
                Notification.show("Select 2nd Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            mrDataGrid.setContainerDataSource(
                    new MaintenanceDataContainer(employeeComboBox.getItemCaption(employeeComboBox.getValue()),
                            CommonUtilities.convertStringToDouble(amountField.getValue().trim()),
                            from.getValue(), to.getValue()));
            mrDataGrid.setFrozenColumnCount(2);
        }

        if (isEmployeeSelect && isAmountSelect && isDateSelect) {
            if (employeeComboBox.getValue() == null) {
                Notification.show("Select a Client!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (amountField.getValue() == null || amountField.getValue().trim().isEmpty()) {
                Notification.show("Enter Amount!", Notification.Type.ERROR_MESSAGE);
                return;
            } else {
                if (!CommonUtilities.checkInputIfDouble(amountField.getValue().trim())) {
                    Notification.show("Enter numeric format for Amount!", Notification.Type.ERROR_MESSAGE);
                    return;
                }
            }

            if (from.getValue() == null) {
                Notification.show("Select first Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (to.getValue() == null) {
                Notification.show("Select 2nd Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            mrDataGrid.setContainerDataSource(new MaintenanceDataContainer((int) employeeComboBox.getValue(),
                    CommonUtilities.convertStringToDouble(amountField.getValue().trim()), from.getValue(),
                    to.getValue()));
            mrDataGrid.setFrozenColumnCount(2);
        }

        sub.close();
    });
    f.addComponent(generate);

    sub.setContent(f);
    sub.getContent().setHeightUndefined();

    return sub;
}

From source file:com.save.reports.promodeals.PromoDealReportUI.java

private Window filterReport() {
    Window sub = new Window("FILTER REPORT");
    sub.setWidth("400px");
    sub.setModal(true);// w w  w  .ja  v a2  s . com
    sub.center();

    FormLayout f = new FormLayout();
    f.setWidth("100%");
    f.setMargin(true);
    f.setSpacing(true);

    CheckBox areaCheckBox = new CheckBox("Filter by Area");
    f.addComponent(areaCheckBox);

    CheckBox clientCheckBox = new CheckBox("Filter by Client");
    f.addComponent(clientCheckBox);

    CheckBox amountCheckBox = new CheckBox("Filter by Amount");
    f.addComponent(amountCheckBox);

    CheckBox dateCheckBox = new CheckBox("Filter by Date");
    f.addComponent(dateCheckBox);

    ComboBox areaComboBox = CommonComboBox.areas();
    ComboBox clientComboBox = CommonComboBox.getAllClients();

    areaComboBox.setEnabled(false);
    f.addComponent(areaComboBox);
    areaCheckBox.addValueChangeListener((Property.ValueChangeEvent event) -> {
        areaComboBox.setEnabled((boolean) event.getProperty().getValue());
        clientComboBox.setEnabled(!(boolean) event.getProperty().getValue());
        clientCheckBox.setValue(!(boolean) event.getProperty().getValue());
        isAreaSelect = (boolean) event.getProperty().getValue();
        isClientSelect = !(boolean) event.getProperty().getValue();
    });

    clientComboBox.setEnabled(false);
    f.addComponent(clientComboBox);
    clientCheckBox.addValueChangeListener((Property.ValueChangeEvent e) -> {
        clientComboBox.setEnabled((boolean) e.getProperty().getValue());
        areaComboBox.setEnabled(!(boolean) e.getProperty().getValue());
        areaCheckBox.setValue(!(boolean) e.getProperty().getValue());
        isClientSelect = (boolean) e.getProperty().getValue();
        isAreaSelect = !(boolean) e.getProperty().getValue();
    });

    TextField amountField = new CommonTextField("Amount: ");
    amountField.addStyleName("align-right");
    amountField.setEnabled(false);
    f.addComponent(amountField);
    amountCheckBox.addValueChangeListener((Property.ValueChangeEvent e) -> {
        amountField.setEnabled((boolean) e.getProperty().getValue());
        isAmountSelect = (boolean) e.getProperty().getValue();
    });

    HorizontalLayout h = new HorizontalLayout();
    h.setCaption("Date: ");
    h.setWidth("100%");
    h.setSpacing(true);

    DateField from = new DateField();
    from.setWidth("100%");
    from.setEnabled(false);
    h.addComponent(from);

    DateField to = new DateField();
    to.setWidth("100%");
    to.setEnabled(false);
    h.addComponent(to);

    dateCheckBox.addValueChangeListener((Property.ValueChangeEvent e) -> {
        from.setEnabled((boolean) e.getProperty().getValue());
        to.setEnabled((boolean) e.getProperty().getValue());
        isDateSelect = (boolean) e.getProperty().getValue();
    });

    f.addComponent(h);

    Button generate = new CommonButton("Generate Report");
    generate.addClickListener((Button.ClickEvent e) -> {
        if (!isClientSelect && !isAmountSelect && !isDateSelect) {
            promoDealGrid.setContainerDataSource(new PromoDealDataContainer());
            promoDealGrid.setFrozenColumnCount(2);
        }

        if (isAreaSelect && !isAmountSelect && !isDateSelect) {
            if (areaComboBox.getValue() == null) {
                Notification.show("Select a Client!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            promoDealGrid.setContainerDataSource(
                    new PromoDealDataContainer(areaComboBox.getItemCaption(areaComboBox.getValue())));
            promoDealGrid.setFrozenColumnCount(2);
        }

        if (isClientSelect && !isAmountSelect && !isDateSelect) {
            if (clientComboBox.getValue() == null) {
                Notification.show("Select a Client!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            promoDealGrid.setContainerDataSource(new PromoDealDataContainer((int) clientComboBox.getValue()));
            promoDealGrid.setFrozenColumnCount(2);
        }

        if (!isClientSelect && isAmountSelect && !isDateSelect) {
            if (amountField.getValue() == null || amountField.getValue().trim().isEmpty()) {
                Notification.show("Enter Amount!", Notification.Type.ERROR_MESSAGE);
                return;
            } else {
                if (!CommonUtilities.checkInputIfDouble(amountField.getValue().trim())) {
                    Notification.show("Enter numeric format for Amount!", Notification.Type.ERROR_MESSAGE);
                    return;
                }
            }

            promoDealGrid.setContainerDataSource(new PromoDealDataContainer(
                    CommonUtilities.convertStringToDouble(amountField.getValue().trim())));
            promoDealGrid.setFrozenColumnCount(2);
        }

        if (!isClientSelect && !isAmountSelect && isDateSelect) {
            if (from.getValue() == null) {
                Notification.show("Select first Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (to.getValue() == null) {
                Notification.show("Select 2nd Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            promoDealGrid.setContainerDataSource(new PromoDealDataContainer(from.getValue(), to.getValue()));
            promoDealGrid.setFrozenColumnCount(2);
        }

        if (isAreaSelect && isAmountSelect && !isDateSelect) {
            if (areaComboBox.getValue() == null) {
                Notification.show("Select an Area!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (amountField.getValue() == null || amountField.getValue().trim().isEmpty()) {
                Notification.show("Enter Amount!", Notification.Type.ERROR_MESSAGE);
                return;
            } else {
                if (!CommonUtilities.checkInputIfDouble(amountField.getValue().trim())) {
                    Notification.show("Enter numeric format for Amount!", Notification.Type.ERROR_MESSAGE);
                    return;
                }
            }

            promoDealGrid.setContainerDataSource(
                    new PromoDealDataContainer(areaComboBox.getItemCaption(areaComboBox.getValue()),
                            CommonUtilities.convertStringToDouble(amountField.getValue().trim())));
            promoDealGrid.setFrozenColumnCount(2);
        }

        if (isClientSelect && isAmountSelect && !isDateSelect) {
            if (clientComboBox.getValue() == null) {
                Notification.show("Select a Client!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (amountField.getValue() == null || amountField.getValue().trim().isEmpty()) {
                Notification.show("Enter Amount!", Notification.Type.ERROR_MESSAGE);
                return;
            } else {
                if (!CommonUtilities.checkInputIfDouble(amountField.getValue().trim())) {
                    Notification.show("Enter numeric format for Amount!", Notification.Type.ERROR_MESSAGE);
                    return;
                }
            }

            promoDealGrid.setContainerDataSource(new PromoDealDataContainer((int) clientComboBox.getValue(),
                    CommonUtilities.convertStringToDouble(amountField.getValue().trim())));
            promoDealGrid.setFrozenColumnCount(2);
        }

        if (isAreaSelect && !isAmountSelect && isDateSelect) {
            if (areaComboBox.getValue() == null) {
                Notification.show("Select an Area!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (from.getValue() == null) {
                Notification.show("Select first Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (to.getValue() == null) {
                Notification.show("Select 2nd Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            promoDealGrid.setContainerDataSource(new PromoDealDataContainer(
                    areaComboBox.getItemCaption(areaComboBox.getValue()), from.getValue(), to.getValue()));
            promoDealGrid.setFrozenColumnCount(2);
        }

        if (isClientSelect && !isAmountSelect && isDateSelect) {
            if (clientComboBox.getValue() == null) {
                Notification.show("Select a Client!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (from.getValue() == null) {
                Notification.show("Select first Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (to.getValue() == null) {
                Notification.show("Select 2nd Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            promoDealGrid.setContainerDataSource(new PromoDealDataContainer((int) clientComboBox.getValue(),
                    from.getValue(), to.getValue()));
            promoDealGrid.setFrozenColumnCount(2);
        }

        if (!isClientSelect && isAmountSelect && isDateSelect) {
            if (amountField.getValue() == null || amountField.getValue().trim().isEmpty()) {
                Notification.show("Enter Amount!", Notification.Type.ERROR_MESSAGE);
                return;
            } else {
                if (!CommonUtilities.checkInputIfDouble(amountField.getValue().trim())) {
                    Notification.show("Enter numeric format for Amount!", Notification.Type.ERROR_MESSAGE);
                    return;
                }
            }

            if (from.getValue() == null) {
                Notification.show("Select first Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (to.getValue() == null) {
                Notification.show("Select 2nd Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            promoDealGrid.setContainerDataSource(new PromoDealDataContainer(
                    CommonUtilities.convertStringToDouble(amountField.getValue().trim()), from.getValue(),
                    to.getValue()));
            promoDealGrid.setFrozenColumnCount(2);
        }

        if (isAreaSelect && isAmountSelect && isDateSelect) {
            if (areaComboBox.getValue() == null) {
                Notification.show("Select an Area!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (amountField.getValue() == null || amountField.getValue().trim().isEmpty()) {
                Notification.show("Enter Amount!", Notification.Type.ERROR_MESSAGE);
                return;
            } else {
                if (!CommonUtilities.checkInputIfDouble(amountField.getValue().trim())) {
                    Notification.show("Enter numeric format for Amount!", Notification.Type.ERROR_MESSAGE);
                    return;
                }
            }

            if (from.getValue() == null) {
                Notification.show("Select first Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (to.getValue() == null) {
                Notification.show("Select 2nd Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            promoDealGrid.setContainerDataSource(
                    new PromoDealDataContainer(areaComboBox.getItemCaption(areaComboBox.getValue()),
                            CommonUtilities.convertStringToDouble(amountField.getValue().trim()),
                            from.getValue(), to.getValue()));
            promoDealGrid.setFrozenColumnCount(2);
        }

        if (isClientSelect && isAmountSelect && isDateSelect) {
            if (clientComboBox.getValue() == null) {
                Notification.show("Select a Client!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (amountField.getValue() == null || amountField.getValue().trim().isEmpty()) {
                Notification.show("Enter Amount!", Notification.Type.ERROR_MESSAGE);
                return;
            } else {
                if (!CommonUtilities.checkInputIfDouble(amountField.getValue().trim())) {
                    Notification.show("Enter numeric format for Amount!", Notification.Type.ERROR_MESSAGE);
                    return;
                }
            }

            if (from.getValue() == null) {
                Notification.show("Select first Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (to.getValue() == null) {
                Notification.show("Select 2nd Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            promoDealGrid.setContainerDataSource(new PromoDealDataContainer((int) clientComboBox.getValue(),
                    CommonUtilities.convertStringToDouble(amountField.getValue().trim()), from.getValue(),
                    to.getValue()));
            promoDealGrid.setFrozenColumnCount(2);
        }

        sub.close();
    });
    f.addComponent(generate);

    sub.setContent(f);
    sub.getContent().setHeightUndefined();

    return sub;
}

From source file:com.save.reports.reimbursement.ReimbursementReportUI.java

private Window filterReport() {
    Window sub = new Window("FILTER REPORT");
    sub.setWidth("400px");
    sub.setModal(true);/*w ww  .  j av a2s . c o  m*/
    sub.center();

    FormLayout f = new FormLayout();
    f.setWidth("100%");
    f.setMargin(true);
    f.setSpacing(true);

    CheckBox employeeCheckBox = new CheckBox("Filter by Employee");
    f.addComponent(employeeCheckBox);

    CheckBox amountCheckBox = new CheckBox("Filter by Amount");
    f.addComponent(amountCheckBox);

    CheckBox dateCheckBox = new CheckBox("Filter by Date");
    f.addComponent(dateCheckBox);

    ComboBox employeeComboBox = CommonComboBox.getAllEmpployees(null);
    employeeComboBox.setEnabled(false);
    f.addComponent(employeeComboBox);
    employeeCheckBox.addValueChangeListener((Property.ValueChangeEvent e) -> {
        employeeComboBox.setEnabled((boolean) e.getProperty().getValue());
        isEmployee = (boolean) e.getProperty().getValue();
    });

    TextField amountField = new CommonTextField("Amount: ");
    amountField.addStyleName("align-right");
    amountField.setEnabled(false);
    f.addComponent(amountField);
    amountCheckBox.addValueChangeListener((Property.ValueChangeEvent e) -> {
        amountField.setEnabled((boolean) e.getProperty().getValue());
        isAmount = (boolean) e.getProperty().getValue();
    });

    HorizontalLayout h = new HorizontalLayout();
    h.setCaption("Date: ");
    h.setWidth("100%");
    h.setSpacing(true);

    DateField from = new DateField();
    from.setWidth("100%");
    from.setEnabled(false);
    h.addComponent(from);

    DateField to = new DateField();
    to.setWidth("100%");
    to.setEnabled(false);
    h.addComponent(to);

    dateCheckBox.addValueChangeListener((Property.ValueChangeEvent e) -> {
        from.setEnabled((boolean) e.getProperty().getValue());
        to.setEnabled((boolean) e.getProperty().getValue());
        isDate = (boolean) e.getProperty().getValue();
    });

    f.addComponent(h);

    Button generate = new CommonButton("Generate Report");
    generate.addClickListener((Button.ClickEvent e) -> {
        if (!isEmployee && !isAmount && !isDate) {
            mrDataGrid.setContainerDataSource(new ReimbursementDataContainer());
            mrDataGrid.setFrozenColumnCount(2);
        }

        if (isEmployee && !isAmount && !isDate) {
            if (employeeComboBox.getValue() == null) {
                Notification.show("Select a Client!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            mrDataGrid.setContainerDataSource(
                    new ReimbursementDataContainer(employeeComboBox.getValue().toString()));
            mrDataGrid.setFrozenColumnCount(2);
        }

        if (!isEmployee && isAmount && !isDate) {
            if (amountField.getValue() == null || amountField.getValue().trim().isEmpty()) {
                Notification.show("Enter Amount!", Notification.Type.ERROR_MESSAGE);
                return;
            } else {
                if (!CommonUtilities.checkInputIfDouble(amountField.getValue().trim())) {
                    Notification.show("Enter numeric format for Amount!", Notification.Type.ERROR_MESSAGE);
                    return;
                }
            }

            mrDataGrid.setContainerDataSource(new ReimbursementDataContainer(
                    CommonUtilities.convertStringToDouble(amountField.getValue().trim())));
            mrDataGrid.setFrozenColumnCount(2);
        }

        if (!isEmployee && !isAmount && isDate) {
            if (from.getValue() == null) {
                Notification.show("Select first Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (to.getValue() == null) {
                Notification.show("Select 2nd Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            mrDataGrid.setContainerDataSource(new ReimbursementDataContainer(from.getValue(), to.getValue()));
            mrDataGrid.setFrozenColumnCount(2);
        }

        if (isEmployee && isAmount && !isDate) {
            if (employeeComboBox.getValue() == null) {
                Notification.show("Select a Client!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (amountField.getValue() == null || amountField.getValue().trim().isEmpty()) {
                Notification.show("Enter Amount!", Notification.Type.ERROR_MESSAGE);
                return;
            } else {
                if (!CommonUtilities.checkInputIfDouble(amountField.getValue().trim())) {
                    Notification.show("Enter numeric format for Amount!", Notification.Type.ERROR_MESSAGE);
                    return;
                }
            }

            mrDataGrid.setContainerDataSource(
                    new ReimbursementDataContainer(employeeComboBox.getValue().toString(),
                            CommonUtilities.convertStringToDouble(amountField.getValue().trim())));
            mrDataGrid.setFrozenColumnCount(2);
        }

        if (isEmployee && !isAmount && isDate) {
            if (employeeComboBox.getValue() == null) {
                Notification.show("Select a Client!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (from.getValue() == null) {
                Notification.show("Select first Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (to.getValue() == null) {
                Notification.show("Select 2nd Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            mrDataGrid.setContainerDataSource(new ReimbursementDataContainer(
                    employeeComboBox.getValue().toString(), from.getValue(), to.getValue()));
            mrDataGrid.setFrozenColumnCount(2);
        }

        if (!isEmployee && isAmount && isDate) {
            if (amountField.getValue() == null || amountField.getValue().trim().isEmpty()) {
                Notification.show("Enter Amount!", Notification.Type.ERROR_MESSAGE);
                return;
            } else {
                if (!CommonUtilities.checkInputIfDouble(amountField.getValue().trim())) {
                    Notification.show("Enter numeric format for Amount!", Notification.Type.ERROR_MESSAGE);
                    return;
                }
            }

            if (from.getValue() == null) {
                Notification.show("Select first Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (to.getValue() == null) {
                Notification.show("Select 2nd Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            mrDataGrid.setContainerDataSource(new ReimbursementDataContainer(
                    CommonUtilities.convertStringToDouble(amountField.getValue().trim()), from.getValue(),
                    to.getValue()));
            mrDataGrid.setFrozenColumnCount(2);
        }

        if (isEmployee && isAmount && isDate) {
            if (employeeComboBox.getValue() == null) {
                Notification.show("Select a Client!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (amountField.getValue() == null || amountField.getValue().trim().isEmpty()) {
                Notification.show("Enter Amount!", Notification.Type.ERROR_MESSAGE);
                return;
            } else {
                if (!CommonUtilities.checkInputIfDouble(amountField.getValue().trim())) {
                    Notification.show("Enter numeric format for Amount!", Notification.Type.ERROR_MESSAGE);
                    return;
                }
            }

            if (from.getValue() == null) {
                Notification.show("Select first Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            if (to.getValue() == null) {
                Notification.show("Select 2nd Date!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            mrDataGrid.setContainerDataSource(
                    new ReimbursementDataContainer(employeeComboBox.getValue().toString(),
                            CommonUtilities.convertStringToDouble(amountField.getValue().trim()),
                            from.getValue(), to.getValue()));
            mrDataGrid.setFrozenColumnCount(2);
        }

        sub.close();
    });
    f.addComponent(generate);

    sub.setContent(f);
    sub.getContent().setHeightUndefined();

    return sub;
}

From source file:com.skysql.manager.ui.ChartPreviewLayout.java

License:Open Source License

/**
 * Instantiates a new chart preview layout.
 *
 * @param userChart the user chart//  w ww .j  av a  2  s.co  m
 * @param time the time
 * @param interval the interval
 */
public ChartPreviewLayout(final UserChart userChart, String time, String interval) {
    this.userChart = userChart;
    this.time = time;
    this.interval = interval;

    addStyleName("ChartPreviewLayout");
    setSpacing(true);
    setMargin(true);

    HorizontalLayout formDescription = new HorizontalLayout();
    formDescription.setSpacing(true);

    Embedded info = new Embedded(null, new ThemeResource("img/info.png"));
    info.addStyleName("infoButton");
    String infoText = "<table border=0 cellspacing=3 cellpadding=0 summary=\"\">\n"
            + "     <tr bgcolor=\"#ccccff\">" + "         <th align=left>Field"
            + "         <th align=left>Description" + "     <tr>" + "         <td><code>Title</code>"
            + "         <td>Name of the Chart" + "     <tr bgcolor=\"#eeeeff\">"
            + "         <td><code>Description</code>" + "         <td>Description of the Chart " + "     <tr>"
            + "         <td nowrap><code>Measurement Unit</code>"
            + "         <td>Unit of measurement for the data returned by the monitor, used as caption for the vertical axis of the chart"
            + "     <tr bgcolor=\"#eeeeff\">" + "         <td><code>Type</code>"
            + "         <td>Chart type (LineChart, AreaChart)" + "     <tr>"
            + "         <td><code>Points</code>" + "         <td>Number of data points displayed";
    infoText += " </table>" + " </blockquote>";
    info.setDescription(infoText);
    formDescription.addComponent(info);

    final Label monitorsLabel = new Label("Display as Chart");
    monitorsLabel.setStyleName("dialogLabel");
    formDescription.addComponent(monitorsLabel);
    formDescription.setComponentAlignment(monitorsLabel, Alignment.MIDDLE_LEFT);

    addComponent(formDescription);
    setComponentAlignment(formDescription, Alignment.TOP_CENTER);

    HorizontalLayout chartInfo = new HorizontalLayout();
    chartInfo.setSpacing(true);
    addComponent(chartInfo);
    setComponentAlignment(chartInfo, Alignment.MIDDLE_CENTER);

    FormLayout formLayout = new FormLayout();
    chartInfo.addComponent(formLayout);

    chartName = new TextField("Title");
    chartName.setImmediate(true);
    formLayout.addComponent(chartName);

    chartDescription = new TextField("Description");
    chartDescription.setWidth("25em");
    chartDescription.setImmediate(true);
    formLayout.addComponent(chartDescription);

    chartUnit = new TextField("Measurement Unit");
    chartUnit.setImmediate(true);
    formLayout.addComponent(chartUnit);

    chartSelectType = new NativeSelect("Type");
    chartSelectType.setImmediate(true);
    for (UserChart.ChartType type : UserChart.ChartType.values()) {
        chartSelectType.addItem(type.name());
    }
    chartSelectType.setNullSelectionAllowed(false);
    formLayout.addComponent(chartSelectType);

    selectCount = new NativeSelect("Points");
    selectCount.setImmediate(true);
    for (int points : UserChart.chartPoints()) {
        selectCount.addItem(points);
        selectCount.setItemCaption(points, String.valueOf(points));
    }
    selectCount.setNullSelectionAllowed(false);
    formLayout.addComponent(selectCount);

    updateChartInfo(userChart.getName(), userChart.getDescription(), userChart.getUnit(), userChart.getType(),
            userChart.getPoints());

    chartName.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void valueChange(ValueChangeEvent event) {

            String chartName = (String) (event.getProperty()).getValue();
            userChart.setName(chartName);
            refreshChart();

        }
    });

    chartDescription.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void valueChange(ValueChangeEvent event) {

            String value = (String) (event.getProperty()).getValue();
            userChart.setDescription(value);
            refreshChart();

        }
    });

    chartUnit.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void valueChange(ValueChangeEvent event) {

            String value = (String) (event.getProperty()).getValue();
            userChart.setUnit(value);
            refreshChart();

        }
    });

    chartSelectType.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void valueChange(ValueChangeEvent event) {

            String value = (String) (event.getProperty()).getValue();
            userChart.setType(value);
            refreshChart();

        }
    });

    selectCount.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void valueChange(ValueChangeEvent event) {

            int points = (Integer) (event.getProperty()).getValue();
            userChart.setPoints(points);
            refreshChart();

        }
    });

    chartLayout = drawChart();
    addComponent(chartLayout);

}

From source file:com.skysql.manager.ui.components.ChartControls.java

License:Open Source License

/**
 * Instantiates a new chart controls./*from  ww w .  j a va  2s.c o  m*/
 */
public ChartControls() {

    setSpacing(true);

    final FormLayout form1 = new FormLayout();
    form1.setSpacing(false);
    form1.setMargin(false);
    addComponent(form1);

    selectInterval = new NativeSelect("Charts Time Span");
    selectInterval.setImmediate(true);
    selectInterval.setNullSelectionAllowed(false);

    selectInterval.addItem(INTERVAL_5_MIN);
    selectInterval.addItem(INTERVAL_10_MIN);
    selectInterval.addItem(INTERVAL_30_MIN);
    selectInterval.addItem(INTERVAL_1_HOUR);
    selectInterval.addItem(INTERVAL_6_HOURS);
    selectInterval.addItem(INTERVAL_12_HOURS);
    selectInterval.addItem(INTERVAL_1_DAY);
    selectInterval.addItem(INTERVAL_1_WEEK);
    selectInterval.addItem(INTERVAL_1_MONTH);

    selectInterval.setItemCaption(INTERVAL_5_MIN, "5 Minutes");
    selectInterval.setItemCaption(INTERVAL_10_MIN, "10 Minutes");
    selectInterval.setItemCaption(INTERVAL_30_MIN, "30 Minutes");
    selectInterval.setItemCaption(INTERVAL_1_HOUR, "1 Hour");
    selectInterval.setItemCaption(INTERVAL_6_HOURS, "6 Hours");
    selectInterval.setItemCaption(INTERVAL_12_HOURS, "12 Hours");
    selectInterval.setItemCaption(INTERVAL_1_DAY, "1 Day");
    selectInterval.setItemCaption(INTERVAL_1_WEEK, "1 Week");
    selectInterval.setItemCaption(INTERVAL_1_MONTH, "1 Month");

    form1.addComponent(selectInterval);

    final FormLayout form2 = new FormLayout();
    form2.setSpacing(false);
    form2.setMargin(false);
    addComponent(form2);

    selectTheme = new NativeSelect("Theme");
    selectTheme.setImmediate(true);
    selectTheme.setNullSelectionAllowed(false);

    for (Themes theme : Themes.values()) {
        selectTheme.addItem(theme.name());
    }
    form2.addComponent(selectTheme);

}

From source file:com.skysql.manager.ui.components.ParametersLayout.java

License:Open Source License

/**
 * Instantiates a new parameters layout.
 *
 * @param runningTask the running task/*from   www. j  a  v  a  2s  . c o  m*/
 * @param nodeInfo the node info
 * @param commandEnum the command enum
 */
public ParametersLayout(final RunningTask runningTask, final NodeInfo nodeInfo, Commands.Command commandEnum) {
    this.runningTask = runningTask;

    addStyleName("parametersLayout");
    setSizeFull();
    setSpacing(true);
    setMargin(true);

    params = new HashMap<String, String>();
    runningTask.selectParameter(params);

    switch (commandEnum) {
    case backup:
        backupLevel = new OptionGroup("Backup Level");
        backupLevel.setImmediate(true);
        backupLevel.addItem(BackupRecord.BACKUP_TYPE_FULL);
        backupLevel.setItemCaption(BackupRecord.BACKUP_TYPE_FULL, "Full");
        backupLevel.addItem(BackupRecord.BACKUP_TYPE_INCREMENTAL);
        backupLevel.setItemCaption(BackupRecord.BACKUP_TYPE_INCREMENTAL, "Incremental");
        addComponent(backupLevel);
        setComponentAlignment(backupLevel, Alignment.MIDDLE_LEFT);
        backupLevel.addValueChangeListener(new ValueChangeListener() {
            private static final long serialVersionUID = 0x4C656F6E6172646FL;

            public void valueChange(ValueChangeEvent event) {
                String level = (String) event.getProperty().getValue();
                params.put(PARAM_BACKUP_TYPE, level);
                if (level.equals(BackupRecord.BACKUP_TYPE_INCREMENTAL)) {
                    addComponent(prevBackupsLayout);
                    selectPrevBackup.select(firstItem);
                } else {
                    params.remove(PARAM_BACKUP_PARENT);
                    if (getComponentIndex(prevBackupsLayout) != -1) {
                        removeComponent(prevBackupsLayout);
                    }
                }
            }
        });

        backupLevel.setValue(BackupRecord.BACKUP_TYPE_FULL);
        isParameterReady = true;

    case restore:
        VerticalLayout restoreLayout = new VerticalLayout();
        restoreLayout.setSpacing(true);

        if (commandEnum == Command.restore) {
            addComponent(restoreLayout);
            FormLayout formLayout = new FormLayout();
            //formLayout.setMargin(new MarginInfo(false, false, true, false));
            formLayout.setMargin(false);
            restoreLayout.addComponent(formLayout);

            final NativeSelect selectSystem;
            selectSystem = new NativeSelect("Backups from");
            selectSystem.setImmediate(true);
            selectSystem.setNullSelectionAllowed(false);
            SystemInfo systemInfo = VaadinSession.getCurrent().getAttribute(SystemInfo.class);
            for (SystemRecord systemRecord : systemInfo.getSystemsMap().values()) {
                if (!systemRecord.getID().equals(SystemInfo.SYSTEM_ROOT)) {
                    selectSystem.addItem(systemRecord.getID());
                    selectSystem.setItemCaption(systemRecord.getID(), systemRecord.getName());
                }
            }
            selectSystem.select(systemInfo.getCurrentID());
            formLayout.addComponent(selectSystem);
            selectSystem.addValueChangeListener(new ValueChangeListener() {
                private static final long serialVersionUID = 0x4C656F6E6172646FL;

                public void valueChange(ValueChangeEvent event) {
                    String systemID = (String) event.getProperty().getValue();
                    Backups backups = new Backups(systemID, null);
                    backupsList = backups.getBackupsList();
                    selectPrevBackup.removeAllItems();
                    firstItem = null;
                    if (backupsList != null && backupsList.size() > 0) {
                        Collection<BackupRecord> set = backupsList.values();
                        Iterator<BackupRecord> iter = set.iterator();
                        while (iter.hasNext()) {
                            BackupRecord backupRecord = iter.next();
                            String backupID = backupRecord.getID();
                            selectPrevBackup.addItem(backupID);
                            selectPrevBackup.setItemCaption(backupID,
                                    "ID: " + backupID + ", " + backupRecord.getStarted());
                            if (firstItem == null) {
                                firstItem = backupID;
                                selectPrevBackup.select(firstItem);
                            }
                        }
                        runningTask.getControlsLayout().enableControls(true, Controls.Run);
                    } else {
                        if (backupInfoLayout != null) {
                            displayBackupInfo(backupInfoLayout, new BackupRecord());
                        }
                        runningTask.getControlsLayout().enableControls(false, Controls.Run);
                    }
                }
            });
        }
        prevBackupsLayout = new HorizontalLayout();
        restoreLayout.addComponent(prevBackupsLayout);

        selectPrevBackup = (commandEnum == Command.backup) ? new ListSelect("Backups") : new ListSelect();
        selectPrevBackup.setImmediate(true);
        selectPrevBackup.setNullSelectionAllowed(false);
        selectPrevBackup.setRows(8); // Show a few items and a scrollbar if there are more
        selectPrevBackup.setWidth("20em");
        prevBackupsLayout.addComponent(selectPrevBackup);
        final Backups backups = new Backups(nodeInfo.getParentID(), null);
        //*** this is for when we only want backups from a specific node
        // backupsList = backups.getBackupsForNode(nodeInfo.getID());
        backupsList = backups.getBackupsList();
        if (backupsList != null && backupsList.size() > 0) {
            Collection<BackupRecord> set = backupsList.values();
            Iterator<BackupRecord> iter = set.iterator();
            while (iter.hasNext()) {
                BackupRecord backupRecord = iter.next();
                selectPrevBackup.addItem(backupRecord.getID());
                selectPrevBackup.setItemCaption(backupRecord.getID(),
                        "ID: " + backupRecord.getID() + ", " + backupRecord.getStarted());
                if (firstItem == null) {
                    firstItem = backupRecord.getID();
                }
            }

            backupInfoLayout = new VerticalLayout();
            backupInfoLayout.setSpacing(false);
            backupInfoLayout.setMargin(new MarginInfo(false, true, false, true));
            prevBackupsLayout.addComponent(backupInfoLayout);
            prevBackupsLayout.setComponentAlignment(backupInfoLayout, Alignment.MIDDLE_CENTER);

            selectPrevBackup.addValueChangeListener(new ValueChangeListener() {
                private static final long serialVersionUID = 0x4C656F6E6172646FL;

                public void valueChange(ValueChangeEvent event) {
                    String backupID = (String) event.getProperty().getValue();
                    if (backupID == null) {
                        isParameterReady = false;
                        runningTask.getControlsLayout().enableControls(isParameterReady, Controls.Run);
                        return;
                    }
                    BackupRecord backupRecord = backupsList.get(backupID);
                    displayBackupInfo(backupInfoLayout, backupRecord);
                    if (backupLevel != null) {
                        // we're doing a backup
                        params.put(PARAM_BACKUP_PARENT, backupRecord.getID());
                    } else {
                        // we're doing a restore
                        params.put(PARAM_BACKUP_ID, backupRecord.getID());
                    }
                    isParameterReady = true;
                    ScriptingControlsLayout controlsLayout = runningTask.getControlsLayout();
                    if (controlsLayout != null) {
                        controlsLayout.enableControls(isParameterReady, Controls.Run);
                    }
                }
            });

            // final DisplayBackupRecord displayRecord = new
            // DisplayBackupRecord(parameterLayout);

            if (commandEnum == Command.restore) {
                restoreLayout.addComponent(prevBackupsLayout);
                selectPrevBackup.select(firstItem);
            }

        } else {
            // no previous backups
            if (commandEnum == Command.backup) {
                backupLevel.setEnabled(false);
                isParameterReady = true;
            } else if (commandEnum == Command.restore) {
                //runningTask.getControlsLayout().enableControls(false, Controls.run);
            }
        }
        break;

    case connect:
        VerticalLayout connectLayout = new VerticalLayout();
        addComponent(connectLayout);

        final Validator validator = new Password2Validator(connectPassword);

        passwordOption.addItem(true);
        passwordOption.setItemCaption(true, "Authenticate with root user");
        passwordOption.addItem(false);
        passwordOption.setItemCaption(false, "Authenticate with SSH Key");
        passwordOption.setImmediate(true);
        passwordOption.addValueChangeListener(new Property.ValueChangeListener() {
            private static final long serialVersionUID = 0x4C656F6E6172646FL;

            @Override
            public void valueChange(ValueChangeEvent event) {
                usePassword = (Boolean) event.getProperty().getValue();
                if (usePassword) {
                    connectPassword2.addValidator(validator);
                } else {
                    connectPassword2.removeValidator(validator);
                }
                connectPassword.setVisible(usePassword);
                connectPassword.setRequired(usePassword);
                connectPassword2.setVisible(usePassword);
                connectPassword2.setRequired(usePassword);
                connectKey.setVisible(!usePassword);
                connectKey.setRequired(!usePassword);
                boolean isValid;
                if (runningTask.getControlsLayout() != null) {
                    if (usePassword) {
                        isValid = connectPassword.isValid();
                    } else {
                        isValid = connectKey.isValid();
                    }
                    if (isValid) {
                        connectParamsListener.valueChange(null);
                    } else {
                        form.setComponentError(null);
                        form.setValidationVisible(false);
                        runningTask.getControlsLayout().enableControls(false, Controls.Run);
                    }
                }
            }
        });
        connectLayout.addComponent(passwordOption);
        passwordOption.select(false);

        connectLayout.addComponent(form);
        form.setImmediate(true);
        form.setFooter(null);
        Layout layout = form.getLayout();

        form.addField("connectPassword", connectPassword);
        connectPassword.setImmediate(true);
        connectPassword.setRequiredError("Root Password is a required field");
        connectPassword.addValueChangeListener(connectParamsListener);

        form.addField("connectPassword2", connectPassword2);
        connectPassword2.setImmediate(true);
        connectPassword2.setRequiredError("Confirm Password is a required field");
        connectPassword2.addValueChangeListener(connectParamsListener);

        form.addField("connectKey", connectKey);
        connectKey.setStyleName("sshkey");
        connectKey.setColumns(41);
        connectKey.setImmediate(true);
        connectKey.setRequiredError("SSH Key is a required field");
        connectKey.addValueChangeListener(connectParamsListener);
        break;

    default:
        isParameterReady = true;
        break;

    }

}