Example usage for com.vaadin.ui FormLayout addComponent

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

Introduction

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

Prototype

@Override
public void addComponent(Component c) 

Source Link

Document

Add a component into this container.

Usage

From source file:org.jumpmind.vaadin.ui.sqlexplorer.DbFillDialog.java

License:Open Source License

protected void createOptionLayout() {
    optionLayout = new VerticalLayout();
    optionLayout.addStyleName("v-scrollable");
    optionLayout.setMargin(true);/*  www .  jav  a2  s  . c  o  m*/
    optionLayout.setSpacing(true);
    optionLayout.setSizeFull();
    optionLayout.addComponent(new Label("Please choose from the following options"));

    FormLayout formLayout = new FormLayout();
    formLayout.setSizeFull();
    optionLayout.addComponent(formLayout);
    optionLayout.setExpandRatio(formLayout, 1);

    countField = new TextField("Count (# of rows to fill)");
    countField.setValue("1");
    countField.setTextChangeEventMode(TextChangeEventMode.EAGER);
    countField.addTextChangeListener(new TextChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void textChange(TextChangeEvent event) {
            countField.setValue(event.getText());
            fillButton.setEnabled(enableFillButton());
        }
    });
    formLayout.addComponent(countField);

    intervalField = new TextField("Interval (ms)");
    intervalField.setValue("0");
    intervalField.setTextChangeEventMode(TextChangeEventMode.EAGER);
    intervalField.addTextChangeListener(new TextChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void textChange(TextChangeEvent event) {
            intervalField.setValue(event.getText());
            fillButton.setEnabled(enableFillButton());
        }
    });
    formLayout.addComponent(intervalField);

    insertWeightField = new TextField("Insert Weight");
    insertWeightField.setValue("1");
    insertWeightField.setTextChangeEventMode(TextChangeEventMode.EAGER);
    insertWeightField.addTextChangeListener(new TextChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void textChange(TextChangeEvent event) {
            insertWeightField.setValue(event.getText());
            fillButton.setEnabled(enableFillButton());
        }
    });
    formLayout.addComponent(insertWeightField);

    updateWeightField = new TextField("Update Weight");
    updateWeightField.setValue("0");
    updateWeightField.setTextChangeEventMode(TextChangeEventMode.EAGER);
    updateWeightField.addTextChangeListener(new TextChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void textChange(TextChangeEvent event) {
            updateWeightField.setValue(event.getText());
            fillButton.setEnabled(enableFillButton());
        }
    });
    formLayout.addComponent(updateWeightField);

    deleteWeightField = new TextField("Delete Weight");
    deleteWeightField.setValue("0");
    deleteWeightField.setTextChangeEventMode(TextChangeEventMode.EAGER);
    deleteWeightField.addTextChangeListener(new TextChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void textChange(TextChangeEvent event) {
            deleteWeightField.setValue(event.getText());
            fillButton.setEnabled(enableFillButton());
        }
    });
    formLayout.addComponent(deleteWeightField);

    continueBox = new CheckBox("Continue (ignore ANY errors and continue to modify)");
    continueBox.setValue(true);
    formLayout.addComponent(continueBox);

    cascadeBox = new CheckBox("Fill dependent tables also.");
    cascadeBox.setValue(false);
    formLayout.addComponent(cascadeBox);

    cascadeSelectBox = new CheckBox("Fill dependent tables by selecting existing data.");
    cascadeSelectBox.setValue(false);
    formLayout.addComponent(cascadeSelectBox);

    verboseBox = new CheckBox("Turn on verbose logging during fill.");
    verboseBox.setValue(false);
    formLayout.addComponent(verboseBox);

    truncateBox = new CheckBox("Truncate table(s) before filling.");
    truncateBox.setValue(false);
    formLayout.addComponent(truncateBox);

    oGroup = new OptionGroup();
    oGroup.addItem("Fill Table(s)");
    oGroup.addItem("Send to Sql Editor");
    oGroup.select("Fill Table(s)");
    oGroup.setNullSelectionAllowed(false);
    formLayout.addComponent(oGroup);

}

From source file:org.jumpmind.vaadin.ui.sqlexplorer.DbImportDialog.java

License:Open Source License

protected void createImportLayout() {
    importLayout = new VerticalLayout();
    importLayout.setSizeFull();/* w ww  . j a  v  a2s  .c o  m*/
    importLayout.addStyleName("v-scrollable");
    importLayout.setMargin(true);
    importLayout.setSpacing(true);

    importLayout.addComponent(new Label("Please select from the following options"));

    FormLayout formLayout = new FormLayout();
    formLayout.setSizeFull();
    importLayout.addComponent(formLayout);
    importLayout.setExpandRatio(formLayout, 1);

    formatSelect = new ComboBox("Format");
    for (DbImportFormat format : DbImportFormat.values()) {
        formatSelect.addItem(format);
    }
    formatSelect.setNullSelectionAllowed(false);
    formatSelect.setValue(DbImportFormat.SQL);
    formatSelect.addValueChangeListener(new Property.ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            DbImportFormat format = (DbImportFormat) formatSelect.getValue();

            switch (format) {
            case SQL:
                listOfTablesSelect.setEnabled(false);
                alter.setEnabled(false);
                alterCase.setEnabled(false);
                break;
            case XML:
                listOfTablesSelect.setEnabled(false);
                alter.setEnabled(true);
                alterCase.setEnabled(true);
                break;
            case CSV:
                listOfTablesSelect.setEnabled(true);
                alter.setEnabled(false);
                alterCase.setEnabled(false);
                importButton.setEnabled(importButtonEnable());
                break;
            case SYM_XML:
                listOfTablesSelect.setEnabled(false);
                alter.setEnabled(false);
                alterCase.setEnabled(false);
                break;
            }
        }
    });
    formLayout.addComponent(formatSelect);

    catalogSelect = new ComboBox("Catalog");
    catalogSelect.setImmediate(true);
    CommonUiUtils.addItems(getCatalogs(), catalogSelect);
    catalogSelect.select(databasePlatform.getDefaultCatalog());
    catalogSelect.setNullSelectionAllowed(false);
    formLayout.addComponent(catalogSelect);

    schemaSelect = new ComboBox("Schema");
    schemaSelect.setImmediate(true);
    CommonUiUtils.addItems(getSchemas(), schemaSelect);
    if (selectedTablesSet.iterator().hasNext()) {
        schemaSelect.select(selectedTablesSet.iterator().next().getSchema());
    } else {
        schemaSelect.select(databasePlatform.getDefaultSchema());
    }
    schemaSelect.setNullSelectionAllowed(false);
    schemaSelect.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            populateListOfTablesSelect();
        }
    });
    formLayout.addComponent(schemaSelect);

    listOfTablesSelect = new ComboBox("Tables");
    populateListOfTablesSelect();
    listOfTablesSelect.setEnabled(false);
    listOfTablesSelect.setNullSelectionAllowed(false);

    if (!this.selectedTablesSet.isEmpty()) {
        if (this.selectedTablesSet.size() == 1) {
            this.selectedTable = this.selectedTablesSet.iterator().next();
            listOfTablesSelect.select(this.selectedTable.getName());
            this.selectedTablesSet.clear();
        } else {
            List<Table> list = new ArrayList<Table>(this.selectedTablesSet);
            listOfTablesSelect.select(list.get(0).getName());
            this.selectedTable = list.get(0);
            this.selectedTablesSet.clear();
        }
    }
    formLayout.addComponent(listOfTablesSelect);

    commitField = new TextField("Rows to Commit");
    commitField.addTextChangeListener(new TextChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void textChange(TextChangeEvent event) {
            commitField.setValue(event.getText());
            if (fileSelected) {
                importButton.setEnabled(importButtonEnable());
            }
        }
    });
    commitField.setImmediate(true);
    commitField.setTextChangeEventMode(TextChangeEventMode.EAGER);
    commitField.setValue("10000");
    formLayout.addComponent(commitField);

    force = new CheckBox("Force");
    formLayout.addComponent(force);

    ignore = new CheckBox("Ignore");
    formLayout.addComponent(ignore);

    replace = new CheckBox("Replace");
    formLayout.addComponent(replace);

    alter = new CheckBox("Alter");
    alter.setEnabled(false);
    formLayout.addComponent(alter);

    alterCase = new CheckBox("Alter Case");
    alterCase.setEnabled(false);
    formLayout.addComponent(alterCase);

    upload = new Upload("File", new Receiver() {

        private static final long serialVersionUID = 1L;

        @Override
        public OutputStream receiveUpload(String filename, String mimeType) {
            try {
                file = File.createTempFile("dbimport", formatSelect.getValue().toString());
                out = new FileOutputStream(file);
                return new BufferedOutputStream(new FileOutputStream(file));
            } catch (Exception e) {
                log.warn(e.getMessage(), e);
                CommonUiUtils.notify("Failed to import " + filename, e);
            }
            return null;
        }
    });
    upload.addSucceededListener(new SucceededListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void uploadSucceeded(SucceededEvent event) {
            createDbImport();
            try {
                doDbImport();
            } catch (FileNotFoundException e) {
                log.warn(e.getMessage(), e);
                Notification.show(e.getMessage());
            }
            deleteFileAndResource();
            close();
        }
    });
    upload.addChangeListener(new ChangeListener() {

        private static final long serialVersionUID = 1L;

        public void filenameChanged(ChangeEvent event) {
            fileSelected = true;
            importButton.setEnabled(importButtonEnable());
        }
    });
    upload.setButtonCaption(null);
    formLayout.addComponent(upload);

    cancelButton = new Button("Cancel", new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            UI.getCurrent().removeWindow(DbImportDialog.this);
        }
    });

    importButton = CommonUiUtils.createPrimaryButton("Import", new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            upload.submitUpload();
        }
    });
    importButton.setEnabled(false);

    addComponent(importLayout, 1);
    addComponent(buildButtonFooter(cancelButton, importButton));
}

From source file:org.jumpmind.vaadin.ui.sqlexplorer.SettingsDialog.java

License:Open Source License

