CCM NG/ccm-cms: BrowsePane: Changing current folder using the folder on the left now works.
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4581 8810af33-2d31-482b-a856-94f89814c4df
Former-commit-id: 87780f49dc
pull/2/head
parent
0a25f0f03e
commit
bb41d6df9e
|
|
@ -20,6 +20,7 @@ package com.arsdigita.cms.ui;
|
|||
|
||||
import com.arsdigita.bebop.Component;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.Link;
|
||||
import com.arsdigita.bebop.Page;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.Resettable;
|
||||
|
|
@ -37,14 +38,21 @@ import com.arsdigita.cms.CMS;
|
|||
import com.arsdigita.cms.ui.folder.FolderRequestLocal;
|
||||
import com.arsdigita.cms.ui.folder.FolderSelectionModel;
|
||||
import com.arsdigita.cms.ui.folder.FolderTreeModelBuilder;
|
||||
import com.arsdigita.cms.ui.folder.FolderTreeModelController;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.toolbox.ui.LayoutPanel;
|
||||
import com.arsdigita.util.Assert;
|
||||
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.core.CcmObject;
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.ContentSectionManager;
|
||||
import org.librecms.contentsection.Folder;
|
||||
import org.librecms.dispatcher.ItemResolver;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A pane that contains a folder tree on the left and a folder manipulator on
|
||||
|
|
@ -66,29 +74,6 @@ public class BrowsePane extends LayoutPanel implements Resettable {
|
|||
|
||||
/* The folder tree displayed on the left side / left column */
|
||||
tree = new BaseTree(new FolderTreeModelBuilder());
|
||||
tree.setCellRenderer(new TreeCellRenderer() {
|
||||
|
||||
@Override
|
||||
public Component getComponent(final Tree tree,
|
||||
final PageState state,
|
||||
final Object value,
|
||||
final boolean isSelected,
|
||||
final boolean isExpanded,
|
||||
final boolean isLeaf,
|
||||
final Object key) {
|
||||
if (value instanceof Folder) {
|
||||
final Folder folder = (Folder) value;
|
||||
if (folder.getParentCategory() == null) {
|
||||
return new Text("/");
|
||||
} else {
|
||||
return new Text(folder.getName());
|
||||
}
|
||||
} else {
|
||||
return new Text(value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
selectionModel = tree.getSelectionModel();
|
||||
folderModel = new FolderSelectionModel(selectionModel);
|
||||
folderRequestLocal = new FolderRequestLocal(folderModel);
|
||||
|
|
@ -216,27 +201,33 @@ public class BrowsePane extends LayoutPanel implements Resettable {
|
|||
if (!root.equals(folderRequestLocal.getFolder(state))) {
|
||||
// Expand the ancestor nodes of the currently
|
||||
// selected node.
|
||||
|
||||
CcmObject object = folderRequestLocal.getFolder(state);
|
||||
|
||||
while (object != null) {
|
||||
if (object instanceof Category) {
|
||||
final Category category = (Category) object;
|
||||
|
||||
if (category.getParentCategory() != null) {
|
||||
final Category result = category.getParentCategory();
|
||||
object = result;
|
||||
tree.expand(
|
||||
((Long) object.getObjectId()).toString(),
|
||||
state);
|
||||
} else {
|
||||
object = null;
|
||||
}
|
||||
|
||||
} else {
|
||||
object = null;
|
||||
}
|
||||
}
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final FolderTreeModelController controller = cdiUtil.findBean(
|
||||
FolderTreeModelController.class);
|
||||
final List<Long> ancestorIds = controller.findAncestorIds(
|
||||
folderRequestLocal.getFolder(state));
|
||||
ancestorIds.forEach(id -> tree.expand(id.toString(), state));
|
||||
|
||||
// CcmObject object = folderRequestLocal.getFolder(state);
|
||||
//
|
||||
// while (object != null) {
|
||||
// if (object instanceof Category) {
|
||||
// final Category category = (Category) object;
|
||||
//
|
||||
// if (category.getParentCategory() != null) {
|
||||
// final Category result = category.getParentCategory();
|
||||
// object = result;
|
||||
// tree.expand(
|
||||
// ((Long) object.getObjectId()).toString(),
|
||||
// state);
|
||||
// } else {
|
||||
// object = null;
|
||||
// }
|
||||
//
|
||||
// } else {
|
||||
// object = null;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,8 +53,6 @@ import org.libreccm.categorization.Category;
|
|||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.security.PermissionChecker;
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
import org.librecms.contentsection.ContentItemManager;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.ContentSectionManager;
|
||||
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||
|
|
|
|||
|
|
@ -36,8 +36,9 @@ class FolderPathListModel implements ListModel {
|
|||
private Folder currentFolder;
|
||||
|
||||
public FolderPathListModel(final Folder folder) {
|
||||
pathFolders = CdiUtil.createCdiUtil().findBean(FolderManager.class)
|
||||
.getParentFolders(folder).iterator();
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final FolderManager folderManager = cdiUtil.findBean(FolderManager.class);
|
||||
pathFolders = folderManager.getParentFolders(folder).iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -34,9 +34,11 @@ import java.util.Collections;
|
|||
import java.util.Iterator;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.librecms.contentsection.Folder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
|
@ -190,9 +192,21 @@ public class FolderTreeModelBuilder extends LockableImpl
|
|||
|
||||
@Override
|
||||
public Object getElement() {
|
||||
return folder;
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final GlobalizationHelper globalizationHelper = cdiUtil.findBean(
|
||||
GlobalizationHelper.class);
|
||||
final Locale locale = globalizationHelper.getNegotiatedLocale();
|
||||
if (folder.getTitle().hasValue(locale)) {
|
||||
return folder.getTitle().getValue(locale);
|
||||
} else {
|
||||
final String value = folder.getTitle().getValue();
|
||||
if (value == null) {
|
||||
return folder.getName();
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*private class NewFolderBrowserIterator implements Iterator {
|
||||
|
|
|
|||
|
|
@ -20,11 +20,15 @@ package com.arsdigita.cms.ui.folder;
|
|||
|
||||
import com.arsdigita.bebop.tree.TreeNode;
|
||||
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.core.UnexpectedErrorException;
|
||||
import org.librecms.contentsection.Folder;
|
||||
import org.librecms.contentsection.FolderRepository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
|
@ -47,10 +51,9 @@ public class FolderTreeModelController {
|
|||
"Can't get current folder from null.");
|
||||
}
|
||||
|
||||
final Folder current = (Folder) node.getElement();
|
||||
|
||||
final Optional<Folder> folder = folderRepo.findById(current
|
||||
.getObjectId());
|
||||
// final Folder current = (Folder) node.getElement();
|
||||
final Optional<Folder> folder = folderRepo
|
||||
.findById((long) node.getKey());
|
||||
if (folder.isPresent()) {
|
||||
return folder.get();
|
||||
} else {
|
||||
|
|
@ -71,4 +74,26 @@ public class FolderTreeModelController {
|
|||
return getCurrentFolder(node).getSubFolders();
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public List<Long> findAncestorIds(final Folder folder) {
|
||||
Objects.requireNonNull(folder,
|
||||
"Can't find ids of the ancestors of folder null.");
|
||||
|
||||
final Optional<Folder> theFolder = folderRepo.findById(folder
|
||||
.getObjectId());
|
||||
if (!theFolder.isPresent()) {
|
||||
throw new UnexpectedErrorException(String.format(
|
||||
"The folder %s was not found in the database, but it should be there.",
|
||||
Objects.toString(folder)));
|
||||
}
|
||||
final List<Long> ancestorIds = new ArrayList<>();
|
||||
Category current = theFolder.get();
|
||||
while(current != null) {
|
||||
ancestorIds.add(current.getObjectId());
|
||||
current = current.getParentCategory();
|
||||
}
|
||||
|
||||
return ancestorIds;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,8 +40,12 @@ import org.librecms.contenttypes.News;
|
|||
import org.librecms.dispatcher.MultilingualItemResolver;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.librecms.contentsection.privileges.TypePrivileges;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
|
|
@ -121,11 +125,13 @@ public class ContentSectionSetup extends AbstractCcmApplicationSetup {
|
|||
rootFolder.setUuid(UUID.randomUUID().toString());
|
||||
rootFolder.setUniqueId(rootFolder.getUuid());
|
||||
rootFolder.setName(String.format("%s_" + ROOT, sectionName));
|
||||
rootFolder.getTitle().addValue(Locale.ROOT, "/");
|
||||
rootFolder.setType(FolderType.DOCUMENTS_FOLDER);
|
||||
rootFolder.setSection(section);
|
||||
|
||||
final Folder rootAssetFolder = new Folder();
|
||||
rootAssetFolder.setName(String.format("%s_" + ASSETS, sectionName));
|
||||
rootAssetFolder.getTitle().addValue(Locale.ROOT, "/");
|
||||
rootAssetFolder.setUuid(UUID.randomUUID().toString());
|
||||
rootAssetFolder.setUniqueId(rootAssetFolder.getUuid());
|
||||
rootAssetFolder.setType(FolderType.ASSETS_FOLDER);
|
||||
|
|
|
|||
|
|
@ -23,10 +23,12 @@ import com.arsdigita.kernel.KernelConfig;
|
|||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.categorization.CategoryManager;
|
||||
import org.libreccm.configuration.ConfigurationManager;
|
||||
import org.libreccm.core.UnexpectedErrorException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
|
@ -108,8 +110,16 @@ public class FolderManager {
|
|||
HAS_LIVE_ITEMS
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public Optional<Folder> getParentFolder(final Folder folder) {
|
||||
final Category parentCategory = folder.getParentCategory();
|
||||
Objects.requireNonNull(folder);
|
||||
final Optional<Folder> theFolder = folderRepo.findById(folder.getObjectId());
|
||||
if (!theFolder.isPresent()) {
|
||||
throw new UnexpectedErrorException(String.format(
|
||||
"The folder %s should be in the database but is not.",
|
||||
Objects.toString(folder)));
|
||||
}
|
||||
final Category parentCategory = theFolder.get().getParentCategory();
|
||||
if (parentCategory == null) {
|
||||
return Optional.empty();
|
||||
} else {
|
||||
|
|
@ -461,6 +471,7 @@ public class FolderManager {
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public List<Folder> getParentFolders(final Folder folder) {
|
||||
|
||||
if (folder == null) {
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ cms.ui.category.use_context_must_be_unique=Use context must be unique within a C
|
|||
cms.ui.category.view_index_item=View index item
|
||||
|
||||
cms.ui.authoring.no_types_registered=No types registered
|
||||
cms.ui.contents_of=Contents of
|
||||
cms.ui.contents_of=Contents of
|
||||
cms.ui.new_folder=Create new folder
|
||||
cms.ui.edit_folder=Rename the current folder
|
||||
cms.ui.authoring.create_new=Create new
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ cms.ui.category.use_context_must_be_unique=Use Context muss innerhalb einer Cont
|
|||
cms.ui.category.view_index_item=Index Element anzeigen
|
||||
|
||||
cms.ui.authoring.no_types_registered=Keine Typen registiert
|
||||
cms.ui.contents_of=Inhalt von
|
||||
cms.ui.contents_of=Inhalt von
|
||||
cms.ui.new_folder=Neuen Ordner erstellen
|
||||
cms.ui.edit_folder=Aktuellen Ordner umbenennen
|
||||
cms.ui.authoring.create_new=Neuer Inhalt
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ cms.ui.permissions.table.actions.remove_all=Remove all permissions
|
|||
cms.ui.permissions.table.actions.remove_all.confirm=Are you sure to remove all permissions for this role from the current object?
|
||||
cms.ui.permissions.table.remove_all.header=Remove all
|
||||
cms.ui.authoring.no_types_registered=No types registered
|
||||
cms.ui.contents_of=Contents of
|
||||
cms.ui.contents_of=Contents of
|
||||
cms.ui.new_folder=Create new folder
|
||||
cms.ui.edit_folder=Rename the current folder
|
||||
cms.ui.authoring.create_new=Create new
|
||||
|
|
|
|||
|
|
@ -355,7 +355,7 @@ public class Category extends CcmObject implements Serializable, Portable {
|
|||
hash = 23 * hash + (enabled ? 1 : 0);
|
||||
hash = 23 * hash + (visible ? 1 : 0);
|
||||
hash = 23 * hash + (abstractCategory ? 1 : 0);
|
||||
hash = 23 * hash + Objects.hashCode(parentCategory);
|
||||
// hash = 23 * hash + Objects.hashCode(parentCategory);
|
||||
hash = 23 * hash + (int) (categoryOrder ^ (categoryOrder >>> 32));
|
||||
return hash;
|
||||
}
|
||||
|
|
@ -402,9 +402,9 @@ public class Category extends CcmObject implements Serializable, Portable {
|
|||
if (abstractCategory != other.isAbstractCategory()) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(parentCategory, other.getParentCategory())) {
|
||||
return false;
|
||||
}
|
||||
// if (!Objects.equals(parentCategory, other.getParentCategory())) {
|
||||
// return false;
|
||||
// }
|
||||
return categoryOrder == other.getCategoryOrder();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue