Example usage for com.vaadin.ui Button Button

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

Introduction

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

Prototype

public Button(Resource icon, ClickListener listener) 

Source Link

Document

Creates a new push button with a click listener.

Usage

From source file:com.esofthead.mycollab.module.project.view.bug.BugTableDisplay.java

License:Open Source License

public BugTableDisplay(String viewId, TableViewField requiredColumn, List<TableViewField> displayColumns) {
    super(ApplicationContextUtil.getSpringBean(BugService.class), SimpleBug.class, viewId, requiredColumn,
            displayColumns);/*www  .j av  a2  s . c o m*/

    this.addGeneratedColumn("id", new Table.ColumnGenerator() {
        private static final long serialVersionUID = 1L;

        @Override
        public Object generateCell(final Table source, final Object itemId, Object columnId) {
            final SimpleBug bug = BugTableDisplay.this.getBeanByIndex(itemId);
            final Button bugSettingBtn = new Button(null, FontAwesome.COG);
            bugSettingBtn.addStyleName(UIConstants.BUTTON_ICON_ONLY);

            final ContextMenu contextMenu = new ContextMenu();
            contextMenu.setAsContextMenuOf(bugSettingBtn);

            contextMenu.addItemClickListener(new ContextMenuItemClickListener() {

                @Override
                public void contextMenuItemClicked(ContextMenuItemClickEvent event) {
                    if (((ContextMenuItem) event.getSource()).getData() == null) {
                        return;
                    }

                    String category = ((MenuItemData) ((ContextMenuItem) event.getSource()).getData())
                            .getAction();
                    String value = ((MenuItemData) ((ContextMenuItem) event.getSource()).getData()).getKey();
                    if ("status".equals(category)) {
                        if (AppContext.getMessage(BugStatus.Verified).equals(value)) {
                            UI.getCurrent().addWindow(new ApproveInputWindow(BugTableDisplay.this, bug));
                        } else if (AppContext.getMessage(BugStatus.InProgress).equals(value)) {
                            bug.setStatus(BugStatus.InProgress.name());
                            BugService bugService = ApplicationContextUtil.getSpringBean(BugService.class);
                            bugService.updateWithSession(bug, AppContext.getUsername());
                        } else if (AppContext.getMessage(BugStatus.Open).equals(value)) {
                            UI.getCurrent().addWindow(new ReOpenWindow(BugTableDisplay.this, bug));
                        } else if (AppContext.getMessage(BugStatus.Resolved).equals(value)) {
                            UI.getCurrent().addWindow(new ResolvedInputWindow(BugTableDisplay.this, bug));
                        }
                    } else if ("severity".equals(category)) {
                        bug.setSeverity(value);
                        BugService bugService = ApplicationContextUtil.getSpringBean(BugService.class);
                        bugService.updateWithSession(bug, AppContext.getUsername());
                        refresh();
                    } else if ("priority".equals(category)) {
                        bug.setPriority(value);
                        BugService bugService = ApplicationContextUtil.getSpringBean(BugService.class);
                        bugService.updateWithSession(bug, AppContext.getUsername());
                        refresh();
                    } else if ("action".equals(category)) {
                        if ("edit".equals(value)) {
                            EventBusFactory.getInstance()
                                    .post(new BugEvent.GotoEdit(BugTableDisplay.this, bug));
                        } else if ("delete".equals(value)) {
                            ConfirmDialogExt.show(UI.getCurrent(),
                                    AppContext.getMessage(GenericI18Enum.DIALOG_DELETE_TITLE,
                                            SiteConfiguration.getSiteName()),
                                    AppContext.getMessage(GenericI18Enum.DIALOG_DELETE_SINGLE_ITEM_MESSAGE),
                                    AppContext.getMessage(GenericI18Enum.BUTTON_YES),
                                    AppContext.getMessage(GenericI18Enum.BUTTON_NO),
                                    new ConfirmDialog.Listener() {
                                        private static final long serialVersionUID = 1L;

                                        @Override
                                        public void onClose(ConfirmDialog dialog) {
                                            if (dialog.isConfirmed()) {
                                                BugService bugService = ApplicationContextUtil
                                                        .getSpringBean(BugService.class);
                                                bugService.removeWithSession(bug.getId(),
                                                        AppContext.getUsername(), AppContext.getAccountId());
                                                refresh();
                                            }
                                        }
                                    });

                        }
                    }

                }
            });

            bugSettingBtn.setEnabled(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.BUGS));

            bugSettingBtn.addClickListener(new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(ClickEvent event) {
                    displayContextMenuItem(contextMenu, bug, event.getClientX(), event.getClientY());
                }
            });
            return bugSettingBtn;
        }
    });

    this.addGeneratedColumn("assignuserFullName", new Table.ColumnGenerator() {
        private static final long serialVersionUID = 1L;

        @Override
        public com.vaadin.ui.Component generateCell(Table source, final Object itemId, Object columnId) {
            final SimpleBug bug = BugTableDisplay.this.getBeanByIndex(itemId);
            return new ProjectUserLink(bug.getAssignuser(), bug.getAssignUserAvatarId(),
                    bug.getAssignuserFullName());
        }
    });

    this.addGeneratedColumn("loguserFullName", new Table.ColumnGenerator() {
        private static final long serialVersionUID = 1L;

        @Override
        public com.vaadin.ui.Component generateCell(Table source, final Object itemId, Object columnId) {
            final SimpleBug bug = BugTableDisplay.this.getBeanByIndex(itemId);
            return new ProjectUserLink(bug.getLogby(), bug.getLoguserAvatarId(), bug.getLoguserFullName());
        }
    });

    this.addGeneratedColumn("summary", new Table.ColumnGenerator() {
        private static final long serialVersionUID = 1L;

        @Override
        public com.vaadin.ui.Component generateCell(Table source, final Object itemId, Object columnId) {

            final SimpleBug bug = BugTableDisplay.this.getBeanByIndex(itemId);

            String bugname = "[%s-%s] %s";
            bugname = String.format(bugname, CurrentProjectVariables.getProject().getShortname(),
                    bug.getBugkey(), bug.getSummary());
            LabelLink b = new LabelLink(bugname,
                    ProjectLinkBuilder.generateBugPreviewFullLink(bug.getBugkey(), bug.getProjectShortName()));

            if (StringUtils.isNotBlank(bug.getPriority())) {
                b.setIconLink(ProjectResources.getIconResourceLink12ByBugPriority(bug.getPriority()));
            }

            b.setDescription(ProjectTooltipGenerator.generateToolTipBug(AppContext.getUserLocale(), bug,
                    AppContext.getSiteUrl(), AppContext.getTimezone()));

            if (bug.isCompleted()) {
                b.addStyleName(UIConstants.LINK_COMPLETED);
            } else if (bug.isOverdue()) {
                b.addStyleName(UIConstants.LINK_OVERDUE);
            }
            return b;

        }
    });

    this.addGeneratedColumn("severity", new Table.ColumnGenerator() {
        private static final long serialVersionUID = 1L;

        @Override
        public com.vaadin.ui.Component generateCell(Table source, final Object itemId, Object columnId) {
            final SimpleBug bug = BugTableDisplay.this.getBeanByIndex(itemId);

            Resource iconPriority = new ExternalResource(
                    ProjectResources.getIconResourceLink12ByBugSeverity(bug.getPriority()));

            Embedded iconEmbedded = new Embedded(null, iconPriority);
            Label lbPriority = new Label(AppContext.getMessage(BugSeverity.class, bug.getSeverity()));
            HorizontalLayout containerField = new HorizontalLayout();
            containerField.setSpacing(true);
            containerField.addComponent(iconEmbedded);
            containerField.addComponent(lbPriority);
            containerField.setExpandRatio(lbPriority, 1.0f);
            return containerField;

        }
    });

    this.addGeneratedColumn("duedate", new Table.ColumnGenerator() {
        private static final long serialVersionUID = 1L;

        @Override
        public com.vaadin.ui.Component generateCell(Table source, final Object itemId, Object columnId) {
            final SimpleBug bug = BugTableDisplay.this.getBeanByIndex(itemId);
            return new Label(AppContext.formatDate(bug.getDuedate()));

        }
    });

    this.addGeneratedColumn("createdtime", new Table.ColumnGenerator() {
        private static final long serialVersionUID = 1L;

        @Override
        public com.vaadin.ui.Component generateCell(Table source, final Object itemId, Object columnId) {
            final SimpleBug bug = BugTableDisplay.this.getBeanByIndex(itemId);
            return new Label(AppContext.formatDateTime(bug.getCreatedtime()));

        }
    });

    this.addGeneratedColumn("resolution", new Table.ColumnGenerator() {
        private static final long serialVersionUID = 1L;

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            final SimpleBug bug = BugTableDisplay.this.getBeanByIndex(itemId);
            return new Label(AppContext.getMessage(BugResolution.class, bug.getResolution()));
        }
    });
    this.setWidth("100%");
}

From source file:com.esofthead.mycollab.module.project.view.bug.ComponentReadViewImpl.java

License:Open Source License

@Override
protected ComponentContainer createButtonControls() {
    ProjectPreviewFormControlsGenerator<SimpleComponent> componentPreviewForm = new ProjectPreviewFormControlsGenerator<>(
            previewForm);//from  w  ww.j a va  2 s .  c o  m
    final HorizontalLayout topPanel = componentPreviewForm
            .createButtonControls(ProjectRolePermissionCollections.COMPONENTS);
    quickActionStatusBtn = new Button("", new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            if (StatusI18nEnum.Closed.name().equals(beanItem.getStatus())) {
                beanItem.setStatus(StatusI18nEnum.Open.name());
                ComponentReadViewImpl.this.removeLayoutStyleName(UIConstants.LINK_COMPLETED);
                quickActionStatusBtn.setCaption(AppContext.getMessage(GenericI18Enum.BUTTON_CLOSE));
                quickActionStatusBtn.setIcon(FontAwesome.ARCHIVE);
            } else {
                beanItem.setStatus(StatusI18nEnum.Closed.name());

                ComponentReadViewImpl.this.addLayoutStyleName(UIConstants.LINK_COMPLETED);
                quickActionStatusBtn.setCaption(AppContext.getMessage(GenericI18Enum.BUTTON_REOPEN));
                quickActionStatusBtn.setIcon(FontAwesome.CLIPBOARD);
            }

            ComponentService service = ApplicationContextUtil.getSpringBean(ComponentService.class);
            service.updateSelectiveWithSession(beanItem, AppContext.getUsername());

        }
    });

    quickActionStatusBtn.setStyleName(UIConstants.THEME_GREEN_LINK);
    componentPreviewForm.insertToControlBlock(quickActionStatusBtn);

    if (!CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.COMPONENTS)) {
        quickActionStatusBtn.setEnabled(false);
    }
    return topPanel;
}

