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;
}
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();
}
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);
}
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;
}
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;
}
Aggregations