protected AbstractLayout createSettingsLayout() {
    VerticalLayout layout = new VerticalLayout();
    layout.setSizeFull();// www  . j  av  a  2s  .c o  m
    layout.setMargin(new MarginInfo(false, true, false, true));
    layout.addStyleName("v-scrollable");
    FormLayout settingsLayout = new FormLayout();

    Settings settings = settingsProvider.get();
    TypedProperties properties = settings.getProperties();

    rowsToFetchField = new TextField("Max Results");
    rowsToFetchField.setColumns(6);
    rowsToFetchField.setValidationVisible(true);
    rowsToFetchField.setConverter(Integer.class);
    rowsToFetchField.setValue(properties.getProperty(SQL_EXPLORER_MAX_RESULTS, "100"));
    settingsLayout.addComponent(rowsToFetchField);

    delimiterField = new TextField("Delimiter");
    delimiterField.setValue(properties.getProperty(SQL_EXPLORER_DELIMITER, ";"));
    settingsLayout.addComponent(delimiterField);

    excludeTablesWithPrefixField = new TextField("Hide Tables (regex)");
    excludeTablesWithPrefixField.setValue(properties.getProperty(SQL_EXPLORER_EXCLUDE_TABLES_REGEX));
    settingsLayout.addComponent(excludeTablesWithPrefixField);

    resultAsTextBox = new CheckBox("Result As Text");
    String resultAsTextValue = (properties.getProperty(SQL_EXPLORER_RESULT_AS_TEXT, "false"));
    if (resultAsTextValue.equals("true")) {
        resultAsTextBox.setValue(true);
    } else {
        resultAsTextBox.setValue(false);
    }
    settingsLayout.addComponent(resultAsTextBox);

    ignoreErrorsWhenRunningScript = new CheckBox("Ignore Errors When Running Scripts");
    String ignoreErrorsWhenRunningScriptTextValue = (properties
            .getProperty(SQL_EXPLORER_IGNORE_ERRORS_WHEN_RUNNING_SCRIPTS, "false"));
    if (ignoreErrorsWhenRunningScriptTextValue.equals("true")) {
        ignoreErrorsWhenRunningScript.setValue(true);
    } else {
        ignoreErrorsWhenRunningScript.setValue(false);
    }
    settingsLayout.addComponent(ignoreErrorsWhenRunningScript);

    autoCommitBox = new CheckBox("Auto Commit");
    String autoCommitValue = (properties.getProperty(SQL_EXPLORER_AUTO_COMMIT, "true"));
    if (autoCommitValue.equals("true")) {
        autoCommitBox.setValue(true);
    } else {
        autoCommitBox.setValue(false);
    }
    settingsLayout.addComponent(autoCommitBox);

    showRowNumbersBox = new CheckBox("Show Row Numbers");
    String showRowNumbersValue = (properties.getProperty(SQL_EXPLORER_SHOW_ROW_NUMBERS, "true"));
    if (showRowNumbersValue.equals("true")) {
        showRowNumbersBox.setValue(true);
    } else {
        showRowNumbersBox.setValue(false);
    }
    settingsLayout.addComponent(showRowNumbersBox);

    showResultsInNewTabsBox = new CheckBox("Always Put Results In New Tabs");
    String showResultsInNewTabsValue = (properties.getProperty(SQL_EXPLORER_SHOW_RESULTS_IN_NEW_TABS, "false"));
    if (showResultsInNewTabsValue.equals("true")) {
        showResultsInNewTabsBox.setValue(true);
    } else {
        showResultsInNewTabsBox.setValue(false);
    }
    settingsLayout.addComponent(showResultsInNewTabsBox);

    layout.addComponent(settingsLayout);
    return layout;

}

From source file:org.lucidj.newview.NewView.java

License:Apache License

private void fill_project_options(FormLayout form) {
    Label section = new Label("Project options");
    section.addStyleName("h4");
    section.addStyleName("colored");
    form.addComponent(section);

    DateField birthday = new DateField("Birthday");
    birthday.setValue(new Date());
    form.addComponent(birthday);/* www.  j  a  v  a2 s .co  m*/

    TextField username = new TextField("Username");
    username.setValue("curiosity");
    form.addComponent(username);

    OptionGroup sex = new OptionGroup("Sex");
    sex.addItem("Female");
    sex.addItem("Male");
    sex.select("Male");
    sex.addStyleName("horizontal");
    form.addComponent(sex);
    sex.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            test_debug_artifact_options = ((String) valueChangeEvent.getProperty().getValue()).equals("Female");
            fill_artifact_options();
        }
    });
}

From source file:org.lucidj.newview.NewView.java

License:Apache License

private boolean component_fill_artifact_options(FormLayout form) {
    if (test_debug_artifact_options) {
        TextField email = new TextField("Email");
        email.setValue("viking@surface.mars");
        email.setWidth("50%");
        email.setRequired(true);/*from   w ww . j a  v a 2  s .co  m*/
        form.addComponent(email);

        TextField location = new TextField("Location");
        location.setValue("Mars, Solar System");
        location.setWidth("50%");
        location.setComponentError(new UserError("This address doesn't exist"));
        form.addComponent(location);

        TextField phone = new TextField("Phone");
        phone.setWidth("50%");
        form.addComponent(phone);
    }
    return (test_debug_artifact_options);
}

From source file:org.milleni.dunning.ui.dpdetail.DunningProcessDetailSearchPanel.java

License:Apache License

