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));
}
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);
}
});
}
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);
}
});
}
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;
}
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;
}
Aggregations