From 9f6685cc22a14f9461e29d95cf32327d1631bc81 Mon Sep 17 00:00:00 2001 From: jensp Date: Sun, 20 Aug 2017 18:10:32 +0000 Subject: [PATCH] CCM NG/ccm-cms: Next part of RelatedInfoStep git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4913 8810af33-2d31-482b-a856-94f89814c4df --- .../relatedinfo/AttachmentTableRow.java | 57 +++++ .../assets/relatedinfo/AttachmentsTable.java | 197 ++++++++++++++++++ .../relatedinfo/AttachmentsTableModel.java | 114 ++++++++++ .../AttachmentsTableModelBuilder.java | 85 ++++++++ .../relatedinfo/RelatedInfoListForm.java | 31 ++- .../relatedinfo/RelatedInfoListTable.java | 107 ++++++---- .../RelatedInfoListTableModelBuilder.java | 3 +- .../assets/relatedinfo/RelatedInfoStep.java | 6 + .../RelatedInfoStepController.java | 76 ++++++- 9 files changed, 633 insertions(+), 43 deletions(-) create mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentTableRow.java create mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentsTable.java create mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentsTableModel.java create mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentsTableModelBuilder.java diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentTableRow.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentTableRow.java new file mode 100644 index 000000000..2b60a1bac --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentTableRow.java @@ -0,0 +1,57 @@ +/* + * 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 org.librecms.contentsection.Asset; + +/** + * + * @author Jens Pelzetter + */ +class AttachmentTableRow { + + private long attachmentId; + private String title; + private Class type; + + public long getAttachmentId() { + return attachmentId; + } + + public void setAttachmentId(final long attachmentId) { + this.attachmentId = attachmentId; + } + + public String getTitle() { + return title; + } + + public void setTitle(final String title) { + this.title = title; + } + + public Class getType() { + return type; + } + + public void setType(final Class type) { + this.type = type; + } + +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentsTable.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentsTable.java new file mode 100644 index 000000000..6aff69773 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentsTable.java @@ -0,0 +1,197 @@ +/* + * 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.cms.ui.authoring.assets.AttachmentSelectionModel; +import com.arsdigita.globalization.GlobalizedMessage; + +import org.libreccm.cdi.utils.CdiUtil; +import org.librecms.CmsConstants; +import org.librecms.contentsection.ItemAttachment; + +/** + * + * @author Jens Pelzetter + */ +class AttachmentsTable extends Table { + + protected static final int COL_TITLE = 0; + protected static final int COL_TYPE = 1; + protected static final int COL_MOVE = 2; + protected static final int COL_REMOVE = 3; + + private final RelatedInfoStep relatedInfoStep; + private final ItemSelectionModel itemSelectionModel; + private final AttachmentListSelectionModel attachmentListSelectionModel; + private final AttachmentSelectionModel selectedAttachmentModel; + private final AttachmentSelectionModel moveAttachmentModel; + private final StringParameter selectedLanguageParam; + + public AttachmentsTable( + final RelatedInfoStep relatedInfoStep, + final ItemSelectionModel itemSelectionModel, + final AttachmentListSelectionModel attachmentListSelectionModel, + final AttachmentSelectionModel selectedAttachmentModel, + final AttachmentSelectionModel moveAttachmentModel, + final StringParameter selectedLanguageParam) { + + super(); + + this.relatedInfoStep = relatedInfoStep; + this.itemSelectionModel = itemSelectionModel; + this.attachmentListSelectionModel = attachmentListSelectionModel; + this.selectedAttachmentModel = selectedAttachmentModel; + this.moveAttachmentModel = moveAttachmentModel; + this.selectedLanguageParam = selectedLanguageParam; + + final TableColumnModel columnModel = super.getColumnModel(); + columnModel.add(new TableColumn( + COL_TITLE, + new Label(new GlobalizedMessage( + "cms.ui.authoring.assets.related_info_step.attachment.title", + CmsConstants.CMS_BUNDLE)))); + columnModel.add(new TableColumn( + COL_TYPE, + new Label(new GlobalizedMessage( + "cms.ui.authoring.assets.related_info_step.attachment.type", + CmsConstants.CMS_BUNDLE)))); + columnModel.add(new TableColumn( + COL_MOVE, + new Label(new GlobalizedMessage( + "cms.ui.authoring.assets.related_info_step.attachment.move")))); + columnModel.add(new TableColumn( + COL_REMOVE, + new Label(new GlobalizedMessage( + "cms.ui.authoring.assets.related_info_step.attachment.remove")))); + + super + .setModelBuilder(new AttachmentsTableModelBuilder( + itemSelectionModel, + attachmentListSelectionModel, + moveAttachmentModel, + selectedLanguageParam)); + + super + .getColumn(COL_MOVE) + .setCellRenderer(new ControlLinkCellRenderer()); + super + .getColumn(COL_REMOVE) + .setCellRenderer(new ControlLinkCellRenderer()); + + 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_MOVE: { + if (moveAttachmentModel + .getSelectedKey(state) == null) { + moveAttachmentModel + .setSelectedKey(state, + Long.parseLong( + (String) event + .getRowKey())); + } else { + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final RelatedInfoStepController controller + = cdiUtil + .findBean( + RelatedInfoStepController.class); + + final ItemAttachment attachment + = moveAttachmentModel + .getSelectedAttachment(state); + + final Long destId = Long.parseLong( + (String) event.getRowKey()); + + controller.moveAfter( + attachmentListSelectionModel + .getSelectedAttachmentList(state), + attachment, + destId); + moveAttachmentModel.clearSelection(state); + + } + break; + } + case COL_REMOVE: { + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final RelatedInfoStepController controller = cdiUtil + .findBean(RelatedInfoStepController.class); + controller.removeAttachment(Long.parseLong( + (String) event.getRowKey())); + } + default: + throw new IllegalArgumentException(String + .format("Illegal column index: %d", + column.getModelIndex())); + } + + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void headSelected(final TableActionEvent event) { + //Nothing + } + + }); + + } + + private class ControlLinkCellRenderer 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/AttachmentsTableModel.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentsTableModel.java new file mode 100644 index 000000000..9d111ab32 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentsTableModel.java @@ -0,0 +1,114 @@ +/* + * 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.AttachmentSelectionModel; +import com.arsdigita.globalization.GlobalizedMessage; + +import org.libreccm.cdi.utils.CdiUtil; +import org.librecms.CmsConstants; +import org.librecms.assets.AssetTypeInfo; +import org.librecms.assets.AssetTypesManager; + +import java.util.Iterator; +import java.util.List; +import java.util.ResourceBundle; + +/** + * + * @author Jens Pelzetter + */ +class AttachmentsTableModel implements TableModel { + + private final PageState state; + private final AttachmentSelectionModel moveAttachmentModel; + + private final Iterator iterator; + private AttachmentTableRow currentRow; + + AttachmentsTableModel( + final List rows, + final PageState state, + final AttachmentSelectionModel moveAttachmentModel) { + + this.state = state; + this.moveAttachmentModel = moveAttachmentModel; + this.iterator = rows.iterator(); + } + + @Override + public int getColumnCount() { + return 4; + } + + @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 AttachmentsTable.COL_TITLE: + return currentRow.getTitle(); + case AttachmentsTable.COL_TYPE: { + final AssetTypesManager typesManager = CdiUtil + .createCdiUtil() + .findBean(AssetTypesManager.class); + final AssetTypeInfo typeInfo = typesManager + .getAssetTypeInfo(currentRow.getType()); + final ResourceBundle bundle = ResourceBundle + .getBundle(typeInfo.getLabelBundle()); + return bundle.getString(typeInfo.getLabelKey()); + } + case AttachmentsTable.COL_MOVE: + if (moveAttachmentModel.getSelectedAttachment(state) == null) { + return new Label(new GlobalizedMessage( + "cms.ui.authoring.assets.related_info_step.attachment.move", + CmsConstants.CMS_BUNDLE)); + } else { + return new Label(new GlobalizedMessage( + "cms.ui.authoring.assets.related_info_step.attachment.move_here", + CmsConstants.CMS_BUNDLE)); + } + case AttachmentsTable.COL_REMOVE: + return new Label(new GlobalizedMessage( + "cms.ui.authoring.assets.related_info_step.attachment.remove", + CmsConstants.CMS_BUNDLE)); + default: + throw new IllegalArgumentException(String.format( + "Illegal column index %d.", columnIndex)); + } + } + + @Override + public Object getKeyAt(final int columnIndex) { + return currentRow.getAttachmentId(); + } + +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentsTableModelBuilder.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentsTableModelBuilder.java new file mode 100644 index 000000000..33d15c893 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentsTableModelBuilder.java @@ -0,0 +1,85 @@ +/* + * 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.cms.ui.authoring.assets.AttachmentSelectionModel; +import com.arsdigita.util.LockableImpl; + +import org.libreccm.cdi.utils.CdiUtil; +import org.librecms.contentsection.AttachmentList; +import org.librecms.contentsection.ContentItem; + +import java.util.List; +import java.util.Locale; + +/** + * + * @author Jens Pelzetter + */ +class AttachmentsTableModelBuilder + extends LockableImpl + implements TableModelBuilder { + + private final ItemSelectionModel itemSelectionModel; + private final AttachmentListSelectionModel listSelectionModel; + private final AttachmentSelectionModel moveAttachmentModel; + private final StringParameter selectedLanguageParam; + + public AttachmentsTableModelBuilder( + final ItemSelectionModel itemSelectionModel, + final AttachmentListSelectionModel listSelectionModel, + final AttachmentSelectionModel moveAttachmentModel, + final StringParameter selectedLanguageParam) { + + super(); + + this.itemSelectionModel = itemSelectionModel; + this.listSelectionModel = listSelectionModel; + this.moveAttachmentModel = moveAttachmentModel; + this.selectedLanguageParam = selectedLanguageParam; + } + + @Override + public TableModel makeModel(final Table table, final PageState state) { + + final ContentItem selectedItem = itemSelectionModel + .getSelectedItem(state); + final AttachmentList list = listSelectionModel.getSelectedAttachmentList(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 + .retrieveAttachments(selectedItem, list, selectedLocale); + + return new AttachmentsTableModel(rows, state, moveAttachmentModel); + } + +} 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 29ff1ad39..a6e6fe798 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 @@ -29,11 +29,15 @@ import com.arsdigita.bebop.event.FormInitListener; import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.bebop.event.FormSubmissionListener; +import com.arsdigita.bebop.event.ParameterEvent; import com.arsdigita.bebop.form.Option; import com.arsdigita.bebop.form.SingleSelect; import com.arsdigita.bebop.form.Submit; import com.arsdigita.bebop.form.TextArea; import com.arsdigita.bebop.form.TextField; +import com.arsdigita.bebop.parameters.GlobalizedParameterListener; +import com.arsdigita.bebop.parameters.ParameterData; +import com.arsdigita.bebop.parameters.StringIsLettersOrDigitsValidationListener; import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.ui.authoring.assets.AttachmentListSelectionModel; @@ -224,6 +228,7 @@ class RelatedInfoListForm super.add(new Label(new GlobalizedMessage("cms.ui.assetlist.name", CmsConstants.CMS_BUNDLE))); nameField = new TextField("attachmentListName"); + nameField.addValidationListener(new AssetListNameValidator()); super.add(nameField); super.add(new Label(new GlobalizedMessage("cms.ui.assetlist.title", @@ -365,13 +370,35 @@ class RelatedInfoListForm @Override public void submitted(final FormSectionEvent event) throws FormProcessException { - + final PageState state = event.getPageState(); - + if (saveCancelSection.getCancelButton().isSelected(state)) { listSelectionModel.clearSelection(state); relatedInfoStep.showAttachmentListTable(state); } } + private class AssetListNameValidator extends GlobalizedParameterListener { + + public AssetListNameValidator() { + super.setError(new GlobalizedMessage( + "cms.ui.assetlist.name_cant_start_with_dot", + CmsConstants.CMS_BUNDLE)); + } + + @Override + public void validate(final ParameterEvent event) throws + FormProcessException { + + final ParameterData data = event.getParameterData(); + final String value = (String) data.getValue(); + + if (value.startsWith(".")) { + data.addError(getError()); + } + } + + } + } 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 index 643040eca..0709a41de 100644 --- 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 @@ -109,15 +109,18 @@ class RelatedInfoListTable extends Table { moveListModel, selectedLanguageParam)); + super + .getColumn(COL_NAME) + .setCellRenderer(new ControlLinkCellRenderer()); super .getColumn(COL_EDIT) - .setCellRenderer(new EditCellRenderer()); + .setCellRenderer(new ControlLinkCellRenderer()); super .getColumn(COL_MOVE) - .setCellRenderer(new MoveCellRenderer()); + .setCellRenderer(new ControlLinkCellRenderer()); super .getColumn(COL_DELETE) - .setCellRenderer(new DeleteCellRenderer()); + .setCellRenderer(new ControlLinkCellRenderer()); super .addTableActionListener(new TableActionListener() { @@ -132,6 +135,13 @@ class RelatedInfoListTable extends Table { .get(event.getColumn()); switch (column.getModelIndex()) { + case COL_NAME: + selectedListModel + .setSelectedKey(state, + Long.parseLong((String) event + .getRowKey())); + relatedInfoStep.showAttachmentsTable(state); + break; case COL_EDIT: selectedListModel .setSelectedKey(state, @@ -168,17 +178,22 @@ class RelatedInfoListTable extends Table { moveListModel.clearSelection(state); } break; - case COL_DELETE: + case COL_DELETE: { final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); final RelatedInfoStepController controller = cdiUtil .findBean(RelatedInfoStepController.class); controller.deleteList(Long .parseLong((String) event.getRowKey())); + break; + } + default: + throw new IllegalArgumentException(String + .format("Illegal column index: %d", + column.getModelIndex())); } } @Override - public void headSelected(final TableActionEvent event) { //Nothing } @@ -186,39 +201,7 @@ class RelatedInfoListTable extends Table { }); } - 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 { + private class ControlLinkCellRenderer implements TableCellRenderer { @Override public Component getComponent(final Table table, @@ -233,5 +216,53 @@ class RelatedInfoListTable extends Table { } } +// +// 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/RelatedInfoListTableModelBuilder.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListTableModelBuilder.java index 06aaca201..9bf752d3c 100644 --- 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 @@ -58,8 +58,7 @@ class RelatedInfoListTableModelBuilder } @Override - public TableModel makeModel(final Table table, - final PageState state) { + public TableModel makeModel(final Table table, final PageState state) { final ContentItem selectedItem = itemSelectionModel .getSelectedItem(state); 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 3022f9285..a19104ed7 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 @@ -151,4 +151,10 @@ public class RelatedInfoStep extends ResettableContainer { listToFirstLink.setVisible(state, false); } + void showAttachmentsTable(final PageState state) { + + + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + } 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 0a4863c32..e44984107 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 @@ -25,6 +25,8 @@ import org.librecms.contentsection.AttachmentList; import org.librecms.contentsection.AttachmentListManager; import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentItemRepository; +import org.librecms.contentsection.ItemAttachment; +import org.librecms.contentsection.ItemAttachmentManager; import java.util.List; import java.util.Locale; @@ -56,6 +58,9 @@ class RelatedInfoStepController { @Inject private EntityManager entityManager; + @Inject + private ItemAttachmentManager itemAttachmentManager; + private Locale defaultLocale; @PostConstruct @@ -167,6 +172,13 @@ class RelatedInfoStepController { entityManager.merge(toMove); } + protected void moveAfter(final AttachmentList list, + final ItemAttachment attachment, + final long destId) { + //ToDo + throw new UnsupportedOperationException(); + } + protected void deleteList(final Long listId) { final AttachmentList list = attachmentListManager @@ -179,7 +191,20 @@ class RelatedInfoStepController { } @Transactional(Transactional.TxType.REQUIRED) - List retrieveAttachmentLists( + protected void removeAttachment(final long attachmentId) { + + final ItemAttachment attachment = itemAttachmentManager + .findById(attachmentId) + .orElseThrow(() -> new IllegalArgumentException(String + .format("No ItemAttachment with ID %d in the database.", + attachmentId))); + + entityManager.remove(attachment); + + } + + @Transactional(Transactional.TxType.REQUIRED) + protected List retrieveAttachmentLists( final ContentItem forContentItem, final Locale selectedLocale) { @@ -197,6 +222,26 @@ class RelatedInfoStepController { } + @Transactional(Transactional.TxType.REQUIRED) + protected List retrieveAttachments( + final ContentItem selectedItem, + final AttachmentList fromList, + final Locale selectedLocale) { + + final AttachmentList list = attachmentListManager + .getAttachmentList(fromList.getListId()) + .orElseThrow(() -> new IllegalArgumentException(String + .format("No AttachmentList with ID %d in the database.", + fromList.getListId()))); + + return list + .getAttachments() + .stream() + .map(attachment -> buildAttachmentTableRow(attachment, + selectedLocale)) + .collect(Collectors.toList()); + } + private AttachmentListTableRow buildAttachmentListTableRow( final AttachmentList attachmentList, final Locale selectedLocale) { @@ -231,6 +276,35 @@ class RelatedInfoStepController { return row; } + private AttachmentTableRow buildAttachmentTableRow( + final ItemAttachment attachment, + final Locale selectedLocale) { + + final AttachmentTableRow row = new AttachmentTableRow(); + + row.setAttachmentId(attachment.getAttachmentId()); + if (attachment.getAsset().getTitle().hasValue(selectedLocale)) { + row.setTitle(attachment + .getAsset() + .getTitle() + .getValue(selectedLocale)); + } else if (attachment.getAsset().getTitle().hasValue(defaultLocale)) { + row.setTitle(attachment + .getAsset() + .getTitle() + .getValue(defaultLocale)); + } else { + row.setTitle(attachment + .getAsset() + .getTitle() + .getValue()); + } + + row.setType(attachment.getAsset().getClass()); + + return row; + } + private String shortenDescription(final String description) { if (description.trim().length() < 140) {