use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.
the class EntityInspectorBrowse method createEntitiesTable.
protected void createEntitiesTable(MetaClass meta) {
if (entitiesTable != null)
tableBox.remove(entitiesTable);
if (filter != null) {
filterBox.remove(filter);
}
entitiesTable = componentsFactory.createComponent(Table.class);
entitiesTable.setFrame(frame);
if (companion != null) {
companion.setHorizontalScrollEnabled(entitiesTable, true);
}
ClientType clientType = AppConfig.getClientType();
if (clientType == ClientType.WEB) {
textSelection.setVisible(true);
textSelection.addValueChangeListener(e -> changeTableTextSelectionEnabled());
}
final SimpleDateFormat dateTimeFormat = new SimpleDateFormat(getMessage("dateTimeFormat"));
Formatter dateTimeFormatter = value -> {
if (value == null) {
return StringUtils.EMPTY;
}
return dateTimeFormat.format(value);
};
// collect properties in order to add non-system columns first
List<Table.Column> nonSystemPropertyColumns = new ArrayList<>(10);
List<Table.Column> systemPropertyColumns = new ArrayList<>(10);
for (MetaProperty metaProperty : meta.getProperties()) {
// don't show embedded, transient & multiple referred entities
if (isEmbedded(metaProperty) || metadata.getTools().isNotPersistent(metaProperty))
continue;
Range range = metaProperty.getRange();
if (range.getCardinality().isMany())
continue;
Table.Column column = new Table.Column(meta.getPropertyPath(metaProperty.getName()));
if (range.isDatatype() && range.asDatatype().getJavaClass().equals(Date.class)) {
column.setFormatter(dateTimeFormatter);
}
if (metaProperty.getJavaType().equals(String.class)) {
column.setMaxTextLength(MAX_TEXT_LENGTH);
}
if (!metadata.getTools().isSystem(metaProperty)) {
column.setCaption(getPropertyCaption(meta, metaProperty));
nonSystemPropertyColumns.add(column);
} else {
column.setCaption(metaProperty.getName());
systemPropertyColumns.add(column);
}
}
for (Table.Column column : nonSystemPropertyColumns) {
entitiesTable.addColumn(column);
}
for (Table.Column column : systemPropertyColumns) {
entitiesTable.addColumn(column);
}
if (entitiesDs != null) {
((DsContextImplementation) getDsContext()).unregister(entitiesDs);
}
entitiesDs = DsBuilder.create(getDsContext()).setId("entitiesDs").setMetaClass(meta).setView(createView(meta)).buildCollectionDatasource();
entitiesDs.setLoadDynamicAttributes(true);
entitiesDs.setSoftDeletion(!removedRecords.isChecked());
entitiesDs.setQuery(String.format("select e from %s e", meta.getName()));
entitiesTable.setDatasource(entitiesDs);
tableBox.add(entitiesTable);
entitiesTable.setSizeFull();
createButtonsPanel(entitiesTable);
RowsCount rowsCount = componentsFactory.createComponent(RowsCount.class);
rowsCount.setDatasource(entitiesDs);
entitiesTable.setRowsCount(rowsCount);
entitiesTable.setEnterPressAction(entitiesTable.getAction("edit"));
entitiesTable.setItemClickAction(entitiesTable.getAction("edit"));
entitiesTable.setMultiSelect(true);
createFilter();
}
use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.
the class EntityInspectorEditor method createNestedEmbeddedDatasources.
protected void createNestedEmbeddedDatasources(MetaClass metaClass, String fqnPrefix, Datasource masterDs) {
for (MetaProperty metaProperty : metaClass.getProperties()) {
if (MetaProperty.Type.ASSOCIATION == metaProperty.getType() || MetaProperty.Type.COMPOSITION == metaProperty.getType()) {
if (isEmbedded(metaProperty)) {
String fqn = fqnPrefix + "." + metaProperty.getName();
MetaClass propertyMetaClass = metaProperty.getRange().asClass();
NestedDatasource propertyDs = new EmbeddedDatasourceImpl();
propertyDs.setup(fqn + "Ds", masterDs, metaProperty.getName());
createNestedEmbeddedDatasources(propertyMetaClass, fqn, propertyDs);
datasources.put(fqn, propertyDs);
dsContext.register(propertyDs);
}
}
}
}
use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.
the class EntityInspectorEditor method createEmbeddedFields.
/**
* Recursively instantiates the embedded properties.
* E.g. embedded properties of the embedded property will also be instantiated.
*
* @param metaClass meta class of the entity
* @param item entity instance
*/
protected void createEmbeddedFields(MetaClass metaClass, Entity item) {
for (MetaProperty metaProperty : metaClass.getProperties()) {
if (isEmbedded(metaProperty)) {
MetaClass embeddedMetaClass = metaProperty.getRange().asClass();
Entity embedded = item.getValue(metaProperty.getName());
if (embedded == null) {
embedded = metadata.create(embeddedMetaClass);
item.setValue(metaProperty.getName(), embedded);
}
createEmbeddedFields(embeddedMetaClass, embedded);
}
}
}
use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.
the class EntityLogBrowser method getEntityMetaClasses.
public TreeMap<String, Object> getEntityMetaClasses() {
TreeMap<String, Object> options = new TreeMap<>();
for (MetaClass metaClass : metadata.getTools().getAllPersistentMetaClasses()) {
if (metadata.getExtendedEntities().getExtendedClass(metaClass) == null) {
MetaClass originalMetaClass = metadata.getExtendedEntities().getOriginalOrThisMetaClass(metaClass);
String originalName = originalMetaClass.getName();
Class javaClass = metaClass.getJavaClass();
if (metadata.getTools().hasCompositePrimaryKey(metaClass) && !HasUuid.class.isAssignableFrom(javaClass)) {
continue;
}
String caption = messages.getMessage(javaClass, javaClass.getSimpleName()) + " (" + metaClass.getName() + ")";
options.put(caption, originalName);
}
}
return options;
}
use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.
the class EntityLogBrowser method init.
@Override
public void init(Map<String, Object> params) {
WindowParams.DISABLE_AUTO_REFRESH.set(params, true);
usersDs.refresh();
loggedEntityDs.refresh();
Companion companion = getCompanion();
if (companion != null) {
companion.enableTextSelection(entityLogTable);
companion.enableTextSelection(entityLogAttrTable);
}
systemAttrsList = Arrays.asList("createTs", "createdBy", "updateTs", "updatedBy", "deleteTs", "deletedBy", "version", "id");
Map<String, Object> changeTypeMap = new LinkedHashMap<>();
changeTypeMap.put(messages.getMessage(getClass(), "createField"), "C");
changeTypeMap.put(messages.getMessage(getClass(), "modifyField"), "M");
changeTypeMap.put(messages.getMessage(getClass(), "deleteField"), "D");
changeTypeMap.put(messages.getMessage(getClass(), "restoreField"), "R");
entityMetaClassesMap = getEntityMetaClasses();
entityNameField.setOptionsMap(entityMetaClassesMap);
changeTypeField.setOptionsMap(changeTypeMap);
filterEntityNameField.setOptionsMap(entityMetaClassesMap);
Action clearAction = instancePicker.getAction("clear");
instancePicker.removeAction(clearAction);
instancePicker.removeAction("lookup");
addAction(new SaveAction());
addAction(new CancelAction());
Label label1 = factory.createComponent(Label.class);
label1.setValue(messages.getMessage(getClass(), "show"));
label1.setAlignment(Alignment.MIDDLE_LEFT);
Label label2 = factory.createComponent(Label.class);
label2.setValue(messages.getMessage(getClass(), "rows"));
label2.setAlignment(Alignment.MIDDLE_LEFT);
ButtonsPanel panel = entityLogTable.getButtonsPanel();
showRowField = factory.createComponent(TextField.class);
showRowField.setWidth(themeConstants.get("cuba.gui.EntityLogBrowser.showRowField.width"));
showRowField.setValue(String.valueOf(DEFAULT_SHOW_ROWS));
panel.add(label1);
panel.add(showRowField);
panel.add(label2);
disableControls();
setDateFieldTime();
instancePicker.setEnabled(false);
PickerField.LookupAction lookupAction = new PickerField.LookupAction(instancePicker) {
@Override
public void actionPerform(Component component) {
final MetaClass metaClass = pickerField.getMetaClass();
if (pickerField.isEditable()) {
String currentWindowAlias = lookupScreen;
if (currentWindowAlias == null) {
if (metaClass == null) {
throw new IllegalStateException("Please specify metaclass or property for PickerField");
}
currentWindowAlias = windowConfig.getLookupScreenId(metaClass);
}
Window lookupWindow = (Window) pickerField.getFrame();
Lookup.Handler lookupWindowHandler = items -> {
if (!items.isEmpty()) {
Object item = items.iterator().next();
pickerField.setValue(item);
afterSelect(items);
}
};
if (config.hasWindow(currentWindowAlias)) {
lookupWindow.openLookup(currentWindowAlias, lookupWindowHandler, lookupScreenOpenType, lookupScreenParams != null ? lookupScreenParams : Collections.emptyMap());
} else {
lookupWindow.openLookup(EntityInspectorBrowse.SCREEN_NAME, lookupWindowHandler, WindowManager.OpenType.THIS_TAB, ParamsMap.of("entity", metaClass.getName()));
}
lookupWindow.addCloseListener(actionId -> pickerField.requestFocus());
}
}
};
instancePicker.addAction(lookupAction);
instancePicker.addAction(clearAction);
entityNameField.addValueChangeListener(e -> {
if (entityNameField.isEditable())
fillAttributes((String) e.getValue(), null, true);
});
loggedEntityDs.addItemChangeListener(e -> {
if (e.getItem() != null) {
fillAttributes(e.getItem().getName(), e.getItem(), false);
checkAllCheckboxes();
} else {
setSelectAllCheckBox(false);
clearAttributes();
}
});
filterEntityNameField.addValueChangeListener(e -> {
if (e.getValue() != null) {
instancePicker.setEnabled(true);
MetaClass metaClass = metadata.getSession().getClassNN(e.getValue().toString());
instancePicker.setMetaClass(metaClass);
} else {
instancePicker.setEnabled(false);
}
instancePicker.setValue(null);
});
selectAllCheckBox.addValueChangeListener(e -> enableAllCheckBoxes((boolean) e.getValue()));
entityLogTable.addGeneratedColumn("entityId", entity -> {
if (entity.getObjectEntityId() != null) {
return new Table.PlainTextCell(entity.getObjectEntityId().toString());
}
return null;
}, Table.PlainTextCell.class);
}
Aggregations