diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AssignedImagesTable.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AssignedImagesTable.java
index 07b003dfb..222830168 100644
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AssignedImagesTable.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AssignedImagesTable.java
@@ -132,8 +132,7 @@ class AssignedImagesTable extends Table {
switch (column.getModelIndex()) {
case COL_MOVE:
- if (moveAttachmentModel
- .getSelectedKey(state) == null) {
+ if (moveAttachmentModel.getSelectedKey(state) == null) {
moveAttachmentModel
.setSelectedKey(state,
@@ -152,7 +151,7 @@ class AssignedImagesTable extends Table {
.parseLong((String) event.getRowKey());
controller.moveAfter(selectedAttachment, destId);
- moveAttachmentModel.setSelectedKey(state, null);
+ moveAttachmentModel.clearSelection(state);
}
break;
case COL_REMOVE:
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/ImageStep.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/ImageStep.java
index dbdcee13c..e045f90ac 100644
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/ImageStep.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/ImageStep.java
@@ -147,7 +147,7 @@ public class ImageStep extends ResettableContainer {
controller.moveToFirst(toMove);
- moveAttachmentModel.setSelectedKey(state, null);
+ moveAttachmentModel.clearSelection(state);
});
assignedImagesTable = new AssignedImagesTable(itemSelectionModel,
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/ImageStepController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/ImageStepController.java
index af287a2f0..c20818a36 100644
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/ImageStepController.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/ImageStepController.java
@@ -65,16 +65,16 @@ class ImageStepController {
private AttachmentListManager attachmentListManager;
@Inject
- private ConfigurationManager confManager;
+ private ItemAttachmentManager attachmentManager;
@Inject
- private ContentItemRepository itemRepo;
+ private ConfigurationManager confManager;
@Inject
private EntityManager entityManager;
@Inject
- private ItemAttachmentManager attachmentManager;
+ private ContentItemRepository itemRepo;
private Locale defaultLocale;
@@ -265,7 +265,7 @@ class ImageStepController {
.orElseThrow(() -> new IllegalArgumentException(String
.format("No ItemAttachment with ID %d in the database.",
attachmentId)));
-
+
deleteAttachment(attachment);
}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentListTableRow.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentListTableRow.java
new file mode 100644
index 000000000..a1a17a345
--- /dev/null
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentListTableRow.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2017 LibreCCM Foundation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+package com.arsdigita.cms.ui.authoring.assets.relatedinfo;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+class AttachmentListTableRow {
+
+ private long listId;
+ private String name;
+ private String title;
+ private String description;
+
+ public long getListId() {
+ return listId;
+ }
+
+ public void setListId(final long listId) {
+ this.listId = listId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(final String title) {
+ this.title = title;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(final String description) {
+ this.description = description;
+ }
+
+
+
+}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoAttachAssetForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoAttachAssetForm.java
index 199b614c3..447410ff9 100644
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoAttachAssetForm.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoAttachAssetForm.java
@@ -109,7 +109,7 @@ class RelatedInfoAttachAssetForm
attachmentManager.attachAsset(asset, list);
}
- relatedInfoStep.showAttachmentList(state);
+ relatedInfoStep.showAttachmentListTable(state);
}
@Override
@@ -119,7 +119,7 @@ class RelatedInfoAttachAssetForm
final PageState state = event.getPageState();
listSelectionModel.clearSelection(state);
- relatedInfoStep.showAttachmentList(state);
+ relatedInfoStep.showAttachmentListTable(state);
}
}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListForm.java
index 4473a272b..29ff1ad39 100644
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListForm.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListForm.java
@@ -370,7 +370,7 @@ class RelatedInfoListForm
if (saveCancelSection.getCancelButton().isSelected(state)) {
listSelectionModel.clearSelection(state);
- relatedInfoStep.showAttachmentList(state);
+ relatedInfoStep.showAttachmentListTable(state);
}
}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListTable.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListTable.java
new file mode 100644
index 000000000..643040eca
--- /dev/null
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListTable.java
@@ -0,0 +1,237 @@
+/*
+ * Copyright (C) 2017 LibreCCM Foundation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+package com.arsdigita.cms.ui.authoring.assets.relatedinfo;
+
+import com.arsdigita.bebop.Component;
+import com.arsdigita.bebop.ControlLink;
+import com.arsdigita.bebop.FormProcessException;
+import com.arsdigita.bebop.Label;
+import com.arsdigita.bebop.PageState;
+import com.arsdigita.bebop.Table;
+import com.arsdigita.bebop.event.TableActionEvent;
+import com.arsdigita.bebop.event.TableActionListener;
+import com.arsdigita.bebop.parameters.StringParameter;
+import com.arsdigita.bebop.table.TableCellRenderer;
+import com.arsdigita.bebop.table.TableColumn;
+import com.arsdigita.bebop.table.TableColumnModel;
+import com.arsdigita.cms.ItemSelectionModel;
+import com.arsdigita.cms.ui.authoring.assets.AttachmentListSelectionModel;
+import com.arsdigita.globalization.GlobalizedMessage;
+
+import org.libreccm.cdi.utils.CdiUtil;
+import org.librecms.CmsConstants;
+import org.librecms.contentsection.AttachmentList;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+class RelatedInfoListTable extends Table {
+
+ protected static final int COL_NAME = 0;
+ protected static final int COL_TITLE = 1;
+ protected static final int COL_DESC = 2;
+ protected static final int COL_EDIT = 3;
+ protected static final int COL_MOVE = 4;
+ protected static final int COL_DELETE = 5;
+
+ private final RelatedInfoStep relatedInfoStep;
+ private final ItemSelectionModel itemSelectionModel;
+ private final AttachmentListSelectionModel selectedListModel;
+ private final AttachmentListSelectionModel moveListModel;
+ private final StringParameter selectedLanguageParam;
+
+ protected RelatedInfoListTable(
+ final RelatedInfoStep relatedInfoStep,
+ final ItemSelectionModel itemSelectionModel,
+ final AttachmentListSelectionModel selectedListModel,
+ final AttachmentListSelectionModel moveListModel,
+ final StringParameter selectedLanguageParam) {
+
+ super();
+ this.relatedInfoStep = relatedInfoStep;
+ this.itemSelectionModel = itemSelectionModel;
+ this.selectedListModel = selectedListModel;
+ this.moveListModel = moveListModel;
+ this.selectedLanguageParam = selectedLanguageParam;
+
+ final TableColumnModel columnModel = super.getColumnModel();
+ columnModel.add(new TableColumn(
+ COL_NAME,
+ new Label(new GlobalizedMessage(
+ "cms.ui.authoring.assets.related_info_step.list.name",
+ CmsConstants.CMS_BUNDLE))));
+ columnModel.add(new TableColumn(
+ COL_TITLE,
+ new Label(new GlobalizedMessage(
+ "cms.ui.authoring.assets.related_info_step.list.title",
+ CmsConstants.CMS_BUNDLE))));
+ columnModel.add(new TableColumn(
+ COL_DESC,
+ new Label(new GlobalizedMessage(
+ "cms.ui.authoring.assets.related_info_step.list.description",
+ CmsConstants.CMS_BUNDLE))));
+ columnModel.add(new TableColumn(
+ COL_EDIT,
+ new Label(new GlobalizedMessage(
+ "cms.ui.authoring.assets.related_info_step.list.edit",
+ CmsConstants.CMS_BUNDLE))));
+ columnModel.add(new TableColumn(
+ COL_MOVE,
+ new Label(new GlobalizedMessage(
+ "cms.ui.authoring.assets.related_info_step.list.move",
+ CmsConstants.CMS_BUNDLE))));
+ columnModel.add(new TableColumn(
+ COL_DELETE,
+ new Label(new GlobalizedMessage(
+ "cms.ui.authoring.assets.related_info_step.list.delete",
+ CmsConstants.CMS_BUNDLE))));
+
+ super
+ .setModelBuilder(new RelatedInfoListTableModelBuilder(
+ itemSelectionModel,
+ moveListModel,
+ selectedLanguageParam));
+
+ super
+ .getColumn(COL_EDIT)
+ .setCellRenderer(new EditCellRenderer());
+ super
+ .getColumn(COL_MOVE)
+ .setCellRenderer(new MoveCellRenderer());
+ super
+ .getColumn(COL_DELETE)
+ .setCellRenderer(new DeleteCellRenderer());
+
+ super
+ .addTableActionListener(new TableActionListener() {
+
+ @Override
+ public void cellSelected(final TableActionEvent event)
+ throws FormProcessException {
+
+ final PageState state = event.getPageState();
+
+ final TableColumn column = getColumnModel()
+ .get(event.getColumn());
+
+ switch (column.getModelIndex()) {
+ case COL_EDIT:
+ selectedListModel
+ .setSelectedKey(state,
+ Long.parseLong((String) event
+ .getRowKey()));
+ relatedInfoStep.showListEditForm(state);
+ break;
+ case COL_MOVE:
+ if (moveListModel.getSelectedKey(state) == null) {
+
+ moveListModel
+ .setSelectedKey(state,
+ Long.parseLong(
+ (String) event
+ .getRowKey()));
+ } else {
+ final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
+ final RelatedInfoStepController controller
+ = cdiUtil
+ .findBean(
+ RelatedInfoStepController.class);
+
+ final AttachmentList selectedList
+ = moveListModel
+ .getSelectedAttachmentList(state);
+
+ final Long destId = Long
+ .parseLong((String) event.getRowKey());
+
+ controller.moveAfter(itemSelectionModel
+ .getSelectedItem(state),
+ selectedList,
+ destId);
+ moveListModel.clearSelection(state);
+ }
+ break;
+ case COL_DELETE:
+ final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
+ final RelatedInfoStepController controller = cdiUtil
+ .findBean(RelatedInfoStepController.class);
+ controller.deleteList(Long
+ .parseLong((String) event.getRowKey()));
+ }
+ }
+
+ @Override
+
+ public void headSelected(final TableActionEvent event) {
+ //Nothing
+ }
+
+ });
+ }
+
+ private class MoveCellRenderer implements TableCellRenderer {
+
+ @Override
+ public Component getComponent(final Table table,
+ final PageState state,
+ final Object value,
+ final boolean isSelected,
+ final Object key,
+ final int row,
+ final int column) {
+
+ return new ControlLink((Component) value);
+ }
+
+ }
+
+ private class EditCellRenderer implements TableCellRenderer {
+
+ @Override
+ public Component getComponent(final Table table,
+ final PageState state,
+ final Object value,
+ final boolean isSelected,
+ final Object key,
+ final int row,
+ final int column) {
+
+ return new ControlLink((Component) value);
+ }
+
+ }
+
+ private class DeleteCellRenderer implements TableCellRenderer {
+
+ @Override
+ public Component getComponent(final Table table,
+ final PageState state,
+ final Object value,
+ final boolean isSelected,
+ final Object key,
+ final int row,
+ final int column) {
+
+ return new ControlLink((Component) value);
+ }
+
+ }
+
+}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListTableModel.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListTableModel.java
new file mode 100644
index 000000000..003c90dd2
--- /dev/null
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListTableModel.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2017 LibreCCM Foundation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+package com.arsdigita.cms.ui.authoring.assets.relatedinfo;
+
+import com.arsdigita.bebop.Label;
+import com.arsdigita.bebop.PageState;
+import com.arsdigita.bebop.table.TableModel;
+import com.arsdigita.cms.ui.authoring.assets.AttachmentListSelectionModel;
+import com.arsdigita.globalization.GlobalizedMessage;
+
+import org.librecms.CmsConstants;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+class RelatedInfoListTableModel implements TableModel {
+
+ private final PageState state;
+ private final AttachmentListSelectionModel moveListModel;
+
+ private final Iterator iterator;
+ private AttachmentListTableRow currentRow;
+
+ RelatedInfoListTableModel(
+ final List rows,
+ final PageState state,
+ final AttachmentListSelectionModel moveListModel) {
+
+ this.iterator = rows.iterator();
+ this.state = state;
+ this.moveListModel = moveListModel;
+ }
+
+ @Override
+ public int getColumnCount() {
+ return 6;
+ }
+
+ @Override
+ public boolean nextRow() {
+ if (iterator.hasNext()) {
+ currentRow = iterator.next();
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public Object getElementAt(final int columnIndex) {
+
+ switch (columnIndex) {
+ case RelatedInfoListTable.COL_NAME:
+ return currentRow.getName();
+ case RelatedInfoListTable.COL_TITLE:
+ return currentRow.getTitle();
+ case RelatedInfoListTable.COL_DESC:
+ return currentRow.getDescription();
+ case RelatedInfoListTable.COL_EDIT:
+ return new Label(new GlobalizedMessage(
+ "cms.ui.authoring.assets.related_info_step.list.edit"));
+ case RelatedInfoListTable.COL_MOVE:
+ if (moveListModel.getSelectedAttachmentList(state) == null) {
+ return new Label(new GlobalizedMessage(
+ "cms.ui.authoring.assets.related_info_step.list.move",
+ CmsConstants.CMS_BUNDLE));
+ } else {
+ return new Label(new GlobalizedMessage(
+ "cms.ui.authoring.assets.related_info_step.list.move_here",
+ CmsConstants.CMS_BUNDLE));
+ }
+ case RelatedInfoListTable.COL_DELETE:
+ return new Label(new GlobalizedMessage(
+ "cms.ui.authoring.assets.related_info_step.list.delete"));
+ default:
+ throw new IllegalArgumentException(String.format(
+ "Illegal column index %d.", columnIndex));
+ }
+ }
+
+ @Override
+ public Object getKeyAt(final int columnIndex) {
+ return currentRow.getListId();
+ }
+
+}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListTableModelBuilder.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListTableModelBuilder.java
new file mode 100644
index 000000000..06aaca201
--- /dev/null
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListTableModelBuilder.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2017 LibreCCM Foundation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+package com.arsdigita.cms.ui.authoring.assets.relatedinfo;
+
+import com.arsdigita.bebop.PageState;
+import com.arsdigita.bebop.Table;
+import com.arsdigita.bebop.parameters.StringParameter;
+import com.arsdigita.bebop.table.TableModel;
+import com.arsdigita.bebop.table.TableModelBuilder;
+import com.arsdigita.cms.ItemSelectionModel;
+import com.arsdigita.cms.ui.authoring.assets.AttachmentListSelectionModel;
+import com.arsdigita.util.LockableImpl;
+
+import org.libreccm.cdi.utils.CdiUtil;
+import org.librecms.contentsection.ContentItem;
+
+import java.util.List;
+import java.util.Locale;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+class RelatedInfoListTableModelBuilder
+ extends LockableImpl
+ implements TableModelBuilder {
+
+ private final ItemSelectionModel itemSelectionModel;
+ private final AttachmentListSelectionModel moveListModel;
+ private final StringParameter selectedLanguageParam;
+
+ protected RelatedInfoListTableModelBuilder(
+ final ItemSelectionModel itemSelectionModel,
+ final AttachmentListSelectionModel moveListModel,
+ final StringParameter selectedLanguageParam) {
+
+ super();
+
+ this.itemSelectionModel = itemSelectionModel;
+ this.moveListModel = moveListModel;
+ this.selectedLanguageParam = selectedLanguageParam;
+ }
+
+ @Override
+ public TableModel makeModel(final Table table,
+ final PageState state) {
+
+ final ContentItem selectedItem = itemSelectionModel
+ .getSelectedItem(state);
+ final String selectedLanguage = (String) state
+ .getValue(selectedLanguageParam);
+ final Locale selectedLocale = new Locale(selectedLanguage);
+
+ final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
+ final RelatedInfoStepController controller = cdiUtil
+ .findBean(RelatedInfoStepController.class);
+
+ final List rows = controller
+ .retrieveAttachmentLists(selectedItem, selectedLocale);
+
+ return new RelatedInfoListTableModel(rows, state, moveListModel);
+ }
+
+}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStep.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStep.java
index 570fa6c2b..3022f9285 100644
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStep.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStep.java
@@ -18,14 +18,20 @@
*/
package com.arsdigita.cms.ui.authoring.assets.relatedinfo;
+import com.arsdigita.bebop.ActionLink;
+import com.arsdigita.bebop.Label;
+import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageState;
-import com.arsdigita.bebop.Text;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
import com.arsdigita.cms.ui.authoring.ResettableContainer;
+import com.arsdigita.cms.ui.authoring.assets.AttachmentListSelectionModel;
+import com.arsdigita.globalization.GlobalizedMessage;
+import org.libreccm.cdi.utils.CdiUtil;
import org.librecms.CmsConstants;
+import org.librecms.contentsection.AttachmentList;
import org.librecms.ui.authoring.ContentItemAuthoringStep;
/**
@@ -39,17 +45,110 @@ import org.librecms.ui.authoring.ContentItemAuthoringStep;
descriptionKey = "related_info_step.description")
public class RelatedInfoStep extends ResettableContainer {
+ private final ItemSelectionModel itemSelectionModel;
+ private final AttachmentListSelectionModel selectedListModel;
+ private final AttachmentListSelectionModel moveListModel;
+ private final AuthoringKitWizard authoringKitWizard;
+ private final StringParameter selectedLanguageParam;
+
+ private final RelatedInfoListTable listTable;
+ private final RelatedInfoListForm listForm;
+ private final ActionLink addListLink;
+ private final ActionLink listToFirstLink;
+
public RelatedInfoStep(final ItemSelectionModel itemSelectionModel,
final AuthoringKitWizard authoringKitWizard,
final StringParameter selectedLanguage) {
super();
- super.add(new Text("Related Info Step placeholder"));
+ this.itemSelectionModel = itemSelectionModel;
+ this.authoringKitWizard = authoringKitWizard;
+ this.selectedLanguageParam = selectedLanguage;
+
+ selectedListModel = new AttachmentListSelectionModel(
+ "selected-attachment-list");
+ moveListModel = new AttachmentListSelectionModel("move-attachment-list");
+
+ listTable = new RelatedInfoListTable(this,
+ itemSelectionModel,
+ selectedListModel, moveListModel,
+ selectedLanguageParam);
+ listForm = new RelatedInfoListForm(this,
+ itemSelectionModel,
+ selectedListModel,
+ selectedLanguageParam);
+
+ super.add(listTable);
+ super.add(listForm);
+
+ addListLink = new ActionLink(new Label(new GlobalizedMessage(
+ "cms.ui.authoring.assets.related_info_step.add_list",
+ CmsConstants.CMS_BUNDLE)));
+ addListLink.addActionListener(event -> {
+ showListEditForm(event.getPageState());
+ });
+
+ listToFirstLink = new ActionLink(new GlobalizedMessage(
+ "cms.ui.authoring.assets.related_info_step.move_to_beginning",
+ CmsConstants.CMS_BUNDLE));
+ listToFirstLink.addActionListener(event -> {
+ final PageState state = event.getPageState();
+ final AttachmentList toMove = moveListModel
+ .getSelectedAttachmentList(state);
+
+ final RelatedInfoStepController controller = CdiUtil
+ .createCdiUtil()
+ .findBean(RelatedInfoStepController.class);
+
+ controller.moveToFirst(itemSelectionModel.getSelectedItem(state),
+ toMove);
+
+ moveListModel.clearSelection(state);
+ });
+
+ moveListModel.addChangeListener(event -> {
+
+ final PageState state = event.getPageState();
+
+ if (moveListModel.getSelectedKey(state) == null) {
+ addListLink.setVisible(state, true);
+ listToFirstLink.setVisible(state, false);
+ } else {
+ addListLink.setVisible(state, false);
+ listToFirstLink.setVisible(state, true);
+ }
+ });
}
- protected void showAttachmentList(final PageState state) {
-
+ @Override
+ public void register(final Page page) {
+
+ super.register(page);
+
+ page.addComponentStateParam(this, selectedListModel.getStateParameter());
+ page.addComponentStateParam(this, moveListModel.getStateParameter());
+
+ page.setVisibleDefault(listTable, true);
+ page.setVisibleDefault(listForm, false);
+ page.setVisibleDefault(addListLink, true);
+ page.setVisibleDefault(listToFirstLink, false);
}
-
+
+ protected void showAttachmentListTable(final PageState state) {
+
+ listTable.setVisible(state, true);
+ addListLink.setVisible(state, true);
+ listForm.setVisible(state, false);
+ listToFirstLink.setVisible(state, false);
+ }
+
+ void showListEditForm(final PageState state) {
+
+ listTable.setVisible(state, false);
+ listForm.setVisible(state, true);
+ addListLink.setVisible(state, false);
+ listToFirstLink.setVisible(state, false);
+ }
+
}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStepController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStepController.java
index ea5ade23e..0a4863c32 100644
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStepController.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStepController.java
@@ -18,12 +18,24 @@
*/
package com.arsdigita.cms.ui.authoring.assets.relatedinfo;
+import com.arsdigita.kernel.KernelConfig;
+
+import org.libreccm.configuration.ConfigurationManager;
import org.librecms.contentsection.AttachmentList;
import org.librecms.contentsection.AttachmentListManager;
+import org.librecms.contentsection.ContentItem;
+import org.librecms.contentsection.ContentItemRepository;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.persistence.EntityManager;
+import javax.transaction.Transactional;
/**
*
@@ -31,19 +43,206 @@ import javax.persistence.EntityManager;
*/
@RequestScoped
class RelatedInfoStepController {
-
+
@Inject
private AttachmentListManager attachmentListManager;
-
+
+ @Inject
+ private ConfigurationManager confManager;
+
+ @Inject
+ private ContentItemRepository itemRepo;
+
@Inject
private EntityManager entityManager;
-
+
+ private Locale defaultLocale;
+
+ @PostConstruct
+ private void init() {
+
+ final KernelConfig kernelConfig = confManager
+ .findConfiguration(KernelConfig.class);
+ defaultLocale = kernelConfig.getDefaultLocale();
+
+ }
+
+ @Transactional(Transactional.TxType.REQUIRED)
protected void saveAttachmentList(final AttachmentList attachmentList) {
-
+
if (attachmentList.getListId() == 0) {
entityManager.persist(attachmentList);
} else {
entityManager.merge(attachmentList);
}
- }
+ }
+
+ @Transactional(Transactional.TxType.REQUIRED)
+ void moveToFirst(final ContentItem selectedItem,
+ final AttachmentList listToMove) {
+
+ Objects.requireNonNull(selectedItem);
+ Objects.requireNonNull(listToMove);
+
+ final ContentItem item = itemRepo
+ .findById(selectedItem.getObjectId())
+ .orElseThrow(() -> new IllegalArgumentException(String
+ .format("No ContentItem with ID %d in the database.",
+ selectedItem.getObjectId())));
+
+ final AttachmentList toMove = attachmentListManager
+ .getAttachmentList(listToMove.getListId())
+ .orElseThrow(() -> new IllegalArgumentException(String
+ .format("No AttachmentList with ID %d in the database.",
+ listToMove.getListId())));
+
+ final List lists = item
+ .getAttachments()
+ .stream()
+ .sorted((list1, list2) -> list1.compareTo(list2))
+ .collect(Collectors.toList());
+
+ toMove.setOrder(0);
+ lists
+ .stream()
+ .filter(current -> !current.equals(toMove))
+ .forEach(current -> current.setOrder(current.getOrder() + 1));
+
+ lists.forEach(entityManager::merge);
+ }
+
+ @Transactional(Transactional.TxType.REQUIRED)
+ protected void moveAfter(final ContentItem selectedItem,
+ final AttachmentList listToMove,
+ final Long destId) {
+
+ Objects.requireNonNull(selectedItem);
+ Objects.requireNonNull(listToMove);
+
+ final ContentItem item = itemRepo
+ .findById(selectedItem.getObjectId())
+ .orElseThrow(() -> new IllegalArgumentException(String
+ .format("No ContentItem with ID %d in the database.",
+ selectedItem.getObjectId())));
+
+ final AttachmentList toMove = attachmentListManager
+ .getAttachmentList(listToMove.getListId())
+ .orElseThrow(() -> new IllegalArgumentException(String
+ .format("No AttachmentList with ID %d in the database.",
+ listToMove.getListId())));
+
+ final AttachmentList after = attachmentListManager
+ .getAttachmentList(destId)
+ .orElseThrow(() -> new IllegalArgumentException(String
+ .format("No AttachmentList with ID %d in the database.", destId)));
+
+ final List lists = item
+ .getAttachments()
+ .stream()
+ .sorted((list1, list2) -> list1.compareTo(list2))
+ .collect(Collectors.toList());
+
+ if (!lists.contains(toMove)) {
+ throw new IllegalArgumentException(String
+ .format("AttachmentList %d is not part of ContentItem %d.",
+ toMove.getListId(),
+ item.getObjectId()));
+ }
+
+ if (!lists.contains(after)) {
+ throw new IllegalArgumentException(String
+ .format("AttachmentList %d is not part of ContentItem %d.",
+ after.getListId(),
+ item.getObjectId()));
+ }
+
+ final int afterIndex = lists.indexOf(after);
+ for (int i = afterIndex + 1; i < lists.size(); i++) {
+ final AttachmentList current = lists.get(i);
+ current.setOrder(current.getOrder() + 1);
+ entityManager.merge(current);
+ }
+
+ toMove.setOrder(afterIndex + 1);
+ entityManager.merge(toMove);
+ }
+
+ protected void deleteList(final Long listId) {
+
+ final AttachmentList list = attachmentListManager
+ .getAttachmentList(listId)
+ .orElseThrow(() -> new IllegalArgumentException(String
+ .format("No AttachmentList with ID %d in the database.",
+ listId)));
+
+ entityManager.remove(list);
+ }
+
+ @Transactional(Transactional.TxType.REQUIRED)
+ List retrieveAttachmentLists(
+ final ContentItem forContentItem,
+ final Locale selectedLocale) {
+
+ final ContentItem item = itemRepo
+ .findById(forContentItem.getObjectId())
+ .orElseThrow(() -> new IllegalArgumentException(String
+ .format("No ContentItem with ID %d in the database.",
+ forContentItem.getObjectId())));
+
+ return item.getAttachments()
+ .stream()
+ .filter(list -> !list.getName().startsWith("."))
+ .map(list -> buildAttachmentListTableRow(list, selectedLocale))
+ .collect(Collectors.toList());
+
+ }
+
+ private AttachmentListTableRow buildAttachmentListTableRow(
+ final AttachmentList attachmentList,
+ final Locale selectedLocale) {
+
+ final AttachmentListTableRow row = new AttachmentListTableRow();
+
+ row.setListId(attachmentList.getListId());
+
+ row.setName(attachmentList.getName());
+ if (attachmentList.getTitle().hasValue(selectedLocale)) {
+ row.setTitle(attachmentList.getTitle().getValue(selectedLocale));
+ } else if (attachmentList.getTitle().hasValue(defaultLocale)) {
+ row.setTitle(attachmentList.getTitle().getValue(defaultLocale));
+ } else {
+ row.setTitle(attachmentList.getTitle().getValue());
+ }
+
+ if (attachmentList.getDescription().hasValue(selectedLocale)) {
+ row.setTitle(shortenDescription(attachmentList
+ .getDescription()
+ .getValue(selectedLocale)));
+ } else if (attachmentList.getDescription().hasValue(defaultLocale)) {
+ row.setTitle(shortenDescription(attachmentList
+ .getDescription()
+ .getValue(defaultLocale)));
+ } else {
+ row.setTitle(shortenDescription(attachmentList
+ .getDescription()
+ .getValue()));
+ }
+
+ return row;
+ }
+
+ private String shortenDescription(final String description) {
+
+ if (description.trim().length() < 140) {
+ return description.trim();
+ } else {
+ final String tmp = description.trim().substring(0, 140);
+
+ return String
+ .format("%s...",
+ tmp.substring(0, tmp.lastIndexOf(" ")));
+ }
+
+ }
+
}