From source file:com.esofthead.mycollab.module.project.view.bug.components.BugRowComponent.java

License:Open Source License

private OptionPopupContent createPopupContent() {
    OptionPopupContent filterBtnLayout = new OptionPopupContent();

    Button editButton = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_EDIT),
            new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override/*from  w w w .  j a v  a2 s  .  co  m*/
                public void buttonClick(Button.ClickEvent event) {
                    bugSettingPopupBtn.setPopupVisible(false);
                    EventBusFactory.getInstance().post(new BugEvent.GotoEdit(BugRowComponent.this, bug));
                }
            });
    editButton.setEnabled(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.BUGS));
    editButton.setIcon(FontAwesome.EDIT);
    filterBtnLayout.addOption(editButton);
    Button deleteBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_DELETE),
            new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(Button.ClickEvent event) {
                    bugSettingPopupBtn.setPopupVisible(false);
                    ConfirmDialogExt.show(UI.getCurrent(),
                            AppContext.getMessage(GenericI18Enum.DIALOG_DELETE_TITLE, AppContext.getSiteName()),
                            AppContext.getMessage(GenericI18Enum.DIALOG_DELETE_SINGLE_ITEM_MESSAGE),
                            AppContext.getMessage(GenericI18Enum.BUTTON_YES),
                            AppContext.getMessage(GenericI18Enum.BUTTON_NO), new ConfirmDialog.Listener() {
                                private static final long serialVersionUID = 1L;

                                @Override
                                public void onClose(ConfirmDialog dialog) {
                                    if (dialog.isConfirmed()) {
                                        BugService bugService = AppContextUtil.getSpringBean(BugService.class);
                                        bugService.removeWithSession(bug, AppContext.getUsername(),
                                                AppContext.getAccountId());
                                        deleteBug();
                                    }
                                }
                            });
                }
            });
    deleteBtn.setIcon(FontAwesome.TRASH_O);
    deleteBtn.setEnabled(CurrentProjectVariables.canAccess(ProjectRolePermissionCollections.TASKS));
    filterBtnLayout.addDangerOption(deleteBtn);
    return filterBtnLayout;
}

From source file:com.esofthead.mycollab.module.project.view.bug.components.ToggleBugSummaryField.java

License:Open Source License

public ToggleBugSummaryField(final BugWithBLOBs bug, int trimCharacters) {
    this.bug = bug;
    this.maxLength = trimCharacters;
    titleLinkLbl = new Label(buildBugLink(), ContentMode.HTML);
    titleLinkLbl.addStyleName(UIConstants.LABEL_WORD_WRAP);
    titleLinkLbl.setWidthUndefined();/*  w w w. ja  v  a  2 s . co m*/
    this.addComponent(titleLinkLbl);
    buttonControls = new MHorizontalLayout().withStyleName("toggle").withSpacing(false);
    if (CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.BUGS)) {
        this.addStyleName("editable-field");
        Button instantEditBtn = new Button(null, new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent clickEvent) {
                if (isRead) {
                    ToggleBugSummaryField.this.removeComponent(titleLinkLbl);
                    ToggleBugSummaryField.this.removeComponent(buttonControls);
                    final TextField editField = new TextField();
                    editField.setValue(bug.getSummary());
                    editField.setWidth("100%");
                    editField.focus();
                    ToggleBugSummaryField.this.addComponent(editField);
                    ToggleBugSummaryField.this.removeStyleName("editable-field");
                    editField.addValueChangeListener(new Property.ValueChangeListener() {
                        @Override
                        public void valueChange(Property.ValueChangeEvent event) {
                            updateFieldValue(editField);
                        }
                    });
                    editField.addBlurListener(new FieldEvents.BlurListener() {
                        @Override
                        public void blur(FieldEvents.BlurEvent event) {
                            updateFieldValue(editField);
                        }
                    });
                    isRead = !isRead;
                }
            }
        });
        instantEditBtn.setDescription("Edit task name");
        instantEditBtn.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
        instantEditBtn.addStyleName(ValoTheme.BUTTON_ICON_ALIGN_TOP);
        instantEditBtn.setIcon(FontAwesome.EDIT);
        buttonControls.with(instantEditBtn);
        this.addComponent(buttonControls);
    }
}

From source file:com.esofthead.mycollab.module.project.view.bug.components.ToggleBugSummaryWithDependentField.java

License:Open Source License

public ToggleBugSummaryWithDependentField(final BugWithBLOBs hostBug, final BugWithBLOBs relatedBug) {
    toggleBugSummaryField = new ToggleBugSummaryField(relatedBug);
    Button unlinkBtn = new Button(null, new Button.ClickListener() {
        @Override/*from w ww  .j  av  a2s  .com*/
        public void buttonClick(Button.ClickEvent clickEvent) {
            ConfirmDialogExt.show(UI.getCurrent(),
                    AppContext.getMessage(GenericI18Enum.DIALOG_DELETE_TITLE, AppContext.getSiteName()),
                    AppContext.getMessage(GenericI18Enum.DIALOG_DELETE_SINGLE_ITEM_MESSAGE),
                    AppContext.getMessage(GenericI18Enum.BUTTON_YES),
                    AppContext.getMessage(GenericI18Enum.BUTTON_NO), new ConfirmDialog.Listener() {
                        @Override
                        public void onClose(ConfirmDialog confirmDialog) {
                            RelatedBugExample ex = new RelatedBugExample();
                            ex.createCriteria().andBugidEqualTo(hostBug.getId())
                                    .andRelatedidEqualTo(relatedBug.getId());
                            RelatedBugMapper bugMapper = AppContextUtil.getSpringBean(RelatedBugMapper.class);
                            bugMapper.deleteByExample(ex);
                            UIUtils.removeChildAssociate(toggleBugSummaryField,
                                    RemoveInlineComponentMarker.class);
                        }
                    });
        }
    });
    unlinkBtn.setIcon(FontAwesome.UNLINK);
    unlinkBtn.setDescription("Remove relationship");
    unlinkBtn.addStyleName(ValoTheme.BUTTON_ICON_ALIGN_TOP);
    unlinkBtn.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    toggleBugSummaryField.addControl(unlinkBtn);
}

From source file:com.esofthead.mycollab.module.project.view.bug.ComponentSearchPanel.java

License:Open Source License

private HorizontalLayout createSearchTopPanel() {
    final MHorizontalLayout layout = new MHorizontalLayout().withWidth("100%").withSpacing(true)
            .withStyleName(UIConstants.HEADER_VIEW).withMargin(new MarginInfo(true, false, true, false));

    final Label componenttitle = new ProjectViewHeader(ProjectTypeConstants.BUG_COMPONENT,
            AppContext.getMessage(ComponentI18nEnum.VIEW_LIST_TITLE));
    componenttitle.setStyleName(UIConstants.HEADER_TEXT);

    layout.with(componenttitle).withAlign(componenttitle, Alignment.MIDDLE_LEFT).expand(componenttitle);

    final Button createBtn = new Button(AppContext.getMessage(BugI18nEnum.BUTTON_NEW_COMPONENT),
            new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override//from w ww  .java  2s . co m
                public void buttonClick(final Button.ClickEvent event) {
                    EventBusFactory.getInstance().post(new BugComponentEvent.GotoAdd(this, null));
                }
            });
    createBtn.setEnabled(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.COMPONENTS));
    createBtn.setStyleName(UIConstants.THEME_GREEN_LINK);
    createBtn.setIcon(FontAwesome.PLUS);

    layout.with(createBtn).withAlign(createBtn, Alignment.MIDDLE_RIGHT);

    return layout;
}

From source file:com.esofthead.mycollab.module.project.view.bug.VersionReadViewImpl.java

License:Open Source License

@Override
protected ComponentContainer createButtonControls() {
    ProjectPreviewFormControlsGenerator<Version> versionPreviewForm = new ProjectPreviewFormControlsGenerator<>(
            previewForm);// w w w  . ja  va2s  .  c  o  m
    final HorizontalLayout topPanel = versionPreviewForm
            .createButtonControls(ProjectRolePermissionCollections.VERSIONS);

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

        @Override
        public void buttonClick(ClickEvent event) {
            if (StatusI18nEnum.Closed.name().equals(beanItem.getStatus())) {
                beanItem.setStatus(StatusI18nEnum.Open.name());
                VersionReadViewImpl.this.removeLayoutStyleName(UIConstants.LINK_COMPLETED);
                quickActionStatusBtn.setCaption(AppContext.getMessage(GenericI18Enum.BUTTON_CLOSE));
                quickActionStatusBtn.setIcon(FontAwesome.ARCHIVE);
            } else {
                beanItem.setStatus(StatusI18nEnum.Closed.name());

                VersionReadViewImpl.this.addLayoutStyleName(UIConstants.LINK_COMPLETED);
                quickActionStatusBtn.setCaption(AppContext.getMessage(GenericI18Enum.BUTTON_REOPEN));
                quickActionStatusBtn.setIcon(FontAwesome.CLIPBOARD);
            }

            VersionService service = ApplicationContextUtil.getSpringBean(VersionService.class);
            service.updateSelectiveWithSession(beanItem, AppContext.getUsername());

        }
    });

    quickActionStatusBtn.setStyleName(UIConstants.THEME_GREEN_LINK);
    versionPreviewForm.insertToControlBlock(quickActionStatusBtn);

    if (!CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.VERSIONS)) {
        quickActionStatusBtn.setEnabled(false);
    }

    return topPanel;
}

From source file:com.esofthead.mycollab.module.project.view.bug.VersionSearchPanel.java

License:Open Source License

private HorizontalLayout createSearchTopPanel() {
    final MHorizontalLayout layout = new MHorizontalLayout().withStyleName(UIConstants.HEADER_VIEW)
            .withWidth("100%").withSpacing(true).withMargin(new MarginInfo(true, false, true, false));

    final Label versionTitle = new ProjectViewHeader(ProjectTypeConstants.BUG_VERSION,
            AppContext.getMessage(VersionI18nEnum.VIEW_LIST_TITLE));
    versionTitle.setStyleName(UIConstants.HEADER_TEXT);
    layout.with(versionTitle).withAlign(versionTitle, Alignment.MIDDLE_LEFT).expand(versionTitle);

    final Button createBtn = new Button(AppContext.getMessage(BugI18nEnum.BUTTON_NEW_VERSION),
            new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override/*  ww w  .  jav  a 2  s.  co  m*/
                public void buttonClick(final Button.ClickEvent event) {
                    EventBusFactory.getInstance().post(new BugVersionEvent.GotoAdd(this, null));
                }
            });
    createBtn.setEnabled(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.VERSIONS));
    createBtn.setStyleName(UIConstants.THEME_GREEN_LINK);
    createBtn.setIcon(FontAwesome.PLUS);

    layout.with(createBtn).withAlign(createBtn, Alignment.MIDDLE_LEFT);

    return layout;
}

From source file:com.esofthead.mycollab.module.project.view.kanban.AddNewColumnWindow.java

License:Open Source License

public AddNewColumnWindow(final IKanbanView kanbanView, final String type, final String fieldGroup) {
    super(AppContext.getMessage(TaskI18nEnum.ACTION_NEW_COLUMN));
    this.setWidth("800px");
    this.setModal(true);
    this.setResizable(false);
    this.center();
    MVerticalLayout layout = new MVerticalLayout().withMargin(new MarginInfo(false, false, true, false));
    GridFormLayoutHelper gridFormLayoutHelper = GridFormLayoutHelper.defaultFormLayoutHelper(1, 4);
    this.setContent(layout);

    final TextField stageField = new TextField();
    final CheckBox defaultProject = new CheckBox();
    defaultProject.setEnabled(AppContext.canBeYes(RolePermissionCollections.GLOBAL_PROJECT_SETTINGS));
    final ColorPicker colorPicker = new ColorPicker("", new com.vaadin.shared.ui.colorpicker.Color(
            DEFAULT_COLOR.getRed(), DEFAULT_COLOR.getGreen(), DEFAULT_COLOR.getBlue()));
    final TextArea description = new TextArea();

    gridFormLayoutHelper.addComponent(stageField, AppContext.getMessage(GenericI18Enum.FORM_NAME), 0, 0);
    gridFormLayoutHelper.addComponent(defaultProject,
            AppContext.getMessage(TaskI18nEnum.FORM_COLUMN_DEFAULT_FOR_NEW_PROJECT), 0, 1);
    gridFormLayoutHelper.addComponent(colorPicker, AppContext.getMessage(TaskI18nEnum.FORM_COLUMN_COLOR), 0, 2);
    gridFormLayoutHelper.addComponent(description, AppContext.getMessage(GenericI18Enum.FORM_DESCRIPTION), 0,
            3);/*from w w  w  .j av a 2  s.co m*/

    Button saveBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_SAVE), new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            OptionVal optionVal = new OptionVal();
            optionVal.setCreatedtime(new GregorianCalendar().getTime());
            optionVal.setCreateduser(AppContext.getUsername());
            optionVal.setDescription(description.getValue());
            com.vaadin.shared.ui.colorpicker.Color color = colorPicker.getColor();
            String cssColor = color.getCSS();
            if (cssColor.startsWith("#")) {
                cssColor = cssColor.substring(1);
            }
            optionVal.setColor(cssColor);
            if (defaultProject.getValue()) {
                optionVal.setIsdefault(true);
            } else {
                optionVal.setIsdefault(false);
                optionVal.setExtraid(CurrentProjectVariables.getProjectId());
            }
            optionVal.setSaccountid(AppContext.getAccountId());
            optionVal.setType(type);
            optionVal.setTypeval(stageField.getValue());
            optionVal.setFieldgroup(fieldGroup);
            OptionValService optionService = AppContextUtil.getSpringBean(OptionValService.class);
            int optionValId = optionService.saveWithSession(optionVal, AppContext.getUsername());

            if (optionVal.getIsdefault()) {
                optionVal.setId(null);
                optionVal.setIsdefault(false);
                optionVal.setRefoption(optionValId);
                optionVal.setExtraid(CurrentProjectVariables.getProjectId());
                optionService.saveWithSession(optionVal, AppContext.getUsername());
            }
            kanbanView.addColumn(optionVal);
            close();
        }
    });
    saveBtn.setIcon(FontAwesome.SAVE);
    saveBtn.setStyleName(UIConstants.BUTTON_ACTION);

    Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
            new Button.ClickListener() {
                @Override
                public void buttonClick(Button.ClickEvent clickEvent) {
                    close();
                }
            });
    cancelBtn.setStyleName(UIConstants.BUTTON_OPTION);

    MHorizontalLayout controls = new MHorizontalLayout().with(cancelBtn, saveBtn)
            .withMargin(new MarginInfo(false, true, false, false));
    layout.with(gridFormLayoutHelper.getLayout(), controls).withAlign(controls, Alignment.BOTTOM_RIGHT);
}

