From 5e207835fc5971b667315b4ca6738c3261d756c4 Mon Sep 17 00:00:00 2001 From: jensp Date: Wed, 12 Jul 2017 16:00:09 +0000 Subject: [PATCH] CCM NG/ccm-cms: Next part of porting the editing step for managing the sections of a MulitPartArticle git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4866 8810af33-2d31-482b-a856-94f89814c4df Former-commit-id: 671c6dab9dd3bd14b3e3d7173425e2f73c03501e --- ...MultiPartArticleSectionStepController.java | 24 +- .../MultiPartArticleSectionsStep.java.todo | 242 ++++++++++++- .../ui/mparticle/SectionDeleteForm.java.todo | 61 ++-- .../ui/mparticle/SectionEditForm.java.todo | 168 ++++----- .../ui/mparticle/SectionSelectionModel.java | 2 +- .../ui/mparticle/SectionTable.java.todo | 342 +++++++----------- .../ui/mparticle/SectionTableModel.java.todo | 148 ++++++++ .../SectionTableModelBuilder.java.todo | 74 ++++ 8 files changed, 726 insertions(+), 335 deletions(-) create mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionTableModel.java.todo create mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionTableModelBuilder.java.todo diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleSectionStepController.java b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleSectionStepController.java index 3b8fa6a5d..99cd6f85d 100644 --- a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleSectionStepController.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleSectionStepController.java @@ -24,8 +24,11 @@ import org.librecms.contenttypes.MultiPartArticleSection; import org.librecms.contenttypes.MultiPartArticleSectionManager; import org.librecms.contenttypes.MultiPartArticleSectionRepository; +import java.util.List; + import javax.enterprise.context.RequestScoped; import javax.inject.Inject; +import javax.transaction.Transactional; /** * @@ -43,6 +46,21 @@ public class MultiPartArticleSectionStepController { @Inject private MultiPartArticleSectionManager sectionManager; + @Transactional(Transactional.TxType.REQUIRED) + public List retrieveSections( + final MultiPartArticle forArticle) { + + final MultiPartArticle article = itemRepo + .findById(forArticle.getObjectId(), + MultiPartArticle.class) + .orElseThrow(() -> new IllegalArgumentException(String + .format("No MultiPartArticle with ID %d in the database.", + forArticle.getObjectId()))); + + return article.getSections(); + } + + @Transactional(Transactional.TxType.REQUIRED) public void moveToFirst(final MultiPartArticle article, final MultiPartArticleSection section) { @@ -54,11 +72,11 @@ public class MultiPartArticleSectionStepController { article.getObjectId()))); final MultiPartArticleSection theSection = sectionRepo - .findById(section.getSectionId()) - .orElseThrow(() -> new IllegalArgumentException(String.format( + .findById(section.getSectionId()) + .orElseThrow(() -> new IllegalArgumentException(String.format( "No MultiPartArticleSection with ID %d in the database.", section.getSectionId()))); - + sectionManager.moveToFirst(article, section); } diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleSectionsStep.java.todo b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleSectionsStep.java.todo index e5b22e040..3cc8bcb2e 100644 --- a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleSectionsStep.java.todo +++ b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleSectionsStep.java.todo @@ -21,23 +21,35 @@ package com.arsdigita.cms.contenttypes.ui.mparticle; import com.arsdigita.bebop.ActionLink; import com.arsdigita.bebop.ColumnPanel; import com.arsdigita.bebop.Container; -import com.arsdigita.bebop.DefaultSingleSelectionModel; import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.Page; import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.SingleSelectionModel; +import com.arsdigita.bebop.event.ActionEvent; +import com.arsdigita.bebop.event.ActionListener; +import com.arsdigita.bebop.event.PrintEvent; +import com.arsdigita.bebop.event.PrintListener; +import com.arsdigita.bebop.event.TableActionEvent; +import com.arsdigita.bebop.event.TableActionListener; import com.arsdigita.bebop.parameters.LongParameter; import com.arsdigita.bebop.parameters.StringParameter; +import com.arsdigita.bebop.table.TableColumn; import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.contenttypes.ui.ResettableContainer; -import com.arsdigita.cms.ui.GlobalNavigation; +import com.arsdigita.cms.dispatcher.Utilities; import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; import com.arsdigita.globalization.GlobalizedMessage; +import com.arsdigita.kernel.KernelConfig; import org.libreccm.cdi.utils.CdiUtil; +import org.libreccm.security.PermissionChecker; import org.librecms.CmsConstants; +import org.librecms.contentsection.ContentItem; +import org.librecms.contentsection.privileges.ItemPrivileges; import org.librecms.contenttypes.MultiPartArticle; import org.librecms.contenttypes.MultiPartArticleSection; -import org.librecms.contenttypes.MultiPartArticleSectionManager; + +import java.util.Locale; /** * Authoring kit step to manage the sections of a MultiPartArticle. Process is @@ -126,8 +138,11 @@ public class MultiPartArticleSectionsStep extends ResettableContainer { sectionTable.setClassAttr(DATA_TABLE); // selected section is based on the selection in the SectionTable - selectedSectionModel = new SectionSelectionModel<>(sectionTable - .getRowSelectionModel()); + @SuppressWarnings("unchecked") + final SingleSelectionModel rowSelectionModel = sectionTable + .getRowSelectionModel(); + selectedSectionModel = new SectionSelectionModel<>( + MultiPartArticleSection.class, rowSelectionModel); sectionTable.setSectionModel(selectedSectionModel); @@ -149,17 +164,220 @@ public class MultiPartArticleSectionsStep extends ResettableContainer { beginLink.addActionListener(event -> { final PageState state = event.getPageState(); final MultiPartArticle article - = (MultiPartArticle) selectedArticleModel + = (MultiPartArticle) selectedArticleModel .getSelectedObject(state); final MultiPartArticleSection section = moveSectionModel - .getSelectedSection(state); - + .getSelectedSection(state); + final MultiPartArticleSectionStepController controller = CdiUtil - .createCdiUtil() - .findBean(MultiPartArticleSectionStepController.class); - + .createCdiUtil() + .findBean(MultiPartArticleSectionStepController.class); + controller.moveToFirst(article, section); }); - + moveSectionModel.addChangeListener(event -> { + final PageState state = event.getPageState(); + + if (moveSectionModel.getSelectedKey(state) == null) { + beginLink.setVisible(state, false); + moveSectionLabel.setVisible(state, false); + } else { + beginLink.setVisible(state, true); + moveSectionLabel.setVisible(state, true); + final String selectedLanguage = (String) state + .getValue(selectedLanguageParam); + final Locale selectedLocale; + if (selectedLanguage == null) { + selectedLocale = KernelConfig.getConfig().getDefaultLocale(); + } else { + selectedLocale = new Locale(selectedLanguage); + } + final Object[] parameterObj = { + moveSectionModel + .getSelectedSection(state) + .getTitle() + .getValue(selectedLocale) + }; + + moveSectionLabel + .setLabel(new GlobalizedMessage( + "cms.contenttypes.ui.mparticle.move_section_name", + CmsConstants.CMS_BUNDLE, + parameterObj)); + } + }); + + // handle clicks to preview or delete a Section + sectionTable.addTableActionListener(new TableActionListener() { + + @Override + public void cellSelected(final TableActionEvent event) { + final PageState state = event.getPageState(); + final TableColumn column = sectionTable + .getColumnModel() + .get(event.getColumn() + .intValue()); + + if (column.getModelIndex() == SectionTable.COL_INDEX_DELETE) { + onlyShowComponent(state, SECTION_DELETE + typeIdStr); + } else if (column.getModelIndex() == SectionTable.COL_INDEX_EDIT) { + onlyShowComponent(state, SECTION_EDIT + typeIdStr); + } + } + + @Override + public void headSelected(final TableActionEvent event) { + //Nothing + } + + }); + + panel.add(sectionTable); + panel.add(buildAddLink()); + + return panel; } + + /** + * Builds a container to hold a SectionEditForm and a link to return to the + * section list. + * + * @return + */ + protected Container buildSectionEdit() { + + final ColumnPanel panel = new ColumnPanel(1); + panel.setKey(SECTION_EDIT + typeIdStr); + panel.setBorderColor("#FFFFFF"); + panel.setPadColor("#FFFFFF"); + + // display an appropriate title + panel.add(new Label(event -> { + final PageState state = event.getPageState(); + final Label target = (Label) event.getTarget(); + + if (selectedSectionModel.getSelectedKey(state) == null) { + target.setLabel(new GlobalizedMessage( + "cms.contenttypes.ui.mparticle.add_section", + CmsConstants.CMS_BUNDLE)); + } else { + target.setLabel(new GlobalizedMessage( + "cms.contenttypes.ui.mparticle.edit_section", + CmsConstants.CMS_BUNDLE)); + } + })); + + sectionEditForm = new SectionEditForm(selectedArticleModel, + selectedSectionModel, + this, + selectedLanguageParam); + + panel.add(sectionEditForm); + panel.add(buildViewAllLink()); + panel.add(buildAddLink()); + + return panel; + } + + /** + * Builds a container to hold the component to confirm deletion of a + * section. + * + * @return + */ + protected Container buildSectionDelete() { + + final ColumnPanel panel = new ColumnPanel(1); + panel.setKey(SECTION_DELETE + typeIdStr); + panel.setBorderColor("#FFFFFF"); + panel.setPadColor("#FFFFFF"); + + panel.add(new Label(new GlobalizedMessage( + "cms.contenttypes.ui.mparticle.delete_section", + CmsConstants.CMS_BUNDLE))); + sectionDeleteForm = new SectionDeleteForm(selectedArticleModel, + selectedSectionModel); + sectionDeleteForm.addSubmissionListener(event -> { + + final PageState state = event.getPageState(); + onlyShowComponent(state, SECTION_TABLE + typeIdStr); + }); + + panel.add(sectionDeleteForm); + panel.add(buildViewAllLink()); + + return panel; + } + + /** + * Utility method to create a link to display the section list. + * + * @return + */ + protected ActionLink buildViewAllLink() { + final ActionLink viewAllLink = new ActionLink( + new GlobalizedMessage( + "cms.contenttypes.ui.mparticle.view_all_sections", + CmsConstants.CMS_BUNDLE)); + viewAllLink.setClassAttr(ACTION_LINK); + viewAllLink.addActionListener(event -> { + onlyShowComponent(event.getPageState(), + SECTION_TABLE + typeIdStr); + }); + + return viewAllLink; + } + + /** + * Utility method to create a link to display the section list. + * + * @return + */ + protected ActionLink buildAddLink() { + final ActionLink addLink = new ActionLink( + new GlobalizedMessage( + "cms.contenttypes.ui.mparticle.add_new_section", + CmsConstants.CMS_BUNDLE)) { + + @Override + public boolean isVisible(final PageState state) { + + final PermissionChecker permissionChecker = CdiUtil + .createCdiUtil() + .findBean(PermissionChecker.class); + final ContentItem item = selectedArticleModel + .getSelectedItem(state); + + return super.isVisible(state) + && permissionChecker.isPermitted(ItemPrivileges.EDIT, + item); + } + + }; + addLink.setClassAttr(ACTION_LINK); + addLink.addActionListener(event -> { + final PageState state = event.getPageState(); + selectedSectionModel.clearSelection(state); + onlyShowComponent(state, SECTION_EDIT + typeIdStr); + }); + + return addLink; + + } + + @Override + public void register(final Page page) { + + super.register(page); + + page.addGlobalStateParam(moveSectionParam); + page.setVisibleDefault(beginLink, false); + page.setVisibleDefault(moveSectionLabel, false); + } + + public String getTypeIDStr() { + return typeIdStr; + } + +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionDeleteForm.java.todo b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionDeleteForm.java.todo index 3fe19a903..fd560dc80 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionDeleteForm.java.todo +++ b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionDeleteForm.java.todo @@ -18,7 +18,6 @@ */ package com.arsdigita.cms.contenttypes.ui.mparticle; - import com.arsdigita.bebop.ColumnPanel; import com.arsdigita.bebop.Form; import com.arsdigita.bebop.FormProcessException; @@ -35,7 +34,9 @@ import com.arsdigita.cms.contenttypes.MultiPartArticle; import com.arsdigita.cms.contenttypes.util.MPArticleGlobalizationUtil; import com.arsdigita.cms.util.GlobalizationUtil; import com.arsdigita.util.Assert; + import org.apache.log4j.Logger; +import org.librecms.contenttypes.MultiPartArticleSection; /** * A form to confirm deletion of a single section of a MultiPartArticle. @@ -44,36 +45,36 @@ import org.apache.log4j.Logger; * @version $Id: SectionDeleteForm.java 287 2005-02-22 00:29:02Z sskracic $ */ public class SectionDeleteForm extends Form - implements FormInitListener, FormSubmissionListener, FormProcessListener -{ - private final static Logger log = Logger.getLogger(SectionDeleteForm.class.getName()); + implements FormInitListener, FormSubmissionListener, FormProcessListener { + + private final static Logger log = Logger.getLogger(SectionDeleteForm.class + .getName()); protected ItemSelectionModel m_selArticle; protected ItemSelectionModel m_selSection; protected SaveCancelSection m_saveCancelSection; private Label m_sectionNameLabel; - /** - * + * * @param selArticle - * @param selSection + * @param selSection */ - public SectionDeleteForm - ( ItemSelectionModel selArticle, - ItemSelectionModel selSection) { + public SectionDeleteForm( + final ItemSelectionModel selArticle, + final SectionSelectionModel selSection) { super("SectionDeleteForm", new ColumnPanel(2)); m_selArticle = selArticle; m_selSection = selSection; - ColumnPanel panel = (ColumnPanel)getPanel(); + ColumnPanel panel = (ColumnPanel) getPanel(); panel.setBorder(false); panel.setPadColor("#FFFFFF"); panel.setColumnWidth(1, "20%"); panel.setColumnWidth(2, "80%"); panel.setWidth("100%"); - m_sectionNameLabel = new Label ("Section Name"); + m_sectionNameLabel = new Label("Section Name"); add(m_sectionNameLabel, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT); addSaveCancelSection(); @@ -83,49 +84,52 @@ public class SectionDeleteForm extends Form } /** - * - * @return + * + * @return */ - protected SaveCancelSection addSaveCancelSection () { + protected SaveCancelSection addSaveCancelSection() { m_saveCancelSection = new SaveCancelSection(); m_saveCancelSection.getSaveButton().setButtonLabel( - GlobalizationUtil.globalize("cms.ui.delete")); + GlobalizationUtil.globalize("cms.ui.delete")); add(m_saveCancelSection, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT); return m_saveCancelSection; } @Override - public void init ( FormSectionEvent event ) throws FormProcessException { + public void init(FormSectionEvent event) throws FormProcessException { PageState state = event.getPageState(); - ArticleSection section = (ArticleSection)m_selSection.getSelectedObject(state); + ArticleSection section = (ArticleSection) m_selSection + .getSelectedObject(state); - if ( section == null ) { + if (section == null) { log.error("No section selected"); } else { - m_sectionNameLabel.setLabel(section.getTitle(),state); + m_sectionNameLabel.setLabel(section.getTitle(), state); } } @Override - public void submitted ( FormSectionEvent event ) throws FormProcessException { + public void submitted(FormSectionEvent event) throws FormProcessException { PageState state = event.getPageState(); - if ( m_saveCancelSection.getCancelButton().isSelected(state) ) { + if (m_saveCancelSection.getCancelButton().isSelected(state)) { throw new FormProcessException( - "Submission cancelled", - MPArticleGlobalizationUtil.globalize( - "cms.contenttypes.ui.mparticle.submission_cancelled") + "Submission cancelled", + MPArticleGlobalizationUtil.globalize( + "cms.contenttypes.ui.mparticle.submission_cancelled") ); } } @Override - public void process ( FormSectionEvent event ) throws FormProcessException { + public void process(FormSectionEvent event) throws FormProcessException { PageState state = event.getPageState(); - MultiPartArticle article = (MultiPartArticle)m_selArticle.getSelectedObject(state); - ArticleSection section = (ArticleSection)m_selSection.getSelectedObject(state); + MultiPartArticle article = (MultiPartArticle) m_selArticle + .getSelectedObject(state); + ArticleSection section = (ArticleSection) m_selSection + .getSelectedObject(state); Assert.exists(article, MultiPartArticle.class); Assert.exists(section, ArticleSection.class); @@ -134,4 +138,5 @@ public class SectionDeleteForm extends Form log.info("section " + m_selSection.getSelectedKey(state) + " delete"); } + } diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionEditForm.java.todo b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionEditForm.java.todo index 0e42c1733..b2f501ad2 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionEditForm.java.todo +++ b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionEditForm.java.todo @@ -18,7 +18,6 @@ */ package com.arsdigita.cms.contenttypes.ui.mparticle; - import com.arsdigita.bebop.ColumnPanel; import com.arsdigita.bebop.Form; import com.arsdigita.bebop.FormData; @@ -36,6 +35,7 @@ import com.arsdigita.bebop.form.CheckboxGroup; import com.arsdigita.bebop.form.Option; import com.arsdigita.bebop.parameters.BigDecimalParameter; import com.arsdigita.bebop.parameters.NotNullValidationListener; +import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.bebop.parameters.TrimmedStringParameter; import com.arsdigita.cms.ReusableImageAsset; import com.arsdigita.cms.ItemSelectionModel; @@ -46,11 +46,12 @@ import com.arsdigita.cms.ui.CMSDHTMLEditor; import com.arsdigita.cms.contenttypes.util.MPArticleGlobalizationUtil; import com.arsdigita.domain.DataObjectNotFoundException; import com.arsdigita.util.UncheckedWrapperException; + import org.apache.log4j.Logger; +import org.librecms.contenttypes.MultiPartArticleSection; import java.math.BigDecimal; - /** * Form to edit an ArticleSection for a MultiPartArticle. * @@ -74,13 +75,12 @@ public class SectionEditForm extends Form { private SaveCancelSection m_saveCancelSection; private ImageUploadSection m_imageUpload; + public static final String TITLE = "title"; + public static final String TEXT = "text"; + public static final String IMAGE = "image"; + public static final String PAGE_BREAK = "pageBreak"; - public static final String TITLE = "title"; - public static final String TEXT = "text"; - public static final String IMAGE = "image"; - public static final String PAGE_BREAK = "pageBreak"; - - private static final String TEXT_PARAM = "textParam"; + private static final String TEXT_PARAM = "textParam"; private static final String IMAGE_PARAM = "imageParam"; /** @@ -93,20 +93,24 @@ public class SectionEditForm extends Form { ItemSelectionModel selSection) { this(selArticle, selSection, null); } + /** * Constructor. * - * @param selArticle the current article - * @param selSection the current section - * @param container container which this form is added to + * @param selArticle the current article + * @param selSection the current section + * @param sectionsStep container which this form is added to */ - public SectionEditForm(ItemSelectionModel selArticle, - ItemSelectionModel selSection, - MultiPartArticleViewSections container) { + public SectionEditForm( + final ItemSelectionModel selArticle, + final SectionSelectionModel selSection, + final MultiPartArticleSectionsStep sectionsStep, + final StringParameter selectedLanguageParam) { + super("SectionEditForm", new ColumnPanel(2)); m_selArticle = selArticle; m_selSection = selSection; - m_container = container; + m_container = sectionsStep; m_imageParam = new BigDecimalParameter(IMAGE_PARAM); m_selImage = new ItemSelectionModel(ReusableImageAsset.class.getName(), @@ -121,7 +125,7 @@ public class SectionEditForm extends Form { setMethod(Form.POST); setEncType("multipart/form-data"); - ColumnPanel panel = (ColumnPanel)getPanel(); + ColumnPanel panel = (ColumnPanel) getPanel(); panel.setBorder(false); panel.setPadColor("#FFFFFF"); panel.setColumnWidth(1, "20%"); @@ -162,19 +166,19 @@ public class SectionEditForm extends Form { //add(new Label(MPArticleGlobalizationUtil // .globalize("cms.contenttypes.ui.mparticle.section.title"))); TextField titleWidget = new TextField( - new TrimmedStringParameter(TITLE)); + new TrimmedStringParameter(TITLE)); titleWidget.addValidationListener(new NotNullValidationListener()); titleWidget.setLabel(MPArticleGlobalizationUtil - .globalize("cms.contenttypes.ui.mparticle.section.title")); + .globalize("cms.contenttypes.ui.mparticle.section.title")); add(titleWidget); //add(new Label(MPArticleGlobalizationUtil // .globalize("cms.contenttypes.ui.mparticle.section.text")), // ColumnPanel.LEFT | ColumnPanel.FULL_WIDTH); - CMSDHTMLEditor textWidget = - new CMSDHTMLEditor(new TrimmedStringParameter(TEXT)); + CMSDHTMLEditor textWidget = new CMSDHTMLEditor( + new TrimmedStringParameter(TEXT)); textWidget.setLabel(MPArticleGlobalizationUtil - .globalize("cms.contenttypes.ui.mparticle.section.text")); + .globalize("cms.contenttypes.ui.mparticle.section.text")); textWidget.setRows(40); textWidget.setCols(70); textWidget.setWrap(CMSDHTMLEditor.SOFT); @@ -186,23 +190,25 @@ public class SectionEditForm extends Form { // ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT); m_imageUpload = new ImageUploadSection("image", m_selImage); m_imageUpload.setLabel(MPArticleGlobalizationUtil - .globalize("cms.contenttypes.ui.mparticle.section.image")); + .globalize("cms.contenttypes.ui.mparticle.section.image")); add(m_imageUpload, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT); //add(new Label()); CheckboxGroup pageBreak = new CheckboxGroup(PAGE_BREAK); - pageBreak.addOption(new Option("true", - new Label(MPArticleGlobalizationUtil - .globalize("cms.contenttypes.ui.mparticle.section.create_break")) )); + pageBreak.addOption(new Option("true", + new Label(MPArticleGlobalizationUtil + .globalize( + "cms.contenttypes.ui.mparticle.section.create_break")))); add(pageBreak); } /** * Utility method to create a Section from the form data supplied. - * + * * @param event * @param article - * @return + * + * @return */ protected ArticleSection createSection(FormSectionEvent event, MultiPartArticle article) { @@ -212,16 +218,16 @@ public class SectionEditForm extends Form { ArticleSection section = new ArticleSection(); - section.setTitle((String)data.get(TITLE)); - section.setName(article.getName() + ": " + (String)data.get(TITLE)); + section.setTitle((String) data.get(TITLE)); + section.setName(article.getName() + ": " + (String) data.get(TITLE)); section.setContentSection(article.getContentSection()); return section; } /** - * - * @param p + * + * @param p */ @Override public void register(Page p) { @@ -230,26 +236,24 @@ public class SectionEditForm extends Form { p.addGlobalStateParam(m_textParam); } - /** - * Initialize the form. If there is a selected section, ie. this - * is an 'edit' step rather than a 'create new' step, load the data - * into the form fields. + * Initialize the form. If there is a selected section, ie. this is an + * 'edit' step rather than a 'create new' step, load the data into the form + * fields. */ private class SectionInitListener implements FormInitListener { @Override - public void init( FormSectionEvent event ) + public void init(FormSectionEvent event) throws FormProcessException { PageState state = event.getPageState(); FormData data = event.getFormData(); m_selImage.setSelectedObject(state, null); - m_selText.setSelectedObject(state,null); + m_selText.setSelectedObject(state, null); - - if ( m_selSection.getSelectedKey(state) != null ) { + if (m_selSection.getSelectedKey(state) != null) { BigDecimal id = new BigDecimal(m_selSection - .getSelectedKey(state).toString()); + .getSelectedKey(state).toString()); try { // retrieve the selected Section from the persistence layer ArticleSection section = new ArticleSection(id); @@ -257,7 +261,7 @@ public class SectionEditForm extends Form { data.put(TITLE, section.getTitle()); TextAsset t = section.getText(); - if ( t != null ) { + if (t != null) { m_selText.setSelectedObject(state, t); data.put(TEXT, t.getText()); } @@ -268,10 +272,10 @@ public class SectionEditForm extends Form { } if (section.isPageBreak()) { - data.put(PAGE_BREAK, new Object[] { "true" }); + data.put(PAGE_BREAK, new Object[]{"true"}); } - } catch ( DataObjectNotFoundException ex ) { + } catch (DataObjectNotFoundException ex) { log.error("Section(" + id + ") could not be found"); } } @@ -280,53 +284,54 @@ public class SectionEditForm extends Form { // initializing the image section m_imageUpload.initImageUpload(event); } + } - /** - * Called on form submission. Check to see if the user clicked the - * cancel button. If they did, don't continue with the form. + * Called on form submission. Check to see if the user clicked the cancel + * button. If they did, don't continue with the form. */ private class SectionSubmissionListener implements FormSubmissionListener { @Override - public void submitted( FormSectionEvent event ) + public void submitted(FormSectionEvent event) throws FormProcessException { PageState state = event.getPageState(); - if ( m_saveCancelSection.getCancelButton() - .isSelected(state) && m_container != null) { + if (m_saveCancelSection.getCancelButton() + .isSelected(state) && m_container != null) { m_container.onlyShowComponent( - state, MultiPartArticleViewSections.SECTION_TABLE+ - m_container.getTypeIDStr()); + state, MultiPartArticleViewSections.SECTION_TABLE + + m_container.getTypeIDStr()); throw new FormProcessException( - "Submission cancelled", - MPArticleGlobalizationUtil.globalize( - "cms.contenttypes.ui.mparticle.submission_cancelled") + "Submission cancelled", + MPArticleGlobalizationUtil.globalize( + "cms.contenttypes.ui.mparticle.submission_cancelled") ); - } else if ( m_imageUpload.getDeleteImageButton().isSelected(state) ) { + } else if (m_imageUpload.getDeleteImageButton().isSelected(state)) { BigDecimal id = new BigDecimal(m_selSection - .getSelectedKey(state).toString()); - log.debug("deleting image for MPA section " + id); + .getSelectedKey(state).toString()); + log.debug("deleting image for MPA section " + id); try { - ArticleSection section = new ArticleSection(id); - section.setImage(null); - } catch ( DataObjectNotFoundException ex ) { + ArticleSection section = new ArticleSection(id); + section.setImage(null); + } catch (DataObjectNotFoundException ex) { log.error("Section(" + id + ") could not be found"); } } } + } /** - * Called after form has been validated. Create the new ArticleSection and + * Called after form has been validated. Create the new ArticleSection and * assign it to the current MultiPartArticle. */ private class SectionProcessListener implements FormProcessListener { @Override - public void process( FormSectionEvent event ) + public void process(FormSectionEvent event) throws FormProcessException { PageState state = event.getPageState(); FormData data = event.getFormData(); @@ -338,25 +343,24 @@ public class SectionEditForm extends Form { try { article = new MultiPartArticle(id); - } catch ( DataObjectNotFoundException ex ) { + } catch (DataObjectNotFoundException ex) { throw new UncheckedWrapperException(ex); } // get the selected section to update or create a new one - ArticleSection section = (ArticleSection) - m_selSection.getSelectedObject(state); - if ( section == null ) { + ArticleSection section = (ArticleSection) m_selSection + .getSelectedObject(state); + if (section == null) { section = createSection(event, article); article.addSection(section); } - section.setTitle((String)data.get(TITLE)); + section.setTitle((String) data.get(TITLE)); - Object[] pageBreakVal = (Object[])data.get(PAGE_BREAK); + Object[] pageBreakVal = (Object[]) data.get(PAGE_BREAK); boolean pageBreak; - if (pageBreakVal == null || - pageBreakVal.length == 0 || - !"true".equals(pageBreakVal[0])) { + if (pageBreakVal == null || pageBreakVal.length == 0 || !"true" + .equals(pageBreakVal[0])) { pageBreak = false; } else { pageBreak = true; @@ -364,36 +368,36 @@ public class SectionEditForm extends Form { section.setPageBreak(pageBreak); // get the image asset - ReusableImageAsset reusableImageAsset = - m_imageUpload.processImageUpload(event); - if ( reusableImageAsset != null ) { + ReusableImageAsset reusableImageAsset = m_imageUpload + .processImageUpload(event); + if (reusableImageAsset != null) { section.setImage(reusableImageAsset); m_selImage.setSelectedObject(state, reusableImageAsset); } - // get the text asset - TextAsset textAsset = (TextAsset)m_selText.getSelectedObject(state); - if ( textAsset == null ) { + TextAsset textAsset = (TextAsset) m_selText.getSelectedObject(state); + if (textAsset == null) { textAsset = new TextAsset(); textAsset.setName(section.getName() + " text"); m_selText.setSelectedObject(state, textAsset); section.setText(textAsset); } - String text = (String)data.get(TEXT); - if ( text == null ) { + String text = (String) data.get(TEXT); + if (text == null) { text = ""; } textAsset.setText(text); - if ( m_container != null) { + if (m_container != null) { m_container.onlyShowComponent( state, - MultiPartArticleViewSections.SECTION_TABLE+ - m_container.getTypeIDStr()); + MultiPartArticleViewSections.SECTION_TABLE + m_container + .getTypeIDStr()); } } + } } diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionSelectionModel.java b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionSelectionModel.java index 099bb29ad..2050a44e8 100644 --- a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionSelectionModel.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionSelectionModel.java @@ -38,7 +38,7 @@ import org.librecms.contenttypes.MultiPartArticleSectionRepository; * * @author Jens Pelzetter */ -class SectionSelectionModel +public class SectionSelectionModel implements SingleSelectionModel { private final Class clazz; diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionTable.java.todo b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionTable.java.todo index 243243a8b..ba02531a0 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionTable.java.todo +++ b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionTable.java.todo @@ -31,274 +31,195 @@ import com.arsdigita.bebop.table.TableColumnModel; import com.arsdigita.bebop.table.TableModel; import com.arsdigita.bebop.table.TableModelBuilder; import com.arsdigita.cms.CMS; -import com.arsdigita.cms.ContentItem; + +import org.librecms.contentsection.ContentItem; + import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.SecurityManager; -import com.arsdigita.cms.contenttypes.ArticleSection; -import com.arsdigita.cms.contenttypes.ArticleSectionCollection; -import com.arsdigita.cms.contenttypes.MultiPartArticle; -import com.arsdigita.cms.contenttypes.util.MPArticleGlobalizationUtil; -import com.arsdigita.domain.DomainObjectFactory; -import com.arsdigita.persistence.OID; +import com.arsdigita.globalization.GlobalizedMessage; + +import org.librecms.contenttypes.MultiPartArticleSection; +import org.librecms.contenttypes.MultiPartArticle; + import com.arsdigita.util.LockableImpl; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.libreccm.cdi.utils.CdiUtil; +import org.librecms.CmsConstants; +import org.librecms.contenttypes.MultiPartArticleSection; +import org.librecms.contenttypes.MultiPartArticleSectionRepository; import java.math.BigDecimal; +import java.util.Objects; /** - * A table that displays the sections for the currently - * selected MultiPartArticle. + * A table that displays the sections for the currently selected + * MultiPartArticle. * * @author Dave Turner - * @version $Id: SectionTable.java 2099 2010-04-17 15:35:14Z pboy $ + * @author Jens Pelzetter */ public class SectionTable extends Table { - private static final Logger s_log = Logger.getLogger(SectionTable.class); - // match columns by (symbolic) index, makes for easier reordering - public static final int COL_INDEX_TITLE = 0; // "Section"; - public static final int COL_INDEX_EDIT = 1; // "Edit"; - public static final int COL_INDEX_MOVE = 2; // "Move"; - public static final int COL_INDEX_DELETE = 3; // "Delete"; - private ItemSelectionModel m_selArticle; - private ItemSelectionModel m_selSection; - private ItemSelectionModel m_moveSection; + private static final Logger LOGGER = LogManager + .getLogger(SectionTable.class); /** - * Constructor. Create an instance of this class. - * - * @param selArticle a selection model that returns the MultiPartArticle - * which holds the sections to display. - * @param moveSection + * Index of the title column */ - public SectionTable(ItemSelectionModel selArticle, - ItemSelectionModel moveSection) { + public static final int COL_INDEX_TITLE = 0; + /** + * Index of the edit column. + */ + public static final int COL_INDEX_EDIT = 1; + /** + * Index of the move column + */ + public static final int COL_INDEX_MOVE = 2; + /** + * Index of the delete column + */ + public static final int COL_INDEX_DELETE = 3; + + private ItemSelectionModel selectedArticleModel; + private SectionSelectionModel selectedSectionModel; + private SectionSelectionModel moveSectionModel; + + /** + * Constructor. Create an instance of this class. + * + * @param selectedArticleModel a selection model that returns the + * MultiPartArticle which holds the sections to + * display. + * @param moveSectionModel + */ + public SectionTable( + final ItemSelectionModel selectedArticleModel, + final SectionSelectionModel moveSectionModel) { super(); - m_selArticle = selArticle; - m_moveSection = moveSection; + this.selectedArticleModel = selectedArticleModel; + this.moveSectionModel = moveSectionModel; - TableColumnModel model = getColumnModel(); + final TableColumnModel model = getColumnModel(); model.add(new TableColumn( - COL_INDEX_TITLE, - new Label(MPArticleGlobalizationUtil.globalize( - "cms.contenttypes.ui.mparticle.section_table.header_section")))); + COL_INDEX_TITLE, + new Label(new GlobalizedMessage( + "cms.contenttypes.ui.mparticle.section_table.header_section", + CmsConstants.CMS_BUNDLE)))); model.add(new TableColumn( - COL_INDEX_EDIT, - new Label(MPArticleGlobalizationUtil.globalize( - "cms.contenttypes.ui.mparticle.section_table.header_edit")))); + COL_INDEX_EDIT, + new Label(new GlobalizedMessage( + "cms.contenttypes.ui.mparticle.section_table.header_edit", + CmsConstants.CMS_BUNDLE)))); model.add(new TableColumn( - COL_INDEX_MOVE, - new Label(MPArticleGlobalizationUtil.globalize( - "cms.contenttypes.ui.mparticle.section_table.header_move")))); + COL_INDEX_MOVE, + new Label(new GlobalizedMessage( + "cms.contenttypes.ui.mparticle.section_table.header_move", + CmsConstants.CMS_BUNDLE)))); model.add(new TableColumn( - COL_INDEX_DELETE, - new Label(MPArticleGlobalizationUtil.globalize( - "cms.contenttypes.ui.mparticle.section_table.header_delete")))); + COL_INDEX_DELETE, + new Label(new GlobalizedMessage( + "cms.contenttypes.ui.mparticle.section_table.header_delete", + CmsConstants.CMS_BUNDLE)))); model.get(1).setCellRenderer(new SectionTableCellRenderer(true)); model.get(2).setCellRenderer(new SectionTableCellRenderer(true)); model.get(3).setCellRenderer(new SectionTableCellRenderer(true)); - - setModelBuilder(new SectionTableModelBuilder(m_selArticle, m_moveSection)); + setModelBuilder( + new SectionTableModelBuilder(selectedArticleModel, moveSectionModel)); addTableActionListener(new TableActionListener() { @Override - public void cellSelected(TableActionEvent event) { - PageState state = event.getPageState(); + public void cellSelected(final TableActionEvent event) { - TableColumn col = getColumnModel().get(event.getColumn() - .intValue()); + final PageState state = event.getPageState(); - if (col.getModelIndex() == COL_INDEX_MOVE) { - if (m_moveSection.getSelectedKey(state) == null) { - m_moveSection.setSelectedKey(state, - m_selSection - .getSelectedKey(state)); + final TableColumn column = getColumnModel() + .get(event.getColumn()); + + if (column.getModelIndex() == COL_INDEX_MOVE) { + + if (moveSectionModel.getSelectedKey(state) == null) { + moveSectionModel.setSelectedKey( + state, + selectedSectionModel.getSelectedKey(state)); } else { - MultiPartArticle article = (MultiPartArticle) m_selArticle. - getSelectedObject(state); + final MultiPartArticle article + = (MultiPartArticle) selectedArticleModel + .getSelectedObject(state); - BigDecimal id = (BigDecimal) m_moveSection.getSelectedKey(state); - ArticleSection sect = (ArticleSection) DomainObjectFactory.newInstance( - new OID(ArticleSection.BASE_DATA_OBJECT_TYPE, id)); + final Long sectionId = moveSectionModel + .getSelectedKey(state); - BigDecimal dest = - new BigDecimal((String) event.getRowKey()); - ArticleSection destSect = (ArticleSection) DomainObjectFactory.newInstance( - new OID(ArticleSection.BASE_DATA_OBJECT_TYPE, dest)); + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final MultiPartArticleSectionRepository sectionRepo + = cdiUtil + .findBean( + MultiPartArticleSectionRepository.class); + final MultiPartArticleSectionStepController controller + = cdiUtil + .findBean( + MultiPartArticleSectionStepController.class); + final MultiPartArticleSection section = sectionRepo + .findById(sectionId) + .orElseThrow(() -> new IllegalArgumentException( + String + .format( + "No MultiPartArticleSection with ID %d in " + + "the database.", + sectionId))); + + final Long destId = Long + .parseLong((String) event.getRowKey()); + final MultiPartArticleSection destSection = sectionRepo + .findById(destId) + .orElseThrow(() -> new IllegalArgumentException( + String.format( + "No MultiPartArticleSection with ID %d in " + + "the database.", + destId))); // if sect is lower in rank than the dest // then move below is default behavior - int rank = destSect.getRank().intValue(); - if (sect.getRank().intValue() > rank) { + int rank = destSection.getRank(); + if (section.getRank() > rank) { // otherwise, add one to get "move below" rank++; } - article.changeSectionRank(sect, rank); - m_moveSection.setSelectedKey(state, null); + section.setRank(rank); + sectionRepo.save(section); + moveSectionModel.setSelectedKey(state, null); } } } @Override - public void headSelected(TableActionEvent event) { + public void headSelected(final TableActionEvent event) { // do nothing } }); } - public void setSectionModel(ItemSelectionModel selSection) { - if (selSection == null) { - s_log.warn("null item model"); - } - m_selSection = selSection; + public void setSectionModel( + final SectionSelectionModel selectedSectionModel) { + + Objects.requireNonNull(selectedSectionModel); + + this.selectedSectionModel = selectedSectionModel; } - /** - * The model builder to generate a suitable model for the SectionTable - */ - protected class SectionTableModelBuilder extends LockableImpl - implements TableModelBuilder { - protected ItemSelectionModel m_selArticle; - protected ItemSelectionModel m_moveSection; - - /** - * Private class constructor. - * @param selArticle - * @param moveSection - */ - public SectionTableModelBuilder(ItemSelectionModel selArticle, - ItemSelectionModel moveSection) { - m_selArticle = selArticle; - m_moveSection = moveSection; - } - - /** - * - * @param table - * @param state - * @return - */ - @Override - public TableModel makeModel(Table table, PageState state) { - table.getRowSelectionModel().clearSelection(state); - - MultiPartArticle article = (MultiPartArticle) m_selArticle - .getSelectedObject(state); - - return new SectionTableModel(table, state, article, m_moveSection); - } - - } /** - * Internal class - */ - protected class SectionTableModel implements TableModel { - - private TableColumnModel m_colModel; - private SectionTable m_table; - private PageState m_state; - private ArticleSectionCollection m_sections; - private ItemSelectionModel m_moveSection; - private ArticleSection m_section; - - /** Constructor. - * @param table - * @param state - * @param article - * @param moveSection - */ - public SectionTableModel(Table table, PageState state, - MultiPartArticle article, - ItemSelectionModel moveSection) { - m_colModel = table.getColumnModel(); - m_state = state; - m_sections = article.getSections(); - m_table = (SectionTable) table; - m_moveSection = moveSection; - } - - /** Return the number of columsn this TableModel has. */ - @Override - public int getColumnCount() { - return m_colModel.size(); - } - - /** Move to the next row and return true if the model is now positioned - * on a valid row. - */ - @Override - public boolean nextRow() { - if (m_sections.next()) { - m_section = (ArticleSection) m_sections.getArticleSection(); - return true; - } - return false; - } - - /** - * Return the data element for the given column and the current row. - */ - @Override - public Object getElementAt(int columnIndex) { - - if (m_colModel == null) { - return null; - } - - // match columns by (symbolic) index, makes for easier reordering - if (columnIndex == COL_INDEX_TITLE) { - return m_section.getTitle(); - } else if (columnIndex == COL_INDEX_EDIT) { - //return "edit"; - return new Label( - MPArticleGlobalizationUtil.globalize( - "cms.contenttypes.ui.mparticle.section_table.link_edit")); - } else if (columnIndex == COL_INDEX_DELETE) { - // return "delete"; - return new Label( - MPArticleGlobalizationUtil.globalize( - "cms.contenttypes.ui.mparticle.section_table.link_delete")); - } else if (columnIndex == COL_INDEX_MOVE) { - if (m_moveSection.getSelectedKey(m_state) == null) { - // return "move"; - return new Label( - MPArticleGlobalizationUtil.globalize( - "cms.contenttypes.ui.mparticle.section_table.link_move")); - } else { - // return "move below here"; - return new Label( - MPArticleGlobalizationUtil.globalize( - "cms.contenttypes.ui.mparticle.section_table.link_move_below")); - } - } - - return null; - } - - /** - * Return the key for the given column and the current row. - */ - @Override - public Object getKeyAt(int columnIndex) { - return m_section.getID(); - } - - } - - /** - * + * */ public class SectionTableCellRenderer extends LockableImpl - implements TableCellRenderer { + implements TableCellRenderer { private boolean m_active; @@ -317,7 +238,9 @@ public class SectionTable extends Table { Component ret; SecurityManager sm = CMS.getSecurityManager(state); - ContentItem item = (ContentItem) m_selArticle.getSelectedObject(state); + ContentItem item = (ContentItem) selectedArticleModel + .getSelectedObject( + state); boolean active = m_active && sm.canAccess(state.getRequest(), SecurityManager.EDIT_ITEM, @@ -339,7 +262,7 @@ public class SectionTable extends Table { } } else { ret = new Label(MPArticleGlobalizationUtil.globalize( - "cms.contenttypes.ui.mparticle.section_table.link_not_defined"), + "cms.contenttypes.ui.mparticle.section_table.link_not_defined"), false); } @@ -347,4 +270,5 @@ public class SectionTable extends Table { } } + } diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionTableModel.java.todo b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionTableModel.java.todo new file mode 100644 index 000000000..9f3ea83eb --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionTableModel.java.todo @@ -0,0 +1,148 @@ +/* + * 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.contenttypes.ui.mparticle; + +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.Table; +import com.arsdigita.bebop.table.TableColumnModel; +import com.arsdigita.bebop.table.TableModel; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.globalization.GlobalizedMessage; + +import org.arsdigita.cms.CMSConfig; +import org.libreccm.cdi.utils.CdiUtil; +import org.librecms.CmsConstants; +import org.librecms.contenttypes.MultiPartArticle; +import org.librecms.contenttypes.MultiPartArticleSection; + +import java.util.Iterator; +import java.util.List; + +class SectionTableModel implements TableModel { + + private final TableColumnModel columnModel; + private final SectionTable sectionTable; + private final PageState pageState; + private final SectionSelectionModel moveSectionModel; + + private final Iterator iterator; + private MultiPartArticleSection currentSection; + + /** + * Constructor. + * + * @param sectionTable + * @param pageState + * @param article + * @param moveSectionModel + */ + public SectionTableModel( + final Table sectionTable, + final PageState pageState, + final MultiPartArticle article, + final SectionSelectionModel moveSectionModel) { + + this.pageState = pageState; + this.sectionTable = (SectionTable) sectionTable; + this.moveSectionModel = moveSectionModel; + + columnModel = sectionTable.getColumnModel(); + + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final MultiPartArticleSectionStepController controller = cdiUtil + .findBean(MultiPartArticleSectionStepController.class); + + final List sections = controller + .retrieveSections(article); + iterator = sections.iterator(); + } + + /** + * Return the number of columns this TableModel has. + */ + @Override + public int getColumnCount() { + return columnModel.size(); + } + + /** + * Move to the next row and return true if the model is now positioned on a + * valid row. + */ + @Override + public boolean nextRow() { + + if (iterator.hasNext()) { + currentSection = iterator.next(); + return true; + } else { + return false; + } + } + + /** + * Return the data element for the given column and the current row. + */ + @Override + public Object getElementAt(final int columnIndex) { + + if (columnModel == null) { + return null; + } + // match columns by (symbolic) index, makes for easier reordering + switch (columnIndex) { + case SectionTable.COL_INDEX_TITLE: + return currentSection.getTitle(); + case SectionTable.COL_INDEX_EDIT: + //return "edit"; + return new Label(new GlobalizedMessage( + "cms.contenttypes.ui.mparticle.section_table.link_edit", + CmsConstants.CMS_BUNDLE)); + case SectionTable.COL_INDEX_DELETE: + // return "delete"; + return new Label(new GlobalizedMessage( + "cms.contenttypes.ui.mparticle.section_table.link_delete", + CmsConstants.CMS_BUNDLE)); + case SectionTable.COL_INDEX_MOVE: + if (moveSectionModel.getSelectedKey(pageState) == null) { + // return "move"; + return new Label(new GlobalizedMessage( + "cms.contenttypes.ui.mparticle.section_table.link_move", + CmsConstants.CMS_BUNDLE)); + } else { + // return "move below here"; + return new Label(new GlobalizedMessage( + "cms.contenttypes.ui.mparticle.section_table.link_move_below", + CmsConstants.CMS_BUNDLE)); + } + default: + return null; + } + } + + /** + * Return the key for the given column and the current row. + */ + @Override + public Object getKeyAt(final int columnIndex) { + return currentSection.getSectionId(); + } + +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionTableModelBuilder.java.todo b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionTableModelBuilder.java.todo new file mode 100644 index 000000000..f98843a28 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/SectionTableModelBuilder.java.todo @@ -0,0 +1,74 @@ +/* + * 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.contenttypes.ui.mparticle; + +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.Table; +import com.arsdigita.bebop.table.TableModel; +import com.arsdigita.bebop.table.TableModelBuilder; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.util.LockableImpl; + +import org.librecms.contenttypes.MultiPartArticle; +import org.librecms.contenttypes.MultiPartArticleSection; + +/** + * The model builder to generate a suitable model for the SectionTable + */ +class SectionTableModelBuilder extends LockableImpl implements TableModelBuilder { + + private final ItemSelectionModel selectedArticleModel; + private final SectionSelectionModel moveSectionModel; + + /** + * Private class constructor. + * + * @param selectedArticleModel + * @param moveSectionModel + */ + public SectionTableModelBuilder( + final ItemSelectionModel selectedArticleModel, + final SectionSelectionModel moveSectionModel) { + + this.selectedArticleModel = selectedArticleModel; + this.moveSectionModel = moveSectionModel; + } + + /** + * + * @param table + * @param state + * + * @return + */ + @Override + public TableModel makeModel(final Table table, + final PageState state) { + + table.getRowSelectionModel().clearSelection(state); + MultiPartArticle article + = (MultiPartArticle) selectedArticleModel + .getSelectedObject(state); + return new SectionTableModel(table, + state, + article, + moveSectionModel); + } + +}