Search in sources :

Example 81 with MetaClass

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();
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) ReferenceImportBehaviour(com.haulmont.cuba.core.app.importexport.ReferenceImportBehaviour) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) LoggerFactory(org.slf4j.LoggerFactory) ParamsMap(com.haulmont.bali.util.ParamsMap) CubaIcon(com.haulmont.cuba.gui.icons.CubaIcon) SimpleDateFormat(java.text.SimpleDateFormat) Icons(com.haulmont.cuba.gui.icons.Icons) MetaClass(com.haulmont.chile.core.model.MetaClass) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) Inject(javax.inject.Inject) JSON(com.haulmont.cuba.gui.export.ExportFormat.JSON) ComponentsFactory(com.haulmont.cuba.gui.xml.layout.ComponentsFactory) Files(com.google.common.io.Files) DsContextImplementation(com.haulmont.cuba.gui.data.impl.DsContextImplementation) ExportFormat(com.haulmont.cuba.gui.export.ExportFormat) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) com.haulmont.cuba.gui.components.actions(com.haulmont.cuba.gui.components.actions) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) Logger(org.slf4j.Logger) Range(com.haulmont.chile.core.model.Range) Formatter(com.haulmont.cuba.gui.components.Formatter) MetaProperty(com.haulmont.chile.core.model.MetaProperty) EntityImportExportService(com.haulmont.cuba.core.app.importexport.EntityImportExportService) ExportDisplay(com.haulmont.cuba.gui.export.ExportDisplay) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) EntityImportView(com.haulmont.cuba.core.app.importexport.EntityImportView) ZIP(com.haulmont.cuba.gui.export.ExportFormat.ZIP) IOUtils(org.apache.commons.io.IOUtils) EntityOp(com.haulmont.cuba.security.entity.EntityOp) ByteArrayDataProvider(com.haulmont.cuba.gui.export.ByteArrayDataProvider) AppConfig(com.haulmont.cuba.gui.AppConfig) FileUploadingAPI(com.haulmont.cuba.gui.upload.FileUploadingAPI) ClientConfig(com.haulmont.cuba.client.ClientConfig) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Session(com.haulmont.chile.core.model.Session) Entity(com.haulmont.cuba.core.entity.Entity) InputStream(java.io.InputStream) DsContextImplementation(com.haulmont.cuba.gui.data.impl.DsContextImplementation) Formatter(com.haulmont.cuba.gui.components.Formatter) Range(com.haulmont.chile.core.model.Range) MetaProperty(com.haulmont.chile.core.model.MetaProperty) SimpleDateFormat(java.text.SimpleDateFormat)

Example 82 with MetaClass

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);
            }
        }
    }
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 83 with MetaClass

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);
        }
    }
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 84 with MetaClass

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;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) MetaClass(com.haulmont.chile.core.model.MetaClass)

Example 85 with MetaClass

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);
}
Also used : java.util(java.util) WindowManager(com.haulmont.cuba.gui.WindowManager) ParamsMap(com.haulmont.bali.util.ParamsMap) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) DynamicAttributesUtils(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesUtils) AppBeans(com.haulmont.cuba.core.global.AppBeans) MetaClass(com.haulmont.chile.core.model.MetaClass) EntityInspectorBrowse(com.haulmont.cuba.gui.app.core.entityinspector.EntityInspectorBrowse) Metadata(com.haulmont.cuba.core.global.Metadata) BooleanUtils(org.apache.commons.lang.BooleanUtils) Inject(javax.inject.Inject) DateUtils(org.apache.commons.lang.time.DateUtils) HasUuid(com.haulmont.cuba.core.entity.HasUuid) ComponentsFactory(com.haulmont.cuba.gui.xml.layout.ComponentsFactory) CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) Named(javax.inject.Named) DynamicAttributes(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) EntityLogService(com.haulmont.cuba.core.app.EntityLogService) Range(com.haulmont.chile.core.model.Range) MetaProperty(com.haulmont.chile.core.model.MetaProperty) com.haulmont.cuba.security.entity(com.haulmont.cuba.security.entity) WindowParams(com.haulmont.cuba.gui.WindowParams) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) TimeSource(com.haulmont.cuba.core.global.TimeSource) ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Entity(com.haulmont.cuba.core.entity.Entity) ReferenceToEntitySupport(com.haulmont.cuba.core.global.ReferenceToEntitySupport) MetaClass(com.haulmont.chile.core.model.MetaClass)

Aggregations

MetaClass (com.haulmont.chile.core.model.MetaClass)302 MetaProperty (com.haulmont.chile.core.model.MetaProperty)103 Entity (com.haulmont.cuba.core.entity.Entity)54 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)36 Nullable (javax.annotation.Nullable)25 BaseGenericIdEntity (com.haulmont.cuba.core.entity.BaseGenericIdEntity)24 Element (org.dom4j.Element)21 java.util (java.util)18 Inject (javax.inject.Inject)17 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)16 Test (org.junit.Test)15 EntityManager (com.haulmont.cuba.core.EntityManager)14 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)14 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)13 Metadata (com.haulmont.cuba.core.global.Metadata)13 Logger (org.slf4j.Logger)13 LoggerFactory (org.slf4j.LoggerFactory)13 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)12 Collectors (java.util.stream.Collectors)11 Range (com.haulmont.chile.core.model.Range)10