protected void initInputField() {
    /*//  ww  w.  j a  va2  s .co m
            
    BeanFieldGroup<Customer>personBinder = new BeanFieldGroup<Customer>(PersonVo.class);
    personBinder.setItemDataSource(person);
    myFormLayout.addComponent(personBinder.buildAndBind("Firstname", "firstName"));
    myFormLayout.addComponent(personBinder.buildAndBind("Country", "country.name"));
            
    */

    formLayout = new FormLayout();

    //txtCustomerId = new TextField(i18nManager.getMessage(Constants.CUSTOMER_ID));
    //formLayout.addComponent(txtCustomerId);

    txtCustomerName = new TextField(i18nManager.getMessage(Constants.CUSTOMER_NAME));
    //formLayout.addComponent(txtCustomerName);

    formLayout.setWidth(100, UNITS_PERCENTAGE); // 99, otherwise the Panel will
    // display scrollbars
    //formLayout.setSpacing(true);
    //formLayout.setMargin(false, false, true, true);

    dpMaster = new DunningProcessMaster();
    dpDetail = new DunningProcessDetail();
    Form dpSearchForm = new Form();
    Form dpDetailSearchForm = new Form();

    dpSearchForm.setFormFieldFactory(new FormFieldFactory() {
        @SuppressWarnings("serial")
        @Override
        public Field createField(Item item, Object propertyId, Component uiContext) {
            Field field = DefaultFieldFactory.get().createField(item, propertyId, uiContext);
            if (field instanceof TextField) {
                ((TextField) field).setNullRepresentation("");
            }

            if ("dunningPolicyId".equals(propertyId)) {
                List<DunningPolicy> dunningPolicyList = new ArrayList<DunningPolicy>();
                Iterable<DunningPolicy> dunningPolicies = DaoHelper.getInstance().getDunningPolicyRepository()
                        .findAll();
                for (DunningPolicy dunningPolicy : dunningPolicies) {
                    dunningPolicyList.add(dunningPolicy);
                }
                BeanItemContainer<DunningPolicy> objects = new BeanItemContainer(DunningPolicy.class,
                        dunningPolicyList);

                policyCombo = new ComboBox(i18nManager.getMessage(Constants.DUNNING_POLICY_TYPE), objects);
                policyCombo.addListener(new ValueChangeListener() {

                    @Override
                    public void valueChange(ValueChangeEvent event) {
                        DunningPolicy selectedDunningPolicy = (DunningPolicy) event.getProperty().getValue();
                        List<ProcessSteps> processSteps = DaoHelper.getInstance().getDunningPolicyRepository()
                                .retrieveDunningProcessSteps(selectedDunningPolicy.getPolicyId());
                        BeanItemContainer<ProcessSteps> objects = new BeanItemContainer(ProcessSteps.class,
                                processSteps);
                        stepCombo.setContainerDataSource(objects);
                    }

                });
                policyCombo.setItemCaptionPropertyId("policyName");
                return policyCombo;
            } else if ("processLastStepId".equals(propertyId)) {
                stepCombo = new ComboBox(i18nManager.getMessage(Constants.DUNNING_POLICY_STEP));
                stepCombo.setItemCaptionPropertyId("stepText");
                return stepCombo;
            } else if ("status".equals(propertyId)) {
                statusCombo = new ComboBox(i18nManager.getMessage(Constants.DUNNING_PROCESS_STATUS));
                statusCombo.setItemCaptionPropertyId("statusText");
                List<DunningProcessMasterStatus> statusList = DaoHelper.getInstance()
                        .getDunningPolicyRepository().retrieveAllDunningProcessMasterStatus();
                BeanItemContainer<DunningProcessMasterStatus> objects = new BeanItemContainer(
                        DunningProcessMasterStatus.class, statusList);
                statusCombo.setContainerDataSource(objects);
                /*
                statusCombo.addItem(Constants.SUCCESS);
                statusCombo.setItemCaption(Constants.SUCCESS, "Baarl");
                statusCombo.addItem(Constants.WARNING);
                statusCombo.setItemCaption(Constants.WARNING, "Uyar");
                statusCombo.addItem(Constants.ERROR);
                statusCombo.setItemCaption(Constants.ERROR, "Hatal");
                statusCombo.addItem(Constants.INITIAL);
                statusCombo.setItemCaption(Constants.INITIAL, "Balang");
                */
                return statusCombo;
            } else if ("createDate".equals(propertyId)) {
                processStartDate = new DateField("Process Balama Zaman");
                return processStartDate;
            } else if ("customerId".equals(propertyId)) {
                txtCustomerId = (TextField) field;
                txtCustomerId.setCaption(i18nManager.getMessage(Constants.CUSTOMER_ID));
                txtCustomerId.setPropertyDataSource(new PropertyFormatter() {

                    @Override
                    public Object parse(String formattedValue) throws Exception {
                        if (StringUtils.hasText(formattedValue))
                            try {
                                return new Customer(Long.parseLong(formattedValue));
                            } catch (Exception e) {
                                return null;
                            }

                        else
                            return null;
                    }

                    @Override
                    public String format(Object value) {
                        if (value instanceof Customer)
                            return String.valueOf(((Customer) value).getCustomerId());
                        return String.valueOf(value);
                    }
                });
                return txtCustomerId;
            }

            return field;
        }

    });

    dpDetailSearchForm.setFormFieldFactory(new FormFieldFactory() {
        @SuppressWarnings("serial")
        @Override
        public Field createField(Item item, Object propertyId, Component uiContext) {
            Field field = DefaultFieldFactory.get().createField(item, propertyId, uiContext);
            if (field instanceof TextField) {
                ((TextField) field).setNullRepresentation("");
            }

            if ("processStepId".equals(propertyId)) {
                stepCombo = new ComboBox(i18nManager.getMessage(Constants.DUNNING_POLICY_LAST_STEP));
                stepCombo.setItemCaptionPropertyId("stepText");
                return stepCombo;
            } else if ("status".equals(propertyId)) {
                statusCombo = new ComboBox(i18nManager.getMessage(Constants.DUNNING_PROCESS_STEP_STATUS));
                statusCombo.setItemCaptionPropertyId("statusText");
                List<DunningProcessDetailStatus> statusList = DaoHelper.getInstance()
                        .getDunningPolicyRepository().retrieveAllDunningProcessDetailStatus();
                BeanItemContainer<DunningProcessDetailStatus> objects = new BeanItemContainer(
                        DunningProcessDetailStatus.class, statusList);
                statusCombo.setContainerDataSource(objects);
                return statusCombo;
            } else if ("createDate".equals(propertyId)) {
                stepCreateDate = new DateField(i18nManager.getMessage(Constants.DUNNING_PROCESS_STEP_START));
                return stepCreateDate;
            } else if ("statusDate".equals(propertyId)) {
                statusChangeDate = new DateField(i18nManager.getMessage(Constants.DUNNING_PROCESS_STEP_STOP));
                return statusChangeDate;
            }

            return field;
        }

    });

    BeanItem<DunningProcessMaster> item = new BeanItem<DunningProcessMaster>(dpMaster,
            new String[] { "dunningPolicyId", "processLastStepId", "createDate", "status" });
    BeanItem<DunningProcessDetail> items = new BeanItem<DunningProcessDetail>(dpDetail,
            new String[] { "status" });

    dpSearchForm.setItemDataSource(item);
    dpDetailSearchForm.setItemDataSource(items);

    stepCreateDateEnd = new DateField(i18nManager.getMessage(Constants.DUNNING_PROCESS_STEP_START_END));
    stepCreateDate = new DateField(i18nManager.getMessage(Constants.DUNNING_PROCESS_STEP_START));

    statusChangeDate = new DateField(i18nManager.getMessage(Constants.DUNNING_PROCESS_STEP_STOP));
    statusChangeDateEnd = new DateField(i18nManager.getMessage(Constants.DUNNING_PROCESS_STEP_STOP_END));

    formLayout.addComponent(dpSearchForm);
    formLayout.addComponent(dpDetailSearchForm);

    FormLayout layout = (FormLayout) dpSearchForm.getLayout();
    layout.addComponent(stepCreateDate);
    layout.addComponent(stepCreateDateEnd);
    layout.addComponent(statusChangeDate);
    layout.addComponent(statusChangeDateEnd);

    setContent(formLayout);

}

