use of com.haulmont.chile.core.model.Instance in project cuba by cuba-platform.
the class WebEntityLinkField method initComponent.
protected void initComponent() {
component.addClickListener(event -> {
if (clickHandler != null) {
clickHandler.onClick(WebEntityLinkField.this);
} else {
openEntityEditor();
}
});
component.setCaptionFormatter((value, locale) -> {
if (value == null) {
return "";
}
if (value instanceof Instance) {
return metadataTools.getInstanceName((Instance) value);
}
Datatype datatype = Datatypes.getNN(value.getClass());
if (locale != null) {
return datatype.format(value, locale);
}
return datatype.format(value);
});
}
use of com.haulmont.chile.core.model.Instance in project cuba by cuba-platform.
the class AbstractCollectionDatasource method getQueryParameters.
protected Map<String, Object> getQueryParameters(Map<String, Object> params) {
final Map<String, Object> map = new HashMap<>();
for (ParameterInfo info : queryParameters) {
String name = info.getFlatName();
final String path = info.getPath();
final String[] elements = path.split("\\.");
switch(info.getType()) {
case DATASOURCE:
{
String dsName = elements[0];
final Datasource datasource = dsContext.get(dsName);
if (datasource == null) {
throw new DevelopmentException("Datasource '" + dsName + "' not found in dsContext", "datasource", dsName);
}
if (datasource.getState() == State.VALID) {
final Entity item = datasource.getItem();
if (elements.length > 1) {
String[] valuePath = ArrayUtils.subarray(elements, 1, elements.length);
String propertyName = InstanceUtils.formatValuePath(valuePath);
Object value = InstanceUtils.getValueEx(item, propertyName);
map.put(name, value);
} else {
map.put(name, item);
}
} else {
map.put(name, null);
}
break;
}
case PARAM:
{
Object value;
if (dsContext.getFrameContext() == null) {
value = null;
} else {
Map<String, Object> windowParams = dsContext.getFrameContext().getParams();
value = windowParams.get(path);
if (value == null && elements.length > 1) {
Instance instance = (Instance) windowParams.get(elements[0]);
if (instance != null) {
String[] valuePath = ArrayUtils.subarray(elements, 1, elements.length);
String propertyName = InstanceUtils.formatValuePath(valuePath);
value = InstanceUtils.getValueEx(instance, propertyName);
}
}
}
if (value instanceof String && info.isCaseInsensitive()) {
value = makeCaseInsensitive((String) value);
}
map.put(name, value);
break;
}
case COMPONENT:
{
Object value = null;
if (dsContext.getFrameContext() != null) {
value = dsContext.getFrameContext().getValue(path);
if (value instanceof String && info.isCaseInsensitive()) {
value = makeCaseInsensitive((String) value);
}
if (java.sql.Date.class.equals(info.getJavaClass()) && value instanceof Date) {
value = new java.sql.Date(((Date) value).getTime());
}
if (refreshOnComponentValueChange) {
if (componentValueListener == null)
componentValueListener = new ComponentValueListener();
try {
dsContext.getFrameContext().addValueChangeListener(path, componentValueListener);
} catch (Exception e) {
Logger log = LoggerFactory.getLogger(AbstractCollectionDatasource.class);
log.error("Unable to add value listener: " + e);
}
}
}
map.put(name, value);
break;
}
case SESSION:
{
Object value;
value = userSession.getAttribute(path);
if (value instanceof String && info.isCaseInsensitive()) {
value = makeCaseInsensitive((String) value);
}
map.put(name, value);
break;
}
case CUSTOM:
{
Object value = params.get(info.getPath());
if (value == null) {
// a case when a query contains a parameter like :custom$city.country.id and we passed
// just "city" parameter to the datasource refresh() method
String[] pathElements = info.getPath().split("\\.");
if (pathElements.length > 1) {
Object entity = params.get(pathElements[0]);
if (entity instanceof Instance) {
value = InstanceUtils.getValueEx((Instance) entity, Arrays.copyOfRange(pathElements, 1, pathElements.length));
}
}
}
if (value instanceof String && info.isCaseInsensitive()) {
value = makeCaseInsensitive((String) value);
}
map.put(name, value);
break;
}
default:
{
throw new UnsupportedOperationException("Unsupported parameter type: " + info.getType());
}
}
}
return map;
}
use of com.haulmont.chile.core.model.Instance in project cuba by cuba-platform.
the class PropertyDatasourceImpl method setItem.
@Override
public void setItem(T item) {
if (getItem() != null) {
metadata.getTools().copy(item, getItem());
itemsToUpdate.add(item);
} else {
final Instance parentItem = masterDs.getItem();
parentItem.setValue(metaProperty.getName(), item);
}
setModified(true);
}
Aggregations