Search in sources :

Example 1 with SearchFolder

use of com.haulmont.cuba.security.entity.SearchFolder in project cuba by cuba-platform.

the class FilterDelegateImpl method saveAsFolder.

protected void saveAsFolder(boolean isAppFolder) {
    final AbstractSearchFolder folder;
    if (isAppFolder)
        folder = (metadata.create(AppFolder.class));
    else
        folder = (metadata.create(SearchFolder.class));
    if (filterEntity.getCode() == null) {
        String folderName = filterEntity != adHocFilter ? filterEntity.getName() : "";
        folder.setName(folderName);
        folder.setTabName(folderName);
    } else {
        String name = messages.getMainMessage(filterEntity.getCode());
        folder.setName(name);
        folder.setTabName(name);
    }
    String newXml = filterParser.getXml(conditions, Param.ValueProperty.VALUE);
    folder.setFilterComponentId(filterEntity.getComponentId());
    folder.setFilterXml(newXml);
    if (!isAppFolder) {
        if (uerCanEditGlobalFilter())
            ((SearchFolder) folder).setUser(filterEntity.getUser());
        else
            ((SearchFolder) folder).setUser(userSessionSource.getUserSession().getCurrentOrSubstitutedUser());
    }
    Presentations presentations;
    if (applyTo != null && applyTo instanceof Component.HasPresentations) {
        final Component.HasPresentations presentationsOwner = (Component.HasPresentations) applyTo;
        presentations = presentationsOwner.isUsePresentations() ? presentationsOwner.getPresentations() : null;
    } else {
        presentations = null;
    }
    Runnable commitHandler;
    if (isAppFolder) {
        commitHandler = () -> {
            AbstractSearchFolder savedFolder = saveFolder(folder);
            filterEntity.setFolder(savedFolder);
        };
    } else {
        commitHandler = () -> {
            AbstractSearchFolder savedFolder = saveFolder(folder);
            filterEntity.setFolder(savedFolder);
        };
    }
    filterHelper.openFolderEditWindow(isAppFolder, folder, presentations, commitHandler);
}
Also used : AppFolder(com.haulmont.cuba.core.entity.AppFolder) AbstractSearchFolder(com.haulmont.cuba.core.entity.AbstractSearchFolder) AbstractSearchFolder(com.haulmont.cuba.core.entity.AbstractSearchFolder) SearchFolder(com.haulmont.cuba.security.entity.SearchFolder) Presentations(com.haulmont.cuba.gui.presentations.Presentations)

Example 2 with SearchFolder

use of com.haulmont.cuba.security.entity.SearchFolder in project cuba by cuba-platform.

the class FoldersServiceBean method loadSearchFolders.

@Override
public List<SearchFolder> loadSearchFolders() {
    log.debug("Loading SearchFolders");
    StopWatch stopWatch = new Slf4JStopWatch("SearchFolders");
    stopWatch.start();
    Transaction tx = persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        MetaClass effectiveMetaClass = metadata.getExtendedEntities().getEffectiveMetaClass(SearchFolder.class);
        TypedQuery<SearchFolder> q = em.createQuery("select f from " + effectiveMetaClass.getName() + " f " + "left join fetch f.user u on u.id = ?1 " + "left join fetch f.presentation " + "where (u.id = ?1 or u is null) " + "order by f.sortOrder, f.name", SearchFolder.class);
        q.setParameter(1, userSessionSource.currentOrSubstitutedUserId());
        List<SearchFolder> list = q.getResultList();
        // fetch parents
        for (SearchFolder folder : list) {
            folder.getParent();
        }
        tx.commit();
        return list;
    } finally {
        tx.end();
        stopWatch.stop();
    }
}
Also used : Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) MetaClass(com.haulmont.chile.core.model.MetaClass) SearchFolder(com.haulmont.cuba.security.entity.SearchFolder) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch)

Example 3 with SearchFolder

use of com.haulmont.cuba.security.entity.SearchFolder in project cuba by cuba-platform.

the class CubaFoldersPane method createSearchFoldersPane.

protected Component createSearchFoldersPane() {
    searchFoldersTree = new CubaTree();
    searchFoldersTree.setCubaId("searchFoldersTree");
    searchFoldersTree.setSelectable(true);
    searchFoldersTree.setItemStyleGenerator(new FolderTreeStyleProvider());
    searchFoldersTree.addShortcutListener(new ShortcutListener("applySearchFolder", ShortcutAction.KeyCode.ENTER, (int[]) null) {

        @Override
        public void handleAction(Object sender, Object target) {
            if (target == searchFoldersTree) {
                AbstractSearchFolder folder = (AbstractSearchFolder) searchFoldersTree.getValue();
                if (folder != null) {
                    openFolder(folder);
                }
            }
        }
    });
    List<SearchFolder> searchFolders = foldersService.loadSearchFolders();
    searchFoldersRoot = messages.getMainMessage("folders.searchFoldersRoot");
    searchFoldersTree.addItemClickListener(new FolderClickListener());
    searchFoldersTree.addActionHandler(new SearchFolderActionsHandler());
    if (!searchFolders.isEmpty()) {
        fillTree(searchFoldersTree, searchFolders, isNeedRootSearchFolder() ? searchFoldersRoot : null);
    }
    for (Object itemId : searchFoldersTree.rootItemIds()) {
        searchFoldersTree.expandItemsRecursively(itemId);
    }
    return searchFoldersTree;
}
Also used : ShortcutListener(com.vaadin.event.ShortcutListener) AbstractSearchFolder(com.haulmont.cuba.core.entity.AbstractSearchFolder) AbstractSearchFolder(com.haulmont.cuba.core.entity.AbstractSearchFolder) SearchFolder(com.haulmont.cuba.security.entity.SearchFolder) CubaTree(com.haulmont.cuba.web.toolkit.ui.CubaTree)

