com.vaadin.ui.ItemCaptionGenerator Java Examples

The following examples show how to use com.vaadin.ui.ItemCaptionGenerator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractOptionValComboBox.java    From mycollab with GNU Affero General Public License v3.0 6 votes vote down vote up
public AbstractOptionValComboBox(Class<E> enumCls) {
    this.enumCls = enumCls;
    this.setPageLength(20);
    this.setEmptySelectionAllowed(false);
    options = loadOptions();
    this.setItems(options);
    this.setStyleGenerator(itemId -> {
        if (itemId != null) {
            return "" + itemId.hashCode();
        }
        return null;
    });
    this.setItemCaptionGenerator((ItemCaptionGenerator<OptionVal>) option -> {
        String value = option.getTypeval();
        try {
            Enum anEnum = Enum.valueOf(enumCls, value);
            return StringUtils.trim(UserUIContext.getMessage(anEnum), 25, true);
        } catch (Exception e) {
            return StringUtils.trim(value, 25, true);
        }
    });
}
 
Example #2
Source File: RoleComboBox.java    From mycollab with GNU Affero General Public License v3.0 6 votes vote down vote up
public RoleComboBox() {
    this.setEmptySelectionAllowed(false);
    RoleSearchCriteria criteria = new RoleSearchCriteria();

    RoleService roleService = AppContextUtil.getSpringBean(RoleService.class);
    roles = (List<SimpleRole>) roleService.findPageableListByCriteria(new BasicSearchRequest<>(criteria));

    SimpleRole ownerRole = new SimpleRole();
    ownerRole.setId(-1);
    ownerRole.setRolename(UserUIContext.getMessage(RoleI18nEnum.OPT_ACCOUNT_OWNER));
    roles.add(ownerRole);

    setItems(roles);
    setItemCaptionGenerator((ItemCaptionGenerator<SimpleRole>) Role::getRolename);
    setValue(roles.get(0));

    roles.forEach(role -> {
        if (Boolean.TRUE.equals(role.getIsdefault())) {
            this.setValue(role);
        }
    });
}
 
Example #3
Source File: TicketTypeListSelect.java    From mycollab with GNU Affero General Public License v3.0 6 votes vote down vote up
public TicketTypeListSelect() {
    this.setRows(3);

    if (!SiteConfiguration.isCommunityEdition()) {
        this.setItems(ProjectTypeConstants.TASK, ProjectTypeConstants.BUG, ProjectTypeConstants.RISK);
    } else {
        this.setItems(ProjectTypeConstants.TASK, ProjectTypeConstants.BUG);
    }

    this.setItemCaptionGenerator((ItemCaptionGenerator<String>) item -> {
        if (ProjectTypeConstants.TASK.equals(item)) {
            return UserUIContext.getMessage(TaskI18nEnum.SINGLE);
        } else if (ProjectTypeConstants.BUG.equals(item)) {
            return UserUIContext.getMessage(BugI18nEnum.SINGLE);
        } else if (ProjectTypeConstants.RISK.equals(item)) {
            return UserUIContext.getMessage(RiskI18nEnum.SINGLE);
        } else {
            return "";
        }
    });
}
 
Example #4
Source File: CountryComboBox.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
public CountryComboBox() {
    String[] countries = CountryValueFactory.countries;
    this.setItems(countries);
    this.setItemCaptionGenerator((ItemCaptionGenerator<String>) country -> {
        Locale obj = new Locale("", country);
        return obj.getDisplayCountry(UserUIContext.getUserLocale());
    });
    setWidth(WebThemes.FORM_CONTROL_WIDTH);
}
 
Example #5
Source File: ActiveUserListSelect.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
public ActiveUserListSelect() {

        UserSearchCriteria criteria = new UserSearchCriteria();
        criteria.setSaccountid(new NumberSearchField(AppUI.getAccountId()));
        criteria.setRegisterStatuses(new SetSearchField<>(RegisterStatusConstants.ACTIVE));

        UserService userService = AppContextUtil.getSpringBean(UserService.class);
        List<SimpleUser> users = (List<SimpleUser>) userService.findPageableListByCriteria(new BasicSearchRequest<>(criteria));

        this.setItems(users);
        this.setItemCaptionGenerator((ItemCaptionGenerator<SimpleUser>) user -> user.getDisplayName());
        this.setItemIconGenerator((IconGenerator<SimpleUser>) user -> UserAvatarControlFactory.createAvatarResource(user.getAvatarid(), 16));

        this.setRows(4);
    }
 
Example #6
Source File: ActiveUserComboBox.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
public ActiveUserComboBox() {
    this.setWidth(WebThemes.FORM_CONTROL_WIDTH);
    UserSearchCriteria criteria = new UserSearchCriteria();
    criteria.setSaccountid(new NumberSearchField(AppUI.getAccountId()));
    criteria.setRegisterStatuses(new SetSearchField<>(RegisterStatusConstants.ACTIVE));

    UserService userService = AppContextUtil.getSpringBean(UserService.class);
    users = (List<SimpleUser>) userService.findPageableListByCriteria(new BasicSearchRequest<>(criteria));
    setItems(users);
    setItemCaptionGenerator((ItemCaptionGenerator<SimpleUser>) user -> StringUtils.trim(user.getDisplayName(), 30, true));
    setItemIconGenerator((IconGenerator<SimpleUser>) user -> UserAvatarControlFactory.createAvatarResource(user.getAvatarid(), 16));
}
 
Example #7
Source File: UserProjectComboBox.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
public UserProjectComboBox() {
    ProjectService projectService = AppContextUtil.getSpringBean(ProjectService.class);
    if (UserUIContext.isAdmin()) {
        projects = projectService.getProjectsUserInvolved(null, AppUI.getAccountId());
    } else {
        projects = projectService.getProjectsUserInvolved(UserUIContext.getUsername(), AppUI.getAccountId());
    }

    setItems(projects);
    setItemCaptionGenerator((ItemCaptionGenerator<SimpleProject>) Project::getName);
    this.setWidth(WebThemes.FORM_CONTROL_WIDTH);
}
 
Example #8
Source File: UserProjectListSelect.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
public UserProjectListSelect() {
    setRows(4);
    ProjectService projectService = AppContextUtil.getSpringBean(ProjectService.class);
    if (UserUIContext.isAdmin()) {
        projects = projectService.getProjectsUserInvolved(null, AppUI.getAccountId());
    } else {
        projects = projectService.getProjectsUserInvolved(UserUIContext.getUsername(), AppUI.getAccountId());
    }

    setItems(projects);
    setItemCaptionGenerator((ItemCaptionGenerator<SimpleProject>) Project::getName);
    this.setWidth(WebThemes.FORM_CONTROL_WIDTH);
}
 
Example #9
Source File: TaskStatusListSelect.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
public TaskStatusListSelect() {
    this.setRows(4);

    OptionValService optionValService = AppContextUtil.getSpringBean(OptionValService.class);
    List<OptionVal> options = optionValService.findOptionVals(ProjectTypeConstants.TASK,
            CurrentProjectVariables.getProjectId(), AppUI.getAccountId());
    setItems(options);
    setItemCaptionGenerator((ItemCaptionGenerator<OptionVal>) option -> UserUIContext.getMessage(StatusI18nEnum.class,
            option.getTypeval()));
}
 
Example #10
Source File: KeyCaptionComboBox.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
public KeyCaptionComboBox(boolean nullSelectionAllowed, Entry... entries) {
    this.setEmptySelectionAllowed(nullSelectionAllowed);
    this.entries = entries;
    this.setItems(entries);
    this.setItemCaptionGenerator((ItemCaptionGenerator<Entry>) entry -> UserUIContext.getMessage(entry.caption));
    this.setWidth(WebThemes.FORM_CONTROL_WIDTH);
}
 
Example #11
Source File: ProjectRoleComboBox.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
public ProjectRoleComboBox() {
    setWidth(WebThemes.FORM_CONTROL_WIDTH);
    setEmptySelectionAllowed(false);
    ProjectRoleSearchCriteria criteria = new ProjectRoleSearchCriteria();
    criteria.setSaccountid(new NumberSearchField(AppUI.getAccountId()));
    criteria.setProjectId(new NumberSearchField(CurrentProjectVariables.getProjectId()));

    ProjectRoleService roleService = AppContextUtil.getSpringBean(ProjectRoleService.class);
    roles = (List<SimpleProjectRole>) roleService.findPageableListByCriteria(new BasicSearchRequest<>(criteria));

    this.setItems(roles);

    this.setEmptySelectionAllowed(false);
    this.setItemCaptionGenerator((ItemCaptionGenerator<SimpleProjectRole>) ProjectRole::getRolename);
}
 
Example #12
Source File: VersionListSelect.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
public VersionListSelect() {
    this.setRows(4);
    VersionSearchCriteria searchCriteria = new VersionSearchCriteria();
    searchCriteria.setStatus(StringSearchField.and(StatusI18nEnum.Open.name()));
    searchCriteria.setProjectId(new NumberSearchField(CurrentProjectVariables.getProjectId()));

    VersionService versionService = AppContextUtil.getSpringBean(VersionService.class);
    versions = (List<Version>) versionService.findPageableListByCriteria(new BasicSearchRequest<>(searchCriteria));
    this.setItems(versions);
    this.setItemCaptionGenerator((ItemCaptionGenerator<Version>) Version::getName);
}
 
Example #13
Source File: ComponentListSelect.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
public ComponentListSelect() {
    this.setRows(4);
    ComponentSearchCriteria searchCriteria = new ComponentSearchCriteria();
    searchCriteria.setStatus(StringSearchField.and(OptionI18nEnum.StatusI18nEnum.Open.name()));
    searchCriteria.setProjectId(NumberSearchField.equal(CurrentProjectVariables.getProjectId()));

    ComponentService componentService = AppContextUtil.getSpringBean(ComponentService.class);
    List<Component> components = (List<Component>) componentService.findPageableListByCriteria(new BasicSearchRequest<>(searchCriteria));
    this.setItems(components);
    this.setItemCaptionGenerator((ItemCaptionGenerator<Component>) Component::getName);
}
 
Example #14
Source File: ProjectMemberListSelect.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
public ProjectMemberListSelect(boolean activeMembers, List<Integer> projectIds) {
    ProjectMemberSearchCriteria criteria = new ProjectMemberSearchCriteria();
    criteria.setProjectIds(new SetSearchField<>(projectIds));

    if (activeMembers) {
        criteria.setStatuses(new SetSearchField<>(ProjectMemberStatusConstants.ACTIVE));
    }

    ProjectMemberService projectMemberService = AppContextUtil.getSpringBean(ProjectMemberService.class);
    List<SimpleProjectMember> members = (List<SimpleProjectMember>) projectMemberService.findPageableListByCriteria(new BasicSearchRequest<>(criteria));
    this.setItems(members);
    this.setItemCaptionGenerator((ItemCaptionGenerator<SimpleProjectMember>) SimpleProjectMember::getDisplayName);
    setItemIconGenerator((IconGenerator<SimpleProjectMember>) member -> UserAvatarControlFactory.createAvatarResource(member.getMemberAvatarId(), 16));
    this.setRows(4);
}
 
Example #15
Source File: ProjectAddBaseTemplateWindow.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
TemplateProjectComboBox() {
    ProjectService projectService = AppContextUtil.getSpringBean(ProjectService.class);
    ProjectSearchCriteria searchCriteria = new ProjectSearchCriteria();
    searchCriteria.addExtraField(ProjectSearchCriteria.p_template.buildParamIsEqual(SearchField.AND, 1));
    searchCriteria.setSaccountid(new NumberSearchField(AppUI.getAccountId()));
    List<SimpleProject> projectTemplates = (List<SimpleProject>) projectService.findPageableListByCriteria(new BasicSearchRequest<>(searchCriteria));
    this.setItems(projectTemplates);
    this.setItemCaptionGenerator((ItemCaptionGenerator<SimpleProject>) item -> StringUtils.trim(String.format("[%s] %s", item.getShortname(),
            item.getName()), 50, true));
}
 
Example #16
Source File: MilestoneListSelect.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
public MilestoneListSelect() {
    this.setRows(4);

    MilestoneService milestoneService = AppContextUtil.getSpringBean(MilestoneService.class);
    MilestoneSearchCriteria criteria = new MilestoneSearchCriteria();
    criteria.setProjectIds(new SetSearchField<>(CurrentProjectVariables.getProjectId()));
    List<SimpleMilestone> milestones = (List<SimpleMilestone>) milestoneService.findPageableListByCriteria(new BasicSearchRequest<>(criteria));
    this.setItems(milestones);
    this.setItemCaptionGenerator((ItemCaptionGenerator<SimpleMilestone>) Milestone::getName);
}
 
Example #17
Source File: MilestoneComboBox.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
public MilestoneComboBox() {
    this.setWidth(WebThemes.FORM_CONTROL_WIDTH);
    MilestoneSearchCriteria criteria = new MilestoneSearchCriteria();
    SimpleProject project = CurrentProjectVariables.getProject();
    if (project != null) {
        criteria.setProjectIds(new SetSearchField<>(project.getId()));
        MilestoneService milestoneService = AppContextUtil.getSpringBean(MilestoneService.class);
        milestones = (List<SimpleMilestone>) milestoneService.findPageableListByCriteria(new BasicSearchRequest<>(criteria));
        milestones.sort(new MilestoneComparator());

        this.setItems(milestones);
        this.setItemCaptionGenerator((ItemCaptionGenerator<SimpleMilestone>) milestone -> StringUtils.trim(milestone.getName(), 25, true));
        this.setItemIconGenerator((IconGenerator<SimpleMilestone>) milestone -> ProjectAssetsUtil.getPhaseIcon(milestone.getStatus()));
    }
}
 
Example #18
Source File: LocaleSelect.java    From viritin with Apache License 2.0 5 votes vote down vote up
public LocaleSelect() {
    setItemCaptionGenerator(new ItemCaptionGenerator<Locale>() {
        @Override
        public String apply(Locale option) {
            return option.getDisplayName(option);
        }
    });
}
 
Example #19
Source File: CurrencyComboBoxField.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
public CurrencyComboBoxField() {
    this.setWidth(WebThemes.FORM_CONTROL_WIDTH);
    Set<Currency> availableCurrencies = Currency.getAvailableCurrencies();
    this.setItems(availableCurrencies);
    this.setItemCaptionGenerator((ItemCaptionGenerator<Currency>) currency -> String.format("%s (%s)", currency.getDisplayName
            (UserUIContext.getUserLocale()), currency.getCurrencyCode()));
}
 
Example #20
Source File: DemoUI.java    From gantt with Apache License 2.0 4 votes vote down vote up
private Panel createControls() {
    Panel panel = new Panel();
    panel.setWidth(100, Unit.PERCENTAGE);

    controls = new HorizontalLayout();
    controls.setSpacing(true);
    controls.setMargin(true);
    panel.setContent(controls);

    subControls = new HorizontalLayout();
    subControls.setSpacing(true);
    subControls.setVisible(false);

    start = createStartDateField();
    end = createEndDateField();

    Button createStep = new Button("Create New Step...", createStepClickListener);

    HorizontalLayout heightAndUnit = new HorizontalLayout(Util.createHeightEditor(gantt),
            Util.createHeightUnitEditor(gantt));

    HorizontalLayout widthAndUnit = new HorizontalLayout(Util.createWidthEditor(gantt),
            Util.createWidthUnitEditor(gantt));

    reso = new NativeSelect<Resolution>("Resolution");
    reso.setEmptySelectionAllowed(false);
    reso.setItems(org.tltv.gantt.client.shared.Resolution.Hour, org.tltv.gantt.client.shared.Resolution.Day,
            org.tltv.gantt.client.shared.Resolution.Week);
    reso.setValue(gantt.getResolution());
    resolutionValueChangeRegistration = Optional.of(reso.addValueChangeListener(resolutionValueChangeListener));

    localeSelect = new NativeSelect<Locale>("Locale") {
        @Override
        public void attach() {
            super.attach();

            if (getValue() == null) {
                // use default locale
                setValue(gantt.getLocale());
                addValueChangeListener(localeValueChangeListener);
            }
        }
    };
    localeSelect.setEmptySelectionAllowed(false);
    localeSelect.setItems(Locale.getAvailableLocales());
    localeSelect.setItemCaptionGenerator((l) -> l.getDisplayName(getLocale()));

    ComboBox<String> timezoneSelect = new ComboBox<String>("Timezone");
    timezoneSelect.setWidth(300, Unit.PIXELS);
    timezoneSelect.setEmptySelectionAllowed(false);
    timezoneSelect.setItemCaptionGenerator(new ItemCaptionGenerator<String>() {

        @Override
        public String apply(String item) {
            if ("Default".equals(item)) {
                return "Default (" + getDefaultTimeZone().getDisplayName() + ")";
            }
            TimeZone tz = TimeZone.getTimeZone(item);
            return tz.getID() + " (raw offset " + (tz.getRawOffset() / 60000) + "m)";
        }
    });
    List<String> items = new ArrayList<>();
    items.add("Default");
    items.addAll(Gantt.getSupportedTimeZoneIDs());
    timezoneSelect.setItems((caption, fltr) -> caption.contains(fltr), items);
    timezoneSelect.setValue("Default");
    timezoneSelect.addValueChangeListener(timezoneValueChangeListener);

    final Button toggleSubControlsBtn = new Button("Show More Settings...");
    toggleSubControlsBtn.addStyleName("link");
    toggleSubControlsBtn.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            subControls.setVisible(!subControls.isVisible());
            toggleSubControlsBtn.setCaption(subControls.isVisible() ? "Less Settings..." : "More Settings...");
        }
    });

    controls.addComponent(start);
    controls.addComponent(end);
    controls.addComponent(reso);
    controls.addComponent(subControls);
    controls.addComponent(toggleSubControlsBtn);
    controls.setComponentAlignment(toggleSubControlsBtn, Alignment.BOTTOM_CENTER);

    subControls.addComponent(localeSelect);
    subControls.addComponent(timezoneSelect);
    subControls.addComponent(heightAndUnit);
    subControls.addComponent(widthAndUnit);
    subControls.addComponent(createStep);
    subControls.setComponentAlignment(createStep, Alignment.MIDDLE_LEFT);

    return panel;
}
 
Example #21
Source File: TimeZoneSelectionField.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
private void setCboTimeZone(String area) {
    Collection<TimezoneVal> timeZones = TimezoneVal.getTimezoneInAreas(area);
    timezoneSelection.setItems(timeZones);
    timezoneSelection.setItemCaptionGenerator((ItemCaptionGenerator<TimezoneVal>) timezone -> timezone.getDisplayName());
}
 
Example #22
Source File: I18nValueListSelect.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
public void loadData(Collection<T> values) {
    this.setRows(4);
    this.setItems(values);
    this.setItemCaptionGenerator((ItemCaptionGenerator<T>) item -> UserUIContext.getMessage(item));
}
 
Example #23
Source File: CubaSearchSelectPickerField.java    From cuba with Apache License 2.0 4 votes vote down vote up
public ItemCaptionGenerator<T> getItemCaptionGenerator() {
    return getFieldInternal().getItemCaptionGenerator();
}
 
Example #24
Source File: I18nValueComboBox.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
public final void loadData(Collection<T> values) {
    this.setItems(values);
    this.setItemCaptionGenerator((ItemCaptionGenerator<T>) o -> UserUIContext.getMessage(o));
}
 
Example #25
Source File: ProjectMemberSelectionBox.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
private void loadUserList() {
    this.setItems(members);
    this.setItemCaptionGenerator((ItemCaptionGenerator<SimpleProjectMember>) member -> StringUtils.trim(member.getDisplayName(), 25, true));
    this.setItemIconGenerator((IconGenerator<SimpleProjectMember>) member -> UserAvatarControlFactory.createAvatarResource(member.getMemberAvatarId(), 16));
}
 
Example #26
Source File: NotificationSettingWindow.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
public NotificationSettingWindow(SimpleProjectMember projectMember) {
    super(UserUIContext.getMessage(ProjectCommonI18nEnum.ACTION_EDIT_NOTIFICATION));
    withModal(true).withResizable(false).withWidth("600px").withCenter();
    ProjectNotificationSettingService prjNotificationSettingService = AppContextUtil.getSpringBean(ProjectNotificationSettingService.class);
    ProjectNotificationSetting notification = prjNotificationSettingService.findNotification(projectMember.getUsername(), projectMember.getProjectid(),
            projectMember.getSaccountid());

    MVerticalLayout body = new MVerticalLayout();

    final RadioButtonGroup<String> optionGroup = new RadioButtonGroup(null);
    optionGroup.setItems(NotificationType.Default.name(), NotificationType.None.name(), NotificationType.Minimal.name(), NotificationType.Full.name());
    optionGroup.setItemCaptionGenerator((ItemCaptionGenerator<String>) item -> {
        if (item.equals(NotificationType.Default.name())) {
            return UserUIContext.getMessage(ProjectSettingI18nEnum.OPT_DEFAULT_SETTING);
        } else if (item.equals(NotificationType.None.name())) {
            return UserUIContext.getMessage(ProjectSettingI18nEnum.OPT_NONE_SETTING);
        } else if (item.equals(NotificationType.Minimal.name())) {
            return UserUIContext.getMessage(ProjectSettingI18nEnum.OPT_MINIMUM_SETTING);
        } else if (item.equals(NotificationType.Full.name())) {
            return UserUIContext.getMessage(ProjectSettingI18nEnum.OPT_MAXIMUM_SETTING);
        } else {
            throw new MyCollabException("Not supported");
        }
    });

    optionGroup.setWidth("100%");
    body.with(optionGroup);

    String levelVal = notification.getLevel();
    if (levelVal == null) {
        optionGroup.setValue(NotificationType.Default.name());
    } else {
        optionGroup.setValue(levelVal);
    }

    MButton closeBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_CLOSE), clickEvent -> close())
            .withStyleName(WebThemes.BUTTON_OPTION);
    MButton saveBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_SAVE), clickEvent -> {
        try {
            notification.setLevel(optionGroup.getValue());
            ProjectNotificationSettingService projectNotificationSettingService = AppContextUtil.getSpringBean(ProjectNotificationSettingService.class);

            if (notification.getId() == null) {
                projectNotificationSettingService.saveWithSession(notification, UserUIContext.getUsername());
            } else {
                projectNotificationSettingService.updateWithSession(notification, UserUIContext.getUsername());
            }
            NotificationUtil.showNotification(UserUIContext.getMessage(GenericI18Enum.OPT_CONGRATS),
                    UserUIContext.getMessage(ProjectSettingI18nEnum.DIALOG_UPDATE_SUCCESS));
            close();
        } catch (Exception e) {
            throw new MyCollabException(e);
        }
    }).withStyleName(WebThemes.BUTTON_ACTION).withIcon(VaadinIcons.CLIPBOARD)
            .withClickShortcut(ShortcutAction.KeyCode.ENTER);
    MHorizontalLayout btnControls = new MHorizontalLayout(closeBtn, saveBtn);
    body.with(btnControls).withAlign(btnControls, Alignment.TOP_RIGHT);

    withContent(body);
}
 
Example #27
Source File: ProjectNotificationSettingViewComponent.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
public ProjectNotificationSettingViewComponent(final ProjectNotificationSetting bean) {
    super(UserUIContext.getMessage(ProjectSettingI18nEnum.VIEW_TITLE));

    MVerticalLayout body = new MVerticalLayout().withMargin(new MarginInfo(true, false, false, false));
    body.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);

    final RadioButtonGroup<String> optionGroup = new RadioButtonGroup<>(null);
    optionGroup.setItems(NotificationType.Default.name(), NotificationType.None.name(), NotificationType.Minimal.name(), NotificationType.Full.name());
    optionGroup.setItemCaptionGenerator((ItemCaptionGenerator<String>) item -> {
        if (item.equals(NotificationType.Default.name())) {
            return UserUIContext.getMessage(ProjectSettingI18nEnum.OPT_DEFAULT_SETTING);
        } else if (item.equals(NotificationType.None.name())) {
            return UserUIContext.getMessage(ProjectSettingI18nEnum.OPT_NONE_SETTING);
        } else if (item.equals(NotificationType.Minimal.name())) {
            return UserUIContext.getMessage(ProjectSettingI18nEnum.OPT_MINIMUM_SETTING);
        } else if (item.equals(NotificationType.Full.name())) {
            return UserUIContext.getMessage(ProjectSettingI18nEnum.OPT_MAXIMUM_SETTING);
        } else {
            throw new MyCollabException("Not supported");
        }
    });

    optionGroup.setWidth("100%");
    body.with(optionGroup);

    String levelVal = bean.getLevel();
    if (levelVal == null) {
        optionGroup.setValue(NotificationType.Default.name());
    } else {
        optionGroup.setValue(levelVal);
    }

    MButton saveBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_SAVE), clickEvent -> {
        try {
            bean.setLevel(optionGroup.getValue());
            ProjectNotificationSettingService projectNotificationSettingService = AppContextUtil.getSpringBean(ProjectNotificationSettingService.class);

            if (bean.getId() == null) {
                projectNotificationSettingService.saveWithSession(bean, UserUIContext.getUsername());
            } else {
                projectNotificationSettingService.updateWithSession(bean, UserUIContext.getUsername());
            }
            NotificationUtil.showNotification(UserUIContext.getMessage(GenericI18Enum.OPT_CONGRATS),
                    UserUIContext.getMessage(ProjectSettingI18nEnum.DIALOG_UPDATE_SUCCESS));
        } catch (Exception e) {
            throw new MyCollabException(e);
        }
    }).withIcon(VaadinIcons.CLIPBOARD).withStyleName(WebThemes.BUTTON_ACTION).withVisible(!CurrentProjectVariables.isProjectArchived())
            .withClickShortcut(KeyCode.ENTER);
    body.addComponent(saveBtn);

    this.addComponent(body);
}
 
Example #28
Source File: EnumSelect.java    From viritin with Apache License 2.0 4 votes vote down vote up
public EnumSelect<T> withItemCaptionGenerator(ItemCaptionGenerator<T> itemCaptionGenerator) {
	setItemCaptionGenerator(itemCaptionGenerator);
	return this;
}
 
Example #29
Source File: CubaComboBoxPickerField.java    From cuba with Apache License 2.0 4 votes vote down vote up
public void setItemCaptionGenerator(ItemCaptionGenerator<T> itemCaptionGenerator) {
    getFieldInternal().setItemCaptionGenerator(itemCaptionGenerator);
}
 
Example #30
Source File: CubaComboBoxPickerField.java    From cuba with Apache License 2.0 4 votes vote down vote up
public ItemCaptionGenerator<T> getItemCaptionGenerator() {
    return getFieldInternal().getItemCaptionGenerator();
}