protected CollectionDatasource getCollectionDatasourceFromOwner() { if (owner != null && owner.getItems() != null) { return owner.getDatasource(); } return null; }
public OrderableItemMoveAction(String actionId, Direction direction, T listComponent, @Nullable String shortcut) { super(actionId, shortcut); if (!(OrderableEntity.class.isAssignableFrom(listComponent.getDatasource().getMetaClass().getJavaClass()))) { throw new UnsupportedOperationException("List component must contain datasource with entities type of OrderableEntity for ordering"); } this.direction = direction; this.listComponent = listComponent; }
/** * Iterate over items and set orderNum value from 1 to size()+1; */ protected void normalizeEntityOrderNum() { long normalizedIdx = 0; List<OrderableEntity> allItems = new ArrayList(listComponent.getDatasource().getItems()); for (OrderableEntity item : allItems) { item.setOrderNum(++normalizedIdx); //first must to be 1 } }
@Override protected boolean isApplicable() { if (target != null && target.getDatasource() != null && target.getSingleSelected() != null) { @SuppressWarnings("unchecked") HierarchicalDatasource<Group, UUID> ds = (HierarchicalDatasource<Group, UUID>) target.getDatasource(); UUID selectedItemId = (UUID) target.getSingleSelected().getId(); return ds.getChildren(selectedItemId).isEmpty(); } return false; } });
/** * Check permissions for Action */ @Override protected boolean isPermitted() { if (target == null || target.getDatasource() == null) { return false; } if (!checkRemovePermission()) { return false; } return super.isPermitted(); }
@Override public void actionPerform(Component component) { final Set selected = target.getSelected(); if (selected.size() == 1) { final CollectionDatasource datasource = target.getDatasource(); internalOpenEditor((Constraint) datasource.getItem()); } }
@Override public void refreshState() { if (target != null) { CollectionDatasource ds = target.getDatasource(); if (ds != null && !captionInitialized) { setCaption(messages.getMainMessage("actions.Edit")); } } super.refreshState(); }
/** * @return editor screen identifier */ public String getWindowId() { if (windowId != null) { return windowId; } else { MetaClass metaClass = target.getDatasource().getMetaClass(); WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME); return windowConfig.getEditorScreenId(metaClass); } }
/** * @return lookup screen id */ public String getWindowId() { if (windowId != null) { return windowId; } else { WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME); MetaClass metaClass = target.getDatasource().getMetaClass(); return windowConfig.getAvailableLookupScreenId(metaClass); } }
@Override protected boolean isPermitted() { CollectionDatasource ownerDatasource = target.getDatasource(); boolean entityOpPermitted = security.isEntityOpPermitted(ownerDatasource.getMetaClass(), EntityOp.UPDATE); if (!entityOpPermitted) { return false; } return super.isPermitted(); } });
/** * @return editor screen identifier */ public String getWindowId() { if (windowId != null) { return windowId; } else { MetaClass metaClass = target.getDatasource().getMetaClass(); WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME); return windowConfig.getEditorScreenId(metaClass); } }
protected void sortTableDsByItemsOrderNum() { if (listComponent.getDatasource() instanceof CollectionDatasource.Sortable) { CollectionDatasource.Sortable.SortInfo sortInfo = new CollectionDatasource.Sortable.SortInfo(); sortInfo.setOrder(CollectionDatasource.Sortable.Order.ASC); sortInfo.setPropertyPath(listComponent.getSingleSelected().getMetaClass().getPropertyPath("orderNum")); ((CollectionDatasource.Sortable) listComponent.getDatasource()).sort(new CollectionDatasource.Sortable.SortInfo[]{sortInfo}); } }
protected void doRemove(Set<Entity> selected, boolean autocommit) { CollectionDatasource datasource = target.getDatasource(); for (Entity item : selected) { datasource.removeItem(item); } if (autocommit && (datasource.getCommitMode() != Datasource.CommitMode.PARENT)) { try { datasource.commit(); } catch (RuntimeException e) { datasource.refresh(); throw e; } } }
@Override public void refreshState() { super.refreshState(); if (target == null || target.getDatasource() == null) return; if (!captionInitialized) { Messages messages = AppBeans.get(Messages.NAME); if (security.isEntityOpPermitted(target.getDatasource().getMetaClass(), EntityOp.UPDATE)) { setCaption(messages.getMainMessage("actions.Edit")); } else { setCaption(messages.getMainMessage("actions.View")); } } }
protected MetaClass getMetaClassForLocking(Entity item) { // lock original metaClass, if any, because by convention all the configuration is based on original entities MetaClass metaClass = AppBeans.get(ExtendedEntities.class).getOriginalMetaClass(item.getMetaClass()); if (metaClass == null) { metaClass = getTable().getDatasource().getMetaClass(); } return metaClass; }
@Override protected void doRemove(Set<Entity> selected, boolean autocommit) { CollectionDatasource<ProcModel, UUID> datasource = target.getDatasource(); datasource.refresh(); for (Entity entity : selected) { Entity reloadedEntity = datasource.getItem((UUID) entity.getId()); if (reloadedEntity != null) { datasource.removeItem((ProcModel) reloadedEntity); } } datasource.commit(); } };
protected boolean isDataAvailable() { if (listComponent.getItems() instanceof ContainerDataUnit) { ContainerDataUnit unit = (ContainerDataUnit) listComponent.getItems(); CollectionContainer container = unit.getContainer(); return container instanceof HasLoader && unit.getState() == BindingState.ACTIVE && !container.getItems().isEmpty(); } else { CollectionDatasource ds = listComponent.getDatasource(); if (ds != null) return ds.getState() == Datasource.State.VALID && ds.size() > 0; } return false; }
@Override protected boolean checkRemovePermission() { CollectionDatasource ds = target.getDatasource(); if (ds instanceof PropertyDatasource) { PropertyDatasource propertyDatasource = (PropertyDatasource) ds; MetaClass parentMetaClass = propertyDatasource.getMaster().getMetaClass(); MetaProperty metaProperty = propertyDatasource.getProperty(); boolean attrPermitted = security.isEntityAttrPermitted(parentMetaClass, metaProperty.getName(), EntityAttrAccess.MODIFY); if (!attrPermitted) { return false; } } return true; }
@Override public void init(Map<String, Object> params) { lookupFrame = openWindow(lookupWindowId, WindowManager.OpenType.DIALOG, widgetRepository.getWidgetParams(widget)); for (ListComponent c : findListComponents(lookupFrame)) { c.getDatasource().addItemChangeListener(e -> events.publish(new ItemsSelectedEvent(widget, c.getSelected()))); } lookupFrame.close(Window.CLOSE_ACTION_ID, true); lookupFrame.setSizeFull(); scroll.add(lookupFrame.getFrame()); }
protected void showPivotTable(ShowPivotMode mode) { ParamsMap paramsMap = ParamsMap.of(); if (mode == ALL_ROWS) { paramsMap.pair("dataItems", convertEntitiesToDataItems(target.getDatasource().getItems())); } else { paramsMap.pair("dataItems", convertEntitiesToDataItems(target.getSelected())); } paramsMap.pair("properties", getPropertiesWithLocale()); paramsMap.pair("nativeJson", nativeJson); WindowManager wm = target.getFrame().getWindowManager(); WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME); wm.openWindow(windowConfig.getWindowInfo(SCREEN_ID), WindowManager.OpenType.NEW_TAB, paramsMap.create()); }