Search in sources :

Example 56 with Datasource

use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.

the class AppPropertiesEdit method init.

@Override
public void init(Map<String, Object> params) {
    cannotEditValueLabel.setVisible(item.getOverridden());
    Datatype datatype = Datatypes.get(item.getDataTypeName());
    fieldGroup.addCustomField("currentValue", (datasource, propertyId) -> {
        if (item.getOverridden()) {
            TextField textField = componentsFactory.createComponent(TextField.class);
            textField.setValue(item.getDisplayedCurrentValue());
            textField.setEditable(false);
            return textField;
        }
        if (item.getEnumValues() != null) {
            return createLookupField(Arrays.asList(item.getEnumValues().split(",")), item.getCurrentValue());
        } else {
            if (datatype instanceof BooleanDatatype) {
                return createLookupField(Arrays.asList(Boolean.TRUE.toString(), Boolean.FALSE.toString()), item.getCurrentValue());
            } else {
                if (Boolean.TRUE.equals(item.getSecret())) {
                    PasswordField passwordField = componentsFactory.createComponent(PasswordField.class);
                    passwordField.setValue(item.getCurrentValue());
                    passwordField.addValueChangeListener(e -> {
                        appPropertyDs.getItem().setCurrentValue(e.getValue() == null ? null : e.getValue().toString());
                    });
                    return passwordField;
                } else {
                    TextField textField = componentsFactory.createComponent(TextField.class);
                    textField.setValue(item.getCurrentValue());
                    try {
                        datatype.parse(item.getCurrentValue(), userSessionSource.getLocale());
                        textField.setDatatype(datatype);
                    } catch (ParseException e) {
                        // do not assign datatype then
                        log.trace("Localized parsing by datatype cannot be used for value {}", item.getCurrentValue());
                    }
                    textField.addValueChangeListener(e -> {
                        appPropertyDs.getItem().setCurrentValue(e.getValue() == null ? null : e.getValue().toString());
                    });
                    return textField;
                }
            }
        }
    });
    final Formatter<String> defaultValueFormatter = (value) -> {
        if (datatype instanceof BooleanDatatype) {
            return value;
        }
        try {
            Object parsedDefaultValue = datatype.parse(value);
            return datatype.format(parsedDefaultValue, userSessionSource.getLocale());
        } catch (ParseException e) {
            log.trace("Localized parsing by datatype cannot be used for value {}", value, e);
        }
        return value;
    };
    displayedDefaultValueField.setFormatter(defaultValueFormatter);
    appPropertyDs.setItem(metadata.getTools().copy(item));
}
Also used : Arrays(java.util.Arrays) Datasource(com.haulmont.cuba.gui.data.Datasource) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Datatypes(com.haulmont.chile.core.datatypes.Datatypes) BooleanDatatype(com.haulmont.chile.core.datatypes.impl.BooleanDatatype) ConfigStorageService(com.haulmont.cuba.core.app.ConfigStorageService) AppBeans(com.haulmont.cuba.core.global.AppBeans) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) Metadata(com.haulmont.cuba.core.global.Metadata) Inject(javax.inject.Inject) ConfigurationClientImpl(com.haulmont.cuba.client.sys.ConfigurationClientImpl) List(java.util.List) Datatype(com.haulmont.chile.core.datatypes.Datatype) AppPropertyEntity(com.haulmont.cuba.core.config.AppPropertyEntity) ComponentsFactory(com.haulmont.cuba.gui.xml.layout.ComponentsFactory) Configuration(com.haulmont.cuba.core.global.Configuration) WindowParam(com.haulmont.cuba.gui.WindowParam) Map(java.util.Map) Named(javax.inject.Named) ParseException(java.text.ParseException) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) BooleanDatatype(com.haulmont.chile.core.datatypes.impl.BooleanDatatype) ParseException(java.text.ParseException) BooleanDatatype(com.haulmont.chile.core.datatypes.impl.BooleanDatatype) Datatype(com.haulmont.chile.core.datatypes.Datatype)

