From 2d4708a679201be8f4849bb8361608d4f1ab7ccf Mon Sep 17 00:00:00 2001 From: jensp Date: Thu, 1 Sep 2011 10:09:14 +0000 Subject: [PATCH] =?UTF-8?q?-=20Beispiel=20f=C3=BCr=20ContentGenerator=20f?= =?UTF-8?q?=C3=BCr=20PublicPersonalProfile=20-=20Verbesserungen=20an=20der?= =?UTF-8?q?=20Admin-Oberfl=C3=A4che=20f=C3=BCr=20PublicPersonalProfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.libreccm.org/ccm/trunk@1085 8810af33-2d31-482b-a856-94f89814c4df --- .../ExampleGenerator.java | 20 +++ .../PublicPersonalProfilesServlet.java | 22 ++-- .../PublicPersonalProfileNavItemsAddForm.java | 115 ++++++++++++++---- .../PublicPersonalProfileNavItemsTable.java | 26 ++-- 4 files changed, 136 insertions(+), 47 deletions(-) create mode 100644 ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/ExampleGenerator.java diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/ExampleGenerator.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/ExampleGenerator.java new file mode 100644 index 000000000..de7703b50 --- /dev/null +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/ExampleGenerator.java @@ -0,0 +1,20 @@ +package com.arsdigita.cms.publicpersonalprofile; + +import com.arsdigita.cms.contenttypes.GenericPerson; +import com.arsdigita.xml.Element; + +/** + * An example implementation of the {@link ContentGenerator} interface. + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class ExampleGenerator implements ContentGenerator { + + public void generateContent(final Element parent, + final GenericPerson person) { + Element message = parent.newChildElement("message"); + + message.setText("Hello World!"); + } +} diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/PublicPersonalProfilesServlet.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/PublicPersonalProfilesServlet.java index 2186ac9ae..d81c913f3 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/PublicPersonalProfilesServlet.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/PublicPersonalProfilesServlet.java @@ -22,6 +22,7 @@ import com.arsdigita.cms.contenttypes.PublicPersonalProfileNavItemCollection; import com.arsdigita.cms.publicpersonalprofile.ui.PublicPersonalProfileNavItemsAddForm; import com.arsdigita.dispatcher.DispatcherHelper; import com.arsdigita.domain.DomainObjectFactory; +import com.arsdigita.kernel.ui.ACSObjectSelectionModel; import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.Session; @@ -39,7 +40,6 @@ import java.math.BigDecimal; import java.rmi.ServerException; import java.util.HashMap; import java.util.Map; -import java.util.logging.Level; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -60,6 +60,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet { private static final String PREVIEW = "preview"; private static final String PPP_NS = "http://www.arsdigita.com/PublicPersonalProfile/1.0"; + public static final String SELECTED_NAV_ITEM = "selectedNavItem"; private final PublicPersonalProfileConfig config = PublicPersonalProfiles. getConfig(); @@ -216,12 +217,13 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet { Class.forName(navItems.getNavItem(). getGeneratorClass()).getConstructor(). newInstance(); - + if (generatorObj instanceof ContentGenerator) { - final ContentGenerator generator = (ContentGenerator) generatorObj; - + final ContentGenerator generator = + (ContentGenerator) generatorObj; + generator.generateContent(root, owner); - + } else { throw new ServerException(String.format( "Class '%s' is not a ContentGenerator.", @@ -520,19 +522,19 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet { page.setClassAttr("adminPage"); - - final BoxPanel box = new BoxPanel(BoxPanel.VERTICAL); final FormSection tableSection = new FormSection(box); + final PublicPersonalProfileNavItemsAddForm addForm = + new PublicPersonalProfileNavItemsAddForm(); final PublicPersonalProfileNavItemsTable table = - new PublicPersonalProfileNavItemsTable(); - + new PublicPersonalProfileNavItemsTable( + addForm); box.add(table); form.add(tableSection); - box.add(new PublicPersonalProfileNavItemsAddForm()); + box.add(addForm); page.add(form); page.lock(); diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/ui/PublicPersonalProfileNavItemsAddForm.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/ui/PublicPersonalProfileNavItemsAddForm.java index 37c171345..e0615ec07 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/ui/PublicPersonalProfileNavItemsAddForm.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/ui/PublicPersonalProfileNavItemsAddForm.java @@ -10,6 +10,7 @@ import com.arsdigita.bebop.SaveCancelSection; 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.FormValidationListener; import com.arsdigita.bebop.form.Option; import com.arsdigita.bebop.form.SingleSelect; @@ -38,13 +39,16 @@ public class PublicPersonalProfileNavItemsAddForm extends FormSection implements FormInitListener, FormProcessListener, - FormValidationListener { + FormValidationListener, + FormSubmissionListener { private final FormSection widgetSection; private final SaveCancelSection saveCancelSection; + private PublicPersonalProfileNavItem selected; public PublicPersonalProfileNavItemsAddForm() { super(new ColumnPanel(2)); + widgetSection = new FormSection(new ColumnPanel(2, true)); super.add(widgetSection, ColumnPanel.INSERT); @@ -94,6 +98,15 @@ public class PublicPersonalProfileNavItemsAddForm labelField.addValidationListener(new NotEmptyValidationListener()); panel.add(labelField); + panel.add(new Label(PublicPersonalProfileGlobalizationUtil.globalize( + "publicpersonalprofile.ui.navitem.generatorclass"))); + final ParameterModel generatorParam = + new StringParameter( + PublicPersonalProfileNavItem.GENERATOR_CLASS); + final TextField generatorField = new TextField(generatorParam); + generatorField.setMaxLength(512); + panel.add(generatorField); + saveCancelSection = new SaveCancelSection(); super.add(saveCancelSection, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT); @@ -104,11 +117,24 @@ public class PublicPersonalProfileNavItemsAddForm } public void init(final FormSectionEvent fse) throws FormProcessException { - FormData data = fse.getFormData(); + final FormData data = fse.getFormData(); + final PageState state = fse.getPageState(); - data.put(PublicPersonalProfileNavItem.KEY, ""); - data.put(PublicPersonalProfileNavItem.LANG, ""); - data.put(PublicPersonalProfileNavItem.LABEL, ""); + if (selected == null) { + data.put(PublicPersonalProfileNavItem.KEY, ""); + data.put(PublicPersonalProfileNavItem.LANG, ""); + data.put(PublicPersonalProfileNavItem.LABEL, ""); + data.put(PublicPersonalProfileNavItem.GENERATOR_CLASS, ""); + } else { + data.put(PublicPersonalProfileNavItem.KEY, + selected.getKey()); + data.put(PublicPersonalProfileNavItem.LANG, + selected.getLang()); + data.put(PublicPersonalProfileNavItem.LABEL, + selected.getLabel()); + data.put(PublicPersonalProfileNavItem.GENERATOR_CLASS, + selected.getGeneratorClass()); + } } public void process(final FormSectionEvent fse) @@ -116,39 +142,74 @@ public class PublicPersonalProfileNavItemsAddForm final PageState state = fse.getPageState(); final FormData data = fse.getFormData(); - PublicPersonalProfileNavItemCollection navItems = - new PublicPersonalProfileNavItemCollection(); + if (saveCancelSection.getSaveButton().isSelected(state)) { + PublicPersonalProfileNavItemCollection navItems = + new PublicPersonalProfileNavItemCollection(); - final Map navItemMap = - new HashMap(); - while (navItems.next()) { - navItemMap.put(navItems.getNavItem().getKey(), navItems.getNavItem()); - } - final int numberOfKeys = navItemMap.size(); + final Map navItemMap = + new HashMap(); + while (navItems.next()) { + navItemMap.put(navItems.getNavItem().getKey(), navItems. + getNavItem()); + } + final int numberOfKeys = navItemMap.size(); - PublicPersonalProfileNavItem item = new PublicPersonalProfileNavItem(); + PublicPersonalProfileNavItem item; + if (selected == null) { + item = new PublicPersonalProfileNavItem(); + item.setId(new BigDecimal(navItems.size() + 1)); + } else { + item = selected; + } - item.setId(new BigDecimal(navItems.size() + 1)); - item.setKey((String) data.get(PublicPersonalProfileNavItem.KEY)); - item.setLang((String) data.get(PublicPersonalProfileNavItem.LANG)); - item.setLabel((String) data.get(PublicPersonalProfileNavItem.LABEL)); - final PublicPersonalProfileNavItem navItem = - navItemMap.get((String) data.get( - PublicPersonalProfileNavItem.KEY)); - if (navItem == null) { - item.setOrder(numberOfKeys + 1); - } else { - item.setOrder(navItem.getOrder()); + item.setKey((String) data.get(PublicPersonalProfileNavItem.KEY)); + item.setLang((String) data.get(PublicPersonalProfileNavItem.LANG)); + item.setLabel((String) data.get(PublicPersonalProfileNavItem.LABEL)); + if (data.get(PublicPersonalProfileNavItem.GENERATOR_CLASS) != null) { + item.setGeneratorClass((String) data.get( + PublicPersonalProfileNavItem.GENERATOR_CLASS)); + } + final PublicPersonalProfileNavItem navItem = + navItemMap.get((String) data.get( + PublicPersonalProfileNavItem.KEY)); + if (navItem == null) { + item.setOrder(numberOfKeys + 1); + } else { + item.setOrder(navItem.getOrder()); + } + + item.save(); } - item.save(); - + this.selected = null; data.put(PublicPersonalProfileNavItem.KEY, ""); data.put(PublicPersonalProfileNavItem.LANG, ""); data.put(PublicPersonalProfileNavItem.LABEL, ""); + data.put(PublicPersonalProfileNavItem.GENERATOR_CLASS, ""); } + @Override public void validate(final FormSectionEvent fse) throws FormProcessException { } + + @Override + public void submitted(final FormSectionEvent fse) + throws FormProcessException { + final PageState state = fse.getPageState(); + final FormData data = fse.getFormData(); + + if (saveCancelSection.getCancelButton().isSelected(state)) { + this.selected = null; + data.put(PublicPersonalProfileNavItem.KEY, ""); + data.put(PublicPersonalProfileNavItem.LANG, ""); + data.put(PublicPersonalProfileNavItem.LABEL, ""); + data.put(PublicPersonalProfileNavItem.GENERATOR_CLASS, ""); + } + } + + protected void setSelectedNavItem( + final PublicPersonalProfileNavItem selected) { + this.selected = selected; + } } diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/ui/PublicPersonalProfileNavItemsTable.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/ui/PublicPersonalProfileNavItemsTable.java index c4fdd2bd8..dcefb4469 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/ui/PublicPersonalProfileNavItemsTable.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/ui/PublicPersonalProfileNavItemsTable.java @@ -15,10 +15,8 @@ import com.arsdigita.bebop.table.TableModelBuilder; import com.arsdigita.cms.contenttypes.PublicPersonalProfileNavItem; import com.arsdigita.cms.contenttypes.PublicPersonalProfileNavItemCollection; import com.arsdigita.cms.contenttypes.ui.PublicPersonalProfileGlobalizationUtil; -import com.arsdigita.cms.dispatcher.Utilities; import com.arsdigita.util.LockableImpl; import java.math.BigDecimal; -import java.math.BigInteger; import java.util.HashSet; import java.util.Set; @@ -34,9 +32,14 @@ public class PublicPersonalProfileNavItemsTable private final static String TABLE_COL_UP = "table_col_up"; private final static String TABLE_COL_DOWN = "table_col_down"; private final static String TABLE_COL_DELETE = "table_col_delete"; - private final static String TABLE_COL_EDIT = "table_col_delete"; + private final static String TABLE_COL_EDIT = "table_col_edit"; + private final PublicPersonalProfileNavItemsAddForm addForm; + + public PublicPersonalProfileNavItemsTable( + final PublicPersonalProfileNavItemsAddForm addForm) { + + this.addForm = addForm; - public PublicPersonalProfileNavItemsTable() { setEmptyView(new Label(PublicPersonalProfileGlobalizationUtil.globalize( "publicpersonalprofile.ui.no_nav_items"))); @@ -114,19 +117,20 @@ public class PublicPersonalProfileNavItemsTable private final PageState state; private final PublicPersonalProfileNavItemCollection navItems = new PublicPersonalProfileNavItemCollection(); - private int lastOrder = 0; + private int lastOrder = 0; private int numberOfKeys; public PublicPersonalProfileNavItemsTableModel(final Table table, final PageState state) { this.table = table; - this.state = state; - final PublicPersonalProfileNavItemCollection items = new PublicPersonalProfileNavItemCollection(); + this.state = state; + final PublicPersonalProfileNavItemCollection items = + new PublicPersonalProfileNavItemCollection(); final Set keys = new HashSet(); - while(items.next()) { + while (items.next()) { keys.add(items.getNavItem().getKey()); } - numberOfKeys = keys.size(); + numberOfKeys = keys.size(); } public int getColumnCount() { @@ -164,7 +168,7 @@ public class PublicPersonalProfileNavItemsTable "publicpersonalprofile.ui.navitem.up").localize(); } case 7: - if ((navItems.getNavItem().getOrder() == lastOrder) + if ((navItems.getNavItem().getOrder() == lastOrder) || (navItems.getNavItem().getOrder() == numberOfKeys)) { return null; } else { @@ -290,7 +294,9 @@ public class PublicPersonalProfileNavItemsTable intValue()); if (TABLE_COL_EDIT.equals(column.getHeaderKey().toString())) { + addForm.setSelectedNavItem(navItem); } else if (TABLE_COL_DELETE.equals(column.getHeaderKey().toString())) { + navItem.delete(); } else if (TABLE_COL_UP.equals(column.getHeaderKey().toString())) { navItems.swapWithPrevious(navItem); } else if (TABLE_COL_DOWN.equals(column.getHeaderKey().toString())) {