Search in sources :

Example 6 with AppFolder

use of com.haulmont.cuba.core.entity.AppFolder in project cuba by cuba-platform.

the class AppFolderEditWindow method commit.

@Override
protected void commit() {
    AppFolder folder = (AppFolder) AppFolderEditWindow.this.folder;
    if (StringUtils.trimToNull(nameField.getValue()) == null) {
        String msg = messages.getMessage(messagesPack, "folders.folderEditWindow.emptyName");
        App.getInstance().getWindowManager().showNotification(msg, Frame.NotificationType.TRAY);
        return;
    }
    folder.setName(nameField.getValue());
    folder.setTabName(tabNameField.getValue());
    if (sortOrderField.getValue() == null || "".equals(sortOrderField.getValue())) {
        folder.setSortOrder(null);
    } else {
        Object value = sortOrderField.getValue();
        int sortOrder;
        try {
            sortOrder = Integer.parseInt((String) value);
        } catch (NumberFormatException e) {
            String msg = messages.getMessage(messagesPack, "folders.folderEditWindow.invalidSortOrder");
            App.getInstance().getWindowManager().showNotification(msg, Frame.NotificationType.TRAY);
            return;
        }
        folder.setSortOrder(sortOrder);
    }
    Object parent = parentSelect.getValue();
    if (parent instanceof Folder) {
        folder.setParent((Folder) parent);
    } else {
        folder.setParent(null);
    }
    if (visibilityScriptField != null) {
        String scriptText = visibilityScriptField.getValue();
        folder.setVisibilityScript(scriptText);
    }
    if (quantityScriptField != null) {
        String scriptText = quantityScriptField.getValue();
        folder.setQuantityScript(scriptText);
    }
    folder.setApplyDefault(Boolean.valueOf(applyDefaultCb.getValue().toString()));
    AppFolderEditWindow.this.commitHandler.run();
    close();
}
Also used : AppFolder(com.haulmont.cuba.core.entity.AppFolder) AppFolder(com.haulmont.cuba.core.entity.AppFolder) Folder(com.haulmont.cuba.core.entity.Folder)

Example 7 with AppFolder

use of com.haulmont.cuba.core.entity.AppFolder in project cuba by cuba-platform.

the class AppFolderEditWindow method fillParentSelect.

@Override
protected void fillParentSelect() {
    parentSelect.removeAllItems();
    String root = getMessage("folders.appFoldersRoot");
    parentSelect.addItem(root);
    parentSelect.setNullSelectionItemId(root);
    FoldersService service = AppBeans.get(FoldersService.NAME);
    List<AppFolder> list = service.loadAppFolders();
    for (AppFolder folder : list) {
        if (!folder.equals(this.folder)) {
            parentSelect.addItem(folder);
            parentSelect.setItemCaption(folder, getMessage(folder.getName()));
        }
    }
}
Also used : AppFolder(com.haulmont.cuba.core.entity.AppFolder) FoldersService(com.haulmont.cuba.core.app.FoldersService)

Example 8 with AppFolder

use of com.haulmont.cuba.core.entity.AppFolder in project cuba by cuba-platform.

the class CubaFoldersPane method getChildFolders.

protected Collection<AppFolder> getChildFolders(AppFolder parentFolder) {
    Collection<AppFolder> result = new LinkedList<>();
    // noinspection unchecked
    Collection<AppFolder> childFolders = (Collection<AppFolder>) appFoldersTree.getChildren(parentFolder);
    if (childFolders != null) {
        result.addAll(childFolders);
        for (AppFolder folder : childFolders) result.addAll(getChildFolders(folder));
    }
    return result;
}
Also used : AppFolder(com.haulmont.cuba.core.entity.AppFolder)

Example 9 with AppFolder

use of com.haulmont.cuba.core.entity.AppFolder in project cuba by cuba-platform.

the class CubaFoldersPane method createAppFoldersPane.