From source file:org.milleni.dunning.ui.dpmaster.DunningProcessSearchPanel.java

License:Apache License

protected void initInputField() {
    /*//from   w w  w  .j ava  2s  . com
            
    BeanFieldGroup<Customer>personBinder = new BeanFieldGroup<Customer>(PersonVo.class);
    personBinder.setItemDataSource(person);
    myFormLayout.addComponent(personBinder.buildAndBind("Firstname", "firstName"));
    myFormLayout.addComponent(personBinder.buildAndBind("Country", "country.name"));
            
    */

    formLayout = new FormLayout();

    //txtCustomerId = new TextField(i18nManager.getMessage(Constants.CUSTOMER_ID));
    //formLayout.addComponent(txtCustomerId);

    txtCustomerName = new TextField(i18nManager.getMessage(Constants.CUSTOMER_NAME));
    //formLayout.addComponent(txtCustomerName);

    formLayout.setWidth(100, UNITS_PERCENTAGE); // 99, otherwise the Panel will
    // display scrollbars
    //formLayout.setSpacing(true);
    //formLayout.setMargin(false, false, true, true);

    dpMaster = new DunningProcessMaster();

    Form dpSearchForm = new Form();

    dpSearchForm.setFormFieldFactory(new FormFieldFactory() {
        @SuppressWarnings("serial")
        @Override
        public Field createField(Item item, Object propertyId, Component uiContext) {
            Field field = DefaultFieldFactory.get().createField(item, propertyId, uiContext);
            if (field instanceof TextField) {
                ((TextField) field).setNullRepresentation("");
            }

            if ("dunningPolicyId".equals(propertyId)) {
                List<DunningPolicy> dunningPolicyList = new ArrayList<DunningPolicy>();
                Iterable<DunningPolicy> dunningPolicies = DaoHelper.getInstance().getDunningPolicyRepository()
                        .findAll();
                for (DunningPolicy dunningPolicy : dunningPolicies) {
                    dunningPolicyList.add(dunningPolicy);
                }
                BeanItemContainer<DunningPolicy> objects = new BeanItemContainer(DunningPolicy.class,
                        dunningPolicyList);

                policyCombo = new ComboBox(i18nManager.getMessage(Constants.DUNNING_POLICY_TYPE), objects);
                policyCombo.addListener(new ValueChangeListener() {

                    @Override
                    public void valueChange(ValueChangeEvent event) {
                        DunningPolicy selectedDunningPolicy = (DunningPolicy) event.getProperty().getValue();
                        List<ProcessSteps> processSteps = DaoHelper.getInstance().getDunningPolicyRepository()
                                .retrieveDunningProcessSteps(selectedDunningPolicy.getPolicyId());
                        BeanItemContainer<ProcessSteps> objects = new BeanItemContainer(ProcessSteps.class,
                                processSteps);
                        stepCombo.setContainerDataSource(objects);
                        nextStepCombo.setContainerDataSource(objects);
                        currentStepCombo.setContainerDataSource(objects);
                    }

                });
                policyCombo.setItemCaptionPropertyId("policyName");
                return policyCombo;
            } else if ("currentStepId".equals(propertyId)) {
                currentStepCombo = new ComboBox(i18nManager.getMessage(Constants.DUNNING_POLICY_CURRENT_STEP));
                currentStepCombo.setItemCaptionPropertyId("stepText");
                return currentStepCombo;
            } else if ("processLastStepId".equals(propertyId)) {
                stepCombo = new ComboBox(i18nManager.getMessage(Constants.DUNNING_POLICY_LAST_STEP));
                stepCombo.setItemCaptionPropertyId("stepText");
                return stepCombo;
            } else if ("nextStepId".equals(propertyId)) {
                nextStepCombo = new ComboBox(i18nManager.getMessage(Constants.DUNNING_NEXT_STEP));
                nextStepCombo.setItemCaptionPropertyId("stepText");
                return nextStepCombo;
            } else if ("status".equals(propertyId)) {
                statusCombo = new ComboBox(i18nManager.getMessage(Constants.DUNNING_PROCESS_STATUS));
                statusCombo.setItemCaptionPropertyId("statusText");
                List<DunningProcessMasterStatus> statusList = DaoHelper.getInstance()
                        .getDunningPolicyRepository().retrieveAllDunningProcessMasterStatus();
                BeanItemContainer<DunningProcessMasterStatus> objects = new BeanItemContainer(
                        DunningProcessMasterStatus.class, statusList);
                statusCombo.setContainerDataSource(objects);
                return statusCombo;
            } else if ("customerId".equals(propertyId)) {
                txtCustomerId = (TextField) field;
                txtCustomerId.setCaption(i18nManager.getMessage(Constants.CUSTOMER_ID));
                txtCustomerId.setPropertyDataSource(new PropertyFormatter() {

                    @Override
                    public Object parse(String formattedValue) throws Exception {
                        if (StringUtils.hasText(formattedValue))
                            try {
                                return new Customer(Long.parseLong(formattedValue));
                            } catch (Exception e) {
                                return null;
                            }

                        else
                            return null;
                    }

                    @Override
                    public String format(Object value) {
                        if (value instanceof Customer)
                            return String.valueOf(((Customer) value).getCustomerId());
                        return String.valueOf(value);
                    }
                });
                return txtCustomerId;
            }

            return field;
        }

    });

    BeanItem<DunningProcessMaster> item = new BeanItem<DunningProcessMaster>(dpMaster, new String[] {
            "dunningPolicyId", "currentStepId", "processLastStepId", "nextStepId", "customerId", "status" });
    dpSearchForm.setItemDataSource(item);

    nextStepDateStart = new DateField(i18nManager.getMessage(Constants.DUNNING_NEXT_STEP_DATE_START));
    nextStepDateStart.setDateFormat("dd.MM.yyyy");

    nextStepDateEnd = new DateField(i18nManager.getMessage(Constants.DUNNING_NEXT_STEP_DATE_END));
    nextStepDateEnd.setDateFormat("dd.MM.yyyy");

    processStartDate = new DateField(i18nManager.getMessage(Constants.DUNNING_PROCESS_DATE_START));
    processStartDate.setDateFormat("dd.MM.yyyy");

    processStartEnd = new DateField(i18nManager.getMessage(Constants.DUNNING_PROCESS_DATE_END));
    processStartEnd.setDateFormat("dd.MM.yyyy");

    processStatusDateStart = new DateField(i18nManager.getMessage(Constants.DUNNING_PROCESS_STATUS_DATE_START));
    processStatusDateStart.setDateFormat("dd.MM.yyyy");

    processStatusDateEnd = new DateField(i18nManager.getMessage(Constants.DUNNING_PROCESS_STATUS_DATE_END));
    processStatusDateEnd.setDateFormat("dd.MM.yyyy");

    invoiceDateStart = new DateField(i18nManager.getMessage(Constants.DUNNING_INVOICE_DATE_START));
    invoiceDateStart.setDateFormat("dd.MM.yyyy");

    invoiceDateEnd = new DateField(i18nManager.getMessage(Constants.DUNNING_INVOICE_DATE_END));
    invoiceDateEnd.setDateFormat("dd.MM.yyyy");

    //dpSearchForm.addField(processStartFinishDate, processStartFinishDate);

    FormLayout layout = (FormLayout) dpSearchForm.getLayout();
    layout.addComponent(nextStepDateStart);
    layout.addComponent(nextStepDateEnd);
    layout.addComponent(processStartDate);
    layout.addComponent(processStartEnd);
    layout.addComponent(processStatusDateStart);
    layout.addComponent(processStatusDateEnd);
    layout.addComponent(invoiceDateStart);
    layout.addComponent(invoiceDateEnd);

    formLayout.addComponent(dpSearchForm);
    setContent(formLayout);
}

