From cf9ed68bfb0f17444c011163052cd2c0f0e091d6 Mon Sep 17 00:00:00 2001 From: jensp Date: Thu, 4 Sep 2014 11:52:51 +0000 Subject: [PATCH] All usages of SingleSelect/OptionGroup and PrintListener fixed by adding a clearOptions() in the PrintListener. Issue #2171. git-svn-id: https://svn.libreccm.org/ccm/trunk@2837 8810af33-2d31-482b-a856-94f89814c4df --- .../CategoryProviderContentTypeBlockForm.java | 1 + .../atoz/ui/admin/ItemProviderAliasForm.java | 76 +- .../ui/GenericOrgaUnitTextAssetEdit.java | 1 + .../ui/PublicPersonalProfileCreate.java | 1 + ...ublicPersonalProfileNavigationAddForm.java | 1 + .../ui/PublicPersonalProfilePropertyForm.java | 1 + .../ui/DecisionTreeOptionEditForm.java | 174 +- .../ui/DecisionTreeTargetEditForm.java | 243 +-- .../ContentSectionCreateForm.java | 3 +- .../ui/GenericAddressPropertyForm.java | 10 +- ...enericContactAttachPersonPropertyForm.java | 11 +- ...GenericContactEditAddressPropertyForm.java | 59 +- .../GenericContactEditPersonPropertyForm.java | 32 +- .../ui/GenericContactEntryAddForm.java | 6 +- .../ui/GenericContactTypeAddForm.java | 41 +- ...nericOrganizationalUnitContactAddForm.java | 65 +- ...enericOrganizationalUnitPersonAddForm.java | 22 +- .../ui/GenericPersonContactAddForm.java | 9 +- .../com/arsdigita/cms/ui/CategoryForm.java | 2 + .../cms/ui/SectionConfigurationPage.java | 1 + .../cms/ui/authoring/PageCreateDynamic.java | 1 + .../cms/ui/folder/AbstractFolderPicker.java | 1 + .../ui/lifecycle/ItemLifecycleSelectForm.java | 1 + .../cms/ui/templates/TemplateCreate.java | 1 + .../cms/ui/type/AddContentItemElement.java | 1 + .../com/arsdigita/cms/ui/type/AddType.java | 1 + .../com/arsdigita/cms/ui/type/CreateType.java | 3 + .../com/arsdigita/cms/ui/type/EditType.java | 2 + .../arsdigita/bebop/form/SearchAndSelect.java | 1 + .../ui/AbstractCategoryPicker.java | 1 + .../ui/editors/DataDrivenSelectForm.java | 1 + .../ui/editors/TemplateEmailForm.java | 1 + .../kernel/ui/PartySearchSelect.java | 2 + .../applications/ApplicationCreateForm.java | 2 + .../ui/BrowseFileInfoPropertiesPane.java | 1647 +++++++++-------- .../docmgr/ui/CategoriesPrintListener.java | 46 +- .../arsdigita/cms/docmgr/ui/FileEditForm.java | 426 ++--- .../arsdigita/cms/docmgr/ui/SearchPane.java | 212 +-- .../arsdigita/forum/ui/CategoryWidget.java | 47 +- .../london/atoz/ui/DomainProviderForm.java | 1 + .../london/cms/dublin/ui/ControlledList.java | 1 + .../terms/ui/admin/DomainContextForm.java | 71 +- .../terms/ui/admin/DomainMappingAddForm.java | 1 + .../navigation/ui/admin/CategoryForm.java | 1 + .../ui/admin/CategoryFormAddContext.java | 1 + .../ui/admin/NavigationCreateForm.java | 1 + .../portlet/NavigationTreePortletEditor.java | 1 + .../ui/portlet/ObjectListPortletEditor.java | 1 + .../permissions/ObjectPermissionEdit.java | 702 ++++--- .../permissions/PartyPermissionEdit.java | 1 + .../permissions/TypeSingleSelect.java | 27 +- .../portalserver/ui/admin/DisplayPane.java | 579 +++--- .../ui/ApplicationSelector.java | 38 +- .../portalworkspace/ui/LayoutForm.java | 138 +- .../portalworkspace/ui/PortletTypeForm.java | 154 +- .../ui/admin/GroupMemberPicker.java | 159 +- .../ui/admin/WorkspaceConfigFormSection.java | 111 +- .../ui/admin/WorkspaceCreateForm.java | 1 + .../ContentDirectoryPortletEditor.java | 172 +- .../ui/portlet/FlashPortletEditor.java | 115 +- .../ui/portlet/RSSFeedPortletBrowserForm.java | 209 +-- .../ui/admin/AnswerValuesPanel.java | 523 +++--- .../com/arsdigita/subsite/ui/SiteForm.java | 3 + .../themedirector/ui/ThemeControlPanel.java | 2 + .../cms/webpage/ui/WebpageCMSEditorPage.java | 1025 +++++----- 65 files changed, 3606 insertions(+), 3588 deletions(-) diff --git a/ccm-atoz/src/com/arsdigita/atoz/ui/admin/CategoryProviderContentTypeBlockForm.java b/ccm-atoz/src/com/arsdigita/atoz/ui/admin/CategoryProviderContentTypeBlockForm.java index cef802bcb..aafb9df24 100755 --- a/ccm-atoz/src/com/arsdigita/atoz/ui/admin/CategoryProviderContentTypeBlockForm.java +++ b/ccm-atoz/src/com/arsdigita/atoz/ui/admin/CategoryProviderContentTypeBlockForm.java @@ -81,6 +81,7 @@ public class CategoryProviderContentTypeBlockForm extends Form { public void prepare(PrintEvent e) { OptionGroup optionGroup = (OptionGroup) e.getTarget(); + optionGroup.clearOptions(); ContentTypeCollection ctc = ContentType .getRegisteredContentTypes(); ctc.addOrder(ContentType.LABEL); diff --git a/ccm-atoz/src/com/arsdigita/atoz/ui/admin/ItemProviderAliasForm.java b/ccm-atoz/src/com/arsdigita/atoz/ui/admin/ItemProviderAliasForm.java index 8fb5dcc82..73c4ecd70 100755 --- a/ccm-atoz/src/com/arsdigita/atoz/ui/admin/ItemProviderAliasForm.java +++ b/ccm-atoz/src/com/arsdigita/atoz/ui/admin/ItemProviderAliasForm.java @@ -15,7 +15,6 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - package com.arsdigita.atoz.ui.admin; import com.arsdigita.bebop.PageState; @@ -49,8 +48,8 @@ import java.math.BigDecimal; import java.util.TooManyListenersException; /** - * - * + * + * */ public class ItemProviderAliasForm extends Form { @@ -62,7 +61,7 @@ public class ItemProviderAliasForm extends Form { private SaveCancelSection m_buttons; public ItemProviderAliasForm(ACSObjectSelectionModel provider) { - super("itemAliasForm", new SimpleContainer()); + super("itemAliasForm", new SimpleContainer()); setRedirecting(true); m_provider = provider; @@ -75,37 +74,39 @@ public class ItemProviderAliasForm extends Form { m_letter = new SingleSelect("letter"); m_letter.addValidationListener(new NotNullValidationListener()); m_letter.addOption(new Option(null, "--Select one--")); - for (int i = 0 ; i < 26 ; i++) { - String letter = new String(new char[]{(char)((int)'a' + i)}); + for (int i = 0; i < 26; i++) { + String letter = new String(new char[]{(char) ((int) 'a' + i)}); m_letter.addOption(new Option(letter, letter.toUpperCase())); } m_item = new SingleSelect(new StringParameter("item")); try { m_item.addPrintListener(new PrintListener() { - public void prepare(PrintEvent event) { - OptionGroup group = (SingleSelect) event.getTarget(); - PageState state = event.getPageState(); - boolean valueSet = false; + public void prepare(PrintEvent event) { + OptionGroup group = (SingleSelect) event.getTarget(); + group.clearOptions(); + PageState state = event.getPageState(); + boolean valueSet = false; - Category category = ((ItemProvider) m_provider.getSelectedObject(state)) - .getCategory(); + Category category = ((ItemProvider) m_provider.getSelectedObject(state)) + .getCategory(); - CategorizedCollection children = category.getObjects(ContentItem.BASE_DATA_OBJECT_TYPE); - children.addOrder("name"); + CategorizedCollection children = category.getObjects( + ContentItem.BASE_DATA_OBJECT_TYPE); + children.addOrder("name"); - while (children.next()) { - ACSObject item = (ACSObject) children.getDomainObject(); + while (children.next()) { + ACSObject item = (ACSObject) children.getDomainObject(); - if ((item instanceof ContentItem) && - ((ContentItem) item).getVersion().equals(ContentItem.DRAFT)) { + if ((item instanceof ContentItem) && ((ContentItem) item).getVersion(). + equals(ContentItem.DRAFT)) { - group.addOption(new Option(item.getID().toString(), - ((ContentItem)item).getName())); - } + group.addOption(new Option(item.getID().toString(), + ((ContentItem) item).getName())); } } - }); + } + }); } catch (TooManyListenersException e) { //s_log.error("Error adding init listener to Radio Group", e); throw new UncheckedWrapperException(e); @@ -113,7 +114,7 @@ public class ItemProviderAliasForm extends Form { add(m_title); add(m_letter); - add(m_item); + add(m_item); m_buttons = new SaveCancelSection(new SimpleContainer()); add(m_buttons); @@ -121,10 +122,11 @@ public class ItemProviderAliasForm extends Form { addProcessListener(new ProviderProcessListener()); addSubmissionListener(new ProviderSubmissionListener()); } - + private class ProviderSubmissionListener implements FormSubmissionListener { + public void submitted(FormSectionEvent e) - throws FormProcessException { + throws FormProcessException { PageState state = e.getPageState(); if (m_buttons.getCancelButton().isSelected(state)) { @@ -135,27 +137,27 @@ public class ItemProviderAliasForm extends Form { } private class ProviderProcessListener implements FormProcessListener { + public void process(FormSectionEvent e) - throws FormProcessException { + throws FormProcessException { PageState state = e.getPageState(); ItemProvider provider = (ItemProvider) m_provider - .getSelectedObject(state); + .getSelectedObject(state); BigDecimal itemId = new BigDecimal(m_item.getValue(state).toString()); - ContentItem item = new ContentItem(itemId); + ContentItem item = new ContentItem(itemId); - String letter = (String)m_letter.getValue(state); - String title = (String)m_title.getValue(state); + String letter = (String) m_letter.getValue(state); + String title = (String) m_title.getValue(state); //provider.addAlias(item, letter, title); - - ItemAlias alias = (ItemAlias) Classes.newInstance(ItemAlias.class); - alias.setTitle(title); - alias.setLetter(letter); - alias.setContentItem(item); - alias.setItemProvider(provider); - alias.save(); + ItemAlias alias = (ItemAlias) Classes.newInstance(ItemAlias.class); + alias.setTitle(title); + alias.setLetter(letter); + alias.setContentItem(item); + alias.setItemProvider(provider); + alias.save(); fireCompletionEvent(state); } diff --git a/ccm-cms-assets-orgaunittext/src/com/arsdigita/cms/contentassets/ui/GenericOrgaUnitTextAssetEdit.java b/ccm-cms-assets-orgaunittext/src/com/arsdigita/cms/contentassets/ui/GenericOrgaUnitTextAssetEdit.java index b47e901e9..3a5099f0d 100644 --- a/ccm-cms-assets-orgaunittext/src/com/arsdigita/cms/contentassets/ui/GenericOrgaUnitTextAssetEdit.java +++ b/ccm-cms-assets-orgaunittext/src/com/arsdigita/cms/contentassets/ui/GenericOrgaUnitTextAssetEdit.java @@ -78,6 +78,7 @@ public class GenericOrgaUnitTextAssetEdit extends BasicItemForm implements FormS @Override public void prepare(final PrintEvent event) { final SingleSelect target = (SingleSelect) event.getTarget(); + target.clearOptions(); final RelationAttributeCollection names = new RelationAttributeCollection( "GenericOrgaUnitTextAssetName"); diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileCreate.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileCreate.java index 9b8f305c6..183b89fce 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileCreate.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileCreate.java @@ -102,6 +102,7 @@ public class PublicPersonalProfileCreate extends PageCreate { ownerSelect.addPrintListener(new PrintListener() { public void prepare(final PrintEvent event) { final SingleSelect ownerSelect = (SingleSelect) event.getTarget(); + ownerSelect.clearOptions(); String personType = config.getPersonType(); if ((personType == null) || (personType.isEmpty())) { diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileNavigationAddForm.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileNavigationAddForm.java index 9a2e6542a..272b2148b 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileNavigationAddForm.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileNavigationAddForm.java @@ -105,6 +105,7 @@ public class PublicPersonalProfileNavigationAddForm public void prepare(final PrintEvent event) { SingleSelect select = (SingleSelect) event.getTarget(); + select.clearOptions(); select.addOption(new Option("", "")); PublicPersonalProfileNavItemCollection navItems = diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfilePropertyForm.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfilePropertyForm.java index eb78c6a0e..e7cf1f6e0 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfilePropertyForm.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfilePropertyForm.java @@ -91,6 +91,7 @@ public class PublicPersonalProfilePropertyForm extends BasicPageForm implements ownerSelect.addPrintListener(new PrintListener() { public void prepare(final PrintEvent event) { final SingleSelect ownerSelect = (SingleSelect) event.getTarget(); + ownerSelect.clearOptions(); final PublicPersonalProfile profile = (PublicPersonalProfile) itemModel.getSelectedItem(event. getPageState()); diff --git a/ccm-cms-types-decisiontree/src/com/arsdigita/cms/contenttypes/ui/DecisionTreeOptionEditForm.java b/ccm-cms-types-decisiontree/src/com/arsdigita/cms/contenttypes/ui/DecisionTreeOptionEditForm.java index bd5126fad..23605492a 100644 --- a/ccm-cms-types-decisiontree/src/com/arsdigita/cms/contenttypes/ui/DecisionTreeOptionEditForm.java +++ b/ccm-cms-types-decisiontree/src/com/arsdigita/cms/contenttypes/ui/DecisionTreeOptionEditForm.java @@ -55,13 +55,13 @@ import com.arsdigita.cms.ItemSelectionModel; * @author Carsten Clasohm * @version $Id$ */ -public class DecisionTreeOptionEditForm extends Form - implements FormInitListener, - FormProcessListener, - FormSubmissionListener { +public class DecisionTreeOptionEditForm extends Form + implements FormInitListener, + FormProcessListener, + FormSubmissionListener { private final static Logger s_log = Logger.getLogger( - DecisionTreeOptionEditForm.class); + DecisionTreeOptionEditForm.class); private ItemSelectionModel m_selTree; private ItemSelectionModel m_selOption; @@ -71,9 +71,9 @@ public class DecisionTreeOptionEditForm extends Form private SaveCancelSection m_saveCancelSection; private SingleSelect m_sectionWidget; - public static final String LABEL = "label"; - public static final String VALUE = "value"; - public static final String SECTION = "section"; + public static final String LABEL = "label"; + public static final String VALUE = "value"; + public static final String SECTION = "section"; /** * Constructor. @@ -82,14 +82,14 @@ public class DecisionTreeOptionEditForm extends Form * @param selOption the current section */ public DecisionTreeOptionEditForm(ItemSelectionModel selTree, - ItemSelectionModel selOption) { + ItemSelectionModel selOption) { this(selTree, selOption, null); } - + /** * Constructor. * - * @param selTree the current decision tree + * @param selTree the current decision tree * @param selOption the current section * @param container container which this form is added to */ @@ -105,7 +105,7 @@ public class DecisionTreeOptionEditForm 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%"); @@ -133,7 +133,8 @@ public class DecisionTreeOptionEditForm extends Form /** * Returns the save/cancel section from this form. - * @return + * + * @return */ public SaveCancelSection getSaveCancelSection() { return m_saveCancelSection; @@ -143,9 +144,11 @@ public class DecisionTreeOptionEditForm extends Form * Set up the dynamic options for the section select widget. */ private void initSectionOptions(PrintEvent e) { - PageState state = e.getPageState(); - SingleSelect target = (SingleSelect) e.getTarget(); - DecisionTree tree = (DecisionTree)m_selTree.getSelectedObject(state); + PageState state = e.getPageState(); + SingleSelect target = (SingleSelect) e.getTarget(); + target.clearOptions(); + + DecisionTree tree = (DecisionTree) m_selTree.getSelectedObject(state); if (tree != null) { DecisionTreeSectionCollection sections = tree.getSections(); @@ -157,18 +160,19 @@ public class DecisionTreeOptionEditForm extends Form } sections.close(); } - } + } } - - /** + + /** * Form initialisation hook. + * * @param fse */ @Override public void init(FormSectionEvent fse) { PageState state = fse.getPageState(); FormData data = fse.getFormData(); - + if (m_selOption.getSelectedKey(state) != null) { BigDecimal id = new BigDecimal(m_selOption.getSelectedKey(state).toString()); // retrieve the selected Option from the persistence layer @@ -185,111 +189,109 @@ public class DecisionTreeOptionEditForm extends Form */ protected void addWidgets() { Option pleaseSelect = new Option( - "", - new Label(DecisionTreeGlobalizationUtil.globalize( - "cms.contenttypes.ui.decisiontree.options.form.please_select") - )); + "", + new Label(DecisionTreeGlobalizationUtil.globalize( + "cms.contenttypes.ui.decisiontree.options.form.please_select") + )); add(new Label(DecisionTreeGlobalizationUtil.globalize( "cms.contenttypes.ui.decisiontree.options.form.section"))); - m_sectionWidget = new SingleSelect(SECTION); - m_sectionWidget.addValidationListener(new NotNullValidationListener()); + m_sectionWidget = new SingleSelect(SECTION); + m_sectionWidget.addValidationListener(new NotNullValidationListener()); m_sectionWidget.addOption(pleaseSelect); - try { - m_sectionWidget.addPrintListener(new PrintListener() { - public void prepare(PrintEvent e) { - initSectionOptions(e); - } - }); - } catch (TooManyListenersException e) { + try { + m_sectionWidget.addPrintListener(new PrintListener() { + public void prepare(PrintEvent e) { + initSectionOptions(e); + } + }); + } catch (TooManyListenersException e) { throw new RuntimeException(e); } - - add(m_sectionWidget); + + add(m_sectionWidget); // add(new Label(DecisionTreeGlobalizationUtil.globalize( - // "cms.contenttypes.ui.decisiontree.options.form.label"))); - TextField labelWidget = new TextField(new TrimmedStringParameter(LABEL)); + // "cms.contenttypes.ui.decisiontree.options.form.label"))); + TextField labelWidget = new TextField(new TrimmedStringParameter(LABEL)); labelWidget.setLabel(DecisionTreeGlobalizationUtil.globalize( "cms.contenttypes.ui.decisiontree.options.form.label")); - labelWidget.addValidationListener(new NotNullValidationListener()); - labelWidget.setSize(60); - add(labelWidget); + labelWidget.addValidationListener(new NotNullValidationListener()); + labelWidget.setSize(60); + add(labelWidget); // add(new Label(DecisionTreeGlobalizationUtil.globalize( - // "cms.contenttypes.ui.decisiontree.options.form.value"))); - TextField valueWidget = new TextField(new TrimmedStringParameter(VALUE)); + // "cms.contenttypes.ui.decisiontree.options.form.value"))); + TextField valueWidget = new TextField(new TrimmedStringParameter(VALUE)); valueWidget.setLabel(DecisionTreeGlobalizationUtil.globalize( "cms.contenttypes.ui.decisiontree.options.form.value")); - valueWidget.addValidationListener(new NotNullValidationListener()); - valueWidget.setSize(60); - add(valueWidget); + valueWidget.addValidationListener(new NotNullValidationListener()); + valueWidget.setSize(60); + add(valueWidget); } /** * @param event - * @throws com.arsdigita.bebop.FormProcessException - * Called on form submission. Check to see if the user clicked the - * cancel button. If they did, don't continue with the form. + * @throws com.arsdigita.bebop.FormProcessException Called on form submission. Check to see if + * the user clicked the cancel button. If they did, don't continue with the form. */ @Override - public void submitted(FormSectionEvent event) - throws FormProcessException { - PageState state = event.getPageState(); + public void submitted(FormSectionEvent event) + throws FormProcessException { + PageState state = event.getPageState(); - if ( m_saveCancelSection.getCancelButton() - .isSelected(state) && m_container != null) { - m_container.onlyShowComponent( - state, DecisionTreeOptionStep.OPTION_TABLE + - m_container.getTypeIDStr()); - throw new FormProcessException( - DecisionTreeGlobalizationUtil.globalize( - "cms.contenttypes.ui.decisiontree.options.form.submission_cancelled") - ); - } + if (m_saveCancelSection.getCancelButton() + .isSelected(state) && m_container != null) { + m_container.onlyShowComponent( + state, DecisionTreeOptionStep.OPTION_TABLE + m_container.getTypeIDStr()); + throw new FormProcessException( + DecisionTreeGlobalizationUtil.globalize( + "cms.contenttypes.ui.decisiontree.options.form.submission_cancelled") + ); + } } /** - * Called after form has been validated. Create the new SectionOption and - * assign it to the current DecisionTree. - * + * Called after form has been validated. Create the new SectionOption and assign it to the + * current DecisionTree. + * * @param event * @throws com.arsdigita.bebop.FormProcessException */ @Override public void process(FormSectionEvent event) throws FormProcessException { - PageState state = event.getPageState(); - FormData data = event.getFormData(); + PageState state = event.getPageState(); + FormData data = event.getFormData(); - DecisionTreeSection section = new DecisionTreeSection(new BigDecimal((String)data.get(SECTION))); + DecisionTreeSection section = new DecisionTreeSection(new BigDecimal((String) data.get( + SECTION))); - DecisionTreeSectionOption option; + DecisionTreeSectionOption option; if (m_selOption.getSelectedKey(state) != null) { BigDecimal id = new BigDecimal(m_selOption - .getSelectedKey(state).toString()); + .getSelectedKey(state).toString()); // retrieve the selected Option from the persistence layer option = new DecisionTreeSectionOption(id); } else { - option = new DecisionTreeSectionOption(); - option.setName("DecisionTreeSectionOption " + option.getID()); - int rank = section.getMaxOptionRank() + 1; - option.setRank(Integer.valueOf(rank)); - } - - String label = (String)data.get(LABEL); - String value = (String)data.get(VALUE); + option = new DecisionTreeSectionOption(); + option.setName("DecisionTreeSectionOption " + option.getID()); + int rank = section.getMaxOptionRank() + 1; + option.setRank(Integer.valueOf(rank)); + } - option.setSection(section); - option.setLabel(label); - option.setValue(value); + String label = (String) data.get(LABEL); + String value = (String) data.get(VALUE); - if (m_container != null) { - m_container.onlyShowComponent( - state, - DecisionTreeOptionStep.OPTION_TABLE + - m_container.getTypeIDStr()); - } + option.setSection(section); + option.setLabel(label); + option.setValue(value); + + if (m_container != null) { + m_container.onlyShowComponent( + state, + DecisionTreeOptionStep.OPTION_TABLE + m_container.getTypeIDStr()); + } } @Override diff --git a/ccm-cms-types-decisiontree/src/com/arsdigita/cms/contenttypes/ui/DecisionTreeTargetEditForm.java b/ccm-cms-types-decisiontree/src/com/arsdigita/cms/contenttypes/ui/DecisionTreeTargetEditForm.java index f7c8742b7..b8e558714 100644 --- a/ccm-cms-types-decisiontree/src/com/arsdigita/cms/contenttypes/ui/DecisionTreeTargetEditForm.java +++ b/ccm-cms-types-decisiontree/src/com/arsdigita/cms/contenttypes/ui/DecisionTreeTargetEditForm.java @@ -58,13 +58,13 @@ import com.arsdigita.globalization.GlobalizedMessage; * @author Carsten Clasohm * @version $Id$ */ -public class DecisionTreeTargetEditForm extends Form - implements FormInitListener, - FormProcessListener, - FormSubmissionListener { +public class DecisionTreeTargetEditForm extends Form + implements FormInitListener, + FormProcessListener, + FormSubmissionListener { private final static Logger s_log = Logger.getLogger( - DecisionTreeTargetEditForm.class); + DecisionTreeTargetEditForm.class); private ItemSelectionModel m_selTree; private ItemSelectionModel m_selTarget; @@ -74,13 +74,13 @@ public class DecisionTreeTargetEditForm extends Form private SaveCancelSection m_saveCancelSection; // private SingleSelect m_sectionWidget; private SingleSelect m_matchValueWidget; - private SingleSelect m_targetSectionWidget; - private TextField m_targetURLWidget; + private SingleSelect m_targetSectionWidget; + private TextField m_targetURLWidget; - public static final String MATCH_OPTION = "matchOption"; - public static final String TARGET_URL = "targetURL"; + public static final String MATCH_OPTION = "matchOption"; + public static final String TARGET_URL = "targetURL"; public static final String TARGET_SECTION = "targetSection"; - + /** * Constructor. * @@ -91,7 +91,7 @@ public class DecisionTreeTargetEditForm extends Form ItemSelectionModel selTarget) { this(selTree, selTarget, null); } - + /** * Constructor. * @@ -111,7 +111,7 @@ public class DecisionTreeTargetEditForm 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%"); @@ -139,7 +139,8 @@ public class DecisionTreeTargetEditForm extends Form /** * Returns the save/cancel section from this form. - * @return + * + * @return */ public SaveCancelSection getSaveCancelSection() { return m_saveCancelSection; @@ -149,16 +150,18 @@ public class DecisionTreeTargetEditForm extends Form * Set up the dynamic options for the section select widget. */ private void initSectionOptions(PrintEvent e) { - PageState state = e.getPageState(); - SingleSelect target = (SingleSelect) e.getTarget(); - DecisionTree tree = (DecisionTree)m_selTree.getSelectedObject(state); + PageState state = e.getPageState(); + SingleSelect target = (SingleSelect) e.getTarget(); + target.clearOptions(); + DecisionTree tree = (DecisionTree) m_selTree.getSelectedObject(state); + if (tree != null) { DecisionTreeSectionCollection sections = tree.getSections(); if (sections != null) { while (sections.next()) { DecisionTreeSection section = sections.getSection(); - Option option = new Option(section.getID().toString(), + Option option = new Option(section.getID().toString(), section.getTitle()); target.addOption(option, state); } @@ -166,21 +169,22 @@ public class DecisionTreeTargetEditForm extends Form } } } - + /** * Set up the dynamic options for the target select widget. */ private void initTargetOptions(PrintEvent e) { - PageState state = e.getPageState(); - SingleSelect target = (SingleSelect) e.getTarget(); - DecisionTree tree = (DecisionTree)m_selTree.getSelectedObject(state); - + PageState state = e.getPageState(); + SingleSelect target = (SingleSelect) e.getTarget(); + target.clearOptions(); + DecisionTree tree = (DecisionTree) m_selTree.getSelectedObject(state); + if (tree != null) { DecisionTreeSectionCollection sections = tree.getSections(); if (sections != null) { while (sections.next()) { DecisionTreeSection section = sections.getSection(); - Option option = new Option(section.getID().toString(), + Option option = new Option(section.getID().toString(), section.getTitle()); target.addOption(option, state); } @@ -188,33 +192,36 @@ public class DecisionTreeTargetEditForm extends Form } } } - + /** * Set up the dynamic options for the match value select widget. */ private void initMatchOptions(PrintEvent e) { - PageState state = e.getPageState(); - SingleSelect target = (SingleSelect) e.getTarget(); - DecisionTree tree = (DecisionTree)m_selTree.getSelectedObject(state); - + PageState state = e.getPageState(); + SingleSelect target = (SingleSelect) e.getTarget(); + target.clearOptions(); + DecisionTree tree = (DecisionTree) m_selTree.getSelectedObject(state); + if (tree != null) { - DecisionTreeSectionOptionCollection sectionOptions = tree.getOptions(); + DecisionTreeSectionOptionCollection sectionOptions = tree.getOptions(); if (sectionOptions != null) { - while (sectionOptions.next()) { - DecisionTreeSectionOption sectionOption = sectionOptions - .getOption(); - String label = sectionOption.getSection().getTitle() + - " : " + sectionOption.getLabel(); - Option option = new Option(sectionOption.getID().toString(), + while (sectionOptions.next()) { + DecisionTreeSectionOption sectionOption = sectionOptions + .getOption(); + String label = sectionOption.getSection().getTitle() + " : " + sectionOption. + getLabel(); + Option option = new Option(sectionOption.getID().toString(), label); - target.addOption(option, state); - } - sectionOptions.close(); + target.addOption(option, state); + } + sectionOptions.close(); } } } - - /** Form initialisation hook. Sets the options for select widgets. + + /** + * Form initialisation hook. Sets the options for select widgets. + * * @param fse */ @Override @@ -224,15 +231,16 @@ public class DecisionTreeTargetEditForm extends Form if (m_selTarget.getSelectedKey(state) != null) { BigDecimal id = new BigDecimal(m_selTarget.getSelectedKey(state) - .toString()); + .toString()); DecisionTreeOptionTarget target = new DecisionTreeOptionTarget(id); data.put(MATCH_OPTION, target.getMatchOption().getID()); data.put(TARGET_URL, target.getTargetURL()); DecisionTreeSection targetSection = target.getTargetSection(); - if (targetSection != null) - data.put(TARGET_SECTION, targetSection.getID()); + if (targetSection != null) { + data.put(TARGET_SECTION, targetSection.getID()); + } } } @@ -241,47 +249,47 @@ public class DecisionTreeTargetEditForm extends Form */ protected void addWidgets() { Option pleaseSelect = new Option( - "", - new Label(DecisionTreeGlobalizationUtil.globalize( - "cms.contenttypes.ui.decisiontree.targets.form.please_select") )); + "", + new Label(DecisionTreeGlobalizationUtil.globalize( + "cms.contenttypes.ui.decisiontree.targets.form.please_select"))); Option none = new Option( - "", - new Label( DecisionTreeGlobalizationUtil.globalize( - "cms.contenttypes.ui.decisiontree.targets.form.none"))); - + "", + new Label(DecisionTreeGlobalizationUtil.globalize( + "cms.contenttypes.ui.decisiontree.targets.form.none"))); + // add(new Label(DecisionTreeGlobalizationUtil.globalize( - // "cms.contenttypes.ui.decisiontree.targets.form.match_value"))); - m_matchValueWidget = new SingleSelect(MATCH_OPTION); + // "cms.contenttypes.ui.decisiontree.targets.form.match_value"))); + m_matchValueWidget = new SingleSelect(MATCH_OPTION); m_matchValueWidget.setLabel(DecisionTreeGlobalizationUtil.globalize( - "cms.contenttypes.ui.decisiontree.targets.form.match_value")); - m_matchValueWidget.addValidationListener(new NotNullValidationListener()); - m_matchValueWidget.addOption(pleaseSelect); + "cms.contenttypes.ui.decisiontree.targets.form.match_value")); + m_matchValueWidget.addValidationListener(new NotNullValidationListener()); + m_matchValueWidget.addOption(pleaseSelect); try { m_matchValueWidget.addPrintListener(new PrintListener() { - @Override - public void prepare(PrintEvent e) { - initMatchOptions(e); - } + @Override + public void prepare(PrintEvent e) { + initMatchOptions(e); + } }); - } catch (TooManyListenersException e) { + } catch (TooManyListenersException e) { throw new RuntimeException(e); } add(m_matchValueWidget); // add(new Label(DecisionTreeGlobalizationUtil.globalize( - // "cms.contenttypes.ui.decisiontree.targets.form.target_url_label"))); - m_targetURLWidget = new TextField(TARGET_URL); + // "cms.contenttypes.ui.decisiontree.targets.form.target_url_label"))); + m_targetURLWidget = new TextField(TARGET_URL); m_targetURLWidget.setLabel(DecisionTreeGlobalizationUtil.globalize( "cms.contenttypes.ui.decisiontree.targets.form.target_url_label")); - m_targetURLWidget.setSize(60); - add(m_targetURLWidget); + m_targetURLWidget.setSize(60); + add(m_targetURLWidget); // add(new Label(DecisionTreeGlobalizationUtil.globalize( - // "cms.contenttypes.ui.decisiontree.targets.form.target_section_label"))); - m_targetSectionWidget = new SingleSelect(TARGET_SECTION); + // "cms.contenttypes.ui.decisiontree.targets.form.target_section_label"))); + m_targetSectionWidget = new SingleSelect(TARGET_SECTION); m_targetSectionWidget.setLabel(DecisionTreeGlobalizationUtil.globalize( "cms.contenttypes.ui.decisiontree.targets.form.target_section_label")); - m_targetSectionWidget.addOption(none); + m_targetSectionWidget.addOption(none); try { m_targetSectionWidget.addPrintListener(new PrintListener() { @Override @@ -289,7 +297,7 @@ public class DecisionTreeTargetEditForm extends Form initTargetOptions(e); } }); - } catch (TooManyListenersException e) { + } catch (TooManyListenersException e) { throw new RuntimeException(e); } add(m_targetSectionWidget); @@ -299,88 +307,87 @@ public class DecisionTreeTargetEditForm extends Form public final void validate(final FormSectionEvent event) throws FormProcessException { final PageState state = event.getPageState(); - if ("".equals(m_targetURLWidget.getValue(state)) - && "".equals(m_targetSectionWidget.getValue(state))) { - GlobalizedMessage msg = DecisionTreeGlobalizationUtil.globalize( - "cms.contenttypes.ui.decisiontree.targets.form.target_required"); - throw new FormProcessException(msg); + if ("".equals(m_targetURLWidget.getValue(state)) + && "".equals(m_targetSectionWidget.getValue(state))) { + GlobalizedMessage msg = DecisionTreeGlobalizationUtil.globalize( + "cms.contenttypes.ui.decisiontree.targets.form.target_required"); + throw new FormProcessException(msg); } - - if (!"".equals(m_targetURLWidget.getValue(state)) - && !"".equals(m_targetSectionWidget.getValue(state))) { - GlobalizedMessage msg = DecisionTreeGlobalizationUtil.globalize( - "cms.contenttypes.ui.decisiontree.targets.form.duplicate_target"); - throw new FormProcessException(msg); + + if (!"".equals(m_targetURLWidget.getValue(state)) + && !"".equals(m_targetSectionWidget.getValue(state))) { + GlobalizedMessage msg = DecisionTreeGlobalizationUtil.globalize( + "cms.contenttypes.ui.decisiontree.targets.form.duplicate_target"); + throw new FormProcessException(msg); } } }); } /** - * 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. + * * @param event * @throws com.arsdigita.bebop.FormProcessException */ @Override - public void submitted(FormSectionEvent event) - throws FormProcessException { - PageState state = event.getPageState(); + public void submitted(FormSectionEvent event) + throws FormProcessException { + PageState state = event.getPageState(); - if ( m_saveCancelSection.getCancelButton().isSelected(state) - && m_container != null) { - m_container.onlyShowComponent(state, - DecisionTreeTargetStep.TARGET_TABLE + - m_container.getTypeIDStr()); - throw new FormProcessException( + if (m_saveCancelSection.getCancelButton().isSelected(state) + && m_container != null) { + m_container.onlyShowComponent(state, + DecisionTreeTargetStep.TARGET_TABLE + m_container. + getTypeIDStr()); + throw new FormProcessException( DecisionTreeGlobalizationUtil.globalize( - "cms.contenttypes.ui.decisiontree.targets.form.submission_cancelled") - ); + "cms.contenttypes.ui.decisiontree.targets.form.submission_cancelled") + ); } } /** - * Called after form has been validated. Create the new - * DecisionTreeOptionTarget and assign it to the current DecisionTree. - * + * Called after form has been validated. Create the new DecisionTreeOptionTarget and assign it + * to the current DecisionTree. + * * @param event * @throws com.arsdigita.bebop.FormProcessException */ @Override public void process(FormSectionEvent event) throws FormProcessException { - PageState state = event.getPageState(); - FormData data = event.getFormData(); + PageState state = event.getPageState(); + FormData data = event.getFormData(); - DecisionTreeSectionOption matchOption = new - DecisionTreeSectionOption(new - BigDecimal((String)data.get(MATCH_OPTION))); - - DecisionTreeSection targetSection = null; - String sectionID = (String)data.get(TARGET_SECTION); - if (!"".equals(sectionID)) { - targetSection = new DecisionTreeSection(new BigDecimal(sectionID)); - } + DecisionTreeSectionOption matchOption = new DecisionTreeSectionOption(new BigDecimal( + (String) data.get(MATCH_OPTION))); - DecisionTreeOptionTarget target; + DecisionTreeSection targetSection = null; + String sectionID = (String) data.get(TARGET_SECTION); + if (!"".equals(sectionID)) { + targetSection = new DecisionTreeSection(new BigDecimal(sectionID)); + } + + DecisionTreeOptionTarget target; if (m_selTarget.getSelectedKey(state) != null) { BigDecimal id = new BigDecimal(m_selTarget - .getSelectedKey(state).toString()); + .getSelectedKey(state).toString()); target = new DecisionTreeOptionTarget(id); } else { - target = new DecisionTreeOptionTarget(); - target.setName("OptionTarget " + target.getID()); - } + target = new DecisionTreeOptionTarget(); + target.setName("OptionTarget " + target.getID()); + } target.setMatchOption(matchOption); - target.setTargetURL((String)data.get(TARGET_URL)); + target.setTargetURL((String) data.get(TARGET_URL)); target.setTargetSection(targetSection); - if (m_container != null) { - m_container.onlyShowComponent( - state, - DecisionTreeTargetStep.TARGET_TABLE + - m_container.getTypeIDStr()); - } + if (m_container != null) { + m_container.onlyShowComponent( + state, + DecisionTreeTargetStep.TARGET_TABLE + m_container.getTypeIDStr()); + } } @Override diff --git a/ccm-cms/src/com/arsdigita/cms/contentsection/ContentSectionCreateForm.java b/ccm-cms/src/com/arsdigita/cms/contentsection/ContentSectionCreateForm.java index 12e805d56..0fe69802e 100644 --- a/ccm-cms/src/com/arsdigita/cms/contentsection/ContentSectionCreateForm.java +++ b/ccm-cms/src/com/arsdigita/cms/contentsection/ContentSectionCreateForm.java @@ -76,7 +76,8 @@ public class ContentSectionCreateForm extends Form { @Override public void prepare(final PrintEvent event) { final SingleSelect target = (SingleSelect) event.getTarget(); - + target.clearOptions(); + final DataCollection categories = SessionManager.getSession().retrieve( Category.BASE_DATA_OBJECT_TYPE); Category current; diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericAddressPropertyForm.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericAddressPropertyForm.java index 88661f6b3..0242afac1 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericAddressPropertyForm.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericAddressPropertyForm.java @@ -124,19 +124,21 @@ public class GenericAddressPropertyForm extends BasicPageForm SingleSelect country = new SingleSelect(countryParam); country.setLabel(ContenttypesGlobalizationUtil .globalize("cms.contenttypes.ui.address.iso_country_code")); - country.addOption(new Option("", - new Label(GlobalizationUtil - .globalize("cms.ui.select_one")))); - + try { country.addPrintListener(new PrintListener() { @Override public void prepare(final PrintEvent event) { final SingleSelect target = (SingleSelect) event.getTarget(); + target.clearOptions(); final Iterator countries = GenericAddress.getSortedListOfCountries(null) .entrySet().iterator(); + target.addOption(new Option("", + new Label(GlobalizationUtil + .globalize("cms.ui.select_one")))); + while (countries.hasNext()) { Map.Entry elem = (Map.Entry) countries .next(); diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactAttachPersonPropertyForm.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactAttachPersonPropertyForm.java index 0f701efc4..2175ef24c 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactAttachPersonPropertyForm.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactAttachPersonPropertyForm.java @@ -118,16 +118,19 @@ public class GenericContactAttachPersonPropertyForm extends BasicPageForm contactType.setLabel(ContenttypesGlobalizationUtil.globalize( "cms.contenttypes.ui.genericperson.contact.type")); contactType.addValidationListener(new NotNullValidationListener()); - contactType.addOption(new Option("", - new Label(GlobalizationUtil - .globalize("cms.ui.select_one")))); + try { contactType.addPrintListener(new PrintListener() { @Override public void prepare(final PrintEvent event) { final SingleSelect target = (SingleSelect) event.getTarget(); - + target.clearOptions(); + + target.addOption(new Option("", + new Label(GlobalizationUtil + .globalize("cms.ui.select_one")))); + final GenericContactTypeCollection contacttypes = new GenericContactTypeCollection(); contacttypes.addLanguageFilter(GlobalizationHelper.getNegotiatedLocale(). diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactEditAddressPropertyForm.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactEditAddressPropertyForm.java index ecd8d9aef..4fdf18ca9 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactEditAddressPropertyForm.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactEditAddressPropertyForm.java @@ -57,12 +57,12 @@ import org.apache.log4j.Logger; * @author quasi, Created on 8. Juli 2009, 10:27 */ public class GenericContactEditAddressPropertyForm extends BasicPageForm - implements FormProcessListener, - FormInitListener, - FormSubmissionListener { + implements FormProcessListener, + FormInitListener, + FormSubmissionListener { private static final Logger logger = Logger.getLogger( - GenericContactPropertyForm.class); + GenericContactPropertyForm.class); public static final String ADDRESS = GenericAddress.ADDRESS; public static final String POSTAL_CODE = GenericAddress.POSTAL_CODE; @@ -106,7 +106,7 @@ public class GenericContactEditAddressPropertyForm extends BasicPageForm addressParam.addParameterListener(new StringInRangeValidationListener(0, 1000)); TextArea address = new TextArea(addressParam); address.setLabel(ContenttypesGlobalizationUtil - .globalize("cms.contenttypes.ui.address.address")); + .globalize("cms.contenttypes.ui.address.address")); address.setRows(5); address.setCols(30); add(address); @@ -115,7 +115,7 @@ public class GenericContactEditAddressPropertyForm extends BasicPageForm ParameterModel postalCodeParam = new StringParameter(POSTAL_CODE); TextField postalCode = new TextField(postalCodeParam); postalCode.setLabel(ContenttypesGlobalizationUtil - .globalize("cms.contenttypes.ui.address.postal_code")); + .globalize("cms.contenttypes.ui.address.postal_code")); /* XXX NumberListener ?*/ add(postalCode); } @@ -123,14 +123,14 @@ public class GenericContactEditAddressPropertyForm extends BasicPageForm ParameterModel cityParam = new StringParameter(CITY); TextField city = new TextField(cityParam); city.setLabel(ContenttypesGlobalizationUtil - .globalize("cms.contenttypes.ui.address.city")); + .globalize("cms.contenttypes.ui.address.city")); add(city); if (!GenericContact.getConfig().getHideAddressState()) { ParameterModel stateParam = new StringParameter(STATE); TextField state = new TextField(stateParam); state.setLabel(ContenttypesGlobalizationUtil - .globalize("cms.contenttypes.ui.address.state")); + .globalize("cms.contenttypes.ui.address.state")); add(state); } @@ -140,11 +140,7 @@ public class GenericContactEditAddressPropertyForm extends BasicPageForm SingleSelect country = new SingleSelect(countryParam); country.setLabel(ContenttypesGlobalizationUtil.globalize( - "cms.contenttypes.ui.address.iso_country_code")); - - country.addOption(new Option("", - new Label(ContenttypesGlobalizationUtil - .globalize("cms.ui.select_one")))); + "cms.contenttypes.ui.address.iso_country_code")); try { country.addPrintListener(new PrintListener() { @@ -152,14 +148,19 @@ public class GenericContactEditAddressPropertyForm extends BasicPageForm @Override public void prepare(final PrintEvent event) { final SingleSelect target = (SingleSelect) event.getTarget(); + target.clearOptions(); + target.addOption(new Option("", + new Label(ContenttypesGlobalizationUtil + .globalize("cms.ui.select_one")))); + final Iterator countries = GenericAddress.getSortedListOfCountries(null) - .entrySet().iterator(); + .entrySet().iterator(); while (countries.hasNext()) { Map.Entry elem = (Map.Entry) countries - .next(); + .next(); target.addOption(new Option(elem.getValue().toString(), - elem.getKey().toString())); + elem.getKey().toString())); } } @@ -169,21 +170,21 @@ public class GenericContactEditAddressPropertyForm extends BasicPageForm } country.addValidationListener( - new ParameterListener() { + new ParameterListener() { - @Override - public void validate(ParameterEvent e) throws FormProcessException { - ParameterData data = e.getParameterData(); - String isoCode = (String) data.getValue(); - if (isoCode == null || isoCode.length() == 0) { - data.addError((String) ContenttypesGlobalizationUtil - .globalize( - "cms.contenttypes.ui.address.error_iso_country") - .localize()); + @Override + public void validate(ParameterEvent e) throws FormProcessException { + ParameterData data = e.getParameterData(); + String isoCode = (String) data.getValue(); + if (isoCode == null || isoCode.length() == 0) { + data.addError((String) ContenttypesGlobalizationUtil + .globalize( + "cms.contenttypes.ui.address.error_iso_country") + .localize()); + } } - } - }); + }); add(country); } @@ -210,7 +211,7 @@ public class GenericContactEditAddressPropertyForm extends BasicPageForm @Override public void submitted(FormSectionEvent fse) { if (m_step != null - && getSaveCancelSection().getCancelButton().isSelected(fse.getPageState())) { + && getSaveCancelSection().getCancelButton().isSelected(fse.getPageState())) { m_step.cancelStreamlinedCreation(fse.getPageState()); } } diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactEditPersonPropertyForm.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactEditPersonPropertyForm.java index 454b9bd28..7296f1dcf 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactEditPersonPropertyForm.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactEditPersonPropertyForm.java @@ -56,9 +56,9 @@ import org.apache.log4j.Logger; * @author quasi */ public class GenericContactEditPersonPropertyForm extends BasicPageForm - implements FormProcessListener, - FormInitListener, - FormSubmissionListener { + implements FormProcessListener, + FormInitListener, + FormSubmissionListener { private static final Logger logger = Logger.getLogger(GenericContactPropertyForm.class); private GenericContactPersonPropertiesStep m_step; @@ -106,7 +106,7 @@ public class GenericContactEditPersonPropertyForm extends BasicPageForm surnameParam.addParameterListener(new StringInRangeValidationListener(0, 1000)); TextField surname = new TextField(surnameParam); surname.setLabel(ContenttypesGlobalizationUtil - .globalize("cms.contenttypes.ui.person.surname")); + .globalize("cms.contenttypes.ui.person.surname")); add(surname); ParameterModel givennameParam = new StringParameter(GIVENNAME); @@ -114,43 +114,45 @@ public class GenericContactEditPersonPropertyForm extends BasicPageForm givennameParam.addParameterListener(new StringInRangeValidationListener(0, 1000)); TextField givenname = new TextField(givennameParam); givenname.setLabel(ContenttypesGlobalizationUtil - .globalize("cms.contenttypes.ui.person.givenname")); + .globalize("cms.contenttypes.ui.person.givenname")); add(givenname); ParameterModel titlepreParam = new StringParameter(TITLEPRE); titlepreParam.addParameterListener(new StringInRangeValidationListener(0, 1000)); TextField titlepre = new TextField(titlepreParam); titlepre.setLabel(ContenttypesGlobalizationUtil - .globalize("cms.contenttypes.ui.person.titlepre")); + .globalize("cms.contenttypes.ui.person.titlepre")); add(titlepre); ParameterModel titlepostParam = new StringParameter(TITLEPOST); titlepostParam.addParameterListener(new StringInRangeValidationListener(0, 1000)); TextField titlepost = new TextField(titlepostParam); titlepost.setLabel(ContenttypesGlobalizationUtil - .globalize("cms.contenttypes.ui.person.titlepost")); + .globalize("cms.contenttypes.ui.person.titlepost")); add(titlepost); // GenericContact type field ParameterModel contactTypeParam = new StringParameter(CONTACTS_KEY); SingleSelect contactType = new SingleSelect(contactTypeParam); contactType.setLabel(ContenttypesGlobalizationUtil - .globalize("cms.contenttypes.ui.person.contact.type")); + .globalize("cms.contenttypes.ui.person.contact.type")); contactType.addValidationListener(new NotNullValidationListener()); - contactType.addOption(new Option("", - new Label(GlobalizationUtil - .globalize("cms.ui.select_one")))); try { contactType.addPrintListener(new PrintListener() { @Override public void prepare(final PrintEvent event) { final SingleSelect target = (SingleSelect) event.getTarget(); + target.clearOptions(); + + target.addOption(new Option("", + new Label(GlobalizationUtil + .globalize("cms.ui.select_one")))); final GenericContactTypeCollection contacttypes = new GenericContactTypeCollection(); contacttypes.addLanguageFilter(GlobalizationHelper - .getNegotiatedLocale().getLanguage()); + .getNegotiatedLocale().getLanguage()); while (contacttypes.next()) { RelationAttribute ct = contacttypes.getRelationAttribute(); @@ -171,7 +173,7 @@ public class GenericContactEditPersonPropertyForm extends BasicPageForm FormData data = fse.getFormData(); PageState state = fse.getPageState(); GenericContact contact = (GenericContact) getItemSelectionModel() - .getSelectedObject(state); + .getSelectedObject(state); if (contact.getPerson() != null) { data.put(SURNAME, contact.getPerson().getSurname()); @@ -184,7 +186,7 @@ public class GenericContactEditPersonPropertyForm extends BasicPageForm public void submitted(FormSectionEvent fse) { if (m_step != null - && getSaveCancelSection().getCancelButton().isSelected(fse.getPageState())) { + && getSaveCancelSection().getCancelButton().isSelected(fse.getPageState())) { m_step.cancelStreamlinedCreation(fse.getPageState()); } } @@ -193,7 +195,7 @@ public class GenericContactEditPersonPropertyForm extends BasicPageForm FormData data = fse.getFormData(); PageState state = fse.getPageState(); GenericContact contact = (GenericContact) getItemSelectionModel() - .getSelectedObject(state); + .getSelectedObject(state); if (getSaveCancelSection().getSaveButton().isSelected(fse.getPageState())) { diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactEntryAddForm.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactEntryAddForm.java index 95a2a7fb8..0486f307f 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactEntryAddForm.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactEntryAddForm.java @@ -74,14 +74,16 @@ public class GenericContactEntryAddForm extends BasicItemForm { contactEntryKey.setLabel(ContenttypesGlobalizationUtil.globalize( "cms.contenttypes.ui.genericcontact.contactEntry.key")); contactEntryKey.addValidationListener(new NotNullValidationListener()); - contactEntryKey.addOption(new Option("", new Label(GlobalizationUtil.globalize( - "cms.ui.select_one")))); try { contactEntryKey.addPrintListener(new PrintListener() { @Override public void prepare(final PrintEvent event) { final SingleSelect target = (SingleSelect) event.getTarget(); + target.clearOptions(); + + target.addOption(new Option("", new Label(GlobalizationUtil.globalize( + "cms.ui.select_one")))); final GenericContactEntryKeys keyList = new GenericContactEntryKeys(); // keyList.addLanguageFilter(GlobalizationHelper.getNegotiatedLocale() diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactTypeAddForm.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactTypeAddForm.java index a2afc365b..3263d9c6c 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactTypeAddForm.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericContactTypeAddForm.java @@ -45,15 +45,15 @@ import org.apache.log4j.Logger; /** * Generates a form for creating new localisations for the given category. * - * This class is part of the admin GUI of CCM and extends the standard form - * in order to present forms for managing the multi-language categories. + * This class is part of the admin GUI of CCM and extends the standard form in order to present + * forms for managing the multi-language categories. * * @author Sören Bernstein */ public class GenericContactTypeAddForm extends BasicItemForm { private static final Logger s_log = Logger.getLogger( - GenericContactTypeAddForm.class); + GenericContactTypeAddForm.class); public final static String KEY = RelationAttribute.KEY; public final static String LANGUAGE = RelationAttribute.LANGUAGE; @@ -63,7 +63,9 @@ public class GenericContactTypeAddForm extends BasicItemForm { private ItemSelectionModel m_itemModel; private SingleSelect language; - /** Creates a new instance of CategoryLocalizationAddForm */ + /** + * Creates a new instance of CategoryLocalizationAddForm + */ public GenericContactTypeAddForm(ItemSelectionModel itemModel) { super("ContactEntryAddForm", itemModel); @@ -79,16 +81,17 @@ public class GenericContactTypeAddForm extends BasicItemForm { keyParam.addParameterListener(new StringInRangeValidationListener(0, 1000)); TextField key = new TextField(keyParam); key.setLabel(ContenttypesGlobalizationUtil - .globalize("cms.contenttypes.ui.contacttypes.key")); + .globalize("cms.contenttypes.ui.contacttypes.key")); add(key); // Language ParameterModel languageParam = new StringParameter(LANGUAGE); language = new SingleSelect(languageParam); language.setLabel(ContenttypesGlobalizationUtil - .globalize("cms.contenttypes.ui.contacttypes.language")); + .globalize("cms.contenttypes.ui.contacttypes.language")); language.addValidationListener(new NotNullValidationListener()); - language.addOption(new Option("", new Label((String) ContenttypesGlobalizationUtil.globalize("cms.ui.select_one").localize()))); + language.addOption(new Option("", new Label((String) ContenttypesGlobalizationUtil. + globalize("cms.ui.select_one").localize()))); // Name ParameterModel nameParam = new StringParameter(NAME); @@ -96,20 +99,18 @@ public class GenericContactTypeAddForm extends BasicItemForm { nameParam.addParameterListener(new StringInRangeValidationListener(0, 1000)); TextField name = new TextField(nameParam); name.setLabel(ContenttypesGlobalizationUtil - .globalize("cms.contenttypes.ui.contacttypes.name")); + .globalize("cms.contenttypes.ui.contacttypes.name")); add(name); - } public void init(FormSectionEvent fse) { FormData data = fse.getFormData(); PageState state = fse.getPageState(); - RelationAttribute contacttype = (RelationAttribute) - getItemSelectionModel() - .getSelectedObject(state); - GenericContactTypeCollection contacttypeCollection = new - GenericContactTypeCollection(contacttype.getKey()); + RelationAttribute contacttype = (RelationAttribute) getItemSelectionModel() + .getSelectedObject(state); + GenericContactTypeCollection contacttypeCollection = new GenericContactTypeCollection( + contacttype.getKey()); // all supported languages (by registry entry) KernelConfig kernelConfig = Kernel.getConfig(); @@ -121,10 +122,9 @@ public class GenericContactTypeAddForm extends BasicItemForm { // If lanuage exists, remove it from the selection list if (!contacttypeCollection.hasLanguage(code)) { - language.addOption(new - Option(code, - new Locale(code).getDisplayLanguage()), - state); + language.addOption(new Option(code, + new Locale(code).getDisplayLanguage()), + state); } } @@ -138,9 +138,8 @@ public class GenericContactTypeAddForm extends BasicItemForm { public void process(FormSectionEvent fse) { FormData data = fse.getFormData(); PageState state = fse.getPageState(); - RelationAttribute contacttype = (RelationAttribute) - getItemSelectionModel() - .getSelectedObject(state); + RelationAttribute contacttype = (RelationAttribute) getItemSelectionModel() + .getSelectedObject(state); // if (!this.getSaveCancelSection().getCancelButton().isSelected(state)) { diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitContactAddForm.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitContactAddForm.java index 21a71baea..ed3972e2d 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitContactAddForm.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitContactAddForm.java @@ -56,11 +56,11 @@ import org.apache.log4j.Logger; * @author Jens Pelzetter */ public class GenericOrganizationalUnitContactAddForm - extends BasicItemForm - implements FormSubmissionListener { + extends BasicItemForm + implements FormSubmissionListener { private final static Logger s_log = Logger.getLogger( - GenericOrganizationalUnitContactAddForm.class); + GenericOrganizationalUnitContactAddForm.class); private GenericOrganizationalUnitPropertiesStep m_step; private ItemSearchWidget m_itemSearch; private SaveCancelSection m_saveCancelSection; @@ -80,12 +80,12 @@ public class GenericOrganizationalUnitContactAddForm @Override protected void addWidgets() { // add(new Label(ContenttypesGlobalizationUtil.globalize( - // "cms.contenttypes.ui.genericorgaunit.select_contact"))); + // "cms.contenttypes.ui.genericorgaunit.select_contact"))); m_itemSearch = new ItemSearchWidget(ITEM_SEARCH, ContentType. findByAssociatedObjectType(GenericContact.class - .getName())); + .getName())); m_itemSearch.setLabel(ContenttypesGlobalizationUtil.globalize( - "cms.contenttypes.ui.genericorgaunit.select_contact")); + "cms.contenttypes.ui.genericorgaunit.select_contact")); m_itemSearch.setDisableCreatePane(false); add(m_itemSearch); @@ -93,25 +93,28 @@ public class GenericOrganizationalUnitContactAddForm add(selectedContactLabel); ParameterModel contactTypeParam = new StringParameter( - GenericOrganizationalUnitContactCollection.CONTACT_TYPE); + GenericOrganizationalUnitContactCollection.CONTACT_TYPE); SingleSelect contactType = new SingleSelect(contactTypeParam); contactType.setLabel(ContenttypesGlobalizationUtil.globalize( - "cms.contenttypes.ui.genericorgaunit.contact.type")); + "cms.contenttypes.ui.genericorgaunit.contact.type")); contactType.addValidationListener(new NotNullValidationListener()); - contactType.addOption(new Option("", - new Label(ContenttypesGlobalizationUtil. - globalize("cms.ui.select_one")))); + try { contactType.addPrintListener(new PrintListener() { @Override public void prepare(final PrintEvent event) { final SingleSelect target = (SingleSelect) event.getTarget(); + target.clearOptions(); + + target.addOption(new Option("", + new Label(ContenttypesGlobalizationUtil. + globalize("cms.ui.select_one")))); final GenericOrganizationContactTypeCollection contacttypes - = new GenericOrganizationContactTypeCollection(); + = new GenericOrganizationContactTypeCollection(); contacttypes.addLanguageFilter(GlobalizationHelper.getNegotiatedLocale(). - getLanguage()); + getLanguage()); while (contacttypes.next()) { RelationAttribute ct = contacttypes.getRelationAttribute(); @@ -154,7 +157,7 @@ public class GenericOrganizationalUnitContactAddForm FormData data = fse.getFormData(); PageState state = fse.getPageState(); GenericOrganizationalUnit orgaunit = (GenericOrganizationalUnit) getItemSelectionModel(). - getSelectedObject(state); + getSelectedObject(state); if (this.getSaveCancelSection().getSaveButton().isSelected(state)) { GenericContact selectedContact; @@ -164,17 +167,17 @@ public class GenericOrganizationalUnitContactAddForm GenericContact contact = (GenericContact) data.get(ITEM_SEARCH); if (orgaunit.getLanguage().equals( - GlobalizationHelper.LANG_INDEPENDENT)) { + GlobalizationHelper.LANG_INDEPENDENT)) { contact = (GenericContact) contact.getContentBundle(). - getPrimaryInstance(); + getPrimaryInstance(); } else { contact = (GenericContact) contact.getContentBundle(). - getInstance(orgaunit.getLanguage()); + getInstance(orgaunit.getLanguage()); } orgaunit.addContact(contact, (String) data.get( - GenericOrganizationalUnitContactCollection.CONTACT_TYPE)); + GenericOrganizationalUnitContactCollection.CONTACT_TYPE)); } else { GenericOrganizationalUnitContactCollection contacts; @@ -187,7 +190,7 @@ public class GenericOrganizationalUnitContactAddForm } contacts.setContactType((String) data.get( - GenericOrganizationalUnitContactCollection.CONTACT_TYPE)); + GenericOrganizationalUnitContactCollection.CONTACT_TYPE)); editStep.setSelectedContact(null); editStep.setSelectedContactType(null); @@ -200,7 +203,7 @@ public class GenericOrganizationalUnitContactAddForm public void submitted(FormSectionEvent fse) throws FormProcessException { if (getSaveCancelSection().getCancelButton().isSelected( - fse.getPageState())) { + fse.getPageState())) { editStep.setSelectedContact(null); editStep.setSelectedContactType(null); @@ -214,16 +217,16 @@ public class GenericOrganizationalUnitContactAddForm final FormData data = fse.getFormData(); if ((editStep.getSelectedContact() == null) - && (data.get(ITEM_SEARCH) == null)) { + && (data.get(ITEM_SEARCH) == null)) { data.addError((ContenttypesGlobalizationUtil.globalize( - "cms.contenttypes.ui.genericorgaunit.select_contact.no_contact_selected"))); + "cms.contenttypes.ui.genericorgaunit.select_contact.no_contact_selected"))); return; } if (editStep.getSelectedContact() == null) { GenericOrganizationalUnit orgaunit = (GenericOrganizationalUnit) getItemSelectionModel() - .getSelectedObject(state); + .getSelectedObject(state); GenericContact contact = (GenericContact) data.get(ITEM_SEARCH); @@ -234,30 +237,30 @@ public class GenericOrganizationalUnitContactAddForm Kernel.getConfig(). languageIndependentItems()))) { data.addError( - ContenttypesGlobalizationUtil.globalize( - "cms.contenttypes.ui.genericorgaunit.select_contact.no_suitable_language_variant")); + ContenttypesGlobalizationUtil.globalize( + "cms.contenttypes.ui.genericorgaunit.select_contact.no_suitable_language_variant")); return; } } if (orgaunit.getLanguage().equals( - GlobalizationHelper.LANG_INDEPENDENT)) { + GlobalizationHelper.LANG_INDEPENDENT)) { contact = (GenericContact) contact.getContentBundle(). - getPrimaryInstance(); + getPrimaryInstance(); } else { contact = (GenericContact) contact.getContentBundle(). - getInstance(orgaunit.getLanguage()); + getInstance(orgaunit.getLanguage()); } GenericOrganizationalUnitContactCollection contacts = orgaunit. - getContacts(); + getContacts(); contacts.addFilter(String.format("id = %s", contact.getID().toString())); if (contacts.size() > 0) { data.addError( - ContenttypesGlobalizationUtil.globalize( - "cms.contenttypes.ui.genericorgaunit.select_contact.already_added")); + ContenttypesGlobalizationUtil.globalize( + "cms.contenttypes.ui.genericorgaunit.select_contact.already_added")); } contacts.close(); diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitPersonAddForm.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitPersonAddForm.java index 0713f6bdf..348a4237f 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitPersonAddForm.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitPersonAddForm.java @@ -100,19 +100,22 @@ public class GenericOrganizationalUnitPersonAddForm roleSelect.setLabel(ContenttypesGlobalizationUtil.globalize( "cms.contenttypes.ui.genericorgaunit.person.role")); roleSelect.addValidationListener(new NotNullValidationListener()); - roleSelect.addOption( - new Option("", - new Label(ContenttypesGlobalizationUtil - .globalize("cms.ui.select_one")))); + try { roleSelect.addPrintListener(new PrintListener() { @Override public void prepare(final PrintEvent event) { final SingleSelect target = (SingleSelect) event.getTarget(); + target.clearOptions(); + + target.addOption( + new Option("", + new Label(ContenttypesGlobalizationUtil + .globalize("cms.ui.select_one")))); final RelationAttributeCollection roles = new RelationAttributeCollection( - getRoleAttributeName()); + getRoleAttributeName()); roles.addLanguageFilter(Kernel.getConfig().getDefaultLanguage()); while (roles.next()) { RelationAttribute role; @@ -139,15 +142,18 @@ public class GenericOrganizationalUnitPersonAddForm statusSelect.setLabel(ContenttypesGlobalizationUtil.globalize( "cms.contenttypes.ui.genericorgaunit.person.status")); statusSelect.addValidationListener(new NotNullValidationListener()); - statusSelect.addOption(new Option("", - new Label(ContenttypesGlobalizationUtil. - globalize("cms.ui.select_one")))); try { statusSelect.addPrintListener(new PrintListener() { @Override public void prepare(final PrintEvent event) { final SingleSelect target = (SingleSelect) event.getTarget(); + target.clearOptions(); + + statusSelect.addOption(new Option("", + new Label(ContenttypesGlobalizationUtil. + globalize("cms.ui.select_one")))); + RelationAttributeCollection statusColl = new RelationAttributeCollection( getStatusAttributeName()); statusColl.addLanguageFilter(Kernel.getConfig().getDefaultLanguage()); diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonContactAddForm.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonContactAddForm.java index c74f1ba29..3737e49ac 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonContactAddForm.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonContactAddForm.java @@ -100,15 +100,18 @@ public class GenericPersonContactAddForm extends BasicItemForm { contactType.setLabel(ContenttypesGlobalizationUtil.globalize( "cms.contenttypes.ui.genericperson.contact.type")); contactType.addValidationListener(new NotNullValidationListener()); - contactType.addOption(new Option("", - new Label(GlobalizationUtil. - globalize("cms.ui.select_one")))); try { contactType.addPrintListener(new PrintListener() { @Override public void prepare(final PrintEvent event) { final SingleSelect target = (SingleSelect) event.getTarget(); + target.clearOptions(); + + target.addOption(new Option("", + new Label(GlobalizationUtil. + globalize("cms.ui.select_one")))); + // Add the Options to the SingleSelect widget final GenericContactTypeCollection contacttypes = new GenericContactTypeCollection(); diff --git a/ccm-cms/src/com/arsdigita/cms/ui/CategoryForm.java b/ccm-cms/src/com/arsdigita/cms/ui/CategoryForm.java index d7770a036..c9d47a42e 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/CategoryForm.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/CategoryForm.java @@ -231,6 +231,7 @@ public abstract class CategoryForm extends Form public void prepare(PrintEvent e) { OptionGroup target = (OptionGroup) e.getTarget(); + target.clearOptions(); PageState state = e.getPageState(); Category root = getRootCategory(state); if (root == null) { @@ -361,6 +362,7 @@ public abstract class CategoryForm extends Form @Override public void prepare(PrintEvent e) { OptionGroup o = (OptionGroup) e.getTarget(); + o.clearOptions(); PageState state = e.getPageState(); CategoryMap m = getAssignedCategories(state); diff --git a/ccm-cms/src/com/arsdigita/cms/ui/SectionConfigurationPage.java b/ccm-cms/src/com/arsdigita/cms/ui/SectionConfigurationPage.java index 37ce5a79e..6aa17a706 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/SectionConfigurationPage.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/SectionConfigurationPage.java @@ -345,6 +345,7 @@ public class SectionConfigurationPage extends CMSPage implements Resettable { public void prepare(PrintEvent event) { PageState state = event.getPageState(); SingleSelect target = (SingleSelect) event.getTarget(); + target.clearOptions(); addLocales(state, target); } }); diff --git a/ccm-cms/src/com/arsdigita/cms/ui/authoring/PageCreateDynamic.java b/ccm-cms/src/com/arsdigita/cms/ui/authoring/PageCreateDynamic.java index cea8160aa..2a13ce0c0 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/authoring/PageCreateDynamic.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/authoring/PageCreateDynamic.java @@ -686,6 +686,7 @@ public class PageCreateDynamic extends FormSection public void prepare(PrintEvent event) { SingleSelect t = (SingleSelect) event.getTarget(); + t.clearOptions(); PageState s = event.getPageState(); //get the current content section diff --git a/ccm-cms/src/com/arsdigita/cms/ui/folder/AbstractFolderPicker.java b/ccm-cms/src/com/arsdigita/cms/ui/folder/AbstractFolderPicker.java index 58ff0807f..53a13d895 100644 --- a/ccm-cms/src/com/arsdigita/cms/ui/folder/AbstractFolderPicker.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/folder/AbstractFolderPicker.java @@ -28,6 +28,7 @@ public abstract class AbstractFolderPicker extends SingleSelect { @Override public void prepare(PrintEvent ev) { + ((SingleSelect) ev.getTarget()).clearOptions(); addOptions(ev.getPageState(), (SingleSelect) ev.getTarget()); } diff --git a/ccm-cms/src/com/arsdigita/cms/ui/lifecycle/ItemLifecycleSelectForm.java b/ccm-cms/src/com/arsdigita/cms/ui/lifecycle/ItemLifecycleSelectForm.java index 9dc531355..867ab1bba 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/lifecycle/ItemLifecycleSelectForm.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/lifecycle/ItemLifecycleSelectForm.java @@ -256,6 +256,7 @@ class ItemLifecycleSelectForm extends BaseForm { ldc.addOrder("label"); final SingleSelect target = (SingleSelect) e.getTarget(); + target.clearOptions(); while (ldc.next()) { final LifecycleDefinition ld = ldc.getLifecycleDefinition(); diff --git a/ccm-cms/src/com/arsdigita/cms/ui/templates/TemplateCreate.java b/ccm-cms/src/com/arsdigita/cms/ui/templates/TemplateCreate.java index fc5629a75..acbc744cf 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/templates/TemplateCreate.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/templates/TemplateCreate.java @@ -105,6 +105,7 @@ public class TemplateCreate extends BasicItemForm { PageState state = e.getPageState(); SingleSelect target = (SingleSelect)e.getTarget(); + target.clearOptions(); TemplateContextCollection contexts = TemplateContext.retrieveAll(); contexts.addOrder(TemplateContext.LABEL); diff --git a/ccm-cms/src/com/arsdigita/cms/ui/type/AddContentItemElement.java b/ccm-cms/src/com/arsdigita/cms/ui/type/AddContentItemElement.java index d58a7a0d1..df68f0353 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/type/AddContentItemElement.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/type/AddContentItemElement.java @@ -126,6 +126,7 @@ public class AddContentItemElement extends ElementAddForm { public void prepare(PrintEvent event) { SingleSelect t = (SingleSelect) event.getTarget(); + t.clearOptions(); // Get the current content section ContentSection section = CMS.getContext().getContentSection(); diff --git a/ccm-cms/src/com/arsdigita/cms/ui/type/AddType.java b/ccm-cms/src/com/arsdigita/cms/ui/type/AddType.java index a24aa0303..7e04530a7 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/type/AddType.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/type/AddType.java @@ -154,6 +154,7 @@ public class AddType extends CMSForm public void prepare(PrintEvent event) { SingleSelect t = (SingleSelect) event.getTarget(); + t.clearOptions(); //get the current content section ContentSection section = CMS.getContext().getContentSection(); diff --git a/ccm-cms/src/com/arsdigita/cms/ui/type/CreateType.java b/ccm-cms/src/com/arsdigita/cms/ui/type/CreateType.java index ee5f3363a..bd9627475 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/type/CreateType.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/type/CreateType.java @@ -447,6 +447,7 @@ public class CreateType extends CMSForm public void prepare(PrintEvent event) { SingleSelect t = (SingleSelect) event.getTarget(); + t.clearOptions(); // Get the current content section ContentSection section = CMS.getContext().getContentSection(); @@ -474,6 +475,7 @@ public class CreateType extends CMSForm public void prepare(PrintEvent event) { SingleSelect t = (SingleSelect) event.getTarget(); + t.clearOptions(); // Get the current content section ContentSection section = CMS.getContext().getContentSection(); @@ -496,6 +498,7 @@ public class CreateType extends CMSForm public void prepare(PrintEvent event) { SingleSelect t = (SingleSelect) event.getTarget(); + t.clearOptions(); // Get the current content section ContentSection section = CMS.getContext().getContentSection(); diff --git a/ccm-cms/src/com/arsdigita/cms/ui/type/EditType.java b/ccm-cms/src/com/arsdigita/cms/ui/type/EditType.java index 411cc72f9..eeb3b3b09 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/type/EditType.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/type/EditType.java @@ -301,6 +301,7 @@ public class EditType extends CMSForm public void prepare(PrintEvent event) { SingleSelect t = (SingleSelect) event.getTarget(); + t.clearOptions(); // Get the current content section ContentSection section = CMS.getContext().getContentSection(); @@ -325,6 +326,7 @@ public class EditType extends CMSForm public void prepare(PrintEvent event) { SingleSelect t = (SingleSelect) event.getTarget(); + t.clearOptions(); // Get the current content section ContentSection section = CMS.getContext().getContentSection(); diff --git a/ccm-core/src/com/arsdigita/bebop/form/SearchAndSelect.java b/ccm-core/src/com/arsdigita/bebop/form/SearchAndSelect.java index 966ad73b6..3428e7c21 100755 --- a/ccm-core/src/com/arsdigita/bebop/form/SearchAndSelect.java +++ b/ccm-core/src/com/arsdigita/bebop/form/SearchAndSelect.java @@ -154,6 +154,7 @@ public class SearchAndSelect extends FormSection && (m_results.resultsCount() > 0))) { OptionGroup outputWidget = (OptionGroup) e.getTarget(); + outputWidget.clearOptions(); if (m_isOptional && !m_isMultiple) { outputWidget.addOption(new Option("", "None")); diff --git a/ccm-core/src/com/arsdigita/categorization/ui/AbstractCategoryPicker.java b/ccm-core/src/com/arsdigita/categorization/ui/AbstractCategoryPicker.java index 8392c4244..80a1f1343 100755 --- a/ccm-core/src/com/arsdigita/categorization/ui/AbstractCategoryPicker.java +++ b/ccm-core/src/com/arsdigita/categorization/ui/AbstractCategoryPicker.java @@ -40,6 +40,7 @@ public abstract class AbstractCategoryPicker extends SingleSelect try { addPrintListener(new PrintListener() { public void prepare(PrintEvent ev) { + ((SingleSelect) ev.getTarget()).clearOptions(); addOptions(ev.getPageState(), (SingleSelect)ev.getTarget()); } diff --git a/ccm-core/src/com/arsdigita/formbuilder/ui/editors/DataDrivenSelectForm.java b/ccm-core/src/com/arsdigita/formbuilder/ui/editors/DataDrivenSelectForm.java index e11d938f6..70e1d465e 100755 --- a/ccm-core/src/com/arsdigita/formbuilder/ui/editors/DataDrivenSelectForm.java +++ b/ccm-core/src/com/arsdigita/formbuilder/ui/editors/DataDrivenSelectForm.java @@ -79,6 +79,7 @@ public class DataDrivenSelectForm extends WidgetLabelForm { try { m_query.addPrintListener(new PrintListener() { public void prepare(PrintEvent e) { + ((Select) e.getTarget()).clearOptions(); loadComponents((Select)e.getTarget(), e.getPageState()); } }); diff --git a/ccm-core/src/com/arsdigita/formbuilder/ui/editors/TemplateEmailForm.java b/ccm-core/src/com/arsdigita/formbuilder/ui/editors/TemplateEmailForm.java index 99136a84e..7734bb1d0 100755 --- a/ccm-core/src/com/arsdigita/formbuilder/ui/editors/TemplateEmailForm.java +++ b/ccm-core/src/com/arsdigita/formbuilder/ui/editors/TemplateEmailForm.java @@ -120,6 +120,7 @@ public class TemplateEmailForm extends ProcessListenerForm { new OID( PersistentFormSection.BASE_DATA_OBJECT_TYPE, formID ); + m_controls.clearOptions(); m_controls.addOption(new Option("::user.email::", "Email address"), ps); PersistentFormSection form = (PersistentFormSection) diff --git a/ccm-core/src/com/arsdigita/kernel/ui/PartySearchSelect.java b/ccm-core/src/com/arsdigita/kernel/ui/PartySearchSelect.java index b35331583..52bf01411 100755 --- a/ccm-core/src/com/arsdigita/kernel/ui/PartySearchSelect.java +++ b/ccm-core/src/com/arsdigita/kernel/ui/PartySearchSelect.java @@ -317,6 +317,8 @@ public class PartySearchSelect } protected void initPartyChoices(PageState ps) { + m_select.clearOptions(); + PartyCollection parties = (PartyCollection) m_partyQuery.get(ps); boolean isEmpty = true; diff --git a/ccm-core/src/com/arsdigita/ui/admin/applications/ApplicationCreateForm.java b/ccm-core/src/com/arsdigita/ui/admin/applications/ApplicationCreateForm.java index 8e8e55820..c767b0eab 100644 --- a/ccm-core/src/com/arsdigita/ui/admin/applications/ApplicationCreateForm.java +++ b/ccm-core/src/com/arsdigita/ui/admin/applications/ApplicationCreateForm.java @@ -113,6 +113,8 @@ public class ApplicationCreateForm extends Form implement @Override public void prepare(final PrintEvent event) { final SingleSelect target = (SingleSelect) event.getTarget(); + + target.clearOptions(); target.addOption(new Option("", "")); final ApplicationCollection applications = Application.retrieveAllApplications(); diff --git a/ccm-docmgr/src/com/arsdigita/cms/docmgr/ui/BrowseFileInfoPropertiesPane.java b/ccm-docmgr/src/com/arsdigita/cms/docmgr/ui/BrowseFileInfoPropertiesPane.java index 2e1d45fc9..729651b89 100755 --- a/ccm-docmgr/src/com/arsdigita/cms/docmgr/ui/BrowseFileInfoPropertiesPane.java +++ b/ccm-docmgr/src/com/arsdigita/cms/docmgr/ui/BrowseFileInfoPropertiesPane.java @@ -95,957 +95,968 @@ import com.arsdigita.xml.Element; * @author Peter Kopunec */ public class BrowseFileInfoPropertiesPane extends ModalContainer implements DMConstants { - - private static final Logger s_log = Logger.getLogger(BrowseFileInfoPropertiesPane.class); - - private BrowsePane m_parent; - private Page m_page; - - private Component m_properties; - private Component m_edit; - private Component m_upload; - private FileSendColleaguePane m_sendColleague; - private Component m_action; - - private FilePropertiesPanel m_propertiesPane; - private BigDecimalParameter docIDParam = new BigDecimalParameter("doc_id"); - - public BrowseFileInfoPropertiesPane(BrowsePane parent) { - m_parent = parent; - - m_properties = makePropertiesPane(); - add(m_properties); - setDefaultComponent(m_properties); - - m_edit = makeEditPane(); - add(m_edit); - - m_upload = makeUploadForm(); - add(m_upload); - - m_sendColleague = makeSendColleagueForm(); - add(m_sendColleague); - } - - /** - * Register the page the fist time - */ - public void register(Page p) { - m_page = p; - p.addGlobalStateParam(docIDParam); - - super.register(p); - } + + private static final Logger s_log = Logger.getLogger(BrowseFileInfoPropertiesPane.class); + + private BrowsePane m_parent; + private Page m_page; + + private Component m_properties; + private Component m_edit; + private Component m_upload; + private FileSendColleaguePane m_sendColleague; + private Component m_action; + + private FilePropertiesPanel m_propertiesPane; + private BigDecimalParameter docIDParam = new BigDecimalParameter("doc_id"); + + public BrowseFileInfoPropertiesPane(BrowsePane parent) { + m_parent = parent; + + m_properties = makePropertiesPane(); + add(m_properties); + setDefaultComponent(m_properties); + + m_edit = makeEditPane(); + add(m_edit); + + m_upload = makeUploadForm(); + add(m_upload); + + m_sendColleague = makeSendColleagueForm(); + add(m_sendColleague); + } + + /** + * Register the page the fist time + */ + public void register(Page p) { + m_page = p; + p.addGlobalStateParam(docIDParam); + + super.register(p); + } public BigDecimalParameter getFileIDParam() { - try { - return ((DocmgrBasePage) m_page).getFileIDParam(); - } - catch (Throwable e) { - } + try { + return ((DocmgrBasePage) m_page).getFileIDParam(); + } catch (Throwable e) { + } return null; } - + public void setDocID(PageState state, BigDecimal docID) { - state.setValue(docIDParam, docID); - m_page.getTitle().setLabel(DMUtils.getFile(docID).getTitle(), state); - } - - private Component makePropertiesPane() { - SimpleContainer container= new SimpleContainer(); - - m_propertiesPane = new FilePropertiesPanel(this); - container.add(m_propertiesPane); - - container.add(new FileActionPane()); - return container; - } - - public void displayPropertiesPane(PageState state) { - setVisibleComponent(state, m_properties); - } - - private Component makeEditPane() { - return new FileEditForm(this); - } - - public void displayEditForm(PageState state) { - setVisibleComponent(state, m_edit); - } - - private Component makeUploadForm() { - return new VersionUploadForm(); - } - - public void displayUploadForm(PageState state) { - setVisibleComponent(state, m_upload); - } - - private FileSendColleaguePane makeSendColleagueForm() { - return new FileSendColleaguePane(); - } - - public void displaySendColleagueForm(PageState state) { - m_sendColleague.initState(state); - setVisibleComponent(state, m_sendColleague); - } - - class BackCancelActionLink extends ActionLink { - - public BackCancelActionLink(String label) { - super(label); - addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - m_parent.displayFolderContentPanel(e.getPageState()); - } - }); - } + state.setValue(docIDParam, docID); + m_page.getTitle().setLabel(DMUtils.getFile(docID).getTitle(), state); } - - class FilePropertiesPanel extends SimpleComponent { - - BrowseFileInfoPropertiesPane m_parent; - - public FilePropertiesPanel(BrowseFileInfoPropertiesPane parent) { - m_parent = parent; - } - - public void generateXML(PageState state, Element parent) { - Element element = parent.newChildElement("docs:file-info", DOCS_XML_NS); - BigDecimal docID = (BigDecimal) state.getValue(docIDParam); - if (docID != null) { - try { - // Retrieve resource properties. - Document doc = new Document(docID); - if (s_log.isDebugEnabled()) { - s_log.debug("doc raw content: " + doc.getSearchRawContent()); - //s_log.debug("doc xml content: " + doc.getSearchXMLContent()); - } - Element titleElement = element.newChildElement("docs:title", DOCS_XML_NS); - titleElement.setText(doc.getTitle()); + private Component makePropertiesPane() { + SimpleContainer container = new SimpleContainer(); - Element nameElement = element.newChildElement("docs:name", DOCS_XML_NS); - nameElement.setText(URLDecoder.decode(doc.getName())); + m_propertiesPane = new FilePropertiesPanel(this); + container.add(m_propertiesPane); - Element descriptionElement = element.newChildElement("docs:description", DOCS_XML_NS); - String description = doc.getDescription(); - if (description != null) { - descriptionElement.setText(description); - } + container.add(new FileActionPane()); + return container; + } - Element sizeElement = element.newChildElement("docs:size", DOCS_XML_NS); - sizeElement.setText(DMUtils.FileSize.formatFileSize(doc.getSize())); + public void displayPropertiesPane(PageState state) { + setVisibleComponent(state, m_properties); + } - Element typeElement = element.newChildElement("docs:type", DOCS_XML_NS); - // Retrieve pretty name for a mime type. - typeElement.setText(doc.getPrettyMimeType()); + private Component makeEditPane() { + return new FileEditForm(this); + } - Element lastModifiedElement = element.newChildElement("docs:last-modified", DOCS_XML_NS); - lastModifiedElement.setText(null != doc.getLastModifiedDate() ? DMUtils.DateFormat.format(doc.getLastModifiedDate()) : ""); + public void displayEditForm(PageState state) { + setVisibleComponent(state, m_edit); + } - Element revisionElement = element.newChildElement("docs:revision", DOCS_XML_NS); + private Component makeUploadForm() { + return new VersionUploadForm(); + } - TransactionCollection tc = Versions.getTaggedTransactions(doc.getOID()); - long numRevs = tc.size(); - revisionElement.setText(numRevs + ""); + public void displayUploadForm(PageState state) { + setVisibleComponent(state, m_upload); + } + + private FileSendColleaguePane makeSendColleagueForm() { + return new FileSendColleaguePane(); + } + + public void displaySendColleagueForm(PageState state) { + m_sendColleague.initState(state); + setVisibleComponent(state, m_sendColleague); + } + + class BackCancelActionLink extends ActionLink { + + public BackCancelActionLink(String label) { + super(label); + addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + m_parent.displayFolderContentPanel(e.getPageState()); + } + }); + } + } + + class FilePropertiesPanel extends SimpleComponent { + + BrowseFileInfoPropertiesPane m_parent; + + public FilePropertiesPanel(BrowseFileInfoPropertiesPane parent) { + m_parent = parent; + } + + public void generateXML(PageState state, Element parent) { + Element element = parent.newChildElement("docs:file-info", DOCS_XML_NS); + BigDecimal docID = (BigDecimal) state.getValue(docIDParam); + if (docID != null) { + try { + // Retrieve resource properties. + Document doc = new Document(docID); + if (s_log.isDebugEnabled()) { + s_log.debug("doc raw content: " + doc.getSearchRawContent()); + //s_log.debug("doc xml content: " + doc.getSearchXMLContent()); + } + + Element titleElement = element.newChildElement("docs:title", DOCS_XML_NS); + titleElement.setText(doc.getTitle()); + + Element nameElement = element.newChildElement("docs:name", DOCS_XML_NS); + nameElement.setText(URLDecoder.decode(doc.getName())); + + Element descriptionElement = element.newChildElement("docs:description", + DOCS_XML_NS); + String description = doc.getDescription(); + if (description != null) { + descriptionElement.setText(description); + } + + Element sizeElement = element.newChildElement("docs:size", DOCS_XML_NS); + sizeElement.setText(DMUtils.FileSize.formatFileSize(doc.getSize())); + + Element typeElement = element.newChildElement("docs:type", DOCS_XML_NS); + // Retrieve pretty name for a mime type. + typeElement.setText(doc.getPrettyMimeType()); + + Element lastModifiedElement = element.newChildElement("docs:last-modified", + DOCS_XML_NS); + lastModifiedElement.setText( + null != doc.getLastModifiedDate() ? DMUtils.DateFormat.format(doc. + getLastModifiedDate()) : ""); + + Element revisionElement = element.newChildElement("docs:revision", DOCS_XML_NS); + + TransactionCollection tc = Versions.getTaggedTransactions(doc.getOID()); + long numRevs = tc.size(); + revisionElement.setText(numRevs + ""); // Must allow for the possibility that not author is available. + Element authorElement = element.newChildElement("docs:author", DOCS_XML_NS); + authorElement.setText(doc.getImpliedAuthor()); - Element authorElement = element.newChildElement("docs:author", DOCS_XML_NS); - authorElement.setText(doc.getImpliedAuthor()); + Element uriElement = element.newChildElement("docs:uri", DOCS_XML_NS); + uriElement.setText(makeFileURL(doc, state)); - Element uriElement = element.newChildElement("docs:uri", DOCS_XML_NS); - uriElement.setText(makeFileURL(doc, state)); + Element catsElement = element.newChildElement("docs:categories", DOCS_XML_NS); - Element catsElement = element.newChildElement("docs:categories", DOCS_XML_NS); + CategoryCollection cats = doc.getCategoryCollection(); + Category cat; + Element catElement; + while (cats.next()) { + cat = cats.getCategory(); + catElement = catsElement.newChildElement("docs:category", DOCS_XML_NS); + catElement.addAttribute("id", cat.getID().toString()); + catElement.addAttribute("name", cat.getName()); + } - CategoryCollection cats = doc.getCategoryCollection(); - Category cat; - Element catElement; - while (cats.next()) { - cat = cats.getCategory(); - catElement = catsElement.newChildElement("docs:category", DOCS_XML_NS); - catElement.addAttribute("id", cat.getID().toString()); - catElement.addAttribute("name", cat.getName()); - } + } catch (DataObjectNotFoundException exc) { + Element notfoundElement = element.newChildElement("docs:notfound", DOCS_XML_NS); + } + } else { + Element notfoundElement = element.newChildElement("docs:notfound", DOCS_XML_NS); + } + } - } - catch (DataObjectNotFoundException exc) { - Element notfoundElement = element.newChildElement("docs:notfound", DOCS_XML_NS); - } - } - else { - Element notfoundElement = element.newChildElement("docs:notfound", DOCS_XML_NS); - } - } + private String makeFileURL(Document doc, PageState state) { + final HttpServletRequest req = state.getRequest(); - private String makeFileURL(Document doc, PageState state) { - final HttpServletRequest req = state.getRequest(); + final ParameterMap params = new ParameterMap(); + params.setParameter(FILE_ID_PARAM_NAME, doc.getID()); - final ParameterMap params = new ParameterMap(); - params.setParameter(FILE_ID_PARAM_NAME, doc.getID()); + return URL.here(req, "/download/", params).toString(); + } + } - return URL.here(req, "/download/", params).toString(); - } - } - - class FileEditForm extends Form implements FormValidationListener, FormProcessListener, FormInitListener { - - private final static String FILE_EDIT = "file-edit"; - private final static String FILE_EDIT_CATS = "file-edit-cats"; - private final static String FILE_EDIT_FNAME = "file-edit-name"; - private final static String FILE_EDIT_AUDIENCE = "file-edit-audience"; - private final static String FILE_EDIT_AUTHOR = "file-edit-author"; - private final static String FILE_EDIT_DESCRIPTION = "file-edit-description"; - private final static String FILE_EDIT_TITLE = "file-edit-title"; - - private BrowseFileInfoPropertiesPane m_parent; + class FileEditForm extends Form implements FormValidationListener, FormProcessListener, + FormInitListener { - private StringParameter m_FileAudience; - private StringParameter m_FileName; - private TrimmedStringParameter m_FileAuthor; - private StringParameter m_FileDesc; - private ArrayParameter m_FileCats; - private StringParameter m_FileTitle; - - private FileUpload m_fileUpload; - private final static String FILE_UPLOAD = "file-upload"; - private Submit m_submit; - - public FileEditForm(BrowseFileInfoPropertiesPane parent) { - super(FILE_EDIT, new ColumnPanel(2)); + private final static String FILE_EDIT = "file-edit"; + private final static String FILE_EDIT_CATS = "file-edit-cats"; + private final static String FILE_EDIT_FNAME = "file-edit-name"; + private final static String FILE_EDIT_AUDIENCE = "file-edit-audience"; + private final static String FILE_EDIT_AUTHOR = "file-edit-author"; + private final static String FILE_EDIT_DESCRIPTION = "file-edit-description"; + private final static String FILE_EDIT_TITLE = "file-edit-title"; - m_parent = parent; + private BrowseFileInfoPropertiesPane m_parent; - m_FileAudience = new StringParameter(FILE_EDIT_AUDIENCE); - m_FileAuthor = new TrimmedStringParameter(FILE_EDIT_AUTHOR); - m_FileDesc = new StringParameter(FILE_EDIT_DESCRIPTION); - m_FileCats = new ArrayParameter(FILE_EDIT_CATS); + private StringParameter m_FileAudience; + private StringParameter m_FileName; + private TrimmedStringParameter m_FileAuthor; + private StringParameter m_FileDesc; + private ArrayParameter m_FileCats; + private StringParameter m_FileTitle; - add(new Label(FILE_NAME_REQUIRED)); - m_FileName = new StringParameter(FILE_EDIT_FNAME); - TextField fnameEntry = new TextField(m_FileName); - add(fnameEntry); + private FileUpload m_fileUpload; + private final static String FILE_UPLOAD = "file-upload"; + private Submit m_submit; - add(new Label("Title"));//TODO - m_FileTitle = new StringParameter(FILE_EDIT_TITLE); - TextField fTitleEntry = new TextField(m_FileTitle); - add(fTitleEntry); + public FileEditForm(BrowseFileInfoPropertiesPane parent) { + super(FILE_EDIT, new ColumnPanel(2)); - add(new Label(FILE_INTENDED_AUDIENCE)); - SingleSelect audienceEntry = new SingleSelect(m_FileAudience); - try { - audienceEntry.addPrintListener(new IntendedAudienceSelectPrinter()); - } - catch (TooManyListenersException tmlex) { - s_log.error(tmlex.getMessage()); - tmlex.printStackTrace(); - } - add(audienceEntry); + m_parent = parent; - add(new Label(new AuthorLabelPrinter())); - TextField authorEntry = new TextField(m_FileAuthor); - authorEntry.addValidationListener(new StringLengthValidationListener(200)); - add(authorEntry); + m_FileAudience = new StringParameter(FILE_EDIT_AUDIENCE); + m_FileAuthor = new TrimmedStringParameter(FILE_EDIT_AUTHOR); + m_FileDesc = new StringParameter(FILE_EDIT_DESCRIPTION); + m_FileCats = new ArrayParameter(FILE_EDIT_CATS); - add(new Label(FILE_CATEGORIES)); - MultipleSelect catSelect = new MultipleSelect(FILE_EDIT_CATS); - catSelect.setSize(20); - try { - BigDecimalParameter fileIDParam = null; - fileIDParam = getFileIDParam(); - catSelect.addPrintListener(new CategoriesPrintListener(getContentSection(), fileIDParam)); - } - catch (java.util.TooManyListenersException tmex) { - throw new UncheckedWrapperException(tmex.getMessage()); - } - add(catSelect); + add(new Label(FILE_NAME_REQUIRED)); + m_FileName = new StringParameter(FILE_EDIT_FNAME); + TextField fnameEntry = new TextField(m_FileName); + add(fnameEntry); - add(new Label(FILE_DESCRIPTION)); - TextArea descArea = new TextArea(m_FileDesc); - descArea.setRows(10); - descArea.setCols(40); - add(descArea); + add(new Label("Title"));//TODO + m_FileTitle = new StringParameter(FILE_EDIT_TITLE); + TextField fTitleEntry = new TextField(m_FileTitle); + add(fTitleEntry); - m_submit = new Submit("file-edit-save"); - m_submit.setButtonLabel(FILE_SAVE); - add(new Label()); // spacer + add(new Label(FILE_INTENDED_AUDIENCE)); + SingleSelect audienceEntry = new SingleSelect(m_FileAudience); + try { + audienceEntry.addPrintListener(new IntendedAudienceSelectPrinter()); + } catch (TooManyListenersException tmlex) { + s_log.error(tmlex.getMessage()); + tmlex.printStackTrace(); + } + add(audienceEntry); - SimpleContainer sc = new SimpleContainer(); - sc.add(m_submit); - sc.add(new Submit(CANCEL)); + add(new Label(new AuthorLabelPrinter())); + TextField authorEntry = new TextField(m_FileAuthor); + authorEntry.addValidationListener(new StringLengthValidationListener(200)); + add(authorEntry); - add(sc); + add(new Label(FILE_CATEGORIES)); + MultipleSelect catSelect = new MultipleSelect(FILE_EDIT_CATS); + catSelect.setSize(20); + try { + BigDecimalParameter fileIDParam = null; + fileIDParam = getFileIDParam(); + catSelect.addPrintListener(new CategoriesPrintListener(getContentSection(), + fileIDParam)); + } catch (java.util.TooManyListenersException tmex) { + throw new UncheckedWrapperException(tmex.getMessage()); + } + add(catSelect); - addInitListener(this); - addProcessListener(this); - addValidationListener(this); - } - - /** - * Initializer to pre-fill name and description - */ - public void init(FormSectionEvent e) throws FormProcessException { - PageState state = e.getPageState(); + add(new Label(FILE_DESCRIPTION)); + TextArea descArea = new TextArea(m_FileDesc); + descArea.setRows(10); + descArea.setCols(40); + add(descArea); - FormData data = e.getFormData(); + m_submit = new Submit("file-edit-save"); + m_submit.setButtonLabel(FILE_SAVE); + add(new Label()); // spacer - BigDecimal id = (BigDecimal) state.getValue(docIDParam); - Document doc = DMUtils.getFile(id); + SimpleContainer sc = new SimpleContainer(); + sc.add(m_submit); + sc.add(new Submit(CANCEL)); - ArrayList assignedCats = new ArrayList(); + add(sc); - CategoryCollection cats = doc.getCategoryCollection(); - Category cat; - while (cats.next()) { - cat = cats.getCategory(); - String catID = cat.getID().toString(); - assignedCats.add(catID); - s_log.debug("init: "+catID); - } + addInitListener(this); + addProcessListener(this); + addValidationListener(this); + } - data.put(FILE_EDIT_FNAME, URLDecoder.decode(doc.getName())); - data.put(FILE_EDIT_TITLE, doc.getTitle()); - data.put(FILE_EDIT_AUTHOR, doc.getAuthor()); - data.put(FILE_EDIT_DESCRIPTION, doc.getDescription()); - data.put(FILE_EDIT_CATS, assignedCats.toArray()); - initAudienceFormData(data, doc); - } + /** + * Initializer to pre-fill name and description + */ + public void init(FormSectionEvent e) throws FormProcessException { + PageState state = e.getPageState(); - /** - * read form and update - */ - public void process(FormSectionEvent e) throws FormProcessException { - PageState state = e.getPageState(); - if (m_submit.isSelected(state)) { - processEdit(e); - } + FormData data = e.getFormData(); - displayPropertiesPane(state); - } + BigDecimal id = (BigDecimal) state.getValue(docIDParam); + Document doc = DMUtils.getFile(id); - private void processEdit(FormSectionEvent e) throws FormProcessException { - PageState state = e.getPageState(); - FormData data = e.getFormData(); + ArrayList assignedCats = new ArrayList(); - Document doc = DMUtils.getFile((BigDecimal) state.getValue(docIDParam)); + CategoryCollection cats = doc.getCategoryCollection(); + Category cat; + while (cats.next()) { + cat = cats.getCategory(); + String catID = cat.getID().toString(); + assignedCats.add(catID); + s_log.debug("init: " + catID); + } - setDocumentAttributes(data, doc); - doc.setCategories((String[]) data.get(FILE_EDIT_CATS)); - doc.setLastModifiedLocal(new java.util.Date()); - doc.save(); // creates a new revision + data.put(FILE_EDIT_FNAME, URLDecoder.decode(doc.getName())); + data.put(FILE_EDIT_TITLE, doc.getTitle()); + data.put(FILE_EDIT_AUTHOR, doc.getAuthor()); + data.put(FILE_EDIT_DESCRIPTION, doc.getDescription()); + data.put(FILE_EDIT_CATS, assignedCats.toArray()); + initAudienceFormData(data, doc); + } - setDocumentPermission(data, doc); - } + /** + * read form and update + */ + public void process(FormSectionEvent e) throws FormProcessException { + PageState state = e.getPageState(); + if (m_submit.isSelected(state)) { + processEdit(e); + } - private void setDocumentAttributes(FormData data, Document doc) { - String ftitle = (String) data.get(FILE_EDIT_TITLE); - String fname = (String) data.get(FILE_EDIT_FNAME); - // title must be set before name - doc.setTitle((ftitle != null && ftitle.length() > 0) ? ftitle : fname); - fname = fname.replace('"', ' '); - doc.setName(URLEncoder.encode(fname)); + displayPropertiesPane(state); + } - String fauthor = (String) data.get(FILE_EDIT_AUTHOR); - String fdesc = (String) data.get(FILE_EDIT_DESCRIPTION); + private void processEdit(FormSectionEvent e) throws FormProcessException { + PageState state = e.getPageState(); + FormData data = e.getFormData(); - if (fauthor != null) { - doc.setAuthor(fauthor); - } - doc.setDescription(fdesc); - } + Document doc = DMUtils.getFile((BigDecimal) state.getValue(docIDParam)); - protected String getUploadFileName(FormSectionEvent e) { - FormData data = e.getFormData(); - String filename = (String) data.get(FILE_UPLOAD); - return DMUtils.extractFileName(filename, e.getPageState()); - } + setDocumentAttributes(data, doc); + doc.setCategories((String[]) data.get(FILE_EDIT_CATS)); + doc.setLastModifiedLocal(new java.util.Date()); + doc.save(); // creates a new revision - /** - * Test if the new name already exists in the current folder - */ + setDocumentPermission(data, doc); + } - public void validate(FormSectionEvent event) throws FormProcessException { - PageState state = event.getPageState(); - if (m_submit.isSelected(state)) { - validateEdit(event); - } - } + private void setDocumentAttributes(FormData data, Document doc) { + String ftitle = (String) data.get(FILE_EDIT_TITLE); + String fname = (String) data.get(FILE_EDIT_FNAME); + // title must be set before name + doc.setTitle((ftitle != null && ftitle.length() > 0) ? ftitle : fname); + fname = fname.replace('"', ' '); + doc.setName(URLEncoder.encode(fname)); - private void validateEdit(FormSectionEvent event) throws FormProcessException { - PageState state = event.getPageState(); - FormData data = event.getFormData(); + String fauthor = (String) data.get(FILE_EDIT_AUTHOR); + String fdesc = (String) data.get(FILE_EDIT_DESCRIPTION); - String fname = (String) data.get(FILE_EDIT_FNAME); - if (fname == null || fname.trim().length() == 0) { - data.addError(FILE_EDIT_FNAME, "This parameter is required"); - } + if (fauthor != null) { + doc.setAuthor(fauthor); + } + doc.setDescription(fdesc); + } - String title = (String) data.get(FILE_EDIT_TITLE); - if (title == null || title.length() == 0) { - data.addError(FILE_EDIT_TITLE, "This parameter is required."); - } - else if (title.length() > 200) { - data.addError(FILE_EDIT_TITLE, "This title is too long. It must be fewer than 200 characters."); - } - } + protected String getUploadFileName(FormSectionEvent e) { + FormData data = e.getFormData(); + String filename = (String) data.get(FILE_UPLOAD); + return DMUtils.extractFileName(filename, e.getPageState()); + } - /* - * Initialize form data for document's intended audience. - */ - private void initAudienceFormData(FormData data, Document doc) { - ObjectPermissionCollection opc = PermissionService.getDirectGrantedPermissions(doc.getOID()); - long numPermissions = opc.size(); - if (numPermissions > 1) { - s_log.error("there should only be 1 direct permission for " + "a document"); - } - if (numPermissions == 0) { - data.put(FILE_EDIT_AUDIENCE, "workspace"); - opc.close(); - return; - } - boolean isPublic = false; - while (opc.next()) { - if (opc.getGranteeID().intValue() == PermissionManager.VIRTUAL_PUBLIC_ID) { - isPublic = true; - } - } - opc.close(); - if (isPublic) { - data.put(FILE_EDIT_AUDIENCE, "public"); - } - else { - data.put(FILE_EDIT_AUDIENCE, "internal"); - } - } + /** + * Test if the new name already exists in the current folder + */ + public void validate(FormSectionEvent event) throws FormProcessException { + PageState state = event.getPageState(); + if (m_submit.isSelected(state)) { + validateEdit(event); + } + } - /* - * Grant/revoke direct permissions as needed. Note that workspace - * permissions is always implied. - */ - private void setDocumentPermission(FormData data, Document doc) throws FormProcessException { - final String intendedAudience = (String) data.get(FILE_EDIT_AUDIENCE); - if (intendedAudience == null) { - throw new FormProcessException("Intended Audience cannot be null"); - } - final PermissionDescriptor publicDescriptor = new PermissionDescriptor(PrivilegeDescriptor.READ, doc.getOID(), new OID( - User.BASE_DATA_OBJECT_TYPE, PermissionManager.VIRTUAL_PUBLIC_ID)); - final PermissionDescriptor internalDescriptor = new PermissionDescriptor(PrivilegeDescriptor.READ, doc.getOID(), new OID( - Group.BASE_DATA_OBJECT_TYPE, DocMgr.getConfig().getInternalGroupID())); - new KernelExcursion() { - protected void excurse() { - //Party currentParty = Kernel.getWebContext().getParty(); + private void validateEdit(FormSectionEvent event) throws FormProcessException { + PageState state = event.getPageState(); + FormData data = event.getFormData(); - setParty(Kernel.getSystemParty()); - if ("public".equals(intendedAudience)) { - PermissionService.grantPermission(publicDescriptor); - PermissionService.revokePermission(internalDescriptor); - } - else if ("internal".equals(intendedAudience)) { - PermissionService.revokePermission(publicDescriptor); - PermissionService.grantPermission(internalDescriptor); - } - else { - // workspace only - PermissionService.revokePermission(publicDescriptor); - PermissionService.revokePermission(internalDescriptor); - } - } - }.run(); - } + String fname = (String) data.get(FILE_EDIT_FNAME); + if (fname == null || fname.trim().length() == 0) { + data.addError(FILE_EDIT_FNAME, "This parameter is required"); + } - protected class AuthorLabelPrinter implements PrintListener { - public AuthorLabelPrinter() { - // Empty - } + String title = (String) data.get(FILE_EDIT_TITLE); + if (title == null || title.length() == 0) { + data.addError(FILE_EDIT_TITLE, "This parameter is required."); + } else if (title.length() > 200) { + data.addError(FILE_EDIT_TITLE, + "This title is too long. It must be fewer than 200 characters."); + } + } - public void prepare(PrintEvent e) { - Label label = (Label) e.getTarget(); - PageState pageState = e.getPageState(); + /* + * Initialize form data for document's intended audience. + */ + private void initAudienceFormData(FormData data, Document doc) { + ObjectPermissionCollection opc = PermissionService.getDirectGrantedPermissions(doc. + getOID()); + long numPermissions = opc.size(); + if (numPermissions > 1) { + s_log.error("there should only be 1 direct permission for " + "a document"); + } + if (numPermissions == 0) { + data.put(FILE_EDIT_AUDIENCE, "workspace"); + opc.close(); + return; + } + boolean isPublic = false; + while (opc.next()) { + if (opc.getGranteeID().intValue() == PermissionManager.VIRTUAL_PUBLIC_ID) { + isPublic = true; + } + } + opc.close(); + if (isPublic) { + data.put(FILE_EDIT_AUDIENCE, "public"); + } else { + data.put(FILE_EDIT_AUDIENCE, "internal"); + } + } - String name = Web.getWebContext().getUser().getName(); + /* + * Grant/revoke direct permissions as needed. Note that workspace + * permissions is always implied. + */ + private void setDocumentPermission(FormData data, Document doc) throws FormProcessException { + final String intendedAudience = (String) data.get(FILE_EDIT_AUDIENCE); + if (intendedAudience == null) { + throw new FormProcessException("Intended Audience cannot be null"); + } + final PermissionDescriptor publicDescriptor = new PermissionDescriptor( + PrivilegeDescriptor.READ, doc.getOID(), new OID( + User.BASE_DATA_OBJECT_TYPE, PermissionManager.VIRTUAL_PUBLIC_ID)); + final PermissionDescriptor internalDescriptor = new PermissionDescriptor( + PrivilegeDescriptor.READ, doc.getOID(), new OID( + Group.BASE_DATA_OBJECT_TYPE, DocMgr.getConfig().getInternalGroupID())); + new KernelExcursion() { + protected void excurse() { + //Party currentParty = Kernel.getWebContext().getParty(); - label.setLabel("Author: (if not " + name + ")"); - } - } + setParty(Kernel.getSystemParty()); + if ("public".equals(intendedAudience)) { + PermissionService.grantPermission(publicDescriptor); + PermissionService.revokePermission(internalDescriptor); + } else if ("internal".equals(intendedAudience)) { + PermissionService.revokePermission(publicDescriptor); + PermissionService.grantPermission(internalDescriptor); + } else { + // workspace only + PermissionService.revokePermission(publicDescriptor); + PermissionService.revokePermission(internalDescriptor); + } + } + }.run(); + } - protected class IntendedAudienceSelectPrinter implements PrintListener { - public IntendedAudienceSelectPrinter() { - } + protected class AuthorLabelPrinter implements PrintListener { - public void prepare(PrintEvent e) { - SingleSelect select = (SingleSelect) e.getTarget(); + public AuthorLabelPrinter() { + // Empty + } + + public void prepare(PrintEvent e) { + Label label = (Label) e.getTarget(); + PageState pageState = e.getPageState(); + + String name = Web.getWebContext().getUser().getName(); + + label.setLabel("Author: (if not " + name + ")"); + } + } + + protected class IntendedAudienceSelectPrinter implements PrintListener { + + public IntendedAudienceSelectPrinter() { + } + + public void prepare(PrintEvent e) { + SingleSelect select = (SingleSelect) e.getTarget(); + select.clearOptions(); + + select.addOption(new Option("workspace", Web.getWebContext().getApplication(). + getParentApplication() == null ? Web.getWebContext(). + getApplication().getDisplayName() : Web.getWebContext(). + getApplication().getParentApplication().getDisplayName() + + " members")); + select.addOption(new Option("internal", new Label(FILE_INTENDED_AUDIENCE_INTERNAL))); + select.addOption(new Option("public", new Label(FILE_INTENDED_AUDIENCE_PUBLIC))); + } + } + + private ContentSection getContentSection() { + ContentSectionCollection csl = ContentSection.getAllSections(); + csl.addEqualsFilter("label", DocMgr.getConfig().getContentSection()); + if (!csl.next()) { + csl.close(); + return null; + } + ContentSection docsContentSection = csl.getContentSection(); + csl.close(); + return docsContentSection; + } + } + + class VersionUploadForm extends Form implements FormInitListener, FormProcessListener, + FormValidationListener { + + private static final String VERSION_UPLOAD_FORM = "file-version"; + private static final String VERSION_TRANSACTION_DESCRIPTION = "file-transaction-description"; + private static final String VERSION_FILE_UPLOAD = "file-version-upload"; + + private FileUpload m_fileUpload; + private StringParameter m_versionDesc; + private RequestLocal m_fileData; + private Submit m_submit; - select.addOption(new Option("workspace", Web.getWebContext().getApplication().getParentApplication()== null? Web.getWebContext().getApplication().getDisplayName():Web.getWebContext().getApplication().getParentApplication().getDisplayName() + " members")); - select.addOption(new Option("internal", new Label(FILE_INTENDED_AUDIENCE_INTERNAL))); - select.addOption(new Option("public", new Label(FILE_INTENDED_AUDIENCE_PUBLIC))); - } - } - - private ContentSection getContentSection() { - ContentSectionCollection csl = ContentSection.getAllSections(); - csl.addEqualsFilter("label", DocMgr.getConfig().getContentSection()); - if (!csl.next()) { - csl.close(); - return null; - } - ContentSection docsContentSection = csl.getContentSection(); - csl.close(); - return docsContentSection; - } - } - - class VersionUploadForm extends Form implements FormInitListener, FormProcessListener, FormValidationListener { - - private static final String VERSION_UPLOAD_FORM = "file-version"; - private static final String VERSION_TRANSACTION_DESCRIPTION = "file-transaction-description"; - private static final String VERSION_FILE_UPLOAD = "file-version-upload"; - - private FileUpload m_fileUpload; - private StringParameter m_versionDesc; - private RequestLocal m_fileData; - private Submit m_submit; - //This const allows for less than 4k bytes of 2byte unicode chars, plus - // a little wiggle room... - private int FOUR_K_CHAR_LIMIT = 1994; - - public VersionUploadForm() { - super(VERSION_UPLOAD_FORM, new ColumnPanel(2)); - setMethod(Form.POST); - setEncType("multipart/form-data"); + // a little wiggle room... + private int FOUR_K_CHAR_LIMIT = 1994; - // initialize the file - m_fileData = new RequestLocal() { - protected Object initialValue(PageState state) { - BigDecimal id = (BigDecimal) state.getValue(docIDParam); - return new Document(id); - } - }; + public VersionUploadForm() { + super(VERSION_UPLOAD_FORM, new ColumnPanel(2)); + setMethod(Form.POST); + setEncType("multipart/form-data"); - m_fileUpload = new FileUpload(VERSION_FILE_UPLOAD); + // initialize the file + m_fileData = new RequestLocal() { + protected Object initialValue(PageState state) { + BigDecimal id = (BigDecimal) state.getValue(docIDParam); + return new Document(id); + } + }; - m_versionDesc = new StringParameter(VERSION_TRANSACTION_DESCRIPTION); + m_fileUpload = new FileUpload(VERSION_FILE_UPLOAD); - add(new Label("Title"));//TODO - Label labelTitle = new Label(); - labelTitle.addPrintListener(new PrintListener() { - public void prepare(PrintEvent e) { - PageState state = e.getPageState(); - Label t = (Label) e.getTarget(); - t.setLabel(getFile(state).getTitle()); - } - }); - add(labelTitle); + m_versionDesc = new StringParameter(VERSION_TRANSACTION_DESCRIPTION); - add(new Label(FILE_NAME)); - Label label = new Label(); - label.addPrintListener(new PrintListener() { - public void prepare(PrintEvent e) { - PageState state = e.getPageState(); - Label t = (Label) e.getTarget(); - t.setLabel(URLDecoder.decode(getFile(state).getName())); - } - }); - add(label); + add(new Label("Title"));//TODO + Label labelTitle = new Label(); + labelTitle.addPrintListener(new PrintListener() { + public void prepare(PrintEvent e) { + PageState state = e.getPageState(); + Label t = (Label) e.getTarget(); + t.setLabel(getFile(state).getTitle()); + } + }); + add(labelTitle); - add(new Label(FILE_SOURCE)); - add(m_fileUpload); + add(new Label(FILE_NAME)); + Label label = new Label(); + label.addPrintListener(new PrintListener() { + public void prepare(PrintEvent e) { + PageState state = e.getPageState(); + Label t = (Label) e.getTarget(); + t.setLabel(URLDecoder.decode(getFile(state).getName())); + } + }); + add(label); - add(new Label(FILE_VERSION_DESCRIPTION)); - TextArea fversionDesc = new TextArea(m_versionDesc); - fversionDesc.setRows(10); - fversionDesc.setCols(40); - add(fversionDesc); + add(new Label(FILE_SOURCE)); + add(m_fileUpload); - m_submit = new Submit("file-version-save"); - m_submit.setButtonLabel(FILE_SAVE); - add(new Label()); // spacer + add(new Label(FILE_VERSION_DESCRIPTION)); + TextArea fversionDesc = new TextArea(m_versionDesc); + fversionDesc.setRows(10); + fversionDesc.setCols(40); + add(fversionDesc); - SimpleContainer sc = new SimpleContainer(); - sc.add(m_submit); - sc.add(new Submit(CANCEL)); + m_submit = new Submit("file-version-save"); + m_submit.setButtonLabel(FILE_SAVE); + add(new Label()); // spacer - add(sc, ColumnPanel.LEFT); + SimpleContainer sc = new SimpleContainer(); + sc.add(m_submit); + sc.add(new Submit(CANCEL)); - addInitListener(this); - addValidationListener(this); - addProcessListener(this); - } - - private Document getFile(PageState s) { - return (Document) m_fileData.get(s); - } + add(sc, ColumnPanel.LEFT); - public void init(FormSectionEvent e) { - PageState state = e.getPageState(); - } + addInitListener(this); + addValidationListener(this); + addProcessListener(this); + } - /** - * Receive uploaded file and reset file content, mime type, and - * description. Return to File properties screen. - */ - public void process(FormSectionEvent e) throws FormProcessException { + private Document getFile(PageState s) { + return (Document) m_fileData.get(s); + } - PageState state = e.getPageState(); - - if (m_submit.isSelected(state)) { - FormData data = e.getFormData(); - MultipartHttpServletRequest req = (MultipartHttpServletRequest) state.getRequest(); + public void init(FormSectionEvent e) { + PageState state = e.getPageState(); + } - String fpath = (String) data.get(VERSION_FILE_UPLOAD); - String fname = DMUtils.extractFileName(fpath, state); - Document doc = getFile(state); - java.io.File src = null; + /** + * Receive uploaded file and reset file content, mime type, and description. Return to File + * properties screen. + */ + public void process(FormSectionEvent e) throws FormProcessException { - try { + PageState state = e.getPageState(); - if (fpath != null && fpath.length() > 0) { - src = req.getFile(VERSION_FILE_UPLOAD); - } + if (m_submit.isSelected(state)) { + FormData data = e.getFormData(); + MultipartHttpServletRequest req = (MultipartHttpServletRequest) state.getRequest(); + + String fpath = (String) data.get(VERSION_FILE_UPLOAD); + String fname = DMUtils.extractFileName(fpath, state); + Document doc = getFile(state); + java.io.File src = null; + + try { + + if (fpath != null && fpath.length() > 0) { + src = req.getFile(VERSION_FILE_UPLOAD); + } // Try to update the file in the database + FileAsset fa = doc.getFile(); + fa.loadFromFile(fname, src, "txt"); - FileAsset fa = doc.getFile(); - fa.loadFromFile(fname, src, "txt"); + } catch (java.io.IOException ex) { + ex.printStackTrace(); + throw new FormProcessException(ex.getMessage()); + } - } - catch (java.io.IOException ex) { - ex.printStackTrace(); - throw new FormProcessException(ex.getMessage()); - } + // Annotate transaction description + String vdesc = (String) data.get(VERSION_TRANSACTION_DESCRIPTION); + //If version description string is over 4K in size, truncate... + if (vdesc.length() > FOUR_K_CHAR_LIMIT) { + vdesc = vdesc.substring(0, FOUR_K_CHAR_LIMIT); + } + Versions.tag(doc.getOID(), vdesc); + doc.setLastModifiedLocal(doc.getLastModifiedDate()); + doc.save(); + } - // Annotate transaction description - String vdesc = (String) data.get(VERSION_TRANSACTION_DESCRIPTION); - //If version description string is over 4K in size, truncate... - if (vdesc.length() > FOUR_K_CHAR_LIMIT) - vdesc = vdesc.substring(0, FOUR_K_CHAR_LIMIT); - Versions.tag(doc.getOID(), vdesc); - doc.setLastModifiedLocal(doc.getLastModifiedDate()); - doc.save(); - } + displayPropertiesPane(state); + } - displayPropertiesPane(state); - } + /** + * Validate the length of name of the new file being uploaded. Validate if user tries to + * upload a file with a different Mime type than the original. This is not supported. + * + */ + public void validate(FormSectionEvent e) throws FormProcessException { + PageState state = e.getPageState(); + if (!m_submit.isSelected(state)) { + return; + } + FormData data = e.getFormData(); + String fpath = (String) data.get(VERSION_FILE_UPLOAD); + if (fpath == null || fpath.length() == 0) { + data.addError(VERSION_FILE_UPLOAD, "This parameter is required."); + } - /** - * Validate the length of name of the new file being uploaded. Validate - * if user tries to upload a file with a different Mime type than the - * original. This is not supported. - * - */ - public void validate(FormSectionEvent e) throws FormProcessException { - PageState state = e.getPageState(); - if (!m_submit.isSelected(state)) { - return; - } - FormData data = e.getFormData(); - String fpath = (String) data.get(VERSION_FILE_UPLOAD); - if (fpath == null || fpath.length() == 0) { - data.addError(VERSION_FILE_UPLOAD, "This parameter is required."); - } + String fname = DMUtils.extractFileName(fpath, state); - String fname = DMUtils.extractFileName(fpath, state); + int nameLength = 500; + try { + nameLength = fname.getBytes("UTF-8").length; + } catch (UnsupportedEncodingException uee) { + throw new RuntimeException("No UTF-8 support: " + uee); + } + // XXX Not localized as the other errors are. + if (nameLength > 200) { + data.addError(VERSION_FILE_UPLOAD, + "This filename is too long. It must be fewer than 200 characters."); + } - int nameLength = 500; - try { - nameLength = fname.getBytes("UTF-8").length; - } - catch (UnsupportedEncodingException uee) { - throw new RuntimeException("No UTF-8 support: " + uee); - } - // XXX Not localized as the other errors are. - if (nameLength > 200) { - data.addError(VERSION_FILE_UPLOAD, "This filename is too long. It must be fewer than 200 characters."); - } - - String desc = (String) data.get(VERSION_TRANSACTION_DESCRIPTION); + String desc = (String) data.get(VERSION_TRANSACTION_DESCRIPTION); // trim it to really check it's not empty if (desc != null) { desc = desc.trim(); } - if (desc == null || desc.length() == 0) { - data.addError(VERSION_TRANSACTION_DESCRIPTION, "This parameter is required."); - } + if (desc == null || desc.length() == 0) { + data.addError(VERSION_TRANSACTION_DESCRIPTION, "This parameter is required."); + } //Default to more than required so that it will fail. /* - * PageState state = e.getPageState(); FormData data = - * e.getFormData(); HttpServletRequest req = state.getRequest(); - * - * String uploadedFileName = (String) data.get(VERSION_FILE_UPLOAD); - * String newType = File.guessContentType(uploadedFileName,req); - * String oldType = getFile(state).getContentType(); - * - * if (!newType.equalsIgnoreCase(oldType)) { - * data.addError(VERSION_FILE_UPLOAD, - * DIFFERENT_MIMETYPE_ERROR.localize(req).toString()); } - */ - } - } - - class FileSendColleaguePane extends SimpleContainer { - - private Component m_sendForm; - private Component m_thankYou; + * PageState state = e.getPageState(); FormData data = + * e.getFormData(); HttpServletRequest req = state.getRequest(); + * + * String uploadedFileName = (String) data.get(VERSION_FILE_UPLOAD); + * String newType = File.guessContentType(uploadedFileName,req); + * String oldType = getFile(state).getContentType(); + * + * if (!newType.equalsIgnoreCase(oldType)) { + * data.addError(VERSION_FILE_UPLOAD, + * DIFFERENT_MIMETYPE_ERROR.localize(req).toString()); } + */ + } + } - public FileSendColleaguePane() { - GridPanel spacer = new GridPanel(1); - spacer.add(new Label(" ")); - add(spacer); + class FileSendColleaguePane extends SimpleContainer { - m_sendForm = new SendForm(this); - add(m_sendForm); + private Component m_sendForm; + private Component m_thankYou; - m_thankYou = buildThankYou(); - add(m_thankYou); - } - - public void initState(PageState ps) { - s_log.debug("FileSendColleaguePane.initState"); - m_sendForm.setVisible(ps, true); - m_thankYou.setVisible(ps, false); - } - - private Component buildThankYou() { - BoxPanel panel = new BoxPanel(); + public FileSendColleaguePane() { + GridPanel spacer = new GridPanel(1); + spacer.add(new Label(" ")); + add(spacer); - panel.add(FILE_SEND_COLLEAGUE_THANKS); - ActionLink backLink = new ActionLink(FILE_SEND_COLLEAGUE_THANKS_RETURN_LINK.localize().toString()); - backLink.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - PageState state = e.getPageState(); - displayPropertiesPane(state); - } - }); - panel.add(backLink); + m_sendForm = new SendForm(this); + add(m_sendForm); - return panel; - } - - public void displayThankYou(PageState ps) { - s_log.debug("FileSendColleaguePane.displayThankYou"); - m_thankYou.setVisible(ps, true); - } - } - - class SendForm extends Form implements FormProcessListener { - - private static final String EMAIL_PARAM_NAME = "scEmail"; - - private final TrimmedStringParameter m_emailParam = new TrimmedStringParameter(EMAIL_PARAM_NAME); - private FileSendColleaguePane m_parent; - - public SendForm(FileSendColleaguePane parent) { - super("sendEmail",new BoxPanel()); - - m_parent = parent; - - GridPanel panel = new GridPanel(2); - - panel.add(FILE_SEND_COLLEAGUE_FORM_EMAIL); - TextField emailField = new TextField(m_emailParam); - emailField.addValidationListener(new EmailValidationListener()); - panel.add(emailField, GridPanel.LEFT); - panel.add(new Submit(FILE_SEND_COLLEAGUE_SUBMIT)); + m_thankYou = buildThankYou(); + add(m_thankYou); + } - add(panel); + public void initState(PageState ps) { + s_log.debug("FileSendColleaguePane.initState"); + m_sendForm.setVisible(ps, true); + m_thankYou.setVisible(ps, false); + } - addProcessListener(this); - } + private Component buildThankYou() { + BoxPanel panel = new BoxPanel(); - public void process(FormSectionEvent e) throws FormProcessException { + panel.add(FILE_SEND_COLLEAGUE_THANKS); + ActionLink backLink = new ActionLink(FILE_SEND_COLLEAGUE_THANKS_RETURN_LINK.localize(). + toString()); + backLink.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + PageState state = e.getPageState(); + displayPropertiesPane(state); + } + }); + panel.add(backLink); - PageState state = e.getPageState(); - FormData data = e.getFormData(); - this.setVisible(state, false); - m_parent.displayThankYou(state); + return panel; + } - // send the mail - User u = Web.getWebContext().getUser(); + public void displayThankYou(PageState ps) { + s_log.debug("FileSendColleaguePane.displayThankYou"); + m_thankYou.setVisible(ps, true); + } + } - s_log.debug(FILE_SEND_COLLEAGUE_RETURN_ADDRESS.localize().toString()); + class SendForm extends Form implements FormProcessListener { - Mail mail = new Mail((String) data.get(EMAIL_PARAM_NAME), FILE_SEND_COLLEAGUE_RETURN_ADDRESS.localize().toString(), - FILE_SEND_COLLEAGUE_SUBJECT.localize().toString(), FILE_SEND_COLLEAGUE_MESSAGE.localize().toString() + " " + u.getName()); - Document doc = new Document((BigDecimal) state.getValue(docIDParam)); - try { - FileAsset fa = doc.getFile(); - if (fa == null) { - return; - } + private static final String EMAIL_PARAM_NAME = "scEmail"; - ByteArrayOutputStream assetStream = new ByteArrayOutputStream(); - long readBytes = fa.writeBytes(assetStream); - if (readBytes == 0) { - return; - } + private final TrimmedStringParameter m_emailParam = new TrimmedStringParameter( + EMAIL_PARAM_NAME); + private FileSendColleaguePane m_parent; - String mimeTypeString = "application/octet-stream"; - MimeType mimeType = fa.getMimeType(); - if (mimeType != null) { - mimeTypeString = mimeType.getMimeType(); - } - s_log.debug("mimeTypeString: " + mimeTypeString); - mail.attach(assetStream.toByteArray(), mimeTypeString, doc.getTitle()); - mail.send(); - } - catch (java.io.IOException iox) { - s_log.error("SendForm.process", iox); + public SendForm(FileSendColleaguePane parent) { + super("sendEmail", new BoxPanel()); + + m_parent = parent; + + GridPanel panel = new GridPanel(2); + + panel.add(FILE_SEND_COLLEAGUE_FORM_EMAIL); + TextField emailField = new TextField(m_emailParam); + emailField.addValidationListener(new EmailValidationListener()); + panel.add(emailField, GridPanel.LEFT); + panel.add(new Submit(FILE_SEND_COLLEAGUE_SUBMIT)); + + add(panel); + + addProcessListener(this); + } + + public void process(FormSectionEvent e) throws FormProcessException { + + PageState state = e.getPageState(); + FormData data = e.getFormData(); + this.setVisible(state, false); + m_parent.displayThankYou(state); + + // send the mail + User u = Web.getWebContext().getUser(); + + s_log.debug(FILE_SEND_COLLEAGUE_RETURN_ADDRESS.localize().toString()); + + Mail mail = new Mail((String) data.get(EMAIL_PARAM_NAME), + FILE_SEND_COLLEAGUE_RETURN_ADDRESS.localize().toString(), + FILE_SEND_COLLEAGUE_SUBJECT.localize().toString(), + FILE_SEND_COLLEAGUE_MESSAGE.localize().toString() + " " + u. + getName()); + Document doc = new Document((BigDecimal) state.getValue(docIDParam)); + try { + FileAsset fa = doc.getFile(); + if (fa == null) { + return; + } + + ByteArrayOutputStream assetStream = new ByteArrayOutputStream(); + long readBytes = fa.writeBytes(assetStream); + if (readBytes == 0) { + return; + } + + String mimeTypeString = "application/octet-stream"; + MimeType mimeType = fa.getMimeType(); + if (mimeType != null) { + mimeTypeString = mimeType.getMimeType(); + } + s_log.debug("mimeTypeString: " + mimeTypeString); + mail.attach(assetStream.toByteArray(), mimeTypeString, doc.getTitle()); + mail.send(); + } catch (java.io.IOException iox) { + s_log.error("SendForm.process", iox); // iox.printStackTrace(); - throw new FormProcessException("An error occurred while trying to send document"); - } - catch (javax.mail.MessagingException mex) { - s_log.error("SendForm.process", mex); - //mex.printStackTrace(); - throw new FormProcessException("An error occurred while trying to send document"); - } - } - } - - class FileActionPane extends ColumnPanel implements RequestListener { - - private ActionLink m_newVersion; - private Link m_download; - private ActionLink m_email; - private ActionLink m_delete; - private ActionLink m_editLink; - private ActionLink m_fileRevisions; - - public FileActionPane() { - super(1); - - add(new BackCancelActionLink("back")); + throw new FormProcessException("An error occurred while trying to send document"); + } catch (javax.mail.MessagingException mex) { + s_log.error("SendForm.process", mex); + //mex.printStackTrace(); + throw new FormProcessException("An error occurred while trying to send document"); + } + } + } - m_editLink = new ActionLink(new Label(FILE_EDIT_LINK)); - m_editLink.setClassAttr("actionLink"); - m_editLink.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - PageState state = e.getPageState(); - displayEditForm(state); - } - }); - add(m_editLink); - - m_fileRevisions = new ActionLink("file revisions"); - m_fileRevisions.setClassAttr("actionLink"); - m_fileRevisions.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - PageState state = e.getPageState(); - m_parent.displayFileVersions(state, (BigDecimal) state.getValue(docIDParam)); - } - }); - add(m_fileRevisions); - - m_newVersion = addActionLink(FILE_NEW_VERSION_LINK); + class FileActionPane extends ColumnPanel implements RequestListener { - PrintListener printListener = new PrintListener() { - public void prepare(PrintEvent e) { - Link l = (Link) e.getTarget(); - PageState state = e.getPageState(); - Document f = new Document((BigDecimal) state.getValue(docIDParam)); - l.setTarget("download/?" + FILE_ID_PARAM_NAME + "=" + f.getID()); - } - }; + private ActionLink m_newVersion; + private Link m_download; + private ActionLink m_email; + private ActionLink m_delete; + private ActionLink m_editLink; + private ActionLink m_fileRevisions; - m_download = new Link(new Label(FILE_DOWNLOAD_LINK), printListener); - m_download.setClassAttr("actionLink"); - add(m_download); + public FileActionPane() { + super(1); - m_email = addActionLink(FILE_SEND_COLLEAGUE_LINK); - m_delete = addActionLink(FILE_DELETE_LINK); + add(new BackCancelActionLink("back")); - m_newVersion.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - displayUploadForm(e.getPageState()); - } - }); + m_editLink = new ActionLink(new Label(FILE_EDIT_LINK)); + m_editLink.setClassAttr("actionLink"); + m_editLink.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + PageState state = e.getPageState(); + displayEditForm(state); + } + }); + add(m_editLink); - m_email.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - displaySendColleagueForm(e.getPageState()); + m_fileRevisions = new ActionLink("file revisions"); + m_fileRevisions.setClassAttr("actionLink"); + m_fileRevisions.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + PageState state = e.getPageState(); + m_parent.displayFileVersions(state, (BigDecimal) state.getValue(docIDParam)); + } + }); + add(m_fileRevisions); - } - }); + m_newVersion = addActionLink(FILE_NEW_VERSION_LINK); - m_delete.addActionListener(new DeleteListener()); - m_delete.setConfirmation(FILE_DELETE_CONFIRM.localize().toString()); - } - - public void register(Page p) { - super.register(p); - p.addRequestListener(this); - } - - private ActionLink addActionLink(GlobalizedMessage msg) { - ActionLink ln = new ActionLink(new Label(msg)); - ln.setClassAttr("actionLink"); - this.add(ln); - return ln; - } + PrintListener printListener = new PrintListener() { + public void prepare(PrintEvent e) { + Link l = (Link) e.getTarget(); + PageState state = e.getPageState(); + Document f = new Document((BigDecimal) state.getValue(docIDParam)); + l.setTarget("download/?" + FILE_ID_PARAM_NAME + "=" + f.getID()); + } + }; - public void pageRequested(RequestEvent event) { - PageState state = event.getPageState(); - s_log.debug("pageRequested"); + m_download = new Link(new Label(FILE_DOWNLOAD_LINK), printListener); + m_download.setClassAttr("actionLink"); + add(m_download); - if (!isVisible(state)) { - // no point in hiding links - return; - } + m_email = addActionLink(FILE_SEND_COLLEAGUE_LINK); + m_delete = addActionLink(FILE_DELETE_LINK); - User user = Web.getWebContext().getUser(); - Application app = Web.getWebContext().getApplication(); + m_newVersion.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + displayUploadForm(e.getPageState()); + } + }); + + m_email.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + displaySendColleagueForm(e.getPageState()); + + } + }); + + m_delete.addActionListener(new DeleteListener()); + m_delete.setConfirmation(FILE_DELETE_CONFIRM.localize().toString()); + } + + public void register(Page p) { + super.register(p); + p.addRequestListener(this); + } + + private ActionLink addActionLink(GlobalizedMessage msg) { + ActionLink ln = new ActionLink(new Label(msg)); + ln.setClassAttr("actionLink"); + this.add(ln); + return ln; + } + + public void pageRequested(RequestEvent event) { + PageState state = event.getPageState(); + s_log.debug("pageRequested"); + + if (!isVisible(state)) { + // no point in hiding links + return; + } + + User user = Web.getWebContext().getUser(); + Application app = Web.getWebContext().getApplication(); // Document doc = new Document((BigDecimal) state.getValue(docIDParam)); - if (PermissionService.checkPermission(new PermissionDescriptor(PrivilegeDescriptor.ADMIN, app, user))) { - return; - } + if (PermissionService.checkPermission( + new PermissionDescriptor(PrivilegeDescriptor.ADMIN, app, user))) { + return; + } + + if (!PermissionService.checkPermission( + new PermissionDescriptor(PrivilegeDescriptor.EDIT, app, user))) { + m_editLink.setVisible(state, false); + m_delete.setVisible(state, false); + m_newVersion.setVisible(state, false); + } + } + } - if (!PermissionService.checkPermission(new PermissionDescriptor(PrivilegeDescriptor.EDIT, app, user))) { - m_editLink.setVisible(state, false); - m_delete.setVisible(state, false); - m_newVersion.setVisible(state, false); - } - } - } - /** - * Delete Listener of a file. - */ - private final class DeleteListener implements ActionListener { + * Delete Listener of a file. + */ + private final class DeleteListener implements ActionListener { - public void actionPerformed(ActionEvent e) { - PageState state = e.getPageState(); - Document doc = new Document((BigDecimal) state.getValue(docIDParam)); - ContentBundle cb = (ContentBundle) doc.getParent(); - String parentFolderID = cb.getParent().getID().toString(); - cb.delete(); + public void actionPerformed(ActionEvent e) { + PageState state = e.getPageState(); + Document doc = new Document((BigDecimal) state.getValue(docIDParam)); + ContentBundle cb = (ContentBundle) doc.getParent(); + String parentFolderID = cb.getParent().getID().toString(); + cb.delete(); - try { - String appURI = getRedirectURI(state); + try { + String appURI = getRedirectURI(state); - DispatcherHelper.sendRedirect(state.getRequest(), state.getResponse(), appURI + "?" + SEL_FOLDER_ID_PARAM.getName() + "=" - + parentFolderID); - } - catch (IOException iox) { - throw new UncheckedWrapperException(iox); - } - } + DispatcherHelper.sendRedirect(state.getRequest(), state.getResponse(), appURI + "?" + + SEL_FOLDER_ID_PARAM. + getName() + "=" + + parentFolderID); + } catch (IOException iox) { + throw new UncheckedWrapperException(iox); + } + } - private String getRedirectURI(PageState state) { - String appURI = state.getRequestURI(); - s_log.debug("Original app URI: " + appURI); - int idx = appURI.indexOf("/file/"); - if (idx > -1) { - appURI = appURI.substring(0, idx); - } + private String getRedirectURI(PageState state) { + String appURI = state.getRequestURI(); + s_log.debug("Original app URI: " + appURI); + int idx = appURI.indexOf("/file/"); + if (idx > -1) { + appURI = appURI.substring(0, idx); + } - final String servletPath = Web.getConfig().getDispatcherServletPath(); - if (appURI.startsWith(servletPath)) { - appURI = appURI.substring(servletPath.length()); - } + final String servletPath = Web.getConfig().getDispatcherServletPath(); + if (appURI.startsWith(servletPath)) { + appURI = appURI.substring(servletPath.length()); + } - s_log.debug("New URI: " + appURI); - return appURI; - } - } + s_log.debug("New URI: " + appURI); + return appURI; + } + } } diff --git a/ccm-docmgr/src/com/arsdigita/cms/docmgr/ui/CategoriesPrintListener.java b/ccm-docmgr/src/com/arsdigita/cms/docmgr/ui/CategoriesPrintListener.java index c76139373..6bc765fcc 100755 --- a/ccm-docmgr/src/com/arsdigita/cms/docmgr/ui/CategoriesPrintListener.java +++ b/ccm-docmgr/src/com/arsdigita/cms/docmgr/ui/CategoriesPrintListener.java @@ -12,7 +12,6 @@ * rights and limitations under the License. * */ - package com.arsdigita.cms.docmgr.ui; import java.math.BigDecimal; @@ -55,9 +54,9 @@ public class CategoriesPrintListener implements PrintListener { BigDecimalParameter selectedFileParam) { this(docsContentSection, selectedFileParam, false); } - + public CategoriesPrintListener(ContentSection docsContentSection, - BigDecimalParameter selectedFileParam, + BigDecimalParameter selectedFileParam, boolean showRoot) { m_docsContentSection = docsContentSection; m_selectedFileParam = selectedFileParam; @@ -65,10 +64,11 @@ public class CategoriesPrintListener implements PrintListener { } public void prepare(PrintEvent e) { - OptionGroup o = (OptionGroup)e.getTarget(); + OptionGroup o = (OptionGroup) e.getTarget(); + o.clearOptions(); PageState state = e.getPageState(); - Category root = - m_docsContentSection.getRootCategory(); + Category root + = m_docsContentSection.getRootCategory(); // Breadth-first traversal of the teee CategoryTreeModelLite model = new CategoryTreeModelLite(root); @@ -89,24 +89,24 @@ public class CategoriesPrintListener implements PrintListener { BigDecimal id = (BigDecimal) state.getValue(m_selectedFileParam); if (id != null) { ContentItem ci = new ContentItem(id); - CategoryCollection cats = ci.getCategoryCollection(); - Category cat; - if (cats.next()) { - cat = cats.getCategory(); - String catID = cat.getID().toString(); - assignedIDs.add(catID); + CategoryCollection cats = ci.getCategoryCollection(); + Category cat; + if (cats.next()) { + cat = cats.getCategory(); + String catID = cat.getID().toString(); + assignedIDs.add(catID); } - } + } } - + boolean firstLoop = true; - while(!queue.isEmpty()) { - DataQueryTreeNode node = (DataQueryTreeNode)queue.removeFirst(); - String name = (String)nameQueue.removeFirst(); + while (!queue.isEmpty()) { + DataQueryTreeNode node = (DataQueryTreeNode) queue.removeFirst(); + String name = (String) nameQueue.removeFirst(); // Process the node - String id = (String)node.getKey(); - + String id = (String) node.getKey(); + if (firstLoop && m_showRoot) { // can't assign to root category o.addOption(new Option(id, name)); @@ -116,11 +116,11 @@ public class CategoriesPrintListener implements PrintListener { if (model.hasChildren(node, state)) { // Append children - for(Iterator i = model.getChildren(node, state); i.hasNext(); ) { - TreeNode n = (TreeNode)i.next(); + for (Iterator i = model.getChildren(node, state); i.hasNext();) { + TreeNode n = (TreeNode) i.next(); queue.addLast(n); StringBuffer nameBuf = new StringBuffer(name); - if(name.length() > 0) { + if (name.length() > 0) { nameBuf.append(SEPARATOR); } nameBuf.append(n.getElement()); @@ -129,7 +129,7 @@ public class CategoriesPrintListener implements PrintListener { } firstLoop = false; } - + } //addFillerOption(o); diff --git a/ccm-docmgr/src/com/arsdigita/cms/docmgr/ui/FileEditForm.java b/ccm-docmgr/src/com/arsdigita/cms/docmgr/ui/FileEditForm.java index b8e50d73c..eb67f1f77 100755 --- a/ccm-docmgr/src/com/arsdigita/cms/docmgr/ui/FileEditForm.java +++ b/ccm-docmgr/src/com/arsdigita/cms/docmgr/ui/FileEditForm.java @@ -12,7 +12,6 @@ * rights and limitations under the License. * */ - package com.arsdigita.cms.docmgr.ui; import com.arsdigita.bebop.ColumnPanel; @@ -80,21 +79,21 @@ import java.util.Iterator; import java.util.TooManyListenersException; /** - * This component allows to change the file name and the - * description of a file. It also serves to associate - * keywords to a file (knowledge object). + * This component allows to change the file name and the description of a file. It also serves to + * associate keywords to a file (knowledge object). * - * @author Stefan Deusch - * @author Crag Wolfe + * @author Stefan Deusch + * @author Crag Wolfe */ class FileEditForm extends Form - implements FormValidationListener, - FormProcessListener, - FormInitListener, - DMConstants -{ - private final static org.apache.log4j.Logger s_log = - org.apache.log4j.Logger.getLogger(FileEditForm.class); + implements FormValidationListener, + FormProcessListener, + FormInitListener, + DMConstants { + + private final static org.apache.log4j.Logger s_log + = org.apache.log4j.Logger.getLogger( + FileEditForm.class); private final static String FILE_EDIT = "file-edit"; private final static String FILE_EDIT_CATS = "file-edit-cats"; @@ -123,17 +122,18 @@ class FileEditForm extends Form private final static String FILE_UPLOAD = "file-upload"; private final static String FILE_UPLOAD_FORM = "file-upload-form"; //private final static String FILE_UPLOAD_INPUT_DESCRIPTION = "file-description"; - + private Submit m_submit; public FileEditForm(Component parent) { - this(parent,false, null); + this(parent, false, null); } + /** * Constructor */ - public FileEditForm(Component parent, + public FileEditForm(Component parent, boolean creation, Tree tree) { super(FILE_EDIT, new ColumnPanel(2)); @@ -145,7 +145,7 @@ class FileEditForm extends Form m_FileAuthor = new TrimmedStringParameter(FILE_EDIT_AUTHOR); m_FileDesc = new StringParameter(FILE_EDIT_DESCRIPTION); m_FileCats = new ArrayParameter(FILE_EDIT_CATS); - + if (m_creation) { setMethod(Form.POST); setEncType("multipart/form-data"); @@ -153,20 +153,18 @@ class FileEditForm extends Form add(new Label(FILE_UPLOAD_ADD_FILE)); m_fileUpload = new FileUpload(FILE_UPLOAD); add(m_fileUpload); - } - else { - add(new Label(FILE_NAME_REQUIRED)); + } else { + add(new Label(FILE_NAME_REQUIRED)); m_FileName = new StringParameter(FILE_EDIT_FNAME); TextField fnameEntry = new TextField(m_FileName); add(fnameEntry); } - + add(new Label("Title"));//TODO m_FileTitle = new StringParameter(FILE_EDIT_TITLE); TextField fTitleEntry = new TextField(m_FileTitle); add(fTitleEntry); - add(new Label(FILE_INTENDED_AUDIENCE)); SingleSelect audienceEntry = new SingleSelect(m_FileAudience); try { @@ -183,17 +181,15 @@ class FileEditForm extends Form add(new Label(FILE_CATEGORIES)); MultipleSelect catSelect - = new MultipleSelect(FILE_EDIT_CATS); + = new MultipleSelect(FILE_EDIT_CATS); catSelect.setSize(20); try { BigDecimalParameter fileIDParam = null; if (!m_creation) { fileIDParam = getFileIDParam(); } - catSelect.addPrintListener - (new CategoriesPrintListener - (getContentSection(), - fileIDParam)); + catSelect.addPrintListener(new CategoriesPrintListener(getContentSection(), + fileIDParam)); } catch (java.util.TooManyListenersException tmex) { throw new UncheckedWrapperException(tmex.getMessage()); } @@ -215,7 +211,7 @@ class FileEditForm extends Form add(sc); - addInitListener(this); + addInitListener(this); addProcessListener(this); addValidationListener(this); } @@ -224,34 +220,34 @@ class FileEditForm extends Form * Initializer to pre-fill name and description */ public void init(FormSectionEvent e) - throws FormProcessException { + throws FormProcessException { - if (m_creation) { - initCreate(e); - } - else { - initEdit(e); + if (m_creation) { + initCreate(e); + } else { + initEdit(e); } } + public void initEdit(FormSectionEvent e) - throws FormProcessException { + throws FormProcessException { PageState state = e.getPageState(); - + FormData data = e.getFormData(); - - BigDecimal id = getSelectedDocID(state); + + BigDecimal id = getSelectedDocID(state); Document doc = DMUtils.getFile(id); ArrayList assignedCats = new ArrayList(); // Iterator i = doc.getCategories(); - CategoryCollection cats = doc.getCategoryCollection(); - Category cat; - if (cats.next()) { - cat = cats.getCategory(); - String catID = cat.getID().toString(); + CategoryCollection cats = doc.getCategoryCollection(); + Category cat; + if (cats.next()) { + cat = cats.getCategory(); + String catID = cat.getID().toString(); assignedCats.add(catID); - s_log.debug("init: "+catID); + s_log.debug("init: " + catID); } data.put(FILE_EDIT_FNAME, URLDecoder.decode(doc.getName())); @@ -262,8 +258,8 @@ class FileEditForm extends Form initAudienceFormData(data, doc); } - private void initCreate(FormSectionEvent e) - throws FormProcessException { + private void initCreate(FormSectionEvent e) + throws FormProcessException { if (m_parent instanceof BrowsePane) { PageState state = e.getPageState(); @@ -281,9 +277,9 @@ class FileEditForm extends Form * read form and update */ public void process(FormSectionEvent e) - throws FormProcessException { - - Document doc = null; + throws FormProcessException { + + Document doc = null; if (m_submit.isSelected(e.getPageState())) { if (m_creation) { doc = processCreate(e); @@ -295,24 +291,24 @@ class FileEditForm extends Form } private Document processEdit(FormSectionEvent e) - throws FormProcessException { + throws FormProcessException { PageState state = e.getPageState(); FormData data = e.getFormData(); Document doc = DMUtils.getFile(getSelectedDocID(state)); - setDocumentAttributes(data,doc); + setDocumentAttributes(data, doc); doc.setCategories((String[]) data.get(FILE_EDIT_CATS)); doc.setLastModifiedLocal(new java.util.Date()); doc.save(); // creates a new revision - setDocumentPermission(data,doc); + setDocumentPermission(data, doc); return doc; } private Document processCreate(FormSectionEvent e) - throws FormProcessException { + throws FormProcessException { PageState state = e.getPageState(); final FormData data = e.getFormData(); @@ -321,15 +317,14 @@ class FileEditForm extends Form final String fname = getUploadFileName(e); String titleTmp = (String) data.get(FILE_EDIT_TITLE); if (titleTmp == null || titleTmp.trim().length() == 0) { - titleTmp = fname; - MimeType mime = MimeType.guessMimeTypeFromFile(fname); - int index; - if (mime != null && (index = fname.lastIndexOf('.')) > -1) { - titleTmp = fname.substring(0, index); - } - else { - titleTmp = fname; - } + titleTmp = fname; + MimeType mime = MimeType.guessMimeTypeFromFile(fname); + int index; + if (mime != null && (index = fname.lastIndexOf('.')) > -1) { + titleTmp = fname.substring(0, index); + } else { + titleTmp = fname; + } } final String title = titleTmp; String fpath = (String) data.get(FILE_UPLOAD); @@ -340,8 +335,8 @@ class FileEditForm extends Form HttpServletRequest mreq = e.getPageState().getRequest(); Assert.isTrue(mreq instanceof MultipartHttpServletRequest, - "I got a " + mreq + " when I was " + - "expecting a MultipartHttpServletRequest"); + "I got a " + mreq + " when I was " + + "expecting a MultipartHttpServletRequest"); src = ((MultipartHttpServletRequest) mreq).getFile(FILE_UPLOAD); } @@ -359,15 +354,13 @@ class FileEditForm extends Form BigDecimal folderID = new BigDecimal(selKey); try { p = new DocFolder(folderID); - } catch(DataObjectNotFoundException nf) { - throw new ObjectNotFoundException - ((String) FOLDER_PARENTNOTFOUND_ERROR.localize(req)); + } catch (DataObjectNotFoundException nf) { + throw new ObjectNotFoundException((String) FOLDER_PARENTNOTFOUND_ERROR.localize(req)); } } final DocFolder parent = p; // insert the file in the data base below parent - final Document f1 = new Document(); // FR: define the bundle here @@ -378,62 +371,62 @@ class FileEditForm extends Form final ContentBundle bundle = new ContentBundle(f1); final FileAsset fa = new FileAsset(); - + new KernelExcursion() { - protected void excurse() { + protected void excurse() { // Create all the objects inside the kernel excursion - // so persistence doesn't barf... - setParty(Kernel.getSystemParty()); + // so persistence doesn't barf... + setParty(Kernel.getSystemParty()); //f1.setTitle(title); - //f1.setName(URLEncoder.encode(fname)); - //f1.setLanguage("en"); - fa.setName("temp"); - f1.setFile(fa); - bundle.setDefaultLanguage(f1.getLanguage()); - //bundle.addInstance(f1); - bundle.setName(fname); - bundle.setParent(parent); - bundle.setContentSection(parent.getContentSection()); - PermissionService.setContext(bundle,parent); - PermissionService.setContext(f1,bundle); - PermissionService.setContext(fa,f1); - bundle.save(); - f1.save(); - }}.run(); - + //f1.setName(URLEncoder.encode(fname)); + //f1.setLanguage("en"); + fa.setName("temp"); + f1.setFile(fa); + bundle.setDefaultLanguage(f1.getLanguage()); + //bundle.addInstance(f1); + bundle.setName(fname); + bundle.setParent(parent); + bundle.setContentSection(parent.getContentSection()); + PermissionService.setContext(bundle, parent); + PermissionService.setContext(f1, bundle); + PermissionService.setContext(fa, f1); + bundle.save(); + f1.save(); + } + }.run(); + try { - fa.loadFromFile(fname,src,"txt"); + fa.loadFromFile(fname, src, "txt"); } catch (java.io.IOException ex) { ex.printStackTrace(); throw new FormProcessException(ex.getMessage()); } - - Versions.tag(f1.getOID(),(FILE_UPLOAD_INITIAL_TRANSACTION_DESCRIPTION - .localize(req) - .toString())); - - setDocumentAttributes(data,f1); + + Versions.tag(f1.getOID(), (FILE_UPLOAD_INITIAL_TRANSACTION_DESCRIPTION + .localize(req) + .toString())); + + setDocumentAttributes(data, f1); // title must be set before name f1.setTitle(title); f1.setName(URLEncoder.encode(fname)); f1.setRepository(DocFolder.getRepository(p)); - + f1.setLastModifiedLocal(f1.getLastModifiedDate()); - + //f1.save(); // context has been set, now add additional permissions - setDocumentPermission(data,f1); - + setDocumentPermission(data, f1); + f1.setCategories((String[]) data.get(FILE_EDIT_CATS)); bundle.save(); - return f1; + return f1; } private void setDocumentAttributes(FormData data, Document doc) { - - + if (!m_creation) { String ftitle = (String) data.get(FILE_EDIT_TITLE); String fname = (String) data.get(FILE_EDIT_FNAME); @@ -460,21 +453,22 @@ class FileEditForm extends Form /** * Test if the new name already exists in the current folder */ - public void validate(FormSectionEvent event) - throws FormProcessException { + throws FormProcessException { if (m_submit.isSelected(event.getPageState())) { FormData data = event.getFormData(); //validate length of author String author = (String) data.get(FILE_EDIT_AUTHOR); if (author != null && author.length() > 200) { - data.addError(FILE_EDIT_AUTHOR, "This parameter is too long. It must be fewer than 200 characters."); + data.addError(FILE_EDIT_AUTHOR, + "This parameter is too long. It must be fewer than 200 characters."); } //validate length of description String desc = (String) data.get(FILE_EDIT_DESCRIPTION); if (desc != null && desc.length() > 4000) { - data.addError(FILE_EDIT_DESCRIPTION, "This parameter is too long. It must be fewer than 4000 characters."); + data.addError(FILE_EDIT_DESCRIPTION, + "This parameter is too long. It must be fewer than 4000 characters."); } if (m_creation) { @@ -486,29 +480,28 @@ class FileEditForm extends Form } private void validateCreate(FormSectionEvent e) - throws FormProcessException { + throws FormProcessException { PageState state = e.getPageState(); FormData data = e.getFormData(); HttpServletRequest req = state.getRequest(); String fname = (String) data.get(FILE_UPLOAD); if (fname == null || fname.length() == 0) { - data.addError(FILE_UPLOAD, "This parameter is required."); + data.addError(FILE_UPLOAD, "This parameter is required."); } - + fname = DMUtils.extractFileName(getUploadFileName(e), state); // XXX Not localized as the other errors are. if (fname.length() > 200) { - data.addError - (FILE_UPLOAD, - "This filename is too long. It must be fewer than 200 characters."); + data.addError(FILE_UPLOAD, + "This filename is too long. It must be fewer than 200 characters."); } String title = (String) data.get(FILE_EDIT_TITLE); if (title != null && title.length() > 200) { - data.addError(FILE_EDIT_TITLE, - "This title is too long. It must be fewer than 200 characters."); + data.addError(FILE_EDIT_TITLE, + "This title is too long. It must be fewer than 200 characters."); } DocFolder parent = null; @@ -520,100 +513,91 @@ class FileEditForm extends Form BigDecimal folderID = new BigDecimal(selKey); try { parent = new DocFolder(folderID); - } catch(DataObjectNotFoundException nf) { + } catch (DataObjectNotFoundException nf) { throw new ObjectNotFoundException(FOLDER_PARENTNOTFOUND_ERROR - .localize(req).toString()); + .localize(req).toString()); } } // Now we have the parent, make sure the user is allowed to create here parent.assertPrivilege(PrivilegeDescriptor.CREATE); - + try { parent.retrieveSubResource(fname); data.addError(FILE_UPLOAD, RESOURCE_EXISTS_ERROR .localize(req).toString()); - } catch(DataObjectNotFoundException nf) { + } catch (DataObjectNotFoundException nf) { // ok here }// catch(InvalidNameException ex) { } private void validateEdit(FormSectionEvent event) - throws FormProcessException { + throws FormProcessException { // PageState state = event.getPageState(); FormData data = event.getFormData(); - + String fname = (String) data.get(FILE_EDIT_FNAME); if (fname == null || fname.trim().length() == 0) { - data.addError(FILE_EDIT_FNAME, "This parameter is required"); + data.addError(FILE_EDIT_FNAME, "This parameter is required"); } - + String title = (String) data.get(FILE_EDIT_TITLE); if (title == null || title.length() == 0) { data.addError(FILE_EDIT_TITLE, "This parameter is required."); + } else if (title.length() > 200) { + data.addError(FILE_EDIT_TITLE, + "This title is too long. It must be fewer than 200 characters."); } - else if (title.length() > 200) { - data.addError(FILE_EDIT_TITLE, - "This title is too long. It must be fewer than 200 characters."); - } - + // HttpServletRequest req = state.getRequest(); - // Document doc = DMUtils.getFile(getSelectedDocID(state)); - // // Construct a name with the optional extension - // String name = doc.getName(); - // if (!doc.isValidNewName(name)) { // data.addError(FILE_EDIT_FNAME, // "Not a valid new name for this file"); // } - // Verify that the new name does not correspond to an existing // resource (file or folder) - // XXX we need this, but leaving it broken for now... --hbrock - /* - if (!name.equals(file.getName())) { - try { - Folder parent = (Folder) file.getParent(); - parent.getResourceID(name); - data.addError(FILE_EDIT_FNAME, - (String)RESOURCE_EXISTS_ERROR.localize(req)); - } catch(DataObjectNotFoundException nfe) { - // good, so we can rename it - } catch (InvalidNameException ex) { - data.addError(FILE_EDIT_FNAME, - ex.getMessage()); - } - } - */ + /* + if (!name.equals(file.getName())) { + try { + Folder parent = (Folder) file.getParent(); + parent.getResourceID(name); + data.addError(FILE_EDIT_FNAME, + (String)RESOURCE_EXISTS_ERROR.localize(req)); + } catch(DataObjectNotFoundException nfe) { + // good, so we can rename it + } catch (InvalidNameException ex) { + data.addError(FILE_EDIT_FNAME, + ex.getMessage()); + } + } + */ } /* Initialize form data for document's intended audience. */ private void initAudienceFormData(FormData data, - Document doc) { - ObjectPermissionCollection opc = - PermissionService.getDirectGrantedPermissions(doc.getOID()); + Document doc) { + ObjectPermissionCollection opc + = PermissionService.getDirectGrantedPermissions(doc.getOID()); long numPermissions = opc.size(); if (numPermissions > 1) { - s_log.error("there should only be 1 direct permission for "+ - "a document"); + s_log.error("there should only be 1 direct permission for " + "a document"); } if (numPermissions == 0) { - data.put(FILE_EDIT_AUDIENCE,"workspace"); + data.put(FILE_EDIT_AUDIENCE, "workspace"); opc.close(); return; } boolean isPublic = false; while (opc.next()) { - if (opc.getGranteeID().intValue() == - PermissionManager.VIRTUAL_PUBLIC_ID) { + if (opc.getGranteeID().intValue() == PermissionManager.VIRTUAL_PUBLIC_ID) { isPublic = true; } } @@ -626,38 +610,35 @@ class FileEditForm extends Form } /* Grant/revoke direct permissions as needed. - Note that workspace permissions is always implied. - */ + Note that workspace permissions is always implied. + */ private void setDocumentPermission(FormData data, - Document doc) - throws FormProcessException { + Document doc) + throws FormProcessException { final String intendedAudience = (String) data.get(FILE_EDIT_AUDIENCE); if (intendedAudience == null) { - throw new FormProcessException - ("Intended Audience cannot be null"); + throw new FormProcessException("Intended Audience cannot be null"); } - final PermissionDescriptor publicDescriptor = - new PermissionDescriptor - (PrivilegeDescriptor.READ, - doc.getOID(), - new OID(User.BASE_DATA_OBJECT_TYPE, - PermissionManager.VIRTUAL_PUBLIC_ID)); - final PermissionDescriptor internalDescriptor = - new PermissionDescriptor - (PrivilegeDescriptor.READ, - doc.getOID(), - new OID(Group.BASE_DATA_OBJECT_TYPE, - DocMgr.getConfig().getInternalGroupID())); + final PermissionDescriptor publicDescriptor + = new PermissionDescriptor(PrivilegeDescriptor.READ, + doc.getOID(), + new OID(User.BASE_DATA_OBJECT_TYPE, + PermissionManager.VIRTUAL_PUBLIC_ID)); + final PermissionDescriptor internalDescriptor + = new PermissionDescriptor(PrivilegeDescriptor.READ, + doc.getOID(), + new OID(Group.BASE_DATA_OBJECT_TYPE, + DocMgr.getConfig(). + getInternalGroupID())); new KernelExcursion() { protected void excurse() { //Party currentParty = Kernel.getWebContext().getParty(); - setParty(Kernel.getSystemParty()); - if("public".equals(intendedAudience)) { + if ("public".equals(intendedAudience)) { PermissionService.grantPermission(publicDescriptor); PermissionService.revokePermission(internalDescriptor); - } else if("internal".equals(intendedAudience)) { + } else if ("internal".equals(intendedAudience)) { PermissionService.revokePermission(publicDescriptor); PermissionService.grantPermission(internalDescriptor); } else { @@ -666,10 +647,11 @@ class FileEditForm extends Form PermissionService.revokePermission(internalDescriptor); } } - }.run(); + }.run(); } protected class AuthorLabelPrinter implements PrintListener { + public AuthorLabelPrinter() { // Empty } @@ -680,38 +662,39 @@ class FileEditForm extends Form String name = Web.getWebContext().getUser().getName(); - label.setLabel("Author: (if not "+name+")"); + label.setLabel("Author: (if not " + name + ")"); } } protected class IntendedAudienceSelectPrinter implements PrintListener { + public IntendedAudienceSelectPrinter() { } public void prepare(PrintEvent e) { SingleSelect select = (SingleSelect) e.getTarget(); + select.clearOptions(); - select.addOption - (new Option("workspace", - Web.getWebContext().getApplication() - .getParentApplication() == null ? Web.getWebContext().getApplication().getDisplayName() - : Web.getWebContext().getApplication().getParentApplication().getDisplayName()+ - " members")); - - select.addOption - (new Option("internal", - new Label(FILE_INTENDED_AUDIENCE_INTERNAL))); - select.addOption - (new Option("public", - new Label(FILE_INTENDED_AUDIENCE_PUBLIC))); + select.addOption(new Option("workspace", + Web.getWebContext().getApplication() + .getParentApplication() == null ? Web.getWebContext(). + getApplication().getDisplayName() + : Web.getWebContext().getApplication(). + getParentApplication().getDisplayName() + " members")); + + select.addOption(new Option("internal", + new Label(FILE_INTENDED_AUDIENCE_INTERNAL))); + select.addOption(new Option("public", + new Label(FILE_INTENDED_AUDIENCE_PUBLIC))); } } private ContentSection getContentSection() { ContentSectionCollection csl = ContentSection.getAllSections(); - csl.addEqualsFilter("label",DocMgr.getConfig().getContentSection()); + csl.addEqualsFilter("label", DocMgr.getConfig().getContentSection()); if (!csl.next()) { - csl.close(); return null; + csl.close(); + return null; } ContentSection docsContentSection = csl.getContentSection(); csl.close(); @@ -725,38 +708,33 @@ class FileEditForm extends Form } return (BigDecimal) state.getValue(getFileIDParam()); } - + private BigDecimalParameter getFileIDParam() { - if (m_parent instanceof FileInfoPropertiesPane) { - return ((FileInfoPropertiesPane) m_parent).getFileIDParam(); - } - else { - if (m_parent instanceof BrowseFileInfoPropertiesPane) { - ((BrowseFileInfoPropertiesPane) m_parent).getFileIDParam(); - } - } - return null; + if (m_parent instanceof FileInfoPropertiesPane) { + return ((FileInfoPropertiesPane) m_parent).getFileIDParam(); + } else { + if (m_parent instanceof BrowseFileInfoPropertiesPane) { + ((BrowseFileInfoPropertiesPane) m_parent).getFileIDParam(); + } + } + return null; } - + private void backCancel(PageState state, BigDecimal docID) { - if (m_parent instanceof BrowsePane) { - if (docID != null) { - ((BrowsePane) m_parent).displayFilePropPanel(state, docID); - } - else { - ((BrowsePane) m_parent).displayFolderContentPanel(state); - } - } - else { - if (m_parent instanceof FileInfoPropertiesPane) { - ((FileInfoPropertiesPane) m_parent).displayPropertiesAndActions(state); - } - else { - if (m_parent instanceof BrowseFileInfoPropertiesPane) { - ((BrowseFileInfoPropertiesPane) m_parent).displayPropertiesPane(state); - } - } - } + if (m_parent instanceof BrowsePane) { + if (docID != null) { + ((BrowsePane) m_parent).displayFilePropPanel(state, docID); + } else { + ((BrowsePane) m_parent).displayFolderContentPanel(state); + } + } else { + if (m_parent instanceof FileInfoPropertiesPane) { + ((FileInfoPropertiesPane) m_parent).displayPropertiesAndActions(state); + } else { + if (m_parent instanceof BrowseFileInfoPropertiesPane) { + ((BrowseFileInfoPropertiesPane) m_parent).displayPropertiesPane(state); + } + } + } } } - diff --git a/ccm-docmgr/src/com/arsdigita/cms/docmgr/ui/SearchPane.java b/ccm-docmgr/src/com/arsdigita/cms/docmgr/ui/SearchPane.java index 8b1ccdb01..bf3bb941a 100755 --- a/ccm-docmgr/src/com/arsdigita/cms/docmgr/ui/SearchPane.java +++ b/ccm-docmgr/src/com/arsdigita/cms/docmgr/ui/SearchPane.java @@ -12,7 +12,6 @@ * rights and limitations under the License. * */ - package com.arsdigita.cms.docmgr.ui; import com.arsdigita.bebop.*; @@ -47,10 +46,11 @@ import java.util.TooManyListenersException; * * @author Crag Wolfe */ -class SearchPane extends SimpleContainer implements DMConstants -{ - private static final org.apache.log4j.Logger s_log = - org.apache.log4j.Logger.getLogger(SearchPane.class); +class SearchPane extends SimpleContainer implements DMConstants { + + private static final org.apache.log4j.Logger s_log + = org.apache.log4j.Logger.getLogger( + SearchPane.class); public static final String SEARCH_AUTHOR = "searchAuthor"; public static final String SEARCH_TERMS = "searchTerms"; @@ -58,8 +58,8 @@ class SearchPane extends SimpleContainer implements DMConstants public static final String CATEGORY_SELECT = "searchCategorySelect"; public static final String WORKSPACE_SELECT = "workspaceSelect"; - private final BigDecimalParameter m_categoriesParam = new BigDecimalParameter(CATEGORY_SELECT) ; - private final BigDecimalParameter m_workspaceParam = new BigDecimalParameter(WORKSPACE_SELECT) ; + private final BigDecimalParameter m_categoriesParam = new BigDecimalParameter(CATEGORY_SELECT); + private final BigDecimalParameter m_workspaceParam = new BigDecimalParameter(WORKSPACE_SELECT); private final TrimmedStringParameter m_termsParam = new TrimmedStringParameter(SEARCH_TERMS); private final TrimmedStringParameter m_authorParam = new TrimmedStringParameter(SEARCH_AUTHOR); private final StringParameter m_mimeTypeParam = new StringParameter(SEARCH_MIME_TYPE); @@ -86,26 +86,25 @@ class SearchPane extends SimpleContainer implements DMConstants // set component's content section ContentSectionCollection csl = ContentSection.getAllSections(); - csl.addEqualsFilter("label",DocMgr.getConfig().getContentSection()); + csl.addEqualsFilter("label", DocMgr.getConfig().getContentSection()); if (!csl.next()) { - csl.close(); return; + csl.close(); + return; } m_docsContentSection = csl.getContentSection(); csl.close(); // bebop components //m_mainTabPane = new SimpleContainer(); - m_mainBrowseContainer = new BoxPanel(BoxPanel.HORIZONTAL, true); //m_mainTabPane.addTab(WS_SEARCH_TITLE, // m_mainBrowseContainer); //m_mainTabPane.add(new Label("yo")); //m_mainBrowseContainer.setClassAttr("sidebarNavPanel"); - DocsSearchForm leftSide = new DocsSearchForm(new GridPanel(2)); m_mainBrowseContainer.add(leftSide); - m_mainBrowseContainer.add(new Label("     ",false)); + m_mainBrowseContainer.add(new Label("     ", false)); m_model = new SearchListModelBuilder(leftSide); @@ -124,10 +123,10 @@ class SearchPane extends SimpleContainer implements DMConstants m_segmentHeader.setDefaultComponent(m_emptyLabel); rightSide.addSegment( - // (new Label(new EmptySearchPrintListener(leftSide)), - m_segmentHeader, - m_searchList); - + // (new Label(new EmptySearchPrintListener(leftSide)), + m_segmentHeader, + m_searchList); + m_mainBrowseContainer.add(rightSide); //m_searchResultsTable = new Table(new SearchTableModelBuilder(), @@ -150,13 +149,14 @@ class SearchPane extends SimpleContainer implements DMConstants p.addGlobalStateParam(m_endDateParam); p.addGlobalStateParam(m_startDateParam); } - - private class DocsSearchForm extends Form - implements SearchForm, FormValidationListener, - FormProcessListener, FormInitListener { + + private class DocsSearchForm extends Form + implements SearchForm, FormValidationListener, + FormProcessListener, FormInitListener { + public DocsSearchForm(Container panel) { - super("docSearch",panel); - + super("docSearch", panel); + add(new Label("Search text:")); TextField searchText = new TextField(SEARCH_TERMS); //searchText.addValidationListener(new NotEmptyValidationListener()); @@ -172,32 +172,27 @@ class SearchPane extends SimpleContainer implements DMConstants add(new com.arsdigita.bebop.form.Date(m_endDateParam)); add(new Label("Category")); - SingleSelect categoriesWidget = - new SingleSelect(m_categoriesParam); + SingleSelect categoriesWidget + = new SingleSelect(m_categoriesParam); try { - categoriesWidget.addOption(new Option("","")); - categoriesWidget.addPrintListener - (new CategoriesPrintListener - (m_docsContentSection)); + categoriesWidget.addOption(new Option("", "")); + categoriesWidget.addPrintListener(new CategoriesPrintListener(m_docsContentSection)); } catch (TooManyListenersException e) { - UncheckedWrapperException.throwLoggedException - (getClass(), "Too many listeners", e); + UncheckedWrapperException.throwLoggedException(getClass(), "Too many listeners", e); } add(categoriesWidget); //categoriesWidget.setSize(SELECT_HEIGHT); add(new Label("Workspace")); - SingleSelect workspaceWidget = - new SingleSelect(m_workspaceParam); + SingleSelect workspaceWidget + = new SingleSelect(m_workspaceParam); try { - workspaceWidget.addPrintListener - (new WorkspacesPrintListener()); + workspaceWidget.addPrintListener(new WorkspacesPrintListener()); } catch (TooManyListenersException e) { - UncheckedWrapperException.throwLoggedException - (getClass(), "Too many listeners", e); + UncheckedWrapperException.throwLoggedException(getClass(), "Too many listeners", e); } add(workspaceWidget); - + m_submit = new Submit("search", "Search"); add(m_submit); addInitListener(this); @@ -206,26 +201,23 @@ class SearchPane extends SimpleContainer implements DMConstants } public void validate(FormSectionEvent e) - throws FormProcessException { + throws FormProcessException { PageState state = e.getPageState(); - - String terms = (String)state.getValue(m_termsParam); - String author = (String)state.getValue(m_authorParam); - String mimeType = (String)state.getValue(m_mimeTypeParam); - Date endDate = (Date)state.getValue(m_endDateParam); - Date startDate = (Date)state.getValue(m_startDateParam); - BigDecimal workspaceID = (BigDecimal)state.getValue(m_workspaceParam); - BigDecimal categoryID = - (BigDecimal) state.getValue(m_categoriesParam); - if (StringUtils.emptyString(terms) && - StringUtils.emptyString(author) && - StringUtils.emptyString(mimeType) && - endDate == null && - startDate == null && - categoryID == null && - workspaceID == null) { - m_emptyLabel.setVisible(state,true); + String terms = (String) state.getValue(m_termsParam); + String author = (String) state.getValue(m_authorParam); + String mimeType = (String) state.getValue(m_mimeTypeParam); + Date endDate = (Date) state.getValue(m_endDateParam); + Date startDate = (Date) state.getValue(m_startDateParam); + BigDecimal workspaceID = (BigDecimal) state.getValue(m_workspaceParam); + BigDecimal categoryID + = (BigDecimal) state.getValue(m_categoriesParam); + + if (StringUtils.emptyString(terms) && StringUtils.emptyString(author) && StringUtils. + emptyString(mimeType) && endDate == null && startDate == null && categoryID + == null + && workspaceID == null) { + m_emptyLabel.setVisible(state, true); m_validated.set(state, new Boolean(false)); throw new FormProcessException("At least one search parameter must be specified"); } @@ -233,57 +225,50 @@ class SearchPane extends SimpleContainer implements DMConstants } public void init(FormSectionEvent e) { - m_segmentHeader.setVisibleComponent - (e.getPageState(),m_emptyLabel); + m_segmentHeader.setVisibleComponent(e.getPageState(), m_emptyLabel); } public void process(FormSectionEvent e) { PageState state = e.getPageState(); SearchResults results = getSearchHits(state); - if(results != null && - results.getTotalSize() > 0) { - m_segmentHeader.setVisibleComponent - (state,m_hasResultsLabel); + if (results != null && results.getTotalSize() > 0) { + m_segmentHeader.setVisibleComponent(state, m_hasResultsLabel); s_log.debug("results"); } else { - m_segmentHeader.setVisibleComponent - (state,m_noResultsLabel); + m_segmentHeader.setVisibleComponent(state, m_noResultsLabel); s_log.debug("no results"); } } - public SearchResults getSearchHits( PageState state ) { + public SearchResults getSearchHits(PageState state) { SearchResults coln = (SearchResults) m_coln.get(state); - if (coln == null && - m_submit.isSelected(state) && - ((Boolean) m_validated.get(state)).booleanValue()) { - String terms = (String)state.getValue(m_termsParam); - String author = (String)state.getValue(m_authorParam); - String mimeType = (String)state.getValue(m_mimeTypeParam); - Date endDate = (Date)state.getValue(m_endDateParam); - Date startDate = (Date)state.getValue(m_startDateParam); - BigDecimal workspaceID = (BigDecimal)state.getValue(m_workspaceParam); + if (coln == null && m_submit.isSelected(state) && ((Boolean) m_validated.get(state)). + booleanValue()) { + String terms = (String) state.getValue(m_termsParam); + String author = (String) state.getValue(m_authorParam); + String mimeType = (String) state.getValue(m_mimeTypeParam); + Date endDate = (Date) state.getValue(m_endDateParam); + Date startDate = (Date) state.getValue(m_startDateParam); + BigDecimal workspaceID = (BigDecimal) state.getValue(m_workspaceParam); String[] sections = null; if (!LuceneSearcher.class.equals(SearchUtils.getSearcher().getClass())) { - sections = (String[]) new String[] - {m_docsContentSection.getID().toString()}; + sections = (String[]) new String[]{m_docsContentSection.getID().toString()}; } // don't need this since all types in this section are documents //String[] types = (String[])state.getValue(m_typesParam); String[] types = null; - BigDecimal rootCategoryID = - m_docsContentSection.getRootCategory().getID(); + BigDecimal rootCategoryID + = m_docsContentSection.getRootCategory().getID(); ArrayList categoryIDs = new ArrayList(); if (!LuceneSearcher.class.equals(SearchUtils.getSearcher().getClass())) { - BigDecimal categoryID = - (BigDecimal) state.getValue(m_categoriesParam); - if (categoryID != null && - !categoryID.equals(rootCategoryID)) { + BigDecimal categoryID + = (BigDecimal) state.getValue(m_categoriesParam); + if (categoryID != null && !categoryID.equals(rootCategoryID)) { categoryIDs.add(categoryID.toString()); } @@ -299,10 +284,10 @@ class SearchPane extends SimpleContainer implements DMConstants // } //} } - + //if (terms != null && !"".equals(terms)) { // if form has been submitted, m_emptyLabel will not be visible - User user = (User)Kernel.getContext().getParty(); + User user = (User) Kernel.getContext().getParty(); coln = SearchUtils.getAdvancedSearch(terms, author, mimeType, @@ -313,7 +298,7 @@ class SearchPane extends SimpleContainer implements DMConstants sections, user, categoryIDs); - //} + //} m_coln.set(state, coln); } return coln; @@ -322,54 +307,55 @@ class SearchPane extends SimpleContainer implements DMConstants public boolean isVisible(PageState state) { return true; } + public long getSearchResultCount(PageState state) { - return m_coln.get(state) == null ? 0 : - ((SearchResults)m_coln.get(state)).getTotalSize(); + return m_coln.get(state) == null ? 0 + : ((SearchResults) m_coln.get(state)).getTotalSize(); } } - private class MimeTypesWidget extends SingleSelect { - public MimeTypesWidget (ParameterModel pm) { + public MimeTypesWidget(ParameterModel pm) { super(pm); - addOption(new Option("","")); - addOption(new Option("excel","Excel document")); - addOption(new Option("html","HTML")); - addOption(new Option("acrobat","PDF")); - addOption(new Option("plain text","Plain text")); - addOption(new Option("powerpoint","Powerpoint file")); - addOption(new Option("rich text","Rich Text Format (rtf)")); - addOption(new Option("word","Word document")); + addOption(new Option("", "")); + addOption(new Option("excel", "Excel document")); + addOption(new Option("html", "HTML")); + addOption(new Option("acrobat", "PDF")); + addOption(new Option("plain text", "Plain text")); + addOption(new Option("powerpoint", "Powerpoint file")); + addOption(new Option("rich text", "Rich Text Format (rtf)")); + addOption(new Option("word", "Word document")); } } private class WorkspacesPrintListener implements PrintListener { - public WorkspacesPrintListener() { } + + public WorkspacesPrintListener() { + } public void prepare(PrintEvent e) { - OptionGroup o = (OptionGroup)e.getTarget(); + OptionGroup o = (OptionGroup) e.getTarget(); + o.clearOptions(); PageState state = e.getPageState(); User user = Web.getWebContext().getUser(); - o.addOption(new Option("","")); - DataQuery dq = SessionManager.getSession().retrieveQuery - ("com.arsdigita.cms.docmgr.workspacesWithRepositories"); - while(dq.next()) { - if (PermissionService.checkPermission - (new PermissionDescriptor - (PrivilegeDescriptor.READ, - new OID(Document.BASE_DATA_OBJECT_TYPE, - dq.get("workspaceID")), - user.getOID()))) { - o.addOption(new Option - (((BigDecimal) dq.get("workspaceID")).toString(), - (String) dq.get("title"))); + o.addOption(new Option("", "")); + DataQuery dq = SessionManager.getSession().retrieveQuery( + "com.arsdigita.cms.docmgr.workspacesWithRepositories"); + while (dq.next()) { + if (PermissionService.checkPermission(new PermissionDescriptor( + PrivilegeDescriptor.READ, + new OID(Document.BASE_DATA_OBJECT_TYPE, + dq.get("workspaceID")), + user.getOID()))) { + o.addOption(new Option(((BigDecimal) dq.get("workspaceID")).toString(), + (String) dq.get("title"))); } - + dq.close(); - } + } } } diff --git a/ccm-forum/src/com/arsdigita/forum/ui/CategoryWidget.java b/ccm-forum/src/com/arsdigita/forum/ui/CategoryWidget.java index b6be6626e..038f5871d 100755 --- a/ccm-forum/src/com/arsdigita/forum/ui/CategoryWidget.java +++ b/ccm-forum/src/com/arsdigita/forum/ui/CategoryWidget.java @@ -50,23 +50,24 @@ public class CategoryWidget extends SingleSelect implements Constants { try { addPrintListener(new PrintListener() { - public void prepare(PrintEvent e) { - PageState s = e.getPageState(); - final Forum forum = getForum(s); - SingleSelect target = (SingleSelect) e.getTarget(); - - // Get categories for this forum - if (forum.noCategoryPostsAllowed()) { - target.addOption(new Option( - TOPIC_NONE.toString(), - new Label(GlobalizationUtil.gz("forum.ui.topic.none")))); - } - final Category root = forum.getRootCategory(); - if (root != null) { - addCategories(root, target); - } + public void prepare(PrintEvent e) { + PageState s = e.getPageState(); + final Forum forum = getForum(s); + SingleSelect target = (SingleSelect) e.getTarget(); + target.clearOptions(); + + // Get categories for this forum + if (forum.noCategoryPostsAllowed()) { + target.addOption(new Option( + TOPIC_NONE.toString(), + new Label(GlobalizationUtil.gz("forum.ui.topic.none")))); } - }); + final Category root = forum.getRootCategory(); + if (root != null) { + addCategories(root, target); + } + } + }); } catch (TooManyListenersException ex) { throw new UncheckedWrapperException(ex); } @@ -83,9 +84,8 @@ public class CategoryWidget extends SingleSelect implements Constants { try { while (children.next()) { Category c = children.getCategory(); - target.addOption(new Option - (c.getID().toString(), - c.getName())); + target.addOption(new Option(c.getID().toString(), + c.getName())); } } finally { @@ -101,16 +101,15 @@ public class CategoryWidget extends SingleSelect implements Constants { */ private Forum getForum(final PageState s) { Forum forum; - if (ForumContext.getContext(s).getThreadID() != null ) { - Post rootPost = (Post)ForumContext.getContext(s). - getMessageThread().getRootMessage(); + if (ForumContext.getContext(s).getThreadID() != null) { + Post rootPost = (Post) ForumContext.getContext(s). + getMessageThread().getRootMessage(); forum = rootPost.getForum(); } else if (ForumContext.getContext(s).getForum() != null) { forum = ForumContext.getContext(s).getForum(); } else { // sanity check - throw new UncheckedWrapperException - ("Must be either a forum, or a thread page."); + throw new UncheckedWrapperException("Must be either a forum, or a thread page."); } return forum; } diff --git a/ccm-ldn-atoz/src/com/arsdigita/london/atoz/ui/DomainProviderForm.java b/ccm-ldn-atoz/src/com/arsdigita/london/atoz/ui/DomainProviderForm.java index 89af35d2a..b51b4dee8 100755 --- a/ccm-ldn-atoz/src/com/arsdigita/london/atoz/ui/DomainProviderForm.java +++ b/ccm-ldn-atoz/src/com/arsdigita/london/atoz/ui/DomainProviderForm.java @@ -75,6 +75,7 @@ public class DomainProviderForm extends AbstractProviderForm { m_domain.addPrintListener(new PrintListener() { public void prepare(PrintEvent e) { SingleSelect s = (SingleSelect)e.getTarget(); + s.clearOptions(); DataCollection domains = SessionManager.getSession() .retrieve(Domain.BASE_DATA_OBJECT_TYPE); diff --git a/ccm-ldn-dublin/src/com/arsdigita/london/cms/dublin/ui/ControlledList.java b/ccm-ldn-dublin/src/com/arsdigita/london/cms/dublin/ui/ControlledList.java index 5022e362b..69e8e8265 100755 --- a/ccm-ldn-dublin/src/com/arsdigita/london/cms/dublin/ui/ControlledList.java +++ b/ccm-ldn-dublin/src/com/arsdigita/london/cms/dublin/ui/ControlledList.java @@ -49,6 +49,7 @@ public class ControlledList extends SingleSelect { addPrintListener(new PrintListener() { public void prepare(PrintEvent e) { ControlledList target = (ControlledList)e.getTarget(); + target.clearOptions(); target.populate(); } }); diff --git a/ccm-ldn-terms/src/com/arsdigita/london/terms/ui/admin/DomainContextForm.java b/ccm-ldn-terms/src/com/arsdigita/london/terms/ui/admin/DomainContextForm.java index 35a6f377b..7fb26eaf3 100755 --- a/ccm-ldn-terms/src/com/arsdigita/london/terms/ui/admin/DomainContextForm.java +++ b/ccm-ldn-terms/src/com/arsdigita/london/terms/ui/admin/DomainContextForm.java @@ -15,7 +15,6 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - package com.arsdigita.london.terms.ui.admin; import com.arsdigita.bebop.Form; @@ -43,10 +42,9 @@ import com.arsdigita.web.ApplicationCollection; import java.util.TooManyListenersException; - /** - * - * + * + * */ public class DomainContextForm extends Form { @@ -56,18 +54,18 @@ public class DomainContextForm extends Form { private TextField m_context; private SaveCancelSection m_buttons; - + public DomainContextForm(String name, DomainObjectParameter domain) { super(name, new SimpleContainer("terms:domainContextForm", Terms.XML_NS)); setRedirecting(true); - + m_domain = domain; - + addWidgets(); - + m_buttons = new SaveCancelSection(new SimpleContainer()); add(m_buttons); @@ -75,25 +73,26 @@ public class DomainContextForm extends Form { addProcessListener(new DomainProcessListener()); addSubmissionListener(new DomainSubmissionListener()); } - + protected void addWidgets() { m_app = new SingleSelect(new DomainObjectParameter("app")); m_app.addValidationListener(new NotNullValidationListener()); try { m_app.addPrintListener(new PrintListener() { - public void prepare(PrintEvent e) { - SingleSelect t = (SingleSelect)e.getTarget(); - ApplicationCollection apps = Application + public void prepare(PrintEvent e) { + SingleSelect t = (SingleSelect) e.getTarget(); + t.clearOptions(); + ApplicationCollection apps = Application .retrieveAllApplications(); - apps.addOrder(Application.PRIMARY_URL); - t.addOption(new Option(null, "--select one--")); - while (apps.next()) { - Application app = apps.getApplication(); - t.addOption(new Option(app.getOID().toString(), - app.getPath())); - } + apps.addOrder(Application.PRIMARY_URL); + t.addOption(new Option(null, "--select one--")); + while (apps.next()) { + Application app = apps.getApplication(); + t.addOption(new Option(app.getOID().toString(), + app.getPath())); } - }); + } + }); } catch (TooManyListenersException ex) { throw new UncheckedWrapperException("cannot happen", ex); } @@ -111,8 +110,9 @@ public class DomainContextForm extends Form { } private class DomainInitListener implements FormInitListener { - public void init(FormSectionEvent ev) - throws FormProcessException { + + public void init(FormSectionEvent ev) + throws FormProcessException { PageState state = ev.getPageState(); m_app.setValue(state, null); @@ -121,31 +121,32 @@ public class DomainContextForm extends Form { } private class DomainSubmissionListener implements FormSubmissionListener { - public void submitted(FormSectionEvent ev) - throws FormProcessException { + + public void submitted(FormSectionEvent ev) + throws FormProcessException { PageState state = ev.getPageState(); - + if (m_buttons.getCancelButton().isSelected(state)) { fireCompletionEvent(state); throw new FormProcessException("cancelled"); } } } - + private class DomainProcessListener implements FormProcessListener { - public void process(FormSectionEvent ev) - throws FormProcessException { + + public void process(FormSectionEvent ev) + throws FormProcessException { PageState state = ev.getPageState(); - Domain domain = (Domain)state.getValue(m_domain); - - Application app = (Application)m_app.getValue(state); - + Domain domain = (Domain) state.getValue(m_domain); + + Application app = (Application) m_app.getValue(state); + domain.setAsRootForObject(app, - (String)m_context.getValue(state)); - + (String) m_context.getValue(state)); + fireCompletionEvent(state); } } - } diff --git a/ccm-ldn-terms/src/com/arsdigita/london/terms/ui/admin/DomainMappingAddForm.java b/ccm-ldn-terms/src/com/arsdigita/london/terms/ui/admin/DomainMappingAddForm.java index 88546ba4a..c4e388c50 100644 --- a/ccm-ldn-terms/src/com/arsdigita/london/terms/ui/admin/DomainMappingAddForm.java +++ b/ccm-ldn-terms/src/com/arsdigita/london/terms/ui/admin/DomainMappingAddForm.java @@ -69,6 +69,7 @@ public class DomainMappingAddForm extends Form { @Override public void prepare(final PrintEvent event) { final SingleSelect target = (SingleSelect) event.getTarget(); + target.clearOptions(); if (event.getPageState().getValue(selected) == null) { target.setReadOnly(); diff --git a/ccm-navigation/src/com/arsdigita/navigation/ui/admin/CategoryForm.java b/ccm-navigation/src/com/arsdigita/navigation/ui/admin/CategoryForm.java index 36c690bd2..0ab281d87 100755 --- a/ccm-navigation/src/com/arsdigita/navigation/ui/admin/CategoryForm.java +++ b/ccm-navigation/src/com/arsdigita/navigation/ui/admin/CategoryForm.java @@ -98,6 +98,7 @@ public class CategoryForm extends Form { private static class TemplatePrintListener implements PrintListener { public void prepare(PrintEvent ev) { SingleSelect target = (SingleSelect)ev.getTarget(); + target.clearOptions(); target.addOption(new Option(null, "Inherit from parent")); TemplateCollection templates = Template.retrieveAll(); diff --git a/ccm-navigation/src/com/arsdigita/navigation/ui/admin/CategoryFormAddContext.java b/ccm-navigation/src/com/arsdigita/navigation/ui/admin/CategoryFormAddContext.java index fa4148904..4233448ba 100755 --- a/ccm-navigation/src/com/arsdigita/navigation/ui/admin/CategoryFormAddContext.java +++ b/ccm-navigation/src/com/arsdigita/navigation/ui/admin/CategoryFormAddContext.java @@ -124,6 +124,7 @@ public class CategoryFormAddContext extends Form { private class ContextPrintListener implements PrintListener { public void prepare(PrintEvent ev) { SingleSelect target = (SingleSelect)ev.getTarget(); + target.clearOptions(); TemplateContextCollection contexts = TemplateContext.retrieveAll(); while (contexts.next()) { TemplateContext context = contexts.getTemplateContext(); diff --git a/ccm-navigation/src/com/arsdigita/navigation/ui/admin/NavigationCreateForm.java b/ccm-navigation/src/com/arsdigita/navigation/ui/admin/NavigationCreateForm.java index 3144dcb0b..fd104fd53 100644 --- a/ccm-navigation/src/com/arsdigita/navigation/ui/admin/NavigationCreateForm.java +++ b/ccm-navigation/src/com/arsdigita/navigation/ui/admin/NavigationCreateForm.java @@ -76,6 +76,7 @@ public class NavigationCreateForm extends Form { termDomainSelect.addPrintListener(new PrintListener() { public void prepare(final PrintEvent event) { final SingleSelect target = (SingleSelect) event.getTarget(); + target.clearOptions(); final DataCollection termDomains = SessionManager.getSession(). retrieve(Domain.BASE_DATA_OBJECT_TYPE); diff --git a/ccm-navigation/src/com/arsdigita/navigation/ui/portlet/NavigationTreePortletEditor.java b/ccm-navigation/src/com/arsdigita/navigation/ui/portlet/NavigationTreePortletEditor.java index 120cad257..a80edb784 100644 --- a/ccm-navigation/src/com/arsdigita/navigation/ui/portlet/NavigationTreePortletEditor.java +++ b/ccm-navigation/src/com/arsdigita/navigation/ui/portlet/NavigationTreePortletEditor.java @@ -142,6 +142,7 @@ public class NavigationTreePortletEditor extends PortletConfigFormSection public void prepare(PrintEvent e) { SingleSelect target = (SingleSelect) e.getTarget(); + target.clearOptions(); DomainCollection navigations = new DomainCollection(SessionManager.getSession().retrieve( Navigation.BASE_DATA_OBJECT_TYPE)); diff --git a/ccm-navigation/src/com/arsdigita/navigation/ui/portlet/ObjectListPortletEditor.java b/ccm-navigation/src/com/arsdigita/navigation/ui/portlet/ObjectListPortletEditor.java index 950aa90d9..5c5e74e1f 100755 --- a/ccm-navigation/src/com/arsdigita/navigation/ui/portlet/ObjectListPortletEditor.java +++ b/ccm-navigation/src/com/arsdigita/navigation/ui/portlet/ObjectListPortletEditor.java @@ -189,6 +189,7 @@ public class ObjectListPortletEditor extends PortletConfigFormSection { public void prepare(PrintEvent ev) { OptionGroup target = (OptionGroup)ev.getTarget(); + target.clearOptions(); MetadataRoot root = MetadataRoot.getMetadataRoot(); Iterator types = root.getObjectTypes().iterator(); diff --git a/ccm-portalserver/src/com/arsdigita/portalserver/permissions/ObjectPermissionEdit.java b/ccm-portalserver/src/com/arsdigita/portalserver/permissions/ObjectPermissionEdit.java index aea45a849..549820bd6 100644 --- a/ccm-portalserver/src/com/arsdigita/portalserver/permissions/ObjectPermissionEdit.java +++ b/ccm-portalserver/src/com/arsdigita/portalserver/permissions/ObjectPermissionEdit.java @@ -18,9 +18,7 @@ */ package com.arsdigita.portalserver.permissions; - -import com.arsdigita.portalserver.permissions.util.GlobalizationUtil; - +import com.arsdigita.portalserver.permissions.util.GlobalizationUtil; import java.util.LinkedList; import java.util.Collection; @@ -54,45 +52,42 @@ import com.arsdigita.portalserver.*; import com.arsdigita.util.Assert; import org.apache.log4j.Category; - /** - * - * @version $Id: ObjectPermissionEdit.java#3 $ + * + * @version $Id: ObjectPermissionEdit.java#3 $ */ public class ObjectPermissionEdit extends CompoundComponent { - private static Category s_log = Category.getInstance - (ObjectPermissionEdit.class.getName()); + private static Category s_log = Category.getInstance(ObjectPermissionEdit.class.getName()); // Heavily-reused per-request label for renderer getComponent calls private final static RequestLocal s_dynamicLabel = new RequestLocal() { - @Override - public Object initialValue(PageState ps) { - return new Label(); - } - }; - + @Override + public Object initialValue(PageState ps) { + return new Label(); + } + }; private static class ObjectGrantsTable extends GrantsTable { + static void getGrantsHelper(ACSObject object, Collection types, LinkedList ordering) { HashMap canonicalMap = new HashMap(); - ObjectPermissionCollection opc = - PermissionService.getDirectGrantedPermissions(object.getOID()); + ObjectPermissionCollection opc + = PermissionService.getDirectGrantedPermissions(object. + getOID()); try { while (opc.next()) { - s_log.debug - ("Current grant in loop is " + opc.getPrivilege()); + s_log.debug("Current grant in loop is " + opc.getPrivilege()); if (opc.isInherited() - // Skip create privileges. They are created - // and destroyed implicitly when the other - // privileges are used. - || opc.getPrivilege().equals - (PrivilegeDescriptor.CREATE)) { + // Skip create privileges. They are created + // and destroyed implicitly when the other + // privileges are used. + || opc.getPrivilege().equals(PrivilegeDescriptor.CREATE)) { continue; } @@ -105,8 +100,8 @@ public class ObjectPermissionEdit extends CompoundComponent { } if (grant.objectType != null - && types != null - && !types.contains(grant.objectType)) { + && types != null + && !types.contains(grant.objectType)) { continue; } @@ -134,7 +129,6 @@ public class ObjectPermissionEdit extends CompoundComponent { } } - public ObjectGrantsTable(RequestLocal grantsRL, RequestLocal typesRL, boolean isEditable) { @@ -143,140 +137,140 @@ public class ObjectPermissionEdit extends CompoundComponent { // COLUMN 0: The party with the grant TableColumn partyColumn = new TableColumn(0, "User or Role"); partyColumn.setCellRenderer(new TableCellRenderer() { - final RequestLocal m_userNameDisplay = new RequestLocal() { - public Object initialValue(PageState ps) { - SimpleContainer result = new SimpleContainer(); - result.add(Icons.USER_16); - result.add((Component) s_dynamicLabel.get(ps)); - return result; - } - }; - final RequestLocal m_groupNameDisplay = new RequestLocal() { - public Object initialValue(PageState ps) { - SimpleContainer result = new SimpleContainer(); - result.add(Icons.GROUP_16); - result.add((Component)s_dynamicLabel.get(ps)); - return result; - } - }; - public Component getComponent(Table table, - PageState ps, - Object value, - boolean isSelected, - Object key, - int row, - int column) { - Grant grant = (Grant)value; - Label nameLabel = (Label)s_dynamicLabel.get(ps); - nameLabel.setLabel( (String) GlobalizationUtil.globalize("cw.cw.permissions.").localize() + grant.granteeName); - if (grant.granteeIsUser) { - return (Component) m_userNameDisplay.get(ps); - } else { - return (Component) m_groupNameDisplay.get(ps); - } + final RequestLocal m_userNameDisplay = new RequestLocal() { + public Object initialValue(PageState ps) { + SimpleContainer result = new SimpleContainer(); + result.add(Icons.USER_16); + result.add((Component) s_dynamicLabel.get(ps)); + return result; } - }); + }; + final RequestLocal m_groupNameDisplay = new RequestLocal() { + public Object initialValue(PageState ps) { + SimpleContainer result = new SimpleContainer(); + result.add(Icons.GROUP_16); + result.add((Component) s_dynamicLabel.get(ps)); + return result; + } + }; + + public Component getComponent(Table table, + PageState ps, + Object value, + boolean isSelected, + Object key, + int row, + int column) { + Grant grant = (Grant) value; + Label nameLabel = (Label) s_dynamicLabel.get(ps); + nameLabel.setLabel((String) GlobalizationUtil.globalize("cw.cw.permissions."). + localize() + grant.granteeName); + if (grant.granteeIsUser) { + return (Component) m_userNameDisplay.get(ps); + } else { + return (Component) m_groupNameDisplay.get(ps); + } + } + }); getColumnModel().add(0, partyColumn); } } - - private static class ObjectDirectGrantsTable extends ObjectGrantsTable { + public ObjectDirectGrantsTable(final RequestLocal objectRL, final RequestLocal typesRL) { super(new RequestLocal() { - public Object initialValue(PageState ps) { - LinkedList ordering = new LinkedList(); - getGrantsHelper((ACSObject) objectRL.get(ps), - (Collection) typesRL.get(ps), - ordering); - return ordering.iterator(); - } - }, typesRL, true); + public Object initialValue(PageState ps) { + LinkedList ordering = new LinkedList(); + getGrantsHelper((ACSObject) objectRL.get(ps), + (Collection) typesRL.get(ps), + ordering); + return ordering.iterator(); + } + }, typesRL, true); } } - - private static class ObjectIndirectGrantsTable extends ObjectGrantsTable { + public ObjectIndirectGrantsTable(final RequestLocal objectRL, final RequestLocal typesRL) { super(new RequestLocal() { - public Object initialValue(PageState ps) { - LinkedList ordering = new LinkedList(); + public Object initialValue(PageState ps) { + LinkedList ordering = new LinkedList(); - ACSObject object = (ACSObject) objectRL.get(ps); - Collection types = (Collection) typesRL.get(ps); + ACSObject object = (ACSObject) objectRL.get(ps); + Collection types = (Collection) typesRL.get(ps); // FIXME: May need to do this by getting the OID - // and doing a verifySubtype check - while (!(object instanceof PortalSite)) { - DataObject ctx = PermissionService.getContext(object); - if (ctx == null) { - break; - } - object = (ACSObject) DomainObjectFactory.newInstance - (ctx); - getGrantsHelper(object, types, ordering); + // and doing a verifySubtype check + while (!(object instanceof PortalSite)) { + DataObject ctx = PermissionService.getContext(object); + if (ctx == null) { + break; } - - return ordering.iterator(); + object = (ACSObject) DomainObjectFactory.newInstance(ctx); + getGrantsHelper(object, types, ordering); } - }, typesRL, false); + + return ordering.iterator(); + } + }, typesRL, false); // 'Target' column TableColumn targetColumn = new TableColumn(1, "On"); targetColumn.setCellRenderer(new TableCellRenderer() { - public Component getComponent(Table table, - PageState ps, - Object value, - boolean isSelected, - Object key, - int row, - int column) { - Grant grant = (Grant) value; - Label l = (Label) s_dynamicLabel.get(ps); - l.setLabel(grant.objectName); - return l; - } - }); + public Component getComponent(Table table, + PageState ps, + Object value, + boolean isSelected, + Object key, + int row, + int column) { + Grant grant = (Grant) value; + Label l = (Label) s_dynamicLabel.get(ps); + l.setLabel(grant.objectName); + return l; + } + }); getColumnModel().add(1, targetColumn); } } private class MainDisplay extends CompoundComponent { + MainDisplay(final RequestLocal objectRL, final RequestLocal directTypesRL, final RequestLocal indirectTypesRL, final ActionListener onAddClick) { super(new BoxPanel(BoxPanel.VERTICAL)); - // Header for direct permission list final GridPanel directHeader = new GridPanel(2); - Label directLabel = - new Label(GlobalizationUtil.globalize("cw.cw.permissions.view_and_manage_specific_permissions")); + Label directLabel + = new Label(GlobalizationUtil.globalize( + "cw.cw.permissions.view_and_manage_specific_permissions")); directLabel.setFontWeight(Label.BOLD); directHeader.add(directLabel, GridPanel.LEFT); - ActionLink newGrantLink = new ActionLink( (String) GlobalizationUtil.globalize("cw.cw.permissions.add_user_or_role").localize()); + ActionLink newGrantLink = new ActionLink((String) GlobalizationUtil.globalize( + "cw.cw.permissions.add_user_or_role").localize()); newGrantLink.setClassAttr("actionLink"); newGrantLink.addActionListener(onAddClick); directHeader.add(newGrantLink, GridPanel.RIGHT); add(directHeader); - add(new Label("The following users and roles have specific " + - "privileges on this knowledge item:")); + add(new Label("The following users and roles have specific " + + "privileges on this knowledge item:")); // Direct permission list - Table directTable = new ObjectDirectGrantsTable - (objectRL, directTypesRL); + Table directTable = new ObjectDirectGrantsTable(objectRL, directTypesRL); directTable.setCellPadding("5"); - Label directEmptyView = new Label("No specific privileges are " + - "defined on this item."); + Label directEmptyView = new Label("No specific privileges are " + + "defined on this item."); directEmptyView.setFontWeight(Label.ITALIC); directTable.setEmptyView(directEmptyView); add(directTable); @@ -284,24 +278,22 @@ public class ObjectPermissionEdit extends CompoundComponent { add(new Label(" ")); // Header for indirect permission list - Label indirectLabel = new Label(GlobalizationUtil.globalize("cw.cw.permissions.view_general_permissions")); + Label indirectLabel = new Label(GlobalizationUtil.globalize( + "cw.cw.permissions.view_general_permissions")); indirectLabel.setFontWeight(Label.BOLD); add(indirectLabel); - add(new Label("The following users and roles have broader " + - "privileges applying to this and other knowledge " + - "items. Note that these are inherited privileges " + - "and can only be changed from the location given " + - "in the \"On\" column.")); - + add(new Label("The following users and roles have broader " + + "privileges applying to this and other knowledge " + + "items. Note that these are inherited privileges " + + "and can only be changed from the location given " + + "in the \"On\" column.")); // Indirect permission list - Table indirectTable = new ObjectIndirectGrantsTable - (objectRL, indirectTypesRL); + Table indirectTable = new ObjectIndirectGrantsTable(objectRL, indirectTypesRL); indirectTable.setCellPadding("5"); - Label indirectEmpty = new Label("No general permissions apply " + - "to this item."); + Label indirectEmpty = new Label("No general permissions apply " + "to this item."); indirectEmpty.setFontWeight(Label.ITALIC); indirectTable.setEmptyView(indirectEmpty); add(indirectTable); @@ -314,43 +306,44 @@ public class ObjectPermissionEdit extends CompoundComponent { private static final long MAX_RESULTS = 20; private class NewGrantDisplay extends CompoundComponent { + // RequestLocal storing the object + private final RequestLocal m_objectRL; // Collection of 'relevant types' private final RequestLocal m_typesRL; // Parameter containing user's search string - private final StringParameter m_queryParam = - new StringParameter("queryParam"); + private final StringParameter m_queryParam + = new StringParameter("queryParam"); // Flag indicating whether or not to limit search to current // workspace's participants - private final BooleanParameter m_limitParam = - new BooleanParameter("limitParam"); + private final BooleanParameter m_limitParam + = new BooleanParameter("limitParam"); private final RequestLocal m_partiesRL = new RequestLocal() { - public Object initialValue(PageState ps) { - PortalSite psite = - PortalSite.getCurrentPortalSite(ps.getRequest()); + public Object initialValue(PageState ps) { + PortalSite psite + = PortalSite.getCurrentPortalSite(ps.getRequest()); - String queryString = (String) ps.getValue(m_queryParam); + String queryString = (String) ps.getValue(m_queryParam); - PartyCollection parties; - Boolean limit = (Boolean) ps.getValue(m_limitParam); + PartyCollection parties; + Boolean limit = (Boolean) ps.getValue(m_limitParam); - if (limit != null && limit.booleanValue()) { - parties = psite.getParticipants(); - } else { - parties = Party.retrieveAllParties(); - } - - parties.filter(queryString); - - return parties; + if (limit != null && limit.booleanValue()) { + parties = psite.getParticipants(); + } else { + parties = Party.retrieveAllParties(); } - }; + parties.filter(queryString); + + return parties; + } + }; private void clearQuery(PageState ps) { ps.setValue(m_queryParam, null); @@ -374,6 +367,7 @@ public class ObjectPermissionEdit extends CompoundComponent { } private class BoldLabel extends Label { + public BoldLabel(String text) { super(text); setFontWeight(Label.BOLD); @@ -381,6 +375,7 @@ public class ObjectPermissionEdit extends CompoundComponent { } private class MyAddGrantForm extends AddGrantForm { + public MyAddGrantForm(String name, Widget partyWidget, final RequestLocal errorMessageRL) { @@ -391,24 +386,23 @@ public class ObjectPermissionEdit extends CompoundComponent { add(new BoldLabel("Select Grantee:")); add(new BoldLabel("On:") { - public void generateXML(PageState ps, Element parent) { - Collection types = (Collection)m_typesRL.get(ps); + public void generateXML(PageState ps, Element parent) { + Collection types = (Collection) m_typesRL.get(ps); - if ((types == null) || (types.size() <= 1)) { - parent.newChildElement("bebop:label", BEBOP_XML_NS); - return; - } else { - super.generateXML(ps, parent); - } + if ((types == null) || (types.size() <= 1)) { + parent.newChildElement("bebop:label", BEBOP_XML_NS); + return; + } else { + super.generateXML(ps, parent); } - }); + } + }); add(new BoldLabel("Privilege:")); add(new Label("")); // Row 2: Widgets - // Create a hidden widget for the objectID add(new Hidden(getObjectParameter())); @@ -427,20 +421,20 @@ public class ObjectPermissionEdit extends CompoundComponent { // Init listener to initialize the objectID parameter addInitListener(new FormInitListener() { - public void init(FormSectionEvent ev) { - PageState ps = ev.getPageState(); - FormData fd = ev.getFormData(); - fd.put(getObjectParameter().getName(), - ((ACSObject)m_objectRL.get(ps)).getID()); - } - }); + public void init(FormSectionEvent ev) { + PageState ps = ev.getPageState(); + FormData fd = ev.getFormData(); + fd.put(getObjectParameter().getName(), + ((ACSObject) m_objectRL.get(ps)).getID()); + } + }); addProcessListener(new FormProcessListener() { - public void process(FormSectionEvent ev) { - PageState ps = ev.getPageState(); - NewGrantDisplay.this.fireCompletionEvent(ps); - } - }); + public void process(FormSectionEvent ev) { + PageState ps = ev.getPageState(); + NewGrantDisplay.this.fireCompletionEvent(ps); + } + }); } } @@ -451,32 +445,30 @@ public class ObjectPermissionEdit extends CompoundComponent { // This RL makes available a PartyCollection containing // the result of the specified query - final BoxPanel screen1 = new BoxPanel(BoxPanel.VERTICAL) { - public boolean isVisible(PageState ps) { - if (!haveQuery(ps)) { - return true; - } - PartyCollection pc = - NewGrantDisplay.this.getQueryResults(ps); - long n = pc.size(); - return (n == 0 || n > MAX_RESULTS); + public boolean isVisible(PageState ps) { + if (!haveQuery(ps)) { + return true; } - }; + PartyCollection pc + = NewGrantDisplay.this.getQueryResults(ps); + long n = pc.size(); + return (n == 0 || n > MAX_RESULTS); + } + }; add(screen1); - Label roleFormTitle = new BoldLabel(""); roleFormTitle.addPrintListener(new PrintListener() { - public void prepare(PrintEvent ev) { - PageState ps = ev.getPageState(); - Label tgt = (Label)ev.getTarget(); - PortalSite psite = - PortalSite.getCurrentPortalSite(ps.getRequest()); - tgt.setLabel("Grant privilege to a role from the \"" + - psite.getTitle() + "\" portal:"); - } - }); + public void prepare(PrintEvent ev) { + PageState ps = ev.getPageState(); + Label tgt = (Label) ev.getTarget(); + PortalSite psite + = PortalSite.getCurrentPortalSite(ps.getRequest()); + tgt.setLabel("Grant privilege to a role from the \"" + psite.getTitle() + + "\" portal:"); + } + }); screen1.add(roleFormTitle); // Form for granting to a portal role @@ -484,19 +476,19 @@ public class ObjectPermissionEdit extends CompoundComponent { SingleSelect roleField = new SingleSelect("roleField"); roleField.setPrintListener(new PrintListener() { - public void prepare(PrintEvent ev) { - SingleSelect tgt = (SingleSelect)ev.getTarget(); - PageState ps = ev.getPageState(); - PortalSite psite = - PortalSite.getCurrentPortalSite(ps.getRequest()); - RoleCollection rc = psite.getRoles(); - while (rc.next()) { - Option o = new Option - (rc.getID().toString(), rc.getRoleName()); - tgt.addOption(o); - } + public void prepare(PrintEvent ev) { + SingleSelect tgt = (SingleSelect) ev.getTarget(); + tgt.clearOptions(); + PageState ps = ev.getPageState(); + PortalSite psite + = PortalSite.getCurrentPortalSite(ps.getRequest()); + RoleCollection rc = psite.getRoles(); + while (rc.next()) { + Option o = new Option(rc.getID().toString(), rc.getRoleName()); + tgt.addOption(o); } - }); + } + }); Form roleForm = new MyAddGrantForm("roleGrant", roleField, rfErrorMessageRL); @@ -505,11 +497,8 @@ public class ObjectPermissionEdit extends CompoundComponent { // Error message display screen1.add(new ErrorMessageDisplay(rfErrorMessageRL)); - - // Toplevel search label - screen1.add(new BoldLabel("Search for a user or role to recieve " + - "a privilege:")); + screen1.add(new BoldLabel("Search for a user or role to recieve " + "a privilege:")); Form otherSearch = new Form("otherSearch", new GridPanel(2)); otherSearch.setRedirecting(true); @@ -521,19 +510,18 @@ public class ObjectPermissionEdit extends CompoundComponent { Label limitLabel = new Label(""); limitLabel.addPrintListener(new PrintListener() { - public void prepare(PrintEvent ev) { - Label tgt = (Label)ev.getTarget(); - PageState ps = ev.getPageState(); - PortalSite psite = - PortalSite.getCurrentPortalSite(ps.getRequest()); - tgt.setLabel("Limit search to \"" + psite.getTitle() + - "\" participants"); - } - }); + public void prepare(PrintEvent ev) { + Label tgt = (Label) ev.getTarget(); + PageState ps = ev.getPageState(); + PortalSite psite + = PortalSite.getCurrentPortalSite(ps.getRequest()); + tgt.setLabel("Limit search to \"" + psite.getTitle() + "\" participants"); + } + }); - final CheckboxGroup limitToParticipants = - new CheckboxGroup("limitToParticipants"); - String[] limitDefault = { "yes" }; + final CheckboxGroup limitToParticipants + = new CheckboxGroup("limitToParticipants"); + String[] limitDefault = {"yes"}; limitToParticipants.setDefaultValue(limitDefault); limitToParticipants.addOption(new Option("yes", limitLabel)); otherSearch.add(limitToParticipants); @@ -541,21 +529,22 @@ public class ObjectPermissionEdit extends CompoundComponent { otherSearch.add(new Label("")); // Label to display when no matches are found - Label noMatchLabel = new Label(GlobalizationUtil.globalize("cw.cw.permissions.no_matches_found")) { - public boolean isVisible(PageState ps) { - if (!haveQuery(ps)) { - return false; - } + Label noMatchLabel = new Label(GlobalizationUtil.globalize( + "cw.cw.permissions.no_matches_found")) { + public boolean isVisible(PageState ps) { + if (!haveQuery(ps)) { + return false; + } - PartyCollection pc = getQueryResults(ps); + PartyCollection pc = getQueryResults(ps); - if (pc == null || pc.size() > 0) { - return false; - } else { - return true; + if (pc == null || pc.size() > 0) { + return false; + } else { + return true; + } } - } - }; + }; // @deprecated bebop must not specify design properties, just // logical properties. // TODO: add as error condition to the widget. @@ -563,120 +552,120 @@ public class ObjectPermissionEdit extends CompoundComponent { otherSearch.add(noMatchLabel); // Label to display when too many matches are found. - Label tooManyLabel = - new Label(GlobalizationUtil.globalize("cw.cw.permissions.too_many_matches_refine_your_search")) { - public boolean isVisible(PageState ps) { - if (!haveQuery(ps)) { - return false; - } + Label tooManyLabel + = new Label(GlobalizationUtil.globalize( + "cw.cw.permissions.too_many_matches_refine_your_search")) { + public boolean isVisible(PageState ps) { + if (!haveQuery(ps)) { + return false; + } - PartyCollection pc = getQueryResults(ps); + PartyCollection pc = getQueryResults(ps); - if (pc == null || pc.size() <= MAX_RESULTS) { - return false; - } else { - return true; - } - } - }; + if (pc == null || pc.size() <= MAX_RESULTS) { + return false; + } else { + return true; + } + } + }; // @deprecated bebop must not specify design properties, just - // logical properties. - // TODO: add as error condition to the widget. - // noMatchLabel.setColor(Color.red); - // tooManyLabel.setColor(Color.red); - otherSearch.add(tooManyLabel); + // logical properties. + // TODO: add as error condition to the widget. + // noMatchLabel.setColor(Color.red); + // tooManyLabel.setColor(Color.red); + otherSearch.add(tooManyLabel); + // SECOND Add screen: Search results + final BoxPanel screen2 = new BoxPanel(BoxPanel.VERTICAL) { + public boolean isVisible(PageState ps) { + if (!haveQuery(ps)) { + return false; + } + PartyCollection pc = getQueryResults(ps); + long n = pc.size(); + return (n > 0 && n <= MAX_RESULTS); + } + }; + add(screen2); + otherSearch.addProcessListener(new FormProcessListener() { + public void process(FormSectionEvent ev) { + PageState ps = ev.getPageState(); + String queryString = (String) queryField.getValue(ps); + String[] limit = (String[]) limitToParticipants.getValue(ps); + if (limit != null && limit.length > 0) { + setQuery(ps, queryString, Boolean.TRUE); + } else { + setQuery(ps, queryString, Boolean.FALSE); + } + } + }); - // SECOND Add screen: Search results - final BoxPanel screen2 = new BoxPanel(BoxPanel.VERTICAL) { - public boolean isVisible(PageState ps) { - if (!haveQuery(ps)) { - return false; - } - PartyCollection pc = getQueryResults(ps); - long n = pc.size(); - return (n > 0 && n <= MAX_RESULTS); - } - }; - add(screen2); + screen1.add(otherSearch); - otherSearch.addProcessListener(new FormProcessListener() { - public void process(FormSectionEvent ev) { - PageState ps = ev.getPageState(); - String queryString = (String)queryField.getValue(ps); - String[] limit = (String[])limitToParticipants.getValue(ps); - if (limit != null && limit.length > 0) { - setQuery(ps, queryString, Boolean.TRUE); - } else { - setQuery(ps, queryString, Boolean.FALSE); - } - } - }); - - screen1.add(otherSearch); - - screen1.add(new Label("")); - - ActionLink returnLink = - new ActionLink( (String) GlobalizationUtil.globalize("cw.cw.permissions.return_to_current_permissions_view").localize()); - returnLink.setClassAttr("actionLink"); - returnLink.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent ev) { - fireCompletionEvent(ev.getPageState()); - } - }); - screen1.add(returnLink); + screen1.add(new Label("")); + ActionLink returnLink + = new ActionLink((String) GlobalizationUtil.globalize( + "cw.cw.permissions.return_to_current_permissions_view"). + localize()); + returnLink.setClassAttr("actionLink"); + returnLink.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ev) { + fireCompletionEvent(ev.getPageState()); + } + }); + screen1.add(returnLink); // Build Search results form + RequestLocal pfErrorMessageRL = new RequestLocal(); - RequestLocal pfErrorMessageRL = new RequestLocal(); + RadioGroup partyField = new RadioGroup("partyField"); + partyField.setLayout(RadioGroup.VERTICAL); + partyField.setPrintListener(new PrintListener() { + public void prepare(PrintEvent ev) { + PageState ps = ev.getPageState(); + RadioGroup target = (RadioGroup) ev.getTarget(); + PartyCollection parties = getQueryResults(ps); + while (parties.next()) { + target.addOption(new Option(parties.getID().toString(), + parties.getDisplayName())); + } + } + }); - RadioGroup partyField = new RadioGroup("partyField"); - partyField.setLayout(RadioGroup.VERTICAL); - partyField.setPrintListener(new PrintListener() { - public void prepare(PrintEvent ev) { - PageState ps = ev.getPageState(); - RadioGroup target = (RadioGroup)ev.getTarget(); - PartyCollection parties = getQueryResults(ps); - while (parties.next()) { - target.addOption(new Option(parties.getID().toString(), - parties.getDisplayName())); - } - } - }); + Form partyForm = new MyAddGrantForm("partyGrant", + partyField, + pfErrorMessageRL); + screen2.add(partyForm); - Form partyForm = new MyAddGrantForm("partyGrant", - partyField, - pfErrorMessageRL); + screen2.add(new ErrorMessageDisplay(pfErrorMessageRL)); - screen2.add(partyForm); + ActionLink newSearchLink = new ActionLink((String) GlobalizationUtil. + globalize("cw.cw.permissions.try_a_new_search").localize()); + newSearchLink.setClassAttr("actionLink"); + newSearchLink.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ev) { + clearQuery(ev.getPageState()); + } + }); + screen2.add(newSearchLink); - screen2.add(new ErrorMessageDisplay(pfErrorMessageRL)); - - ActionLink newSearchLink = new ActionLink( (String) GlobalizationUtil.globalize("cw.cw.permissions.try_a_new_search").localize()); - newSearchLink.setClassAttr("actionLink"); - newSearchLink.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent ev) { - clearQuery(ev.getPageState()); - } - }); - screen2.add(newSearchLink); - - ActionLink returnToMainLink = - new ActionLink( (String) GlobalizationUtil.globalize("cw.cw.permissions.return_to_current_permissions_view").localize()); - returnToMainLink.setClassAttr("actionLink"); - returnToMainLink.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent ev) { - NewGrantDisplay.this.fireCompletionEvent(ev.getPageState()); - } - }); - screen2.add(returnToMainLink); + ActionLink returnToMainLink + = new ActionLink((String) GlobalizationUtil.globalize( + "cw.cw.permissions.return_to_current_permissions_view"). + localize()); + returnToMainLink.setClassAttr("actionLink"); + returnToMainLink.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ev) { + NewGrantDisplay.this.fireCompletionEvent(ev.getPageState()); + } + }); + screen2.add(returnToMainLink); } - public void fireCompletionEvent(PageState ps) { clearQuery(ps); super.fireCompletionEvent(ps); @@ -690,71 +679,66 @@ public class ObjectPermissionEdit extends CompoundComponent { } - public void register(Page p) { - // Assert.assertTrue((p instanceof CWPage), + // Assert.assertTrue((p instanceof CWPage), Assert.isTrue((p instanceof CWPage), - "ObjectPermissionEdit may only be used on " + - "instances of CWPage."); + "ObjectPermissionEdit may only be used on " + "instances of CWPage."); super.register(p); } - private void initialize(RequestLocal objectRL, RequestLocal directTypesRL, RequestLocal indirectTypesRL) { - final SimpleContainer c = (SimpleContainer)getContainer(); + final SimpleContainer c = (SimpleContainer) getContainer(); - final Completable newGrantDisplay = - new NewGrantDisplay(objectRL, directTypesRL) { - public void register(Page p) { - super.register(p); - p.setVisibleDefault(this, false); - } - }; + final Completable newGrantDisplay + = new NewGrantDisplay(objectRL, directTypesRL) { + public void register(Page p) { + super.register(p); + p.setVisibleDefault(this, false); + } + }; ActionListener onAddClick = new ActionListener() { - public void actionPerformed(ActionEvent ev) { - PageState ps = ev.getPageState(); - CWPage page = (CWPage)ps.getPage(); - page.goModal(ps, newGrantDisplay); - } - }; + public void actionPerformed(ActionEvent ev) { + PageState ps = ev.getPageState(); + CWPage page = (CWPage) ps.getPage(); + page.goModal(ps, newGrantDisplay); + } + }; - final Component mainDisplay = - new MainDisplay(objectRL, - directTypesRL, - indirectTypesRL, - onAddClick); + final Component mainDisplay + = new MainDisplay(objectRL, + directTypesRL, + indirectTypesRL, + onAddClick); newGrantDisplay.addCompletionListener(new ActionListener() { - public void actionPerformed(ActionEvent ev) { - PageState ps = ev.getPageState(); - CWPage page = (CWPage)ps.getPage(); - page.goUnmodal(ps); - } - }); + public void actionPerformed(ActionEvent ev) { + PageState ps = ev.getPageState(); + CWPage page = (CWPage) ps.getPage(); + page.goUnmodal(ps); + } + }); add(mainDisplay); add(newGrantDisplay); } - - public ObjectPermissionEdit(final RequestLocal objectRL) { super(new SimpleContainer()); initialize(objectRL, new RequestLocal(), new RequestLocal()); /* - { - public Object initialValue(PageState ps) { - ACSObject object = (ACSObject)objectRL.get(ps); - HashSet result = new HashSet(1); - result.add(object.getObjectType()); - return result; - } - }); - */ + { + public Object initialValue(PageState ps) { + ACSObject object = (ACSObject)objectRL.get(ps); + HashSet result = new HashSet(1); + result.add(object.getObjectType()); + return result; + } + }); + */ } diff --git a/ccm-portalserver/src/com/arsdigita/portalserver/permissions/PartyPermissionEdit.java b/ccm-portalserver/src/com/arsdigita/portalserver/permissions/PartyPermissionEdit.java index 3dae878e2..52af29902 100644 --- a/ccm-portalserver/src/com/arsdigita/portalserver/permissions/PartyPermissionEdit.java +++ b/ccm-portalserver/src/com/arsdigita/portalserver/permissions/PartyPermissionEdit.java @@ -251,6 +251,7 @@ public class PartyPermissionEdit extends CompoundComponent { objectSelect.setPrintListener(new PrintListener() { public void prepare(PrintEvent ev) { SingleSelect target = (SingleSelect)ev.getTarget(); + target.clearOptions(); PageState ps = ev.getPageState(); List options = (List) m_targetsRL.get(ps); for (Iterator it = options.iterator(); it.hasNext(); ) { diff --git a/ccm-portalserver/src/com/arsdigita/portalserver/permissions/TypeSingleSelect.java b/ccm-portalserver/src/com/arsdigita/portalserver/permissions/TypeSingleSelect.java index 53cc0b0e3..aea1a54d6 100644 --- a/ccm-portalserver/src/com/arsdigita/portalserver/permissions/TypeSingleSelect.java +++ b/ccm-portalserver/src/com/arsdigita/portalserver/permissions/TypeSingleSelect.java @@ -26,8 +26,8 @@ import com.arsdigita.bebop.event.*; import com.arsdigita.xml.Element; import com.arsdigita.persistence.metadata.ObjectType; - class TypeSingleSelect extends SingleSelect { + private RequestLocal m_typesRL; public TypeSingleSelect(ParameterModel param, @@ -39,22 +39,23 @@ class TypeSingleSelect extends SingleSelect { addOption(new Option(AddGrantForm.ALL_TYPES, "All Contained Items")); setPrintListener(new PrintListener() { - public void prepare(PrintEvent ev) { - SingleSelect tgt = (SingleSelect)ev.getTarget(); - PageState ps = ev.getPageState(); - Iterator types = - ((Collection)m_typesRL.get(ps)).iterator(); - while (types.hasNext()) { - ObjectType type = (ObjectType)types.next(); - tgt.addOption(new Option(type.getQualifiedName(), - type.getName())); - } + public void prepare(PrintEvent ev) { + SingleSelect tgt = (SingleSelect) ev.getTarget(); + tgt.clearOptions(); + PageState ps = ev.getPageState(); + Iterator types + = ((Collection) m_typesRL.get(ps)).iterator(); + while (types.hasNext()) { + ObjectType type = (ObjectType) types.next(); + tgt.addOption(new Option(type.getQualifiedName(), + type.getName())); } - }); + } + }); } public void generateXML(PageState ps, Element parent) { - Collection types = (Collection)m_typesRL.get(ps); + Collection types = (Collection) m_typesRL.get(ps); if (types == null) { parent.newChildElement("bebop:label", BEBOP_XML_NS); return; diff --git a/ccm-portalserver/src/com/arsdigita/portalserver/ui/admin/DisplayPane.java b/ccm-portalserver/src/com/arsdigita/portalserver/ui/admin/DisplayPane.java index eb40aa36e..3ecea975f 100644 --- a/ccm-portalserver/src/com/arsdigita/portalserver/ui/admin/DisplayPane.java +++ b/ccm-portalserver/src/com/arsdigita/portalserver/ui/admin/DisplayPane.java @@ -18,8 +18,7 @@ */ package com.arsdigita.portalserver.ui.admin; - -import com.arsdigita.portalserver.util.GlobalizationUtil; +import com.arsdigita.portalserver.util.GlobalizationUtil; import com.arsdigita.web.ApplicationType; import com.arsdigita.portalserver.PortalSite; @@ -77,10 +76,11 @@ import java.math.BigDecimal; * @version $Id: //portalserver/dev/src/com/arsdigita/portalserver/ui/admin/DisplayPane.java#9 $ */ public class DisplayPane extends DynamicListWizard { + public static final String versionId = "$Id: //portalserver/dev/src/com/arsdigita/portalserver/ui/admin/DisplayPane.java#9 $ by $Author: dennis $, $DateTime: 2004/08/17 23:19:25 $"; - private static final Logger s_cat = - Logger.getLogger(ApplicationsPane.class.getName()); + private static final Logger s_cat + = Logger.getLogger(ApplicationsPane.class.getName()); final ModalContainer m_editContainer = new ModalContainer(); @@ -91,18 +91,21 @@ public class DisplayPane extends DynamicListWizard { DeleteTabForm m_deleteTabForm; List m_layouts; RequestLocal selectedTabIDRL; - static final String m_layoutNames[] = {"W","NW","WN","NWN","NNN"}; + static final String m_layoutNames[] = {"W", "NW", "WN", "NWN", "NNN"}; BigDecimalParameter m_selectedPortletParam; static final String FOUR_SPACE_INDENT_STRING = "    "; static class TabListModel implements ListModel { + PortalTabCollection m_tabs; PortalTab m_currTab; + public TabListModel(PortalSite psite) { m_tabs = psite.getTabsForPortalSite(); } + public boolean next() { if (!m_tabs.next()) { return false; @@ -110,138 +113,142 @@ public class DisplayPane extends DynamicListWizard { m_currTab = m_tabs.getPortalTab(); return true; } + public Object getElement() { return m_currTab.getTitle(); } + public String getKey() { return m_currTab.getID().toString(); } } - - - public DisplayPane(final RequestLocal portalsiteRL) - { + public DisplayPane(final RequestLocal portalsiteRL) { super("Current Tabs. Use the arrows to shift tab position.", new ListModelBuilder() { public ListModel makeModel(List l, PageState ps) { - PortalSite psite = (PortalSite)portalsiteRL.get(ps); + PortalSite psite = (PortalSite) portalsiteRL.get(ps); return new TabListModel(psite); } - public void lock() {} - public boolean isLocked() { return true; } + + public void lock() { + } + + public boolean isLocked() { + return true; + } }, "Add a tab", - new Label(GlobalizationUtil.globalize("cw.workspace.ui.admin.there_currently_is_no_tab_selected_please_select_a_tab"))); + new Label(GlobalizationUtil.globalize( + "cw.workspace.ui.admin.there_currently_is_no_tab_selected_please_select_a_tab"))); final DynamicListWizard dlw = this; - // FORM FOR ADDING NEW TABS Form addForm = new Form("addTab"); addForm.add(new Label(GlobalizationUtil.globalize("cw.workspace.ui.admin.new_tab_name"))); final TextField newTabName = new TextField("name"); - newTabName.getParameterModel().addParameterListener - (new NotEmptyValidationListener()); + newTabName.getParameterModel().addParameterListener(new NotEmptyValidationListener()); newTabName.setSize(40); addForm.add(newTabName); addForm.add(new Label()); addForm.add(new Submit("Add tab")); - addForm.addProcessListener(new FormProcessListener() { public void process(FormSectionEvent ev) { PageState ps = ev.getPageState(); - PortalSite psite = (PortalSite)portalsiteRL.get(ps); - PortalTab newTab = - PortalTab.createTab((String)newTabName.getValue(ps),psite); - psite.addPortalTab(newTab); - newTab.save(); - psite.save(); + PortalSite psite = (PortalSite) portalsiteRL.get(ps); + PortalTab newTab + = PortalTab.createTab((String) newTabName.getValue(ps), psite); + psite.addPortalTab(newTab); + newTab.save(); + psite.save(); - List list = (List) dlw.getListingComponent(); + List list = (List) dlw.getListingComponent(); - list.getSelectionModel() + list.getSelectionModel() .setSelectedKey(ps, newTab.getID().toString()); - } - }); + } + }); setAddPane(addForm); // CONSTRUCT EDIT COMPONENT selectedTabIDRL = new RequestLocal() { - protected Object initialValue(PageState ps) { - String tabIDstr = (String)dlw.getSelectionModel() + protected Object initialValue(PageState ps) { + String tabIDstr = (String) dlw.getSelectionModel() .getSelectedKey(ps); - return new BigDecimal(tabIDstr); - } - }; + return new BigDecimal(tabIDstr); + } + }; m_selectedPortletParam = new BigDecimalParameter("selectedPortlet"); m_mainDisplay = new BoxPanel(BoxPanel.VERTICAL); - PortletLayoutComponent plc = - new PortletLayoutComponent(portalsiteRL, selectedTabIDRL) { - protected void handleConfigure(PageState ps, BigDecimal id) { - ps.setValue(m_selectedPortletParam, id); - m_editContainer.setVisibleComponent(ps, m_portletModify); - } - }; - LockableLinks locklinks = - new LockableLinks(portalsiteRL, selectedTabIDRL); + PortletLayoutComponent plc + = new PortletLayoutComponent(portalsiteRL, selectedTabIDRL) { + protected void handleConfigure(PageState ps, BigDecimal id) { + ps.setValue(m_selectedPortletParam, id); + m_editContainer.setVisibleComponent(ps, m_portletModify); + } + }; + LockableLinks locklinks + = new LockableLinks(portalsiteRL, selectedTabIDRL); m_mainDisplay.add(locklinks); m_mainDisplay.add(plc); BoxPanel links = new BoxPanel(BoxPanel.HORIZONTAL, true); - ActionLink renameLink = new ActionLink( (String) GlobalizationUtil.globalize("cw.workspace.ui.admin.rename_tab").localize()); + ActionLink renameLink = new ActionLink((String) GlobalizationUtil.globalize( + "cw.workspace.ui.admin.rename_tab").localize()); renameLink.setClassAttr("actionLink"); renameLink.addActionListener(new RenameLinkListener()); links.add(renameLink); - ActionLink deleteLink = new ActionLink( (String) GlobalizationUtil.globalize("cw.workspace.ui.admin.delete_tab").localize()) { - public boolean isVisible(PageState ps) { - PortalSite psite = (PortalSite)portalsiteRL.get(ps); - PortalTabCollection pstc = psite.getTabsForPortalSite(); - return (pstc.size() > 1); - } - }; + ActionLink deleteLink = new ActionLink((String) GlobalizationUtil.globalize( + "cw.workspace.ui.admin.delete_tab").localize()) { + public boolean isVisible(PageState ps) { + PortalSite psite = (PortalSite) portalsiteRL.get(ps); + PortalTabCollection pstc = psite.getTabsForPortalSite(); + return (pstc.size() > 1); + } + }; deleteLink.setClassAttr("actionLink"); deleteLink.addActionListener(new DeleteLinkListener()); links.add(deleteLink); m_mainDisplay.add(links); - final BigDecimalParameter portletTypeParam = - new BigDecimalParameter("typeID"); + final BigDecimalParameter portletTypeParam + = new BigDecimalParameter("typeID"); Form addPortlet = new Form("ap1", new GridPanel(1)) { - public void register(Page p) { - super.register(p); - p.addComponentStateParam(this, portletTypeParam); - } - }; + public void register(Page p) { + super.register(p); + p.addComponentStateParam(this, portletTypeParam); + } + }; Image image = new Image("/assets/cw/general/add.gif"); image.setBorder("0"); SimpleContainer imageLabelSC = new SimpleContainer(); imageLabelSC.add(image); - imageLabelSC.add(new Label - ("To add a portlet to this page, first choose a type: ")); + imageLabelSC.add(new Label("To add a portlet to this page, first choose a type: ")); addPortlet.add(imageLabelSC); final SingleSelect portletTypeSelect = new SingleSelect("ptype"); portletTypeSelect.addValidationListener( - new NotNullValidationListener()); + new NotNullValidationListener()); PortletTypeCollection ptc = PortletType.retrieveAllPortletTypes(); //Alphabetize by title ptc.addOrder("title"); while (ptc.next()) { ApplicationType providerAppType = ptc.getPortletType().getProviderApplicationType(); - if ( providerAppType != null ) { - portletTypeSelect.addOption(new Option(ptc.getID().toString(), ptc.getTitle() + - " (" + providerAppType.getTitle() + ") ")); + if (providerAppType != null) { + portletTypeSelect.addOption(new Option(ptc.getID().toString(), ptc.getTitle() + " (" + + providerAppType. + getTitle() + ") ")); } else { portletTypeSelect.addOption(new Option(ptc.getID().toString(), ptc.getTitle())); } @@ -253,37 +260,33 @@ public class DisplayPane extends DynamicListWizard { addPortlet.add(selectorSC); addPortlet.addProcessListener(new FormProcessListener() { - public void process(FormSectionEvent ev) { - PageState ps = ev.getPageState(); - m_editContainer.setVisibleComponent(ps, m_portletAddForm); - ps.setValue(portletTypeParam, new BigDecimal( - (String) portletTypeSelect.getValue(ps))); - m_portletAddForm.activate(ps); - } - }); + public void process(FormSectionEvent ev) { + PageState ps = ev.getPageState(); + m_editContainer.setVisibleComponent(ps, m_portletAddForm); + ps.setValue(portletTypeParam, new BigDecimal( + (String) portletTypeSelect.getValue(ps))); + m_portletAddForm.activate(ps); + } + }); m_mainDisplay.add(addPortlet); BoxPanel tabLayouts = new BoxPanel(BoxPanel.HORIZONTAL, true); - ListModelBuilder lmb = new ListModelBuilder() - { - boolean m_isLocked; + ListModelBuilder lmb = new ListModelBuilder() { + boolean m_isLocked; - public ListModel makeModel(List l, PageState pageState) - { - return new LayoutListModel (pageState); - } + public ListModel makeModel(List l, PageState pageState) { + return new LayoutListModel(pageState); + } - public void lock() - { - m_isLocked = true; - } + public void lock() { + m_isLocked = true; + } - public boolean isLocked() - { - return m_isLocked; - } - }; + public boolean isLocked() { + return m_isLocked; + } + }; m_layouts = new List(lmb); @@ -291,62 +294,59 @@ public class DisplayPane extends DynamicListWizard { m_layouts.setCellRenderer(new LayoutListCellRenderer()); - m_layouts.addChangeListener(new ChangeListener () { - public void stateChanged(ChangeEvent e) - { - PageState ps = e.getPageState(); - String key = (String) ((List) dlw.getListingComponent()) + m_layouts.addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + PageState ps = e.getPageState(); + String key = (String) ((List) dlw.getListingComponent()) .getSelectedKey(ps); - BigDecimal bd = new BigDecimal(key); - PortalTab ptab = PortalTab.retrieveTab(bd); - String laykey = (String)m_layouts.getSelectedKey(ps); - Integer lk = new Integer(laykey); - ptab.setLayout(m_layoutNames[lk.intValue()]); - ptab.save(); - } - }); + BigDecimal bd = new BigDecimal(key); + PortalTab ptab = PortalTab.retrieveTab(bd); + String laykey = (String) m_layouts.getSelectedKey(ps); + Integer lk = new Integer(laykey); + ptab.setLayout(m_layoutNames[lk.intValue()]); + ptab.save(); + } + }); tabLayouts.add(m_layouts); m_mainDisplay.add(tabLayouts); - - m_portletAddForm = - new PortletAddForm(portalsiteRL, selectedTabIDRL, new RequestLocal() { - protected Object initialValue(PageState ps) { - BigDecimal id = (BigDecimal) ps.getValue(portletTypeParam); - if (id == null) { - return null; + m_portletAddForm + = new PortletAddForm(portalsiteRL, selectedTabIDRL, new RequestLocal() { + protected Object initialValue(PageState ps) { + BigDecimal id = (BigDecimal) ps.getValue(portletTypeParam); + if (id == null) { + return null; + } + return PortletType.retrievePortletType(id); } - return PortletType.retrievePortletType(id); - } - }); + }); m_portletAddForm.addCompletionListener(new ActionListener() { - public void actionPerformed(ActionEvent ev) { - PageState ps = ev.getPageState(); - ps.reset(m_editContainer); - } - }); + public void actionPerformed(ActionEvent ev) { + PageState ps = ev.getPageState(); + ps.reset(m_editContainer); + } + }); RequestLocal selectedPortletRL = new RequestLocal() { - public Object initialValue(PageState ps) { - BigDecimal portletID = - (BigDecimal)ps.getValue(m_selectedPortletParam); - if (portletID == null) { - return null; - } - return Portlet.retrievePortlet(portletID); + public Object initialValue(PageState ps) { + BigDecimal portletID + = (BigDecimal) ps.getValue(m_selectedPortletParam); + if (portletID == null) { + return null; } - }; + return Portlet.retrievePortlet(portletID); + } + }; ActionListener reset = new ActionListener() { - public void actionPerformed(ActionEvent ev) { - PageState ps = ev.getPageState(); - ps.reset(m_editContainer); - ps.setValue(m_selectedPortletParam, null); - } - }; - m_portletModify = new ApplicationModifyComponent - (selectedPortletRL, true, reset, reset); + public void actionPerformed(ActionEvent ev) { + PageState ps = ev.getPageState(); + ps.reset(m_editContainer); + ps.setValue(m_selectedPortletParam, null); + } + }; + m_portletModify = new ApplicationModifyComponent(selectedPortletRL, true, reset, reset); m_renameTabForm = new RenameTabForm(selectedTabIDRL); m_deleteTabForm = new DeleteTabForm(selectedTabIDRL); @@ -359,10 +359,10 @@ public class DisplayPane extends DynamicListWizard { setEditPane(m_editContainer); ((List) getListingComponent()).addChangeListener(new ChangeListener() { - public void stateChanged(ChangeEvent ev) { - ev.getPageState().reset(m_editContainer); - } - }); + public void stateChanged(ChangeEvent ev) { + ev.getPageState().reset(m_editContainer); + } + }); // //This cell renderer attempts to do the following: @@ -377,118 +377,110 @@ public class DisplayPane extends DynamicListWizard { //One other thing, if there is only one tab in the list, //this code preselects it, unless the add tab link has been //clicked. - ((List) getListingComponent()).setCellRenderer(new ListCellRenderer() { - public Component getComponent(List list,PageState state, - Object value,String key, int index,boolean isSelected) { + public Component getComponent(List list, PageState state, + Object value, String key, int index, boolean isSelected) { - Label tabName; - int indent_ctr = 0; - boolean isFirst = false; - boolean isLast = false; + Label tabName; + int indent_ctr = 0; + boolean isFirst = false; + boolean isLast = false; - SimpleContainer container = new SimpleContainer(); + SimpleContainer container = new SimpleContainer(); //get the collection of tabs, its size, and use this info - //to determine where in the collection this tab name resides... - BigDecimal bd = new BigDecimal(key); - PortalTab ptab = PortalTab.retrieveTab(bd); - PortalSite psite = ptab.getPortalSite(); - PortalTabCollection ptcoll = psite.getTabsForPortalSite(); - long size = ptcoll.size(); + //to determine where in the collection this tab name resides... + BigDecimal bd = new BigDecimal(key); + PortalTab ptab = PortalTab.retrieveTab(bd); + PortalSite psite = ptab.getPortalSite(); + PortalTabCollection ptcoll = psite.getTabsForPortalSite(); + long size = ptcoll.size(); //If only one tab, select it ONLY if addtablink not selected - // and then get outa here... - if(size == 1) - { - if((dlw.getAddLink().isSelected(state)) == false) - { - list.setSelectedKey(state,key); - tabName = new Label(value.toString()); - container.add(tabName); - //Update tab request local - selectedTabIDRL.set(state,bd); - return container; - } - } - else //more than one tab... - { - indent_ctr = 0; - while(ptcoll.next()) - { - indent_ctr++; - if(bd.compareTo(ptcoll.getID()) == 0) //we found tab... - { - if(indent_ctr == 1) - isFirst = true; - if(indent_ctr == size) - isLast = true; - break; - } - } + // and then get outa here... + if (size == 1) { + if ((dlw.getAddLink().isSelected(state)) == false) { + list.setSelectedKey(state, key); + tabName = new Label(value.toString()); + container.add(tabName); + //Update tab request local + selectedTabIDRL.set(state, bd); + return container; } - ptcoll.close(); - - //Code below constructs proper indent for tab - StringBuffer buf = new StringBuffer(200); - for(int i = 0; i < (indent_ctr - 1); i++) + } else //more than one tab... + { + indent_ctr = 0; + while (ptcoll.next()) { + indent_ctr++; + if (bd.compareTo(ptcoll.getID()) == 0) //we found tab... { - buf.append(FOUR_SPACE_INDENT_STRING); + if (indent_ctr == 1) { + isFirst = true; + } + if (indent_ctr == size) { + isLast = true; + } + break; } + } + } + ptcoll.close(); + + //Code below constructs proper indent for tab + StringBuffer buf = new StringBuffer(200); + for (int i = 0; i < (indent_ctr - 1); i++) { + buf.append(FOUR_SPACE_INDENT_STRING); + } //Here we construct the control links for arrows - //This could be done below in the particular cases for - //a slight performance benefit, but putting them - //here, together, is easier to understand... - if(isSelected) //This tab name is currently selected... - { - tabName = new Label(value.toString()); - tabName.setFontWeight(Label.BOLD); - Label labelLeft = new Label(GlobalizationUtil.globalize("cw.workspace.ui.admin.shift_left")); - Label labelRight = new Label(GlobalizationUtil.globalize("cw.workspace.ui.admin.shift_right")); - - ControlLink linkLeft = new ControlLink(labelLeft) { - public void setControlEvent(PageState s) { - s.setControlEvent(dlw,"left","1"); - } - }; - ControlLink linkRight = new ControlLink(labelRight) { - public void setControlEvent(PageState s) { - s.setControlEvent(dlw,"right","1"); - } - }; - - linkLeft.setClassAttr("shiftleft"); - linkRight.setClassAttr("shiftright"); - if(isFirst) - { - container.add(tabName); - container.add(linkRight); - } - else if(isLast) - { - container.add(linkLeft); - container.add(tabName); - } - else //This tab is somewhere in the middle... - { - container.add(linkLeft); - container.add(tabName); - container.add(linkRight); - } + //This could be done below in the particular cases for + //a slight performance benefit, but putting them + //here, together, is easier to understand... + if (isSelected) //This tab name is currently selected... + { + tabName = new Label(value.toString()); + tabName.setFontWeight(Label.BOLD); + Label labelLeft = new Label(GlobalizationUtil.globalize( + "cw.workspace.ui.admin.shift_left")); + Label labelRight = new Label(GlobalizationUtil.globalize( + "cw.workspace.ui.admin.shift_right")); + ControlLink linkLeft = new ControlLink(labelLeft) { + public void setControlEvent(PageState s) { + s.setControlEvent(dlw, "left", "1"); } - else //this tab is NOT selected...return a link - { - String ttab = buf.toString() + value.toString(); - tabName = new Label(ttab,false); - ControlLink l = new ControlLink(tabName); - container.add(l); + }; + ControlLink linkRight = new ControlLink(labelRight) { + public void setControlEvent(PageState s) { + s.setControlEvent(dlw, "right", "1"); } - return container; + }; + + linkLeft.setClassAttr("shiftleft"); + linkRight.setClassAttr("shiftright"); + if (isFirst) { + container.add(tabName); + container.add(linkRight); + } else if (isLast) { + container.add(linkLeft); + container.add(tabName); + } else //This tab is somewhere in the middle... + { + container.add(linkLeft); + container.add(tabName); + container.add(linkRight); + } + + } else //this tab is NOT selected...return a link + { + String ttab = buf.toString() + value.toString(); + tabName = new Label(ttab, false); + ControlLink l = new ControlLink(tabName); + container.add(l); } - }); - + return container; + } + }); } //end of constructor @@ -497,53 +489,55 @@ public class DisplayPane extends DynamicListWizard { p.addComponentStateParam(this, m_selectedPortletParam); } - public void respond(PageState state) throws javax.servlet.ServletException{ - String tabIDstr = - (String)this.getSelectionModel() - .getSelectedKey(state); + public void respond(PageState state) throws javax.servlet.ServletException { + String tabIDstr + = (String) this.getSelectionModel() + .getSelectedKey(state); BigDecimal tabID = new BigDecimal(tabIDstr); String name = state.getControlEventName(); - if(name.compareTo("left") == 0) { + if (name.compareTo("left") == 0) { PortalTab ptab = PortalTab.retrieveTab(tabID); PortalSite psite = ptab.getPortalSite(); psite.swapTabWithPrevious(ptab); - } else if(name.compareTo("right") == 0) { + } else if (name.compareTo("right") == 0) { PortalTab ptab = PortalTab.retrieveTab(tabID); PortalSite psite = ptab.getPortalSite(); psite.swapTabWithNext(ptab); } } - public class RenameTabForm extends Form implements FormProcessListener { + private TextField currenttabName; private Label instruction; - private Submit button,cancelbutton; + private Submit button, cancelbutton; private RequestLocal m_tabIDRL; public RenameTabForm(RequestLocal SelectedTabIDRL) { super("renametabform"); m_tabIDRL = SelectedTabIDRL; - instruction = new Label(GlobalizationUtil.globalize("cw.workspace.ui.admin.enter_new_name_for_this_tab_in_text_field")); + instruction = new Label(GlobalizationUtil.globalize( + "cw.workspace.ui.admin.enter_new_name_for_this_tab_in_text_field")); currenttabName = new TextField("CurrentTabName"); currenttabName.setDefaultValue(""); currenttabName.setSize(40); - currenttabName.addValidationListener - (new NotNullValidationListener("Every Tab must have a name!")); + currenttabName.addValidationListener(new NotNullValidationListener( + "Every Tab must have a name!")); try { currenttabName.addPrintListener(new PrintListener() { - public void prepare(PrintEvent e) { - PageState s = e.getPageState(); - BigDecimal tabID = (BigDecimal)m_tabIDRL.get(s); - PortalTab ptab = PortalTab.retrieveTab(tabID); - TextField tf = (TextField)e.getTarget(); - tf.setValue(s,ptab.getTitle()); - } - }); - } catch(java.util.TooManyListenersException e) { } + public void prepare(PrintEvent e) { + PageState s = e.getPageState(); + BigDecimal tabID = (BigDecimal) m_tabIDRL.get(s); + PortalTab ptab = PortalTab.retrieveTab(tabID); + TextField tf = (TextField) e.getTarget(); + tf.setValue(s, ptab.getTitle()); + } + }); + } catch (java.util.TooManyListenersException e) { + } button = new Submit("Rename tab"); button.setButtonLabel("Rename tab"); cancelbutton = new Submit("Cancel"); @@ -558,8 +552,8 @@ public class DisplayPane extends DynamicListWizard { public void process(FormSectionEvent e) { PageState s = e.getPageState(); - if(button.isSelected(s)) { - BigDecimal tabID = (BigDecimal)m_tabIDRL.get(s); + if (button.isSelected(s)) { + BigDecimal tabID = (BigDecimal) m_tabIDRL.get(s); PortalTab ptab = PortalTab.retrieveTab(tabID); ptab.setTitle(currenttabName.getValue(s).toString()); ptab.save(); @@ -570,28 +564,29 @@ public class DisplayPane extends DynamicListWizard { } //end rename form public class DeleteTabForm extends Form implements FormProcessListener { + private TextField currenttabName; private Label instruction; private Submit button; private Submit cancelbutton; private RequestLocal m_tabIDRL; - public DeleteTabForm(RequestLocal SelectedTabIDRL) { super("deletetabform"); m_tabIDRL = SelectedTabIDRL; - instruction = new Label(GlobalizationUtil.globalize("cw.workspace.ui.admin.are_you_sure_you_want_to_delete_this_tab")); + instruction = new Label(GlobalizationUtil.globalize( + "cw.workspace.ui.admin.are_you_sure_you_want_to_delete_this_tab")); instruction.addPrintListener(new PrintListener() { - public void prepare(PrintEvent e) { - PageState s = e.getPageState(); - String prefixstr = "Are you sure you want to delete the "; - BigDecimal tabID = (BigDecimal)m_tabIDRL.get(s); - PortalTab ptab = PortalTab.retrieveTab(tabID); - Label t = (Label)e.getTarget(); - t.setLabel(prefixstr + ptab.getTitle() + " tab?"); - } - }); + public void prepare(PrintEvent e) { + PageState s = e.getPageState(); + String prefixstr = "Are you sure you want to delete the "; + BigDecimal tabID = (BigDecimal) m_tabIDRL.get(s); + PortalTab ptab = PortalTab.retrieveTab(tabID); + Label t = (Label) e.getTarget(); + t.setLabel(prefixstr + ptab.getTitle() + " tab?"); + } + }); button = new Submit("Delete this tab"); button.setButtonLabel("Delete this tab"); @@ -606,8 +601,8 @@ public class DisplayPane extends DynamicListWizard { public void process(FormSectionEvent e) { PageState s = e.getPageState(); - if(button.isSelected(s)) { - BigDecimal tabID = (BigDecimal)m_tabIDRL.get(s); + if (button.isSelected(s)) { + BigDecimal tabID = (BigDecimal) m_tabIDRL.get(s); PortalTab ptab = PortalTab.retrieveTab(tabID); ptab.delete(); getSelectionModel().clearSelection(s); @@ -618,6 +613,7 @@ public class DisplayPane extends DynamicListWizard { } //end delete form private class RenameLinkListener implements ActionListener { + public void actionPerformed(ActionEvent event) { PageState ps = event.getPageState(); m_editContainer.setVisibleComponent(ps, m_renameTabForm); @@ -625,19 +621,19 @@ public class DisplayPane extends DynamicListWizard { } private class DeleteLinkListener implements ActionListener { + public void actionPerformed(ActionEvent event) { PageState ps = event.getPageState(); m_editContainer.setVisibleComponent(ps, m_deleteTabForm); } } - private class LayoutListModel implements ListModel - { + private class LayoutListModel implements ListModel { + Vector vec; ListIterator vl; - LayoutListModel (PageState pageState) - { + LayoutListModel(PageState pageState) { vec = new Vector(); vec.add("W"); vec.add("NW"); @@ -648,18 +644,15 @@ public class DisplayPane extends DynamicListWizard { vl = vec.listIterator(); } - public boolean next() - { + public boolean next() { return vl.hasNext(); } - public Object getElement() - { + public Object getElement() { return vl.next(); } - public String getKey() - { + public String getKey() { int dex = vl.previousIndex(); dex = dex + 1; //Integer it = new Integer(vl.previousIndex()); @@ -668,34 +661,28 @@ public class DisplayPane extends DynamicListWizard { } } - class LayoutListCellRenderer implements ListCellRenderer - { - public Component getComponent - (List list, PageState pageState, Object value, String key, - int index, boolean isSelected) - { - String val = (String)value; + class LayoutListCellRenderer implements ListCellRenderer { + + public Component getComponent(List list, PageState pageState, Object value, String key, + int index, boolean isSelected) { + String val = (String) value; //check if selected...if not selected //find out what index we are... //then set an attribute on the link so that it is replaced //with an image link in the stylesheet. //if selected, return a label with a selected attr and value... - if(isSelected) - { - Label label = new Label(val); - label.setClassAttr(val); - return label; - } - else - { - ControlLink link = new ControlLink(val); - link.setClassAttr(val); - link.setStyleAttr("HooHaH"); - return link; - } + if (isSelected) { + Label label = new Label(val); + label.setClassAttr(val); + return label; + } else { + ControlLink link = new ControlLink(val); + link.setClassAttr(val); + link.setStyleAttr("HooHaH"); + return link; + } } } - } diff --git a/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/ApplicationSelector.java b/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/ApplicationSelector.java index 903533172..0344148d3 100755 --- a/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/ApplicationSelector.java +++ b/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/ApplicationSelector.java @@ -15,7 +15,6 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - package com.arsdigita.portalworkspace.ui; import com.arsdigita.bebop.Form; @@ -47,8 +46,8 @@ import java.util.TooManyListenersException; import org.apache.log4j.Logger; /** - * - * + * + * */ public class ApplicationSelector extends Form { @@ -63,15 +62,17 @@ public class ApplicationSelector extends Form { /** * Convenient Constructor + * * @param type * @param app */ - public ApplicationSelector(ApplicationType type,DomainObjectParameter app) { + public ApplicationSelector(ApplicationType type, DomainObjectParameter app) { this(type, app, null); } /** * Constructor + * * @param type * @param app * @param privilege @@ -85,8 +86,7 @@ public class ApplicationSelector extends Form { m_app = app; m_privilege = privilege; - s_log.debug("displayed applications will be filtered by privilege " + - m_privilege); + s_log.debug("displayed applications will be filtered by privilege " + m_privilege); m_apps = new SingleSelect(new DomainObjectParameter("apps")); m_apps.addValidationListener(new NotNullValidationListener()); @@ -108,15 +108,16 @@ public class ApplicationSelector extends Form { * */ private class AppSubmissionListener implements FormSubmissionListener { - public void submitted(FormSectionEvent e) - throws FormProcessException { - if (m_buttons.getCancelButton().isSelected(e.getPageState())) { - s_log.debug("Firing event for cancel"); - fireCompletionEvent(e.getPageState()); - throw new FormProcessException("canncelled"); - } - s_log.debug("Falling through for process"); - } + + public void submitted(FormSectionEvent e) + throws FormProcessException { + if (m_buttons.getCancelButton().isSelected(e.getPageState())) { + s_log.debug("Firing event for cancel"); + fireCompletionEvent(e.getPageState()); + throw new FormProcessException("canncelled"); + } + s_log.debug("Falling through for process"); + } } /** @@ -130,7 +131,7 @@ public class ApplicationSelector extends Form { PageState state = e.getPageState(); state.setValue(m_app, m_apps.getValue(state)); - fireCompletionEvent(e.getPageState()); + fireCompletionEvent(e.getPageState()); } } @@ -148,15 +149,16 @@ public class ApplicationSelector extends Form { apps.addEqualsFilter("resourceType.id", m_type.getID()); if (m_privilege != null) { - Party user = Kernel.getContext().getParty(); + Party user = Kernel.getContext().getParty(); if (user == null) { user = Kernel.getPublicUser(); } - PermissionService.filterObjects(apps,m_privilege, user.getOID()); + PermissionService.filterObjects(apps, m_privilege, user.getOID()); } apps.addOrder("primaryURL"); SingleSelect t = (SingleSelect) e.getTarget(); + t.clearOptions(); t.addOption(new Option(null, "--select one--")); while (apps.next()) { Application app = apps.getApplication(); diff --git a/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/LayoutForm.java b/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/LayoutForm.java index 9264d76d4..0f7b6f7e2 100755 --- a/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/LayoutForm.java +++ b/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/LayoutForm.java @@ -15,7 +15,6 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - package com.arsdigita.portalworkspace.ui; import java.util.TooManyListenersException; @@ -53,94 +52,95 @@ import com.arsdigita.util.UncheckedWrapperException; * @version $Id: LayoutForm.java 1174 2006-06-14 14:14:15Z fabrice $ */ public class LayoutForm extends Form implements FormProcessListener, - FormInitListener { + FormInitListener { - private WorkspaceSelectionAbstractModel m_workspace; + private WorkspaceSelectionAbstractModel m_workspace; - private PortalSelectionModel m_portal; + private PortalSelectionModel m_portal; - private SingleSelect m_layout; + private SingleSelect m_layout; - private Submit m_save; + private Submit m_save; - public LayoutForm(PortalSelectionModel portal) { - this(null, portal); - } + public LayoutForm(PortalSelectionModel portal) { + this(null, portal); + } - public LayoutForm(WorkspaceSelectionAbstractModel workspace, - PortalSelectionModel portal) { - super("editLayout", new SimpleContainer("portal:editLayout", - WorkspacePage.PORTAL_XML_NS)); + public LayoutForm(WorkspaceSelectionAbstractModel workspace, + PortalSelectionModel portal) { + super("editLayout", new SimpleContainer("portal:editLayout", + WorkspacePage.PORTAL_XML_NS)); - m_workspace = workspace; - m_portal = portal; + m_workspace = workspace; + m_portal = portal; - m_layout = new SingleSelect(new OIDParameter("layout")); - m_layout.addValidationListener(new NotNullValidationListener()); - try { - m_layout.addPrintListener(new PrintListener() { - public void prepare(PrintEvent ev) { - SingleSelect target = (SingleSelect) ev.getTarget(); - DomainCollection layouts = PageLayout.retrieveAll(); - layouts.addOrder(PageLayout.TITLE); - while (layouts.next()) { - PageLayout layout = (PageLayout) layouts - .getDomainObject(); - target.addOption(new Option(layout.getOID().toString(), - layout.getTitle())); - } - } - }); - } catch (TooManyListenersException ex) { - throw new UncheckedWrapperException("this cannot happen", ex); - } + m_layout = new SingleSelect(new OIDParameter("layout")); + m_layout.addValidationListener(new NotNullValidationListener()); + try { + m_layout.addPrintListener(new PrintListener() { + public void prepare(PrintEvent ev) { + SingleSelect target = (SingleSelect) ev.getTarget(); + target.clearOptions(); + DomainCollection layouts = PageLayout.retrieveAll(); + layouts.addOrder(PageLayout.TITLE); + while (layouts.next()) { + PageLayout layout = (PageLayout) layouts + .getDomainObject(); + target.addOption(new Option(layout.getOID().toString(), + layout.getTitle())); + } + } + }); + } catch (TooManyListenersException ex) { + throw new UncheckedWrapperException("this cannot happen", ex); + } - m_save = new Submit("Save"); + m_save = new Submit("Save"); - add(m_layout); - add(m_save); + add(m_layout); + add(m_save); - addProcessListener(this); - addInitListener(this); - } + addProcessListener(this); + addInitListener(this); + } - public void setWorkspaceModel(WorkspaceSelectionAbstractModel workspace) { - m_workspace = workspace; - } + public void setWorkspaceModel(WorkspaceSelectionAbstractModel workspace) { + m_workspace = workspace; + } - public Workspace getSelectedWorkspace(PageState state) { - return m_workspace.getSelectedWorkspace(state); - } + public Workspace getSelectedWorkspace(PageState state) { + return m_workspace.getSelectedWorkspace(state); + } - public void init(FormSectionEvent e) { - PageState state = e.getPageState(); + public void init(FormSectionEvent e) { + PageState state = e.getPageState(); - WorkspacePage portal = (WorkspacePage) m_portal - .getSelectedPortal(state); + WorkspacePage portal = (WorkspacePage) m_portal + .getSelectedPortal(state); - Assert.exists(portal, WorkspacePage.class); + Assert.exists(portal, WorkspacePage.class); - m_layout.setValue(state, portal.getLayout().getOID()); - } + m_layout.setValue(state, portal.getLayout().getOID()); + } - public void process(FormSectionEvent e) { - PageState state = e.getPageState(); + public void process(FormSectionEvent e) { + PageState state = e.getPageState(); - Workspace workspace = getSelectedWorkspace(state); - Party party = Kernel.getContext().getParty(); - if (!PortalHelper.canCustomize(party, workspace)) { - throw new AccessDeniedException( - "no permissions to customize workspace"); - } + Workspace workspace = getSelectedWorkspace(state); + Party party = Kernel.getContext().getParty(); + if (!PortalHelper.canCustomize(party, workspace)) { + throw new AccessDeniedException( + "no permissions to customize workspace"); + } - WorkspacePage portal = (WorkspacePage) m_portal - .getSelectedPortal(state); + WorkspacePage portal = (WorkspacePage) m_portal + .getSelectedPortal(state); - Assert.exists(portal, WorkspacePage.class); + Assert.exists(portal, WorkspacePage.class); - OID layoutOID = (OID) m_layout.getValue(state); - PageLayout layout = (PageLayout) DomainObjectFactory - .newInstance(layoutOID); - portal.setLayout(layout); - } + OID layoutOID = (OID) m_layout.getValue(state); + PageLayout layout = (PageLayout) DomainObjectFactory + .newInstance(layoutOID); + portal.setLayout(layout); + } } diff --git a/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/PortletTypeForm.java b/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/PortletTypeForm.java index e38b0c634..0ccf13762 100755 --- a/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/PortletTypeForm.java +++ b/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/PortletTypeForm.java @@ -12,7 +12,6 @@ * rights and limitations under the License. * */ - package com.arsdigita.portalworkspace.ui; import java.math.BigDecimal; @@ -46,97 +45,98 @@ import com.arsdigita.web.Application; public class PortletTypeForm extends Form { - private Label m_portletTypeLabel; + private Label m_portletTypeLabel; - private SingleSelect m_portletType; + private SingleSelect m_portletType; - private Submit m_submit; + private Submit m_submit; - private static Logger s_log = Logger.getLogger(PortletTypeForm.class); + private static Logger s_log = Logger.getLogger(PortletTypeForm.class); - private PrintListener m_portletTypePrintListener = new PrintListener() { - public void prepare(PrintEvent e) { - PageState pageState = e.getPageState(); + private PrintListener m_portletTypePrintListener = new PrintListener() { + public void prepare(PrintEvent e) { + PageState pageState = e.getPageState(); - OptionGroup optionGroup = (OptionGroup) e.getTarget(); + OptionGroup optionGroup = (OptionGroup) e.getTarget(); + optionGroup.clearOptions(); - PortletTypeCollection portletTypes = PortletType - .retrieveAllPortletTypes(); - List excludedTypes = Workspace.getConfig() - .getExcludedPortletTypes(); - if (!excludedTypes.isEmpty()) { - Filter excludedTypesFilter = portletTypes - .addFilter(Application.OBJECT_TYPE - + " not in :nonDisplayTypes"); - excludedTypesFilter.set("nonDisplayTypes", excludedTypes); - } - User thisUser = (User) Kernel.getContext().getParty(); - if (thisUser == null) { + PortletTypeCollection portletTypes = PortletType + .retrieveAllPortletTypes(); + List excludedTypes = Workspace.getConfig() + .getExcludedPortletTypes(); + if (!excludedTypes.isEmpty()) { + Filter excludedTypesFilter = portletTypes + .addFilter(Application.OBJECT_TYPE + + " not in :nonDisplayTypes"); + excludedTypesFilter.set("nonDisplayTypes", excludedTypes); + } + User thisUser = (User) Kernel.getContext().getParty(); + if (thisUser == null) { // can't actually happen, as user must be logged in at the point - // when the page with this portal in edit mode was requested - thisUser = Kernel.getPublicUser(); - } - Workspace mainWorkspace; - if (Subsite.getContext().hasSite()) { - mainWorkspace = (Workspace) Subsite.getContext().getSite() - .getFrontPage(); - } else { - mainWorkspace = Workspace.getDefaultHomepageWorkspace(); - } + // when the page with this portal in edit mode was requested + thisUser = Kernel.getPublicUser(); + } + Workspace mainWorkspace; + if (Subsite.getContext().hasSite()) { + mainWorkspace = (Workspace) Subsite.getContext().getSite() + .getFrontPage(); + } else { + mainWorkspace = Workspace.getDefaultHomepageWorkspace(); + } - PermissionDescriptor admin = new PermissionDescriptor( - PrivilegeDescriptor.ADMIN, mainWorkspace, thisUser); - if (PermissionService.checkPermission(admin)) { - s_log.debug(thisUser.getName() - + " has admin rights on the current workspace"); - } else { - s_log.debug(thisUser.getName() - + " cannot administer the current main workspace"); - List adminTypes = Workspace.getConfig().getAdminPortletTypes(); - if (!adminTypes.isEmpty()) { - Filter adminTypesFilter = portletTypes - .addFilter(Application.OBJECT_TYPE - + " not in :adminTypes"); - adminTypesFilter.set("adminTypes", adminTypes); - } - } - portletTypes.addOrder("title"); - while (portletTypes.next()) { - PortletType portletType = portletTypes.getPortletType(); - Option option = new Option(portletType.getID().toString(), - portletType.getTitle()); + PermissionDescriptor admin = new PermissionDescriptor( + PrivilegeDescriptor.ADMIN, mainWorkspace, thisUser); + if (PermissionService.checkPermission(admin)) { + s_log.debug(thisUser.getName() + + " has admin rights on the current workspace"); + } else { + s_log.debug(thisUser.getName() + + " cannot administer the current main workspace"); + List adminTypes = Workspace.getConfig().getAdminPortletTypes(); + if (!adminTypes.isEmpty()) { + Filter adminTypesFilter = portletTypes + .addFilter(Application.OBJECT_TYPE + + " not in :adminTypes"); + adminTypesFilter.set("adminTypes", adminTypes); + } + } + portletTypes.addOrder("title"); + while (portletTypes.next()) { + PortletType portletType = portletTypes.getPortletType(); + Option option = new Option(portletType.getID().toString(), + portletType.getTitle()); - optionGroup.addOption(option); - } - } - }; + optionGroup.addOption(option); + } + } + }; - /** + /** * Default constructor */ public PortletTypeForm() { - this("portletTypeForm"); - } + this("portletTypeForm"); + } - public PortletTypeForm(String name) { - super(name, new SimpleContainer()); - setRedirecting(true); + public PortletTypeForm(String name) { + super(name, new SimpleContainer()); + setRedirecting(true); - m_portletType = new SingleSelect("portletTypeID"); - try { - m_portletType.addPrintListener(m_portletTypePrintListener); - } catch (TooManyListenersException e) { - /* Nothing here yet. */ - } - m_portletType.addValidationListener(new NotNullValidationListener( - "You must select a Portlet Type")); - add(m_portletType); + m_portletType = new SingleSelect("portletTypeID"); + try { + m_portletType.addPrintListener(m_portletTypePrintListener); + } catch (TooManyListenersException e) { + /* Nothing here yet. */ + } + m_portletType.addValidationListener(new NotNullValidationListener( + "You must select a Portlet Type")); + add(m_portletType); - m_submit = new Submit("Add"); - add(m_submit); - } + m_submit = new Submit("Add"); + add(m_submit); + } - public BigDecimal getPortletType(PageState state) { - return new BigDecimal((String) m_portletType.getValue(state)); - } + public BigDecimal getPortletType(PageState state) { + return new BigDecimal((String) m_portletType.getValue(state)); + } } diff --git a/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/admin/GroupMemberPicker.java b/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/admin/GroupMemberPicker.java index efef1d550..e49eb1fa8 100755 --- a/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/admin/GroupMemberPicker.java +++ b/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/admin/GroupMemberPicker.java @@ -15,7 +15,6 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - package com.arsdigita.portalworkspace.ui.admin; import java.math.BigDecimal; @@ -46,113 +45,113 @@ import com.arsdigita.util.UncheckedWrapperException; public abstract class GroupMemberPicker extends UserPicker { - private StringParameter m_restrictParam; + private StringParameter m_restrictParam; - private SingleSelect m_restrict; + private SingleSelect m_restrict; - private Option m_both; + private Option m_both; - private Option m_users; + private Option m_users; - private Option m_groups; + private Option m_groups; - public GroupMemberPicker() { - } + public GroupMemberPicker() { + } - protected void addWidgets() { - m_restrictParam = new StringParameter("restrict"); + protected void addWidgets() { + m_restrictParam = new StringParameter("restrict"); - m_restrict = new SingleSelect("restrict1"); - m_both = new Option("both", "Users & Groups"); - m_users = new Option("users", "Users Only"); - m_groups = new Option("groups", "Groups Only"); + m_restrict = new SingleSelect("restrict1"); + m_both = new Option("both", "Users & Groups"); + m_users = new Option("users", "Users Only"); + m_groups = new Option("groups", "Groups Only"); - m_restrict.addOption(m_both); - m_restrict.addOption(m_users); - m_restrict.addOption(m_groups); - m_restrict.setOptionSelected(m_users); + m_restrict.addOption(m_both); + m_restrict.addOption(m_users); + m_restrict.addOption(m_groups); + m_restrict.setOptionSelected(m_users); - BoxPanel opt = new BoxPanel(BoxPanel.HORIZONTAL); - opt.add(new Label("Search for")); - opt.add(m_restrict); - add(opt); + BoxPanel opt = new BoxPanel(BoxPanel.HORIZONTAL); + opt.add(new Label("Search for")); + opt.add(m_restrict); + add(opt); - super.addWidgets(); - } + super.addWidgets(); + } - public void register(Page p) { - super.register(p); + public void register(Page p) { + super.register(p); - p.addGlobalStateParam(m_restrictParam); - } + p.addGlobalStateParam(m_restrictParam); + } - public void init(FormSectionEvent e) { - PageState ps = e.getPageState(); + public void init(FormSectionEvent e) { + PageState ps = e.getPageState(); - super.init(e); + super.init(e); - m_restrict.setValue(ps, ps.getValue(m_restrictParam)); - } + m_restrict.setValue(ps, ps.getValue(m_restrictParam)); + } - public void process(FormSectionEvent e) { - PageState ps = e.getPageState(); + public void process(FormSectionEvent e) { + PageState ps = e.getPageState(); - super.process(e); + super.process(e); - ps.setValue(m_restrictParam, m_restrict.getValue(ps)); - } + ps.setValue(m_restrictParam, m_restrict.getValue(ps)); + } - protected abstract Group getGroup(PageState ps); + protected abstract Group getGroup(PageState ps); - protected DataQuery getUsers(PageState ps, String search) { - String bdot = Party.BASE_DATA_OBJECT_TYPE; - if (m_users.getValue().equals(ps.getValue(m_restrictParam))) { - bdot = User.BASE_DATA_OBJECT_TYPE; - } else if (m_groups.getValue().equals(ps.getValue(m_restrictParam))) { - bdot = Group.BASE_DATA_OBJECT_TYPE; - } + protected DataQuery getUsers(PageState ps, String search) { + String bdot = Party.BASE_DATA_OBJECT_TYPE; + if (m_users.getValue().equals(ps.getValue(m_restrictParam))) { + bdot = User.BASE_DATA_OBJECT_TYPE; + } else if (m_groups.getValue().equals(ps.getValue(m_restrictParam))) { + bdot = Group.BASE_DATA_OBJECT_TYPE; + } - DataCollection parties = SessionManager.getSession().retrieve(bdot); + DataCollection parties = SessionManager.getSession().retrieve(bdot); - CompoundFilter or = parties.getFilterFactory().or(); + CompoundFilter or = parties.getFilterFactory().or(); - Filter nameFilter = parties.getFilterFactory().simple( - "lower(displayName) like lower(:term)"); - nameFilter.set("term", "%" + search + "%"); - Filter emailFilter = parties.getFilterFactory().simple( - "lower(primaryEmail) like lower(:term)"); - emailFilter.set("term", "%" + search + "%"); + Filter nameFilter = parties.getFilterFactory().simple( + "lower(displayName) like lower(:term)"); + nameFilter.set("term", "%" + search + "%"); + Filter emailFilter = parties.getFilterFactory().simple( + "lower(primaryEmail) like lower(:term)"); + emailFilter.set("term", "%" + search + "%"); - or.addFilter(nameFilter); - or.addFilter(emailFilter); - parties.addFilter(or); - parties.addOrder(ACSObject.DISPLAY_NAME); + or.addFilter(nameFilter); + or.addFilter(emailFilter); + parties.addFilter(or); + parties.addOrder(ACSObject.DISPLAY_NAME); - return parties; - } + return parties; + } - protected String getDisplayName(DataQuery q) { - DataObject party = ((DataCollection) q).getDataObject(); - return (String) party.get(ACSObject.DISPLAY_NAME); - } + protected String getDisplayName(DataQuery q) { + DataObject party = ((DataCollection) q).getDataObject(); + return (String) party.get(ACSObject.DISPLAY_NAME); + } - protected String getKey(DataQuery q) { - DataObject party = ((DataCollection) q).getDataObject(); - return party.get(ACSObject.ID).toString(); - } + protected String getKey(DataQuery q) { + DataObject party = ((DataCollection) q).getDataObject(); + return party.get(ACSObject.ID).toString(); + } - protected void addUser(PageState ps, BigDecimal userID) { - Party party = null; + protected void addUser(PageState ps, BigDecimal userID) { + Party party = null; - try { - party = (Party) DomainObjectFactory.newInstance(new OID( - Party.BASE_DATA_OBJECT_TYPE, userID)); - } catch (DataObjectNotFoundException ex) { - throw new UncheckedWrapperException("cannot find user", ex); - } + try { + party = (Party) DomainObjectFactory.newInstance(new OID( + Party.BASE_DATA_OBJECT_TYPE, userID)); + } catch (DataObjectNotFoundException ex) { + throw new UncheckedWrapperException("cannot find user", ex); + } - Group group = getGroup(ps); - group.addMemberOrSubgroup(party); - group.save(); - } + Group group = getGroup(ps); + group.addMemberOrSubgroup(party); + group.save(); + } } diff --git a/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/admin/WorkspaceConfigFormSection.java b/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/admin/WorkspaceConfigFormSection.java index 43da09e53..864cd76f8 100755 --- a/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/admin/WorkspaceConfigFormSection.java +++ b/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/admin/WorkspaceConfigFormSection.java @@ -15,7 +15,6 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - package com.arsdigita.portalworkspace.ui.admin; import java.util.TooManyListenersException; @@ -41,77 +40,75 @@ import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.web.Application; import com.arsdigita.web.ui.ApplicationConfigFormSection; - // Referenced in Initializer. // No other referebce found. // TODO: What happens if omitted? // (2013-02-10pb) - - /** - * - * + * + * */ public class WorkspaceConfigFormSection extends ApplicationConfigFormSection { - private SingleSelect m_layout; + private SingleSelect m_layout; - public WorkspaceConfigFormSection(ResourceType resType, - RequestLocal parentAppRL) { - super(resType, parentAppRL); - } + public WorkspaceConfigFormSection(ResourceType resType, + RequestLocal parentAppRL) { + super(resType, parentAppRL); + } - public WorkspaceConfigFormSection(RequestLocal application) { - super(application); - } + public WorkspaceConfigFormSection(RequestLocal application) { + super(application); + } - protected void addWidgets() { - super.addWidgets(); + protected void addWidgets() { + super.addWidgets(); - m_layout = new SingleSelect(new OIDParameter("layout")); - m_layout.addValidationListener(new NotNullValidationListener()); - try { - m_layout.addPrintListener(new PrintListener() { - public void prepare(PrintEvent ev) { - SingleSelect target = (SingleSelect) ev.getTarget(); - DomainCollection layouts = PageLayout.retrieveAll(); - layouts.addOrder(PageLayout.TITLE); - while (layouts.next()) { - PageLayout layout = (PageLayout) layouts - .getDomainObject(); - target.addOption(new Option(layout.getOID().toString(), - layout.getTitle())); - } - } - }); - } catch (TooManyListenersException ex) { - throw new UncheckedWrapperException("this cannot happen", ex); - } - add(new Label("Default Page Layout:", Label.BOLD), ColumnPanel.RIGHT); - add(m_layout); - } + m_layout = new SingleSelect(new OIDParameter("layout")); + m_layout.addValidationListener(new NotNullValidationListener()); + try { + m_layout.addPrintListener(new PrintListener() { + public void prepare(PrintEvent ev) { + SingleSelect target = (SingleSelect) ev.getTarget(); + target.clearOptions(); + DomainCollection layouts = PageLayout.retrieveAll(); + layouts.addOrder(PageLayout.TITLE); + while (layouts.next()) { + PageLayout layout = (PageLayout) layouts + .getDomainObject(); + target.addOption(new Option(layout.getOID().toString(), + layout.getTitle())); + } + } + }); + } catch (TooManyListenersException ex) { + throw new UncheckedWrapperException("this cannot happen", ex); + } + add(new Label("Default Page Layout:", Label.BOLD), ColumnPanel.RIGHT); + add(m_layout); + } - protected void initWidgets(PageState state, Application app) - throws FormProcessException { - super.initWidgets(state, app); + protected void initWidgets(PageState state, Application app) + throws FormProcessException { + super.initWidgets(state, app); - if (app != null) { - Workspace workspace = (Workspace) app; - m_layout.setValue(state, workspace.getDefaultLayout().getOID()); - } else { - m_layout.setValue(state, PageLayout.getDefaultLayout().getOID()); - } - } + if (app != null) { + Workspace workspace = (Workspace) app; + m_layout.setValue(state, workspace.getDefaultLayout().getOID()); + } else { + m_layout.setValue(state, PageLayout.getDefaultLayout().getOID()); + } + } - protected void processWidgets(PageState state, Application app) - throws FormProcessException { - super.processWidgets(state, app); + protected void processWidgets(PageState state, Application app) + throws FormProcessException { + super.processWidgets(state, app); - Workspace workspace = (Workspace) app; + Workspace workspace = (Workspace) app; - OID layoutOID = (OID) m_layout.getValue(state); - PageLayout layout = (PageLayout) DomainObjectFactory - .newInstance(layoutOID); - workspace.setDefaultLayout(layout); - } + OID layoutOID = (OID) m_layout.getValue(state); + PageLayout layout = (PageLayout) DomainObjectFactory + .newInstance(layoutOID); + workspace.setDefaultLayout(layout); + } } diff --git a/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/admin/WorkspaceCreateForm.java b/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/admin/WorkspaceCreateForm.java index 08785261c..7bb000c6c 100644 --- a/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/admin/WorkspaceCreateForm.java +++ b/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/admin/WorkspaceCreateForm.java @@ -62,6 +62,7 @@ public class WorkspaceCreateForm extends ApplicationCreateForm { layout.addPrintListener(new PrintListener() { public void prepare(final PrintEvent event) { final SingleSelect target = (SingleSelect) event.getTarget(); + target.clearOptions(); final DomainCollection layouts = PageLayout.retrieveAll(); layouts.addOrder(PageLayout.TITLE); while (layouts.next()) { diff --git a/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/portlet/ContentDirectoryPortletEditor.java b/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/portlet/ContentDirectoryPortletEditor.java index 6a98d706c..820eac7aa 100755 --- a/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/portlet/ContentDirectoryPortletEditor.java +++ b/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/portlet/ContentDirectoryPortletEditor.java @@ -12,7 +12,6 @@ * rights and limitations under the License. * */ - package com.arsdigita.portalworkspace.ui.portlet; import java.math.BigDecimal; @@ -50,139 +49,142 @@ import com.arsdigita.web.Application; import com.arsdigita.web.Web; /** - * - * + * + * */ public class ContentDirectoryPortletEditor extends PortletConfigFormSection { - private static final Logger s_log = Logger - .getLogger(ContentDirectoryPortletEditor.class); + private static final Logger s_log = Logger + .getLogger(ContentDirectoryPortletEditor.class); - private SingleSelect m_root; + private SingleSelect m_root; - private SingleSelect m_layout; + private SingleSelect m_layout; - private SingleSelect m_depth; + private SingleSelect m_depth; - /** + /** * Constructor + * * @param resType * @param parentAppRL */ public ContentDirectoryPortletEditor(ResourceType resType, - RequestLocal parentAppRL) { - super(resType, parentAppRL); - } + RequestLocal parentAppRL) { + super(resType, parentAppRL); + } - /** - * + /** + * * @param application */ public ContentDirectoryPortletEditor(RequestLocal application) { - super(application); - } + super(application); + } - /** - * + /** + * */ public void addWidgets() { - super.addWidgets(); + super.addWidgets(); - m_root = new SingleSelect(new BigDecimalParameter("root")); - try { - m_root.addPrintListener(new CategoryPrintListener()); - } catch (TooManyListenersException ex) { - throw new UncheckedWrapperException("this cannot happen", ex); - } + m_root = new SingleSelect(new BigDecimalParameter("root")); + try { + m_root.addPrintListener(new CategoryPrintListener()); + } catch (TooManyListenersException ex) { + throw new UncheckedWrapperException("this cannot happen", ex); + } - m_layout = new SingleSelect(new StringParameter("layout")); - m_layout.addOption(new Option("grid", "Grid")); - m_layout.addOption(new Option("panel", "Panel")); + m_layout = new SingleSelect(new StringParameter("layout")); + m_layout.addOption(new Option("grid", "Grid")); + m_layout.addOption(new Option("panel", "Panel")); - m_depth = new SingleSelect(new IntegerParameter("depth")); - m_depth.addOption(new Option("1", "1 Level")); - m_depth.addOption(new Option("2", "2 Levels")); + m_depth = new SingleSelect(new IntegerParameter("depth")); + m_depth.addOption(new Option("1", "1 Level")); + m_depth.addOption(new Option("2", "2 Levels")); - add(new Label("Root category:", Label.BOLD), ColumnPanel.RIGHT); - add(m_root); + add(new Label("Root category:", Label.BOLD), ColumnPanel.RIGHT); + add(m_root); - add(new Label("Layout:", Label.BOLD), ColumnPanel.RIGHT); - add(m_layout); + add(new Label("Layout:", Label.BOLD), ColumnPanel.RIGHT); + add(m_layout); - add(new Label("Depth:", Label.BOLD), ColumnPanel.RIGHT); - add(m_depth); - } + add(new Label("Depth:", Label.BOLD), ColumnPanel.RIGHT); + add(m_depth); + } - /** - * + /** + * * @param state * @param portlet * @throws FormProcessException */ public void initWidgets(PageState state, Portlet portlet) - throws FormProcessException { - super.initWidgets(state, portlet); + throws FormProcessException { + super.initWidgets(state, portlet); - if (portlet != null) { - ContentDirectoryPortlet myportlet = (ContentDirectoryPortlet) portlet; + if (portlet != null) { + ContentDirectoryPortlet myportlet = (ContentDirectoryPortlet) portlet; - m_root.setValue(state, myportlet.getRoot().getID()); - m_layout.setValue(state, myportlet.getLayout()); - m_depth.setValue(state, new Integer(myportlet.getDepth())); - } - } + m_root.setValue(state, myportlet.getRoot().getID()); + m_layout.setValue(state, myportlet.getLayout()); + m_depth.setValue(state, new Integer(myportlet.getDepth())); + } + } - /** - * + /** + * * @param state * @param portlet * @throws FormProcessException */ public void processWidgets(PageState state, Portlet portlet) - throws FormProcessException { - super.processWidgets(state, portlet); + throws FormProcessException { + super.processWidgets(state, portlet); - ContentDirectoryPortlet myportlet = (ContentDirectoryPortlet) portlet; - myportlet.setLayout((String) m_layout.getValue(state)); - myportlet.setDepth(((Integer) m_depth.getValue(state)).intValue()); + ContentDirectoryPortlet myportlet = (ContentDirectoryPortlet) portlet; + myportlet.setLayout((String) m_layout.getValue(state)); + myportlet.setDepth(((Integer) m_depth.getValue(state)).intValue()); - BigDecimal id = (BigDecimal) m_root.getValue(state); - Category root; - try { - root = (Category) DomainObjectFactory.newInstance(new OID( - Category.BASE_DATA_OBJECT_TYPE, id)); - } catch (DataObjectNotFoundException ex) { - throw new UncheckedWrapperException("cannot find category", ex); - } - myportlet.setRoot(root); - } + BigDecimal id = (BigDecimal) m_root.getValue(state); + Category root; + try { + root = (Category) DomainObjectFactory.newInstance(new OID( + Category.BASE_DATA_OBJECT_TYPE, id)); + } catch (DataObjectNotFoundException ex) { + throw new UncheckedWrapperException("cannot find category", ex); + } + myportlet.setRoot(root); + } - /** - * + /** + * * @return */ protected String getUseContext() { - return null; - } + return null; + } - /** - * + /** + * */ private class CategoryPrintListener implements PrintListener { - public void prepare(PrintEvent e) { - SingleSelect target = (SingleSelect) e.getTarget(); - Application app = Web.getWebContext().getApplication(); - Category root = Category.getRootForObject(app, getUseContext()); + public void prepare(PrintEvent e) { + SingleSelect target = (SingleSelect) e.getTarget(); + target.clearOptions(); - Map cats = CategorizationTree.getSubtreePath(root, " > "); - Iterator i = cats.keySet().iterator(); - while (i.hasNext()) { - String path = (String) i.next(); - Category cat = (Category) cats.get(path); + Application app = Web.getWebContext().getApplication(); + Category root = Category.getRootForObject(app, getUseContext()); - target.addOption(new Option(cat.getID().toString(), path)); - } - } - } + Map cats = CategorizationTree.getSubtreePath(root, " > "); + Iterator i = cats.keySet().iterator(); + while (i.hasNext()) { + String path = (String) i.next(); + Category cat = (Category) cats.get(path); + + target.addOption(new Option(cat.getID().toString(), path)); + } + } + } } diff --git a/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/portlet/FlashPortletEditor.java b/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/portlet/FlashPortletEditor.java index 7ae7c8e93..e6d5a5afd 100644 --- a/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/portlet/FlashPortletEditor.java +++ b/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/portlet/FlashPortletEditor.java @@ -15,7 +15,6 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - package com.arsdigita.portalworkspace.ui.portlet; import com.arsdigita.bebop.ColumnPanel; @@ -39,8 +38,8 @@ import com.arsdigita.portal.Portlet; /** * @author terry_permeance */ -public class FlashPortletEditor extends PortletConfigFormSection -{ +public class FlashPortletEditor extends PortletConfigFormSection { + private TextField m_backgroundColour; private TextField m_detectKey; @@ -63,25 +62,23 @@ public class FlashPortletEditor extends PortletConfigFormSection private TextField m_xiRedirectUrl; - public FlashPortletEditor(ResourceType resType, RequestLocal parentAppRL) - { + public FlashPortletEditor(ResourceType resType, RequestLocal parentAppRL) { super(resType, parentAppRL); } - public FlashPortletEditor(RequestLocal application) - { + public FlashPortletEditor(RequestLocal application) { super(application); } - protected void addWidgets() - { + protected void addWidgets() { super.addWidgets(); m_file = this.addTextField(FlashPortlet.SWF_FILE, "SWF file", 64, 2048, true); m_width = this.addTextField(FlashPortlet.WIDTH, "Width", 8, 8, true); m_height = this.addTextField(FlashPortlet.HEIGHT, "Height", 8, 8, true); m_version = this.addTextField(FlashPortlet.VERSION, "Minimum Flash version", 8, 8, true); - m_backgroundColour = this.addTextField(FlashPortlet.BACKGROUND_COLOUR, "Background colour", 7, 7, true); + m_backgroundColour = this.addTextField(FlashPortlet.BACKGROUND_COLOUR, "Background colour", + 7, 7, true); m_backgroundColour.addValidationListener(new HTMLColourCodeValidationListener()); m_quality = this.addSingleSelect(FlashPortlet.QUALITY, "Quality", false); @@ -96,18 +93,19 @@ public class FlashPortletEditor extends PortletConfigFormSection m_variables = this.addTextArea(FlashPortlet.VARIABLES, "Variables", 4, 64, false); m_detectKey = this.addTextField(FlashPortlet.DETECT_KEY, "Detect key", 32, 32, false); - m_redirectUrl = this.addTextField(FlashPortlet.REDIRECT_URL, "Redirect URL", 64, 2048, false); - m_xiRedirectUrl = this.addTextField(FlashPortlet.XI_REDIRECT_URL, "XI Redirect URL", 64, 2048, false); + m_redirectUrl = this. + addTextField(FlashPortlet.REDIRECT_URL, "Redirect URL", 64, 2048, false); + m_xiRedirectUrl = this.addTextField(FlashPortlet.XI_REDIRECT_URL, "XI Redirect URL", 64, + 2048, false); - add(new Link("What do these fields mean?", "http://blog.deconcept.com/swfobject/"), ColumnPanel.FULL_WIDTH|ColumnPanel.CENTER); + add(new Link("What do these fields mean?", "http://blog.deconcept.com/swfobject/"), + ColumnPanel.FULL_WIDTH | ColumnPanel.CENTER); } - protected void initWidgets(PageState state, Portlet portlet) throws FormProcessException - { + protected void initWidgets(PageState state, Portlet portlet) throws FormProcessException { super.initWidgets(state, portlet); - if (portlet != null) - { + if (portlet != null) { FlashPortlet flashPortlet = (FlashPortlet) portlet; // Load the form from the portlet @@ -123,12 +121,11 @@ public class FlashPortletEditor extends PortletConfigFormSection m_width.setValue(state, flashPortlet.getWidth()); m_xiRedirectUrl.setValue(state, flashPortlet.getXiRedirectUrl()); m_quality.setValue(state, flashPortlet.getQuality()); - } - else - { + } else { // Set defaults m_backgroundColour.setValue(state, "#ffffff"); - m_file.setValue(state, "http://www.adobe.com/support/flashplayer/ts/documents/tn_15507/flashplayerversion.swf"); + m_file.setValue(state, + "http://www.adobe.com/support/flashplayer/ts/documents/tn_15507/flashplayerversion.swf"); m_width.setValue(state, "100%"); m_height.setValue(state, "100%"); m_version.setValue(state, "8.0"); @@ -137,8 +134,7 @@ public class FlashPortletEditor extends PortletConfigFormSection } } - protected void processWidgets(PageState state, Portlet portlet) throws FormProcessException - { + protected void processWidgets(PageState state, Portlet portlet) throws FormProcessException { super.processWidgets(state, portlet); FlashPortlet flashPortlet = (FlashPortlet) portlet; @@ -158,91 +154,76 @@ public class FlashPortletEditor extends PortletConfigFormSection /** * Add a new text field. - * - * @param name - * the name of the parameter - * @param label - * the label to be displayed - * @param size - * the visible size of the text field - * @param maxLength - * the maximum length of text that can be entered - * @param mandatory - * denotes whether this text field requires a value + * + * @param name the name of the parameter + * @param label the label to be displayed + * @param size the visible size of the text field + * @param maxLength the maximum length of text that can be entered + * @param mandatory denotes whether this text field requires a value * @return the text field */ - private TextField addTextField(String name, String label, int size, int maxLength, boolean mandatory) - { + private TextField addTextField(String name, String label, int size, int maxLength, + boolean mandatory) { TextField field = new TextField(new StringParameter(name)); field.setSize(size); field.setMaxLength(maxLength); // Add validation - if (mandatory) - { + if (mandatory) { field.addValidationListener(new NotEmptyValidationListener()); } // Add to the form - add(mandatory ? new Label(label + ":", Label.BOLD) : new Label(label + ":"), ColumnPanel.RIGHT); + add(mandatory ? new Label(label + ":", Label.BOLD) : new Label(label + ":"), + ColumnPanel.RIGHT); add(field); return field; } /** * Add a new text area. - * - * @param name - * the name of the parameter - * @param label - * the label to be displayed - * @param rows - * the visible rows - * @param cols - * the visible cols - * @param mandatory - * denotes whether this text field requires a value + * + * @param name the name of the parameter + * @param label the label to be displayed + * @param rows the visible rows + * @param cols the visible cols + * @param mandatory denotes whether this text field requires a value * @return the text area */ - private TextArea addTextArea(String name, String label, int rows, int cols, boolean mandatory) - { + private TextArea addTextArea(String name, String label, int rows, int cols, boolean mandatory) { TextArea field = new TextArea(new StringParameter(name), rows, cols, TextArea.SOFT); // Add validation - if (mandatory) - { + if (mandatory) { field.addValidationListener(new NotEmptyValidationListener()); } // Add to the form - add(mandatory ? new Label(label + ":", Label.BOLD) : new Label(label + ":"), ColumnPanel.RIGHT); + add(mandatory ? new Label(label + ":", Label.BOLD) : new Label(label + ":"), + ColumnPanel.RIGHT); add(field); return field; } /** * Add a new single select. - * - * @param name - * the name of the parameter - * @param label - * the label to be displayed - * @param mandatory - * denotes whether this text field requires a value + * + * @param name the name of the parameter + * @param label the label to be displayed + * @param mandatory denotes whether this text field requires a value * @return the text area */ - private SingleSelect addSingleSelect(String name, String label, boolean mandatory) - { + private SingleSelect addSingleSelect(String name, String label, boolean mandatory) { SingleSelect field = new SingleSelect(new StringParameter(name)); // Add validation - if (mandatory) - { + if (mandatory) { field.addValidationListener(new NotEmptyValidationListener()); } // Add to the form - add(mandatory ? new Label(label + ":", Label.BOLD) : new Label(label + ":"), ColumnPanel.RIGHT); + add(mandatory ? new Label(label + ":", Label.BOLD) : new Label(label + ":"), + ColumnPanel.RIGHT); add(field); return field; } diff --git a/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/portlet/RSSFeedPortletBrowserForm.java b/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/portlet/RSSFeedPortletBrowserForm.java index 2f4fc970c..2065320bf 100755 --- a/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/portlet/RSSFeedPortletBrowserForm.java +++ b/ccm-portalworkspace/src/com/arsdigita/portalworkspace/ui/portlet/RSSFeedPortletBrowserForm.java @@ -12,7 +12,6 @@ * rights and limitations under the License. * */ - package com.arsdigita.portalworkspace.ui.portlet; import java.util.Iterator; @@ -39,140 +38,142 @@ import com.arsdigita.xml.Element; public class RSSFeedPortletBrowserForm extends Form { - private BoxPanel m_hosts_pnl; + private BoxPanel m_hosts_pnl; - private BoxPanel m_feeds_pnl; + private BoxPanel m_feeds_pnl; - private SingleSelect m_hosts; + private SingleSelect m_hosts; - private SingleSelect m_feeds; + private SingleSelect m_feeds; - private Label m_no_feeds; + private Label m_no_feeds; - private Submit m_display; + private Submit m_display; - private Submit m_cancel; + private Submit m_cancel; - private Submit m_select; + private Submit m_select; - private Submit m_back; + private Submit m_back; - private RequestLocal m_feed = new RequestLocal(); + private RequestLocal m_feed = new RequestLocal(); - public RSSFeedPortletBrowserForm() { - super("Browser"); + public RSSFeedPortletBrowserForm() { + super("Browser"); - m_hosts_pnl = new BoxPanel(BoxPanel.HORIZONTAL); - m_feeds_pnl = new BoxPanel(BoxPanel.HORIZONTAL); + m_hosts_pnl = new BoxPanel(BoxPanel.HORIZONTAL); + m_feeds_pnl = new BoxPanel(BoxPanel.HORIZONTAL); - add(m_hosts_pnl); - add(m_feeds_pnl); + add(m_hosts_pnl); + add(m_feeds_pnl); - Label hosts_lbl = new Label("Hosts:"); - Label feeds_lbl = new Label("Feeds:"); - m_no_feeds = new Label("none available"); + Label hosts_lbl = new Label("Hosts:"); + Label feeds_lbl = new Label("Feeds:"); + m_no_feeds = new Label("none available"); - m_hosts_pnl.add(hosts_lbl); - m_feeds_pnl.add(feeds_lbl); - m_feeds_pnl.add(m_no_feeds); + m_hosts_pnl.add(hosts_lbl); + m_feeds_pnl.add(feeds_lbl); + m_feeds_pnl.add(m_no_feeds); - m_hosts = new SingleSelect(new StringParameter("host")); - m_feeds = new SingleSelect(new StringParameter("feed")); + m_hosts = new SingleSelect(new StringParameter("host")); + m_feeds = new SingleSelect(new StringParameter("feed")); - m_hosts_pnl.add(m_hosts); - m_feeds_pnl.add(m_feeds); + m_hosts_pnl.add(m_hosts); + m_feeds_pnl.add(m_feeds); - m_back = new Submit("back", "Back"); - m_cancel = new Submit("cancel", "Back"); - m_display = new Submit("display", "Display feeds"); - m_select = new Submit("select", "Select feed"); + m_back = new Submit("back", "Back"); + m_cancel = new Submit("cancel", "Back"); + m_display = new Submit("display", "Display feeds"); + m_select = new Submit("select", "Select feed"); - m_feeds_pnl.add(m_back); - m_feeds_pnl.add(m_select); - m_hosts_pnl.add(m_cancel); - m_hosts_pnl.add(m_display); + m_feeds_pnl.add(m_back); + m_feeds_pnl.add(m_select); + m_hosts_pnl.add(m_cancel); + m_hosts_pnl.add(m_display); - addProcessListener(new FormProcessListener() { - public void process(FormSectionEvent e) throws FormProcessException { - PageState state = e.getPageState(); + addProcessListener(new FormProcessListener() { + public void process(FormSectionEvent e) throws FormProcessException { + PageState state = e.getPageState(); - if (m_select.isSelected(state)) { - fireCompletionEvent(state); - } else if (m_display.isSelected(state)) { - setDisplay(state, false); - } else if (m_back.isSelected(state)) { - setDisplay(state, true); - } else if (m_cancel.isSelected(state)) { - fireCompletionEvent(state); - } - } - }); + if (m_select.isSelected(state)) { + fireCompletionEvent(state); + } else if (m_display.isSelected(state)) { + setDisplay(state, false); + } else if (m_back.isSelected(state)) { + setDisplay(state, true); + } else if (m_cancel.isSelected(state)) { + fireCompletionEvent(state); + } + } + }); - try { - m_hosts.addPrintListener(new PrintListener() { - public void prepare(PrintEvent e) { - SingleSelect group = (SingleSelect) e.getTarget(); + try { + m_hosts.addPrintListener(new PrintListener() { + public void prepare(PrintEvent e) { + SingleSelect group = (SingleSelect) e.getTarget(); + group.clearOptions(); - Iterator hosts = RSSFeedPortletHelper.getACSJHosts(); - while (hosts.hasNext()) { - String host[] = (String[]) hosts.next(); + Iterator hosts = RSSFeedPortletHelper.getACSJHosts(); + while (hosts.hasNext()) { + String host[] = (String[]) hosts.next(); - group.addOption(new Option(host[0], host[1])); - } - } - }); - } catch (TooManyListenersException ex) { - throw new UncheckedWrapperException("This can never happen", ex); - } + group.addOption(new Option(host[0], host[1])); + } + } + }); + } catch (TooManyListenersException ex) { + throw new UncheckedWrapperException("This can never happen", ex); + } - try { - m_feeds.addPrintListener(new PrintListener() { - public void prepare(PrintEvent e) { - SingleSelect group = (SingleSelect) e.getTarget(); + try { + m_feeds.addPrintListener(new PrintListener() { + public void prepare(PrintEvent e) { + SingleSelect group = (SingleSelect) e.getTarget(); + group.clearOptions(); - Iterator feeds = (Iterator) m_feed.get(e.getPageState()); - while (feeds != null && feeds.hasNext()) { - String feed[] = (String[]) feeds.next(); + Iterator feeds = (Iterator) m_feed.get(e.getPageState()); + while (feeds != null && feeds.hasNext()) { + String feed[] = (String[]) feeds.next(); - group.addOption(new Option(feed[0], feed[1])); - } - } - }); - } catch (TooManyListenersException ex) { - throw new UncheckedWrapperException("This can never happen", ex); - } - } + group.addOption(new Option(feed[0], feed[1])); + } + } + }); + } catch (TooManyListenersException ex) { + throw new UncheckedWrapperException("This can never happen", ex); + } + } - public String getFeedURL(PageState state) { - return (String) m_feeds.getValue(state); - } + public String getFeedURL(PageState state) { + return (String) m_feeds.getValue(state); + } - public void register(Page p) { - super.register(p); + public void register(Page p) { + super.register(p); - p.setVisibleDefault(m_hosts_pnl, true); - p.setVisibleDefault(m_feeds_pnl, false); - } + p.setVisibleDefault(m_hosts_pnl, true); + p.setVisibleDefault(m_feeds_pnl, false); + } - private void setDisplay(PageState state, boolean initial) { - m_hosts_pnl.setVisible(state, initial); - m_feeds_pnl.setVisible(state, !initial); - } + private void setDisplay(PageState state, boolean initial) { + m_hosts_pnl.setVisible(state, initial); + m_feeds_pnl.setVisible(state, !initial); + } - public void generateXML(PageState state, Element parent) { - if (m_hosts.getValue(state) == null) { - m_feed.set(state, null); - setDisplay(state, true); - } else { - String host = (String) m_hosts.getValue(state); - Iterator feed = RSSFeedPortletHelper.getACSJFeeds(host); - m_feed.set(state, feed); + public void generateXML(PageState state, Element parent) { + if (m_hosts.getValue(state) == null) { + m_feed.set(state, null); + setDisplay(state, true); + } else { + String host = (String) m_hosts.getValue(state); + Iterator feed = RSSFeedPortletHelper.getACSJFeeds(host); + m_feed.set(state, feed); - m_no_feeds.setVisible(state, !feed.hasNext()); - m_feeds.setVisible(state, feed.hasNext()); - m_select.setVisible(state, feed.hasNext()); - } + m_no_feeds.setVisible(state, !feed.hasNext()); + m_feeds.setVisible(state, feed.hasNext()); + m_select.setVisible(state, feed.hasNext()); + } - super.generateXML(state, parent); - } + super.generateXML(state, parent); + } } diff --git a/ccm-simplesurvey/src/com/arsdigita/simplesurvey/ui/admin/AnswerValuesPanel.java b/ccm-simplesurvey/src/com/arsdigita/simplesurvey/ui/admin/AnswerValuesPanel.java index dd415769f..a811dafca 100755 --- a/ccm-simplesurvey/src/com/arsdigita/simplesurvey/ui/admin/AnswerValuesPanel.java +++ b/ccm-simplesurvey/src/com/arsdigita/simplesurvey/ui/admin/AnswerValuesPanel.java @@ -17,7 +17,8 @@ * */ package com.arsdigita.simplesurvey.ui.admin; -import com.arsdigita.simplesurvey.util.GlobalizationUtil ; + +import com.arsdigita.simplesurvey.util.GlobalizationUtil; import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.bebop.event.FormProcessListener; @@ -30,7 +31,7 @@ import com.arsdigita.bebop.event.RequestEvent; import com.arsdigita.bebop.event.ActionListener; import com.arsdigita.bebop.event.PrintEvent; import com.arsdigita.bebop.event.ActionEvent; -import com.arsdigita.bebop.FormData; +import com.arsdigita.bebop.FormData; import com.arsdigita.bebop.Form; import com.arsdigita.bebop.Link; import com.arsdigita.bebop.Page; @@ -62,11 +63,10 @@ import com.arsdigita.simplesurvey.ui.SurveySelectionModel; import java.math.BigDecimal; -public class AnswerValuesPanel extends SimpleContainer { +public class AnswerValuesPanel extends SimpleContainer { // Displays a list of the multiple choice answers grouped by question // Each of the answers contains a link that leads to a drop-down value selection widget - private SurveySelectionModel m_survey; private static final String QUESTION_TEXT = "questionText"; private static final String ANSWER_TEXT = "answerText"; @@ -85,291 +85,316 @@ public class AnswerValuesPanel extends SimpleContainer { private ActionLink m_complete; private Link m_back; - private static org.apache.log4j.Logger s_log = - org.apache.log4j.Logger.getLogger(AnswerValuesPanel.class.getName()); + private static org.apache.log4j.Logger s_log + = org.apache.log4j.Logger.getLogger( + AnswerValuesPanel.class.getName()); private DataTable m_answerTable; public AnswerValuesPanel(SurveySelectionModel survey) { - super(); - m_survey = survey; - - m_answerText = new RequestLocal(); - m_questionText = new RequestLocal(); - m_answerValue = new RequestLocal(); - - m_complete = new ActionLink( (String) GlobalizationUtil.globalize("simplesurvey.ui.admin.back_to_question_list").localize()); - m_complete.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - PageState ps = e.getPageState(); - m_answerTable.setVisible(ps, true); - m_answerValuesForm.setVisible(ps, false); - m_complete.setVisible(ps,false); - m_back.setVisible(ps, true); - } - }); - m_back = new Link(new Label(GlobalizationUtil.globalize("simplesurvey.ui.admin.back_to_survey_list")), "../admin"); + super(); + m_survey = survey; - add(m_complete); - add(m_back); - setupAnswerTable(); - setupAnswerValuesForm(); + m_answerText = new RequestLocal(); + m_questionText = new RequestLocal(); + m_answerValue = new RequestLocal(); + + m_complete = new ActionLink((String) GlobalizationUtil.globalize( + "simplesurvey.ui.admin.back_to_question_list").localize()); + m_complete.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + PageState ps = e.getPageState(); + m_answerTable.setVisible(ps, true); + m_answerValuesForm.setVisible(ps, false); + m_complete.setVisible(ps, false); + m_back.setVisible(ps, true); + } + }); + m_back = new Link(new Label(GlobalizationUtil.globalize( + "simplesurvey.ui.admin.back_to_survey_list")), "../admin"); + + add(m_complete); + add(m_back); + setupAnswerTable(); + setupAnswerValuesForm(); } - public void register (Page p) { - p.setVisibleDefault(m_answerValuesForm,false); - m_optionID = new BigDecimalParameter("option_id"); - m_surveyID = new BigDecimalParameter("survey_id"); - p.addGlobalStateParam(m_optionID); - p.addGlobalStateParam(m_surveyID); - p.addRequestListener( new RequestListener() { - public void pageRequested(RequestEvent e) { - PageState ps = e.getPageState(); - - if ( ps.getValue(m_optionID) == null || - m_answerValuesForm.getFormData(ps).isSubmission()) { - m_answerTable.setVisible(ps, true); - m_answerValuesForm.setVisible(ps, false); - m_complete.setVisible(ps,false); - m_back.setVisible(ps, true); - } /*else { - m_answerTable.setVisible(ps, false); - m_answerValuesForm.setVisible(ps, true); + + public void register(Page p) { + p.setVisibleDefault(m_answerValuesForm, false); + m_optionID = new BigDecimalParameter("option_id"); + m_surveyID = new BigDecimalParameter("survey_id"); + p.addGlobalStateParam(m_optionID); + p.addGlobalStateParam(m_surveyID); + p.addRequestListener(new RequestListener() { + public void pageRequested(RequestEvent e) { + PageState ps = e.getPageState(); + + if (ps.getValue(m_optionID) == null || m_answerValuesForm.getFormData(ps). + isSubmission()) { + m_answerTable.setVisible(ps, true); + m_answerValuesForm.setVisible(ps, false); + m_complete.setVisible(ps, false); + m_back.setVisible(ps, true); + } /*else { + m_answerTable.setVisible(ps, false); + m_answerValuesForm.setVisible(ps, true); - BigDecimal optionID = (BigDecimal) ps.getValue(m_optionID); - final String query = "com.arsdigita.simplesurvey.getAnswerOption"; - DataQuery dq = SessionManager.getSession().retrieveQuery(query); - dq.setParameter("optionID", optionID); + BigDecimal optionID = (BigDecimal) ps.getValue(m_optionID); + final String query = "com.arsdigita.simplesurvey.getAnswerOption"; + DataQuery dq = SessionManager.getSession().retrieveQuery(query); + dq.setParameter("optionID", optionID); - if ( dq.next()) { - m_questionText.set(ps, (String) dq.get(QUESTION_TEXT)); - m_answerText.set(ps, (String) dq.get(ANSWER_TEXT)); - m_answerValue.set(ps, (BigDecimal) dq.get(ANSWER_VALUE)); - m_select.setValue(ps,getAnswerValue(ps)); - } - dq.close(); - }*/ - } - }); - } - - private String getQuestionText(PageState ps) { - String s = (String) m_questionText.get(ps); - return s.substring(6, s.length()); - } - private String getAnswerText(PageState ps) { - String s = (String) m_answerText.get(ps); - return s; - } - private BigDecimal getAnswerValue(PageState ps) { - BigDecimal bi = (BigDecimal) m_answerValue.get(ps); - return bi; + if ( dq.next()) { + m_questionText.set(ps, (String) dq.get(QUESTION_TEXT)); + m_answerText.set(ps, (String) dq.get(ANSWER_TEXT)); + m_answerValue.set(ps, (BigDecimal) dq.get(ANSWER_VALUE)); + m_select.setValue(ps,getAnswerValue(ps)); + } + dq.close(); + }*/ + + } + }); + } + + private String getQuestionText(PageState ps) { + String s = (String) m_questionText.get(ps); + return s.substring(6, s.length()); + } + + private String getAnswerText(PageState ps) { + String s = (String) m_answerText.get(ps); + return s; + } + + private BigDecimal getAnswerValue(PageState ps) { + BigDecimal bi = (BigDecimal) m_answerValue.get(ps); + return bi; } - private void setupAnswerTable() { - // This is the table that holds the list of all answer options in the survey - m_answerTable = new DataTable(new AnswerListingBuilder()); - - TableColumn c1 = m_answerTable.addColumn("simplesurvey.ui.admin.question", QUESTION_TEXT, - false, new QuestionTextRenderer()); - TableColumn c2 = m_answerTable.addColumn("simplesurvey.ui.admin.answer", ANSWER_TEXT); - TableColumn c3 = m_answerTable.addColumn("simplesurvey.ui.admin.current_value", ANSWER_VALUE); - c1.setHeaderRenderer(new GlobalizedHeaderRenderer()); - c2.setHeaderRenderer(new GlobalizedHeaderRenderer()); - c3.setHeaderRenderer(new GlobalizedHeaderRenderer()); - + // This is the table that holds the list of all answer options in the survey + m_answerTable = new DataTable(new AnswerListingBuilder()); + + TableColumn c1 = m_answerTable.addColumn("simplesurvey.ui.admin.question", QUESTION_TEXT, + false, new QuestionTextRenderer()); + TableColumn c2 = m_answerTable.addColumn("simplesurvey.ui.admin.answer", ANSWER_TEXT); + TableColumn c3 = m_answerTable. + addColumn("simplesurvey.ui.admin.current_value", ANSWER_VALUE); + c1.setHeaderRenderer(new GlobalizedHeaderRenderer()); + c2.setHeaderRenderer(new GlobalizedHeaderRenderer()); + c3.setHeaderRenderer(new GlobalizedHeaderRenderer()); // Add a single select box widget to each possible answer - // The admin can select a point value for each answer - TableColumn editValueColumn = new TableColumn(); - editValueColumn.setCellRenderer(new EditLinkRenderer()); - m_answerTable.getColumnModel().add(editValueColumn); - m_answerTable.addTableActionListener(new AnswerValueActionListener()); - add(m_answerTable); + // The admin can select a point value for each answer + TableColumn editValueColumn = new TableColumn(); + editValueColumn.setCellRenderer(new EditLinkRenderer()); + m_answerTable.getColumnModel().add(editValueColumn); + m_answerTable.addTableActionListener(new AnswerValueActionListener()); + add(m_answerTable); } - private BigDecimal getSurveyID(PageState ps) { - BigDecimal surveyID = null; - if ( ps.getValue(m_surveyID) == null ) { - Survey s = m_survey.getSelectedSurvey(ps); - surveyID = s.getID(); - } else { - surveyID = (BigDecimal) ps.getValue(m_surveyID); - } - return surveyID; - } + + private BigDecimal getSurveyID(PageState ps) { + BigDecimal surveyID = null; + if (ps.getValue(m_surveyID) == null) { + Survey s = m_survey.getSelectedSurvey(ps); + surveyID = s.getID(); + } else { + surveyID = (BigDecimal) ps.getValue(m_surveyID); + } + return surveyID; + } private void setupAnswerValuesForm() { - m_answerValuesForm = new AnswerValuesForm(); - add(m_answerValuesForm); - } - private class AnswerValueActionListener extends TableActionAdapter{ - - public void cellSelected(TableActionEvent e) { - PageState ps = e.getPageState(); - ps.setValue(m_optionID, new BigDecimal(e.getRowKey().toString())); - m_answerTable.setVisible(ps, false); - m_back.setVisible(ps, false); - m_complete.setVisible(ps, true); - m_answerValuesForm.setVisible(ps, true); - - BigDecimal optionID = (BigDecimal) ps.getValue(m_optionID); - final String query = "com.arsdigita.simplesurvey.getAnswerOption"; - DataQuery dq = SessionManager.getSession().retrieveQuery(query); - dq.setParameter("optionID", optionID); - - if ( dq.next()) { - m_questionText.set(ps, (String) dq.get(QUESTION_TEXT)); - m_answerText.set(ps, (String) dq.get(ANSWER_TEXT)); - m_answerValue.set(ps, (BigDecimal) dq.get(ANSWER_VALUE)); - m_select.setValue(ps,getAnswerValue(ps)); - } - dq.close(); + m_answerValuesForm = new AnswerValuesForm(); + add(m_answerValuesForm); + } - } + private class AnswerValueActionListener extends TableActionAdapter { + + public void cellSelected(TableActionEvent e) { + PageState ps = e.getPageState(); + ps.setValue(m_optionID, new BigDecimal(e.getRowKey().toString())); + m_answerTable.setVisible(ps, false); + m_back.setVisible(ps, false); + m_complete.setVisible(ps, true); + m_answerValuesForm.setVisible(ps, true); + + BigDecimal optionID = (BigDecimal) ps.getValue(m_optionID); + final String query = "com.arsdigita.simplesurvey.getAnswerOption"; + DataQuery dq = SessionManager.getSession().retrieveQuery(query); + dq.setParameter("optionID", optionID); + + if (dq.next()) { + m_questionText.set(ps, (String) dq.get(QUESTION_TEXT)); + m_answerText.set(ps, (String) dq.get(ANSWER_TEXT)); + m_answerValue.set(ps, (BigDecimal) dq.get(ANSWER_VALUE)); + m_select.setValue(ps, getAnswerValue(ps)); + } + dq.close(); + + } } + private class AnswerValuesForm extends Form { - - private AnswerValuesForm() { - super("answerValuesForm"); - Label questionText = new Label(new PrintListener() { - public void prepare(PrintEvent e) { - PageState ps = e.getPageState(); - Label target = (Label) e.getTarget(); - target.setLabel(getQuestionText(ps)); - } - }); - - Label answerText = new Label(new PrintListener() { - public void prepare(PrintEvent e) { - PageState ps = e.getPageState(); - Label target = (Label) e.getTarget(); - target.setLabel(getAnswerText(ps)); - } - }); - add(questionText); - add(answerText); - m_select = new SingleSelect(ANSWER_VALUE); - m_select.addOption(new Option("0", new Label("0"))); - m_select.addOption(new Option("1", new Label("1"))); - m_select.addOption(new Option("2", new Label("2"))); - m_select.addOption(new Option("3", new Label("3"))); - m_select.addOption(new Option("4", new Label("4"))); - m_select.addOption(new Option("5", new Label("5"))); - m_select.addOption(new Option("6", new Label("6"))); - m_select.addOption(new Option("7", new Label("7"))); - m_select.addOption(new Option("8", new Label("8"))); - m_select.addOption(new Option("9", new Label("9"))); - m_select.addOption(new Option("10", new Label("10"))); - add(m_select); - add(new Submit(GlobalizationUtil.globalize("simplesurvey.ui.admin.submit"))); - //add(new Submit(GlobalizationUtil.globalize("simplesurvey.ui.admin.done_editing"))); - addProcessListener(new AnswerValuesProcessListener()); - addInitListener(new AnswerValuesInitListener()); - } + private AnswerValuesForm() { + + super("answerValuesForm"); + Label questionText = new Label(new PrintListener() { + public void prepare(PrintEvent e) { + PageState ps = e.getPageState(); + Label target = (Label) e.getTarget(); + target.setLabel(getQuestionText(ps)); + } + }); + + Label answerText = new Label(new PrintListener() { + public void prepare(PrintEvent e) { + PageState ps = e.getPageState(); + Label target = (Label) e.getTarget(); + target.setLabel(getAnswerText(ps)); + } + }); + add(questionText); + add(answerText); + m_select = new SingleSelect(ANSWER_VALUE); + m_select.addOption(new Option("0", new Label("0"))); + m_select.addOption(new Option("1", new Label("1"))); + m_select.addOption(new Option("2", new Label("2"))); + m_select.addOption(new Option("3", new Label("3"))); + m_select.addOption(new Option("4", new Label("4"))); + m_select.addOption(new Option("5", new Label("5"))); + m_select.addOption(new Option("6", new Label("6"))); + m_select.addOption(new Option("7", new Label("7"))); + m_select.addOption(new Option("8", new Label("8"))); + m_select.addOption(new Option("9", new Label("9"))); + m_select.addOption(new Option("10", new Label("10"))); + add(m_select); + add(new Submit(GlobalizationUtil.globalize("simplesurvey.ui.admin.submit"))); + //add(new Submit(GlobalizationUtil.globalize("simplesurvey.ui.admin.done_editing"))); + addProcessListener(new AnswerValuesProcessListener()); + addInitListener(new AnswerValuesInitListener()); + } } + private class AnswerValuesProcessListener implements FormProcessListener { - public void process(FormSectionEvent e) throws FormProcessException { - PageState ps = e.getPageState(); - FormData fd = e.getFormData(); - BigDecimal optionID = (BigDecimal) ps.getValue(m_optionID); - BigDecimal answerValue = new BigDecimal((String) fd.get(ANSWER_VALUE)); - - DataOperation dao = SessionManager.getSession().retrieveDataOperation("com.arsdigita.simplesurvey.updateAnswerValue"); - dao.setParameter("optionID", optionID); - dao.setParameter("answerValue", answerValue); - dao.execute(); - ps.setValue(m_optionID, null); - } + + public void process(FormSectionEvent e) throws FormProcessException { + PageState ps = e.getPageState(); + FormData fd = e.getFormData(); + BigDecimal optionID = (BigDecimal) ps.getValue(m_optionID); + BigDecimal answerValue = new BigDecimal((String) fd.get(ANSWER_VALUE)); + + DataOperation dao = SessionManager.getSession().retrieveDataOperation( + "com.arsdigita.simplesurvey.updateAnswerValue"); + dao.setParameter("optionID", optionID); + dao.setParameter("answerValue", answerValue); + dao.execute(); + ps.setValue(m_optionID, null); + } } + private class AnswerValuesInitListener implements FormInitListener { - public void init(FormSectionEvent e) throws FormProcessException { - PageState ps = e.getPageState(); - s_log.warn("Setting value of select to " + getAnswerValue(ps)); - m_select.setValue(ps, getAnswerValue(ps)); - } + + public void init(FormSectionEvent e) throws FormProcessException { + PageState ps = e.getPageState(); + s_log.warn("Setting value of select to " + getAnswerValue(ps)); + m_select.setValue(ps, getAnswerValue(ps)); + } } + private class GlobalizedHeaderRenderer implements TableCellRenderer { - public Component getComponent(Table table, PageState state, Object value, - boolean isSelected, Object key, int row, - int column) { - - Label label = new Label(GlobalizationUtil.globalize((String) value)); + + public Component getComponent(Table table, PageState state, Object value, + boolean isSelected, Object key, int row, + int column) { + + Label label = new Label(GlobalizationUtil.globalize((String) value)); // Removed. Is is the responsibility of the theme to position Labels - // appropriately. We have to check for side effects in older themes! - // label.setVerticalAlignment(CENTER); - return label; - } + // appropriately. We have to check for side effects in older themes! + // label.setVerticalAlignment(CENTER); + return label; + } } + private class QuestionTextRenderer implements TableCellRenderer { - @Override - public Component getComponent(Table table, PageState state, Object value, - boolean isSelected, Object key, int row, - int column) { - - if ( ! isLocked() && table != null && table.isLocked() ) { - lock(); - } - if ( value == null ) { - return new Label(""); - } - String question = (String) value; - // Cut off the 6 chars "label=" stored in the db - return new Label(question.substring(6,question.length())); - } + + @Override + public Component getComponent(Table table, PageState state, Object value, + boolean isSelected, Object key, int row, + int column) { + + if (!isLocked() && table != null && table.isLocked()) { + lock(); + } + if (value == null) { + return new Label(""); + } + String question = (String) value; + // Cut off the 6 chars "label=" stored in the db + return new Label(question.substring(6, question.length())); + } } + private class EditLinkRenderer implements TableCellRenderer { - @Override - public Component getComponent(Table table, PageState ps, Object value, - boolean isSelected, Object key, int row, - int column) { - - if ( ! isLocked() && table != null && table.isLocked() ) { - lock(); - } - if ( value == null ) { - return new Label(""); - } - /*Link l = new Link(new Label(GlobalizationUtil.globalize("simplesurvey.ui.admin.edit_value")),"../admin"); - BigDecimal surveyID = getSurveyID(ps); + @Override + public Component getComponent(Table table, PageState ps, Object value, + boolean isSelected, Object key, int row, + int column) { + + if (!isLocked() && table != null && table.isLocked()) { + lock(); + } + if (value == null) { + return new Label(""); + } + /*Link l = new Link(new Label(GlobalizationUtil.globalize("simplesurvey.ui.admin.edit_value")),"../admin"); + BigDecimal surveyID = getSurveyID(ps); - //Sometimes we can get the surveyID from the global parameter, sometimes from the selection - l.setVar("survey_id", surveyID.toString()); - l.setVar("option_id", ((BigDecimal) key).toString()); + //Sometimes we can get the surveyID from the global parameter, sometimes from the selection + l.setVar("survey_id", surveyID.toString()); + l.setVar("option_id", ((BigDecimal) key).toString()); - return l; */ - ControlLink cl = new ControlLink(new Label (GlobalizationUtil.globalize("simplesurvey.ui.admin.edit_value"))); - return cl; - } + return l; */ + ControlLink cl = new ControlLink(new Label(GlobalizationUtil.globalize( + "simplesurvey.ui.admin.edit_value"))); + return cl; + } } - + private class AnswerListingBuilder implements DataQueryBuilder { - private final static String KEY_COLUMN = "optionID"; - public boolean m_locked; - public AnswerListingBuilder() { - super(); - } - public DataQuery makeDataQuery(DataTable t, PageState ps) { - final String query = "com.arsdigita.simplesurvey.getAnswerOptions"; - DataQuery dq = SessionManager.getSession().retrieveQuery(query); - - dq.setParameter("surveyID", getSurveyID(ps)); - return dq; - } - - public String getKeyColumn() { - return KEY_COLUMN; - } + + private final static String KEY_COLUMN = "optionID"; + public boolean m_locked; + + public AnswerListingBuilder() { + super(); + } + + public DataQuery makeDataQuery(DataTable t, PageState ps) { + final String query = "com.arsdigita.simplesurvey.getAnswerOptions"; + DataQuery dq = SessionManager.getSession().retrieveQuery(query); + + dq.setParameter("surveyID", getSurveyID(ps)); + return dq; + } + + public String getKeyColumn() { + return KEY_COLUMN; + } + public void lock() { - m_locked = true; - } - public boolean isLocked() { - return m_locked; - } + m_locked = true; + } + + public boolean isLocked() { + return m_locked; + } } diff --git a/ccm-subsite/src/com/arsdigita/subsite/ui/SiteForm.java b/ccm-subsite/src/com/arsdigita/subsite/ui/SiteForm.java index 9f378d989..bf8f37c53 100755 --- a/ccm-subsite/src/com/arsdigita/subsite/ui/SiteForm.java +++ b/ccm-subsite/src/com/arsdigita/subsite/ui/SiteForm.java @@ -489,6 +489,8 @@ public class SiteForm extends Form { @Override public void prepare(PrintEvent e) { final SingleSelect target = (SingleSelect) e.getTarget(); + target.clearOptions(); + ApplicationCollection customApps; target.addOption(new Option(DEFAULT_APP, @@ -525,6 +527,7 @@ public class SiteForm extends Form { @Override public void prepare(PrintEvent e) { SingleSelect target = (SingleSelect) e.getTarget(); + target.clearOptions(); PageState state = e.getPageState(); Map themes = Subsite.getConfig().getThemes(); Set entrySet = themes.entrySet(); diff --git a/ccm-themedirector/src/com/arsdigita/themedirector/ui/ThemeControlPanel.java b/ccm-themedirector/src/com/arsdigita/themedirector/ui/ThemeControlPanel.java index 90d5c56cc..7dc378f51 100755 --- a/ccm-themedirector/src/com/arsdigita/themedirector/ui/ThemeControlPanel.java +++ b/ccm-themedirector/src/com/arsdigita/themedirector/ui/ThemeControlPanel.java @@ -142,6 +142,8 @@ public class ThemeControlPanel extends SelectionPanel @Override public void prepare(final PrintEvent event) { final SingleSelect target = (SingleSelect) event.getTarget(); + target.clearOptions(); + final DataCollection options = SessionManager .getSession() .retrieve(Theme.BASE_DATA_OBJECT_TYPE); diff --git a/ccm-webpage/src/com/arsdigita/cms/webpage/ui/WebpageCMSEditorPage.java b/ccm-webpage/src/com/arsdigita/cms/webpage/ui/WebpageCMSEditorPage.java index 490599680..7df540e0a 100755 --- a/ccm-webpage/src/com/arsdigita/cms/webpage/ui/WebpageCMSEditorPage.java +++ b/ccm-webpage/src/com/arsdigita/cms/webpage/ui/WebpageCMSEditorPage.java @@ -70,534 +70,523 @@ import com.arsdigita.xml.Document; * @author Peter Kopunec */ public class WebpageCMSEditorPage extends CMSPage implements WebpageConstants { - - private static final Logger s_log = Logger.getLogger(WebpageCMSEditorPage.class); - - private WebpageCMSEditorForm m_createForm; - private WebpageCMSEditorForm m_editForm; - - public WebpageCMSEditorPage() { - super("Story Editor", new SimpleContainer()); - - SimpleContainer header = new SimpleContainer(HEADER_ELEMENT, XML_NS); - SimpleContainer body = new SimpleContainer(BODY_ELEMENT, XML_NS); - SimpleContainer footer = new SimpleContainer(FOOTER_ELEMENT, XML_NS); - - m_createForm = new WebpageCMSEditorForm(true); - m_editForm = new WebpageCMSEditorForm(false); - body.add(m_createForm); - body.add(m_editForm); - - add(header); - add(body); - add(footer); - } - - protected void buildPage() { - super.buildPage(); - setClassAttr("webpage"); - } - - public void generateXML(PageState state, Document parent) { - BigDecimal id = null; - try { - HttpServletRequest request = state.getRequest(); - id = new BigDecimal(request.getParameter(Webpage.ID)); - } - catch (Exception ex) { - } - m_createForm.setVisible(state, id == null); - m_editForm.setVisible(state, id != null); - super.generateXML(state, parent); - } - - public class WebpageCMSEditorForm extends Form implements FormInitListener, FormValidationListener, FormProcessListener { - - Hidden m_itemID; - TextField m_author, m_title; - MultipleSelect m_categories; - CMSDHTMLEditor m_body; - CMSDHTMLEditor m_desc; - Submit m_save; - Date m_startDate; - TextField m_startHour; - TextField m_startMinute; - SingleSelect m_startAmpm; - Date m_endDate; - TextField m_endHour; - TextField m_endMinute; - SingleSelect m_endAmpm; - boolean m_displayDates; - - public WebpageCMSEditorForm(boolean displayDates) { - super("WebpageCMSEditorForm"); - - m_displayDates = displayDates; - - m_title = new TextField(new StringParameter("title")); - m_title.setSize(35); - add(new Label("Title:"), RIGHT | TOP); - add(m_title); - m_author = new TextField(Webpage.AUTHOR); - add(new Label(new AuthorLabelPrinter()), RIGHT | TOP); - add(m_author); + private static final Logger s_log = Logger.getLogger(WebpageCMSEditorPage.class); - m_desc = new CMSDHTMLEditor("desc");//CMSDHTMLEditor.m_configWithoutToolbar - m_desc.setRows(10); - m_desc.setCols(80); + private WebpageCMSEditorForm m_createForm; + private WebpageCMSEditorForm m_editForm; - add(new Label("Lead:", false), RIGHT | TOP);//
(this field is currently not displayed on the website) - add(m_desc); - - add(new Label("Location:"), RIGHT | TOP); - m_categories = new MultipleSelect("categories"); - m_categories.setSize(5); - add(m_categories); + public WebpageCMSEditorPage() { + super("Story Editor", new SimpleContainer()); - add(new Label("Body:"), RIGHT | TOP); - StringParameter bodyParam = new StringParameter(Webpage.BODY); - m_body = new CMSDHTMLEditor(bodyParam); - m_body.setCols(80); - m_body.setRows(20); - add(m_body); - - if (displayDates) { - add(new Label("Start date:"), RIGHT | TOP); - m_startDate = new Date(new DateParameter("start_date") { - protected final Calendar getCalendar(final HttpServletRequest sreq) { - final Calendar cal = super.getCalendar(sreq); - cal.setLenient(false); - return cal; - } - }); - add(m_startDate); - - add(new Label("Start time:"), RIGHT | TOP); - BoxPanel startTime = new BoxPanel(BoxPanel.HORIZONTAL); - m_startHour = new TextField(new IntegerParameter("start_hour")); - m_startHour.setSize(3); - startTime.add(m_startHour); - m_startMinute = new TextField(new IntegerParameter("start_minute")); - m_startMinute.setSize(3); - startTime.add(m_startMinute); - m_startAmpm = new SingleSelect(new IntegerParameter("start_ampm")); - m_startAmpm.addOption(new Option("0", "am")); - m_startAmpm.addOption(new Option("1", "pm")); - startTime.add(m_startAmpm); - startTime.add(new Label(new TimeZonePrinter())); - add(startTime); - - add(new Label("End date:"), RIGHT | TOP); - m_endDate = new Date(new DateParameter("end_date") { - protected final Calendar getCalendar(final HttpServletRequest sreq) { - final Calendar cal = super.getCalendar(sreq); - cal.setLenient(false); - return cal; - } - }); - add(m_endDate); + SimpleContainer header = new SimpleContainer(HEADER_ELEMENT, XML_NS); + SimpleContainer body = new SimpleContainer(BODY_ELEMENT, XML_NS); + SimpleContainer footer = new SimpleContainer(FOOTER_ELEMENT, XML_NS); - add(new Label("End time:"), RIGHT | TOP); - BoxPanel endTime = new BoxPanel(BoxPanel.HORIZONTAL); - m_endHour = new TextField(new IntegerParameter("end_hour")); - m_endHour.setSize(3); - endTime.add(m_endHour); - m_endMinute = new TextField(new IntegerParameter("end_minute")); - m_endMinute.setSize(3); - endTime.add(m_endMinute); - m_endAmpm = new SingleSelect(new IntegerParameter("end_ampm")); - m_endAmpm.addOption(new Option("0", "am")); - m_endAmpm.addOption(new Option("1", "pm")); - endTime.add(m_endAmpm); - endTime.add(new Label(new TimeZonePrinter())); - add(endTime); - } - - m_itemID = new Hidden(Webpage.ID); - add(m_itemID); - - SimpleContainer buttons = new SimpleContainer(); - m_save = new Submit("Save"); - buttons.add(m_save); - buttons.add(new Label("")); - buttons.add(new Submit("Cancel")); - - add(new Label("")); - add(buttons); - - addInitListener(this); - addValidationListener(this); - addProcessListener(this); - } - - public void init(FormSectionEvent e) throws FormProcessException { - s_log.debug("init"); - PageState state = e.getPageState(); - HttpServletRequest request = state.getRequest(); - // ContentSection section = ContentSectionDispatcher.getContentSection(request); + m_createForm = new WebpageCMSEditorForm(true); + m_editForm = new WebpageCMSEditorForm(false); + body.add(m_createForm); + body.add(m_editForm); + + add(header); + add(body); + add(footer); + } + + protected void buildPage() { + super.buildPage(); + setClassAttr("webpage"); + } + + public void generateXML(PageState state, Document parent) { + BigDecimal id = null; + try { + HttpServletRequest request = state.getRequest(); + id = new BigDecimal(request.getParameter(Webpage.ID)); + } catch (Exception ex) { + } + m_createForm.setVisible(state, id == null); + m_editForm.setVisible(state, id != null); + super.generateXML(state, parent); + } + + public class WebpageCMSEditorForm extends Form implements FormInitListener, + FormValidationListener, + FormProcessListener { + + Hidden m_itemID; + TextField m_author, m_title; + MultipleSelect m_categories; + CMSDHTMLEditor m_body; + CMSDHTMLEditor m_desc; + Submit m_save; + Date m_startDate; + TextField m_startHour; + TextField m_startMinute; + SingleSelect m_startAmpm; + Date m_endDate; + TextField m_endHour; + TextField m_endMinute; + SingleSelect m_endAmpm; + boolean m_displayDates; + + public WebpageCMSEditorForm(boolean displayDates) { + super("WebpageCMSEditorForm"); + + m_displayDates = displayDates; + + m_title = new TextField(new StringParameter("title")); + m_title.setSize(35); + add(new Label("Title:"), RIGHT | TOP); + add(m_title); + + m_author = new TextField(Webpage.AUTHOR); + add(new Label(new AuthorLabelPrinter()), RIGHT | TOP); + add(m_author); + + m_desc = new CMSDHTMLEditor("desc");//CMSDHTMLEditor.m_configWithoutToolbar + m_desc.setRows(10); + m_desc.setCols(80); + + add(new Label("Lead:", false), RIGHT | TOP);//
(this field is currently not displayed on the website) + add(m_desc); + + add(new Label("Location:"), RIGHT | TOP); + m_categories = new MultipleSelect("categories"); + m_categories.setSize(5); + add(m_categories); + + add(new Label("Body:"), RIGHT | TOP); + StringParameter bodyParam = new StringParameter(Webpage.BODY); + m_body = new CMSDHTMLEditor(bodyParam); + m_body.setCols(80); + m_body.setRows(20); + add(m_body); + + if (displayDates) { + add(new Label("Start date:"), RIGHT | TOP); + m_startDate = new Date(new DateParameter("start_date") { + protected final Calendar getCalendar(final HttpServletRequest sreq) { + final Calendar cal = super.getCalendar(sreq); + cal.setLenient(false); + return cal; + } + }); + add(m_startDate); + + add(new Label("Start time:"), RIGHT | TOP); + BoxPanel startTime = new BoxPanel(BoxPanel.HORIZONTAL); + m_startHour = new TextField(new IntegerParameter("start_hour")); + m_startHour.setSize(3); + startTime.add(m_startHour); + m_startMinute = new TextField(new IntegerParameter("start_minute")); + m_startMinute.setSize(3); + startTime.add(m_startMinute); + m_startAmpm = new SingleSelect(new IntegerParameter("start_ampm")); + m_startAmpm.addOption(new Option("0", "am")); + m_startAmpm.addOption(new Option("1", "pm")); + startTime.add(m_startAmpm); + startTime.add(new Label(new TimeZonePrinter())); + add(startTime); + + add(new Label("End date:"), RIGHT | TOP); + m_endDate = new Date(new DateParameter("end_date") { + protected final Calendar getCalendar(final HttpServletRequest sreq) { + final Calendar cal = super.getCalendar(sreq); + cal.setLenient(false); + return cal; + } + }); + add(m_endDate); + + add(new Label("End time:"), RIGHT | TOP); + BoxPanel endTime = new BoxPanel(BoxPanel.HORIZONTAL); + m_endHour = new TextField(new IntegerParameter("end_hour")); + m_endHour.setSize(3); + endTime.add(m_endHour); + m_endMinute = new TextField(new IntegerParameter("end_minute")); + m_endMinute.setSize(3); + endTime.add(m_endMinute); + m_endAmpm = new SingleSelect(new IntegerParameter("end_ampm")); + m_endAmpm.addOption(new Option("0", "am")); + m_endAmpm.addOption(new Option("1", "pm")); + endTime.add(m_endAmpm); + endTime.add(new Label(new TimeZonePrinter())); + add(endTime); + } + + m_itemID = new Hidden(Webpage.ID); + add(m_itemID); + + SimpleContainer buttons = new SimpleContainer(); + m_save = new Submit("Save"); + buttons.add(m_save); + buttons.add(new Label("")); + buttons.add(new Submit("Cancel")); + + add(new Label("")); + add(buttons); + + addInitListener(this); + addValidationListener(this); + addProcessListener(this); + } + + public void init(FormSectionEvent e) throws FormProcessException { + s_log.debug("init"); + PageState state = e.getPageState(); + HttpServletRequest request = state.getRequest(); + // ContentSection section = ContentSectionDispatcher.getContentSection(request); ContentSection section = ContentSectionServlet.getContentSection(request); - - Webpage webpage = null; - try { - BigDecimal id = new BigDecimal(request.getParameter(Webpage.ID)); - webpage = new Webpage(id); - if (!webpage.getContentSection().equals(section)) { - s_log.error("content section doesn't match! create new webpage entity."); - webpage = null; - } - } - catch (Exception ex) { - } - - m_categories.setPrintListener(new CategoriesPrintListener(section)); - - if (webpage != null) { - m_itemID.setValue(state, webpage.getID().toString()); - m_author.setValue(state, webpage.getAuthor()); - m_title.setValue(state, webpage.getTitle()); - m_desc.setValue(state, webpage.getDescription()); - m_body.setValue(state, webpage.getBody()); - - ArrayList assignedCats = new ArrayList(); - CategoryCollection cc = webpage.getCategoryCollection(); - while (cc.next()) { - String catID = cc.getCategory().getID().toString(); - assignedCats.add(catID); - } - m_categories.setValue(state, assignedCats.toArray()); - } - else { - m_categories.setValue(state, new String[]{request.getParameter("categoryID")}); - if (m_displayDates) { - final java.util.Date start = new java.util.Date(System.currentTimeMillis()); - m_startDate.setValue(state, start); - - final Calendar calendar = Calendar.getInstance(); - calendar.setTime(start); + + Webpage webpage = null; + try { + BigDecimal id = new BigDecimal(request.getParameter(Webpage.ID)); + webpage = new Webpage(id); + if (!webpage.getContentSection().equals(section)) { + s_log.error("content section doesn't match! create new webpage entity."); + webpage = null; + } + } catch (Exception ex) { + } + + m_categories.setPrintListener(new CategoriesPrintListener(section)); + + if (webpage != null) { + m_itemID.setValue(state, webpage.getID().toString()); + m_author.setValue(state, webpage.getAuthor()); + m_title.setValue(state, webpage.getTitle()); + m_desc.setValue(state, webpage.getDescription()); + m_body.setValue(state, webpage.getBody()); + + ArrayList assignedCats = new ArrayList(); + CategoryCollection cc = webpage.getCategoryCollection(); + while (cc.next()) { + String catID = cc.getCategory().getID().toString(); + assignedCats.add(catID); + } + m_categories.setValue(state, assignedCats.toArray()); + } else { + m_categories.setValue(state, new String[]{request.getParameter("categoryID")}); + if (m_displayDates) { + final java.util.Date start = new java.util.Date(System.currentTimeMillis()); + m_startDate.setValue(state, start); + + final Calendar calendar = Calendar.getInstance(); + calendar.setTime(start); // If the hour is 12, then Calendar.get(Calendar.HOUR) - // returns 0 (from the 24 hour time - 12). We want it to - // return 12. - if (calendar.get(Calendar.HOUR) == 0) { - m_startHour.setValue(state, new Integer(12)); - } - else { - m_startHour.setValue(state, new Integer(calendar.get(Calendar.HOUR))); - } - final Integer min = new Integer(calendar.get(Calendar.MINUTE)); - if (min.intValue() < 10) { - m_startMinute.setValue(state, "0" + min.toString()); - } - else { - m_startMinute.setValue(state, min.toString()); - } - m_startAmpm.setValue(state, new Integer(calendar.get(Calendar.AM_PM))); - } - } - } - - public void validate(FormSectionEvent e) throws FormProcessException { - s_log.debug("validate"); - PageState state = e.getPageState(); - boolean valid = true; - if (m_save.isSelected(state)) { - String title = (String) m_title.getValue(state); - if (title == null || title.length() == 0) { - m_title.addError("This parameter is required"); - valid = false; - } - if (title != null && (title.length() < 1 || title.length() > 200)) { - m_title.addError("This parameter is not between 1 and 200 characters long"); - valid = false; - } - String desc = (String) m_desc.getValue(state); - if (desc != null && (desc.length() < 1 || desc.length() > 4000)) { - m_desc.addError("This parameter is not between 1 and 4000 characters long"); - valid = false; - } - if (m_displayDates) { - Integer startHour = (Integer) m_startHour.getValue(state); - if (startHour != null && (startHour.intValue() < 1 || startHour.intValue() > 12)) { - m_startHour.addError("This parameter is not between 1 and 12"); - valid = false; - } - Integer startMin = (Integer) m_startMinute.getValue(state); - if (startMin != null && (startMin.intValue() < 0 || startMin.intValue() > 59)) { - m_startMinute.addError("This parameter is not between 0 and 59"); - valid = false; - } - Integer endHour = (Integer) m_endHour.getValue(state); - if (endHour != null && (endHour.intValue() < 1 || endHour.intValue() > 12)) { - m_endHour.addError("This parameter is not between 1 and 12"); - valid = false; - } - Integer endMin = (Integer) m_endMinute.getValue(state); - if (endMin != null && (endMin.intValue() < 0 || endMin.intValue() > 59)) { - m_endMinute.addError("This parameter is not between 0 and 59"); - valid = false; - } - } - } - if (! valid) { - throw new FormProcessException("There is an error on the form"); - } - } - - public void process(FormSectionEvent e) throws FormProcessException { - s_log.debug("process"); - PageState state = e.getPageState(); - HttpServletRequest request = state.getRequest(); - // ContentSection section = ContentSectionDispatcher.getContentSection(request); + // returns 0 (from the 24 hour time - 12). We want it to + // return 12. + if (calendar.get(Calendar.HOUR) == 0) { + m_startHour.setValue(state, new Integer(12)); + } else { + m_startHour.setValue(state, new Integer(calendar.get(Calendar.HOUR))); + } + final Integer min = new Integer(calendar.get(Calendar.MINUTE)); + if (min.intValue() < 10) { + m_startMinute.setValue(state, "0" + min.toString()); + } else { + m_startMinute.setValue(state, min.toString()); + } + m_startAmpm.setValue(state, new Integer(calendar.get(Calendar.AM_PM))); + } + } + } + + public void validate(FormSectionEvent e) throws FormProcessException { + s_log.debug("validate"); + PageState state = e.getPageState(); + boolean valid = true; + if (m_save.isSelected(state)) { + String title = (String) m_title.getValue(state); + if (title == null || title.length() == 0) { + m_title.addError("This parameter is required"); + valid = false; + } + if (title != null && (title.length() < 1 || title.length() > 200)) { + m_title.addError("This parameter is not between 1 and 200 characters long"); + valid = false; + } + String desc = (String) m_desc.getValue(state); + if (desc != null && (desc.length() < 1 || desc.length() > 4000)) { + m_desc.addError("This parameter is not between 1 and 4000 characters long"); + valid = false; + } + if (m_displayDates) { + Integer startHour = (Integer) m_startHour.getValue(state); + if (startHour != null && (startHour.intValue() < 1 || startHour.intValue() > 12)) { + m_startHour.addError("This parameter is not between 1 and 12"); + valid = false; + } + Integer startMin = (Integer) m_startMinute.getValue(state); + if (startMin != null && (startMin.intValue() < 0 || startMin.intValue() > 59)) { + m_startMinute.addError("This parameter is not between 0 and 59"); + valid = false; + } + Integer endHour = (Integer) m_endHour.getValue(state); + if (endHour != null && (endHour.intValue() < 1 || endHour.intValue() > 12)) { + m_endHour.addError("This parameter is not between 1 and 12"); + valid = false; + } + Integer endMin = (Integer) m_endMinute.getValue(state); + if (endMin != null && (endMin.intValue() < 0 || endMin.intValue() > 59)) { + m_endMinute.addError("This parameter is not between 0 and 59"); + valid = false; + } + } + } + if (!valid) { + throw new FormProcessException("There is an error on the form"); + } + } + + public void process(FormSectionEvent e) throws FormProcessException { + s_log.debug("process"); + PageState state = e.getPageState(); + HttpServletRequest request = state.getRequest(); + // ContentSection section = ContentSectionDispatcher.getContentSection(request); ContentSection section = ContentSectionServlet.getContentSection(request); - - if (m_save.isSelected(state)) { - Webpage webpage = null; - - boolean commitTransaction = false; - boolean isMyTransaction = false; - TransactionContext txn = null; - try { - Session session = SessionManager.getSession(); - txn = session.getTransactionContext(); - if (!txn.inTxn()) { - txn.beginTxn(); - isMyTransaction = true; - } - try { - String idTxt = (String) m_itemID.getValue(state); - if (idTxt != null && idTxt.length() > 0) { - BigDecimal id = new BigDecimal(idTxt); - webpage = new Webpage(id); - } - } - catch (Exception ex) { - throw new FormProcessException(ex); - } - - if (section == null) { - throw new FormProcessException("ContentSection is null"); - } - SecurityManager sm = new SecurityManager(section); - User user = Web.getWebContext().getUser(); - - if (webpage != null) { - if ( !sm.canAccess(user, SecurityConstants.EDIT_ITEM, webpage ) ) { - throw new FormProcessException("Insufficient permissions"); - } - if (!webpage.getContentSection().equals(section)) { - throw new FormProcessException("content section doesn't match!"); - } - webpage.setTitle((String) m_title.getValue(state)); - webpage.setName("webpage" + webpage.getID()); - webpage.setBody((String) m_body.getValue(state)); - webpage.setAuthor((String) m_author.getValue(state)); - webpage.setCategories((String[]) m_categories.getValue(state)); - webpage.setDescription((String) m_desc.getValue(state)); - webpage.save(); - } - else { - if ( !sm.canAccess(user, SecurityConstants.NEW_ITEM ) ) { - throw new FormProcessException("Insufficient permissions"); - } - webpage = new Webpage(); - webpage.setLanguage("en"); - webpage.setName("webpage" + webpage.getID()); - webpage.setTitle((String) m_title.getValue(state)); - webpage.setBody((String) m_body.getValue(state)); - webpage.setAuthor((String) m_author.getValue(state)); - webpage.setDescription((String) m_desc.getValue(state)); - webpage.save(); - - ContentBundle bundle = new ContentBundle(webpage); - bundle.setContentSection(section); - bundle.setParent(section.getRootFolder()); - webpage.setCategories((String[]) m_categories.getValue(state)); - - // get lifecycleDefinition - LifecycleDefinitionCollection lfColl = null; - LifecycleDefinition lifecycleDefinition = null; - try { - lfColl = section.getLifecycleDefinitions(); - if (lfColl.next()) { - lifecycleDefinition = lfColl.getLifecycleDefinition(); - } - } - finally { - if (lfColl != null) { - lfColl.close(); - } - } - - // set workflow - TaskCollection taskColl = null; - try { - taskColl = section.getWorkflowTemplates(); - if (taskColl.next()) { - Task task = taskColl.getTask(); - final WorkflowTemplate wfTemp = new WorkflowTemplate(task.getID()); - final Workflow flow = wfTemp.instantiateNewWorkflow(); - flow.setObjectID(webpage.getID()); - flow.start(Web.getWebContext().getUser()); - flow.save(); - } - } - finally { - if (taskColl != null) { - taskColl.close(); - } - } - - // finish all task - Workflow workflow = Workflow.getObjectWorkflow(webpage); - - Engine engine = Engine.getInstance(); - Assert.exists(engine, Engine.class); - Iterator i = engine.getEnabledTasks(Web.getWebContext().getUser(), workflow.getID()).iterator(); - CMSTask task; - do { - while (i.hasNext()) { - task = (CMSTask) i.next(); - try { - task.finish(); - } - catch (Exception ex) { - throw new FormProcessException(ex); - } - } - - i = engine.getEnabledTasks(Web.getWebContext().getUser(), workflow.getID()).iterator(); - } - while (i.hasNext()); - - // publish - if (lifecycleDefinition != null) { - if (m_displayDates) { - final Integer startHour = (Integer) m_startHour.getValue(state); - Integer startMinute = (Integer) m_startMinute.getValue(state); - if (startMinute == null) { - startMinute = new Integer(0); - } - final Integer startAmpm = (Integer) m_startAmpm.getValue(state); - final Integer endHour = (Integer) m_endHour.getValue(state); - Integer endMinute = (Integer) m_endMinute.getValue(state); - if (endMinute == null) { - endMinute = new Integer(0); - } - final Integer endAmpm = (Integer) m_endAmpm.getValue(state); - - java.util.Date startDate = (java.util.Date) m_startDate.getValue(state); - final Calendar start = Calendar.getInstance(); - start.setTime(startDate); - start.set(Calendar.AM_PM, startAmpm.intValue()); - start.set(Calendar.MINUTE, startMinute.intValue()); - start.set(Calendar.AM_PM, startAmpm.intValue()); - if (startHour.intValue() != 12) { - start.set(Calendar.HOUR_OF_DAY, 12 * startAmpm.intValue() + startHour.intValue()); - start.set(Calendar.HOUR, startHour.intValue()); - } - else { - if (startAmpm.intValue() == 0) { - start.set(Calendar.HOUR_OF_DAY, 0); - start.set(Calendar.HOUR, 0); - } - else { - start.set(Calendar.HOUR_OF_DAY, 12); - start.set(Calendar.HOUR, 0); - } - } - startDate = start.getTime(); - - java.util.Date endDate = (java.util.Date) m_endDate.getValue(state); - if (endDate != null) { - final Calendar end = Calendar.getInstance(); - end.setTime(endDate); - end.set(Calendar.AM_PM, endAmpm.intValue()); - end.set(Calendar.MINUTE, endMinute.intValue()); - end.set(Calendar.AM_PM, endAmpm.intValue()); - if (endHour.intValue() != 12) { - end.set(Calendar.HOUR_OF_DAY, 12 * endAmpm.intValue() + endHour.intValue()); - end.set(Calendar.HOUR, endHour.intValue()); - } - else { - if (endAmpm.intValue() == 0) { - end.set(Calendar.HOUR_OF_DAY, 0); - end.set(Calendar.HOUR, 0); - } - else { - end.set(Calendar.HOUR_OF_DAY, 12); - end.set(Calendar.HOUR, 0); - } - } - endDate = end.getTime(); - } - - webpage.publish(lifecycleDefinition, startDate); - - if (endDate != null) { - final Lifecycle lifecycle = webpage.getLifecycle(); - - // update individual phases - final PhaseCollection phases = lifecycle.getPhases(); - - while (phases.next()) { - final Phase phase = phases.getPhase(); - java.util.Date thisEnd = phase.getEndDate(); - if (thisEnd == null || thisEnd.compareTo(endDate) > 0) { - phase.setEndDate(endDate); - phase.save(); - } - } - } - } - else { - webpage.publish(lifecycleDefinition, new java.util.Date()); - } - + + if (m_save.isSelected(state)) { + Webpage webpage = null; + + boolean commitTransaction = false; + boolean isMyTransaction = false; + TransactionContext txn = null; + try { + Session session = SessionManager.getSession(); + txn = session.getTransactionContext(); + if (!txn.inTxn()) { + txn.beginTxn(); + isMyTransaction = true; + } + try { + String idTxt = (String) m_itemID.getValue(state); + if (idTxt != null && idTxt.length() > 0) { + BigDecimal id = new BigDecimal(idTxt); + webpage = new Webpage(id); + } + } catch (Exception ex) { + throw new FormProcessException(ex); + } + + if (section == null) { + throw new FormProcessException("ContentSection is null"); + } + SecurityManager sm = new SecurityManager(section); + User user = Web.getWebContext().getUser(); + + if (webpage != null) { + if (!sm.canAccess(user, SecurityConstants.EDIT_ITEM, webpage)) { + throw new FormProcessException("Insufficient permissions"); + } + if (!webpage.getContentSection().equals(section)) { + throw new FormProcessException("content section doesn't match!"); + } + webpage.setTitle((String) m_title.getValue(state)); + webpage.setName("webpage" + webpage.getID()); + webpage.setBody((String) m_body.getValue(state)); + webpage.setAuthor((String) m_author.getValue(state)); + webpage.setCategories((String[]) m_categories.getValue(state)); + webpage.setDescription((String) m_desc.getValue(state)); + webpage.save(); + } else { + if (!sm.canAccess(user, SecurityConstants.NEW_ITEM)) { + throw new FormProcessException("Insufficient permissions"); + } + webpage = new Webpage(); + webpage.setLanguage("en"); + webpage.setName("webpage" + webpage.getID()); + webpage.setTitle((String) m_title.getValue(state)); + webpage.setBody((String) m_body.getValue(state)); + webpage.setAuthor((String) m_author.getValue(state)); + webpage.setDescription((String) m_desc.getValue(state)); + webpage.save(); + + ContentBundle bundle = new ContentBundle(webpage); + bundle.setContentSection(section); + bundle.setParent(section.getRootFolder()); + webpage.setCategories((String[]) m_categories.getValue(state)); + + // get lifecycleDefinition + LifecycleDefinitionCollection lfColl = null; + LifecycleDefinition lifecycleDefinition = null; + try { + lfColl = section.getLifecycleDefinitions(); + if (lfColl.next()) { + lifecycleDefinition = lfColl.getLifecycleDefinition(); + } + } finally { + if (lfColl != null) { + lfColl.close(); + } + } + + // set workflow + TaskCollection taskColl = null; + try { + taskColl = section.getWorkflowTemplates(); + if (taskColl.next()) { + Task task = taskColl.getTask(); + final WorkflowTemplate wfTemp = new WorkflowTemplate(task.getID()); + final Workflow flow = wfTemp.instantiateNewWorkflow(); + flow.setObjectID(webpage.getID()); + flow.start(Web.getWebContext().getUser()); + flow.save(); + } + } finally { + if (taskColl != null) { + taskColl.close(); + } + } + + // finish all task + Workflow workflow = Workflow.getObjectWorkflow(webpage); + + Engine engine = Engine.getInstance(); + Assert.exists(engine, Engine.class); + Iterator i = engine.getEnabledTasks(Web.getWebContext().getUser(), workflow. + getID()).iterator(); + CMSTask task; + do { + while (i.hasNext()) { + task = (CMSTask) i.next(); + try { + task.finish(); + } catch (Exception ex) { + throw new FormProcessException(ex); + } + } + + i = engine.getEnabledTasks(Web.getWebContext().getUser(), workflow. + getID()).iterator(); + } while (i.hasNext()); + + // publish + if (lifecycleDefinition != null) { + if (m_displayDates) { + final Integer startHour = (Integer) m_startHour.getValue(state); + Integer startMinute = (Integer) m_startMinute.getValue(state); + if (startMinute == null) { + startMinute = new Integer(0); + } + final Integer startAmpm = (Integer) m_startAmpm.getValue(state); + final Integer endHour = (Integer) m_endHour.getValue(state); + Integer endMinute = (Integer) m_endMinute.getValue(state); + if (endMinute == null) { + endMinute = new Integer(0); + } + final Integer endAmpm = (Integer) m_endAmpm.getValue(state); + + java.util.Date startDate = (java.util.Date) m_startDate.getValue( + state); + final Calendar start = Calendar.getInstance(); + start.setTime(startDate); + start.set(Calendar.AM_PM, startAmpm.intValue()); + start.set(Calendar.MINUTE, startMinute.intValue()); + start.set(Calendar.AM_PM, startAmpm.intValue()); + if (startHour.intValue() != 12) { + start.set(Calendar.HOUR_OF_DAY, 12 * startAmpm.intValue() + + startHour.intValue()); + start.set(Calendar.HOUR, startHour.intValue()); + } else { + if (startAmpm.intValue() == 0) { + start.set(Calendar.HOUR_OF_DAY, 0); + start.set(Calendar.HOUR, 0); + } else { + start.set(Calendar.HOUR_OF_DAY, 12); + start.set(Calendar.HOUR, 0); + } + } + startDate = start.getTime(); + + java.util.Date endDate = (java.util.Date) m_endDate.getValue(state); + if (endDate != null) { + final Calendar end = Calendar.getInstance(); + end.setTime(endDate); + end.set(Calendar.AM_PM, endAmpm.intValue()); + end.set(Calendar.MINUTE, endMinute.intValue()); + end.set(Calendar.AM_PM, endAmpm.intValue()); + if (endHour.intValue() != 12) { + end.set(Calendar.HOUR_OF_DAY, 12 * endAmpm.intValue() + + endHour.intValue()); + end.set(Calendar.HOUR, endHour.intValue()); + } else { + if (endAmpm.intValue() == 0) { + end.set(Calendar.HOUR_OF_DAY, 0); + end.set(Calendar.HOUR, 0); + } else { + end.set(Calendar.HOUR_OF_DAY, 12); + end.set(Calendar.HOUR, 0); + } + } + endDate = end.getTime(); + } + + webpage.publish(lifecycleDefinition, startDate); + + if (endDate != null) { + final Lifecycle lifecycle = webpage.getLifecycle(); + + // update individual phases + final PhaseCollection phases = lifecycle.getPhases(); + + while (phases.next()) { + final Phase phase = phases.getPhase(); + java.util.Date thisEnd = phase.getEndDate(); + if (thisEnd == null || thisEnd.compareTo(endDate) > 0) { + phase.setEndDate(endDate); + phase.save(); + } + } + } + } else { + webpage.publish(lifecycleDefinition, new java.util.Date()); + } + // Force the lifecycle scheduler to run to avoid any - // scheduler delay for items that should be published - // immediately. - webpage.getLifecycle().start(); - - webpage.save(); - } - } - commitTransaction = true; - } - finally { - if (txn != null && isMyTransaction) { - if (commitTransaction) { - txn.commitTxn(); - } - else { - txn.abortTxn(); - } - } - } - } - - try { - DispatcherHelper.sendRedirect(request, state.getResponse(), section.getPath()); - } - catch (IOException ex) { - throw new FormProcessException(ex); - } - } - - public class TimeZonePrinter implements PrintListener { - public void prepare(PrintEvent e) { - final Label target = (Label) e.getTarget(); - final PageState state = e.getPageState(); - final Calendar mStart = Calendar.getInstance(); - java.util.Date st = (java.util.Date) m_startDate.getValue(state); + // scheduler delay for items that should be published + // immediately. + webpage.getLifecycle().start(); - if (st != null) { - mStart.setTime((java.util.Date) m_startDate.getValue(state)); - } + webpage.save(); + } + } + commitTransaction = true; + } finally { + if (txn != null && isMyTransaction) { + if (commitTransaction) { + txn.commitTxn(); + } else { + txn.abortTxn(); + } + } + } + } - final String zone = mStart.getTimeZone().getDisplayName(true, TimeZone.SHORT); + try { + DispatcherHelper.sendRedirect(request, state.getResponse(), section.getPath()); + } catch (IOException ex) { + throw new FormProcessException(ex); + } + } - target.setLabel(zone); - } - } - } + public class TimeZonePrinter implements PrintListener { + + public void prepare(PrintEvent e) { + final Label target = (Label) e.getTarget(); + final PageState state = e.getPageState(); + final Calendar mStart = Calendar.getInstance(); + java.util.Date st = (java.util.Date) m_startDate.getValue(state); + + if (st != null) { + mStart.setTime((java.util.Date) m_startDate.getValue(state)); + } + + final String zone = mStart.getTimeZone().getDisplayName(true, TimeZone.SHORT); + + target.setLabel(zone); + } + } + } }