Search in sources :

Example 71 with Entity

use of com.haulmont.cuba.core.entity.Entity in project cuba by cuba-platform.

the class DesktopTableCellEditor method getCellComponent.

protected Component getCellComponent(int row) {
    Entity item = desktopAbstractTable.getTableModel().getItem(row);
    StopWatch sw = new Slf4JStopWatch("TableColumnGenerator." + desktopAbstractTable.getId());
    @SuppressWarnings("unchecked") com.haulmont.cuba.gui.components.Component component = columnGenerator.generateCell(item);
    sw.stop();
    Component comp;
    if (component == null) {
        comp = new JLabel("");
    } else if (component instanceof Table.PlainTextCell) {
        comp = new JLabel(((Table.PlainTextCell) component).getText());
    } else {
        if (component instanceof BelongToFrame) {
            BelongToFrame belongToFrame = (BelongToFrame) component;
            if (belongToFrame.getFrame() == null) {
                belongToFrame.setFrame(desktopAbstractTable.getFrame());
            }
        }
        component.setParent(desktopAbstractTable);
        JComponent jComposition = DesktopComponentsHelper.getComposition(component);
        jComposition.putClientProperty(CELL_EDITOR_TABLE, desktopAbstractTable.getComponent());
        jComposition.putClientProperty(CELL_COMPONENT, component);
        comp = jComposition;
    }
    cache.put(row, comp);
    return comp;
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) Table(com.haulmont.cuba.gui.components.Table) BelongToFrame(com.haulmont.cuba.gui.components.Component.BelongToFrame) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch)

Example 72 with Entity

use of com.haulmont.cuba.core.entity.Entity in project cuba by cuba-platform.

the class DesktopTokenList method setLookup.

@Override
public void setLookup(boolean lookup) {
    if (this.lookup != lookup) {
        if (lookup) {
            lookupAction = new PickerField.LookupAction(lookupPickerField) {

                @Nonnull
                @Override
                protected Map<String, Object> prepareScreenParams() {
                    Map<String, Object> screenParams = super.prepareScreenParams();
                    if (isMultiSelect()) {
                        screenParams = new HashMap<>(screenParams);
                        WindowParams.MULTI_SELECT.set(screenParams, true);
                        // for backward compatibility
                        screenParams.put("multiSelect", "true");
                    }
                    return screenParams;
                }

                @SuppressWarnings("unchecked")
                @Override
                protected void handleLookupWindowSelection(Collection items) {
                    if (items.isEmpty()) {
                        return;
                    }
                    @SuppressWarnings("unchecked") Collection<Entity> selected = items;
                    CollectionDatasource optionsDatasource = lookupPickerField.getOptionsDatasource();
                    if (optionsDatasource != null && lookupPickerField.isRefreshOptionsOnLookupClose()) {
                        optionsDatasource.refresh();
                        if (datasource != null) {
                            for (Object obj : getDatasource().getItems()) {
                                Entity entity = (Entity) obj;
                                if (getOptionsDatasource().containsItem(entity.getId())) {
                                    datasource.updateItem(getOptionsDatasource().getItem(entity.getId()));
                                }
                            }
                        }
                    }
                    // add all selected items to tokens
                    if (itemChangeHandler != null) {
                        for (Entity newItem : selected) {
                            itemChangeHandler.addItem(newItem);
                        }
                    } else if (datasource != null) {
                        // get master entity and inverse attribute in case of nested datasource
                        Entity masterEntity = getMasterEntity(datasource);
                        MetaProperty inverseProp = getInverseProperty(datasource);
                        for (Entity newItem : selected) {
                            if (!datasource.containsItem(newItem.getId())) {
                                // Initialize reference to master entity
                                if (inverseProp != null && isInitializeMasterReference(inverseProp)) {
                                    newItem.setValue(inverseProp.getName(), masterEntity);
                                }
                                datasource.addItem(newItem);
                            }
                        }
                    }
                    afterSelect(items);
                    if (afterLookupSelectionHandler != null) {
                        afterLookupSelectionHandler.onSelect(items);
                    }
                }
            };
            lookupPickerField.addAction(lookupAction);
            if (getLookupScreen() != null) {
                lookupAction.setLookupScreen(getLookupScreen());
            }
            lookupAction.setLookupScreenOpenType(lookupOpenMode);
            lookupAction.setLookupScreenParams(lookupScreenParams);
            lookupAction.setLookupScreenDialogParams(lookupScreenDialogParams);
        } else {
            lookupPickerField.removeAction(lookupAction);
        }
        lookupAction.setAfterLookupCloseHandler((window, actionId) -> {
            if (afterLookupCloseHandler != null) {
                afterLookupCloseHandler.onClose(window, actionId);
            }
        });
        lookupAction.setAfterLookupSelectionHandler(items -> {
            if (afterLookupSelectionHandler != null) {
                afterLookupSelectionHandler.onSelect(items);
            }
        });
    }
    this.lookup = lookup;
    rootPanel.refreshComponent();
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) Nonnull(javax.annotation.Nonnull) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 73 with Entity

