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);
}
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();
}
}
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;
}
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();
}
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());
}
}
}
Aggregations