private MetaClass getMetaClass(ListComponent listComponent) { if (!(listComponent.getItems() instanceof EntityDataUnit)) { throw new IllegalStateException("ListComponent items is null or does not implement EntityDataUnit"); } MetaClass metaClass = ((EntityDataUnit) listComponent.getItems()).getEntityMetaClass(); if (metaClass == null) { throw new IllegalStateException("ListComponent is not bound to entity"); } return metaClass; }
@Override protected boolean isPermitted() { if (target == null || !(target.getItems() instanceof EntityDataUnit)) { return false; } MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass(); if (metaClass == null) { return true; } boolean createPermitted = security.isEntityOpPermitted(metaClass, EntityOp.CREATE); if (!createPermitted) { return false; } return super.isPermitted(); }
@Override public void actionPerform(Component component) { Set<Entity> ownerSelection = target.getSelected(); if (!ownerSelection.isEmpty()) { String entityType; if (target.getItems() instanceof EntityDataUnit) { MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass(); entityType = metaClass.getName(); } else { throw new UnsupportedOperationException("Unsupported data unit " + target.getItems()); } String[] strings = ValuePathHelper.parse(ComponentsHelper.getFilterComponentPath(filter)); String componentId = ValuePathHelper.format(Arrays.copyOfRange(strings, 1, strings.length)); Map<String, Object> params = new HashMap<>(); params.put("entityType", entityType); params.put("items", ownerSelection); params.put("componentPath", ComponentsHelper.getFilterComponentPath(filter)); params.put("componentId", componentId); params.put("foldersPane", filterHelper.getFoldersPane()); params.put("entityClass", adapter.getMetaClass().getJavaClass().getName()); params.put("query", adapter.getQuery()); WindowManager wm = (WindowManager) ComponentsHelper.getScreenContext(filter).getScreens(); WindowInfo windowInfo = windowConfig.getWindowInfo("saveSetInFolder"); wm.openWindow(windowInfo, OpenType.DIALOG, params); } } }
@Override protected boolean isPermitted() { if (target == null || !(target.getItems() instanceof EntityDataUnit)) { return false; } MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass(); if (metaClass == null) { return true; } boolean permitted = security.isScreenPermitted(BulkEditor.PERMISSION); if (!permitted) { return false; } return super.isPermitted(); }
@Override protected boolean isPermitted() { if (target == null ||!(target.getItems() instanceof EntityDataUnit)) { return false; } MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass(); if (metaClass == null) { return true; } boolean entityOpPermitted = security.isEntityOpPermitted(metaClass, EntityOp.READ); if (!entityOpPermitted) { return false; } return super.isPermitted(); }
@SuppressWarnings("unchecked") @Override public void actionPerform(Component component) { // if standard behaviour if (!hasSubscriptions(ActionPerformedEvent.class)) { if (!(target.getItems() instanceof EntityDataUnit)) { throw new IllegalStateException("CreateAction target items is null or does not implement EntityDataUnit"); } MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass(); if (metaClass == null) { throw new IllegalStateException("Target is not bound to entity"); } Screen editor = screenBuilders.editor(target) .newEntity() .build(); editor.show(); } else { super.actionPerform(component); } } }
@SuppressWarnings("unchecked") @Override public void actionPerform(Component component) { // if standard behaviour if (!hasSubscriptions(ActionPerformedEvent.class)) { if (!(target.getItems() instanceof EntityDataUnit)) { throw new IllegalStateException("EditAction target dataSource is null or does not implement EntityDataUnit"); } MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass(); if (metaClass == null) { throw new IllegalStateException("Target is not bound to entity"); } Entity editedEntity = target.getSingleSelected(); if (editedEntity == null) { throw new IllegalStateException("There is not selected item in EditAction target"); } Screen editor = screenBuilders.editor(target) .editEntity(editedEntity) .build(); editor.show(); } else { super.actionPerform(component); } } }
/** * Creates a screen builder using list component. * <p> * Example of building a lookup screen for adding row to table / tree component: * <pre>{@code * SomeCustomerListScreen screen = screenBuilders.lookup(customersTable) * .withScreen(SomeCustomerListScreen.class) * .build(); * }</pre> * * @param listComponent {@link Table}, {@link DataGrid} or another component containing the list of entities * @param <E> type of entity * @see #lookup(Class, FrameOwner) */ public <E extends Entity> LookupBuilder<E> lookup(ListComponent<E> listComponent) { checkNotNullArgument(listComponent); checkNotNullArgument(listComponent.getFrame()); FrameOwner frameOwner = listComponent.getFrame().getFrameOwner(); Class<E> entityClass; DataUnit items = listComponent.getItems(); if (items instanceof EntityDataUnit) { entityClass = ((EntityDataUnit) items).getEntityMetaClass().getJavaClass(); } else { throw new IllegalStateException(String.format("Component %s is not bound to data", listComponent)); } LookupBuilder<E> builder = new LookupBuilder<>(frameOwner, entityClass, lookupBuilderProcessor::buildLookup); builder.withListComponent(listComponent); return builder; }
DataUnit items = listComponent.getItems(); if (items instanceof EntityDataUnit) { entityClass = ((EntityDataUnit) items).getEntityMetaClass().getJavaClass(); } else { throw new IllegalStateException(String.format("Component %s is not bound to data", listComponent));
@Override public void refreshState() { super.refreshState(); if (!(target.getItems() instanceof EntityDataUnit)) { return; } if (!captionInitialized) { MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass(); if (metaClass != null) { if (security.isEntityOpPermitted(metaClass, EntityOp.UPDATE)) { setCaption(messages.getMainMessage("actions.Edit")); } else { setCaption(messages.getMainMessage("actions.View")); } } } }
MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass(); if (metaClass == null) { throw new IllegalStateException("Target is not bound to entity");