use of com.haulmont.cuba.core.entity.Entity in project cuba by cuba-platform.

the class DesktopTree method setSelected.

@Override
public void setSelected(Collection<E> items) {
    TreePath[] paths = new TreePath[items.size()];
    int i = 0;
    for (Entity item : items) {
        paths[i] = model.getTreePath(item);
    }
    impl.setSelectionPaths(paths);
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) TreePath(javax.swing.tree.TreePath)

Example 74 with Entity

use of com.haulmont.cuba.core.entity.Entity in project cuba by cuba-platform.

the class DesktopTree method getSelected.

@SuppressWarnings("unchecked")
@Override
public Set<E> getSelected() {
    Set<E> selected = new HashSet<>();
    TreePath[] selectionPaths = impl.getSelectionPaths();
    if (selectionPaths != null) {
        for (TreePath selectionPath : selectionPaths) {
            Entity entity = model.getEntity(selectionPath.getLastPathComponent());
            if (entity != null) {
                selected.add((E) entity);
            }
        }
    }
    return selected;
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) TreePath(javax.swing.tree.TreePath)

Example 75 with Entity

use of com.haulmont.cuba.core.entity.Entity in project cuba by cuba-platform.

the class DesktopTreeTable method getSelected.

@SuppressWarnings("unchecked")
@Override
public Set<E> getSelected() {
    Set<E> selected = new HashSet<>();
    TreePath[] selectionPaths = impl.getTreeSelectionModel().getSelectionPaths();
    if (selectionPaths != null) {
        for (TreePath path : selectionPaths) {
            Entity entity = ((TreeTableModelAdapter) tableModel).getEntity(path.getLastPathComponent());
            if (entity != null)
                selected.add((E) entity);
        }
    }
    return selected;
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) TreePath(javax.swing.tree.TreePath) TreeTableModelAdapter(com.haulmont.cuba.desktop.gui.data.TreeTableModelAdapter)

Aggregations

Entity (com.haulmont.cuba.core.entity.Entity)203 MetaClass (com.haulmont.chile.core.model.MetaClass)51 MetaProperty (com.haulmont.chile.core.model.MetaProperty)44 BaseGenericIdEntity (com.haulmont.cuba.core.entity.BaseGenericIdEntity)40 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)18 Test (org.junit.Test)15 Inject (javax.inject.Inject)14 java.util (java.util)12 EntityManager (com.haulmont.cuba.core.EntityManager)11 ParseException (java.text.ParseException)11 Element (org.dom4j.Element)11 Logger (org.slf4j.Logger)11 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)10 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)9 LoggerFactory (org.slf4j.LoggerFactory)9 Query (com.haulmont.cuba.core.Query)8 Server (com.haulmont.cuba.core.entity.Server)8 Transaction (com.haulmont.cuba.core.Transaction)7 Datasource (com.haulmont.cuba.gui.data.Datasource)7 Collectors (java.util.stream.Collectors)7