Example usage for com.vaadin.ui DateField DateField

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

Introduction

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

Prototype

public DateField(ValueChangeListener<LocalDate> valueChangeListener) 

Source Link

Document

Constructs a new DateField with a value change listener.

Usage

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);//w  ww  .  ja v a 2 s .  c  om

    DateField birthday = new DateField("Birthday");
    birthday.setValue(new Date());
    form.addComponent(birthday);

    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.milleni.dunning.ui.dpdetail.DunningProcessDetailSearchPanel.java

License:Apache License

protected void initInputField() {
    /*/*from w w w. j  a v  a2s .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();
    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  a v  a 2 s  . 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.milleni.dunning.ui.prcstart.BulkDunningProcessStartPanel.java

License:Apache License

protected void initSettingsProperties() {
    panelLayout = new VerticalLayout();
    panelLayout.setSpacing(true);//from   w w  w. java 2  s.  c  o  m
    detailLayout.setMargin(true, true, true, false);
    detailLayout.addComponent(panelLayout);

    processDate = new DateField("Sre Balama Zaman");
    panelLayout.addComponent(processDate);
    // Database type

    textArea = new TextArea("");
    textArea.setRequired(true);
    textArea.setEnabled(true);
    textArea.setRows(10);
    textArea.setColumns(50);
    check = new CheckBox("Gn gemi stepi yapma");
    panelLayout.addComponent(check);
    panelLayout.addComponent(textArea);

    Button claimButton = new Button("Balat");
    claimButton.setIcon(Images.EXECUTE);
    claimButton.addListener(new ClickListener() {
        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            String customerIds = (String) textArea.getValue();
            Date processDateValue = (Date) processDate.getValue();

            boolean startStepFirst = false;
            if ((Boolean) check.getValue()) {
                startStepFirst = true;
            }

            String[] customerIdArray = customerIds.split("\n");
            List<Long> customerIdList = new ArrayList<Long>();
            for (String strCustomerId : customerIdArray) {
                strCustomerId = strCustomerId.trim();
                if (StringUtils.hasText(strCustomerId)) {
                    customerIdList.add(Long.parseLong(strCustomerId));
                }
            }

            for (Long customerId : customerIdList) {
                Map<String, Object> variables = new HashMap<String, Object>();
                variables.put(Constants.customerId, customerId);
                if (loggedInUser != null)
                    variables.put(Constants.user, loggedInUser.getFullName());
                if (startStepFirst)
                    variables.put(Constants.firstStepNext, true);
                if (processDateValue != null)
                    variables.put(Constants.processStartDate, processDateValue);
                runtimeService.startProcessInstanceByKey(Constants.FL100_DunningProcessInitializer, variables);
            }
            textArea.setValue("");
        }
    });

    panelLayout.addComponent(claimButton);
}

From source file:org.milleni.dunning.ui.prcstart.DunningProcessTimingOperationsPanel.java

License:Apache License

protected void initPageTitle() {
    HorizontalLayout layout = createHorizontalLayout();
    addDetailComponent(layout);// w  ww .  j  ava2s.  com

    Embedded databaseImage = new Embedded(null, Images.DATABASE_50);
    layout.addComponent(databaseImage);

    Label groupName = new Label("Toplu Tarih Ve Adim Degistirme");
    groupName.setSizeUndefined();
    groupName.addStyleName(Reindeer.LABEL_H2);
    layout.addComponent(groupName);
    layout.setComponentAlignment(groupName, Alignment.MIDDLE_LEFT);
    layout.setExpandRatio(groupName, 1.0f);

    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.setItemCaptionPropertyId("policyName");

    stepCombo = new ComboBox(i18nManager.getMessage(Constants.DUNNING_NEXT_STEP));
    stepCombo.setItemCaptionPropertyId("stepText");

    nextStepCombo = new ComboBox(i18nManager.getMessage(Constants.DUNNING_NEXT_STEP));
    nextStepCombo.setItemCaptionPropertyId("stepText");

    nextStepDateStart = new DateField(i18nManager.getMessage(Constants.DUNNING_NEXT_STEP_DATE_START));
    executionDate = new DateField(i18nManager.getMessage(Constants.DUNNING_NEXT_STEP_DATE_START));
    nextStepDateEnd = new DateField(i18nManager.getMessage(Constants.DUNNING_NEXT_STEP_DATE_END));

    policyCombo.addListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            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);
        }

    });

    stepCombo.addListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            selectedProcessStep = (ProcessSteps) event.getProperty().getValue();
        }

    });

    nextStepCombo.addListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            nextSelectedProcessStep = (ProcessSteps) event.getProperty().getValue();
        }

    });

}

From source file:org.milleni.dunning.ui.prcstart.StepSelectStartDunningProcessPanel.java

License:Apache License

protected void initSettingsProperties() {
    panelLayout = new VerticalLayout();
    panelLayout.setSpacing(true);/*from ww  w .  j ava  2  s. c  o  m*/
    detailLayout.setMargin(true, true, true, false);
    detailLayout.addComponent(panelLayout);

    processDate = new DateField("Sre Balama Zaman");
    panelLayout.addComponent(processDate);
    // Database type

    textArea = new TextArea("");
    textArea.setRequired(true);
    textArea.setEnabled(true);
    textArea.setRows(10);
    textArea.setColumns(50);
    check = new CheckBox("Gn gemi stepi yapma");

    panelLayout.addComponent(policyCombo);
    panelLayout.addComponent(stepCombo);
    panelLayout.addComponent(textArea);

    Button claimButton = new Button("Balat");
    claimButton.setIcon(Images.EXECUTE);
    claimButton.addListener(new ClickListener() {
        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            if (selectedProcessStep == null)
                throw new RuntimeException("Adm bo olamaz");
            String customerIds = (String) textArea.getValue();
            Date processDateValue = (Date) processDate.getValue();

            String[] customerIdArray = customerIds.split("\n");
            List<Long> customerIdList = new ArrayList<Long>();
            for (String strCustomerId : customerIdArray) {
                strCustomerId = strCustomerId.trim();
                if (StringUtils.hasText(strCustomerId)) {
                    customerIdList.add(Long.parseLong(strCustomerId));
                }
            }

            for (Long customerId : customerIdList) {
                Map<String, Object> variables = new HashMap<String, Object>();
                variables.put(Constants.customerId, customerId);
                if (loggedInUser != null)
                    variables.put(Constants.user, loggedInUser.getFullName());
                if (processDateValue != null)
                    variables.put(Constants.processStartDate, processDateValue);

                if (selectedProcessStep != null) {
                    variables.put(Constants.userSelectedProcessStep, selectedProcessStep.getStepId());
                }
                runtimeService.startProcessInstanceByKey(Constants.FL100_DunningProcessInitializer, variables);
            }
            textArea.setValue("");
        }
    });

    panelLayout.addComponent(claimButton);

}