Example 4 with SearchFolder

use of com.haulmont.cuba.security.entity.SearchFolder in project cuba by cuba-platform.

the class FolderEditWindow method commit.

protected void commit() {
    SearchFolder folder = (SearchFolder) FolderEditWindow.this.folder;
    if (StringUtils.trimToNull(nameField.getValue()) == null) {
        String msg = messages.getMainMessage("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 {
        String value = sortOrderField.getValue();
        int sortOrder;
        try {
            sortOrder = Integer.parseInt(value);
        } catch (NumberFormatException e) {
            String msg = messages.getMainMessage("folders.folderEditWindow.invalidSortOrder");
            App.getInstance().getWindowManager().showNotification(msg, Frame.NotificationType.WARNING);
            return;
        }
        folder.setSortOrder(sortOrder);
    }
    Object parent = parentSelect.getValue();
    if (parent instanceof Folder)
        folder.setParent((Folder) parent);
    else
        folder.setParent(null);
    folder.setApplyDefault(Boolean.valueOf(applyDefaultCb.getValue().toString()));
    if (globalCb != null) {
        if (BooleanUtils.isTrue(globalCb.getValue())) {
            folder.setUser(null);
        } else {
            folder.setUser(userSessionSource.getUserSession().getCurrentOrSubstitutedUser());
        }
    } else {
        folder.setUser(userSessionSource.getUserSession().getCurrentOrSubstitutedUser());
    }
    if (presentation != null) {
        folder.setPresentation((Presentation) presentation.getValue());
    }
    FolderEditWindow.this.commitHandler.run();
    close();
}
Also used : AbstractSearchFolder(com.haulmont.cuba.core.entity.AbstractSearchFolder) SearchFolder(com.haulmont.cuba.security.entity.SearchFolder) AbstractSearchFolder(com.haulmont.cuba.core.entity.AbstractSearchFolder) SearchFolder(com.haulmont.cuba.security.entity.SearchFolder) Folder(com.haulmont.cuba.core.entity.Folder)

Example 5 with SearchFolder

use of com.haulmont.cuba.security.entity.SearchFolder in project cuba by cuba-platform.

the class FolderEditWindow method fillParentSelect.

protected void fillParentSelect() {
    parentSelect.removeAllItems();
    String root = getMessage("folders.searchFoldersRoot");
    parentSelect.addItem(root);
    parentSelect.setNullSelectionItemId(root);
    FoldersService service = AppBeans.get(FoldersService.NAME);
    List<SearchFolder> list = service.loadSearchFolders();
    for (SearchFolder folder : list) {
        if (!folder.equals(this.folder)) {
            parentSelect.addItem(folder);
            parentSelect.setItemCaption(folder, folder.getCaption());
        }
    }
}
Also used : FoldersService(com.haulmont.cuba.core.app.FoldersService) AbstractSearchFolder(com.haulmont.cuba.core.entity.AbstractSearchFolder) SearchFolder(com.haulmont.cuba.security.entity.SearchFolder)

Aggregations

SearchFolder (com.haulmont.cuba.security.entity.SearchFolder)8 AbstractSearchFolder (com.haulmont.cuba.core.entity.AbstractSearchFolder)6 AppFolder (com.haulmont.cuba.core.entity.AppFolder)3 Folder (com.haulmont.cuba.core.entity.Folder)3 MetaClass (com.haulmont.chile.core.model.MetaClass)1 EntityManager (com.haulmont.cuba.core.EntityManager)1 Transaction (com.haulmont.cuba.core.Transaction)1 FoldersService (com.haulmont.cuba.core.app.FoldersService)1 Filter (com.haulmont.cuba.gui.components.Filter)1 WindowConfig (com.haulmont.cuba.gui.config.WindowConfig)1 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)1 DsContextImplementation (com.haulmont.cuba.gui.data.impl.DsContextImplementation)1 Presentations (com.haulmont.cuba.gui.presentations.Presentations)1 FilterEntity (com.haulmont.cuba.security.entity.FilterEntity)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 HashMap (java.util.HashMap)1 StopWatch (org.perf4j.StopWatch)1