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-94f89814c4dfccm-docs
parent
05f26bdd34
commit
053cba0183
|
|
@ -65,7 +65,6 @@ import com.arsdigita.toolbox.ui.ActionGroup;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -81,11 +80,14 @@ import org.librecms.contentsection.ContentItem;
|
||||||
import org.librecms.contentsection.ContentItemManager;
|
import org.librecms.contentsection.ContentItemManager;
|
||||||
import org.librecms.contentsection.ContentItemRepository;
|
import org.librecms.contentsection.ContentItemRepository;
|
||||||
import org.librecms.contentsection.Folder;
|
import org.librecms.contentsection.Folder;
|
||||||
|
import org.librecms.contentsection.FolderManager;
|
||||||
import org.librecms.contentsection.FolderRepository;
|
import org.librecms.contentsection.FolderRepository;
|
||||||
import org.librecms.contentsection.privileges.ItemPrivileges;
|
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static org.librecms.CmsConstants.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Browse folders and manipulate them with various actions (move/copy/delete).
|
* 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 CcmObject object;
|
||||||
final String name;
|
final String name;
|
||||||
if (objectId.startsWith("folder--")) {
|
if (objectId.startsWith(FOLDER_BROWSER_KEY_PREFIX_FOLDER)) {
|
||||||
final long folderId = Long.parseLong(objectId.substring(
|
final long folderId = Long.parseLong(objectId.substring(
|
||||||
"folder--".length()));
|
FOLDER_BROWSER_KEY_PREFIX_FOLDER.length()));
|
||||||
final Folder folder = folderRepo.findById(folderId).orElseThrow(
|
final Folder folder = folderRepo.findById(folderId).orElseThrow(
|
||||||
() -> new IllegalArgumentException(String.format(
|
() -> new IllegalArgumentException(String.format(
|
||||||
"No folder with id %d in database.", folderId)));
|
"No folder with id %d in database.", folderId)));
|
||||||
|
|
@ -568,9 +570,9 @@ public class FolderManipulator extends SimpleContainer implements
|
||||||
|
|
||||||
object = folder;
|
object = folder;
|
||||||
|
|
||||||
} else if (objectId.startsWith("item--")) {
|
} else if (objectId.startsWith(FOLDER_BROWSER_KEY_PREFIX_ITEM)) {
|
||||||
final long itemId = Long.parseLong(objectId.substring(
|
final long itemId = Long.parseLong(objectId.substring(
|
||||||
"item--".length()));
|
FOLDER_BROWSER_KEY_PREFIX_ITEM.length()));
|
||||||
final ContentItem item = itemRepo.findById(itemId).orElseThrow(
|
final ContentItem item = itemRepo.findById(itemId).orElseThrow(
|
||||||
() -> new IllegalArgumentException(String.format(
|
() -> new IllegalArgumentException(String.format(
|
||||||
"No content item with id %d in database.",
|
"No content item with id %d in database.",
|
||||||
|
|
@ -585,9 +587,11 @@ public class FolderManipulator extends SimpleContainer implements
|
||||||
object = item;
|
object = item;
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException(String.format(
|
throw new IllegalArgumentException(String.format(
|
||||||
"Provided objectId '%s' does not start with 'folder--' "
|
"Provided objectId '%s' does not start with '%s' "
|
||||||
+ "or 'item--'.",
|
+ "or '%s'.",
|
||||||
objectId));
|
objectId,
|
||||||
|
FOLDER_BROWSER_KEY_PREFIX_FOLDER,
|
||||||
|
FOLDER_BROWSER_KEY_PREFIX_ITEM));
|
||||||
}
|
}
|
||||||
|
|
||||||
final long count = controller.countObjects(target, name);
|
final long count = controller.countObjects(target, name);
|
||||||
|
|
@ -704,6 +708,7 @@ public class FolderManipulator extends SimpleContainer implements
|
||||||
} else if (isCopy(state)) {
|
} else if (isCopy(state)) {
|
||||||
label.setLabel(new GlobalizedMessage(
|
label.setLabel(new GlobalizedMessage(
|
||||||
"cms.ui.folder.copy",
|
"cms.ui.folder.copy",
|
||||||
|
CMS_BUNDLE,
|
||||||
new Object[]{numberOfItems,
|
new Object[]{numberOfItems,
|
||||||
categoryManager.getCategoryPath(
|
categoryManager.getCategoryPath(
|
||||||
folder)}));
|
folder)}));
|
||||||
|
|
@ -729,21 +734,22 @@ public class FolderManipulator extends SimpleContainer implements
|
||||||
|
|
||||||
// Set things up the first time the selector gets visible
|
// Set things up the first time the selector gets visible
|
||||||
public void expose(final PageState state) {
|
public void expose(final PageState state) {
|
||||||
final Category folder = (Category) sourceFolderModel.
|
final Folder folder = sourceFolderModel.getSelectedObject(state);
|
||||||
getSelectedObject(
|
|
||||||
state);
|
|
||||||
targetModel.clearSelection(state);
|
targetModel.clearSelection(state);
|
||||||
if (folder != null) {
|
if (folder != null) {
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
final ContentItemManager itemManager = cdiUtil.findBean(
|
final FolderManager folderManager = cdiUtil.findBean(
|
||||||
ContentItemManager.class);
|
FolderManager.class);
|
||||||
|
if (folder.getParentFolder() == null) {
|
||||||
//ToDo
|
folderTree.expand(Long.toString(folder.getObjectId()),
|
||||||
// final ItemCollection items = folder.getPathInfo(true);
|
state);
|
||||||
// while (items.next()) {
|
} else {
|
||||||
// folderTree.expand(items.getID().toString(), state);
|
final List<Folder> parents = folderManager.getParentFolders(
|
||||||
// }
|
folder);
|
||||||
// items.close();
|
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 com.arsdigita.ui.CcmObjectSelectionModel;
|
||||||
|
|
||||||
import org.libreccm.categorization.Category;
|
import org.libreccm.categorization.Category;
|
||||||
import org.librecms.CmsConstants;
|
|
||||||
import org.librecms.contentsection.ContentSection;
|
import org.librecms.contentsection.ContentSection;
|
||||||
import org.librecms.contentsection.Folder;
|
import org.librecms.contentsection.Folder;
|
||||||
|
|
||||||
|
|
@ -63,20 +62,6 @@ public class FolderSelectionModel extends CcmObjectSelectionModel<Folder> {
|
||||||
super.setSelectedKey(state, key);
|
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.
|
* Clear the selection by resetting it to the root folder id.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,13 @@
|
||||||
*/
|
*/
|
||||||
package com.arsdigita.cms.ui.folder;
|
package com.arsdigita.cms.ui.folder;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
import com.arsdigita.bebop.Tree;
|
import com.arsdigita.bebop.Tree;
|
||||||
|
|
||||||
|
import org.librecms.CmsConstants;
|
||||||
|
|
||||||
|
import static org.librecms.CmsConstants.*;
|
||||||
|
|
||||||
public class FolderTree extends Tree {
|
public class FolderTree extends Tree {
|
||||||
|
|
||||||
public FolderTree(final FolderSelectionModel folderSel) {
|
public FolderTree(final FolderSelectionModel folderSel) {
|
||||||
|
|
@ -27,4 +32,26 @@ public class FolderTree extends Tree {
|
||||||
setSelectionModel(folderSel);
|
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