Example 57 with Datasource

use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.

the class EntityCombinedScreen method initBrowseItemChangeListener.

/**
 * Adds a listener that reloads the selected record with the specified view and sets it to editDs.
 */
@SuppressWarnings("unchecked")
protected void initBrowseItemChangeListener() {
    CollectionDatasource browseDs = getTable().getDatasource();
    Datasource editDs = getFieldGroup().getDatasource();
    browseDs.addItemChangeListener(e -> {
        if (e.getItem() != null) {
            Entity reloadedItem = getDsContext().getDataSupplier().reload(e.getDs().getItem(), editDs.getView());
            editDs.setItem(reloadedItem);
        }
    });
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Entity(com.haulmont.cuba.core.entity.Entity) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource)

Example 58 with Datasource

use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.

the class EntityCombinedScreen method initBrowseCreateAction.

/**
 * Adds a CreateAction that removes selection in table, sets a newly created item to editDs
 * and enables controls for record editing.
 */
protected void initBrowseCreateAction() {
    ListComponent table = getTable();
    table.addAction(new CreateAction(table) {

        @SuppressWarnings("unchecked")
        @Override
        protected void internalOpenEditor(CollectionDatasource datasource, Entity newItem, Datasource parentDs, Map<String, Object> params) {
            initNewItem(newItem);
            table.setSelected(Collections.emptyList());
            getFieldGroup().getDatasource().setItem(newItem);
            refreshOptionsForLookupFields();
            enableEditControls(true);
        }
    });
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Entity(com.haulmont.cuba.core.entity.Entity) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) CreateAction(com.haulmont.cuba.gui.components.actions.CreateAction)

Example 59 with Datasource

use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.

the class DesktopTokenList method getMasterEntity.

@Nullable
protected Entity getMasterEntity(CollectionDatasource datasource) {
    if (datasource instanceof NestedDatasource) {
        Datasource masterDs = ((NestedDatasource) datasource).getMaster();
        com.google.common.base.Preconditions.checkState(masterDs != null);
        return masterDs.getItem();
    }
    return null;
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) NestedDatasource(com.haulmont.cuba.gui.data.NestedDatasource) NestedDatasource(com.haulmont.cuba.gui.data.NestedDatasource) Nullable(javax.annotation.Nullable)

Example 60 with Datasource

use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.

the class WebTokenList method getMasterEntity.

@Nullable
protected Entity getMasterEntity(CollectionDatasource datasource) {
    if (datasource instanceof NestedDatasource) {
        Datasource masterDs = ((NestedDatasource) datasource).getMaster();
        com.google.common.base.Preconditions.checkState(masterDs != null);
        return masterDs.getItem();
    }
    return null;
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) NestedDatasource(com.haulmont.cuba.gui.data.NestedDatasource) NestedDatasource(com.haulmont.cuba.gui.data.NestedDatasource) Nullable(javax.annotation.Nullable)

Aggregations

Datasource (com.haulmont.cuba.gui.data.Datasource)111 Ignore (org.junit.Ignore)66 Test (org.junit.Test)66 Component (com.haulmont.cuba.gui.components.Component)61 User (com.haulmont.cuba.security.entity.User)56 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)53 Assert.assertTrue (org.junit.Assert.assertTrue)49 Assert.assertEquals (org.junit.Assert.assertEquals)44 Group (com.haulmont.cuba.security.entity.Group)29 UUID (java.util.UUID)24 ArrayList (java.util.ArrayList)23 Assert (org.junit.Assert)22 List (java.util.List)20 DsBuilder (com.haulmont.cuba.gui.data.DsBuilder)13 Assert.assertNotNull (org.junit.Assert.assertNotNull)12 Date (java.util.Date)11 Entity (com.haulmont.cuba.core.entity.Entity)10 Role (com.haulmont.cuba.security.entity.Role)10 MetaClass (com.haulmont.chile.core.model.MetaClass)9 LookupField (com.haulmont.cuba.gui.components.LookupField)9