Search in sources :

Example 1 with CubaComboBox

use of com.haulmont.cuba.web.toolkit.ui.CubaComboBox in project cuba by cuba-platform.

the class WebUserIndicator method refreshUserSubstitutions.

@Override
public void refreshUserSubstitutions() {
    component.removeAllComponents();
    UserSessionSource uss = AppBeans.get(UserSessionSource.NAME);
    List<UserSubstitution> substitutions = getUserSubstitutions();
    User user = uss.getUserSession().getUser();
    AppUI ui = AppUI.getCurrent();
    String substitutedUserCaption = getSubstitutedUserCaption(user);
    if (substitutions.isEmpty()) {
        userComboBox = null;
        userNameLabel = new Label(substitutedUserCaption);
        userNameLabel.setStyleName("c-user-select-label");
        userNameLabel.setSizeUndefined();
        if (ui.isTestMode()) {
            userNameLabel.setCubaId("currentUserLabel");
        }
        component.addComponent(userNameLabel);
        component.setDescription(substitutedUserCaption);
    } else {
        userNameLabel = null;
        userComboBox = new CubaComboBox();
        userComboBox.setFilteringMode(FilteringMode.CONTAINS);
        userComboBox.setNullSelectionAllowed(false);
        userComboBox.setImmediate(true);
        if (ui.isTestMode()) {
            userComboBox.setCubaId("substitutedUserSelect");
            userComboBox.setId(ui.getTestIdManager().getTestId("substitutedUserSelect"));
        }
        userComboBox.setStyleName("c-user-select-combobox");
        userComboBox.addItem(user);
        userComboBox.setItemCaption(user, substitutedUserCaption);
        for (UserSubstitution substitution : substitutions) {
            User substitutedUser = substitution.getSubstitutedUser();
            userComboBox.addItem(substitutedUser);
            userComboBox.setItemCaption(substitutedUser, getSubstitutedUserCaption(substitutedUser));
        }
        UserSession session = uss.getUserSession();
        userComboBox.select(session.getSubstitutedUser() == null ? session.getUser() : session.getSubstitutedUser());
        userComboBox.addValueChangeListener(new SubstitutedUserChangeListener(userComboBox));
        component.addComponent(userComboBox);
        component.setDescription(null);
    }
    adjustWidth();
    adjustHeight();
}
Also used : User(com.haulmont.cuba.security.entity.User) CubaComboBox(com.haulmont.cuba.web.toolkit.ui.CubaComboBox) UserSession(com.haulmont.cuba.security.global.UserSession) Label(com.vaadin.ui.Label) UserSubstitution(com.haulmont.cuba.security.entity.UserSubstitution) AppUI(com.haulmont.cuba.web.AppUI)

Example 2 with CubaComboBox

use of com.haulmont.cuba.web.toolkit.ui.CubaComboBox in project cuba by cuba-platform.

the class WebLookupField method createComponent.

protected void createComponent() {
    this.component = new CubaComboBox() {

        @Override
        public void setPropertyDataSource(Property newDataSource) {
            if (newDataSource == null)
                super.setPropertyDataSource(null);
            else
                super.setPropertyDataSource(new LookupPropertyAdapter(newDataSource));
        }

        @Override
        public void setComponentError(ErrorMessage componentError) {
            boolean handled = false;
            if (componentErrorHandler != null)
                handled = componentErrorHandler.handleError(componentError);
            if (!handled)
                super.setComponentError(componentError);
        }
    };
}
Also used : CubaComboBox(com.haulmont.cuba.web.toolkit.ui.CubaComboBox) ErrorMessage(com.vaadin.server.ErrorMessage) Property(com.vaadin.data.Property)

Aggregations

CubaComboBox (com.haulmont.cuba.web.toolkit.ui.CubaComboBox)2 User (com.haulmont.cuba.security.entity.User)1 UserSubstitution (com.haulmont.cuba.security.entity.UserSubstitution)1 UserSession (com.haulmont.cuba.security.global.UserSession)1 AppUI (com.haulmont.cuba.web.AppUI)1 Property (com.vaadin.data.Property)1 ErrorMessage (com.vaadin.server.ErrorMessage)1 Label (com.vaadin.ui.Label)1