Search in sources :

Example 11 with RemoveAction

use of com.haulmont.cuba.gui.components.actions.RemoveAction in project cuba by cuba-platform.

the class UiPermissionsFrame method init.

@Override
public void init(Map<String, Object> params) {
    super.init(params);
    WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
    Collection<WindowInfo> windows = sortWindowInfos(windowConfig.getWindows());
    Map<String, Object> screens = new LinkedHashMap<>();
    for (WindowInfo windowInfo : windows) {
        String id = windowInfo.getId();
        String menuId = "menu-config." + id;
        String localeMsg = messages.getMessage(AppConfig.getMessagesPack(), menuId);
        String title = menuId.equals(localeMsg) ? id : localeMsg + " (" + id + ")";
        screens.put(title, id);
    }
    screenFilter.setOptionsMap(screens);
    companion.initPermissionsColoredColumns(uiPermissionsTable);
    uiPermissionTargetsDs.addItemChangeListener(e -> {
        if (!selectedComponentPanel.isVisible() && (e.getItem() != null)) {
            selectedComponentPanel.setVisible(true);
        }
        if (selectedComponentPanel.isVisible() && (e.getItem() == null)) {
            selectedComponentPanel.setVisible(false);
        }
        updateCheckBoxes(e.getItem());
    });
    uiPermissionTargetsDs.addItemPropertyChangeListener(e -> {
        if ("permissionVariant".equals(e.getProperty())) {
            updateCheckBoxes(uiPermissionsTable.getSingleSelected());
        }
    });
    attachCheckBoxListener(readOnlyCheckBox, UiPermissionVariant.READ_ONLY);
    attachCheckBoxListener(hideCheckBox, UiPermissionVariant.HIDE);
    attachCheckBoxListener(showCheckBox, UiPermissionVariant.SHOW);
    uiPermissionTargetsDs.setPermissionDs(uiPermissionsDs);
    uiPermissionsDs.refresh();
    uiPermissionTargetsDs.refresh();
    boolean isCreatePermitted = security.isEntityOpPermitted(Permission.class, EntityOp.CREATE);
    boolean isDeletePermitted = security.isEntityOpPermitted(Permission.class, EntityOp.DELETE);
    boolean isRoleEditPermitted = security.isEntityOpPermitted(metadata.getClass(Role.class), EntityOp.UPDATE);
    final boolean hasPermissionsToModifyPermission = isCreatePermitted && isDeletePermitted && isRoleEditPermitted;
    RemoveAction removeAction = new RemoveAction(uiPermissionsTable, false);
    removeAction.setAfterRemoveHandler(removedItems -> {
        if (!removedItems.isEmpty()) {
            UiPermissionTarget removedPermission = (UiPermissionTarget) removedItems.iterator().next();
            markItemPermission(UiPermissionVariant.NOTSET, removedPermission);
        }
    });
    removeAction.setEnabled(hasPermissionsToModifyPermission);
    removeAction.setIcon(null);
    removeAction.setCaption(getMessage("actions.RemoveSelected"));
    removePermissionBtn.setAction(removeAction);
    uiPermissionsTable.addAction(removeAction);
    editPane.setEnabled(security.isEntityOpPermitted(Role.class, EntityOp.UPDATE));
    applyPermissions(hasPermissionsToModifyPermission);
}
Also used : WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) Role(com.haulmont.cuba.security.entity.Role) RemoveAction(com.haulmont.cuba.gui.components.actions.RemoveAction) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo) UiPermissionTarget(com.haulmont.cuba.gui.app.security.entity.UiPermissionTarget)

Example 12 with RemoveAction

use of com.haulmont.cuba.gui.components.actions.RemoveAction in project cuba by cuba-platform.

the class UserLookup method init.

@Override
public void init(Map<String, Object> params) {
    if (WindowParams.MULTI_SELECT.getBool(getContext())) {
        usersTable.setMultiSelect(true);
    }
    RemoveAction removeAction = new UserRemoveAction(usersTable, userManagementService);
    usersTable.addAction(removeAction);
}
Also used : RemoveAction(com.haulmont.cuba.gui.components.actions.RemoveAction)

Example 13 with RemoveAction

use of com.haulmont.cuba.gui.components.actions.RemoveAction in project cuba by cuba-platform.

the class FileFrameController method init.

@Override
public void init(Map<String, Object> params) {
    super.init(params);
    uploadField = (FileUploadField) getComponent("uploadField");
    filesTable = (Table) getComponent("files");
    initGeneratedColumn();
    ds = (CollectionDatasource) getDsContext().get("filesDs");
    Button remove = (Button) getComponentNN("remove");
    remove.setAction(new RemoveAction(filesTable, false));
    uploadField.addFileUploadSucceedListener(e -> {
        fd = metadata.create(FileDescriptor.class);
        fd.setName(uploadField.getFileName());
        fd.setExtension(FilenameUtils.getExtension(uploadField.getFileName()));
        FileUploadingAPI fileUploading = AppBeans.get(FileUploadingAPI.NAME);
        File file = fileUploading.getFile(uploadField.getFileId());
        fd.setSize(file.length());
        fd.setCreateDate(AppBeans.get(TimeSource.class).currentTimestamp());
        saveFile();
        ds.addItem(fd);
        showNotification(getMessage("uploadSuccess"), NotificationType.HUMANIZED);
    });
    uploadField.addFileUploadErrorListener(e -> showNotification(getMessage("uploadUnsuccess"), NotificationType.HUMANIZED));
}
Also used : FileUploadingAPI(com.haulmont.cuba.gui.upload.FileUploadingAPI) RemoveAction(com.haulmont.cuba.gui.components.actions.RemoveAction) File(java.io.File) FileDescriptor(com.haulmont.cuba.core.entity.FileDescriptor)

Aggregations

RemoveAction (com.haulmont.cuba.gui.components.actions.RemoveAction)13 MetaClass (com.haulmont.chile.core.model.MetaClass)4 EditAction (com.haulmont.cuba.gui.components.actions.EditAction)3 ItemTrackingAction (com.haulmont.cuba.gui.components.actions.ItemTrackingAction)3 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)3 Entity (com.haulmont.cuba.core.entity.Entity)2 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)2 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)2 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)2 CreateAction (com.haulmont.cuba.gui.components.actions.CreateAction)2 FileUploadingAPI (com.haulmont.cuba.gui.upload.FileUploadingAPI)2 ComponentsFactory (com.haulmont.cuba.gui.xml.layout.ComponentsFactory)2 File (java.io.File)2 java.util (java.util)2 Files (com.google.common.io.Files)1 ParamsMap (com.haulmont.bali.util.ParamsMap)1 ClientCacheManager (com.haulmont.cuba.client.sys.cache.ClientCacheManager)1 DynamicAttributesCacheStrategy (com.haulmont.cuba.client.sys.cache.DynamicAttributesCacheStrategy)1 ConstraintLocalizationService (com.haulmont.cuba.core.app.ConstraintLocalizationService)1 LockService (com.haulmont.cuba.core.app.LockService)1