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