CCM NG/ccm-cms: Copying items in the FolderBrowser now works
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4618 8810af33-2d31-482b-a856-94f89814c4df
Former-commit-id: e1b296b5dd
pull/2/head
parent
5e493556ca
commit
b847caf6d1
|
|
@ -65,7 +65,6 @@ import com.arsdigita.toolbox.ui.ActionGroup;
|
|||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -81,11 +80,14 @@ import org.librecms.contentsection.ContentItem;
|
|||
import org.librecms.contentsection.ContentItemManager;
|
||||
import org.librecms.contentsection.ContentItemRepository;
|
||||
import org.librecms.contentsection.Folder;
|
||||
import org.librecms.contentsection.FolderManager;
|
||||
import org.librecms.contentsection.FolderRepository;
|
||||
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.librecms.CmsConstants.*;
|
||||
|
||||
/**
|
||||
* Browse folders and manipulate them with various actions (move/copy/delete).
|
||||
*
|
||||
|
|
@ -552,9 +554,9 @@ public class FolderManipulator extends SimpleContainer implements
|
|||
|
||||
final CcmObject object;
|
||||
final String name;
|
||||
if (objectId.startsWith("folder--")) {
|
||||
if (objectId.startsWith(FOLDER_BROWSER_KEY_PREFIX_FOLDER)) {
|
||||
final long folderId = Long.parseLong(objectId.substring(
|
||||
"folder--".length()));
|
||||
FOLDER_BROWSER_KEY_PREFIX_FOLDER.length()));
|
||||
final Folder folder = folderRepo.findById(folderId).orElseThrow(
|
||||
() -> new IllegalArgumentException(String.format(
|
||||
"No folder with id %d in database.", folderId)));
|
||||
|
|
@ -568,9 +570,9 @@ public class FolderManipulator extends SimpleContainer implements
|
|||
|
||||
object = folder;
|
||||
|
||||
} else if (objectId.startsWith("item--")) {
|
||||
} else if (objectId.startsWith(FOLDER_BROWSER_KEY_PREFIX_ITEM)) {
|
||||
final long itemId = Long.parseLong(objectId.substring(
|
||||
"item--".length()));
|
||||
FOLDER_BROWSER_KEY_PREFIX_ITEM.length()));
|
||||
final ContentItem item = itemRepo.findById(itemId).orElseThrow(
|
||||
() -> new IllegalArgumentException(String.format(
|
||||
"No content item with id %d in database.",
|
||||
|
|
@ -585,9 +587,11 @@ public class FolderManipulator extends SimpleContainer implements
|
|||
object = item;
|
||||
} else {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Provided objectId '%s' does not start with 'folder--' "
|
||||
+ "or 'item--'.",
|
||||
objectId));
|
||||
"Provided objectId '%s' does not start with '%s' "
|
||||
+ "or '%s'.",
|
||||
objectId,
|
||||
FOLDER_BROWSER_KEY_PREFIX_FOLDER,
|
||||
FOLDER_BROWSER_KEY_PREFIX_ITEM));
|
||||
}
|
||||
|
||||
final long count = controller.countObjects(target, name);
|
||||
|
|
@ -704,6 +708,7 @@ public class FolderManipulator extends SimpleContainer implements
|
|||
} else if (isCopy(state)) {
|
||||
label.setLabel(new GlobalizedMessage(
|
||||
"cms.ui.folder.copy",
|
||||
CMS_BUNDLE,
|
||||
new Object[]{numberOfItems,
|
||||
categoryManager.getCategoryPath(
|
||||
folder)}));
|
||||
|
|
@ -729,21 +734,22 @@ public class FolderManipulator extends SimpleContainer implements
|
|||
|
||||
// Set things up the first time the selector gets visible
|
||||
public void expose(final PageState state) {
|
||||
final Category folder = (Category) sourceFolderModel.
|
||||
getSelectedObject(
|
||||
state);
|
||||
final Folder folder = sourceFolderModel.getSelectedObject(state);
|
||||
targetModel.clearSelection(state);
|
||||
if (folder != null) {
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ContentItemManager itemManager = cdiUtil.findBean(
|
||||
ContentItemManager.class);
|
||||
|
||||
//ToDo
|
||||
// final ItemCollection items = folder.getPathInfo(true);
|
||||
// while (items.next()) {
|
||||
// folderTree.expand(items.getID().toString(), state);
|
||||
// }
|
||||
// items.close();
|
||||
final FolderManager folderManager = cdiUtil.findBean(
|
||||
FolderManager.class);
|
||||
if (folder.getParentFolder() == null) {
|
||||
folderTree.expand(Long.toString(folder.getObjectId()),
|
||||
state);
|
||||
} else {
|
||||
final List<Folder> parents = folderManager.getParentFolders(
|
||||
folder);
|
||||
parents.stream()
|
||||
.map(parent -> Long.toString(parent.getObjectId()))
|
||||
.forEach(folderId -> folderTree.expand(folderId, state));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import com.arsdigita.cms.CMS;
|
|||
import com.arsdigita.ui.CcmObjectSelectionModel;
|
||||
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.Folder;
|
||||
|
||||
|
|
@ -63,20 +62,6 @@ public class FolderSelectionModel extends CcmObjectSelectionModel<Folder> {
|
|||
super.setSelectedKey(state, key);
|
||||
}
|
||||
|
||||
public void setSelectedKey(final PageState state, final String key) {
|
||||
if (!key.startsWith(CmsConstants.FOLDER_BROWSER_KEY_PREFIX_FOLDER)) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"The string '%s' does not contain a folder id "
|
||||
+ "(it does not start with '%s').",
|
||||
key,
|
||||
CmsConstants.FOLDER_BROWSER_KEY_PREFIX_FOLDER));
|
||||
}
|
||||
|
||||
final long keyAsLong = Long.parseLong(key.substring(
|
||||
CmsConstants.FOLDER_BROWSER_KEY_PREFIX_FOLDER.length()));
|
||||
setSelectedKey(state, keyAsLong);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the selection by resetting it to the root folder id.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -18,8 +18,13 @@
|
|||
*/
|
||||
package com.arsdigita.cms.ui.folder;
|
||||
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.Tree;
|
||||
|
||||
import org.librecms.CmsConstants;
|
||||
|
||||
import static org.librecms.CmsConstants.*;
|
||||
|
||||
public class FolderTree extends Tree {
|
||||
|
||||
public FolderTree(final FolderSelectionModel folderSel) {
|
||||
|
|
@ -27,4 +32,26 @@ public class FolderTree extends Tree {
|
|||
setSelectionModel(folderSel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectedKey(final PageState state, final Object key) {
|
||||
if (key instanceof String) {
|
||||
final Long keyAsLong;
|
||||
if (((String) key).startsWith(
|
||||
FOLDER_BROWSER_KEY_PREFIX_FOLDER)) {
|
||||
keyAsLong = Long.parseLong(((String) key).substring(
|
||||
FOLDER_BROWSER_KEY_PREFIX_FOLDER.length()));
|
||||
} else {
|
||||
keyAsLong = Long.parseLong((String) key);
|
||||
}
|
||||
super.setSelectedKey(state, keyAsLong);
|
||||
} else if (key instanceof Long) {
|
||||
super.setSelectedKey(state, key);
|
||||
} else {
|
||||
//We now that a FolderSelectionModel only takes keys of type Long.
|
||||
//Therefore we try to cast here
|
||||
final Long keyAsLong = (Long) key;
|
||||
super.setSelectedKey(state, keyAsLong);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue