Search in sources :

Example 1 with WebComponentRenderer

use of com.haulmont.cuba.web.gui.components.renderers.WebComponentRenderer in project documentation by cuba-platform.

the class Users method init.

@Override
public void init(Map<String, Object> params) {
    Map<String, Locale> locales = configuration.getConfig(GlobalConfig.class).getAvailableLocales();
    Map<String, Object> options = new TreeMap<>();
    for (Map.Entry<String, Locale> entry : locales.entrySet()) {
        options.put(entry.getKey(), messages.getTools().localeToString(entry.getValue()));
    }
    DataGrid.Column column = usersGrid.addGeneratedColumn("language", new DataGrid.ColumnGenerator<User, Component>() {

        @Override
        public Component getValue(DataGrid.ColumnGeneratorEvent<User> event) {
            LookupField component = componentsFactory.createComponent(LookupField.class);
            component.setOptionsMap(options);
            component.setWidth("100%");
            User user = event.getItem();
            component.setValue(user.getLanguage());
            component.addValueChangeListener(e -> user.setLanguage((String) e.getValue()));
            return component;
        }

        @Override
        public Class<Component> getType() {
            return Component.class;
        }
    });
    column.setRenderer(new WebComponentRenderer());
}
Also used : Locale(java.util.Locale) GlobalConfig(com.haulmont.cuba.core.global.GlobalConfig) WebComponentRenderer(com.haulmont.cuba.web.gui.components.renderers.WebComponentRenderer) User(com.haulmont.cuba.security.entity.User) Inject(javax.inject.Inject) AbstractWindow(com.haulmont.cuba.gui.components.AbstractWindow) ComponentsFactory(com.haulmont.cuba.gui.xml.layout.ComponentsFactory) TreeMap(java.util.TreeMap) Configuration(com.haulmont.cuba.core.global.Configuration) Locale(java.util.Locale) Map(java.util.Map) LookupField(com.haulmont.cuba.gui.components.LookupField) DataGrid(com.haulmont.cuba.gui.components.DataGrid) Component(com.haulmont.cuba.gui.components.Component) User(com.haulmont.cuba.security.entity.User) GlobalConfig(com.haulmont.cuba.core.global.GlobalConfig) DataGrid(com.haulmont.cuba.gui.components.DataGrid) WebComponentRenderer(com.haulmont.cuba.web.gui.components.renderers.WebComponentRenderer) LookupField(com.haulmont.cuba.gui.components.LookupField) TreeMap(java.util.TreeMap) Component(com.haulmont.cuba.gui.components.Component) TreeMap(java.util.TreeMap) Map(java.util.Map)

Aggregations

Configuration (com.haulmont.cuba.core.global.Configuration)1 GlobalConfig (com.haulmont.cuba.core.global.GlobalConfig)1 AbstractWindow (com.haulmont.cuba.gui.components.AbstractWindow)1 Component (com.haulmont.cuba.gui.components.Component)1 DataGrid (com.haulmont.cuba.gui.components.DataGrid)1 LookupField (com.haulmont.cuba.gui.components.LookupField)1 ComponentsFactory (com.haulmont.cuba.gui.xml.layout.ComponentsFactory)1 User (com.haulmont.cuba.security.entity.User)1 WebComponentRenderer (com.haulmont.cuba.web.gui.components.renderers.WebComponentRenderer)1 Locale (java.util.Locale)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Inject (javax.inject.Inject)1