From source file:org.tltv.gantt.demo.DemoUI.java

License:Apache License

private void openStepEditor(AbstractStep step) {
    final Window win = new Window("Step Editor");
    win.setResizable(false);//w  ww  . jav a2s . co  m
    win.center();

    final Collection<Component> hidden = new ArrayList<Component>();

    BeanItem<AbstractStep> item = new BeanItem<AbstractStep>(step);

    final FieldGroup group = new FieldGroup(item);
    group.setBuffered(true);

    TextField captionField = new TextField("Caption");
    captionField.setNullRepresentation("");
    group.bind(captionField, "caption");

    TextField descriptionField = new TextField("Description");
    descriptionField.setNullRepresentation("");
    group.bind(descriptionField, "description");
    descriptionField.setVisible(false);
    hidden.add(descriptionField);

    NativeSelect captionMode = new NativeSelect("Caption Mode");
    captionMode.addItem(Step.CaptionMode.TEXT);
    captionMode.addItem(Step.CaptionMode.HTML);
    group.bind(captionMode, "captionMode");
    captionMode.setVisible(false);
    hidden.add(captionMode);

    CheckBox showProgress = new CheckBox("Show progress");
    group.bind(showProgress, "showProgress");
    showProgress.setVisible(false);
    hidden.add(showProgress);

    Slider progress = new Slider("Progress");
    progress.setWidth(100, Unit.PERCENTAGE);
    group.bind(progress, "progress");
    progress.setVisible(false);
    hidden.add(progress);

    NativeSelect predecessorSelect = new NativeSelect("Predecessor Step");
    predecessorSelect.setWidth(100, Unit.PERCENTAGE);
    fillPredecessorCanditatesToSelect(step, predecessorSelect);
    predecessorSelect.setEnabled(step instanceof Step);
    if (step instanceof Step) {
        group.bind(predecessorSelect, "predecessor");
    }
    predecessorSelect.setVisible(false);
    hidden.add(predecessorSelect);

    final NativeSelect parentStepSelect = new NativeSelect("Parent Step");
    parentStepSelect.setWidth(100, Unit.PERCENTAGE);
    parentStepSelect.setEnabled(false);
    fillParentStepCanditatesToSelect(step, parentStepSelect);
    parentStepSelect.setVisible(false);
    hidden.add(parentStepSelect);

    HorizontalLayout colorLayout = new HorizontalLayout();
    colorLayout.setWidth(100, Unit.PERCENTAGE);
    colorLayout.setVisible(false);
    hidden.add(colorLayout);

    final TextField bgField = new TextField("Background color");
    bgField.setNullRepresentation("");
    group.bind(bgField, "backgroundColor");
    bgField.setEnabled(false);

    final ColorPicker bgColorPicker = new ColorPicker();
    bgColorPicker.setPosition(300, 100);
    bgColorPicker.setColor(new CssColorToColorPickerConverter().convertToModel(step.getBackgroundColor()));
    bgColorPicker.addColorChangeListener(new ColorChangeListener() {
        @Override
        public void colorChanged(ColorChangeEvent event) {
            bgField.setValue(event.getColor().getCSS());
        }
    });

    colorLayout.addComponent(bgField);
    colorLayout.addComponent(bgColorPicker);
    colorLayout.setExpandRatio(bgField, 1);
    colorLayout.setComponentAlignment(bgColorPicker, Alignment.BOTTOM_LEFT);

    DateField startDate = new DateField("Start date");
    startDate.setLocale(gantt.getLocale());
    startDate.setTimeZone(gantt.getTimeZone());
    startDate.setResolution(Resolution.SECOND);
    startDate.setConverter(new DateToLongConverter());
    group.bind(startDate, "startDate");

    DateField endDate = new DateField("End date");
    endDate.setLocale(gantt.getLocale());
    endDate.setTimeZone(gantt.getTimeZone());
    endDate.setResolution(Resolution.SECOND);
    endDate.setConverter(new DateToLongConverter());
    group.bind(endDate, "endDate");

    CheckBox showMore = new CheckBox("Show all settings");
    showMore.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            for (Component c : hidden) {
                c.setVisible((Boolean) event.getProperty().getValue());
            }
            win.center();
        }
    });

    VerticalLayout content = new VerticalLayout();
    content.setMargin(true);
    content.setSpacing(true);
    win.setContent(content);

    content.addComponent(captionField);
    content.addComponent(captionMode);
    content.addComponent(descriptionField);
    content.addComponent(showProgress);
    content.addComponent(progress);
    content.addComponent(predecessorSelect);
    content.addComponent(parentStepSelect);
    content.addComponent(colorLayout);
    content.addComponent(startDate);
    content.addComponent(endDate);
    content.addComponent(showMore);

    HorizontalLayout buttons = new HorizontalLayout();
    content.addComponent(buttons);

    Button ok = new Button("Ok", new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            commit(win, group, parentStepSelect);
        }

    });
    Button cancel = new Button("Cancel", new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            cancel(win, group);
        }
    });
    Button delete = new Button("Delete", new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            delete(win, group);
        }

    });
    buttons.addComponent(ok);
    buttons.addComponent(cancel);
    buttons.addComponent(delete);
    win.setClosable(true);

    getUI().addWindow(win);
}

