@SuppressWarnings("unchecked") @Override public void actionPerform(Component component) { // if standard behaviour if (!hasSubscriptions(ActionPerformedEvent.class)) { Screen lookupScreen = screenBuilders.lookup(target) .build(); lookupScreen.show(); } else { super.actionPerform(component); } } }
/** * Set action performed event handler using fluent API method. Can be used instead of subclassing BaseAction class. * * @param handler action performed handler * @return current instance of action */ public ListAction withHandler(Consumer<ActionPerformedEvent> handler) { getEventHub().subscribe(ActionPerformedEvent.class, handler); return this; }
@Override protected boolean isApplicable() { return target != null && target.getSingleSelected() != null && super.isApplicable(); }
protected void initMoveButtons() { Action moveUpAction = new ItemTrackingAction("moveUp") .withCaption("") .withHandler(event -> { Set<CategoryAttribute> selected = categoryAttrsTable.getSelected(); if (selected.isEmpty()) .withHandler(event -> { Set<CategoryAttribute> selected = categoryAttrsTable.getSelected(); if (selected.isEmpty())
protected void initUsersTableActions() { userCreateAction = new GroupPropertyCreateAction(usersTable); userCreateAction.setAfterCommitHandler(entity -> usersTable.getDatasource().refresh() ); usersTable.addAction(userCreateAction); usersTable.addAction(new UserRemoveAction(usersTable, userManagementService)); Action moveToGroupAction = new ItemTrackingAction("moveToGroup") .withIcon("icons/move.png") .withCaption(getMessage("moveToGroup")) .withHandler(event -> { Set<User> selected = usersTable.getSelected(); if (!selected.isEmpty()) { moveUsersToGroup(selected); } }); moveToGroupAction.setEnabled(security.isEntityOpPermitted(User.class, EntityOp.UPDATE)); usersTable.addAction(moveToGroupAction); }
Action restoreAction = new ItemTrackingAction("restore") .withCaption(getMessage("entityRestore.restore")) .withPrimary(true) .withHandler(event -> showRestoreDialog() );
.withIcon("icons/move.png") .withHandler(e -> moveConstraintToGroup(constraintsTable.getSingleSelected()) );
@Override protected boolean isPermitted() { if (target == null) { return false; } Entity singleSelected = target.getSingleSelected(); if (singleSelected == null) { return false; } if (constraintOperationType != null) { boolean isPermitted; if (constraintCode != null) { isPermitted = security.isPermitted(singleSelected, constraintCode); } else { isPermitted = security.isPermitted(singleSelected, constraintOperationType); } if (!isPermitted) { return false; } } return super.isPermitted(); }
@Override public boolean isEnabled() { return super.isEnabled() && isUpdatePermitted(); } });
.withHandler(event -> { userManagementService.copyRole(rolesTable.getSingleSelected().getId()); rolesDs.refresh(); .withHandler(event -> { Set<Role> selected = rolesTable.getSelected(); if (selected.isEmpty()) {
@Override protected boolean isPermitted() { if (target == null) { return false; } Entity singleSelected = target.getSingleSelected(); if (singleSelected == null) { return false; } if (constraintOperationType != null) { boolean isPermitted; if (constraintCode != null) { isPermitted = security.isPermitted(singleSelected, constraintCode); } else { isPermitted = security.isPermitted(singleSelected, constraintOperationType); } if (!isPermitted) { return false; } } return super.isPermitted(); }
.withHandler(event -> { FileDescriptor fileDescriptor = filesTable.getSingleSelected(); if (fileDescriptor != null) {
@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) { if (!hasSubscriptions(ActionPerformedEvent.class)) { if (!(target.getItems() instanceof ContainerDataUnit)) { throw new IllegalStateException("RefreshAction target is null or does not implement SupportsContainerBinding"); } CollectionContainer container = ((ContainerDataUnit) target.getItems()).getContainer(); if (container == null) { throw new IllegalStateException("RefreshAction target is not bound to CollectionContainer"); } DataLoader loader = null; if (container instanceof HasLoader) { loader = ((HasLoader) container).getLoader(); } if (loader != null) { loader.load(); } else { log.warn("RefreshAction '{}' target container has no loader, refresh is impossible", getId()); } } else { super.actionPerform(component); } } }
.withHandler(event -> { Report report = reportsTable.getSingleSelected(); if (report != null) { .withHandler(event -> { Report report = reportsTable.getSingleSelected(); if (report != null) {
@Override protected boolean isPermitted() { if (target == null || target.getDatasource() == null) { return false; } CollectionDatasource ownerDs = target.getDatasource(); if (ownerDs instanceof PropertyDatasource) { PropertyDatasource datasource = (PropertyDatasource) ownerDs; MetaClass parentMetaClass = datasource.getMaster().getMetaClass(); MetaProperty metaProperty = datasource.getProperty(); boolean attrPermitted = security.isEntityAttrPermitted(parentMetaClass, metaProperty.getName(), EntityAttrAccess.MODIFY); if (!attrPermitted) { 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); } } }
.withHandler(event -> { Set<ManagedBeanInfo> selected = mbeansTable.getSelected(); if (!selected.isEmpty()) {
/** * Check permissions for Action */ @Override protected boolean isPermitted() { if (target == null || target.getDatasource() == null) { return false; } CollectionDatasource ownerDatasource = target.getDatasource(); MetaClass metaClass = ownerDatasource.getMetaClass(); boolean createPermitted = security.isEntityOpPermitted(metaClass, EntityOp.CREATE); if (!createPermitted) { return false; } if (ownerDatasource instanceof PropertyDatasource) { PropertyDatasource propertyDatasource = (PropertyDatasource) ownerDatasource; MetaClass parentMetaClass = propertyDatasource.getMaster().getMetaClass(); MetaProperty metaProperty = propertyDatasource.getProperty(); boolean attrPermitted = security.isEntityAttrPermitted(parentMetaClass, metaProperty.getName(), EntityAttrAccess.MODIFY); if (!attrPermitted) { return false; } } return super.isPermitted(); }
super.actionPerform(component);