use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class EntityInspectorEditor method createView.
/**
* Creates a view, loading all the properties.
* Referenced entities will be loaded with a LOCAL view.
*
* @param meta meta class
* @return View instance
*/
@SuppressWarnings("unchecked")
protected View createView(MetaClass meta) {
View view = new View(meta.getJavaClass(), false);
for (MetaProperty metaProperty : meta.getProperties()) {
switch(metaProperty.getType()) {
case DATATYPE:
case ENUM:
view.addProperty(metaProperty.getName());
break;
case ASSOCIATION:
case COMPOSITION:
String viewName;
if (metadata.getTools().isEmbedded(metaProperty)) {
viewName = View.BASE;
} else if (metaProperty.getRange().getCardinality().isMany()) {
viewName = View.LOCAL;
} else {
viewName = View.MINIMAL;
}
View propView = viewRepository.getView(metaProperty.getRange().asClass(), viewName);
view.addProperty(metaProperty.getName(), new View(propView, metaProperty.getRange().asClass().getName() + ".entity-inspector-view", true));
break;
default:
throw new IllegalStateException("unknown property type");
}
}
return view;
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class EntityInspectorEditor method createPropertyDatasources.
/**
* Creates and registers in dsContext property datasource for each of the entity non-datatype
* and non-enum property
*
* @param masterDs master datasource
*/
protected void createPropertyDatasources(Datasource masterDs) {
for (MetaProperty metaProperty : meta.getProperties()) {
switch(metaProperty.getType()) {
case COMPOSITION:
case ASSOCIATION:
NestedDatasource propertyDs;
if (metaProperty.getRange().getCardinality().isMany()) {
propertyDs = new CollectionPropertyDatasourceImpl();
} else {
if (isEmbedded(metaProperty)) {
propertyDs = new EmbeddedDatasourceImpl();
} else {
propertyDs = new PropertyDatasourceImpl();
}
}
propertyDs.setup(metaProperty.getName() + "Ds", masterDs, metaProperty.getName());
if (isEmbedded(metaProperty)) {
createNestedEmbeddedDatasources(metaProperty.getRange().asClass(), metaProperty.getName(), propertyDs);
}
datasources.put(metaProperty.getName(), propertyDs);
dsContext.register(propertyDs);
break;
default:
break;
}
}
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class EntityInspectorEditor method addEmbeddedFieldGroup.
/**
* Creates field group for the embedded property
*
* @param embeddedMetaProperty meta property of the embedded property
* @param embeddedItem current value of the embedded property
*/
protected void addEmbeddedFieldGroup(MetaProperty embeddedMetaProperty, String fqnPrefix, Entity embeddedItem) {
String fqn = fqnPrefix.isEmpty() ? embeddedMetaProperty.getName() : fqnPrefix + "." + embeddedMetaProperty.getName();
Datasource embedDs = datasources.get(fqn);
if (embedDs == null) {
throw new IllegalStateException(String.format("Datasource %s for property %s not found", fqn, embeddedMetaProperty.getName()));
}
FieldGroup fieldGroup = componentsFactory.createComponent(FieldGroup.class);
fieldGroup.setBorderVisible(true);
fieldGroup.setCaption(getPropertyCaption(embedDs.getMetaClass(), embeddedMetaProperty));
contentPane.add(fieldGroup);
fieldGroup.setFrame(frame);
MetaClass embeddableMetaClass = embeddedMetaProperty.getRange().asClass();
Collection<FieldGroup.FieldConfig> customFields = new LinkedList<>();
MetaProperty nullIndicatorProperty = getNullIndicatorProperty(embeddedMetaProperty);
List<String> dateTimeFields = new ArrayList<>();
for (MetaProperty metaProperty : embeddableMetaClass.getProperties()) {
boolean isRequired = isRequired(metaProperty) || metaProperty.equals(nullIndicatorProperty);
boolean isReadonly = metaProperty.isReadOnly();
switch(metaProperty.getType()) {
case DATATYPE:
if (metaProperty.getRange().asDatatype().getJavaClass().equals(Date.class)) {
dateTimeFields.add(metaProperty.getName());
}
case ENUM:
// skip system properties
if (metadata.getTools().isSystem(metaProperty) && !showSystemFields) {
continue;
}
if (metaProperty.getType() != MetaProperty.Type.ENUM && (isByteArray(metaProperty) || isUuid(metaProperty))) {
continue;
}
addField(embeddableMetaClass, metaProperty, embeddedItem, fieldGroup, isRequired, false, isReadonly, customFields);
break;
case COMPOSITION:
case ASSOCIATION:
if (metaProperty.getRange().getCardinality().isMany()) {
throw new IllegalStateException("tables for the embeddable entities are not supported");
} else {
if (isEmbedded(metaProperty)) {
Entity propertyValue = embeddedItem.getValue(metaProperty.getName());
addEmbeddedFieldGroup(metaProperty, fqn, propertyValue);
} else {
addField(embeddableMetaClass, metaProperty, embeddedItem, fieldGroup, isRequired, true, isReadonly, customFields);
}
}
break;
default:
break;
}
}
fieldGroup.setDatasource(embedDs);
fieldGroup.bind();
for (String dateTimeField : dateTimeFields) {
FieldGroup.FieldConfig field = fieldGroup.getField(dateTimeField);
if (field != null && field.getComponent() != null) {
((DateField) field.getComponent()).setResolution(DateField.Resolution.SEC);
}
}
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class EntityInspectorEditor method createAddAction.
protected AddAction createAddAction(MetaProperty metaProperty, CollectionDatasource propertyDs, Table table, MetaClass propertyMetaClass) {
Lookup.Handler addHandler = createAddHandler(metaProperty, propertyDs);
AddAction addAction = new AddAction(table, addHandler, OPEN_TYPE);
addAction.setWindowId(EntityInspectorBrowse.SCREEN_NAME);
HashMap<String, Object> params = new HashMap<>();
params.put("entity", propertyMetaClass.getName());
MetaProperty inverseProperty = metaProperty.getInverse();
if (inverseProperty != null)
params.put("parentProperty", inverseProperty.getName());
addAction.setWindowParams(params);
addAction.setOpenType(OPEN_TYPE);
addAction.setShortcut(configuration.getConfig(ClientConfig.class).getTableAddShortcut());
return addAction;
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class EntityInspectorEditor method addTable.
/**
* Creates a table for the entities in ONE_TO_MANY or MANY_TO_MANY relation with the current one
*/
protected void addTable(MetaClass metaClass, MetaProperty childMeta) {
MetaClass meta = childMeta.getRange().asClass();
// don't show empty table if the user don't have permissions on the attribute or the entity
if (!attrViewPermitted(metaClass, childMeta.getName()) || !entityOpPermitted(meta, EntityOp.READ)) {
return;
}
// don't show table on new master item, because an exception occurred on safe new item in table
if (isNew && childMeta.getType().equals(MetaProperty.Type.ASSOCIATION)) {
return;
}
// vertical box for the table and its label
BoxLayout vbox = componentsFactory.createComponent(VBoxLayout.class);
vbox.setWidth("100%");
CollectionDatasource propertyDs = (CollectionDatasource) datasources.get(childMeta.getName());
Table table = componentsFactory.createComponent(Table.class);
table.setMultiSelect(true);
table.setFrame(frame);
// place non-system properties columns first
LinkedList<Table.Column> nonSystemPropertyColumns = new LinkedList<>();
LinkedList<Table.Column> systemPropertyColumns = new LinkedList<>();
for (MetaProperty metaProperty : meta.getProperties()) {
if (metaProperty.getRange().isClass() || isRelatedToNonLocalProperty(metaProperty))
// because we use local views
continue;
Table.Column column = new Table.Column(meta.getPropertyPath(metaProperty.getName()));
if (!metadata.getTools().isSystem(metaProperty)) {
column.setCaption(getPropertyCaption(meta, metaProperty));
nonSystemPropertyColumns.add(column);
} else {
column.setCaption(metaProperty.getName());
systemPropertyColumns.add(column);
}
if (metaProperty.getJavaType().equals(String.class)) {
column.setMaxTextLength(MAX_TEXT_LENGTH);
}
}
for (Table.Column column : nonSystemPropertyColumns) table.addColumn(column);
for (Table.Column column : systemPropertyColumns) table.addColumn(column);
// set datasource so we could create a buttons panel
table.setDatasource(propertyDs);
// refresh ds to read ds size
propertyDs.refresh();
ButtonsPanel propertyButtonsPanel = createButtonsPanel(childMeta, propertyDs, table);
table.setButtonsPanel(propertyButtonsPanel);
RowsCount rowsCount = componentsFactory.createComponent(RowsCount.class);
rowsCount.setDatasource(propertyDs);
table.setRowsCount(rowsCount);
table.setWidth("100%");
vbox.setHeight(themeConstants.get("cuba.gui.EntityInspectorEditor.tableContainer.height"));
vbox.add(table);
vbox.expand(table);
vbox.setMargin(true);
TabSheet.Tab tab = tablesTabSheet.addTab(childMeta.toString(), vbox);
tab.setCaption(getPropertyCaption(metaClass, childMeta));
tables.add(table);
}
Aggregations