mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 04:07:42 +08:00
PL-7904 Show seconds in Date fields in Entity Inspector
This commit is contained in:
parent
3fac643db4
commit
054211798a
@ -19,12 +19,12 @@ package com.haulmont.cuba.gui.app.core.entityinspector;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import com.haulmont.bali.util.ParamsMap;
|
||||
import com.haulmont.chile.core.datatypes.impl.DateTimeDatatype;
|
||||
import com.haulmont.chile.core.model.MetaClass;
|
||||
import com.haulmont.chile.core.model.MetaProperty;
|
||||
import com.haulmont.chile.core.model.Range;
|
||||
import com.haulmont.chile.core.model.Session;
|
||||
import com.haulmont.cuba.client.ClientConfig;
|
||||
import com.haulmont.cuba.core.app.importexport.CollectionImportPolicy;
|
||||
import com.haulmont.cuba.core.app.importexport.EntityImportExportService;
|
||||
import com.haulmont.cuba.core.app.importexport.EntityImportView;
|
||||
import com.haulmont.cuba.core.app.importexport.ReferenceImportBehaviour;
|
||||
@ -33,6 +33,7 @@ import com.haulmont.cuba.core.global.*;
|
||||
import com.haulmont.cuba.gui.AppConfig;
|
||||
import com.haulmont.cuba.gui.WindowManager;
|
||||
import com.haulmont.cuba.gui.components.*;
|
||||
import com.haulmont.cuba.gui.components.Formatter;
|
||||
import com.haulmont.cuba.gui.components.actions.ExcelAction;
|
||||
import com.haulmont.cuba.gui.components.actions.ItemTrackingAction;
|
||||
import com.haulmont.cuba.gui.components.actions.RefreshAction;
|
||||
@ -49,6 +50,7 @@ import com.haulmont.cuba.gui.upload.FileUploadingAPI;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.security.entity.EntityOp;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -57,6 +59,7 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
import static com.haulmont.cuba.gui.export.ExportFormat.JSON;
|
||||
@ -127,9 +130,6 @@ public class EntityInspectorBrowse extends AbstractLookup {
|
||||
@Inject
|
||||
protected EntityInspectorBrowse.Companion companion;
|
||||
|
||||
/**
|
||||
* Buttons
|
||||
*/
|
||||
protected Button createButton;
|
||||
protected Button editButton;
|
||||
protected Button removeButton;
|
||||
@ -138,7 +138,6 @@ public class EntityInspectorBrowse extends AbstractLookup {
|
||||
protected FileUploadField importUpload;
|
||||
protected PopupButton exportPopupButton;
|
||||
|
||||
|
||||
protected CollectionDatasource entitiesDs;
|
||||
protected MetaClass selectedMeta;
|
||||
|
||||
@ -208,6 +207,15 @@ public class EntityInspectorBrowse extends AbstractLookup {
|
||||
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
|
||||
LinkedList<Table.Column> nonSystemPropertyColumns = new LinkedList<>();
|
||||
LinkedList<Table.Column> systemPropertyColumns = new LinkedList<>();
|
||||
@ -215,10 +223,18 @@ public class EntityInspectorBrowse extends AbstractLookup {
|
||||
//don't show embedded & multiple referred entities
|
||||
if (isEmbedded(metaProperty))
|
||||
continue;
|
||||
if (metaProperty.getRange().getCardinality().isMany())
|
||||
|
||||
Range range = metaProperty.getRange();
|
||||
if (range.getCardinality().isMany())
|
||||
continue;
|
||||
|
||||
|
||||
Table.Column column = new Table.Column(meta.getPropertyPath(metaProperty.getName()));
|
||||
|
||||
if (range.isDatatype() && DateTimeDatatype.NAME.equals(range.asDatatype().getName())) {
|
||||
column.setFormatter(dateTimeFormatter);
|
||||
}
|
||||
|
||||
if (metaProperty.getJavaType().equals(String.class)) {
|
||||
column.setMaxTextLength(MAX_TEXT_LENGTH);
|
||||
}
|
||||
@ -231,11 +247,13 @@ public class EntityInspectorBrowse extends AbstractLookup {
|
||||
systemPropertyColumns.add(column);
|
||||
}
|
||||
}
|
||||
for (Table.Column column : nonSystemPropertyColumns)
|
||||
for (Table.Column column : nonSystemPropertyColumns) {
|
||||
entitiesTable.addColumn(column);
|
||||
}
|
||||
|
||||
for (Table.Column column : systemPropertyColumns)
|
||||
for (Table.Column column : systemPropertyColumns) {
|
||||
entitiesTable.addColumn(column);
|
||||
}
|
||||
|
||||
if (entitiesDs != null) {
|
||||
((DsContextImplementation) getDsContext()).unregister(entitiesDs);
|
||||
|
@ -18,6 +18,7 @@
|
||||
package com.haulmont.cuba.gui.app.core.entityinspector;
|
||||
|
||||
import com.haulmont.chile.core.datatypes.impl.ByteArrayDatatype;
|
||||
import com.haulmont.chile.core.datatypes.impl.DateTimeDatatype;
|
||||
import com.haulmont.chile.core.datatypes.impl.UUIDDatatype;
|
||||
import com.haulmont.chile.core.model.MetaClass;
|
||||
import com.haulmont.chile.core.model.MetaProperty;
|
||||
@ -205,7 +206,7 @@ public class EntityInspectorEditor extends AbstractWindow {
|
||||
}
|
||||
|
||||
protected void initShortcuts() {
|
||||
final String commitShortcut = configuration.getConfig(ClientConfig.class).getCommitShortcut();
|
||||
final String commitShortcut = configuration.getConfig(ClientConfig.class).getCommitShortcut();
|
||||
Action commitAction = new AbstractAction("commitAndClose", commitShortcut) {
|
||||
@Override
|
||||
public void actionPerform(Component component) {
|
||||
@ -287,7 +288,7 @@ public class EntityInspectorEditor extends AbstractWindow {
|
||||
// EmbeddedMapping embeddedMapping = embeddedMetaProperty.getAnnotatedElement().getAnnotation(EmbeddedMapping.class);
|
||||
|
||||
// if (embeddedMapping == null)
|
||||
return null;
|
||||
return null;
|
||||
|
||||
// MetaClass meta = embeddedMetaProperty.getRange().asClass();
|
||||
//
|
||||
@ -395,11 +396,12 @@ public class EntityInspectorEditor extends AbstractWindow {
|
||||
|
||||
createCustomFields(fieldGroup, customFields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates field group for the embedded property
|
||||
*
|
||||
* @param embeddedMetaProperty meta property of the embedded property
|
||||
* @param embeddedItem current value 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()
|
||||
@ -419,18 +421,24 @@ public class EntityInspectorEditor extends AbstractWindow {
|
||||
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 (DateTimeDatatype.NAME.equals(metaProperty.getRange().asDatatype().getName())) {
|
||||
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))) {
|
||||
&& (isByteArray(metaProperty) || isUuid(metaProperty))) {
|
||||
continue;
|
||||
}
|
||||
addField(embeddableMetaClass, metaProperty, embeddedItem, fieldGroup, isRequired, false, isReadonly, customFields);
|
||||
@ -454,6 +462,13 @@ public class EntityInspectorEditor extends AbstractWindow {
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isByteArray(MetaProperty metaProperty) {
|
||||
@ -548,15 +563,15 @@ public class EntityInspectorEditor extends AbstractWindow {
|
||||
* which can be used later to create fieldGenerators
|
||||
*
|
||||
* @param metaProperty meta property of the item's property which field is creating
|
||||
* @param item entity instance containing given property
|
||||
* @param item entity instance containing given property
|
||||
* @param fieldGroup field group to which created field will be added
|
||||
* @param customFields if the field is custom it will be added to this collection
|
||||
* @param required true if the field is required
|
||||
* @param custom true if the field is custom
|
||||
*/
|
||||
protected void addField(MetaClass metaClass, MetaProperty metaProperty, Entity item,
|
||||
FieldGroup fieldGroup, boolean required, boolean custom, boolean readOnly,
|
||||
Collection<FieldGroup.FieldConfig> customFields) {
|
||||
FieldGroup fieldGroup, boolean required, boolean custom, boolean readOnly,
|
||||
Collection<FieldGroup.FieldConfig> customFields) {
|
||||
if (!attrViewPermitted(metaClass, metaProperty))
|
||||
return;
|
||||
|
||||
@ -594,7 +609,7 @@ public class EntityInspectorEditor extends AbstractWindow {
|
||||
|
||||
/**
|
||||
* @param metaProperty meta property
|
||||
* @param item entity containing property of the given meta property
|
||||
* @param item entity containing property of the given meta property
|
||||
* @return true if property require text area component; that is if it either too long or contains line separators
|
||||
*/
|
||||
protected boolean requireTextArea(MetaProperty metaProperty, Entity item) {
|
||||
@ -612,7 +627,7 @@ public class EntityInspectorEditor extends AbstractWindow {
|
||||
}
|
||||
|
||||
protected boolean containsSeparator(String s) {
|
||||
return s.indexOf('\n') >=0 || s.indexOf('\r') >= 0;
|
||||
return s.indexOf('\n') >= 0 || s.indexOf('\r') >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -774,7 +789,7 @@ public class EntityInspectorEditor extends AbstractWindow {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected ButtonsPanel createButtonsPanel(final MetaProperty metaProperty,
|
||||
final CollectionDatasource propertyDs, Table table) {
|
||||
final CollectionDatasource propertyDs, Table table) {
|
||||
MetaClass propertyMetaClass = metaProperty.getRange().asClass();
|
||||
ButtonsPanel propertyButtonsPanel = componentsFactory.createComponent(ButtonsPanel.class);
|
||||
|
||||
@ -816,7 +831,7 @@ public class EntityInspectorEditor extends AbstractWindow {
|
||||
}
|
||||
|
||||
protected AddAction createAddAction(MetaProperty metaProperty, CollectionDatasource propertyDs,
|
||||
Table table, MetaClass propertyMetaClass) {
|
||||
Table table, MetaClass propertyMetaClass) {
|
||||
Lookup.Handler addHandler = createAddHandler(metaProperty, propertyDs);
|
||||
AddAction addAction = new AddAction(table, addHandler, OPEN_TYPE);
|
||||
addAction.setWindowId(EntityInspectorBrowse.SCREEN_NAME);
|
||||
|
@ -27,11 +27,12 @@ excel = Excel
|
||||
refresh = Refresh
|
||||
entityType = Entity Type
|
||||
showRemovedRecords = Show removed records
|
||||
export=Export
|
||||
import=Import
|
||||
exportFailed=Export failed
|
||||
importFailed=Import failed
|
||||
textSelection=Text selection
|
||||
exportZIP=Export as ZIP
|
||||
exportJSON=Export as JSON
|
||||
general=General
|
||||
export = Export
|
||||
import = Import
|
||||
exportFailed = Export failed
|
||||
importFailed = Import failed
|
||||
textSelection = Text selection
|
||||
exportZIP = Export as ZIP
|
||||
exportJSON = Export as JSON
|
||||
general = General
|
||||
dateTimeFormat = dd/MM/yyyy HH:mm:ss
|
@ -34,4 +34,5 @@ importFailed=Импорт не удался
|
||||
textSelection=Выделение текста
|
||||
exportZIP=Экспортировать в ZIP
|
||||
exportJSON=Экспортировать в JSON
|
||||
general=Общие
|
||||
general=Общие
|
||||
dateTimeFormat = dd.MM.yyyy HH:mm:ss
|
Loading…
Reference in New Issue
Block a user