From source file:org.opencms.ui.dialogs.CmsCopyMoveDialog.java

License:Open Source License

/**
 * Initializes the form fields.<p>
 *
 * @return the form component/*from   w  ww . j a  v  a2  s  . co  m*/
 */
private FormLayout initForm() {

    FormLayout form = new FormLayout();
    form.setWidth("100%");
    m_targetPath = new CmsPathSelectField();
    m_targetPath.setCaption(
            CmsVaadinUtils.getMessageText(org.opencms.workplace.commons.Messages.GUI_COPY_MOVE_TARGET_0));
    m_targetPath.setFileSelectCaption(
            CmsVaadinUtils.getMessageText(Messages.GUI_COPY_MOVE_SELECT_TARGET_CAPTION_0));
    m_targetPath.setResourceFilter(CmsResourceFilter.ONLY_VISIBLE_NO_DELETED.addRequireFolder());
    m_targetPath.setWidth("100%");
    form.addComponent(m_targetPath);

    if (m_dialogMode != DialogMode.move) {
        m_actionCombo = new ComboBox();
        m_actionCombo
                .setCaption(CmsVaadinUtils.getMessageText(org.opencms.ui.Messages.GUI_COPYPAGE_COPY_MODE_0));
        m_actionCombo.setNullSelectionAllowed(false);
        m_actionCombo.setNewItemsAllowed(false);
        m_actionCombo.setWidth("100%");
        //            m_actionCombo.addItem(Action.automatic);
        //            m_actionCombo.setItemCaption(
        //                Action.automatic,
        //                CmsVaadinUtils.getMessageText(Messages.GUI_COPY_MOVE_AUTOMATIC_0));
        //            m_actionCombo.setValue(Action.automatic);
        if (m_context.getResources().size() == 1) {
            if (m_context.getResources().get(0).isFile()) {
                m_actionCombo.addItem(Action.copy_all);
                m_actionCombo.setItemCaption(Action.copy_all, CmsVaadinUtils
                        .getMessageText(org.opencms.workplace.commons.Messages.GUI_COPY_AS_NEW_0));
                m_actionCombo.addItem(Action.copy_sibling_all);
                m_actionCombo.setItemCaption(Action.copy_sibling_all, CmsVaadinUtils
                        .getMessageText(org.opencms.workplace.commons.Messages.GUI_CREATE_SIBLING_0));
                if (m_dialogMode == DialogMode.copy_and_move) {
                    m_actionCombo.addItem(Action.move);
                    m_actionCombo.setItemCaption(Action.move, CmsVaadinUtils
                            .getMessageText(org.opencms.workplace.commons.Messages.GUI_COPY_MOVE_MOVE_FILE_0));
                }
            } else {
                CmsResource folder = m_context.getResources().get(0);
                m_hasContainerPageDefaultFile = hasContainerPageDefaultFile(folder);
                if (m_hasContainerPageDefaultFile) {
                    m_actionCombo.addItem(Action.container_page_automatic);
                    m_actionCombo.setItemCaption(Action.container_page_automatic,
                            CmsVaadinUtils.getMessageText(Messages.GUI_COPY_MOVE_AUTOMATIC_0));
                    m_actionCombo.addItem(Action.container_page_copy);
                    m_actionCombo.setItemCaption(Action.container_page_copy,
                            CmsVaadinUtils.getMessageText(Messages.GUI_COPY_MOVE_CONTAINERPAGE_COPY_0));
                    m_actionCombo.addItem(Action.container_page_reuse);
                    m_actionCombo.setItemCaption(Action.container_page_reuse,
                            CmsVaadinUtils.getMessageText(Messages.GUI_COPY_MOVE_CONTAINERPAGE_REUSE_0));
                }
                if (CmsResourceTypeFolderSubSitemap.isSubSitemap(folder)) {
                    m_actionCombo.addItem(Action.sub_sitemap);
                    m_actionCombo.setItemCaption(Action.sub_sitemap,
                            CmsVaadinUtils.getMessageText(Messages.GUI_COPY_MOVE_SUBSITEMAP_0));
                }
                m_actionCombo.addItem(Action.copy_sibling_mixed);
                m_actionCombo.setItemCaption(Action.copy_sibling_mixed, CmsVaadinUtils
                        .getMessageText(org.opencms.workplace.commons.Messages.GUI_COPY_ALL_NO_SIBLINGS_0));
                m_actionCombo.addItem(Action.copy_all);
                m_actionCombo.setItemCaption(Action.copy_all,
                        CmsVaadinUtils.getMessageText(org.opencms.workplace.commons.Messages.GUI_COPY_ALL_0));
                m_actionCombo.addItem(Action.copy_sibling_all);
                m_actionCombo.setItemCaption(Action.copy_sibling_all, CmsVaadinUtils.getMessageText(
                        org.opencms.workplace.commons.Messages.GUI_COPY_MULTI_CREATE_SIBLINGS_0));
                if (m_dialogMode == DialogMode.copy_and_move) {
                    m_actionCombo.addItem(Action.move);
                    m_actionCombo.setItemCaption(Action.move, CmsVaadinUtils.getMessageText(
                            org.opencms.workplace.commons.Messages.GUI_COPY_MOVE_MOVE_FOLDER_0));
                }
            }
        } else {
            m_actionCombo.addItem(Action.copy_sibling_mixed);
            m_actionCombo.setItemCaption(Action.copy_sibling_mixed, CmsVaadinUtils
                    .getMessageText(org.opencms.workplace.commons.Messages.GUI_COPY_ALL_NO_SIBLINGS_0));
            m_actionCombo.addItem(Action.copy_all);
            m_actionCombo.setItemCaption(Action.copy_all,
                    CmsVaadinUtils.getMessageText(org.opencms.workplace.commons.Messages.GUI_COPY_ALL_0));
            m_actionCombo.addItem(Action.copy_sibling_all);
            m_actionCombo.setItemCaption(Action.copy_sibling_all, CmsVaadinUtils
                    .getMessageText(org.opencms.workplace.commons.Messages.GUI_COPY_MULTI_CREATE_SIBLINGS_0));
            if (m_dialogMode == DialogMode.copy_and_move) {
                m_actionCombo.addItem(Action.move);
                m_actionCombo.setItemCaption(Action.move, CmsVaadinUtils
                        .getMessageText(org.opencms.workplace.commons.Messages.GUI_COPY_MOVE_MOVE_RESOURCES_0));
            }
        }
        m_actionCombo.setItemStyleGenerator(new ItemStyleGenerator() {

            private static final long serialVersionUID = 1L;

            public String getStyle(ComboBox source, Object itemId) {

                String style = null;
                if (m_defaultActions.contains(itemId)) {
                    style = "bold";
                }
                return style;
            }
        });
        form.addComponent(m_actionCombo);
    }
    if (m_context.getResources().size() > 1) {
        m_overwriteExisting = new CheckBox(CmsVaadinUtils
                .getMessageText(org.opencms.workplace.commons.Messages.GUI_COPY_MULTI_OVERWRITE_0));
        m_overwriteExisting.setValue(Boolean.FALSE);
        form.addComponent(m_overwriteExisting);
    }

    return form;
}