From source file:pl.exsio.ca.module.config.groups.AssignmentsDataTable.java

License:Open Source License

private DateField getDateField(EntityItem<? extends OverseerAssignment> item) {
    DateField date = new DateField(t("date"));
    date.setPropertyDataSource(item.getItemProperty("date"));
    date.setResolution(Resolution.DAY);//from  www  . j  a  va 2 s  . co m
    date.addValidator(new NullValidator(t("invalid_date"), false));
    date.setDateFormat("yyyy-MM-dd");
    return date;
}

From source file:pl.exsio.ca.module.config.preachers.AssignmentsDataTable.java

License:Open Source License

private DateField getDateField(EntityItem<? extends PreacherAssignment> item) {
    DateField date = new DateField(t("date"));
    date.setPropertyDataSource(item.getItemProperty("date"));
    date.setResolution(Resolution.DAY);/*from   w w  w  .  j  ava 2 s. c o m*/
    date.addValidator(new NullValidator(t("invalid_group"), false));
    date.setDateFormat("yyyy-MM-dd");
    return date;
}

From source file:pl.exsio.ca.module.config.preachers.PriviledgesDataTable.java

License:Open Source License

@Override
protected Layout decorateForm(Form form, EntityItem<? extends PreacherPriviledge> item, int mode) {

    VerticalLayout formLayout = new VerticalLayout();

    Field priviledge = ComponentFactory.createEnumComboBox(t("priviledge"), Priviledge.class);
    priviledge.setPropertyDataSource(item.getItemProperty("priviledge"));
    priviledge.addValidator(new NullValidator(t("not_null"), false));
    form.addField("priviledge", priviledge);

    DateField start = new DateField(t("start_date"));
    start.setPropertyDataSource(item.getItemProperty("startDate"));
    start.setResolution(Resolution.DAY);
    start.addValidator(new NullValidator(t("invalid_start_date"), false));
    start.setDateFormat(CalendarUtil.getDateFormat(this.getLocale()));
    form.addField("startDate", start);

    DateField end = new DateField(t("end_date"));
    end.setPropertyDataSource(item.getItemProperty("endDate"));
    end.setResolution(Resolution.DAY);//from w  w  w.ja  v a 2  s.  co m
    end.setDateFormat(CalendarUtil.getDateFormat(this.getLocale()));
    form.addField("endDate", end);

    form.setBuffered(true);
    form.setEnabled(true);

    formLayout.addComponent(form);
    return formLayout;
}