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; }
@Override public void actionPerform(Component component) { final Set selected = target.getSelected(); if (selected.size() == 1) { final CollectionDatasource datasource = target.getDatasource(); internalOpenEditor((Constraint) datasource.getItem()); } }
/** * This method is invoked by the action owner component. * * @param component component invoking the action */ @Override public void actionPerform(Component component) { final Set<Entity> selected = target.getSelected(); target.getFrame().openWindow("admintools$generateScriptsDialog", WindowManager.OpenType.DIALOG, ParamsMap.of("selectedEntities", selected) ); }
protected CollectionDatasource getCollectionDatasourceFromOwner() { if (owner != null && owner.getItems() != null) { return owner.getDatasource(); } return null; }
@SuppressWarnings("unchecked") protected <T> T getValue(Component component) { if (component instanceof HasValue) { return (T) ((HasValue) component).getValue(); } else if (component instanceof ListComponent) { ListComponent list = (ListComponent) component; //noinspection unchecked return list.isMultiSelect() ? (T)list.getSelected() : (T)list.getSingleSelected(); } else { return null; } }
@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; } });
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()); }
@Override protected boolean isApplicable() { return target != null && target.getSingleSelected() != null; }
@Override protected boolean isApplicable() { return target != null && !target.getSelected().isEmpty(); }
@Override protected boolean isPermitted() { if (getTarget().getSingleSelected() instanceof SoftDelete) { for (Object e : getTarget().getSelected()) { if (((SoftDelete) e).isDeleted()) return false; } } return super.isPermitted(); } };
protected boolean needExportAll() { if (target.getSelected().isEmpty()) { return true; } CollectionContainer container = ((ContainerDataUnit) target.getItems()).getContainer(); return container != null && container.getItems().size() <= 1; }
/** * Adds an EditAction that enables controls for editing. */ protected void initBrowseEditAction() { ListComponent<T> table = getTable(); EditAction editAction = (EditAction) table.getActionNN("edit"); editAction.withHandler(actionPerformedEvent -> { if (table.getSelected().size() == 1) { if (lockIfNeeded(table.getSingleSelected())) { refreshOptionsForLookupFields(); enableEditControls(false); } } }); editAction.addEnabledRule(() -> table.getSelected().size() == 1 && getBeanLocator().get(Security.class).isEntityOpPermitted(getEntityClass(), EntityOp.UPDATE)); }
checkNotNullArgument(listComponent.getFrame()); FrameOwner frameOwner = listComponent.getFrame().getFrameOwner(); Class<E> entityClass; DataUnit items = listComponent.getItems(); if (items instanceof EntityDataUnit) { entityClass = ((EntityDataUnit) items).getEntityMetaClass().getJavaClass(); builder.editEntity(listComponent.getSingleSelected()); return builder;
if (!(target.getItems() instanceof EntityDataUnit)) { throw new IllegalStateException("BulkEditAction 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"); Notifications notifications = getScreenContext(target.getFrame()).getNotifications(); notifications.create(NotificationType.ERROR) .withCaption(messages.getMainMessage("accessDenied.message")) if (target.getSelected().isEmpty()) { Notifications notifications = getScreenContext(target.getFrame()).getNotifications(); notifications.create(NotificationType.ERROR) .withCaption(messages.getMainMessage("actions.BulkEdit.emptySelection")) bulkEditors.builder(metaClass, target.getSelected(), window.getFrameOwner()) .withListComponent(target) .create()
protected void confirmAndRemove(Set<Entity> selected) { Dialogs dialogs = ComponentsHelper.getScreenContext(target.getFrame()).getDialogs(); dialogs.createOptionDialog() .withCaption(getConfirmationTitle()) .withMessage(getConfirmationMessage()) .withActions( new DialogAction(Type.OK, Status.PRIMARY).withHandler(event -> { try { remove(selected); } finally { if (target instanceof Component.Focusable) { ((Component.Focusable) target).focus(); } Set<Entity> filtered = new HashSet<>(selected); filtered.retainAll(target.getDatasource().getItems()); //noinspection unchecked target.setSelected(filtered); } }), new DialogAction(Type.CANCEL).withHandler(event -> { // move focus to owner if (target instanceof Component.Focusable) { ((Component.Focusable) target).focus(); } })) .show(); }
@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 remove builder using list component, e.g. {@link Table} or {@link DataGrid}. * * @param listComponent list component * @param <E> type of entity */ public <E extends Entity> RemoveBuilder<E> builder(ListComponent<E> listComponent) { checkNotNullArgument(listComponent); checkNotNullArgument(listComponent.getFrame()); FrameOwner frameOwner = listComponent.getFrame().getFrameOwner(); Class<E> entityClass; DataUnit items = listComponent.getItems(); if (items instanceof ContainerDataUnit) { entityClass = ((ContainerDataUnit) items).getEntityMetaClass().getJavaClass(); } else { throw new IllegalStateException(String.format("Component %s is not bound to data", listComponent)); } return builder(entityClass, frameOwner) .withListComponent(listComponent); }
/** * The simplest constructor. The action uses default name and other parameters. * * @param listComponent listComponent containing this action */ public ExcelAction(ListComponent listComponent) { this(listComponent, AppConfig.createExportDisplay(listComponent.getFrame()), ACTION_ID); }
@SuppressWarnings("unchecked") protected void internalOpenEditor(CollectionDatasource datasource, Entity newItem, Datasource parentDs, Map<String, Object> params) { LegacyFrame frameOwner = (LegacyFrame) target.getFrame().getFrameOwner(); AbstractEditor window = frameOwner.openEditor(getWindowId(), newItem, getOpenType(), params, parentDs); datasource.includeItem(editedItem); target.setSelected(editedItem); afterCommit(editedItem); if (afterCommitHandler != null) {