protected Component createAppFoldersPane() {
    List<AppFolder> appFolders = foldersService.loadAppFolders();
    if (appFolders.isEmpty())
        return null;
    appFoldersTree = new CubaTree();
    appFoldersTree.setCubaId("appFoldersTree");
    appFoldersTree.setSelectable(true);
    appFoldersTree.setItemStyleGenerator(new FolderTreeStyleProvider());
    appFoldersTree.addShortcutListener(new ShortcutListener("applyAppFolder", ShortcutAction.KeyCode.ENTER, (int[]) null) {

        @Override
        public void handleAction(Object sender, Object target) {
            if (target == appFoldersTree) {
                AbstractSearchFolder folder = (AbstractSearchFolder) appFoldersTree.getValue();
                if (folder != null) {
                    openFolder(folder);
                }
            }
        }
    });
    appFoldersTree.addExpandListener(new Tree.ExpandListener() {

        @Override
        public void nodeExpand(Tree.ExpandEvent event) {
            AppFolder folder = (AppFolder) event.getItemId();
            if (StringUtils.isBlank(folder.getQuantityScript())) {
                folder.setQuantity(null);
                folder.setItemStyle(null);
                setFolderTreeItemCaption(appFoldersTree, folder);
            }
        }
    });
    appFoldersTree.addCollapseListener(new Tree.CollapseListener() {

        @Override
        public void nodeCollapse(Tree.CollapseEvent event) {
            AppFolder folder = (AppFolder) event.getItemId();
            if (StringUtils.isBlank(folder.getQuantityScript())) {
                reloadSingleParentFolder(folder, null);
                setFolderTreeItemCaption(appFoldersTree, folder);
            }
        }
    });
    appFoldersRoot = messages.getMainMessage("folders.appFoldersRoot");
    fillTree(appFoldersTree, appFolders, isNeedRootAppFolder() ? appFoldersRoot : null);
    appFoldersTree.addItemClickListener(new FolderClickListener());
    appFoldersTree.addActionHandler(new AppFolderActionsHandler());
    for (Object itemId : appFoldersTree.rootItemIds()) {
        appFoldersTree.expandItemsRecursively(itemId);
    }
    return appFoldersTree;
}
Also used : CubaTree(com.haulmont.cuba.web.toolkit.ui.CubaTree) AppFolder(com.haulmont.cuba.core.entity.AppFolder) ShortcutListener(com.vaadin.event.ShortcutListener) AbstractSearchFolder(com.haulmont.cuba.core.entity.AbstractSearchFolder) CubaTree(com.haulmont.cuba.web.toolkit.ui.CubaTree)

Example 10 with AppFolder

use of com.haulmont.cuba.core.entity.AppFolder in project cuba by cuba-platform.

the class CubaFoldersPane method fillTree.

protected void fillTree(Tree tree, List<? extends Folder> folders, Object rootItemId) {
    if (rootItemId != null) {
        tree.addItem(rootItemId);
    }
    for (Folder folder : folders) {
        tree.addItem(folder);
        setFolderTreeItemCaption(tree, folder);
        if (webConfig.getShowFolderIcons()) {
            if (folder instanceof SearchFolder) {
                if (BooleanUtils.isTrue(((SearchFolder) folder).getIsSet())) {
                    tree.setItemIcon(folder, WebComponentsHelper.getIcon("icons/set-small.png"));
                } else {
                    tree.setItemIcon(folder, WebComponentsHelper.getIcon("icons/search-folder-small.png"));
                }
            } else if (folder instanceof AppFolder) {
                tree.setItemIcon(folder, WebComponentsHelper.getIcon("icons/app-folder-small.png"));
            }
        }
    }
    for (Folder folder : folders) {
        if (folder.getParent() == null) {
            tree.setParent(folder, rootItemId);
        } else {
            if (tree.getItem(folder.getParent()) != null)
                tree.setParent(folder, folder.getParent());
            else
                tree.setParent(folder, rootItemId);
        }
    }
    for (Folder folder : folders) {
        if (!tree.hasChildren(folder)) {
            tree.setChildrenAllowed(folder, false);
        }
    }
}
Also used : AppFolder(com.haulmont.cuba.core.entity.AppFolder) AbstractSearchFolder(com.haulmont.cuba.core.entity.AbstractSearchFolder) SearchFolder(com.haulmont.cuba.security.entity.SearchFolder) AppFolder(com.haulmont.cuba.core.entity.AppFolder) AbstractSearchFolder(com.haulmont.cuba.core.entity.AbstractSearchFolder) SearchFolder(com.haulmont.cuba.security.entity.SearchFolder) Folder(com.haulmont.cuba.core.entity.Folder)

Aggregations

AppFolder (com.haulmont.cuba.core.entity.AppFolder)13 Folder (com.haulmont.cuba.core.entity.Folder)4 Transaction (com.haulmont.cuba.core.Transaction)3 SearchFolder (com.haulmont.cuba.security.entity.SearchFolder)3 FoldersService (com.haulmont.cuba.core.app.FoldersService)2 AbstractSearchFolder (com.haulmont.cuba.core.entity.AbstractSearchFolder)2 Binding (groovy.lang.Binding)2 StopWatch (org.perf4j.StopWatch)2 Slf4JStopWatch (org.perf4j.slf4j.Slf4JStopWatch)2 EntityManager (com.haulmont.cuba.core.EntityManager)1 Query (com.haulmont.cuba.core.Query)1 TypedQuery (com.haulmont.cuba.core.TypedQuery)1 User (com.haulmont.cuba.security.entity.User)1 UserSession (com.haulmont.cuba.security.global.UserSession)1 CubaTree (com.haulmont.cuba.web.toolkit.ui.CubaTree)1 ShortcutListener (com.vaadin.event.ShortcutListener)1 IOException (java.io.IOException)1