From source file:org.opencms.ui.dialogs.CmsProjectSelectDialog.java

License:Open Source License

/**
 * Initializes the form component.<p>
 *
 * @return the form component/* w w  w . j  a  va  2s  .c  o  m*/
 */
private FormLayout initForm() {

    FormLayout form = new FormLayout();
    form.setWidth("100%");

    IndexedContainer sites = CmsVaadinUtils.getAvailableSitesContainer(m_context.getCms(), CAPTION_PROPERTY);
    m_siteComboBox = prepareComboBox(sites, org.opencms.workplace.Messages.GUI_LABEL_SITE_0);
    m_siteComboBox.select(m_context.getCms().getRequestContext().getSiteRoot());
    form.addComponent(m_siteComboBox);
    ValueChangeListener changeListener = new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {

            submit();
        }
    };
    m_siteComboBox.addValueChangeListener(changeListener);
    IndexedContainer projects = CmsVaadinUtils.getProjectsContainer(m_context.getCms(), CAPTION_PROPERTY);
    m_projectComboBox = prepareComboBox(projects, org.opencms.workplace.Messages.GUI_LABEL_PROJECT_0);
    CmsUUID currentProjectId = m_context.getCms().getRequestContext().getCurrentProject().getUuid();
    if (projects.containsId(currentProjectId)) {
        m_projectComboBox.select(currentProjectId);
    } else {
        try {
            CmsUUID ouProject = OpenCms.getOrgUnitManager().readOrganizationalUnit(m_context.getCms(),
                    m_context.getCms().getRequestContext().getOuFqn()).getProjectId();
            if (projects.containsId(ouProject)) {
                m_projectComboBox.select(ouProject);
            }
        } catch (CmsException e) {
            LOG.error("Error while reading current OU.", e);
        }
    }

    form.addComponent(m_projectComboBox);
    m_projectComboBox.addValueChangeListener(changeListener);
    return form;
}

From source file:org.opencms.ui.dialogs.CmsPublishScheduledDialog.java

License:Open Source License

/**
 * Initializes the form fields.<p>
 *
 * @return the form component/*w  w w  .j a v  a2s.c  om*/
 */
private FormLayout initForm() {

    FormLayout form = new FormLayout();
    form.setWidth("100%");
    m_dateField = new CmsDateField();
    m_dateField.setCaption(CmsVaadinUtils
            .getMessageText(org.opencms.workplace.commons.Messages.GUI_LABEL_DATE_PUBLISH_SCHEDULED_0));
    form.addComponent(m_dateField);
    m_includeSubResources = new CheckBox(CmsVaadinUtils
            .getMessageText(org.opencms.workplace.commons.Messages.GUI_PUBLISH_MULTI_SUBRESOURCES_0));
    if (hasFolders()) {
        form.addComponent(m_includeSubResources);
    }

    return form;
}