From source file:com.esofthead.mycollab.module.project.view.milestone.MilestoneAddWindow.java

License:Open Source License

public MilestoneAddWindow(final SimpleMilestone milestone) {
    if (milestone.getId() == null) {
        setCaption("New milestone");
    } else {//from   ww w  . j a v  a2s .  c  om
        setCaption("Edit milestone");
    }
    this.setWidth("800px");
    this.setModal(true);
    this.setResizable(false);
    VerticalLayout content = new VerticalLayout();
    this.setContent(content);
    final AdvancedEditBeanForm<SimpleMilestone> editForm = new AdvancedEditBeanForm<>();
    content.addComponent(editForm);
    editForm.setFormLayoutFactory(new DefaultDynaFormLayout(ProjectTypeConstants.MILESTONE,
            MilestoneDefaultFormLayoutFactory.getForm(), Milestone.Field.id.name()));
    final MilestoneEditFormFieldFactory milestoneEditFormFieldFactory = new MilestoneEditFormFieldFactory(
            editForm);
    editForm.setBeanFormFieldFactory(milestoneEditFormFieldFactory);
    editForm.setBean(milestone);

    MHorizontalLayout buttonControls = new MHorizontalLayout()
            .withMargin(new MarginInfo(true, true, true, false));
    buttonControls.setDefaultComponentAlignment(Alignment.MIDDLE_RIGHT);

    Button updateAllBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_UPDATE_OTHER_FIELDS),
            new Button.ClickListener() {
                @Override
                public void buttonClick(Button.ClickEvent clickEvent) {
                    EventBusFactory.getInstance()
                            .post(new MilestoneEvent.GotoAdd(MilestoneAddWindow.this, milestone));
                    close();
                }
            });
    updateAllBtn.addStyleName(UIConstants.BUTTON_LINK);

    Button saveBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_SAVE), new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            if (editForm.validateForm()) {
                MilestoneService milestoneService = AppContextUtil.getSpringBean(MilestoneService.class);
                Integer milestoneId;
                if (milestone.getId() == null) {
                    milestoneId = milestoneService.saveWithSession(milestone, AppContext.getUsername());
                } else {
                    milestoneService.updateWithSession(milestone, AppContext.getUsername());
                    milestoneId = milestone.getId();
                }

                AttachmentUploadField uploadField = milestoneEditFormFieldFactory.getAttachmentUploadField();
                String attachPath = AttachmentUtils.getProjectEntityAttachmentPath(AppContext.getAccountId(),
                        milestone.getProjectid(), ProjectTypeConstants.MILESTONE, "" + milestone.getId());
                uploadField.saveContentsToRepo(attachPath);

                EventBusFactory.getInstance()
                        .post(new MilestoneEvent.NewMilestoneAdded(MilestoneAddWindow.this, milestoneId));
                EventBusFactory.getInstance().post(new AssignmentEvent.NewAssignmentAdd(MilestoneAddWindow.this,
                        ProjectTypeConstants.MILESTONE, milestoneId));
                close();
            }
        }
    });
    saveBtn.setIcon(FontAwesome.SAVE);
    saveBtn.setStyleName(UIConstants.BUTTON_ACTION);
    saveBtn.setClickShortcut(ShortcutAction.KeyCode.ENTER);

    Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
            new Button.ClickListener() {
                @Override
                public void buttonClick(Button.ClickEvent clickEvent) {
                    close();
                }
            });
    cancelBtn.setStyleName(UIConstants.BUTTON_OPTION);
    buttonControls.with(updateAllBtn, cancelBtn, saveBtn);
    content.addComponent(buttonControls);
    content.setComponentAlignment(buttonControls, Alignment.MIDDLE_RIGHT);
}