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
master
jensp 2014-09-04 11:52:51 +00:00
parent 31d94afaad
commit cf9ed68bfb
65 changed files with 3606 additions and 3588 deletions

View File

@ -81,6 +81,7 @@ public class CategoryProviderContentTypeBlockForm extends Form {
public void prepare(PrintEvent e) { public void prepare(PrintEvent e) {
OptionGroup optionGroup = (OptionGroup) e.getTarget(); OptionGroup optionGroup = (OptionGroup) e.getTarget();
optionGroup.clearOptions();
ContentTypeCollection ctc = ContentType ContentTypeCollection ctc = ContentType
.getRegisteredContentTypes(); .getRegisteredContentTypes();
ctc.addOrder(ContentType.LABEL); ctc.addOrder(ContentType.LABEL);

View File

@ -15,7 +15,6 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
package com.arsdigita.atoz.ui.admin; package com.arsdigita.atoz.ui.admin;
import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.PageState;
@ -75,37 +74,39 @@ public class ItemProviderAliasForm extends Form {
m_letter = new SingleSelect("letter"); m_letter = new SingleSelect("letter");
m_letter.addValidationListener(new NotNullValidationListener()); m_letter.addValidationListener(new NotNullValidationListener());
m_letter.addOption(new Option(null, "--Select one--")); m_letter.addOption(new Option(null, "--Select one--"));
for (int i = 0 ; i < 26 ; i++) { for (int i = 0; i < 26; i++) {
String letter = new String(new char[]{(char)((int)'a' + i)}); String letter = new String(new char[]{(char) ((int) 'a' + i)});
m_letter.addOption(new Option(letter, letter.toUpperCase())); m_letter.addOption(new Option(letter, letter.toUpperCase()));
} }
m_item = new SingleSelect(new StringParameter("item")); m_item = new SingleSelect(new StringParameter("item"));
try { try {
m_item.addPrintListener(new PrintListener() { m_item.addPrintListener(new PrintListener() {
public void prepare(PrintEvent event) { public void prepare(PrintEvent event) {
OptionGroup group = (SingleSelect) event.getTarget(); OptionGroup group = (SingleSelect) event.getTarget();
PageState state = event.getPageState(); group.clearOptions();
boolean valueSet = false; PageState state = event.getPageState();
boolean valueSet = false;
Category category = ((ItemProvider) m_provider.getSelectedObject(state)) Category category = ((ItemProvider) m_provider.getSelectedObject(state))
.getCategory(); .getCategory();
CategorizedCollection children = category.getObjects(ContentItem.BASE_DATA_OBJECT_TYPE); CategorizedCollection children = category.getObjects(
children.addOrder("name"); ContentItem.BASE_DATA_OBJECT_TYPE);
children.addOrder("name");
while (children.next()) { while (children.next()) {
ACSObject item = (ACSObject) children.getDomainObject(); ACSObject item = (ACSObject) children.getDomainObject();
if ((item instanceof ContentItem) && if ((item instanceof ContentItem) && ((ContentItem) item).getVersion().
((ContentItem) item).getVersion().equals(ContentItem.DRAFT)) { equals(ContentItem.DRAFT)) {
group.addOption(new Option(item.getID().toString(), group.addOption(new Option(item.getID().toString(),
((ContentItem)item).getName())); ((ContentItem) item).getName()));
}
} }
} }
}); }
});
} catch (TooManyListenersException e) { } catch (TooManyListenersException e) {
//s_log.error("Error adding init listener to Radio Group", e); //s_log.error("Error adding init listener to Radio Group", e);
throw new UncheckedWrapperException(e); throw new UncheckedWrapperException(e);
@ -123,8 +124,9 @@ public class ItemProviderAliasForm extends Form {
} }
private class ProviderSubmissionListener implements FormSubmissionListener { private class ProviderSubmissionListener implements FormSubmissionListener {
public void submitted(FormSectionEvent e) public void submitted(FormSectionEvent e)
throws FormProcessException { throws FormProcessException {
PageState state = e.getPageState(); PageState state = e.getPageState();
if (m_buttons.getCancelButton().isSelected(state)) { if (m_buttons.getCancelButton().isSelected(state)) {
@ -135,27 +137,27 @@ public class ItemProviderAliasForm extends Form {
} }
private class ProviderProcessListener implements FormProcessListener { private class ProviderProcessListener implements FormProcessListener {
public void process(FormSectionEvent e) public void process(FormSectionEvent e)
throws FormProcessException { throws FormProcessException {
PageState state = e.getPageState(); PageState state = e.getPageState();
ItemProvider provider = (ItemProvider) m_provider ItemProvider provider = (ItemProvider) m_provider
.getSelectedObject(state); .getSelectedObject(state);
BigDecimal itemId = new BigDecimal(m_item.getValue(state).toString()); 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 letter = (String) m_letter.getValue(state);
String title = (String)m_title.getValue(state); String title = (String) m_title.getValue(state);
//provider.addAlias(item, letter, title); //provider.addAlias(item, letter, title);
ItemAlias alias = (ItemAlias) Classes.newInstance(ItemAlias.class);
ItemAlias alias = (ItemAlias) Classes.newInstance(ItemAlias.class); alias.setTitle(title);
alias.setTitle(title); alias.setLetter(letter);
alias.setLetter(letter); alias.setContentItem(item);
alias.setContentItem(item); alias.setItemProvider(provider);
alias.setItemProvider(provider); alias.save();
alias.save();
fireCompletionEvent(state); fireCompletionEvent(state);
} }

View File

@ -78,6 +78,7 @@ public class GenericOrgaUnitTextAssetEdit extends BasicItemForm implements FormS
@Override @Override
public void prepare(final PrintEvent event) { public void prepare(final PrintEvent event) {
final SingleSelect target = (SingleSelect) event.getTarget(); final SingleSelect target = (SingleSelect) event.getTarget();
target.clearOptions();
final RelationAttributeCollection names = new RelationAttributeCollection( final RelationAttributeCollection names = new RelationAttributeCollection(
"GenericOrgaUnitTextAssetName"); "GenericOrgaUnitTextAssetName");

View File

@ -102,6 +102,7 @@ public class PublicPersonalProfileCreate extends PageCreate {
ownerSelect.addPrintListener(new PrintListener() { ownerSelect.addPrintListener(new PrintListener() {
public void prepare(final PrintEvent event) { public void prepare(final PrintEvent event) {
final SingleSelect ownerSelect = (SingleSelect) event.getTarget(); final SingleSelect ownerSelect = (SingleSelect) event.getTarget();
ownerSelect.clearOptions();
String personType = config.getPersonType(); String personType = config.getPersonType();
if ((personType == null) || (personType.isEmpty())) { if ((personType == null) || (personType.isEmpty())) {

View File

@ -105,6 +105,7 @@ public class PublicPersonalProfileNavigationAddForm
public void prepare(final PrintEvent event) { public void prepare(final PrintEvent event) {
SingleSelect select = (SingleSelect) event.getTarget(); SingleSelect select = (SingleSelect) event.getTarget();
select.clearOptions();
select.addOption(new Option("", "")); select.addOption(new Option("", ""));
PublicPersonalProfileNavItemCollection navItems = PublicPersonalProfileNavItemCollection navItems =

View File

@ -91,6 +91,7 @@ public class PublicPersonalProfilePropertyForm extends BasicPageForm implements
ownerSelect.addPrintListener(new PrintListener() { ownerSelect.addPrintListener(new PrintListener() {
public void prepare(final PrintEvent event) { public void prepare(final PrintEvent event) {
final SingleSelect ownerSelect = (SingleSelect) event.getTarget(); final SingleSelect ownerSelect = (SingleSelect) event.getTarget();
ownerSelect.clearOptions();
final PublicPersonalProfile profile = (PublicPersonalProfile) itemModel.getSelectedItem(event. final PublicPersonalProfile profile = (PublicPersonalProfile) itemModel.getSelectedItem(event.
getPageState()); getPageState());

View File

@ -56,12 +56,12 @@ import com.arsdigita.cms.ItemSelectionModel;
* @version $Id$ * @version $Id$
*/ */
public class DecisionTreeOptionEditForm extends Form public class DecisionTreeOptionEditForm extends Form
implements FormInitListener, implements FormInitListener,
FormProcessListener, FormProcessListener,
FormSubmissionListener { FormSubmissionListener {
private final static Logger s_log = Logger.getLogger( private final static Logger s_log = Logger.getLogger(
DecisionTreeOptionEditForm.class); DecisionTreeOptionEditForm.class);
private ItemSelectionModel m_selTree; private ItemSelectionModel m_selTree;
private ItemSelectionModel m_selOption; private ItemSelectionModel m_selOption;
@ -71,9 +71,9 @@ public class DecisionTreeOptionEditForm extends Form
private SaveCancelSection m_saveCancelSection; private SaveCancelSection m_saveCancelSection;
private SingleSelect m_sectionWidget; private SingleSelect m_sectionWidget;
public static final String LABEL = "label"; public static final String LABEL = "label";
public static final String VALUE = "value"; public static final String VALUE = "value";
public static final String SECTION = "section"; public static final String SECTION = "section";
/** /**
* Constructor. * Constructor.
@ -82,14 +82,14 @@ public class DecisionTreeOptionEditForm extends Form
* @param selOption the current section * @param selOption the current section
*/ */
public DecisionTreeOptionEditForm(ItemSelectionModel selTree, public DecisionTreeOptionEditForm(ItemSelectionModel selTree,
ItemSelectionModel selOption) { ItemSelectionModel selOption) {
this(selTree, selOption, null); this(selTree, selOption, null);
} }
/** /**
* Constructor. * Constructor.
* *
* @param selTree the current decision tree * @param selTree the current decision tree
* @param selOption the current section * @param selOption the current section
* @param container container which this form is added to * @param container container which this form is added to
*/ */
@ -105,7 +105,7 @@ public class DecisionTreeOptionEditForm extends Form
setMethod(Form.POST); setMethod(Form.POST);
setEncType("multipart/form-data"); setEncType("multipart/form-data");
ColumnPanel panel = (ColumnPanel)getPanel(); ColumnPanel panel = (ColumnPanel) getPanel();
panel.setBorder(false); panel.setBorder(false);
panel.setPadColor("#FFFFFF"); panel.setPadColor("#FFFFFF");
panel.setColumnWidth(1, "20%"); panel.setColumnWidth(1, "20%");
@ -133,6 +133,7 @@ public class DecisionTreeOptionEditForm extends Form
/** /**
* Returns the save/cancel section from this form. * Returns the save/cancel section from this form.
*
* @return * @return
*/ */
public SaveCancelSection getSaveCancelSection() { public SaveCancelSection getSaveCancelSection() {
@ -143,9 +144,11 @@ public class DecisionTreeOptionEditForm extends Form
* Set up the dynamic options for the section select widget. * Set up the dynamic options for the section select widget.
*/ */
private void initSectionOptions(PrintEvent e) { private void initSectionOptions(PrintEvent e) {
PageState state = e.getPageState(); PageState state = e.getPageState();
SingleSelect target = (SingleSelect) e.getTarget(); SingleSelect target = (SingleSelect) e.getTarget();
DecisionTree tree = (DecisionTree)m_selTree.getSelectedObject(state); target.clearOptions();
DecisionTree tree = (DecisionTree) m_selTree.getSelectedObject(state);
if (tree != null) { if (tree != null) {
DecisionTreeSectionCollection sections = tree.getSections(); DecisionTreeSectionCollection sections = tree.getSections();
@ -162,6 +165,7 @@ public class DecisionTreeOptionEditForm extends Form
/** /**
* Form initialisation hook. * Form initialisation hook.
*
* @param fse * @param fse
*/ */
@Override @Override
@ -185,111 +189,109 @@ public class DecisionTreeOptionEditForm extends Form
*/ */
protected void addWidgets() { protected void addWidgets() {
Option pleaseSelect = new Option( Option pleaseSelect = new Option(
"", "",
new Label(DecisionTreeGlobalizationUtil.globalize( new Label(DecisionTreeGlobalizationUtil.globalize(
"cms.contenttypes.ui.decisiontree.options.form.please_select") "cms.contenttypes.ui.decisiontree.options.form.please_select")
)); ));
add(new Label(DecisionTreeGlobalizationUtil.globalize( add(new Label(DecisionTreeGlobalizationUtil.globalize(
"cms.contenttypes.ui.decisiontree.options.form.section"))); "cms.contenttypes.ui.decisiontree.options.form.section")));
m_sectionWidget = new SingleSelect(SECTION); m_sectionWidget = new SingleSelect(SECTION);
m_sectionWidget.addValidationListener(new NotNullValidationListener()); m_sectionWidget.addValidationListener(new NotNullValidationListener());
m_sectionWidget.addOption(pleaseSelect); m_sectionWidget.addOption(pleaseSelect);
try { try {
m_sectionWidget.addPrintListener(new PrintListener() { m_sectionWidget.addPrintListener(new PrintListener() {
public void prepare(PrintEvent e) { public void prepare(PrintEvent e) {
initSectionOptions(e); initSectionOptions(e);
} }
}); });
} catch (TooManyListenersException e) { } catch (TooManyListenersException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
add(m_sectionWidget); add(m_sectionWidget);
// add(new Label(DecisionTreeGlobalizationUtil.globalize( // add(new Label(DecisionTreeGlobalizationUtil.globalize(
// "cms.contenttypes.ui.decisiontree.options.form.label"))); // "cms.contenttypes.ui.decisiontree.options.form.label")));
TextField labelWidget = new TextField(new TrimmedStringParameter(LABEL)); TextField labelWidget = new TextField(new TrimmedStringParameter(LABEL));
labelWidget.setLabel(DecisionTreeGlobalizationUtil.globalize( labelWidget.setLabel(DecisionTreeGlobalizationUtil.globalize(
"cms.contenttypes.ui.decisiontree.options.form.label")); "cms.contenttypes.ui.decisiontree.options.form.label"));
labelWidget.addValidationListener(new NotNullValidationListener()); labelWidget.addValidationListener(new NotNullValidationListener());
labelWidget.setSize(60); labelWidget.setSize(60);
add(labelWidget); add(labelWidget);
// add(new Label(DecisionTreeGlobalizationUtil.globalize( // add(new Label(DecisionTreeGlobalizationUtil.globalize(
// "cms.contenttypes.ui.decisiontree.options.form.value"))); // "cms.contenttypes.ui.decisiontree.options.form.value")));
TextField valueWidget = new TextField(new TrimmedStringParameter(VALUE)); TextField valueWidget = new TextField(new TrimmedStringParameter(VALUE));
valueWidget.setLabel(DecisionTreeGlobalizationUtil.globalize( valueWidget.setLabel(DecisionTreeGlobalizationUtil.globalize(
"cms.contenttypes.ui.decisiontree.options.form.value")); "cms.contenttypes.ui.decisiontree.options.form.value"));
valueWidget.addValidationListener(new NotNullValidationListener()); valueWidget.addValidationListener(new NotNullValidationListener());
valueWidget.setSize(60); valueWidget.setSize(60);
add(valueWidget); add(valueWidget);
} }
/** /**
* @param event * @param event
* @throws com.arsdigita.bebop.FormProcessException * @throws com.arsdigita.bebop.FormProcessException Called on form submission. Check to see if
* Called on form submission. Check to see if the user clicked the * the user clicked the cancel button. If they did, don't continue with the form.
* cancel button. If they did, don't continue with the form.
*/ */
@Override @Override
public void submitted(FormSectionEvent event) public void submitted(FormSectionEvent event)
throws FormProcessException { throws FormProcessException {
PageState state = event.getPageState(); PageState state = event.getPageState();
if ( m_saveCancelSection.getCancelButton() if (m_saveCancelSection.getCancelButton()
.isSelected(state) && m_container != null) { .isSelected(state) && m_container != null) {
m_container.onlyShowComponent( m_container.onlyShowComponent(
state, DecisionTreeOptionStep.OPTION_TABLE + state, DecisionTreeOptionStep.OPTION_TABLE + m_container.getTypeIDStr());
m_container.getTypeIDStr()); throw new FormProcessException(
throw new FormProcessException( DecisionTreeGlobalizationUtil.globalize(
DecisionTreeGlobalizationUtil.globalize( "cms.contenttypes.ui.decisiontree.options.form.submission_cancelled")
"cms.contenttypes.ui.decisiontree.options.form.submission_cancelled") );
); }
}
} }
/** /**
* Called after form has been validated. Create the new SectionOption and * Called after form has been validated. Create the new SectionOption and assign it to the
* assign it to the current DecisionTree. * current DecisionTree.
* *
* @param event * @param event
* @throws com.arsdigita.bebop.FormProcessException * @throws com.arsdigita.bebop.FormProcessException
*/ */
@Override @Override
public void process(FormSectionEvent event) throws FormProcessException { public void process(FormSectionEvent event) throws FormProcessException {
PageState state = event.getPageState(); PageState state = event.getPageState();
FormData data = event.getFormData(); 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) { if (m_selOption.getSelectedKey(state) != null) {
BigDecimal id = new BigDecimal(m_selOption BigDecimal id = new BigDecimal(m_selOption
.getSelectedKey(state).toString()); .getSelectedKey(state).toString());
// retrieve the selected Option from the persistence layer // retrieve the selected Option from the persistence layer
option = new DecisionTreeSectionOption(id); option = new DecisionTreeSectionOption(id);
} else { } else {
option = new DecisionTreeSectionOption(); option = new DecisionTreeSectionOption();
option.setName("DecisionTreeSectionOption " + option.getID()); option.setName("DecisionTreeSectionOption " + option.getID());
int rank = section.getMaxOptionRank() + 1; int rank = section.getMaxOptionRank() + 1;
option.setRank(Integer.valueOf(rank)); option.setRank(Integer.valueOf(rank));
} }
String label = (String)data.get(LABEL); String label = (String) data.get(LABEL);
String value = (String)data.get(VALUE); String value = (String) data.get(VALUE);
option.setSection(section); option.setSection(section);
option.setLabel(label); option.setLabel(label);
option.setValue(value); option.setValue(value);
if (m_container != null) { if (m_container != null) {
m_container.onlyShowComponent( m_container.onlyShowComponent(
state, state,
DecisionTreeOptionStep.OPTION_TABLE + DecisionTreeOptionStep.OPTION_TABLE + m_container.getTypeIDStr());
m_container.getTypeIDStr()); }
}
} }
@Override @Override

View File

@ -59,12 +59,12 @@ import com.arsdigita.globalization.GlobalizedMessage;
* @version $Id$ * @version $Id$
*/ */
public class DecisionTreeTargetEditForm extends Form public class DecisionTreeTargetEditForm extends Form
implements FormInitListener, implements FormInitListener,
FormProcessListener, FormProcessListener,
FormSubmissionListener { FormSubmissionListener {
private final static Logger s_log = Logger.getLogger( private final static Logger s_log = Logger.getLogger(
DecisionTreeTargetEditForm.class); DecisionTreeTargetEditForm.class);
private ItemSelectionModel m_selTree; private ItemSelectionModel m_selTree;
private ItemSelectionModel m_selTarget; private ItemSelectionModel m_selTarget;
@ -74,11 +74,11 @@ public class DecisionTreeTargetEditForm extends Form
private SaveCancelSection m_saveCancelSection; private SaveCancelSection m_saveCancelSection;
// private SingleSelect m_sectionWidget; // private SingleSelect m_sectionWidget;
private SingleSelect m_matchValueWidget; private SingleSelect m_matchValueWidget;
private SingleSelect m_targetSectionWidget; private SingleSelect m_targetSectionWidget;
private TextField m_targetURLWidget; private TextField m_targetURLWidget;
public static final String MATCH_OPTION = "matchOption"; public static final String MATCH_OPTION = "matchOption";
public static final String TARGET_URL = "targetURL"; public static final String TARGET_URL = "targetURL";
public static final String TARGET_SECTION = "targetSection"; public static final String TARGET_SECTION = "targetSection";
/** /**
@ -111,7 +111,7 @@ public class DecisionTreeTargetEditForm extends Form
setMethod(Form.POST); setMethod(Form.POST);
setEncType("multipart/form-data"); setEncType("multipart/form-data");
ColumnPanel panel = (ColumnPanel)getPanel(); ColumnPanel panel = (ColumnPanel) getPanel();
panel.setBorder(false); panel.setBorder(false);
panel.setPadColor("#FFFFFF"); panel.setPadColor("#FFFFFF");
panel.setColumnWidth(1, "20%"); panel.setColumnWidth(1, "20%");
@ -139,6 +139,7 @@ public class DecisionTreeTargetEditForm extends Form
/** /**
* Returns the save/cancel section from this form. * Returns the save/cancel section from this form.
*
* @return * @return
*/ */
public SaveCancelSection getSaveCancelSection() { public SaveCancelSection getSaveCancelSection() {
@ -149,9 +150,11 @@ public class DecisionTreeTargetEditForm extends Form
* Set up the dynamic options for the section select widget. * Set up the dynamic options for the section select widget.
*/ */
private void initSectionOptions(PrintEvent e) { private void initSectionOptions(PrintEvent e) {
PageState state = e.getPageState(); PageState state = e.getPageState();
SingleSelect target = (SingleSelect) e.getTarget(); SingleSelect target = (SingleSelect) e.getTarget();
DecisionTree tree = (DecisionTree)m_selTree.getSelectedObject(state); target.clearOptions();
DecisionTree tree = (DecisionTree) m_selTree.getSelectedObject(state);
if (tree != null) { if (tree != null) {
DecisionTreeSectionCollection sections = tree.getSections(); DecisionTreeSectionCollection sections = tree.getSections();
@ -171,9 +174,10 @@ public class DecisionTreeTargetEditForm extends Form
* Set up the dynamic options for the target select widget. * Set up the dynamic options for the target select widget.
*/ */
private void initTargetOptions(PrintEvent e) { private void initTargetOptions(PrintEvent e) {
PageState state = e.getPageState(); PageState state = e.getPageState();
SingleSelect target = (SingleSelect) e.getTarget(); SingleSelect target = (SingleSelect) e.getTarget();
DecisionTree tree = (DecisionTree)m_selTree.getSelectedObject(state); target.clearOptions();
DecisionTree tree = (DecisionTree) m_selTree.getSelectedObject(state);
if (tree != null) { if (tree != null) {
DecisionTreeSectionCollection sections = tree.getSections(); DecisionTreeSectionCollection sections = tree.getSections();
@ -193,28 +197,31 @@ public class DecisionTreeTargetEditForm extends Form
* Set up the dynamic options for the match value select widget. * Set up the dynamic options for the match value select widget.
*/ */
private void initMatchOptions(PrintEvent e) { private void initMatchOptions(PrintEvent e) {
PageState state = e.getPageState(); PageState state = e.getPageState();
SingleSelect target = (SingleSelect) e.getTarget(); SingleSelect target = (SingleSelect) e.getTarget();
DecisionTree tree = (DecisionTree)m_selTree.getSelectedObject(state); target.clearOptions();
DecisionTree tree = (DecisionTree) m_selTree.getSelectedObject(state);
if (tree != null) { if (tree != null) {
DecisionTreeSectionOptionCollection sectionOptions = tree.getOptions(); DecisionTreeSectionOptionCollection sectionOptions = tree.getOptions();
if (sectionOptions != null) { if (sectionOptions != null) {
while (sectionOptions.next()) { while (sectionOptions.next()) {
DecisionTreeSectionOption sectionOption = sectionOptions DecisionTreeSectionOption sectionOption = sectionOptions
.getOption(); .getOption();
String label = sectionOption.getSection().getTitle() + String label = sectionOption.getSection().getTitle() + " : " + sectionOption.
" : " + sectionOption.getLabel(); getLabel();
Option option = new Option(sectionOption.getID().toString(), Option option = new Option(sectionOption.getID().toString(),
label); label);
target.addOption(option, state); target.addOption(option, state);
} }
sectionOptions.close(); sectionOptions.close();
} }
} }
} }
/** Form initialisation hook. Sets the options for select widgets. /**
* Form initialisation hook. Sets the options for select widgets.
*
* @param fse * @param fse
*/ */
@Override @Override
@ -224,15 +231,16 @@ public class DecisionTreeTargetEditForm extends Form
if (m_selTarget.getSelectedKey(state) != null) { if (m_selTarget.getSelectedKey(state) != null) {
BigDecimal id = new BigDecimal(m_selTarget.getSelectedKey(state) BigDecimal id = new BigDecimal(m_selTarget.getSelectedKey(state)
.toString()); .toString());
DecisionTreeOptionTarget target = new DecisionTreeOptionTarget(id); DecisionTreeOptionTarget target = new DecisionTreeOptionTarget(id);
data.put(MATCH_OPTION, target.getMatchOption().getID()); data.put(MATCH_OPTION, target.getMatchOption().getID());
data.put(TARGET_URL, target.getTargetURL()); data.put(TARGET_URL, target.getTargetURL());
DecisionTreeSection targetSection = target.getTargetSection(); DecisionTreeSection targetSection = target.getTargetSection();
if (targetSection != null) if (targetSection != null) {
data.put(TARGET_SECTION, targetSection.getID()); data.put(TARGET_SECTION, targetSection.getID());
}
} }
} }
@ -241,47 +249,47 @@ public class DecisionTreeTargetEditForm extends Form
*/ */
protected void addWidgets() { protected void addWidgets() {
Option pleaseSelect = new Option( Option pleaseSelect = new Option(
"", "",
new Label(DecisionTreeGlobalizationUtil.globalize( new Label(DecisionTreeGlobalizationUtil.globalize(
"cms.contenttypes.ui.decisiontree.targets.form.please_select") )); "cms.contenttypes.ui.decisiontree.targets.form.please_select")));
Option none = new Option( Option none = new Option(
"", "",
new Label( DecisionTreeGlobalizationUtil.globalize( new Label(DecisionTreeGlobalizationUtil.globalize(
"cms.contenttypes.ui.decisiontree.targets.form.none"))); "cms.contenttypes.ui.decisiontree.targets.form.none")));
// add(new Label(DecisionTreeGlobalizationUtil.globalize( // add(new Label(DecisionTreeGlobalizationUtil.globalize(
// "cms.contenttypes.ui.decisiontree.targets.form.match_value"))); // "cms.contenttypes.ui.decisiontree.targets.form.match_value")));
m_matchValueWidget = new SingleSelect(MATCH_OPTION); m_matchValueWidget = new SingleSelect(MATCH_OPTION);
m_matchValueWidget.setLabel(DecisionTreeGlobalizationUtil.globalize( m_matchValueWidget.setLabel(DecisionTreeGlobalizationUtil.globalize(
"cms.contenttypes.ui.decisiontree.targets.form.match_value")); "cms.contenttypes.ui.decisiontree.targets.form.match_value"));
m_matchValueWidget.addValidationListener(new NotNullValidationListener()); m_matchValueWidget.addValidationListener(new NotNullValidationListener());
m_matchValueWidget.addOption(pleaseSelect); m_matchValueWidget.addOption(pleaseSelect);
try { try {
m_matchValueWidget.addPrintListener(new PrintListener() { m_matchValueWidget.addPrintListener(new PrintListener() {
@Override @Override
public void prepare(PrintEvent e) { public void prepare(PrintEvent e) {
initMatchOptions(e); initMatchOptions(e);
} }
}); });
} catch (TooManyListenersException e) { } catch (TooManyListenersException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
add(m_matchValueWidget); add(m_matchValueWidget);
// add(new Label(DecisionTreeGlobalizationUtil.globalize( // add(new Label(DecisionTreeGlobalizationUtil.globalize(
// "cms.contenttypes.ui.decisiontree.targets.form.target_url_label"))); // "cms.contenttypes.ui.decisiontree.targets.form.target_url_label")));
m_targetURLWidget = new TextField(TARGET_URL); m_targetURLWidget = new TextField(TARGET_URL);
m_targetURLWidget.setLabel(DecisionTreeGlobalizationUtil.globalize( m_targetURLWidget.setLabel(DecisionTreeGlobalizationUtil.globalize(
"cms.contenttypes.ui.decisiontree.targets.form.target_url_label")); "cms.contenttypes.ui.decisiontree.targets.form.target_url_label"));
m_targetURLWidget.setSize(60); m_targetURLWidget.setSize(60);
add(m_targetURLWidget); add(m_targetURLWidget);
// add(new Label(DecisionTreeGlobalizationUtil.globalize( // add(new Label(DecisionTreeGlobalizationUtil.globalize(
// "cms.contenttypes.ui.decisiontree.targets.form.target_section_label"))); // "cms.contenttypes.ui.decisiontree.targets.form.target_section_label")));
m_targetSectionWidget = new SingleSelect(TARGET_SECTION); m_targetSectionWidget = new SingleSelect(TARGET_SECTION);
m_targetSectionWidget.setLabel(DecisionTreeGlobalizationUtil.globalize( m_targetSectionWidget.setLabel(DecisionTreeGlobalizationUtil.globalize(
"cms.contenttypes.ui.decisiontree.targets.form.target_section_label")); "cms.contenttypes.ui.decisiontree.targets.form.target_section_label"));
m_targetSectionWidget.addOption(none); m_targetSectionWidget.addOption(none);
try { try {
m_targetSectionWidget.addPrintListener(new PrintListener() { m_targetSectionWidget.addPrintListener(new PrintListener() {
@Override @Override
@ -289,7 +297,7 @@ public class DecisionTreeTargetEditForm extends Form
initTargetOptions(e); initTargetOptions(e);
} }
}); });
} catch (TooManyListenersException e) { } catch (TooManyListenersException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
add(m_targetSectionWidget); add(m_targetSectionWidget);
@ -300,87 +308,86 @@ public class DecisionTreeTargetEditForm extends Form
throws FormProcessException { throws FormProcessException {
final PageState state = event.getPageState(); final PageState state = event.getPageState();
if ("".equals(m_targetURLWidget.getValue(state)) if ("".equals(m_targetURLWidget.getValue(state))
&& "".equals(m_targetSectionWidget.getValue(state))) { && "".equals(m_targetSectionWidget.getValue(state))) {
GlobalizedMessage msg = DecisionTreeGlobalizationUtil.globalize( GlobalizedMessage msg = DecisionTreeGlobalizationUtil.globalize(
"cms.contenttypes.ui.decisiontree.targets.form.target_required"); "cms.contenttypes.ui.decisiontree.targets.form.target_required");
throw new FormProcessException(msg); throw new FormProcessException(msg);
} }
if (!"".equals(m_targetURLWidget.getValue(state)) if (!"".equals(m_targetURLWidget.getValue(state))
&& !"".equals(m_targetSectionWidget.getValue(state))) { && !"".equals(m_targetSectionWidget.getValue(state))) {
GlobalizedMessage msg = DecisionTreeGlobalizationUtil.globalize( GlobalizedMessage msg = DecisionTreeGlobalizationUtil.globalize(
"cms.contenttypes.ui.decisiontree.targets.form.duplicate_target"); "cms.contenttypes.ui.decisiontree.targets.form.duplicate_target");
throw new FormProcessException(msg); throw new FormProcessException(msg);
} }
} }
}); });
} }
/** /**
* Called on form submission. Check to see if the user clicked the * Called on form submission. Check to see if the user clicked the cancel button. If they did,
* cancel button. If they did, don't continue with the form. * don't continue with the form.
*
* @param event * @param event
* @throws com.arsdigita.bebop.FormProcessException * @throws com.arsdigita.bebop.FormProcessException
*/ */
@Override @Override
public void submitted(FormSectionEvent event) public void submitted(FormSectionEvent event)
throws FormProcessException { throws FormProcessException {
PageState state = event.getPageState(); PageState state = event.getPageState();
if ( m_saveCancelSection.getCancelButton().isSelected(state) if (m_saveCancelSection.getCancelButton().isSelected(state)
&& m_container != null) { && m_container != null) {
m_container.onlyShowComponent(state, m_container.onlyShowComponent(state,
DecisionTreeTargetStep.TARGET_TABLE + DecisionTreeTargetStep.TARGET_TABLE + m_container.
m_container.getTypeIDStr()); getTypeIDStr());
throw new FormProcessException( throw new FormProcessException(
DecisionTreeGlobalizationUtil.globalize( 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 * Called after form has been validated. Create the new DecisionTreeOptionTarget and assign it
* DecisionTreeOptionTarget and assign it to the current DecisionTree. * to the current DecisionTree.
* *
* @param event * @param event
* @throws com.arsdigita.bebop.FormProcessException * @throws com.arsdigita.bebop.FormProcessException
*/ */
@Override @Override
public void process(FormSectionEvent event) throws FormProcessException { public void process(FormSectionEvent event) throws FormProcessException {
PageState state = event.getPageState(); PageState state = event.getPageState();
FormData data = event.getFormData(); FormData data = event.getFormData();
DecisionTreeSectionOption matchOption = new DecisionTreeSectionOption matchOption = new DecisionTreeSectionOption(new BigDecimal(
DecisionTreeSectionOption(new (String) data.get(MATCH_OPTION)));
BigDecimal((String)data.get(MATCH_OPTION)));
DecisionTreeSection targetSection = null; DecisionTreeSection targetSection = null;
String sectionID = (String)data.get(TARGET_SECTION); String sectionID = (String) data.get(TARGET_SECTION);
if (!"".equals(sectionID)) { if (!"".equals(sectionID)) {
targetSection = new DecisionTreeSection(new BigDecimal(sectionID)); targetSection = new DecisionTreeSection(new BigDecimal(sectionID));
} }
DecisionTreeOptionTarget target; DecisionTreeOptionTarget target;
if (m_selTarget.getSelectedKey(state) != null) { if (m_selTarget.getSelectedKey(state) != null) {
BigDecimal id = new BigDecimal(m_selTarget BigDecimal id = new BigDecimal(m_selTarget
.getSelectedKey(state).toString()); .getSelectedKey(state).toString());
target = new DecisionTreeOptionTarget(id); target = new DecisionTreeOptionTarget(id);
} else { } else {
target = new DecisionTreeOptionTarget(); target = new DecisionTreeOptionTarget();
target.setName("OptionTarget " + target.getID()); target.setName("OptionTarget " + target.getID());
} }
target.setMatchOption(matchOption); target.setMatchOption(matchOption);
target.setTargetURL((String)data.get(TARGET_URL)); target.setTargetURL((String) data.get(TARGET_URL));
target.setTargetSection(targetSection); target.setTargetSection(targetSection);
if (m_container != null) { if (m_container != null) {
m_container.onlyShowComponent( m_container.onlyShowComponent(
state, state,
DecisionTreeTargetStep.TARGET_TABLE + DecisionTreeTargetStep.TARGET_TABLE + m_container.getTypeIDStr());
m_container.getTypeIDStr()); }
}
} }
@Override @Override

View File

@ -76,6 +76,7 @@ public class ContentSectionCreateForm extends Form {
@Override @Override
public void prepare(final PrintEvent event) { public void prepare(final PrintEvent event) {
final SingleSelect target = (SingleSelect) event.getTarget(); final SingleSelect target = (SingleSelect) event.getTarget();
target.clearOptions();
final DataCollection categories = SessionManager.getSession().retrieve( final DataCollection categories = SessionManager.getSession().retrieve(
Category.BASE_DATA_OBJECT_TYPE); Category.BASE_DATA_OBJECT_TYPE);

View File

@ -124,9 +124,6 @@ public class GenericAddressPropertyForm extends BasicPageForm
SingleSelect country = new SingleSelect(countryParam); SingleSelect country = new SingleSelect(countryParam);
country.setLabel(ContenttypesGlobalizationUtil country.setLabel(ContenttypesGlobalizationUtil
.globalize("cms.contenttypes.ui.address.iso_country_code")); .globalize("cms.contenttypes.ui.address.iso_country_code"));
country.addOption(new Option("",
new Label(GlobalizationUtil
.globalize("cms.ui.select_one"))));
try { try {
country.addPrintListener(new PrintListener() { country.addPrintListener(new PrintListener() {
@ -134,9 +131,14 @@ public class GenericAddressPropertyForm extends BasicPageForm
@Override @Override
public void prepare(final PrintEvent event) { public void prepare(final PrintEvent event) {
final SingleSelect target = (SingleSelect) event.getTarget(); final SingleSelect target = (SingleSelect) event.getTarget();
target.clearOptions();
final Iterator countries = GenericAddress.getSortedListOfCountries(null) final Iterator countries = GenericAddress.getSortedListOfCountries(null)
.entrySet().iterator(); .entrySet().iterator();
target.addOption(new Option("",
new Label(GlobalizationUtil
.globalize("cms.ui.select_one"))));
while (countries.hasNext()) { while (countries.hasNext()) {
Map.Entry<String, String> elem = (Map.Entry<String, String>) countries Map.Entry<String, String> elem = (Map.Entry<String, String>) countries
.next(); .next();

View File

@ -118,15 +118,18 @@ public class GenericContactAttachPersonPropertyForm extends BasicPageForm
contactType.setLabel(ContenttypesGlobalizationUtil.globalize( contactType.setLabel(ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.genericperson.contact.type")); "cms.contenttypes.ui.genericperson.contact.type"));
contactType.addValidationListener(new NotNullValidationListener()); contactType.addValidationListener(new NotNullValidationListener());
contactType.addOption(new Option("",
new Label(GlobalizationUtil
.globalize("cms.ui.select_one"))));
try { try {
contactType.addPrintListener(new PrintListener() { contactType.addPrintListener(new PrintListener() {
@Override @Override
public void prepare(final PrintEvent event) { public void prepare(final PrintEvent event) {
final SingleSelect target = (SingleSelect) event.getTarget(); final SingleSelect target = (SingleSelect) event.getTarget();
target.clearOptions();
target.addOption(new Option("",
new Label(GlobalizationUtil
.globalize("cms.ui.select_one"))));
final GenericContactTypeCollection contacttypes final GenericContactTypeCollection contacttypes
= new GenericContactTypeCollection(); = new GenericContactTypeCollection();

View File

@ -57,12 +57,12 @@ import org.apache.log4j.Logger;
* @author quasi, Created on 8. Juli 2009, 10:27 * @author quasi, Created on 8. Juli 2009, 10:27
*/ */
public class GenericContactEditAddressPropertyForm extends BasicPageForm public class GenericContactEditAddressPropertyForm extends BasicPageForm
implements FormProcessListener, implements FormProcessListener,
FormInitListener, FormInitListener,
FormSubmissionListener { FormSubmissionListener {
private static final Logger logger = Logger.getLogger( private static final Logger logger = Logger.getLogger(
GenericContactPropertyForm.class); GenericContactPropertyForm.class);
public static final String ADDRESS = GenericAddress.ADDRESS; public static final String ADDRESS = GenericAddress.ADDRESS;
public static final String POSTAL_CODE = GenericAddress.POSTAL_CODE; public static final String POSTAL_CODE = GenericAddress.POSTAL_CODE;
@ -106,7 +106,7 @@ public class GenericContactEditAddressPropertyForm extends BasicPageForm
addressParam.addParameterListener(new StringInRangeValidationListener(0, 1000)); addressParam.addParameterListener(new StringInRangeValidationListener(0, 1000));
TextArea address = new TextArea(addressParam); TextArea address = new TextArea(addressParam);
address.setLabel(ContenttypesGlobalizationUtil address.setLabel(ContenttypesGlobalizationUtil
.globalize("cms.contenttypes.ui.address.address")); .globalize("cms.contenttypes.ui.address.address"));
address.setRows(5); address.setRows(5);
address.setCols(30); address.setCols(30);
add(address); add(address);
@ -115,7 +115,7 @@ public class GenericContactEditAddressPropertyForm extends BasicPageForm
ParameterModel postalCodeParam = new StringParameter(POSTAL_CODE); ParameterModel postalCodeParam = new StringParameter(POSTAL_CODE);
TextField postalCode = new TextField(postalCodeParam); TextField postalCode = new TextField(postalCodeParam);
postalCode.setLabel(ContenttypesGlobalizationUtil postalCode.setLabel(ContenttypesGlobalizationUtil
.globalize("cms.contenttypes.ui.address.postal_code")); .globalize("cms.contenttypes.ui.address.postal_code"));
/* XXX NumberListener ?*/ /* XXX NumberListener ?*/
add(postalCode); add(postalCode);
} }
@ -123,14 +123,14 @@ public class GenericContactEditAddressPropertyForm extends BasicPageForm
ParameterModel cityParam = new StringParameter(CITY); ParameterModel cityParam = new StringParameter(CITY);
TextField city = new TextField(cityParam); TextField city = new TextField(cityParam);
city.setLabel(ContenttypesGlobalizationUtil city.setLabel(ContenttypesGlobalizationUtil
.globalize("cms.contenttypes.ui.address.city")); .globalize("cms.contenttypes.ui.address.city"));
add(city); add(city);
if (!GenericContact.getConfig().getHideAddressState()) { if (!GenericContact.getConfig().getHideAddressState()) {
ParameterModel stateParam = new StringParameter(STATE); ParameterModel stateParam = new StringParameter(STATE);
TextField state = new TextField(stateParam); TextField state = new TextField(stateParam);
state.setLabel(ContenttypesGlobalizationUtil state.setLabel(ContenttypesGlobalizationUtil
.globalize("cms.contenttypes.ui.address.state")); .globalize("cms.contenttypes.ui.address.state"));
add(state); add(state);
} }
@ -140,11 +140,7 @@ public class GenericContactEditAddressPropertyForm extends BasicPageForm
SingleSelect country = new SingleSelect(countryParam); SingleSelect country = new SingleSelect(countryParam);
country.setLabel(ContenttypesGlobalizationUtil.globalize( country.setLabel(ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.address.iso_country_code")); "cms.contenttypes.ui.address.iso_country_code"));
country.addOption(new Option("",
new Label(ContenttypesGlobalizationUtil
.globalize("cms.ui.select_one"))));
try { try {
country.addPrintListener(new PrintListener() { country.addPrintListener(new PrintListener() {
@ -152,14 +148,19 @@ public class GenericContactEditAddressPropertyForm extends BasicPageForm
@Override @Override
public void prepare(final PrintEvent event) { public void prepare(final PrintEvent event) {
final SingleSelect target = (SingleSelect) event.getTarget(); 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) final Iterator countries = GenericAddress.getSortedListOfCountries(null)
.entrySet().iterator(); .entrySet().iterator();
while (countries.hasNext()) { while (countries.hasNext()) {
Map.Entry<String, String> elem = (Map.Entry<String, String>) countries Map.Entry<String, String> elem = (Map.Entry<String, String>) countries
.next(); .next();
target.addOption(new Option(elem.getValue().toString(), target.addOption(new Option(elem.getValue().toString(),
elem.getKey().toString())); elem.getKey().toString()));
} }
} }
@ -169,21 +170,21 @@ public class GenericContactEditAddressPropertyForm extends BasicPageForm
} }
country.addValidationListener( country.addValidationListener(
new ParameterListener() { new ParameterListener() {
@Override @Override
public void validate(ParameterEvent e) throws FormProcessException { public void validate(ParameterEvent e) throws FormProcessException {
ParameterData data = e.getParameterData(); ParameterData data = e.getParameterData();
String isoCode = (String) data.getValue(); String isoCode = (String) data.getValue();
if (isoCode == null || isoCode.length() == 0) { if (isoCode == null || isoCode.length() == 0) {
data.addError((String) ContenttypesGlobalizationUtil data.addError((String) ContenttypesGlobalizationUtil
.globalize( .globalize(
"cms.contenttypes.ui.address.error_iso_country") "cms.contenttypes.ui.address.error_iso_country")
.localize()); .localize());
}
} }
}
}); });
add(country); add(country);
} }
@ -210,7 +211,7 @@ public class GenericContactEditAddressPropertyForm extends BasicPageForm
@Override @Override
public void submitted(FormSectionEvent fse) { public void submitted(FormSectionEvent fse) {
if (m_step != null if (m_step != null
&& getSaveCancelSection().getCancelButton().isSelected(fse.getPageState())) { && getSaveCancelSection().getCancelButton().isSelected(fse.getPageState())) {
m_step.cancelStreamlinedCreation(fse.getPageState()); m_step.cancelStreamlinedCreation(fse.getPageState());
} }
} }

View File

@ -56,9 +56,9 @@ import org.apache.log4j.Logger;
* @author quasi * @author quasi
*/ */
public class GenericContactEditPersonPropertyForm extends BasicPageForm public class GenericContactEditPersonPropertyForm extends BasicPageForm
implements FormProcessListener, implements FormProcessListener,
FormInitListener, FormInitListener,
FormSubmissionListener { FormSubmissionListener {
private static final Logger logger = Logger.getLogger(GenericContactPropertyForm.class); private static final Logger logger = Logger.getLogger(GenericContactPropertyForm.class);
private GenericContactPersonPropertiesStep m_step; private GenericContactPersonPropertiesStep m_step;
@ -106,7 +106,7 @@ public class GenericContactEditPersonPropertyForm extends BasicPageForm
surnameParam.addParameterListener(new StringInRangeValidationListener(0, 1000)); surnameParam.addParameterListener(new StringInRangeValidationListener(0, 1000));
TextField surname = new TextField(surnameParam); TextField surname = new TextField(surnameParam);
surname.setLabel(ContenttypesGlobalizationUtil surname.setLabel(ContenttypesGlobalizationUtil
.globalize("cms.contenttypes.ui.person.surname")); .globalize("cms.contenttypes.ui.person.surname"));
add(surname); add(surname);
ParameterModel givennameParam = new StringParameter(GIVENNAME); ParameterModel givennameParam = new StringParameter(GIVENNAME);
@ -114,43 +114,45 @@ public class GenericContactEditPersonPropertyForm extends BasicPageForm
givennameParam.addParameterListener(new StringInRangeValidationListener(0, 1000)); givennameParam.addParameterListener(new StringInRangeValidationListener(0, 1000));
TextField givenname = new TextField(givennameParam); TextField givenname = new TextField(givennameParam);
givenname.setLabel(ContenttypesGlobalizationUtil givenname.setLabel(ContenttypesGlobalizationUtil
.globalize("cms.contenttypes.ui.person.givenname")); .globalize("cms.contenttypes.ui.person.givenname"));
add(givenname); add(givenname);
ParameterModel titlepreParam = new StringParameter(TITLEPRE); ParameterModel titlepreParam = new StringParameter(TITLEPRE);
titlepreParam.addParameterListener(new StringInRangeValidationListener(0, 1000)); titlepreParam.addParameterListener(new StringInRangeValidationListener(0, 1000));
TextField titlepre = new TextField(titlepreParam); TextField titlepre = new TextField(titlepreParam);
titlepre.setLabel(ContenttypesGlobalizationUtil titlepre.setLabel(ContenttypesGlobalizationUtil
.globalize("cms.contenttypes.ui.person.titlepre")); .globalize("cms.contenttypes.ui.person.titlepre"));
add(titlepre); add(titlepre);
ParameterModel titlepostParam = new StringParameter(TITLEPOST); ParameterModel titlepostParam = new StringParameter(TITLEPOST);
titlepostParam.addParameterListener(new StringInRangeValidationListener(0, 1000)); titlepostParam.addParameterListener(new StringInRangeValidationListener(0, 1000));
TextField titlepost = new TextField(titlepostParam); TextField titlepost = new TextField(titlepostParam);
titlepost.setLabel(ContenttypesGlobalizationUtil titlepost.setLabel(ContenttypesGlobalizationUtil
.globalize("cms.contenttypes.ui.person.titlepost")); .globalize("cms.contenttypes.ui.person.titlepost"));
add(titlepost); add(titlepost);
// GenericContact type field // GenericContact type field
ParameterModel contactTypeParam = new StringParameter(CONTACTS_KEY); ParameterModel contactTypeParam = new StringParameter(CONTACTS_KEY);
SingleSelect contactType = new SingleSelect(contactTypeParam); SingleSelect contactType = new SingleSelect(contactTypeParam);
contactType.setLabel(ContenttypesGlobalizationUtil contactType.setLabel(ContenttypesGlobalizationUtil
.globalize("cms.contenttypes.ui.person.contact.type")); .globalize("cms.contenttypes.ui.person.contact.type"));
contactType.addValidationListener(new NotNullValidationListener()); contactType.addValidationListener(new NotNullValidationListener());
contactType.addOption(new Option("",
new Label(GlobalizationUtil
.globalize("cms.ui.select_one"))));
try { try {
contactType.addPrintListener(new PrintListener() { contactType.addPrintListener(new PrintListener() {
@Override @Override
public void prepare(final PrintEvent event) { public void prepare(final PrintEvent event) {
final SingleSelect target = (SingleSelect) event.getTarget(); final SingleSelect target = (SingleSelect) event.getTarget();
target.clearOptions();
target.addOption(new Option("",
new Label(GlobalizationUtil
.globalize("cms.ui.select_one"))));
final GenericContactTypeCollection contacttypes final GenericContactTypeCollection contacttypes
= new GenericContactTypeCollection(); = new GenericContactTypeCollection();
contacttypes.addLanguageFilter(GlobalizationHelper contacttypes.addLanguageFilter(GlobalizationHelper
.getNegotiatedLocale().getLanguage()); .getNegotiatedLocale().getLanguage());
while (contacttypes.next()) { while (contacttypes.next()) {
RelationAttribute ct = contacttypes.getRelationAttribute(); RelationAttribute ct = contacttypes.getRelationAttribute();
@ -171,7 +173,7 @@ public class GenericContactEditPersonPropertyForm extends BasicPageForm
FormData data = fse.getFormData(); FormData data = fse.getFormData();
PageState state = fse.getPageState(); PageState state = fse.getPageState();
GenericContact contact = (GenericContact) getItemSelectionModel() GenericContact contact = (GenericContact) getItemSelectionModel()
.getSelectedObject(state); .getSelectedObject(state);
if (contact.getPerson() != null) { if (contact.getPerson() != null) {
data.put(SURNAME, contact.getPerson().getSurname()); data.put(SURNAME, contact.getPerson().getSurname());
@ -184,7 +186,7 @@ public class GenericContactEditPersonPropertyForm extends BasicPageForm
public void submitted(FormSectionEvent fse) { public void submitted(FormSectionEvent fse) {
if (m_step != null if (m_step != null
&& getSaveCancelSection().getCancelButton().isSelected(fse.getPageState())) { && getSaveCancelSection().getCancelButton().isSelected(fse.getPageState())) {
m_step.cancelStreamlinedCreation(fse.getPageState()); m_step.cancelStreamlinedCreation(fse.getPageState());
} }
} }
@ -193,7 +195,7 @@ public class GenericContactEditPersonPropertyForm extends BasicPageForm
FormData data = fse.getFormData(); FormData data = fse.getFormData();
PageState state = fse.getPageState(); PageState state = fse.getPageState();
GenericContact contact = (GenericContact) getItemSelectionModel() GenericContact contact = (GenericContact) getItemSelectionModel()
.getSelectedObject(state); .getSelectedObject(state);
if (getSaveCancelSection().getSaveButton().isSelected(fse.getPageState())) { if (getSaveCancelSection().getSaveButton().isSelected(fse.getPageState())) {

View File

@ -74,14 +74,16 @@ public class GenericContactEntryAddForm extends BasicItemForm {
contactEntryKey.setLabel(ContenttypesGlobalizationUtil.globalize( contactEntryKey.setLabel(ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.genericcontact.contactEntry.key")); "cms.contenttypes.ui.genericcontact.contactEntry.key"));
contactEntryKey.addValidationListener(new NotNullValidationListener()); contactEntryKey.addValidationListener(new NotNullValidationListener());
contactEntryKey.addOption(new Option("", new Label(GlobalizationUtil.globalize(
"cms.ui.select_one"))));
try { try {
contactEntryKey.addPrintListener(new PrintListener() { contactEntryKey.addPrintListener(new PrintListener() {
@Override @Override
public void prepare(final PrintEvent event) { public void prepare(final PrintEvent event) {
final SingleSelect target = (SingleSelect) event.getTarget(); 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(); final GenericContactEntryKeys keyList = new GenericContactEntryKeys();
// keyList.addLanguageFilter(GlobalizationHelper.getNegotiatedLocale() // keyList.addLanguageFilter(GlobalizationHelper.getNegotiatedLocale()

View File

@ -45,15 +45,15 @@ import org.apache.log4j.Logger;
/** /**
* Generates a form for creating new localisations for the given category. * 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 * This class is part of the admin GUI of CCM and extends the standard form in order to present
* in order to present forms for managing the multi-language categories. * forms for managing the multi-language categories.
* *
* @author Sören Bernstein <quasi@quasiweb.de> * @author Sören Bernstein <quasi@quasiweb.de>
*/ */
public class GenericContactTypeAddForm extends BasicItemForm { public class GenericContactTypeAddForm extends BasicItemForm {
private static final Logger s_log = Logger.getLogger( private static final Logger s_log = Logger.getLogger(
GenericContactTypeAddForm.class); GenericContactTypeAddForm.class);
public final static String KEY = RelationAttribute.KEY; public final static String KEY = RelationAttribute.KEY;
public final static String LANGUAGE = RelationAttribute.LANGUAGE; public final static String LANGUAGE = RelationAttribute.LANGUAGE;
@ -63,7 +63,9 @@ public class GenericContactTypeAddForm extends BasicItemForm {
private ItemSelectionModel m_itemModel; private ItemSelectionModel m_itemModel;
private SingleSelect language; private SingleSelect language;
/** Creates a new instance of CategoryLocalizationAddForm */ /**
* Creates a new instance of CategoryLocalizationAddForm
*/
public GenericContactTypeAddForm(ItemSelectionModel itemModel) { public GenericContactTypeAddForm(ItemSelectionModel itemModel) {
super("ContactEntryAddForm", itemModel); super("ContactEntryAddForm", itemModel);
@ -79,16 +81,17 @@ public class GenericContactTypeAddForm extends BasicItemForm {
keyParam.addParameterListener(new StringInRangeValidationListener(0, 1000)); keyParam.addParameterListener(new StringInRangeValidationListener(0, 1000));
TextField key = new TextField(keyParam); TextField key = new TextField(keyParam);
key.setLabel(ContenttypesGlobalizationUtil key.setLabel(ContenttypesGlobalizationUtil
.globalize("cms.contenttypes.ui.contacttypes.key")); .globalize("cms.contenttypes.ui.contacttypes.key"));
add(key); add(key);
// Language // Language
ParameterModel languageParam = new StringParameter(LANGUAGE); ParameterModel languageParam = new StringParameter(LANGUAGE);
language = new SingleSelect(languageParam); language = new SingleSelect(languageParam);
language.setLabel(ContenttypesGlobalizationUtil language.setLabel(ContenttypesGlobalizationUtil
.globalize("cms.contenttypes.ui.contacttypes.language")); .globalize("cms.contenttypes.ui.contacttypes.language"));
language.addValidationListener(new NotNullValidationListener()); 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 // Name
ParameterModel nameParam = new StringParameter(NAME); ParameterModel nameParam = new StringParameter(NAME);
@ -96,20 +99,18 @@ public class GenericContactTypeAddForm extends BasicItemForm {
nameParam.addParameterListener(new StringInRangeValidationListener(0, 1000)); nameParam.addParameterListener(new StringInRangeValidationListener(0, 1000));
TextField name = new TextField(nameParam); TextField name = new TextField(nameParam);
name.setLabel(ContenttypesGlobalizationUtil name.setLabel(ContenttypesGlobalizationUtil
.globalize("cms.contenttypes.ui.contacttypes.name")); .globalize("cms.contenttypes.ui.contacttypes.name"));
add(name); add(name);
} }
public void init(FormSectionEvent fse) { public void init(FormSectionEvent fse) {
FormData data = fse.getFormData(); FormData data = fse.getFormData();
PageState state = fse.getPageState(); PageState state = fse.getPageState();
RelationAttribute contacttype = (RelationAttribute) RelationAttribute contacttype = (RelationAttribute) getItemSelectionModel()
getItemSelectionModel() .getSelectedObject(state);
.getSelectedObject(state); GenericContactTypeCollection contacttypeCollection = new GenericContactTypeCollection(
GenericContactTypeCollection contacttypeCollection = new contacttype.getKey());
GenericContactTypeCollection(contacttype.getKey());
// all supported languages (by registry entry) // all supported languages (by registry entry)
KernelConfig kernelConfig = Kernel.getConfig(); KernelConfig kernelConfig = Kernel.getConfig();
@ -121,10 +122,9 @@ public class GenericContactTypeAddForm extends BasicItemForm {
// If lanuage exists, remove it from the selection list // If lanuage exists, remove it from the selection list
if (!contacttypeCollection.hasLanguage(code)) { if (!contacttypeCollection.hasLanguage(code)) {
language.addOption(new language.addOption(new Option(code,
Option(code, new Locale(code).getDisplayLanguage()),
new Locale(code).getDisplayLanguage()), state);
state);
} }
} }
@ -138,9 +138,8 @@ public class GenericContactTypeAddForm extends BasicItemForm {
public void process(FormSectionEvent fse) { public void process(FormSectionEvent fse) {
FormData data = fse.getFormData(); FormData data = fse.getFormData();
PageState state = fse.getPageState(); PageState state = fse.getPageState();
RelationAttribute contacttype = (RelationAttribute) RelationAttribute contacttype = (RelationAttribute) getItemSelectionModel()
getItemSelectionModel() .getSelectedObject(state);
.getSelectedObject(state);
// //
if (!this.getSaveCancelSection().getCancelButton().isSelected(state)) { if (!this.getSaveCancelSection().getCancelButton().isSelected(state)) {

View File

@ -56,11 +56,11 @@ import org.apache.log4j.Logger;
* @author Jens Pelzetter * @author Jens Pelzetter
*/ */
public class GenericOrganizationalUnitContactAddForm public class GenericOrganizationalUnitContactAddForm
extends BasicItemForm extends BasicItemForm
implements FormSubmissionListener { implements FormSubmissionListener {
private final static Logger s_log = Logger.getLogger( private final static Logger s_log = Logger.getLogger(
GenericOrganizationalUnitContactAddForm.class); GenericOrganizationalUnitContactAddForm.class);
private GenericOrganizationalUnitPropertiesStep m_step; private GenericOrganizationalUnitPropertiesStep m_step;
private ItemSearchWidget m_itemSearch; private ItemSearchWidget m_itemSearch;
private SaveCancelSection m_saveCancelSection; private SaveCancelSection m_saveCancelSection;
@ -80,12 +80,12 @@ public class GenericOrganizationalUnitContactAddForm
@Override @Override
protected void addWidgets() { protected void addWidgets() {
// add(new Label(ContenttypesGlobalizationUtil.globalize( // add(new Label(ContenttypesGlobalizationUtil.globalize(
// "cms.contenttypes.ui.genericorgaunit.select_contact"))); // "cms.contenttypes.ui.genericorgaunit.select_contact")));
m_itemSearch = new ItemSearchWidget(ITEM_SEARCH, ContentType. m_itemSearch = new ItemSearchWidget(ITEM_SEARCH, ContentType.
findByAssociatedObjectType(GenericContact.class findByAssociatedObjectType(GenericContact.class
.getName())); .getName()));
m_itemSearch.setLabel(ContenttypesGlobalizationUtil.globalize( m_itemSearch.setLabel(ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.genericorgaunit.select_contact")); "cms.contenttypes.ui.genericorgaunit.select_contact"));
m_itemSearch.setDisableCreatePane(false); m_itemSearch.setDisableCreatePane(false);
add(m_itemSearch); add(m_itemSearch);
@ -93,25 +93,28 @@ public class GenericOrganizationalUnitContactAddForm
add(selectedContactLabel); add(selectedContactLabel);
ParameterModel contactTypeParam = new StringParameter( ParameterModel contactTypeParam = new StringParameter(
GenericOrganizationalUnitContactCollection.CONTACT_TYPE); GenericOrganizationalUnitContactCollection.CONTACT_TYPE);
SingleSelect contactType = new SingleSelect(contactTypeParam); SingleSelect contactType = new SingleSelect(contactTypeParam);
contactType.setLabel(ContenttypesGlobalizationUtil.globalize( contactType.setLabel(ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.genericorgaunit.contact.type")); "cms.contenttypes.ui.genericorgaunit.contact.type"));
contactType.addValidationListener(new NotNullValidationListener()); contactType.addValidationListener(new NotNullValidationListener());
contactType.addOption(new Option("",
new Label(ContenttypesGlobalizationUtil.
globalize("cms.ui.select_one"))));
try { try {
contactType.addPrintListener(new PrintListener() { contactType.addPrintListener(new PrintListener() {
@Override @Override
public void prepare(final PrintEvent event) { public void prepare(final PrintEvent event) {
final SingleSelect target = (SingleSelect) event.getTarget(); final SingleSelect target = (SingleSelect) event.getTarget();
target.clearOptions();
target.addOption(new Option("",
new Label(ContenttypesGlobalizationUtil.
globalize("cms.ui.select_one"))));
final GenericOrganizationContactTypeCollection contacttypes final GenericOrganizationContactTypeCollection contacttypes
= new GenericOrganizationContactTypeCollection(); = new GenericOrganizationContactTypeCollection();
contacttypes.addLanguageFilter(GlobalizationHelper.getNegotiatedLocale(). contacttypes.addLanguageFilter(GlobalizationHelper.getNegotiatedLocale().
getLanguage()); getLanguage());
while (contacttypes.next()) { while (contacttypes.next()) {
RelationAttribute ct = contacttypes.getRelationAttribute(); RelationAttribute ct = contacttypes.getRelationAttribute();
@ -154,7 +157,7 @@ public class GenericOrganizationalUnitContactAddForm
FormData data = fse.getFormData(); FormData data = fse.getFormData();
PageState state = fse.getPageState(); PageState state = fse.getPageState();
GenericOrganizationalUnit orgaunit = (GenericOrganizationalUnit) getItemSelectionModel(). GenericOrganizationalUnit orgaunit = (GenericOrganizationalUnit) getItemSelectionModel().
getSelectedObject(state); getSelectedObject(state);
if (this.getSaveCancelSection().getSaveButton().isSelected(state)) { if (this.getSaveCancelSection().getSaveButton().isSelected(state)) {
GenericContact selectedContact; GenericContact selectedContact;
@ -164,17 +167,17 @@ public class GenericOrganizationalUnitContactAddForm
GenericContact contact = (GenericContact) data.get(ITEM_SEARCH); GenericContact contact = (GenericContact) data.get(ITEM_SEARCH);
if (orgaunit.getLanguage().equals( if (orgaunit.getLanguage().equals(
GlobalizationHelper.LANG_INDEPENDENT)) { GlobalizationHelper.LANG_INDEPENDENT)) {
contact = (GenericContact) contact.getContentBundle(). contact = (GenericContact) contact.getContentBundle().
getPrimaryInstance(); getPrimaryInstance();
} else { } else {
contact = (GenericContact) contact.getContentBundle(). contact = (GenericContact) contact.getContentBundle().
getInstance(orgaunit.getLanguage()); getInstance(orgaunit.getLanguage());
} }
orgaunit.addContact(contact, orgaunit.addContact(contact,
(String) data.get( (String) data.get(
GenericOrganizationalUnitContactCollection.CONTACT_TYPE)); GenericOrganizationalUnitContactCollection.CONTACT_TYPE));
} else { } else {
GenericOrganizationalUnitContactCollection contacts; GenericOrganizationalUnitContactCollection contacts;
@ -187,7 +190,7 @@ public class GenericOrganizationalUnitContactAddForm
} }
contacts.setContactType((String) data.get( contacts.setContactType((String) data.get(
GenericOrganizationalUnitContactCollection.CONTACT_TYPE)); GenericOrganizationalUnitContactCollection.CONTACT_TYPE));
editStep.setSelectedContact(null); editStep.setSelectedContact(null);
editStep.setSelectedContactType(null); editStep.setSelectedContactType(null);
@ -200,7 +203,7 @@ public class GenericOrganizationalUnitContactAddForm
public void submitted(FormSectionEvent fse) throws FormProcessException { public void submitted(FormSectionEvent fse) throws FormProcessException {
if (getSaveCancelSection().getCancelButton().isSelected( if (getSaveCancelSection().getCancelButton().isSelected(
fse.getPageState())) { fse.getPageState())) {
editStep.setSelectedContact(null); editStep.setSelectedContact(null);
editStep.setSelectedContactType(null); editStep.setSelectedContactType(null);
@ -214,16 +217,16 @@ public class GenericOrganizationalUnitContactAddForm
final FormData data = fse.getFormData(); final FormData data = fse.getFormData();
if ((editStep.getSelectedContact() == null) if ((editStep.getSelectedContact() == null)
&& (data.get(ITEM_SEARCH) == null)) { && (data.get(ITEM_SEARCH) == null)) {
data.addError((ContenttypesGlobalizationUtil.globalize( data.addError((ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.genericorgaunit.select_contact.no_contact_selected"))); "cms.contenttypes.ui.genericorgaunit.select_contact.no_contact_selected")));
return; return;
} }
if (editStep.getSelectedContact() == null) { if (editStep.getSelectedContact() == null) {
GenericOrganizationalUnit orgaunit = (GenericOrganizationalUnit) getItemSelectionModel() GenericOrganizationalUnit orgaunit = (GenericOrganizationalUnit) getItemSelectionModel()
.getSelectedObject(state); .getSelectedObject(state);
GenericContact contact = (GenericContact) data.get(ITEM_SEARCH); GenericContact contact = (GenericContact) data.get(ITEM_SEARCH);
@ -234,30 +237,30 @@ public class GenericOrganizationalUnitContactAddForm
Kernel.getConfig(). Kernel.getConfig().
languageIndependentItems()))) { languageIndependentItems()))) {
data.addError( data.addError(
ContenttypesGlobalizationUtil.globalize( ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.genericorgaunit.select_contact.no_suitable_language_variant")); "cms.contenttypes.ui.genericorgaunit.select_contact.no_suitable_language_variant"));
return; return;
} }
} }
if (orgaunit.getLanguage().equals( if (orgaunit.getLanguage().equals(
GlobalizationHelper.LANG_INDEPENDENT)) { GlobalizationHelper.LANG_INDEPENDENT)) {
contact = (GenericContact) contact.getContentBundle(). contact = (GenericContact) contact.getContentBundle().
getPrimaryInstance(); getPrimaryInstance();
} else { } else {
contact = (GenericContact) contact.getContentBundle(). contact = (GenericContact) contact.getContentBundle().
getInstance(orgaunit.getLanguage()); getInstance(orgaunit.getLanguage());
} }
GenericOrganizationalUnitContactCollection contacts = orgaunit. GenericOrganizationalUnitContactCollection contacts = orgaunit.
getContacts(); getContacts();
contacts.addFilter(String.format("id = %s", contacts.addFilter(String.format("id = %s",
contact.getID().toString())); contact.getID().toString()));
if (contacts.size() > 0) { if (contacts.size() > 0) {
data.addError( data.addError(
ContenttypesGlobalizationUtil.globalize( ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.genericorgaunit.select_contact.already_added")); "cms.contenttypes.ui.genericorgaunit.select_contact.already_added"));
} }
contacts.close(); contacts.close();

View File

@ -100,16 +100,19 @@ public class GenericOrganizationalUnitPersonAddForm
roleSelect.setLabel(ContenttypesGlobalizationUtil.globalize( roleSelect.setLabel(ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.genericorgaunit.person.role")); "cms.contenttypes.ui.genericorgaunit.person.role"));
roleSelect.addValidationListener(new NotNullValidationListener()); roleSelect.addValidationListener(new NotNullValidationListener());
roleSelect.addOption(
new Option("",
new Label(ContenttypesGlobalizationUtil
.globalize("cms.ui.select_one"))));
try { try {
roleSelect.addPrintListener(new PrintListener() { roleSelect.addPrintListener(new PrintListener() {
@Override @Override
public void prepare(final PrintEvent event) { public void prepare(final PrintEvent event) {
final SingleSelect target = (SingleSelect) event.getTarget(); 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( final RelationAttributeCollection roles = new RelationAttributeCollection(
getRoleAttributeName()); getRoleAttributeName());
@ -139,15 +142,18 @@ public class GenericOrganizationalUnitPersonAddForm
statusSelect.setLabel(ContenttypesGlobalizationUtil.globalize( statusSelect.setLabel(ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.genericorgaunit.person.status")); "cms.contenttypes.ui.genericorgaunit.person.status"));
statusSelect.addValidationListener(new NotNullValidationListener()); statusSelect.addValidationListener(new NotNullValidationListener());
statusSelect.addOption(new Option("",
new Label(ContenttypesGlobalizationUtil.
globalize("cms.ui.select_one"))));
try { try {
statusSelect.addPrintListener(new PrintListener() { statusSelect.addPrintListener(new PrintListener() {
@Override @Override
public void prepare(final PrintEvent event) { public void prepare(final PrintEvent event) {
final SingleSelect target = (SingleSelect) event.getTarget(); final SingleSelect target = (SingleSelect) event.getTarget();
target.clearOptions();
statusSelect.addOption(new Option("",
new Label(ContenttypesGlobalizationUtil.
globalize("cms.ui.select_one"))));
RelationAttributeCollection statusColl = new RelationAttributeCollection( RelationAttributeCollection statusColl = new RelationAttributeCollection(
getStatusAttributeName()); getStatusAttributeName());
statusColl.addLanguageFilter(Kernel.getConfig().getDefaultLanguage()); statusColl.addLanguageFilter(Kernel.getConfig().getDefaultLanguage());

View File

@ -100,15 +100,18 @@ public class GenericPersonContactAddForm extends BasicItemForm {
contactType.setLabel(ContenttypesGlobalizationUtil.globalize( contactType.setLabel(ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.genericperson.contact.type")); "cms.contenttypes.ui.genericperson.contact.type"));
contactType.addValidationListener(new NotNullValidationListener()); contactType.addValidationListener(new NotNullValidationListener());
contactType.addOption(new Option("",
new Label(GlobalizationUtil.
globalize("cms.ui.select_one"))));
try { try {
contactType.addPrintListener(new PrintListener() { contactType.addPrintListener(new PrintListener() {
@Override @Override
public void prepare(final PrintEvent event) { public void prepare(final PrintEvent event) {
final SingleSelect target = (SingleSelect) event.getTarget(); 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 // Add the Options to the SingleSelect widget
final GenericContactTypeCollection contacttypes final GenericContactTypeCollection contacttypes
= new GenericContactTypeCollection(); = new GenericContactTypeCollection();

View File

@ -231,6 +231,7 @@ public abstract class CategoryForm extends Form
public void prepare(PrintEvent e) { public void prepare(PrintEvent e) {
OptionGroup target = (OptionGroup) e.getTarget(); OptionGroup target = (OptionGroup) e.getTarget();
target.clearOptions();
PageState state = e.getPageState(); PageState state = e.getPageState();
Category root = getRootCategory(state); Category root = getRootCategory(state);
if (root == null) { if (root == null) {
@ -361,6 +362,7 @@ public abstract class CategoryForm extends Form
@Override @Override
public void prepare(PrintEvent e) { public void prepare(PrintEvent e) {
OptionGroup o = (OptionGroup) e.getTarget(); OptionGroup o = (OptionGroup) e.getTarget();
o.clearOptions();
PageState state = e.getPageState(); PageState state = e.getPageState();
CategoryMap m = getAssignedCategories(state); CategoryMap m = getAssignedCategories(state);

View File

@ -345,6 +345,7 @@ public class SectionConfigurationPage extends CMSPage implements Resettable {
public void prepare(PrintEvent event) { public void prepare(PrintEvent event) {
PageState state = event.getPageState(); PageState state = event.getPageState();
SingleSelect target = (SingleSelect) event.getTarget(); SingleSelect target = (SingleSelect) event.getTarget();
target.clearOptions();
addLocales(state, target); addLocales(state, target);
} }
}); });

View File

@ -686,6 +686,7 @@ public class PageCreateDynamic extends FormSection
public void prepare(PrintEvent event) { public void prepare(PrintEvent event) {
SingleSelect t = (SingleSelect) event.getTarget(); SingleSelect t = (SingleSelect) event.getTarget();
t.clearOptions();
PageState s = event.getPageState(); PageState s = event.getPageState();
//get the current content section //get the current content section

View File

@ -28,6 +28,7 @@ public abstract class AbstractFolderPicker extends SingleSelect {
@Override @Override
public void prepare(PrintEvent ev) { public void prepare(PrintEvent ev) {
((SingleSelect) ev.getTarget()).clearOptions();
addOptions(ev.getPageState(), addOptions(ev.getPageState(),
(SingleSelect) ev.getTarget()); (SingleSelect) ev.getTarget());
} }

View File

@ -256,6 +256,7 @@ class ItemLifecycleSelectForm extends BaseForm {
ldc.addOrder("label"); ldc.addOrder("label");
final SingleSelect target = (SingleSelect) e.getTarget(); final SingleSelect target = (SingleSelect) e.getTarget();
target.clearOptions();
while (ldc.next()) { while (ldc.next()) {
final LifecycleDefinition ld = ldc.getLifecycleDefinition(); final LifecycleDefinition ld = ldc.getLifecycleDefinition();

View File

@ -105,6 +105,7 @@ public class TemplateCreate extends BasicItemForm {
PageState state = e.getPageState(); PageState state = e.getPageState();
SingleSelect target = (SingleSelect)e.getTarget(); SingleSelect target = (SingleSelect)e.getTarget();
target.clearOptions();
TemplateContextCollection contexts = TemplateContext.retrieveAll(); TemplateContextCollection contexts = TemplateContext.retrieveAll();
contexts.addOrder(TemplateContext.LABEL); contexts.addOrder(TemplateContext.LABEL);

View File

@ -126,6 +126,7 @@ public class AddContentItemElement extends ElementAddForm {
public void prepare(PrintEvent event) { public void prepare(PrintEvent event) {
SingleSelect t = (SingleSelect) event.getTarget(); SingleSelect t = (SingleSelect) event.getTarget();
t.clearOptions();
// Get the current content section // Get the current content section
ContentSection section = CMS.getContext().getContentSection(); ContentSection section = CMS.getContext().getContentSection();

View File

@ -154,6 +154,7 @@ public class AddType extends CMSForm
public void prepare(PrintEvent event) { public void prepare(PrintEvent event) {
SingleSelect t = (SingleSelect) event.getTarget(); SingleSelect t = (SingleSelect) event.getTarget();
t.clearOptions();
//get the current content section //get the current content section
ContentSection section = CMS.getContext().getContentSection(); ContentSection section = CMS.getContext().getContentSection();

View File

@ -447,6 +447,7 @@ public class CreateType extends CMSForm
public void prepare(PrintEvent event) { public void prepare(PrintEvent event) {
SingleSelect t = (SingleSelect) event.getTarget(); SingleSelect t = (SingleSelect) event.getTarget();
t.clearOptions();
// Get the current content section // Get the current content section
ContentSection section = CMS.getContext().getContentSection(); ContentSection section = CMS.getContext().getContentSection();
@ -474,6 +475,7 @@ public class CreateType extends CMSForm
public void prepare(PrintEvent event) { public void prepare(PrintEvent event) {
SingleSelect t = (SingleSelect) event.getTarget(); SingleSelect t = (SingleSelect) event.getTarget();
t.clearOptions();
// Get the current content section // Get the current content section
ContentSection section = CMS.getContext().getContentSection(); ContentSection section = CMS.getContext().getContentSection();
@ -496,6 +498,7 @@ public class CreateType extends CMSForm
public void prepare(PrintEvent event) { public void prepare(PrintEvent event) {
SingleSelect t = (SingleSelect) event.getTarget(); SingleSelect t = (SingleSelect) event.getTarget();
t.clearOptions();
// Get the current content section // Get the current content section
ContentSection section = CMS.getContext().getContentSection(); ContentSection section = CMS.getContext().getContentSection();

View File

@ -301,6 +301,7 @@ public class EditType extends CMSForm
public void prepare(PrintEvent event) { public void prepare(PrintEvent event) {
SingleSelect t = (SingleSelect) event.getTarget(); SingleSelect t = (SingleSelect) event.getTarget();
t.clearOptions();
// Get the current content section // Get the current content section
ContentSection section = CMS.getContext().getContentSection(); ContentSection section = CMS.getContext().getContentSection();
@ -325,6 +326,7 @@ public class EditType extends CMSForm
public void prepare(PrintEvent event) { public void prepare(PrintEvent event) {
SingleSelect t = (SingleSelect) event.getTarget(); SingleSelect t = (SingleSelect) event.getTarget();
t.clearOptions();
// Get the current content section // Get the current content section
ContentSection section = CMS.getContext().getContentSection(); ContentSection section = CMS.getContext().getContentSection();

View File

@ -154,6 +154,7 @@ public class SearchAndSelect extends FormSection
&& (m_results.resultsCount() > 0))) { && (m_results.resultsCount() > 0))) {
OptionGroup outputWidget = (OptionGroup) e.getTarget(); OptionGroup outputWidget = (OptionGroup) e.getTarget();
outputWidget.clearOptions();
if (m_isOptional && !m_isMultiple) { if (m_isOptional && !m_isMultiple) {
outputWidget.addOption(new Option("", "None")); outputWidget.addOption(new Option("", "None"));

View File

@ -40,6 +40,7 @@ public abstract class AbstractCategoryPicker extends SingleSelect
try { try {
addPrintListener(new PrintListener() { addPrintListener(new PrintListener() {
public void prepare(PrintEvent ev) { public void prepare(PrintEvent ev) {
((SingleSelect) ev.getTarget()).clearOptions();
addOptions(ev.getPageState(), addOptions(ev.getPageState(),
(SingleSelect)ev.getTarget()); (SingleSelect)ev.getTarget());
} }

View File

@ -79,6 +79,7 @@ public class DataDrivenSelectForm extends WidgetLabelForm {
try { try {
m_query.addPrintListener(new PrintListener() { m_query.addPrintListener(new PrintListener() {
public void prepare(PrintEvent e) { public void prepare(PrintEvent e) {
((Select) e.getTarget()).clearOptions();
loadComponents((Select)e.getTarget(), e.getPageState()); loadComponents((Select)e.getTarget(), e.getPageState());
} }
}); });

View File

@ -120,6 +120,7 @@ public class TemplateEmailForm extends ProcessListenerForm {
new OID( PersistentFormSection.BASE_DATA_OBJECT_TYPE, new OID( PersistentFormSection.BASE_DATA_OBJECT_TYPE,
formID ); formID );
m_controls.clearOptions();
m_controls.addOption(new Option("::user.email::", "Email address"), ps); m_controls.addOption(new Option("::user.email::", "Email address"), ps);
PersistentFormSection form = (PersistentFormSection) PersistentFormSection form = (PersistentFormSection)

View File

@ -317,6 +317,8 @@ public class PartySearchSelect
} }
protected void initPartyChoices(PageState ps) { protected void initPartyChoices(PageState ps) {
m_select.clearOptions();
PartyCollection parties = (PartyCollection) m_partyQuery.get(ps); PartyCollection parties = (PartyCollection) m_partyQuery.get(ps);
boolean isEmpty = true; boolean isEmpty = true;

View File

@ -113,6 +113,8 @@ public class ApplicationCreateForm<T extends Application> extends Form implement
@Override @Override
public void prepare(final PrintEvent event) { public void prepare(final PrintEvent event) {
final SingleSelect target = (SingleSelect) event.getTarget(); final SingleSelect target = (SingleSelect) event.getTarget();
target.clearOptions();
target.addOption(new Option("", "")); target.addOption(new Option("", ""));
final ApplicationCollection applications = Application.retrieveAllApplications(); final ApplicationCollection applications = Application.retrieveAllApplications();

View File

@ -12,7 +12,6 @@
* rights and limitations under the License. * rights and limitations under the License.
* *
*/ */
package com.arsdigita.cms.docmgr.ui; package com.arsdigita.cms.docmgr.ui;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -65,10 +64,11 @@ public class CategoriesPrintListener implements PrintListener {
} }
public void prepare(PrintEvent e) { public void prepare(PrintEvent e) {
OptionGroup o = (OptionGroup)e.getTarget(); OptionGroup o = (OptionGroup) e.getTarget();
o.clearOptions();
PageState state = e.getPageState(); PageState state = e.getPageState();
Category root = Category root
m_docsContentSection.getRootCategory(); = m_docsContentSection.getRootCategory();
// Breadth-first traversal of the teee // Breadth-first traversal of the teee
CategoryTreeModelLite model = new CategoryTreeModelLite(root); CategoryTreeModelLite model = new CategoryTreeModelLite(root);
@ -89,23 +89,23 @@ public class CategoriesPrintListener implements PrintListener {
BigDecimal id = (BigDecimal) state.getValue(m_selectedFileParam); BigDecimal id = (BigDecimal) state.getValue(m_selectedFileParam);
if (id != null) { if (id != null) {
ContentItem ci = new ContentItem(id); ContentItem ci = new ContentItem(id);
CategoryCollection cats = ci.getCategoryCollection(); CategoryCollection cats = ci.getCategoryCollection();
Category cat; Category cat;
if (cats.next()) { if (cats.next()) {
cat = cats.getCategory(); cat = cats.getCategory();
String catID = cat.getID().toString(); String catID = cat.getID().toString();
assignedIDs.add(catID); assignedIDs.add(catID);
} }
} }
} }
boolean firstLoop = true; boolean firstLoop = true;
while(!queue.isEmpty()) { while (!queue.isEmpty()) {
DataQueryTreeNode node = (DataQueryTreeNode)queue.removeFirst(); DataQueryTreeNode node = (DataQueryTreeNode) queue.removeFirst();
String name = (String)nameQueue.removeFirst(); String name = (String) nameQueue.removeFirst();
// Process the node // Process the node
String id = (String)node.getKey(); String id = (String) node.getKey();
if (firstLoop && m_showRoot) { if (firstLoop && m_showRoot) {
// can't assign to root category // can't assign to root category
@ -116,11 +116,11 @@ public class CategoriesPrintListener implements PrintListener {
if (model.hasChildren(node, state)) { if (model.hasChildren(node, state)) {
// Append children // Append children
for(Iterator i = model.getChildren(node, state); i.hasNext(); ) { for (Iterator i = model.getChildren(node, state); i.hasNext();) {
TreeNode n = (TreeNode)i.next(); TreeNode n = (TreeNode) i.next();
queue.addLast(n); queue.addLast(n);
StringBuffer nameBuf = new StringBuffer(name); StringBuffer nameBuf = new StringBuffer(name);
if(name.length() > 0) { if (name.length() > 0) {
nameBuf.append(SEPARATOR); nameBuf.append(SEPARATOR);
} }
nameBuf.append(n.getElement()); nameBuf.append(n.getElement());

View File

@ -12,7 +12,6 @@
* rights and limitations under the License. * rights and limitations under the License.
* *
*/ */
package com.arsdigita.cms.docmgr.ui; package com.arsdigita.cms.docmgr.ui;
import com.arsdigita.bebop.ColumnPanel; import com.arsdigita.bebop.ColumnPanel;
@ -80,21 +79,21 @@ import java.util.Iterator;
import java.util.TooManyListenersException; import java.util.TooManyListenersException;
/** /**
* This component allows to change the file name and the * This component allows to change the file name and the description of a file. It also serves to
* description of a file. It also serves to associate * associate keywords to a file (knowledge object).
* keywords to a file (knowledge object).
* *
* @author Stefan Deusch * @author Stefan Deusch
* @author Crag Wolfe * @author Crag Wolfe
*/ */
class FileEditForm extends Form class FileEditForm extends Form
implements FormValidationListener, implements FormValidationListener,
FormProcessListener, FormProcessListener,
FormInitListener, FormInitListener,
DMConstants DMConstants {
{
private final static org.apache.log4j.Logger s_log = private final static org.apache.log4j.Logger s_log
org.apache.log4j.Logger.getLogger(FileEditForm.class); = org.apache.log4j.Logger.getLogger(
FileEditForm.class);
private final static String FILE_EDIT = "file-edit"; private final static String FILE_EDIT = "file-edit";
private final static String FILE_EDIT_CATS = "file-edit-cats"; private final static String FILE_EDIT_CATS = "file-edit-cats";
@ -127,8 +126,9 @@ class FileEditForm extends Form
private Submit m_submit; private Submit m_submit;
public FileEditForm(Component parent) { public FileEditForm(Component parent) {
this(parent,false, null); this(parent, false, null);
} }
/** /**
* Constructor * Constructor
*/ */
@ -153,9 +153,8 @@ class FileEditForm extends Form
add(new Label(FILE_UPLOAD_ADD_FILE)); add(new Label(FILE_UPLOAD_ADD_FILE));
m_fileUpload = new FileUpload(FILE_UPLOAD); m_fileUpload = new FileUpload(FILE_UPLOAD);
add(m_fileUpload); add(m_fileUpload);
} } else {
else { add(new Label(FILE_NAME_REQUIRED));
add(new Label(FILE_NAME_REQUIRED));
m_FileName = new StringParameter(FILE_EDIT_FNAME); m_FileName = new StringParameter(FILE_EDIT_FNAME);
TextField fnameEntry = new TextField(m_FileName); TextField fnameEntry = new TextField(m_FileName);
add(fnameEntry); add(fnameEntry);
@ -166,7 +165,6 @@ class FileEditForm extends Form
TextField fTitleEntry = new TextField(m_FileTitle); TextField fTitleEntry = new TextField(m_FileTitle);
add(fTitleEntry); add(fTitleEntry);
add(new Label(FILE_INTENDED_AUDIENCE)); add(new Label(FILE_INTENDED_AUDIENCE));
SingleSelect audienceEntry = new SingleSelect(m_FileAudience); SingleSelect audienceEntry = new SingleSelect(m_FileAudience);
try { try {
@ -183,17 +181,15 @@ class FileEditForm extends Form
add(new Label(FILE_CATEGORIES)); add(new Label(FILE_CATEGORIES));
MultipleSelect catSelect MultipleSelect catSelect
= new MultipleSelect(FILE_EDIT_CATS); = new MultipleSelect(FILE_EDIT_CATS);
catSelect.setSize(20); catSelect.setSize(20);
try { try {
BigDecimalParameter fileIDParam = null; BigDecimalParameter fileIDParam = null;
if (!m_creation) { if (!m_creation) {
fileIDParam = getFileIDParam(); fileIDParam = getFileIDParam();
} }
catSelect.addPrintListener catSelect.addPrintListener(new CategoriesPrintListener(getContentSection(),
(new CategoriesPrintListener fileIDParam));
(getContentSection(),
fileIDParam));
} catch (java.util.TooManyListenersException tmex) { } catch (java.util.TooManyListenersException tmex) {
throw new UncheckedWrapperException(tmex.getMessage()); throw new UncheckedWrapperException(tmex.getMessage());
} }
@ -215,7 +211,7 @@ class FileEditForm extends Form
add(sc); add(sc);
addInitListener(this); addInitListener(this);
addProcessListener(this); addProcessListener(this);
addValidationListener(this); addValidationListener(this);
} }
@ -224,34 +220,34 @@ class FileEditForm extends Form
* Initializer to pre-fill name and description * Initializer to pre-fill name and description
*/ */
public void init(FormSectionEvent e) public void init(FormSectionEvent e)
throws FormProcessException { throws FormProcessException {
if (m_creation) { if (m_creation) {
initCreate(e); initCreate(e);
} } else {
else { initEdit(e);
initEdit(e);
} }
} }
public void initEdit(FormSectionEvent e) public void initEdit(FormSectionEvent e)
throws FormProcessException { throws FormProcessException {
PageState state = e.getPageState(); PageState state = e.getPageState();
FormData data = e.getFormData(); FormData data = e.getFormData();
BigDecimal id = getSelectedDocID(state); BigDecimal id = getSelectedDocID(state);
Document doc = DMUtils.getFile(id); Document doc = DMUtils.getFile(id);
ArrayList assignedCats = new ArrayList(); ArrayList assignedCats = new ArrayList();
// Iterator i = doc.getCategories(); // Iterator i = doc.getCategories();
CategoryCollection cats = doc.getCategoryCollection(); CategoryCollection cats = doc.getCategoryCollection();
Category cat; Category cat;
if (cats.next()) { if (cats.next()) {
cat = cats.getCategory(); cat = cats.getCategory();
String catID = cat.getID().toString(); String catID = cat.getID().toString();
assignedCats.add(catID); assignedCats.add(catID);
s_log.debug("init: "+catID); s_log.debug("init: " + catID);
} }
data.put(FILE_EDIT_FNAME, URLDecoder.decode(doc.getName())); data.put(FILE_EDIT_FNAME, URLDecoder.decode(doc.getName()));
@ -263,7 +259,7 @@ class FileEditForm extends Form
} }
private void initCreate(FormSectionEvent e) private void initCreate(FormSectionEvent e)
throws FormProcessException { throws FormProcessException {
if (m_parent instanceof BrowsePane) { if (m_parent instanceof BrowsePane) {
PageState state = e.getPageState(); PageState state = e.getPageState();
@ -281,9 +277,9 @@ class FileEditForm extends Form
* read form and update * read form and update
*/ */
public void process(FormSectionEvent e) public void process(FormSectionEvent e)
throws FormProcessException { throws FormProcessException {
Document doc = null; Document doc = null;
if (m_submit.isSelected(e.getPageState())) { if (m_submit.isSelected(e.getPageState())) {
if (m_creation) { if (m_creation) {
doc = processCreate(e); doc = processCreate(e);
@ -295,24 +291,24 @@ class FileEditForm extends Form
} }
private Document processEdit(FormSectionEvent e) private Document processEdit(FormSectionEvent e)
throws FormProcessException { throws FormProcessException {
PageState state = e.getPageState(); PageState state = e.getPageState();
FormData data = e.getFormData(); FormData data = e.getFormData();
Document doc = DMUtils.getFile(getSelectedDocID(state)); Document doc = DMUtils.getFile(getSelectedDocID(state));
setDocumentAttributes(data,doc); setDocumentAttributes(data, doc);
doc.setCategories((String[]) data.get(FILE_EDIT_CATS)); doc.setCategories((String[]) data.get(FILE_EDIT_CATS));
doc.setLastModifiedLocal(new java.util.Date()); doc.setLastModifiedLocal(new java.util.Date());
doc.save(); // creates a new revision doc.save(); // creates a new revision
setDocumentPermission(data,doc); setDocumentPermission(data, doc);
return doc; return doc;
} }
private Document processCreate(FormSectionEvent e) private Document processCreate(FormSectionEvent e)
throws FormProcessException { throws FormProcessException {
PageState state = e.getPageState(); PageState state = e.getPageState();
final FormData data = e.getFormData(); final FormData data = e.getFormData();
@ -321,15 +317,14 @@ class FileEditForm extends Form
final String fname = getUploadFileName(e); final String fname = getUploadFileName(e);
String titleTmp = (String) data.get(FILE_EDIT_TITLE); String titleTmp = (String) data.get(FILE_EDIT_TITLE);
if (titleTmp == null || titleTmp.trim().length() == 0) { if (titleTmp == null || titleTmp.trim().length() == 0) {
titleTmp = fname; titleTmp = fname;
MimeType mime = MimeType.guessMimeTypeFromFile(fname); MimeType mime = MimeType.guessMimeTypeFromFile(fname);
int index; int index;
if (mime != null && (index = fname.lastIndexOf('.')) > -1) { if (mime != null && (index = fname.lastIndexOf('.')) > -1) {
titleTmp = fname.substring(0, index); titleTmp = fname.substring(0, index);
} } else {
else { titleTmp = fname;
titleTmp = fname; }
}
} }
final String title = titleTmp; final String title = titleTmp;
String fpath = (String) data.get(FILE_UPLOAD); String fpath = (String) data.get(FILE_UPLOAD);
@ -340,8 +335,8 @@ class FileEditForm extends Form
HttpServletRequest mreq = e.getPageState().getRequest(); HttpServletRequest mreq = e.getPageState().getRequest();
Assert.isTrue(mreq instanceof MultipartHttpServletRequest, Assert.isTrue(mreq instanceof MultipartHttpServletRequest,
"I got a " + mreq + " when I was " + "I got a " + mreq + " when I was "
"expecting a MultipartHttpServletRequest"); + "expecting a MultipartHttpServletRequest");
src = ((MultipartHttpServletRequest) mreq).getFile(FILE_UPLOAD); src = ((MultipartHttpServletRequest) mreq).getFile(FILE_UPLOAD);
} }
@ -359,15 +354,13 @@ class FileEditForm extends Form
BigDecimal folderID = new BigDecimal(selKey); BigDecimal folderID = new BigDecimal(selKey);
try { try {
p = new DocFolder(folderID); p = new DocFolder(folderID);
} catch(DataObjectNotFoundException nf) { } catch (DataObjectNotFoundException nf) {
throw new ObjectNotFoundException throw new ObjectNotFoundException((String) FOLDER_PARENTNOTFOUND_ERROR.localize(req));
((String) FOLDER_PARENTNOTFOUND_ERROR.localize(req));
} }
} }
final DocFolder parent = p; final DocFolder parent = p;
// insert the file in the data base below parent // insert the file in the data base below parent
final Document f1 = new Document(); final Document f1 = new Document();
// FR: define the bundle here // FR: define the bundle here
@ -380,39 +373,40 @@ class FileEditForm extends Form
final FileAsset fa = new FileAsset(); final FileAsset fa = new FileAsset();
new KernelExcursion() { new KernelExcursion() {
protected void excurse() { protected void excurse() {
// Create all the objects inside the kernel excursion // Create all the objects inside the kernel excursion
// so persistence doesn't barf... // so persistence doesn't barf...
setParty(Kernel.getSystemParty()); setParty(Kernel.getSystemParty());
//f1.setTitle(title); //f1.setTitle(title);
//f1.setName(URLEncoder.encode(fname)); //f1.setName(URLEncoder.encode(fname));
//f1.setLanguage("en"); //f1.setLanguage("en");
fa.setName("temp"); fa.setName("temp");
f1.setFile(fa); f1.setFile(fa);
bundle.setDefaultLanguage(f1.getLanguage()); bundle.setDefaultLanguage(f1.getLanguage());
//bundle.addInstance(f1); //bundle.addInstance(f1);
bundle.setName(fname); bundle.setName(fname);
bundle.setParent(parent); bundle.setParent(parent);
bundle.setContentSection(parent.getContentSection()); bundle.setContentSection(parent.getContentSection());
PermissionService.setContext(bundle,parent); PermissionService.setContext(bundle, parent);
PermissionService.setContext(f1,bundle); PermissionService.setContext(f1, bundle);
PermissionService.setContext(fa,f1); PermissionService.setContext(fa, f1);
bundle.save(); bundle.save();
f1.save(); f1.save();
}}.run(); }
}.run();
try { try {
fa.loadFromFile(fname,src,"txt"); fa.loadFromFile(fname, src, "txt");
} catch (java.io.IOException ex) { } catch (java.io.IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
throw new FormProcessException(ex.getMessage()); throw new FormProcessException(ex.getMessage());
} }
Versions.tag(f1.getOID(),(FILE_UPLOAD_INITIAL_TRANSACTION_DESCRIPTION Versions.tag(f1.getOID(), (FILE_UPLOAD_INITIAL_TRANSACTION_DESCRIPTION
.localize(req) .localize(req)
.toString())); .toString()));
setDocumentAttributes(data,f1); setDocumentAttributes(data, f1);
// title must be set before name // title must be set before name
f1.setTitle(title); f1.setTitle(title);
f1.setName(URLEncoder.encode(fname)); f1.setName(URLEncoder.encode(fname));
@ -422,18 +416,17 @@ class FileEditForm extends Form
//f1.save(); //f1.save();
// context has been set, now add additional permissions // context has been set, now add additional permissions
setDocumentPermission(data,f1); setDocumentPermission(data, f1);
f1.setCategories((String[]) data.get(FILE_EDIT_CATS)); f1.setCategories((String[]) data.get(FILE_EDIT_CATS));
bundle.save(); bundle.save();
return f1; return f1;
} }
private void setDocumentAttributes(FormData data, private void setDocumentAttributes(FormData data,
Document doc) { Document doc) {
if (!m_creation) { if (!m_creation) {
String ftitle = (String) data.get(FILE_EDIT_TITLE); String ftitle = (String) data.get(FILE_EDIT_TITLE);
String fname = (String) data.get(FILE_EDIT_FNAME); 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 * Test if the new name already exists in the current folder
*/ */
public void validate(FormSectionEvent event) public void validate(FormSectionEvent event)
throws FormProcessException { throws FormProcessException {
if (m_submit.isSelected(event.getPageState())) { if (m_submit.isSelected(event.getPageState())) {
FormData data = event.getFormData(); FormData data = event.getFormData();
//validate length of author //validate length of author
String author = (String) data.get(FILE_EDIT_AUTHOR); String author = (String) data.get(FILE_EDIT_AUTHOR);
if (author != null && author.length() > 200) { 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 //validate length of description
String desc = (String) data.get(FILE_EDIT_DESCRIPTION); String desc = (String) data.get(FILE_EDIT_DESCRIPTION);
if (desc != null && desc.length() > 4000) { 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) { if (m_creation) {
@ -486,29 +480,28 @@ class FileEditForm extends Form
} }
private void validateCreate(FormSectionEvent e) private void validateCreate(FormSectionEvent e)
throws FormProcessException { throws FormProcessException {
PageState state = e.getPageState(); PageState state = e.getPageState();
FormData data = e.getFormData(); FormData data = e.getFormData();
HttpServletRequest req = state.getRequest(); HttpServletRequest req = state.getRequest();
String fname = (String) data.get(FILE_UPLOAD); String fname = (String) data.get(FILE_UPLOAD);
if (fname == null || fname.length() == 0) { 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); fname = DMUtils.extractFileName(getUploadFileName(e), state);
// XXX Not localized as the other errors are. // XXX Not localized as the other errors are.
if (fname.length() > 200) { if (fname.length() > 200) {
data.addError data.addError(FILE_UPLOAD,
(FILE_UPLOAD, "This filename is too long. It must be fewer than 200 characters.");
"This filename is too long. It must be fewer than 200 characters.");
} }
String title = (String) data.get(FILE_EDIT_TITLE); String title = (String) data.get(FILE_EDIT_TITLE);
if (title != null && title.length() > 200) { if (title != null && title.length() > 200) {
data.addError(FILE_EDIT_TITLE, data.addError(FILE_EDIT_TITLE,
"This title is too long. It must be fewer than 200 characters."); "This title is too long. It must be fewer than 200 characters.");
} }
DocFolder parent = null; DocFolder parent = null;
@ -520,9 +513,9 @@ class FileEditForm extends Form
BigDecimal folderID = new BigDecimal(selKey); BigDecimal folderID = new BigDecimal(selKey);
try { try {
parent = new DocFolder(folderID); parent = new DocFolder(folderID);
} catch(DataObjectNotFoundException nf) { } catch (DataObjectNotFoundException nf) {
throw new ObjectNotFoundException(FOLDER_PARENTNOTFOUND_ERROR throw new ObjectNotFoundException(FOLDER_PARENTNOTFOUND_ERROR
.localize(req).toString()); .localize(req).toString());
} }
} }
@ -534,86 +527,77 @@ class FileEditForm extends Form
data.addError(FILE_UPLOAD, data.addError(FILE_UPLOAD,
RESOURCE_EXISTS_ERROR RESOURCE_EXISTS_ERROR
.localize(req).toString()); .localize(req).toString());
} catch(DataObjectNotFoundException nf) { } catch (DataObjectNotFoundException nf) {
// ok here // ok here
}// catch(InvalidNameException ex) { }// catch(InvalidNameException ex) {
} }
private void validateEdit(FormSectionEvent event) private void validateEdit(FormSectionEvent event)
throws FormProcessException { throws FormProcessException {
// PageState state = event.getPageState(); // PageState state = event.getPageState();
FormData data = event.getFormData(); FormData data = event.getFormData();
String fname = (String) data.get(FILE_EDIT_FNAME); String fname = (String) data.get(FILE_EDIT_FNAME);
if (fname == null || fname.trim().length() == 0) { 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); String title = (String) data.get(FILE_EDIT_TITLE);
if (title == null || title.length() == 0) { if (title == null || title.length() == 0) {
data.addError(FILE_EDIT_TITLE, "This parameter is required."); data.addError(FILE_EDIT_TITLE, "This parameter is required.");
} } else if (title.length() > 200) {
else if (title.length() > 200) {
data.addError(FILE_EDIT_TITLE, data.addError(FILE_EDIT_TITLE,
"This title is too long. It must be fewer than 200 characters."); "This title is too long. It must be fewer than 200 characters.");
} }
// HttpServletRequest req = state.getRequest(); // HttpServletRequest req = state.getRequest();
// Document doc = DMUtils.getFile(getSelectedDocID(state)); // Document doc = DMUtils.getFile(getSelectedDocID(state));
// // Construct a name with the optional extension // // Construct a name with the optional extension
// String name = doc.getName(); // String name = doc.getName();
// if (!doc.isValidNewName(name)) { // if (!doc.isValidNewName(name)) {
// data.addError(FILE_EDIT_FNAME, // data.addError(FILE_EDIT_FNAME,
// "Not a valid new name for this file"); // "Not a valid new name for this file");
// } // }
// Verify that the new name does not correspond to an existing // Verify that the new name does not correspond to an existing
// resource (file or folder) // resource (file or folder)
// XXX we need this, but leaving it broken for now... --hbrock // XXX we need this, but leaving it broken for now... --hbrock
/* /*
if (!name.equals(file.getName())) { if (!name.equals(file.getName())) {
try { try {
Folder parent = (Folder) file.getParent(); Folder parent = (Folder) file.getParent();
parent.getResourceID(name); parent.getResourceID(name);
data.addError(FILE_EDIT_FNAME, data.addError(FILE_EDIT_FNAME,
(String)RESOURCE_EXISTS_ERROR.localize(req)); (String)RESOURCE_EXISTS_ERROR.localize(req));
} catch(DataObjectNotFoundException nfe) { } catch(DataObjectNotFoundException nfe) {
// good, so we can rename it // good, so we can rename it
} catch (InvalidNameException ex) { } catch (InvalidNameException ex) {
data.addError(FILE_EDIT_FNAME, data.addError(FILE_EDIT_FNAME,
ex.getMessage()); ex.getMessage());
} }
} }
*/ */
} }
/* Initialize form data for document's intended audience. /* Initialize form data for document's intended audience.
*/ */
private void initAudienceFormData(FormData data, private void initAudienceFormData(FormData data,
Document doc) { Document doc) {
ObjectPermissionCollection opc = ObjectPermissionCollection opc
PermissionService.getDirectGrantedPermissions(doc.getOID()); = PermissionService.getDirectGrantedPermissions(doc.getOID());
long numPermissions = opc.size(); long numPermissions = opc.size();
if (numPermissions > 1) { if (numPermissions > 1) {
s_log.error("there should only be 1 direct permission for "+ s_log.error("there should only be 1 direct permission for " + "a document");
"a document");
} }
if (numPermissions == 0) { if (numPermissions == 0) {
data.put(FILE_EDIT_AUDIENCE,"workspace"); data.put(FILE_EDIT_AUDIENCE, "workspace");
opc.close(); opc.close();
return; return;
} }
boolean isPublic = false; boolean isPublic = false;
while (opc.next()) { while (opc.next()) {
if (opc.getGranteeID().intValue() == if (opc.getGranteeID().intValue() == PermissionManager.VIRTUAL_PUBLIC_ID) {
PermissionManager.VIRTUAL_PUBLIC_ID) {
isPublic = true; isPublic = true;
} }
} }
@ -626,38 +610,35 @@ class FileEditForm extends Form
} }
/* Grant/revoke direct permissions as needed. /* 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, private void setDocumentPermission(FormData data,
Document doc) Document doc)
throws FormProcessException { throws FormProcessException {
final String intendedAudience = (String) data.get(FILE_EDIT_AUDIENCE); final String intendedAudience = (String) data.get(FILE_EDIT_AUDIENCE);
if (intendedAudience == null) { if (intendedAudience == null) {
throw new FormProcessException throw new FormProcessException("Intended Audience cannot be null");
("Intended Audience cannot be null");
} }
final PermissionDescriptor publicDescriptor = final PermissionDescriptor publicDescriptor
new PermissionDescriptor = new PermissionDescriptor(PrivilegeDescriptor.READ,
(PrivilegeDescriptor.READ, doc.getOID(),
doc.getOID(), new OID(User.BASE_DATA_OBJECT_TYPE,
new OID(User.BASE_DATA_OBJECT_TYPE, PermissionManager.VIRTUAL_PUBLIC_ID));
PermissionManager.VIRTUAL_PUBLIC_ID)); final PermissionDescriptor internalDescriptor
final PermissionDescriptor internalDescriptor = = new PermissionDescriptor(PrivilegeDescriptor.READ,
new PermissionDescriptor doc.getOID(),
(PrivilegeDescriptor.READ, new OID(Group.BASE_DATA_OBJECT_TYPE,
doc.getOID(), DocMgr.getConfig().
new OID(Group.BASE_DATA_OBJECT_TYPE, getInternalGroupID()));
DocMgr.getConfig().getInternalGroupID()));
new KernelExcursion() { new KernelExcursion() {
protected void excurse() { protected void excurse() {
//Party currentParty = Kernel.getWebContext().getParty(); //Party currentParty = Kernel.getWebContext().getParty();
setParty(Kernel.getSystemParty()); setParty(Kernel.getSystemParty());
if("public".equals(intendedAudience)) { if ("public".equals(intendedAudience)) {
PermissionService.grantPermission(publicDescriptor); PermissionService.grantPermission(publicDescriptor);
PermissionService.revokePermission(internalDescriptor); PermissionService.revokePermission(internalDescriptor);
} else if("internal".equals(intendedAudience)) { } else if ("internal".equals(intendedAudience)) {
PermissionService.revokePermission(publicDescriptor); PermissionService.revokePermission(publicDescriptor);
PermissionService.grantPermission(internalDescriptor); PermissionService.grantPermission(internalDescriptor);
} else { } else {
@ -670,6 +651,7 @@ class FileEditForm extends Form
} }
protected class AuthorLabelPrinter implements PrintListener { protected class AuthorLabelPrinter implements PrintListener {
public AuthorLabelPrinter() { public AuthorLabelPrinter() {
// Empty // Empty
} }
@ -680,38 +662,39 @@ class FileEditForm extends Form
String name = Web.getWebContext().getUser().getName(); String name = Web.getWebContext().getUser().getName();
label.setLabel("Author: (if not "+name+")"); label.setLabel("Author: (if not " + name + ")");
} }
} }
protected class IntendedAudienceSelectPrinter implements PrintListener { protected class IntendedAudienceSelectPrinter implements PrintListener {
public IntendedAudienceSelectPrinter() { public IntendedAudienceSelectPrinter() {
} }
public void prepare(PrintEvent e) { public void prepare(PrintEvent e) {
SingleSelect select = (SingleSelect) e.getTarget(); SingleSelect select = (SingleSelect) e.getTarget();
select.clearOptions();
select.addOption select.addOption(new Option("workspace",
(new Option("workspace", Web.getWebContext().getApplication()
Web.getWebContext().getApplication() .getParentApplication() == null ? Web.getWebContext().
.getParentApplication() == null ? Web.getWebContext().getApplication().getDisplayName() getApplication().getDisplayName()
: Web.getWebContext().getApplication().getParentApplication().getDisplayName()+ : Web.getWebContext().getApplication().
" members")); getParentApplication().getDisplayName() + " members"));
select.addOption select.addOption(new Option("internal",
(new Option("internal", new Label(FILE_INTENDED_AUDIENCE_INTERNAL)));
new Label(FILE_INTENDED_AUDIENCE_INTERNAL))); select.addOption(new Option("public",
select.addOption new Label(FILE_INTENDED_AUDIENCE_PUBLIC)));
(new Option("public",
new Label(FILE_INTENDED_AUDIENCE_PUBLIC)));
} }
} }
private ContentSection getContentSection() { private ContentSection getContentSection() {
ContentSectionCollection csl = ContentSection.getAllSections(); ContentSectionCollection csl = ContentSection.getAllSections();
csl.addEqualsFilter("label",DocMgr.getConfig().getContentSection()); csl.addEqualsFilter("label", DocMgr.getConfig().getContentSection());
if (!csl.next()) { if (!csl.next()) {
csl.close(); return null; csl.close();
return null;
} }
ContentSection docsContentSection = csl.getContentSection(); ContentSection docsContentSection = csl.getContentSection();
csl.close(); csl.close();
@ -727,36 +710,31 @@ class FileEditForm extends Form
} }
private BigDecimalParameter getFileIDParam() { private BigDecimalParameter getFileIDParam() {
if (m_parent instanceof FileInfoPropertiesPane) { if (m_parent instanceof FileInfoPropertiesPane) {
return ((FileInfoPropertiesPane) m_parent).getFileIDParam(); return ((FileInfoPropertiesPane) m_parent).getFileIDParam();
} } else {
else { if (m_parent instanceof BrowseFileInfoPropertiesPane) {
if (m_parent instanceof BrowseFileInfoPropertiesPane) { ((BrowseFileInfoPropertiesPane) m_parent).getFileIDParam();
((BrowseFileInfoPropertiesPane) m_parent).getFileIDParam(); }
} }
} return null;
return null;
} }
private void backCancel(PageState state, BigDecimal docID) { private void backCancel(PageState state, BigDecimal docID) {
if (m_parent instanceof BrowsePane) { if (m_parent instanceof BrowsePane) {
if (docID != null) { if (docID != null) {
((BrowsePane) m_parent).displayFilePropPanel(state, docID); ((BrowsePane) m_parent).displayFilePropPanel(state, docID);
} } else {
else { ((BrowsePane) m_parent).displayFolderContentPanel(state);
((BrowsePane) m_parent).displayFolderContentPanel(state); }
} } else {
} if (m_parent instanceof FileInfoPropertiesPane) {
else { ((FileInfoPropertiesPane) m_parent).displayPropertiesAndActions(state);
if (m_parent instanceof FileInfoPropertiesPane) { } else {
((FileInfoPropertiesPane) m_parent).displayPropertiesAndActions(state); if (m_parent instanceof BrowseFileInfoPropertiesPane) {
} ((BrowseFileInfoPropertiesPane) m_parent).displayPropertiesPane(state);
else { }
if (m_parent instanceof BrowseFileInfoPropertiesPane) { }
((BrowseFileInfoPropertiesPane) m_parent).displayPropertiesPane(state); }
}
}
}
} }
} }

View File

@ -12,7 +12,6 @@
* rights and limitations under the License. * rights and limitations under the License.
* *
*/ */
package com.arsdigita.cms.docmgr.ui; package com.arsdigita.cms.docmgr.ui;
import com.arsdigita.bebop.*; import com.arsdigita.bebop.*;
@ -47,10 +46,11 @@ import java.util.TooManyListenersException;
* *
* @author Crag Wolfe * @author Crag Wolfe
*/ */
class SearchPane extends SimpleContainer implements DMConstants class SearchPane extends SimpleContainer implements DMConstants {
{
private static final org.apache.log4j.Logger s_log = private static final org.apache.log4j.Logger s_log
org.apache.log4j.Logger.getLogger(SearchPane.class); = org.apache.log4j.Logger.getLogger(
SearchPane.class);
public static final String SEARCH_AUTHOR = "searchAuthor"; public static final String SEARCH_AUTHOR = "searchAuthor";
public static final String SEARCH_TERMS = "searchTerms"; 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 CATEGORY_SELECT = "searchCategorySelect";
public static final String WORKSPACE_SELECT = "workspaceSelect"; public static final String WORKSPACE_SELECT = "workspaceSelect";
private final BigDecimalParameter m_categoriesParam = new BigDecimalParameter(CATEGORY_SELECT) ; private final BigDecimalParameter m_categoriesParam = new BigDecimalParameter(CATEGORY_SELECT);
private final BigDecimalParameter m_workspaceParam = new BigDecimalParameter(WORKSPACE_SELECT) ; private final BigDecimalParameter m_workspaceParam = new BigDecimalParameter(WORKSPACE_SELECT);
private final TrimmedStringParameter m_termsParam = new TrimmedStringParameter(SEARCH_TERMS); private final TrimmedStringParameter m_termsParam = new TrimmedStringParameter(SEARCH_TERMS);
private final TrimmedStringParameter m_authorParam = new TrimmedStringParameter(SEARCH_AUTHOR); private final TrimmedStringParameter m_authorParam = new TrimmedStringParameter(SEARCH_AUTHOR);
private final StringParameter m_mimeTypeParam = new StringParameter(SEARCH_MIME_TYPE); 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 // set component's content section
ContentSectionCollection csl = ContentSection.getAllSections(); ContentSectionCollection csl = ContentSection.getAllSections();
csl.addEqualsFilter("label",DocMgr.getConfig().getContentSection()); csl.addEqualsFilter("label", DocMgr.getConfig().getContentSection());
if (!csl.next()) { if (!csl.next()) {
csl.close(); return; csl.close();
return;
} }
m_docsContentSection = csl.getContentSection(); m_docsContentSection = csl.getContentSection();
csl.close(); csl.close();
// bebop components // bebop components
//m_mainTabPane = new SimpleContainer(); //m_mainTabPane = new SimpleContainer();
m_mainBrowseContainer = new BoxPanel(BoxPanel.HORIZONTAL, true); m_mainBrowseContainer = new BoxPanel(BoxPanel.HORIZONTAL, true);
//m_mainTabPane.addTab(WS_SEARCH_TITLE, //m_mainTabPane.addTab(WS_SEARCH_TITLE,
// m_mainBrowseContainer); // m_mainBrowseContainer);
//m_mainTabPane.add(new Label("yo")); //m_mainTabPane.add(new Label("yo"));
//m_mainBrowseContainer.setClassAttr("sidebarNavPanel"); //m_mainBrowseContainer.setClassAttr("sidebarNavPanel");
DocsSearchForm leftSide = new DocsSearchForm(new GridPanel(2)); DocsSearchForm leftSide = new DocsSearchForm(new GridPanel(2));
m_mainBrowseContainer.add(leftSide); m_mainBrowseContainer.add(leftSide);
m_mainBrowseContainer.add(new Label(" &nbsp; &nbsp; ",false)); m_mainBrowseContainer.add(new Label(" &nbsp; &nbsp; ", false));
m_model = new SearchListModelBuilder(leftSide); m_model = new SearchListModelBuilder(leftSide);
@ -124,9 +123,9 @@ class SearchPane extends SimpleContainer implements DMConstants
m_segmentHeader.setDefaultComponent(m_emptyLabel); m_segmentHeader.setDefaultComponent(m_emptyLabel);
rightSide.addSegment( rightSide.addSegment(
// (new Label(new EmptySearchPrintListener(leftSide)), // (new Label(new EmptySearchPrintListener(leftSide)),
m_segmentHeader, m_segmentHeader,
m_searchList); m_searchList);
m_mainBrowseContainer.add(rightSide); m_mainBrowseContainer.add(rightSide);
@ -152,10 +151,11 @@ class SearchPane extends SimpleContainer implements DMConstants
} }
private class DocsSearchForm extends Form private class DocsSearchForm extends Form
implements SearchForm, FormValidationListener, implements SearchForm, FormValidationListener,
FormProcessListener, FormInitListener { FormProcessListener, FormInitListener {
public DocsSearchForm(Container panel) { public DocsSearchForm(Container panel) {
super("docSearch",panel); super("docSearch", panel);
add(new Label("Search text:")); add(new Label("Search text:"));
TextField searchText = new TextField(SEARCH_TERMS); TextField searchText = new TextField(SEARCH_TERMS);
@ -172,29 +172,24 @@ class SearchPane extends SimpleContainer implements DMConstants
add(new com.arsdigita.bebop.form.Date(m_endDateParam)); add(new com.arsdigita.bebop.form.Date(m_endDateParam));
add(new Label("Category")); add(new Label("Category"));
SingleSelect categoriesWidget = SingleSelect categoriesWidget
new SingleSelect(m_categoriesParam); = new SingleSelect(m_categoriesParam);
try { try {
categoriesWidget.addOption(new Option("","")); categoriesWidget.addOption(new Option("", ""));
categoriesWidget.addPrintListener categoriesWidget.addPrintListener(new CategoriesPrintListener(m_docsContentSection));
(new CategoriesPrintListener
(m_docsContentSection));
} catch (TooManyListenersException e) { } catch (TooManyListenersException e) {
UncheckedWrapperException.throwLoggedException UncheckedWrapperException.throwLoggedException(getClass(), "Too many listeners", e);
(getClass(), "Too many listeners", e);
} }
add(categoriesWidget); add(categoriesWidget);
//categoriesWidget.setSize(SELECT_HEIGHT); //categoriesWidget.setSize(SELECT_HEIGHT);
add(new Label("Workspace")); add(new Label("Workspace"));
SingleSelect workspaceWidget = SingleSelect workspaceWidget
new SingleSelect(m_workspaceParam); = new SingleSelect(m_workspaceParam);
try { try {
workspaceWidget.addPrintListener workspaceWidget.addPrintListener(new WorkspacesPrintListener());
(new WorkspacesPrintListener());
} catch (TooManyListenersException e) { } catch (TooManyListenersException e) {
UncheckedWrapperException.throwLoggedException UncheckedWrapperException.throwLoggedException(getClass(), "Too many listeners", e);
(getClass(), "Too many listeners", e);
} }
add(workspaceWidget); add(workspaceWidget);
@ -206,26 +201,23 @@ class SearchPane extends SimpleContainer implements DMConstants
} }
public void validate(FormSectionEvent e) public void validate(FormSectionEvent e)
throws FormProcessException { throws FormProcessException {
PageState state = e.getPageState(); PageState state = e.getPageState();
String terms = (String)state.getValue(m_termsParam); String terms = (String) state.getValue(m_termsParam);
String author = (String)state.getValue(m_authorParam); String author = (String) state.getValue(m_authorParam);
String mimeType = (String)state.getValue(m_mimeTypeParam); String mimeType = (String) state.getValue(m_mimeTypeParam);
Date endDate = (Date)state.getValue(m_endDateParam); Date endDate = (Date) state.getValue(m_endDateParam);
Date startDate = (Date)state.getValue(m_startDateParam); Date startDate = (Date) state.getValue(m_startDateParam);
BigDecimal workspaceID = (BigDecimal)state.getValue(m_workspaceParam); BigDecimal workspaceID = (BigDecimal) state.getValue(m_workspaceParam);
BigDecimal categoryID = BigDecimal categoryID
(BigDecimal) state.getValue(m_categoriesParam); = (BigDecimal) state.getValue(m_categoriesParam);
if (StringUtils.emptyString(terms) && if (StringUtils.emptyString(terms) && StringUtils.emptyString(author) && StringUtils.
StringUtils.emptyString(author) && emptyString(mimeType) && endDate == null && startDate == null && categoryID
StringUtils.emptyString(mimeType) && == null
endDate == null && && workspaceID == null) {
startDate == null && m_emptyLabel.setVisible(state, true);
categoryID == null &&
workspaceID == null) {
m_emptyLabel.setVisible(state,true);
m_validated.set(state, new Boolean(false)); m_validated.set(state, new Boolean(false));
throw new FormProcessException("At least one search parameter must be specified"); 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) { public void init(FormSectionEvent e) {
m_segmentHeader.setVisibleComponent m_segmentHeader.setVisibleComponent(e.getPageState(), m_emptyLabel);
(e.getPageState(),m_emptyLabel);
} }
public void process(FormSectionEvent e) { public void process(FormSectionEvent e) {
PageState state = e.getPageState(); PageState state = e.getPageState();
SearchResults results = getSearchHits(state); SearchResults results = getSearchHits(state);
if(results != null && if (results != null && results.getTotalSize() > 0) {
results.getTotalSize() > 0) { m_segmentHeader.setVisibleComponent(state, m_hasResultsLabel);
m_segmentHeader.setVisibleComponent
(state,m_hasResultsLabel);
s_log.debug("results"); s_log.debug("results");
} else { } else {
m_segmentHeader.setVisibleComponent m_segmentHeader.setVisibleComponent(state, m_noResultsLabel);
(state,m_noResultsLabel);
s_log.debug("no results"); s_log.debug("no results");
} }
} }
public SearchResults getSearchHits( PageState state ) { public SearchResults getSearchHits(PageState state) {
SearchResults coln = (SearchResults) m_coln.get(state); SearchResults coln = (SearchResults) m_coln.get(state);
if (coln == null && if (coln == null && m_submit.isSelected(state) && ((Boolean) m_validated.get(state)).
m_submit.isSelected(state) && booleanValue()) {
((Boolean) m_validated.get(state)).booleanValue()) { String terms = (String) state.getValue(m_termsParam);
String terms = (String)state.getValue(m_termsParam); String author = (String) state.getValue(m_authorParam);
String author = (String)state.getValue(m_authorParam); String mimeType = (String) state.getValue(m_mimeTypeParam);
String mimeType = (String)state.getValue(m_mimeTypeParam); Date endDate = (Date) state.getValue(m_endDateParam);
Date endDate = (Date)state.getValue(m_endDateParam); Date startDate = (Date) state.getValue(m_startDateParam);
Date startDate = (Date)state.getValue(m_startDateParam); BigDecimal workspaceID = (BigDecimal) state.getValue(m_workspaceParam);
BigDecimal workspaceID = (BigDecimal)state.getValue(m_workspaceParam);
String[] sections = null; String[] sections = null;
if (!LuceneSearcher.class.equals(SearchUtils.getSearcher().getClass())) { if (!LuceneSearcher.class.equals(SearchUtils.getSearcher().getClass())) {
sections = (String[]) new String[] sections = (String[]) new String[]{m_docsContentSection.getID().toString()};
{m_docsContentSection.getID().toString()};
} }
// don't need this since all types in this section are documents // don't need this since all types in this section are documents
//String[] types = (String[])state.getValue(m_typesParam); //String[] types = (String[])state.getValue(m_typesParam);
String[] types = null; String[] types = null;
BigDecimal rootCategoryID = BigDecimal rootCategoryID
m_docsContentSection.getRootCategory().getID(); = m_docsContentSection.getRootCategory().getID();
ArrayList categoryIDs = new ArrayList(); ArrayList categoryIDs = new ArrayList();
if (!LuceneSearcher.class.equals(SearchUtils.getSearcher().getClass())) { if (!LuceneSearcher.class.equals(SearchUtils.getSearcher().getClass())) {
BigDecimal categoryID = BigDecimal categoryID
(BigDecimal) state.getValue(m_categoriesParam); = (BigDecimal) state.getValue(m_categoriesParam);
if (categoryID != null && if (categoryID != null && !categoryID.equals(rootCategoryID)) {
!categoryID.equals(rootCategoryID)) {
categoryIDs.add(categoryID.toString()); categoryIDs.add(categoryID.toString());
} }
@ -302,7 +287,7 @@ class SearchPane extends SimpleContainer implements DMConstants
//if (terms != null && !"".equals(terms)) { //if (terms != null && !"".equals(terms)) {
// if form has been submitted, m_emptyLabel will not be visible // 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, coln = SearchUtils.getAdvancedSearch(terms,
author, author,
mimeType, mimeType,
@ -313,7 +298,7 @@ class SearchPane extends SimpleContainer implements DMConstants
sections, sections,
user, user,
categoryIDs); categoryIDs);
//} //}
m_coln.set(state, coln); m_coln.set(state, coln);
} }
return coln; return coln;
@ -322,50 +307,51 @@ class SearchPane extends SimpleContainer implements DMConstants
public boolean isVisible(PageState state) { public boolean isVisible(PageState state) {
return true; return true;
} }
public long getSearchResultCount(PageState state) { public long getSearchResultCount(PageState state) {
return m_coln.get(state) == null ? 0 : return m_coln.get(state) == null ? 0
((SearchResults)m_coln.get(state)).getTotalSize(); : ((SearchResults) m_coln.get(state)).getTotalSize();
} }
} }
private class MimeTypesWidget extends SingleSelect { private class MimeTypesWidget extends SingleSelect {
public MimeTypesWidget (ParameterModel pm) { public MimeTypesWidget(ParameterModel pm) {
super(pm); super(pm);
addOption(new Option("","")); addOption(new Option("", ""));
addOption(new Option("excel","Excel document")); addOption(new Option("excel", "Excel document"));
addOption(new Option("html","HTML")); addOption(new Option("html", "HTML"));
addOption(new Option("acrobat","PDF")); addOption(new Option("acrobat", "PDF"));
addOption(new Option("plain text","Plain text")); addOption(new Option("plain text", "Plain text"));
addOption(new Option("powerpoint","Powerpoint file")); addOption(new Option("powerpoint", "Powerpoint file"));
addOption(new Option("rich text","Rich Text Format (rtf)")); addOption(new Option("rich text", "Rich Text Format (rtf)"));
addOption(new Option("word","Word document")); addOption(new Option("word", "Word document"));
} }
} }
private class WorkspacesPrintListener implements PrintListener { private class WorkspacesPrintListener implements PrintListener {
public WorkspacesPrintListener() { }
public WorkspacesPrintListener() {
}
public void prepare(PrintEvent e) { public void prepare(PrintEvent e) {
OptionGroup o = (OptionGroup)e.getTarget(); OptionGroup o = (OptionGroup) e.getTarget();
o.clearOptions();
PageState state = e.getPageState(); PageState state = e.getPageState();
User user = Web.getWebContext().getUser(); User user = Web.getWebContext().getUser();
o.addOption(new Option("","")); o.addOption(new Option("", ""));
DataQuery dq = SessionManager.getSession().retrieveQuery DataQuery dq = SessionManager.getSession().retrieveQuery(
("com.arsdigita.cms.docmgr.workspacesWithRepositories"); "com.arsdigita.cms.docmgr.workspacesWithRepositories");
while(dq.next()) { while (dq.next()) {
if (PermissionService.checkPermission if (PermissionService.checkPermission(new PermissionDescriptor(
(new PermissionDescriptor PrivilegeDescriptor.READ,
(PrivilegeDescriptor.READ, new OID(Document.BASE_DATA_OBJECT_TYPE,
new OID(Document.BASE_DATA_OBJECT_TYPE, dq.get("workspaceID")),
dq.get("workspaceID")), user.getOID()))) {
user.getOID()))) { o.addOption(new Option(((BigDecimal) dq.get("workspaceID")).toString(),
o.addOption(new Option (String) dq.get("title")));
(((BigDecimal) dq.get("workspaceID")).toString(),
(String) dq.get("title")));
} }
dq.close(); dq.close();

View File

@ -50,23 +50,24 @@ public class CategoryWidget extends SingleSelect implements Constants {
try { try {
addPrintListener(new PrintListener() { addPrintListener(new PrintListener() {
public void prepare(PrintEvent e) { public void prepare(PrintEvent e) {
PageState s = e.getPageState(); PageState s = e.getPageState();
final Forum forum = getForum(s); final Forum forum = getForum(s);
SingleSelect target = (SingleSelect) e.getTarget(); SingleSelect target = (SingleSelect) e.getTarget();
target.clearOptions();
// Get categories for this forum // Get categories for this forum
if (forum.noCategoryPostsAllowed()) { if (forum.noCategoryPostsAllowed()) {
target.addOption(new Option( target.addOption(new Option(
TOPIC_NONE.toString(), TOPIC_NONE.toString(),
new Label(GlobalizationUtil.gz("forum.ui.topic.none")))); new Label(GlobalizationUtil.gz("forum.ui.topic.none"))));
}
final Category root = forum.getRootCategory();
if (root != null) {
addCategories(root, target);
}
} }
}); final Category root = forum.getRootCategory();
if (root != null) {
addCategories(root, target);
}
}
});
} catch (TooManyListenersException ex) { } catch (TooManyListenersException ex) {
throw new UncheckedWrapperException(ex); throw new UncheckedWrapperException(ex);
} }
@ -83,9 +84,8 @@ public class CategoryWidget extends SingleSelect implements Constants {
try { try {
while (children.next()) { while (children.next()) {
Category c = children.getCategory(); Category c = children.getCategory();
target.addOption(new Option target.addOption(new Option(c.getID().toString(),
(c.getID().toString(), c.getName()));
c.getName()));
} }
} finally { } finally {
@ -101,16 +101,15 @@ public class CategoryWidget extends SingleSelect implements Constants {
*/ */
private Forum getForum(final PageState s) { private Forum getForum(final PageState s) {
Forum forum; Forum forum;
if (ForumContext.getContext(s).getThreadID() != null ) { if (ForumContext.getContext(s).getThreadID() != null) {
Post rootPost = (Post)ForumContext.getContext(s). Post rootPost = (Post) ForumContext.getContext(s).
getMessageThread().getRootMessage(); getMessageThread().getRootMessage();
forum = rootPost.getForum(); forum = rootPost.getForum();
} else if (ForumContext.getContext(s).getForum() != null) { } else if (ForumContext.getContext(s).getForum() != null) {
forum = ForumContext.getContext(s).getForum(); forum = ForumContext.getContext(s).getForum();
} else { } else {
// sanity check // sanity check
throw new UncheckedWrapperException throw new UncheckedWrapperException("Must be either a forum, or a thread page.");
("Must be either a forum, or a thread page.");
} }
return forum; return forum;
} }

View File

@ -75,6 +75,7 @@ public class DomainProviderForm extends AbstractProviderForm {
m_domain.addPrintListener(new PrintListener() { m_domain.addPrintListener(new PrintListener() {
public void prepare(PrintEvent e) { public void prepare(PrintEvent e) {
SingleSelect s = (SingleSelect)e.getTarget(); SingleSelect s = (SingleSelect)e.getTarget();
s.clearOptions();
DataCollection domains = SessionManager.getSession() DataCollection domains = SessionManager.getSession()
.retrieve(Domain.BASE_DATA_OBJECT_TYPE); .retrieve(Domain.BASE_DATA_OBJECT_TYPE);

View File

@ -49,6 +49,7 @@ public class ControlledList extends SingleSelect {
addPrintListener(new PrintListener() { addPrintListener(new PrintListener() {
public void prepare(PrintEvent e) { public void prepare(PrintEvent e) {
ControlledList target = (ControlledList)e.getTarget(); ControlledList target = (ControlledList)e.getTarget();
target.clearOptions();
target.populate(); target.populate();
} }
}); });

View File

@ -15,7 +15,6 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
package com.arsdigita.london.terms.ui.admin; package com.arsdigita.london.terms.ui.admin;
import com.arsdigita.bebop.Form; import com.arsdigita.bebop.Form;
@ -43,7 +42,6 @@ import com.arsdigita.web.ApplicationCollection;
import java.util.TooManyListenersException; import java.util.TooManyListenersException;
/** /**
* *
* *
@ -81,19 +79,20 @@ public class DomainContextForm extends Form {
m_app.addValidationListener(new NotNullValidationListener()); m_app.addValidationListener(new NotNullValidationListener());
try { try {
m_app.addPrintListener(new PrintListener() { m_app.addPrintListener(new PrintListener() {
public void prepare(PrintEvent e) { public void prepare(PrintEvent e) {
SingleSelect t = (SingleSelect)e.getTarget(); SingleSelect t = (SingleSelect) e.getTarget();
ApplicationCollection apps = Application t.clearOptions();
ApplicationCollection apps = Application
.retrieveAllApplications(); .retrieveAllApplications();
apps.addOrder(Application.PRIMARY_URL); apps.addOrder(Application.PRIMARY_URL);
t.addOption(new Option(null, "--select one--")); t.addOption(new Option(null, "--select one--"));
while (apps.next()) { while (apps.next()) {
Application app = apps.getApplication(); Application app = apps.getApplication();
t.addOption(new Option(app.getOID().toString(), t.addOption(new Option(app.getOID().toString(),
app.getPath())); app.getPath()));
}
} }
}); }
});
} catch (TooManyListenersException ex) { } catch (TooManyListenersException ex) {
throw new UncheckedWrapperException("cannot happen", ex); throw new UncheckedWrapperException("cannot happen", ex);
} }
@ -111,8 +110,9 @@ public class DomainContextForm extends Form {
} }
private class DomainInitListener implements FormInitListener { private class DomainInitListener implements FormInitListener {
public void init(FormSectionEvent ev) public void init(FormSectionEvent ev)
throws FormProcessException { throws FormProcessException {
PageState state = ev.getPageState(); PageState state = ev.getPageState();
m_app.setValue(state, null); m_app.setValue(state, null);
@ -121,8 +121,9 @@ public class DomainContextForm extends Form {
} }
private class DomainSubmissionListener implements FormSubmissionListener { private class DomainSubmissionListener implements FormSubmissionListener {
public void submitted(FormSectionEvent ev) public void submitted(FormSectionEvent ev)
throws FormProcessException { throws FormProcessException {
PageState state = ev.getPageState(); PageState state = ev.getPageState();
if (m_buttons.getCancelButton().isSelected(state)) { if (m_buttons.getCancelButton().isSelected(state)) {
@ -133,19 +134,19 @@ public class DomainContextForm extends Form {
} }
private class DomainProcessListener implements FormProcessListener { private class DomainProcessListener implements FormProcessListener {
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); 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.setAsRootForObject(app, domain.setAsRootForObject(app,
(String)m_context.getValue(state)); (String) m_context.getValue(state));
fireCompletionEvent(state); fireCompletionEvent(state);
} }
} }
} }

View File

@ -69,6 +69,7 @@ public class DomainMappingAddForm extends Form {
@Override @Override
public void prepare(final PrintEvent event) { public void prepare(final PrintEvent event) {
final SingleSelect target = (SingleSelect) event.getTarget(); final SingleSelect target = (SingleSelect) event.getTarget();
target.clearOptions();
if (event.getPageState().getValue(selected) == null) { if (event.getPageState().getValue(selected) == null) {
target.setReadOnly(); target.setReadOnly();

View File

@ -98,6 +98,7 @@ public class CategoryForm extends Form {
private static class TemplatePrintListener implements PrintListener { private static class TemplatePrintListener implements PrintListener {
public void prepare(PrintEvent ev) { public void prepare(PrintEvent ev) {
SingleSelect target = (SingleSelect)ev.getTarget(); SingleSelect target = (SingleSelect)ev.getTarget();
target.clearOptions();
target.addOption(new Option(null, "Inherit from parent")); target.addOption(new Option(null, "Inherit from parent"));
TemplateCollection templates = Template.retrieveAll(); TemplateCollection templates = Template.retrieveAll();

View File

@ -124,6 +124,7 @@ public class CategoryFormAddContext extends Form {
private class ContextPrintListener implements PrintListener { private class ContextPrintListener implements PrintListener {
public void prepare(PrintEvent ev) { public void prepare(PrintEvent ev) {
SingleSelect target = (SingleSelect)ev.getTarget(); SingleSelect target = (SingleSelect)ev.getTarget();
target.clearOptions();
TemplateContextCollection contexts = TemplateContext.retrieveAll(); TemplateContextCollection contexts = TemplateContext.retrieveAll();
while (contexts.next()) { while (contexts.next()) {
TemplateContext context = contexts.getTemplateContext(); TemplateContext context = contexts.getTemplateContext();

View File

@ -76,6 +76,7 @@ public class NavigationCreateForm extends Form {
termDomainSelect.addPrintListener(new PrintListener() { termDomainSelect.addPrintListener(new PrintListener() {
public void prepare(final PrintEvent event) { public void prepare(final PrintEvent event) {
final SingleSelect target = (SingleSelect) event.getTarget(); final SingleSelect target = (SingleSelect) event.getTarget();
target.clearOptions();
final DataCollection termDomains = SessionManager.getSession(). final DataCollection termDomains = SessionManager.getSession().
retrieve(Domain.BASE_DATA_OBJECT_TYPE); retrieve(Domain.BASE_DATA_OBJECT_TYPE);

View File

@ -142,6 +142,7 @@ public class NavigationTreePortletEditor extends PortletConfigFormSection
public void prepare(PrintEvent e) public void prepare(PrintEvent e)
{ {
SingleSelect target = (SingleSelect) e.getTarget(); SingleSelect target = (SingleSelect) e.getTarget();
target.clearOptions();
DomainCollection navigations = new DomainCollection(SessionManager.getSession().retrieve( DomainCollection navigations = new DomainCollection(SessionManager.getSession().retrieve(
Navigation.BASE_DATA_OBJECT_TYPE)); Navigation.BASE_DATA_OBJECT_TYPE));

View File

@ -189,6 +189,7 @@ public class ObjectListPortletEditor extends PortletConfigFormSection {
public void prepare(PrintEvent ev) { public void prepare(PrintEvent ev) {
OptionGroup target = (OptionGroup)ev.getTarget(); OptionGroup target = (OptionGroup)ev.getTarget();
target.clearOptions();
MetadataRoot root = MetadataRoot.getMetadataRoot(); MetadataRoot root = MetadataRoot.getMetadataRoot();
Iterator types = root.getObjectTypes().iterator(); Iterator types = root.getObjectTypes().iterator();

View File

@ -18,10 +18,8 @@
*/ */
package com.arsdigita.portalserver.permissions; 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.LinkedList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
@ -54,45 +52,42 @@ import com.arsdigita.portalserver.*;
import com.arsdigita.util.Assert; import com.arsdigita.util.Assert;
import org.apache.log4j.Category; import org.apache.log4j.Category;
/** /**
* *
* @version $Id: ObjectPermissionEdit.java#3 $ * @version $Id: ObjectPermissionEdit.java#3 $
*/ */
public class ObjectPermissionEdit extends CompoundComponent { public class ObjectPermissionEdit extends CompoundComponent {
private static Category s_log = Category.getInstance private static Category s_log = Category.getInstance(ObjectPermissionEdit.class.getName());
(ObjectPermissionEdit.class.getName());
// Heavily-reused per-request label for renderer getComponent calls // Heavily-reused per-request label for renderer getComponent calls
private final static RequestLocal s_dynamicLabel = new RequestLocal() { private final static RequestLocal s_dynamicLabel = new RequestLocal() {
@Override @Override
public Object initialValue(PageState ps) { public Object initialValue(PageState ps) {
return new Label(); return new Label();
} }
}; };
private static class ObjectGrantsTable extends GrantsTable { private static class ObjectGrantsTable extends GrantsTable {
static void getGrantsHelper(ACSObject object, static void getGrantsHelper(ACSObject object,
Collection types, Collection types,
LinkedList ordering) { LinkedList ordering) {
HashMap canonicalMap = new HashMap(); HashMap canonicalMap = new HashMap();
ObjectPermissionCollection opc = ObjectPermissionCollection opc
PermissionService.getDirectGrantedPermissions(object.getOID()); = PermissionService.getDirectGrantedPermissions(object.
getOID());
try { try {
while (opc.next()) { while (opc.next()) {
s_log.debug s_log.debug("Current grant in loop is " + opc.getPrivilege());
("Current grant in loop is " + opc.getPrivilege());
if (opc.isInherited() if (opc.isInherited()
// Skip create privileges. They are created // Skip create privileges. They are created
// and destroyed implicitly when the other // and destroyed implicitly when the other
// privileges are used. // privileges are used.
|| opc.getPrivilege().equals || opc.getPrivilege().equals(PrivilegeDescriptor.CREATE)) {
(PrivilegeDescriptor.CREATE)) {
continue; continue;
} }
@ -105,8 +100,8 @@ public class ObjectPermissionEdit extends CompoundComponent {
} }
if (grant.objectType != null if (grant.objectType != null
&& types != null && types != null
&& !types.contains(grant.objectType)) { && !types.contains(grant.objectType)) {
continue; continue;
} }
@ -134,7 +129,6 @@ public class ObjectPermissionEdit extends CompoundComponent {
} }
} }
public ObjectGrantsTable(RequestLocal grantsRL, public ObjectGrantsTable(RequestLocal grantsRL,
RequestLocal typesRL, RequestLocal typesRL,
boolean isEditable) { boolean isEditable) {
@ -143,140 +137,140 @@ public class ObjectPermissionEdit extends CompoundComponent {
// COLUMN 0: The party with the grant // COLUMN 0: The party with the grant
TableColumn partyColumn = new TableColumn(0, "User or Role"); TableColumn partyColumn = new TableColumn(0, "User or Role");
partyColumn.setCellRenderer(new TableCellRenderer() { partyColumn.setCellRenderer(new TableCellRenderer() {
final RequestLocal m_userNameDisplay = new RequestLocal() { final RequestLocal m_userNameDisplay = new RequestLocal() {
public Object initialValue(PageState ps) { public Object initialValue(PageState ps) {
SimpleContainer result = new SimpleContainer(); SimpleContainer result = new SimpleContainer();
result.add(Icons.USER_16); result.add(Icons.USER_16);
result.add((Component) s_dynamicLabel.get(ps)); result.add((Component) s_dynamicLabel.get(ps));
return result; 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_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); getColumnModel().add(0, partyColumn);
} }
} }
private static class ObjectDirectGrantsTable extends ObjectGrantsTable { private static class ObjectDirectGrantsTable extends ObjectGrantsTable {
public ObjectDirectGrantsTable(final RequestLocal objectRL, public ObjectDirectGrantsTable(final RequestLocal objectRL,
final RequestLocal typesRL) { final RequestLocal typesRL) {
super(new RequestLocal() { super(new RequestLocal() {
public Object initialValue(PageState ps) { public Object initialValue(PageState ps) {
LinkedList ordering = new LinkedList(); LinkedList ordering = new LinkedList();
getGrantsHelper((ACSObject) objectRL.get(ps), getGrantsHelper((ACSObject) objectRL.get(ps),
(Collection) typesRL.get(ps), (Collection) typesRL.get(ps),
ordering); ordering);
return ordering.iterator(); return ordering.iterator();
} }
}, typesRL, true); }, typesRL, true);
} }
} }
private static class ObjectIndirectGrantsTable extends ObjectGrantsTable { private static class ObjectIndirectGrantsTable extends ObjectGrantsTable {
public ObjectIndirectGrantsTable(final RequestLocal objectRL, public ObjectIndirectGrantsTable(final RequestLocal objectRL,
final RequestLocal typesRL) { final RequestLocal typesRL) {
super(new RequestLocal() { super(new RequestLocal() {
public Object initialValue(PageState ps) { public Object initialValue(PageState ps) {
LinkedList ordering = new LinkedList(); LinkedList ordering = new LinkedList();
ACSObject object = (ACSObject) objectRL.get(ps); ACSObject object = (ACSObject) objectRL.get(ps);
Collection types = (Collection) typesRL.get(ps); Collection types = (Collection) typesRL.get(ps);
// FIXME: May need to do this by getting the OID // FIXME: May need to do this by getting the OID
// and doing a verifySubtype check // and doing a verifySubtype check
while (!(object instanceof PortalSite)) { while (!(object instanceof PortalSite)) {
DataObject ctx = PermissionService.getContext(object); DataObject ctx = PermissionService.getContext(object);
if (ctx == null) { if (ctx == null) {
break; break;
}
object = (ACSObject) DomainObjectFactory.newInstance
(ctx);
getGrantsHelper(object, types, ordering);
} }
object = (ACSObject) DomainObjectFactory.newInstance(ctx);
return ordering.iterator(); getGrantsHelper(object, types, ordering);
} }
}, typesRL, false);
return ordering.iterator();
}
}, typesRL, false);
// 'Target' column // 'Target' column
TableColumn targetColumn = new TableColumn(1, "On"); TableColumn targetColumn = new TableColumn(1, "On");
targetColumn.setCellRenderer(new TableCellRenderer() { targetColumn.setCellRenderer(new TableCellRenderer() {
public Component getComponent(Table table, public Component getComponent(Table table,
PageState ps, PageState ps,
Object value, Object value,
boolean isSelected, boolean isSelected,
Object key, Object key,
int row, int row,
int column) { int column) {
Grant grant = (Grant) value; Grant grant = (Grant) value;
Label l = (Label) s_dynamicLabel.get(ps); Label l = (Label) s_dynamicLabel.get(ps);
l.setLabel(grant.objectName); l.setLabel(grant.objectName);
return l; return l;
} }
}); });
getColumnModel().add(1, targetColumn); getColumnModel().add(1, targetColumn);
} }
} }
private class MainDisplay extends CompoundComponent { private class MainDisplay extends CompoundComponent {
MainDisplay(final RequestLocal objectRL, MainDisplay(final RequestLocal objectRL,
final RequestLocal directTypesRL, final RequestLocal directTypesRL,
final RequestLocal indirectTypesRL, final RequestLocal indirectTypesRL,
final ActionListener onAddClick) { final ActionListener onAddClick) {
super(new BoxPanel(BoxPanel.VERTICAL)); super(new BoxPanel(BoxPanel.VERTICAL));
// Header for direct permission list // Header for direct permission list
final GridPanel directHeader = new GridPanel(2); final GridPanel directHeader = new GridPanel(2);
Label directLabel = Label directLabel
new Label(GlobalizationUtil.globalize("cw.cw.permissions.view_and_manage_specific_permissions")); = new Label(GlobalizationUtil.globalize(
"cw.cw.permissions.view_and_manage_specific_permissions"));
directLabel.setFontWeight(Label.BOLD); directLabel.setFontWeight(Label.BOLD);
directHeader.add(directLabel, GridPanel.LEFT); 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.setClassAttr("actionLink");
newGrantLink.addActionListener(onAddClick); newGrantLink.addActionListener(onAddClick);
directHeader.add(newGrantLink, GridPanel.RIGHT); directHeader.add(newGrantLink, GridPanel.RIGHT);
add(directHeader); add(directHeader);
add(new Label("The following users and roles have specific " + add(new Label("The following users and roles have specific "
"privileges on this knowledge item:")); + "privileges on this knowledge item:"));
// Direct permission list // Direct permission list
Table directTable = new ObjectDirectGrantsTable Table directTable = new ObjectDirectGrantsTable(objectRL, directTypesRL);
(objectRL, directTypesRL);
directTable.setCellPadding("5"); directTable.setCellPadding("5");
Label directEmptyView = new Label("No specific privileges are " + Label directEmptyView = new Label("No specific privileges are "
"defined on this item."); + "defined on this item.");
directEmptyView.setFontWeight(Label.ITALIC); directEmptyView.setFontWeight(Label.ITALIC);
directTable.setEmptyView(directEmptyView); directTable.setEmptyView(directEmptyView);
add(directTable); add(directTable);
@ -284,24 +278,22 @@ public class ObjectPermissionEdit extends CompoundComponent {
add(new Label(" ")); add(new Label(" "));
// Header for indirect permission list // 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); indirectLabel.setFontWeight(Label.BOLD);
add(indirectLabel); add(indirectLabel);
add(new Label("The following users and roles have broader " + add(new Label("The following users and roles have broader "
"privileges applying to this and other knowledge " + + "privileges applying to this and other knowledge "
"items. Note that these are inherited privileges " + + "items. Note that these are inherited privileges "
"and can only be changed from the location given " + + "and can only be changed from the location given "
"in the \"On\" column.")); + "in the \"On\" column."));
// Indirect permission list // Indirect permission list
Table indirectTable = new ObjectIndirectGrantsTable Table indirectTable = new ObjectIndirectGrantsTable(objectRL, indirectTypesRL);
(objectRL, indirectTypesRL);
indirectTable.setCellPadding("5"); indirectTable.setCellPadding("5");
Label indirectEmpty = new Label("No general permissions apply " + Label indirectEmpty = new Label("No general permissions apply " + "to this item.");
"to this item.");
indirectEmpty.setFontWeight(Label.ITALIC); indirectEmpty.setFontWeight(Label.ITALIC);
indirectTable.setEmptyView(indirectEmpty); indirectTable.setEmptyView(indirectEmpty);
add(indirectTable); add(indirectTable);
@ -314,43 +306,44 @@ public class ObjectPermissionEdit extends CompoundComponent {
private static final long MAX_RESULTS = 20; private static final long MAX_RESULTS = 20;
private class NewGrantDisplay extends CompoundComponent { private class NewGrantDisplay extends CompoundComponent {
// RequestLocal storing the object // RequestLocal storing the object
private final RequestLocal m_objectRL; private final RequestLocal m_objectRL;
// Collection of 'relevant types' // Collection of 'relevant types'
private final RequestLocal m_typesRL; private final RequestLocal m_typesRL;
// Parameter containing user's search string // Parameter containing user's search string
private final StringParameter m_queryParam = private final StringParameter m_queryParam
new StringParameter("queryParam"); = new StringParameter("queryParam");
// Flag indicating whether or not to limit search to current // Flag indicating whether or not to limit search to current
// workspace's participants // workspace's participants
private final BooleanParameter m_limitParam = private final BooleanParameter m_limitParam
new BooleanParameter("limitParam"); = new BooleanParameter("limitParam");
private final RequestLocal m_partiesRL = new RequestLocal() { private final RequestLocal m_partiesRL = new RequestLocal() {
public Object initialValue(PageState ps) { public Object initialValue(PageState ps) {
PortalSite psite = PortalSite psite
PortalSite.getCurrentPortalSite(ps.getRequest()); = PortalSite.getCurrentPortalSite(ps.getRequest());
String queryString = (String) ps.getValue(m_queryParam); String queryString = (String) ps.getValue(m_queryParam);
PartyCollection parties; PartyCollection parties;
Boolean limit = (Boolean) ps.getValue(m_limitParam); Boolean limit = (Boolean) ps.getValue(m_limitParam);
if (limit != null && limit.booleanValue()) { if (limit != null && limit.booleanValue()) {
parties = psite.getParticipants(); parties = psite.getParticipants();
} else { } else {
parties = Party.retrieveAllParties(); parties = Party.retrieveAllParties();
}
parties.filter(queryString);
return parties;
} }
};
parties.filter(queryString);
return parties;
}
};
private void clearQuery(PageState ps) { private void clearQuery(PageState ps) {
ps.setValue(m_queryParam, null); ps.setValue(m_queryParam, null);
@ -374,6 +367,7 @@ public class ObjectPermissionEdit extends CompoundComponent {
} }
private class BoldLabel extends Label { private class BoldLabel extends Label {
public BoldLabel(String text) { public BoldLabel(String text) {
super(text); super(text);
setFontWeight(Label.BOLD); setFontWeight(Label.BOLD);
@ -381,6 +375,7 @@ public class ObjectPermissionEdit extends CompoundComponent {
} }
private class MyAddGrantForm extends AddGrantForm { private class MyAddGrantForm extends AddGrantForm {
public MyAddGrantForm(String name, public MyAddGrantForm(String name,
Widget partyWidget, Widget partyWidget,
final RequestLocal errorMessageRL) { final RequestLocal errorMessageRL) {
@ -391,24 +386,23 @@ public class ObjectPermissionEdit extends CompoundComponent {
add(new BoldLabel("Select Grantee:")); add(new BoldLabel("Select Grantee:"));
add(new BoldLabel("On:") { add(new BoldLabel("On:") {
public void generateXML(PageState ps, Element parent) { public void generateXML(PageState ps, Element parent) {
Collection types = (Collection)m_typesRL.get(ps); Collection types = (Collection) m_typesRL.get(ps);
if ((types == null) || (types.size() <= 1)) { if ((types == null) || (types.size() <= 1)) {
parent.newChildElement("bebop:label", BEBOP_XML_NS); parent.newChildElement("bebop:label", BEBOP_XML_NS);
return; return;
} else { } else {
super.generateXML(ps, parent); super.generateXML(ps, parent);
}
} }
}); }
});
add(new BoldLabel("Privilege:")); add(new BoldLabel("Privilege:"));
add(new Label("")); add(new Label(""));
// Row 2: Widgets // Row 2: Widgets
// Create a hidden widget for the objectID // Create a hidden widget for the objectID
add(new Hidden(getObjectParameter())); add(new Hidden(getObjectParameter()));
@ -427,20 +421,20 @@ public class ObjectPermissionEdit extends CompoundComponent {
// Init listener to initialize the objectID parameter // Init listener to initialize the objectID parameter
addInitListener(new FormInitListener() { addInitListener(new FormInitListener() {
public void init(FormSectionEvent ev) { public void init(FormSectionEvent ev) {
PageState ps = ev.getPageState(); PageState ps = ev.getPageState();
FormData fd = ev.getFormData(); FormData fd = ev.getFormData();
fd.put(getObjectParameter().getName(), fd.put(getObjectParameter().getName(),
((ACSObject)m_objectRL.get(ps)).getID()); ((ACSObject) m_objectRL.get(ps)).getID());
} }
}); });
addProcessListener(new FormProcessListener() { addProcessListener(new FormProcessListener() {
public void process(FormSectionEvent ev) { public void process(FormSectionEvent ev) {
PageState ps = ev.getPageState(); PageState ps = ev.getPageState();
NewGrantDisplay.this.fireCompletionEvent(ps); NewGrantDisplay.this.fireCompletionEvent(ps);
} }
}); });
} }
} }
@ -451,32 +445,30 @@ public class ObjectPermissionEdit extends CompoundComponent {
// This RL makes available a PartyCollection containing // This RL makes available a PartyCollection containing
// the result of the specified query // the result of the specified query
final BoxPanel screen1 = new BoxPanel(BoxPanel.VERTICAL) { final BoxPanel screen1 = new BoxPanel(BoxPanel.VERTICAL) {
public boolean isVisible(PageState ps) { public boolean isVisible(PageState ps) {
if (!haveQuery(ps)) { if (!haveQuery(ps)) {
return true; return true;
}
PartyCollection pc =
NewGrantDisplay.this.getQueryResults(ps);
long n = pc.size();
return (n == 0 || n > MAX_RESULTS);
} }
}; PartyCollection pc
= NewGrantDisplay.this.getQueryResults(ps);
long n = pc.size();
return (n == 0 || n > MAX_RESULTS);
}
};
add(screen1); add(screen1);
Label roleFormTitle = new BoldLabel(""); Label roleFormTitle = new BoldLabel("");
roleFormTitle.addPrintListener(new PrintListener() { roleFormTitle.addPrintListener(new PrintListener() {
public void prepare(PrintEvent ev) { public void prepare(PrintEvent ev) {
PageState ps = ev.getPageState(); PageState ps = ev.getPageState();
Label tgt = (Label)ev.getTarget(); Label tgt = (Label) ev.getTarget();
PortalSite psite = PortalSite psite
PortalSite.getCurrentPortalSite(ps.getRequest()); = PortalSite.getCurrentPortalSite(ps.getRequest());
tgt.setLabel("Grant privilege to a role from the \"" + tgt.setLabel("Grant privilege to a role from the \"" + psite.getTitle()
psite.getTitle() + "\" portal:"); + "\" portal:");
} }
}); });
screen1.add(roleFormTitle); screen1.add(roleFormTitle);
// Form for granting to a portal role // Form for granting to a portal role
@ -484,19 +476,19 @@ public class ObjectPermissionEdit extends CompoundComponent {
SingleSelect roleField = new SingleSelect("roleField"); SingleSelect roleField = new SingleSelect("roleField");
roleField.setPrintListener(new PrintListener() { roleField.setPrintListener(new PrintListener() {
public void prepare(PrintEvent ev) { public void prepare(PrintEvent ev) {
SingleSelect tgt = (SingleSelect)ev.getTarget(); SingleSelect tgt = (SingleSelect) ev.getTarget();
PageState ps = ev.getPageState(); tgt.clearOptions();
PortalSite psite = PageState ps = ev.getPageState();
PortalSite.getCurrentPortalSite(ps.getRequest()); PortalSite psite
RoleCollection rc = psite.getRoles(); = PortalSite.getCurrentPortalSite(ps.getRequest());
while (rc.next()) { RoleCollection rc = psite.getRoles();
Option o = new Option while (rc.next()) {
(rc.getID().toString(), rc.getRoleName()); Option o = new Option(rc.getID().toString(), rc.getRoleName());
tgt.addOption(o); tgt.addOption(o);
}
} }
}); }
});
Form roleForm = new MyAddGrantForm("roleGrant", Form roleForm = new MyAddGrantForm("roleGrant",
roleField, roleField,
rfErrorMessageRL); rfErrorMessageRL);
@ -505,11 +497,8 @@ public class ObjectPermissionEdit extends CompoundComponent {
// Error message display // Error message display
screen1.add(new ErrorMessageDisplay(rfErrorMessageRL)); screen1.add(new ErrorMessageDisplay(rfErrorMessageRL));
// Toplevel search label // Toplevel search label
screen1.add(new BoldLabel("Search for a user or role to recieve " + screen1.add(new BoldLabel("Search for a user or role to recieve " + "a privilege:"));
"a privilege:"));
Form otherSearch = new Form("otherSearch", new GridPanel(2)); Form otherSearch = new Form("otherSearch", new GridPanel(2));
otherSearch.setRedirecting(true); otherSearch.setRedirecting(true);
@ -521,19 +510,18 @@ public class ObjectPermissionEdit extends CompoundComponent {
Label limitLabel = new Label(""); Label limitLabel = new Label("");
limitLabel.addPrintListener(new PrintListener() { limitLabel.addPrintListener(new PrintListener() {
public void prepare(PrintEvent ev) { public void prepare(PrintEvent ev) {
Label tgt = (Label)ev.getTarget(); Label tgt = (Label) ev.getTarget();
PageState ps = ev.getPageState(); PageState ps = ev.getPageState();
PortalSite psite = PortalSite psite
PortalSite.getCurrentPortalSite(ps.getRequest()); = PortalSite.getCurrentPortalSite(ps.getRequest());
tgt.setLabel("Limit search to \"" + psite.getTitle() + tgt.setLabel("Limit search to \"" + psite.getTitle() + "\" participants");
"\" participants"); }
} });
});
final CheckboxGroup limitToParticipants = final CheckboxGroup limitToParticipants
new CheckboxGroup("limitToParticipants"); = new CheckboxGroup("limitToParticipants");
String[] limitDefault = { "yes" }; String[] limitDefault = {"yes"};
limitToParticipants.setDefaultValue(limitDefault); limitToParticipants.setDefaultValue(limitDefault);
limitToParticipants.addOption(new Option("yes", limitLabel)); limitToParticipants.addOption(new Option("yes", limitLabel));
otherSearch.add(limitToParticipants); otherSearch.add(limitToParticipants);
@ -541,21 +529,22 @@ public class ObjectPermissionEdit extends CompoundComponent {
otherSearch.add(new Label("")); otherSearch.add(new Label(""));
// Label to display when no matches are found // Label to display when no matches are found
Label noMatchLabel = new Label(GlobalizationUtil.globalize("cw.cw.permissions.no_matches_found")) { Label noMatchLabel = new Label(GlobalizationUtil.globalize(
public boolean isVisible(PageState ps) { "cw.cw.permissions.no_matches_found")) {
if (!haveQuery(ps)) { public boolean isVisible(PageState ps) {
return false; if (!haveQuery(ps)) {
} return false;
}
PartyCollection pc = getQueryResults(ps); PartyCollection pc = getQueryResults(ps);
if (pc == null || pc.size() > 0) { if (pc == null || pc.size() > 0) {
return false; return false;
} else { } else {
return true; return true;
}
} }
} };
};
// @deprecated bebop must not specify design properties, just // @deprecated bebop must not specify design properties, just
// logical properties. // logical properties.
// TODO: add as error condition to the widget. // TODO: add as error condition to the widget.
@ -563,120 +552,120 @@ public class ObjectPermissionEdit extends CompoundComponent {
otherSearch.add(noMatchLabel); otherSearch.add(noMatchLabel);
// Label to display when too many matches are found. // Label to display when too many matches are found.
Label tooManyLabel = Label tooManyLabel
new Label(GlobalizationUtil.globalize("cw.cw.permissions.too_many_matches_refine_your_search")) { = new Label(GlobalizationUtil.globalize(
public boolean isVisible(PageState ps) { "cw.cw.permissions.too_many_matches_refine_your_search")) {
if (!haveQuery(ps)) { public boolean isVisible(PageState ps) {
return false; if (!haveQuery(ps)) {
} return false;
}
PartyCollection pc = getQueryResults(ps); PartyCollection pc = getQueryResults(ps);
if (pc == null || pc.size() <= MAX_RESULTS) { if (pc == null || pc.size() <= MAX_RESULTS) {
return false; return false;
} else { } else {
return true; return true;
} }
} }
}; };
// @deprecated bebop must not specify design properties, just // @deprecated bebop must not specify design properties, just
// logical properties. // logical properties.
// TODO: add as error condition to the widget. // TODO: add as error condition to the widget.
// noMatchLabel.setColor(Color.red); // noMatchLabel.setColor(Color.red);
// tooManyLabel.setColor(Color.red); // tooManyLabel.setColor(Color.red);
otherSearch.add(tooManyLabel); 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 screen1.add(otherSearch);
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() { screen1.add(new Label(""));
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);
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 // 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"); Form partyForm = new MyAddGrantForm("partyGrant",
partyField.setLayout(RadioGroup.VERTICAL); partyField,
partyField.setPrintListener(new PrintListener() { pfErrorMessageRL);
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()));
}
}
});
screen2.add(partyForm);
Form partyForm = new MyAddGrantForm("partyGrant", screen2.add(new ErrorMessageDisplay(pfErrorMessageRL));
partyField,
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 returnToMainLink
= new ActionLink((String) GlobalizationUtil.globalize(
ActionLink newSearchLink = new ActionLink( (String) GlobalizationUtil.globalize("cw.cw.permissions.try_a_new_search").localize()); "cw.cw.permissions.return_to_current_permissions_view").
newSearchLink.setClassAttr("actionLink"); localize());
newSearchLink.addActionListener(new ActionListener() { returnToMainLink.setClassAttr("actionLink");
public void actionPerformed(ActionEvent ev) { returnToMainLink.addActionListener(new ActionListener() {
clearQuery(ev.getPageState()); public void actionPerformed(ActionEvent ev) {
} NewGrantDisplay.this.fireCompletionEvent(ev.getPageState());
}); }
screen2.add(newSearchLink); });
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) { public void fireCompletionEvent(PageState ps) {
clearQuery(ps); clearQuery(ps);
super.fireCompletionEvent(ps); super.fireCompletionEvent(ps);
@ -690,71 +679,66 @@ public class ObjectPermissionEdit extends CompoundComponent {
} }
public void register(Page p) { public void register(Page p) {
// Assert.assertTrue((p instanceof CWPage), // Assert.assertTrue((p instanceof CWPage),
Assert.isTrue((p instanceof CWPage), Assert.isTrue((p instanceof CWPage),
"ObjectPermissionEdit may only be used on " + "ObjectPermissionEdit may only be used on " + "instances of CWPage.");
"instances of CWPage.");
super.register(p); super.register(p);
} }
private void initialize(RequestLocal objectRL, private void initialize(RequestLocal objectRL,
RequestLocal directTypesRL, RequestLocal directTypesRL,
RequestLocal indirectTypesRL) { RequestLocal indirectTypesRL) {
final SimpleContainer c = (SimpleContainer)getContainer(); final SimpleContainer c = (SimpleContainer) getContainer();
final Completable newGrantDisplay = final Completable newGrantDisplay
new NewGrantDisplay(objectRL, directTypesRL) { = new NewGrantDisplay(objectRL, directTypesRL) {
public void register(Page p) { public void register(Page p) {
super.register(p); super.register(p);
p.setVisibleDefault(this, false); p.setVisibleDefault(this, false);
} }
}; };
ActionListener onAddClick = new ActionListener() { ActionListener onAddClick = new ActionListener() {
public void actionPerformed(ActionEvent ev) { public void actionPerformed(ActionEvent ev) {
PageState ps = ev.getPageState(); PageState ps = ev.getPageState();
CWPage page = (CWPage)ps.getPage(); CWPage page = (CWPage) ps.getPage();
page.goModal(ps, newGrantDisplay); page.goModal(ps, newGrantDisplay);
} }
}; };
final Component mainDisplay = final Component mainDisplay
new MainDisplay(objectRL, = new MainDisplay(objectRL,
directTypesRL, directTypesRL,
indirectTypesRL, indirectTypesRL,
onAddClick); onAddClick);
newGrantDisplay.addCompletionListener(new ActionListener() { newGrantDisplay.addCompletionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) { public void actionPerformed(ActionEvent ev) {
PageState ps = ev.getPageState(); PageState ps = ev.getPageState();
CWPage page = (CWPage)ps.getPage(); CWPage page = (CWPage) ps.getPage();
page.goUnmodal(ps); page.goUnmodal(ps);
} }
}); });
add(mainDisplay); add(mainDisplay);
add(newGrantDisplay); add(newGrantDisplay);
} }
public ObjectPermissionEdit(final RequestLocal objectRL) { public ObjectPermissionEdit(final RequestLocal objectRL) {
super(new SimpleContainer()); super(new SimpleContainer());
initialize(objectRL, new RequestLocal(), new RequestLocal()); initialize(objectRL, new RequestLocal(), new RequestLocal());
/* /*
{ {
public Object initialValue(PageState ps) { public Object initialValue(PageState ps) {
ACSObject object = (ACSObject)objectRL.get(ps); ACSObject object = (ACSObject)objectRL.get(ps);
HashSet result = new HashSet(1); HashSet result = new HashSet(1);
result.add(object.getObjectType()); result.add(object.getObjectType());
return result; return result;
} }
}); });
*/ */
} }

View File

@ -251,6 +251,7 @@ public class PartyPermissionEdit extends CompoundComponent {
objectSelect.setPrintListener(new PrintListener() { objectSelect.setPrintListener(new PrintListener() {
public void prepare(PrintEvent ev) { public void prepare(PrintEvent ev) {
SingleSelect target = (SingleSelect)ev.getTarget(); SingleSelect target = (SingleSelect)ev.getTarget();
target.clearOptions();
PageState ps = ev.getPageState(); PageState ps = ev.getPageState();
List options = (List) m_targetsRL.get(ps); List options = (List) m_targetsRL.get(ps);
for (Iterator it = options.iterator(); it.hasNext(); ) { for (Iterator it = options.iterator(); it.hasNext(); ) {

View File

@ -26,8 +26,8 @@ import com.arsdigita.bebop.event.*;
import com.arsdigita.xml.Element; import com.arsdigita.xml.Element;
import com.arsdigita.persistence.metadata.ObjectType; import com.arsdigita.persistence.metadata.ObjectType;
class TypeSingleSelect extends SingleSelect { class TypeSingleSelect extends SingleSelect {
private RequestLocal m_typesRL; private RequestLocal m_typesRL;
public TypeSingleSelect(ParameterModel param, public TypeSingleSelect(ParameterModel param,
@ -39,22 +39,23 @@ class TypeSingleSelect extends SingleSelect {
addOption(new Option(AddGrantForm.ALL_TYPES, addOption(new Option(AddGrantForm.ALL_TYPES,
"All Contained Items")); "All Contained Items"));
setPrintListener(new PrintListener() { setPrintListener(new PrintListener() {
public void prepare(PrintEvent ev) { public void prepare(PrintEvent ev) {
SingleSelect tgt = (SingleSelect)ev.getTarget(); SingleSelect tgt = (SingleSelect) ev.getTarget();
PageState ps = ev.getPageState(); tgt.clearOptions();
Iterator types = PageState ps = ev.getPageState();
((Collection)m_typesRL.get(ps)).iterator(); Iterator types
while (types.hasNext()) { = ((Collection) m_typesRL.get(ps)).iterator();
ObjectType type = (ObjectType)types.next(); while (types.hasNext()) {
tgt.addOption(new Option(type.getQualifiedName(), ObjectType type = (ObjectType) types.next();
type.getName())); tgt.addOption(new Option(type.getQualifiedName(),
} type.getName()));
} }
}); }
});
} }
public void generateXML(PageState ps, Element parent) { public void generateXML(PageState ps, Element parent) {
Collection types = (Collection)m_typesRL.get(ps); Collection types = (Collection) m_typesRL.get(ps);
if (types == null) { if (types == null) {
parent.newChildElement("bebop:label", BEBOP_XML_NS); parent.newChildElement("bebop:label", BEBOP_XML_NS);
return; return;

View File

@ -18,7 +18,6 @@
*/ */
package com.arsdigita.portalserver.ui.admin; 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.web.ApplicationType;
@ -77,10 +76,11 @@ import java.math.BigDecimal;
* @version $Id: //portalserver/dev/src/com/arsdigita/portalserver/ui/admin/DisplayPane.java#9 $ * @version $Id: //portalserver/dev/src/com/arsdigita/portalserver/ui/admin/DisplayPane.java#9 $
*/ */
public class DisplayPane extends DynamicListWizard { 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 $"; 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 = private static final Logger s_cat
Logger.getLogger(ApplicationsPane.class.getName()); = Logger.getLogger(ApplicationsPane.class.getName());
final ModalContainer m_editContainer = new ModalContainer(); final ModalContainer m_editContainer = new ModalContainer();
@ -91,18 +91,21 @@ public class DisplayPane extends DynamicListWizard {
DeleteTabForm m_deleteTabForm; DeleteTabForm m_deleteTabForm;
List m_layouts; List m_layouts;
RequestLocal selectedTabIDRL; 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; BigDecimalParameter m_selectedPortletParam;
static final String FOUR_SPACE_INDENT_STRING = "&nbsp;&nbsp;&nbsp;&nbsp;"; static final String FOUR_SPACE_INDENT_STRING = "&nbsp;&nbsp;&nbsp;&nbsp;";
static class TabListModel implements ListModel { static class TabListModel implements ListModel {
PortalTabCollection m_tabs; PortalTabCollection m_tabs;
PortalTab m_currTab; PortalTab m_currTab;
public TabListModel(PortalSite psite) { public TabListModel(PortalSite psite) {
m_tabs = psite.getTabsForPortalSite(); m_tabs = psite.getTabsForPortalSite();
} }
public boolean next() { public boolean next() {
if (!m_tabs.next()) { if (!m_tabs.next()) {
return false; return false;
@ -110,138 +113,142 @@ public class DisplayPane extends DynamicListWizard {
m_currTab = m_tabs.getPortalTab(); m_currTab = m_tabs.getPortalTab();
return true; return true;
} }
public Object getElement() { public Object getElement() {
return m_currTab.getTitle(); return m_currTab.getTitle();
} }
public String getKey() { public String getKey() {
return m_currTab.getID().toString(); 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.", super("Current Tabs. Use the arrows to shift tab position.",
new ListModelBuilder() { new ListModelBuilder() {
public ListModel makeModel(List l, PageState ps) { public ListModel makeModel(List l, PageState ps) {
PortalSite psite = (PortalSite)portalsiteRL.get(ps); PortalSite psite = (PortalSite) portalsiteRL.get(ps);
return new TabListModel(psite); return new TabListModel(psite);
} }
public void lock() {}
public boolean isLocked() { return true; } public void lock() {
}
public boolean isLocked() {
return true;
}
}, },
"Add a tab", "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; final DynamicListWizard dlw = this;
// FORM FOR ADDING NEW TABS // FORM FOR ADDING NEW TABS
Form addForm = new Form("addTab"); Form addForm = new Form("addTab");
addForm.add(new Label(GlobalizationUtil.globalize("cw.workspace.ui.admin.new_tab_name"))); addForm.add(new Label(GlobalizationUtil.globalize("cw.workspace.ui.admin.new_tab_name")));
final TextField newTabName = new TextField("name"); final TextField newTabName = new TextField("name");
newTabName.getParameterModel().addParameterListener newTabName.getParameterModel().addParameterListener(new NotEmptyValidationListener());
(new NotEmptyValidationListener());
newTabName.setSize(40); newTabName.setSize(40);
addForm.add(newTabName); addForm.add(newTabName);
addForm.add(new Label()); addForm.add(new Label());
addForm.add(new Submit("Add tab")); addForm.add(new Submit("Add tab"));
addForm.addProcessListener(new FormProcessListener() { addForm.addProcessListener(new FormProcessListener() {
public void process(FormSectionEvent ev) { public void process(FormSectionEvent ev) {
PageState ps = ev.getPageState(); PageState ps = ev.getPageState();
PortalSite psite = (PortalSite)portalsiteRL.get(ps); PortalSite psite = (PortalSite) portalsiteRL.get(ps);
PortalTab newTab = PortalTab newTab
PortalTab.createTab((String)newTabName.getValue(ps),psite); = PortalTab.createTab((String) newTabName.getValue(ps), psite);
psite.addPortalTab(newTab); psite.addPortalTab(newTab);
newTab.save(); newTab.save();
psite.save(); psite.save();
List list = (List) dlw.getListingComponent(); List list = (List) dlw.getListingComponent();
list.getSelectionModel() list.getSelectionModel()
.setSelectedKey(ps, newTab.getID().toString()); .setSelectedKey(ps, newTab.getID().toString());
} }
}); });
setAddPane(addForm); setAddPane(addForm);
// CONSTRUCT EDIT COMPONENT // CONSTRUCT EDIT COMPONENT
selectedTabIDRL = new RequestLocal() { selectedTabIDRL = new RequestLocal() {
protected Object initialValue(PageState ps) { protected Object initialValue(PageState ps) {
String tabIDstr = (String)dlw.getSelectionModel() String tabIDstr = (String) dlw.getSelectionModel()
.getSelectedKey(ps); .getSelectedKey(ps);
return new BigDecimal(tabIDstr); return new BigDecimal(tabIDstr);
} }
}; };
m_selectedPortletParam = new BigDecimalParameter("selectedPortlet"); m_selectedPortletParam = new BigDecimalParameter("selectedPortlet");
m_mainDisplay = new BoxPanel(BoxPanel.VERTICAL); m_mainDisplay = new BoxPanel(BoxPanel.VERTICAL);
PortletLayoutComponent plc = PortletLayoutComponent plc
new PortletLayoutComponent(portalsiteRL, selectedTabIDRL) { = new PortletLayoutComponent(portalsiteRL, selectedTabIDRL) {
protected void handleConfigure(PageState ps, BigDecimal id) { protected void handleConfigure(PageState ps, BigDecimal id) {
ps.setValue(m_selectedPortletParam, id); ps.setValue(m_selectedPortletParam, id);
m_editContainer.setVisibleComponent(ps, m_portletModify); m_editContainer.setVisibleComponent(ps, m_portletModify);
} }
}; };
LockableLinks locklinks = LockableLinks locklinks
new LockableLinks(portalsiteRL, selectedTabIDRL); = new LockableLinks(portalsiteRL, selectedTabIDRL);
m_mainDisplay.add(locklinks); m_mainDisplay.add(locklinks);
m_mainDisplay.add(plc); m_mainDisplay.add(plc);
BoxPanel links = new BoxPanel(BoxPanel.HORIZONTAL, true); 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.setClassAttr("actionLink");
renameLink.addActionListener(new RenameLinkListener()); renameLink.addActionListener(new RenameLinkListener());
links.add(renameLink); links.add(renameLink);
ActionLink deleteLink = new ActionLink( (String) GlobalizationUtil.globalize("cw.workspace.ui.admin.delete_tab").localize()) { ActionLink deleteLink = new ActionLink((String) GlobalizationUtil.globalize(
public boolean isVisible(PageState ps) { "cw.workspace.ui.admin.delete_tab").localize()) {
PortalSite psite = (PortalSite)portalsiteRL.get(ps); public boolean isVisible(PageState ps) {
PortalTabCollection pstc = psite.getTabsForPortalSite(); PortalSite psite = (PortalSite) portalsiteRL.get(ps);
return (pstc.size() > 1); PortalTabCollection pstc = psite.getTabsForPortalSite();
} return (pstc.size() > 1);
}; }
};
deleteLink.setClassAttr("actionLink"); deleteLink.setClassAttr("actionLink");
deleteLink.addActionListener(new DeleteLinkListener()); deleteLink.addActionListener(new DeleteLinkListener());
links.add(deleteLink); links.add(deleteLink);
m_mainDisplay.add(links); m_mainDisplay.add(links);
final BigDecimalParameter portletTypeParam = final BigDecimalParameter portletTypeParam
new BigDecimalParameter("typeID"); = new BigDecimalParameter("typeID");
Form addPortlet = new Form("ap1", new GridPanel(1)) { Form addPortlet = new Form("ap1", new GridPanel(1)) {
public void register(Page p) { public void register(Page p) {
super.register(p); super.register(p);
p.addComponentStateParam(this, portletTypeParam); p.addComponentStateParam(this, portletTypeParam);
} }
}; };
Image image = new Image("/assets/cw/general/add.gif"); Image image = new Image("/assets/cw/general/add.gif");
image.setBorder("0"); image.setBorder("0");
SimpleContainer imageLabelSC = new SimpleContainer(); SimpleContainer imageLabelSC = new SimpleContainer();
imageLabelSC.add(image); imageLabelSC.add(image);
imageLabelSC.add(new Label imageLabelSC.add(new Label("To add a portlet to this page, first choose a type: "));
("To add a portlet to this page, first choose a type: "));
addPortlet.add(imageLabelSC); addPortlet.add(imageLabelSC);
final SingleSelect portletTypeSelect = new SingleSelect("ptype"); final SingleSelect portletTypeSelect = new SingleSelect("ptype");
portletTypeSelect.addValidationListener( portletTypeSelect.addValidationListener(
new NotNullValidationListener()); new NotNullValidationListener());
PortletTypeCollection ptc = PortletType.retrieveAllPortletTypes(); PortletTypeCollection ptc = PortletType.retrieveAllPortletTypes();
//Alphabetize by title //Alphabetize by title
ptc.addOrder("title"); ptc.addOrder("title");
while (ptc.next()) { while (ptc.next()) {
ApplicationType providerAppType = ptc.getPortletType().getProviderApplicationType(); ApplicationType providerAppType = ptc.getPortletType().getProviderApplicationType();
if ( providerAppType != null ) { if (providerAppType != null) {
portletTypeSelect.addOption(new Option(ptc.getID().toString(), ptc.getTitle() + portletTypeSelect.addOption(new Option(ptc.getID().toString(), ptc.getTitle() + " ("
" (" + providerAppType.getTitle() + ") ")); + providerAppType.
getTitle() + ") "));
} else { } else {
portletTypeSelect.addOption(new Option(ptc.getID().toString(), ptc.getTitle())); portletTypeSelect.addOption(new Option(ptc.getID().toString(), ptc.getTitle()));
} }
@ -253,37 +260,33 @@ public class DisplayPane extends DynamicListWizard {
addPortlet.add(selectorSC); addPortlet.add(selectorSC);
addPortlet.addProcessListener(new FormProcessListener() { addPortlet.addProcessListener(new FormProcessListener() {
public void process(FormSectionEvent ev) { public void process(FormSectionEvent ev) {
PageState ps = ev.getPageState(); PageState ps = ev.getPageState();
m_editContainer.setVisibleComponent(ps, m_portletAddForm); m_editContainer.setVisibleComponent(ps, m_portletAddForm);
ps.setValue(portletTypeParam, new BigDecimal( ps.setValue(portletTypeParam, new BigDecimal(
(String) portletTypeSelect.getValue(ps))); (String) portletTypeSelect.getValue(ps)));
m_portletAddForm.activate(ps); m_portletAddForm.activate(ps);
} }
}); });
m_mainDisplay.add(addPortlet); m_mainDisplay.add(addPortlet);
BoxPanel tabLayouts = new BoxPanel(BoxPanel.HORIZONTAL, true); BoxPanel tabLayouts = new BoxPanel(BoxPanel.HORIZONTAL, true);
ListModelBuilder lmb = new ListModelBuilder() ListModelBuilder lmb = new ListModelBuilder() {
{ boolean m_isLocked;
boolean m_isLocked;
public ListModel makeModel(List l, PageState pageState) public ListModel makeModel(List l, PageState pageState) {
{ return new LayoutListModel(pageState);
return new LayoutListModel (pageState); }
}
public void lock() public void lock() {
{ m_isLocked = true;
m_isLocked = true; }
}
public boolean isLocked() public boolean isLocked() {
{ return m_isLocked;
return m_isLocked; }
} };
};
m_layouts = new List(lmb); m_layouts = new List(lmb);
@ -291,62 +294,59 @@ public class DisplayPane extends DynamicListWizard {
m_layouts.setCellRenderer(new LayoutListCellRenderer()); m_layouts.setCellRenderer(new LayoutListCellRenderer());
m_layouts.addChangeListener(new ChangeListener () { m_layouts.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) public void stateChanged(ChangeEvent e) {
{ PageState ps = e.getPageState();
PageState ps = e.getPageState(); String key = (String) ((List) dlw.getListingComponent())
String key = (String) ((List) dlw.getListingComponent())
.getSelectedKey(ps); .getSelectedKey(ps);
BigDecimal bd = new BigDecimal(key); BigDecimal bd = new BigDecimal(key);
PortalTab ptab = PortalTab.retrieveTab(bd); PortalTab ptab = PortalTab.retrieveTab(bd);
String laykey = (String)m_layouts.getSelectedKey(ps); String laykey = (String) m_layouts.getSelectedKey(ps);
Integer lk = new Integer(laykey); Integer lk = new Integer(laykey);
ptab.setLayout(m_layoutNames[lk.intValue()]); ptab.setLayout(m_layoutNames[lk.intValue()]);
ptab.save(); ptab.save();
} }
}); });
tabLayouts.add(m_layouts); tabLayouts.add(m_layouts);
m_mainDisplay.add(tabLayouts); m_mainDisplay.add(tabLayouts);
m_portletAddForm
m_portletAddForm = = new PortletAddForm(portalsiteRL, selectedTabIDRL, new RequestLocal() {
new PortletAddForm(portalsiteRL, selectedTabIDRL, new RequestLocal() { protected Object initialValue(PageState ps) {
protected Object initialValue(PageState ps) { BigDecimal id = (BigDecimal) ps.getValue(portletTypeParam);
BigDecimal id = (BigDecimal) ps.getValue(portletTypeParam); if (id == null) {
if (id == null) { return null;
return null; }
return PortletType.retrievePortletType(id);
} }
return PortletType.retrievePortletType(id); });
}
});
m_portletAddForm.addCompletionListener(new ActionListener() { m_portletAddForm.addCompletionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) { public void actionPerformed(ActionEvent ev) {
PageState ps = ev.getPageState(); PageState ps = ev.getPageState();
ps.reset(m_editContainer); ps.reset(m_editContainer);
} }
}); });
RequestLocal selectedPortletRL = new RequestLocal() { RequestLocal selectedPortletRL = new RequestLocal() {
public Object initialValue(PageState ps) { public Object initialValue(PageState ps) {
BigDecimal portletID = BigDecimal portletID
(BigDecimal)ps.getValue(m_selectedPortletParam); = (BigDecimal) ps.getValue(m_selectedPortletParam);
if (portletID == null) { if (portletID == null) {
return null; return null;
}
return Portlet.retrievePortlet(portletID);
} }
}; return Portlet.retrievePortlet(portletID);
}
};
ActionListener reset = new ActionListener() { ActionListener reset = new ActionListener() {
public void actionPerformed(ActionEvent ev) { public void actionPerformed(ActionEvent ev) {
PageState ps = ev.getPageState(); PageState ps = ev.getPageState();
ps.reset(m_editContainer); ps.reset(m_editContainer);
ps.setValue(m_selectedPortletParam, null); ps.setValue(m_selectedPortletParam, null);
} }
}; };
m_portletModify = new ApplicationModifyComponent m_portletModify = new ApplicationModifyComponent(selectedPortletRL, true, reset, reset);
(selectedPortletRL, true, reset, reset);
m_renameTabForm = new RenameTabForm(selectedTabIDRL); m_renameTabForm = new RenameTabForm(selectedTabIDRL);
m_deleteTabForm = new DeleteTabForm(selectedTabIDRL); m_deleteTabForm = new DeleteTabForm(selectedTabIDRL);
@ -359,10 +359,10 @@ public class DisplayPane extends DynamicListWizard {
setEditPane(m_editContainer); setEditPane(m_editContainer);
((List) getListingComponent()).addChangeListener(new ChangeListener() { ((List) getListingComponent()).addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent ev) { public void stateChanged(ChangeEvent ev) {
ev.getPageState().reset(m_editContainer); ev.getPageState().reset(m_editContainer);
} }
}); });
// //
//This cell renderer attempts to do the following: //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, //One other thing, if there is only one tab in the list,
//this code preselects it, unless the add tab link has been //this code preselects it, unless the add tab link has been
//clicked. //clicked.
((List) getListingComponent()).setCellRenderer(new ListCellRenderer() { ((List) getListingComponent()).setCellRenderer(new ListCellRenderer() {
public Component getComponent(List list,PageState state, public Component getComponent(List list, PageState state,
Object value,String key, int index,boolean isSelected) { Object value, String key, int index, boolean isSelected) {
Label tabName; Label tabName;
int indent_ctr = 0; int indent_ctr = 0;
boolean isFirst = false; boolean isFirst = false;
boolean isLast = false; boolean isLast = false;
SimpleContainer container = new SimpleContainer(); SimpleContainer container = new SimpleContainer();
//get the collection of tabs, its size, and use this info //get the collection of tabs, its size, and use this info
//to determine where in the collection this tab name resides... //to determine where in the collection this tab name resides...
BigDecimal bd = new BigDecimal(key); BigDecimal bd = new BigDecimal(key);
PortalTab ptab = PortalTab.retrieveTab(bd); PortalTab ptab = PortalTab.retrieveTab(bd);
PortalSite psite = ptab.getPortalSite(); PortalSite psite = ptab.getPortalSite();
PortalTabCollection ptcoll = psite.getTabsForPortalSite(); PortalTabCollection ptcoll = psite.getTabsForPortalSite();
long size = ptcoll.size(); long size = ptcoll.size();
//If only one tab, select it ONLY if addtablink not selected //If only one tab, select it ONLY if addtablink not selected
// and then get outa here... // and then get outa here...
if(size == 1) if (size == 1) {
{ if ((dlw.getAddLink().isSelected(state)) == false) {
if((dlw.getAddLink().isSelected(state)) == false) list.setSelectedKey(state, key);
{ tabName = new Label(value.toString());
list.setSelectedKey(state,key); container.add(tabName);
tabName = new Label(value.toString()); //Update tab request local
container.add(tabName); selectedTabIDRL.set(state, bd);
//Update tab request local return container;
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;
}
}
} }
ptcoll.close(); } else //more than one tab...
{
//Code below constructs proper indent for tab indent_ctr = 0;
StringBuffer buf = new StringBuffer(200); while (ptcoll.next()) {
for(int i = 0; i < (indent_ctr - 1); i++) 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 //Here we construct the control links for arrows
//This could be done below in the particular cases for //This could be done below in the particular cases for
//a slight performance benefit, but putting them //a slight performance benefit, but putting them
//here, together, is easier to understand... //here, together, is easier to understand...
if(isSelected) //This tab name is currently selected... if (isSelected) //This tab name is currently selected...
{ {
tabName = new Label(value.toString()); tabName = new Label(value.toString());
tabName.setFontWeight(Label.BOLD); tabName.setFontWeight(Label.BOLD);
Label labelLeft = new Label(GlobalizationUtil.globalize("cw.workspace.ui.admin.shift_left")); Label labelLeft = new Label(GlobalizationUtil.globalize(
Label labelRight = new Label(GlobalizationUtil.globalize("cw.workspace.ui.admin.shift_right")); "cw.workspace.ui.admin.shift_left"));
Label labelRight = new Label(GlobalizationUtil.globalize(
ControlLink linkLeft = new ControlLink(labelLeft) { "cw.workspace.ui.admin.shift_right"));
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);
}
ControlLink linkLeft = new ControlLink(labelLeft) {
public void setControlEvent(PageState s) {
s.setControlEvent(dlw, "left", "1");
} }
else //this tab is NOT selected...return a link };
{ ControlLink linkRight = new ControlLink(labelRight) {
String ttab = buf.toString() + value.toString(); public void setControlEvent(PageState s) {
tabName = new Label(ttab,false); s.setControlEvent(dlw, "right", "1");
ControlLink l = new ControlLink(tabName);
container.add(l);
} }
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 } //end of constructor
@ -497,53 +489,55 @@ public class DisplayPane extends DynamicListWizard {
p.addComponentStateParam(this, m_selectedPortletParam); p.addComponentStateParam(this, m_selectedPortletParam);
} }
public void respond(PageState state) throws javax.servlet.ServletException{ public void respond(PageState state) throws javax.servlet.ServletException {
String tabIDstr = String tabIDstr
(String)this.getSelectionModel() = (String) this.getSelectionModel()
.getSelectedKey(state); .getSelectedKey(state);
BigDecimal tabID = new BigDecimal(tabIDstr); BigDecimal tabID = new BigDecimal(tabIDstr);
String name = state.getControlEventName(); String name = state.getControlEventName();
if(name.compareTo("left") == 0) { if (name.compareTo("left") == 0) {
PortalTab ptab = PortalTab.retrieveTab(tabID); PortalTab ptab = PortalTab.retrieveTab(tabID);
PortalSite psite = ptab.getPortalSite(); PortalSite psite = ptab.getPortalSite();
psite.swapTabWithPrevious(ptab); psite.swapTabWithPrevious(ptab);
} else if(name.compareTo("right") == 0) { } else if (name.compareTo("right") == 0) {
PortalTab ptab = PortalTab.retrieveTab(tabID); PortalTab ptab = PortalTab.retrieveTab(tabID);
PortalSite psite = ptab.getPortalSite(); PortalSite psite = ptab.getPortalSite();
psite.swapTabWithNext(ptab); psite.swapTabWithNext(ptab);
} }
} }
public class RenameTabForm extends Form implements FormProcessListener { public class RenameTabForm extends Form implements FormProcessListener {
private TextField currenttabName; private TextField currenttabName;
private Label instruction; private Label instruction;
private Submit button,cancelbutton; private Submit button, cancelbutton;
private RequestLocal m_tabIDRL; private RequestLocal m_tabIDRL;
public RenameTabForm(RequestLocal SelectedTabIDRL) { public RenameTabForm(RequestLocal SelectedTabIDRL) {
super("renametabform"); super("renametabform");
m_tabIDRL = SelectedTabIDRL; 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 = new TextField("CurrentTabName");
currenttabName.setDefaultValue(""); currenttabName.setDefaultValue("");
currenttabName.setSize(40); currenttabName.setSize(40);
currenttabName.addValidationListener currenttabName.addValidationListener(new NotNullValidationListener(
(new NotNullValidationListener("Every Tab must have a name!")); "Every Tab must have a name!"));
try { try {
currenttabName.addPrintListener(new PrintListener() { currenttabName.addPrintListener(new PrintListener() {
public void prepare(PrintEvent e) { public void prepare(PrintEvent e) {
PageState s = e.getPageState(); PageState s = e.getPageState();
BigDecimal tabID = (BigDecimal)m_tabIDRL.get(s); BigDecimal tabID = (BigDecimal) m_tabIDRL.get(s);
PortalTab ptab = PortalTab.retrieveTab(tabID); PortalTab ptab = PortalTab.retrieveTab(tabID);
TextField tf = (TextField)e.getTarget(); TextField tf = (TextField) e.getTarget();
tf.setValue(s,ptab.getTitle()); tf.setValue(s, ptab.getTitle());
} }
}); });
} catch(java.util.TooManyListenersException e) { } } catch (java.util.TooManyListenersException e) {
}
button = new Submit("Rename tab"); button = new Submit("Rename tab");
button.setButtonLabel("Rename tab"); button.setButtonLabel("Rename tab");
cancelbutton = new Submit("Cancel"); cancelbutton = new Submit("Cancel");
@ -558,8 +552,8 @@ public class DisplayPane extends DynamicListWizard {
public void process(FormSectionEvent e) { public void process(FormSectionEvent e) {
PageState s = e.getPageState(); PageState s = e.getPageState();
if(button.isSelected(s)) { if (button.isSelected(s)) {
BigDecimal tabID = (BigDecimal)m_tabIDRL.get(s); BigDecimal tabID = (BigDecimal) m_tabIDRL.get(s);
PortalTab ptab = PortalTab.retrieveTab(tabID); PortalTab ptab = PortalTab.retrieveTab(tabID);
ptab.setTitle(currenttabName.getValue(s).toString()); ptab.setTitle(currenttabName.getValue(s).toString());
ptab.save(); ptab.save();
@ -570,28 +564,29 @@ public class DisplayPane extends DynamicListWizard {
} //end rename form } //end rename form
public class DeleteTabForm extends Form implements FormProcessListener { public class DeleteTabForm extends Form implements FormProcessListener {
private TextField currenttabName; private TextField currenttabName;
private Label instruction; private Label instruction;
private Submit button; private Submit button;
private Submit cancelbutton; private Submit cancelbutton;
private RequestLocal m_tabIDRL; private RequestLocal m_tabIDRL;
public DeleteTabForm(RequestLocal SelectedTabIDRL) { public DeleteTabForm(RequestLocal SelectedTabIDRL) {
super("deletetabform"); super("deletetabform");
m_tabIDRL = SelectedTabIDRL; 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() { instruction.addPrintListener(new PrintListener() {
public void prepare(PrintEvent e) { public void prepare(PrintEvent e) {
PageState s = e.getPageState(); PageState s = e.getPageState();
String prefixstr = "Are you sure you want to delete the "; String prefixstr = "Are you sure you want to delete the ";
BigDecimal tabID = (BigDecimal)m_tabIDRL.get(s); BigDecimal tabID = (BigDecimal) m_tabIDRL.get(s);
PortalTab ptab = PortalTab.retrieveTab(tabID); PortalTab ptab = PortalTab.retrieveTab(tabID);
Label t = (Label)e.getTarget(); Label t = (Label) e.getTarget();
t.setLabel(prefixstr + ptab.getTitle() + " tab?"); t.setLabel(prefixstr + ptab.getTitle() + " tab?");
} }
}); });
button = new Submit("Delete this tab"); button = new Submit("Delete this tab");
button.setButtonLabel("Delete this tab"); button.setButtonLabel("Delete this tab");
@ -606,8 +601,8 @@ public class DisplayPane extends DynamicListWizard {
public void process(FormSectionEvent e) { public void process(FormSectionEvent e) {
PageState s = e.getPageState(); PageState s = e.getPageState();
if(button.isSelected(s)) { if (button.isSelected(s)) {
BigDecimal tabID = (BigDecimal)m_tabIDRL.get(s); BigDecimal tabID = (BigDecimal) m_tabIDRL.get(s);
PortalTab ptab = PortalTab.retrieveTab(tabID); PortalTab ptab = PortalTab.retrieveTab(tabID);
ptab.delete(); ptab.delete();
getSelectionModel().clearSelection(s); getSelectionModel().clearSelection(s);
@ -618,6 +613,7 @@ public class DisplayPane extends DynamicListWizard {
} //end delete form } //end delete form
private class RenameLinkListener implements ActionListener { private class RenameLinkListener implements ActionListener {
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
PageState ps = event.getPageState(); PageState ps = event.getPageState();
m_editContainer.setVisibleComponent(ps, m_renameTabForm); m_editContainer.setVisibleComponent(ps, m_renameTabForm);
@ -625,19 +621,19 @@ public class DisplayPane extends DynamicListWizard {
} }
private class DeleteLinkListener implements ActionListener { private class DeleteLinkListener implements ActionListener {
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
PageState ps = event.getPageState(); PageState ps = event.getPageState();
m_editContainer.setVisibleComponent(ps, m_deleteTabForm); m_editContainer.setVisibleComponent(ps, m_deleteTabForm);
} }
} }
private class LayoutListModel implements ListModel private class LayoutListModel implements ListModel {
{
Vector vec; Vector vec;
ListIterator vl; ListIterator vl;
LayoutListModel (PageState pageState) LayoutListModel(PageState pageState) {
{
vec = new Vector(); vec = new Vector();
vec.add("W"); vec.add("W");
vec.add("NW"); vec.add("NW");
@ -648,18 +644,15 @@ public class DisplayPane extends DynamicListWizard {
vl = vec.listIterator(); vl = vec.listIterator();
} }
public boolean next() public boolean next() {
{
return vl.hasNext(); return vl.hasNext();
} }
public Object getElement() public Object getElement() {
{
return vl.next(); return vl.next();
} }
public String getKey() public String getKey() {
{
int dex = vl.previousIndex(); int dex = vl.previousIndex();
dex = dex + 1; dex = dex + 1;
//Integer it = new Integer(vl.previousIndex()); //Integer it = new Integer(vl.previousIndex());
@ -668,34 +661,28 @@ public class DisplayPane extends DynamicListWizard {
} }
} }
class LayoutListCellRenderer implements ListCellRenderer class LayoutListCellRenderer implements ListCellRenderer {
{
public Component getComponent public Component getComponent(List list, PageState pageState, Object value, String key,
(List list, PageState pageState, Object value, String key, int index, boolean isSelected) {
int index, boolean isSelected) String val = (String) value;
{
String val = (String)value;
//check if selected...if not selected //check if selected...if not selected
//find out what index we are... //find out what index we are...
//then set an attribute on the link so that it is replaced //then set an attribute on the link so that it is replaced
//with an image link in the stylesheet. //with an image link in the stylesheet.
//if selected, return a label with a selected attr and value... //if selected, return a label with a selected attr and value...
if(isSelected) if (isSelected) {
{ Label label = new Label(val);
Label label = new Label(val); label.setClassAttr(val);
label.setClassAttr(val); return label;
return label; } else {
} ControlLink link = new ControlLink(val);
else link.setClassAttr(val);
{ link.setStyleAttr("HooHaH");
ControlLink link = new ControlLink(val); return link;
link.setClassAttr(val); }
link.setStyleAttr("HooHaH");
return link;
}
} }
} }
} }

View File

@ -15,7 +15,6 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
package com.arsdigita.portalworkspace.ui; package com.arsdigita.portalworkspace.ui;
import com.arsdigita.bebop.Form; import com.arsdigita.bebop.Form;
@ -63,15 +62,17 @@ public class ApplicationSelector extends Form {
/** /**
* Convenient Constructor * Convenient Constructor
*
* @param type * @param type
* @param app * @param app
*/ */
public ApplicationSelector(ApplicationType type,DomainObjectParameter app) { public ApplicationSelector(ApplicationType type, DomainObjectParameter app) {
this(type, app, null); this(type, app, null);
} }
/** /**
* Constructor * Constructor
*
* @param type * @param type
* @param app * @param app
* @param privilege * @param privilege
@ -85,8 +86,7 @@ public class ApplicationSelector extends Form {
m_app = app; m_app = app;
m_privilege = privilege; m_privilege = privilege;
s_log.debug("displayed applications will be filtered by privilege " + s_log.debug("displayed applications will be filtered by privilege " + m_privilege);
m_privilege);
m_apps = new SingleSelect(new DomainObjectParameter("apps")); m_apps = new SingleSelect(new DomainObjectParameter("apps"));
m_apps.addValidationListener(new NotNullValidationListener()); m_apps.addValidationListener(new NotNullValidationListener());
@ -108,15 +108,16 @@ public class ApplicationSelector extends Form {
* *
*/ */
private class AppSubmissionListener implements FormSubmissionListener { private class AppSubmissionListener implements FormSubmissionListener {
public void submitted(FormSectionEvent e) public void submitted(FormSectionEvent e)
throws FormProcessException { throws FormProcessException {
if (m_buttons.getCancelButton().isSelected(e.getPageState())) { if (m_buttons.getCancelButton().isSelected(e.getPageState())) {
s_log.debug("Firing event for cancel"); s_log.debug("Firing event for cancel");
fireCompletionEvent(e.getPageState()); fireCompletionEvent(e.getPageState());
throw new FormProcessException("canncelled"); throw new FormProcessException("canncelled");
} }
s_log.debug("Falling through for process"); s_log.debug("Falling through for process");
} }
} }
/** /**
@ -130,7 +131,7 @@ public class ApplicationSelector extends Form {
PageState state = e.getPageState(); PageState state = e.getPageState();
state.setValue(m_app, m_apps.getValue(state)); 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", apps.addEqualsFilter("resourceType.id",
m_type.getID()); m_type.getID());
if (m_privilege != null) { if (m_privilege != null) {
Party user = Kernel.getContext().getParty(); Party user = Kernel.getContext().getParty();
if (user == null) { if (user == null) {
user = Kernel.getPublicUser(); user = Kernel.getPublicUser();
} }
PermissionService.filterObjects(apps,m_privilege, user.getOID()); PermissionService.filterObjects(apps, m_privilege, user.getOID());
} }
apps.addOrder("primaryURL"); apps.addOrder("primaryURL");
SingleSelect t = (SingleSelect) e.getTarget(); SingleSelect t = (SingleSelect) e.getTarget();
t.clearOptions();
t.addOption(new Option(null, "--select one--")); t.addOption(new Option(null, "--select one--"));
while (apps.next()) { while (apps.next()) {
Application app = apps.getApplication(); Application app = apps.getApplication();

View File

@ -15,7 +15,6 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
package com.arsdigita.portalworkspace.ui; package com.arsdigita.portalworkspace.ui;
import java.util.TooManyListenersException; 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 $ * @version $Id: LayoutForm.java 1174 2006-06-14 14:14:15Z fabrice $
*/ */
public class LayoutForm extends Form implements FormProcessListener, 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) { public LayoutForm(PortalSelectionModel portal) {
this(null, portal); this(null, portal);
} }
public LayoutForm(WorkspaceSelectionAbstractModel workspace, public LayoutForm(WorkspaceSelectionAbstractModel workspace,
PortalSelectionModel portal) { PortalSelectionModel portal) {
super("editLayout", new SimpleContainer("portal:editLayout", super("editLayout", new SimpleContainer("portal:editLayout",
WorkspacePage.PORTAL_XML_NS)); WorkspacePage.PORTAL_XML_NS));
m_workspace = workspace; m_workspace = workspace;
m_portal = portal; m_portal = portal;
m_layout = new SingleSelect(new OIDParameter("layout")); m_layout = new SingleSelect(new OIDParameter("layout"));
m_layout.addValidationListener(new NotNullValidationListener()); m_layout.addValidationListener(new NotNullValidationListener());
try { try {
m_layout.addPrintListener(new PrintListener() { m_layout.addPrintListener(new PrintListener() {
public void prepare(PrintEvent ev) { public void prepare(PrintEvent ev) {
SingleSelect target = (SingleSelect) ev.getTarget(); SingleSelect target = (SingleSelect) ev.getTarget();
DomainCollection layouts = PageLayout.retrieveAll(); target.clearOptions();
layouts.addOrder(PageLayout.TITLE); DomainCollection layouts = PageLayout.retrieveAll();
while (layouts.next()) { layouts.addOrder(PageLayout.TITLE);
PageLayout layout = (PageLayout) layouts while (layouts.next()) {
.getDomainObject(); PageLayout layout = (PageLayout) layouts
target.addOption(new Option(layout.getOID().toString(), .getDomainObject();
layout.getTitle())); target.addOption(new Option(layout.getOID().toString(),
} layout.getTitle()));
} }
}); }
} catch (TooManyListenersException ex) { });
throw new UncheckedWrapperException("this cannot happen", ex); } 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_layout);
add(m_save); add(m_save);
addProcessListener(this); addProcessListener(this);
addInitListener(this); addInitListener(this);
} }
public void setWorkspaceModel(WorkspaceSelectionAbstractModel workspace) { public void setWorkspaceModel(WorkspaceSelectionAbstractModel workspace) {
m_workspace = workspace; m_workspace = workspace;
} }
public Workspace getSelectedWorkspace(PageState state) { public Workspace getSelectedWorkspace(PageState state) {
return m_workspace.getSelectedWorkspace(state); return m_workspace.getSelectedWorkspace(state);
} }
public void init(FormSectionEvent e) { public void init(FormSectionEvent e) {
PageState state = e.getPageState(); PageState state = e.getPageState();
WorkspacePage portal = (WorkspacePage) m_portal WorkspacePage portal = (WorkspacePage) m_portal
.getSelectedPortal(state); .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) { public void process(FormSectionEvent e) {
PageState state = e.getPageState(); PageState state = e.getPageState();
Workspace workspace = getSelectedWorkspace(state); Workspace workspace = getSelectedWorkspace(state);
Party party = Kernel.getContext().getParty(); Party party = Kernel.getContext().getParty();
if (!PortalHelper.canCustomize(party, workspace)) { if (!PortalHelper.canCustomize(party, workspace)) {
throw new AccessDeniedException( throw new AccessDeniedException(
"no permissions to customize workspace"); "no permissions to customize workspace");
} }
WorkspacePage portal = (WorkspacePage) m_portal WorkspacePage portal = (WorkspacePage) m_portal
.getSelectedPortal(state); .getSelectedPortal(state);
Assert.exists(portal, WorkspacePage.class); Assert.exists(portal, WorkspacePage.class);
OID layoutOID = (OID) m_layout.getValue(state); OID layoutOID = (OID) m_layout.getValue(state);
PageLayout layout = (PageLayout) DomainObjectFactory PageLayout layout = (PageLayout) DomainObjectFactory
.newInstance(layoutOID); .newInstance(layoutOID);
portal.setLayout(layout); portal.setLayout(layout);
} }
} }

View File

@ -12,7 +12,6 @@
* rights and limitations under the License. * rights and limitations under the License.
* *
*/ */
package com.arsdigita.portalworkspace.ui; package com.arsdigita.portalworkspace.ui;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -46,97 +45,98 @@ import com.arsdigita.web.Application;
public class PortletTypeForm extends Form { 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() { private PrintListener m_portletTypePrintListener = new PrintListener() {
public void prepare(PrintEvent e) { public void prepare(PrintEvent e) {
PageState pageState = e.getPageState(); PageState pageState = e.getPageState();
OptionGroup optionGroup = (OptionGroup) e.getTarget(); OptionGroup optionGroup = (OptionGroup) e.getTarget();
optionGroup.clearOptions();
PortletTypeCollection portletTypes = PortletType PortletTypeCollection portletTypes = PortletType
.retrieveAllPortletTypes(); .retrieveAllPortletTypes();
List excludedTypes = Workspace.getConfig() List excludedTypes = Workspace.getConfig()
.getExcludedPortletTypes(); .getExcludedPortletTypes();
if (!excludedTypes.isEmpty()) { if (!excludedTypes.isEmpty()) {
Filter excludedTypesFilter = portletTypes Filter excludedTypesFilter = portletTypes
.addFilter(Application.OBJECT_TYPE .addFilter(Application.OBJECT_TYPE
+ " not in :nonDisplayTypes"); + " not in :nonDisplayTypes");
excludedTypesFilter.set("nonDisplayTypes", excludedTypes); excludedTypesFilter.set("nonDisplayTypes", excludedTypes);
} }
User thisUser = (User) Kernel.getContext().getParty(); User thisUser = (User) Kernel.getContext().getParty();
if (thisUser == null) { if (thisUser == null) {
// can't actually happen, as user must be logged in at the point // can't actually happen, as user must be logged in at the point
// when the page with this portal in edit mode was requested // when the page with this portal in edit mode was requested
thisUser = Kernel.getPublicUser(); thisUser = Kernel.getPublicUser();
} }
Workspace mainWorkspace; Workspace mainWorkspace;
if (Subsite.getContext().hasSite()) { if (Subsite.getContext().hasSite()) {
mainWorkspace = (Workspace) Subsite.getContext().getSite() mainWorkspace = (Workspace) Subsite.getContext().getSite()
.getFrontPage(); .getFrontPage();
} else { } else {
mainWorkspace = Workspace.getDefaultHomepageWorkspace(); mainWorkspace = Workspace.getDefaultHomepageWorkspace();
} }
PermissionDescriptor admin = new PermissionDescriptor( PermissionDescriptor admin = new PermissionDescriptor(
PrivilegeDescriptor.ADMIN, mainWorkspace, thisUser); PrivilegeDescriptor.ADMIN, mainWorkspace, thisUser);
if (PermissionService.checkPermission(admin)) { if (PermissionService.checkPermission(admin)) {
s_log.debug(thisUser.getName() s_log.debug(thisUser.getName()
+ " has admin rights on the current workspace"); + " has admin rights on the current workspace");
} else { } else {
s_log.debug(thisUser.getName() s_log.debug(thisUser.getName()
+ " cannot administer the current main workspace"); + " cannot administer the current main workspace");
List adminTypes = Workspace.getConfig().getAdminPortletTypes(); List adminTypes = Workspace.getConfig().getAdminPortletTypes();
if (!adminTypes.isEmpty()) { if (!adminTypes.isEmpty()) {
Filter adminTypesFilter = portletTypes Filter adminTypesFilter = portletTypes
.addFilter(Application.OBJECT_TYPE .addFilter(Application.OBJECT_TYPE
+ " not in :adminTypes"); + " not in :adminTypes");
adminTypesFilter.set("adminTypes", adminTypes); adminTypesFilter.set("adminTypes", adminTypes);
} }
} }
portletTypes.addOrder("title"); portletTypes.addOrder("title");
while (portletTypes.next()) { while (portletTypes.next()) {
PortletType portletType = portletTypes.getPortletType(); PortletType portletType = portletTypes.getPortletType();
Option option = new Option(portletType.getID().toString(), Option option = new Option(portletType.getID().toString(),
portletType.getTitle()); portletType.getTitle());
optionGroup.addOption(option); optionGroup.addOption(option);
} }
} }
}; };
/** /**
* Default constructor * Default constructor
*/ */
public PortletTypeForm() { public PortletTypeForm() {
this("portletTypeForm"); this("portletTypeForm");
} }
public PortletTypeForm(String name) { public PortletTypeForm(String name) {
super(name, new SimpleContainer()); super(name, new SimpleContainer());
setRedirecting(true); setRedirecting(true);
m_portletType = new SingleSelect("portletTypeID"); m_portletType = new SingleSelect("portletTypeID");
try { try {
m_portletType.addPrintListener(m_portletTypePrintListener); m_portletType.addPrintListener(m_portletTypePrintListener);
} catch (TooManyListenersException e) { } catch (TooManyListenersException e) {
/* Nothing here yet. */ /* Nothing here yet. */
} }
m_portletType.addValidationListener(new NotNullValidationListener( m_portletType.addValidationListener(new NotNullValidationListener(
"You must select a Portlet Type")); "You must select a Portlet Type"));
add(m_portletType); add(m_portletType);
m_submit = new Submit("Add"); m_submit = new Submit("Add");
add(m_submit); add(m_submit);
} }
public BigDecimal getPortletType(PageState state) { public BigDecimal getPortletType(PageState state) {
return new BigDecimal((String) m_portletType.getValue(state)); return new BigDecimal((String) m_portletType.getValue(state));
} }
} }

View File

@ -15,7 +15,6 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
package com.arsdigita.portalworkspace.ui.admin; package com.arsdigita.portalworkspace.ui.admin;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -46,113 +45,113 @@ import com.arsdigita.util.UncheckedWrapperException;
public abstract class GroupMemberPicker extends UserPicker { 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() { protected void addWidgets() {
m_restrictParam = new StringParameter("restrict"); m_restrictParam = new StringParameter("restrict");
m_restrict = new SingleSelect("restrict1"); m_restrict = new SingleSelect("restrict1");
m_both = new Option("both", "Users & Groups"); m_both = new Option("both", "Users & Groups");
m_users = new Option("users", "Users Only"); m_users = new Option("users", "Users Only");
m_groups = new Option("groups", "Groups Only"); m_groups = new Option("groups", "Groups Only");
m_restrict.addOption(m_both); m_restrict.addOption(m_both);
m_restrict.addOption(m_users); m_restrict.addOption(m_users);
m_restrict.addOption(m_groups); m_restrict.addOption(m_groups);
m_restrict.setOptionSelected(m_users); m_restrict.setOptionSelected(m_users);
BoxPanel opt = new BoxPanel(BoxPanel.HORIZONTAL); BoxPanel opt = new BoxPanel(BoxPanel.HORIZONTAL);
opt.add(new Label("Search for")); opt.add(new Label("Search for"));
opt.add(m_restrict); opt.add(m_restrict);
add(opt); add(opt);
super.addWidgets(); super.addWidgets();
} }
public void register(Page p) { public void register(Page p) {
super.register(p); super.register(p);
p.addGlobalStateParam(m_restrictParam); p.addGlobalStateParam(m_restrictParam);
} }
public void init(FormSectionEvent e) { public void init(FormSectionEvent e) {
PageState ps = e.getPageState(); 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) { public void process(FormSectionEvent e) {
PageState ps = e.getPageState(); 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) { protected DataQuery getUsers(PageState ps, String search) {
String bdot = Party.BASE_DATA_OBJECT_TYPE; String bdot = Party.BASE_DATA_OBJECT_TYPE;
if (m_users.getValue().equals(ps.getValue(m_restrictParam))) { if (m_users.getValue().equals(ps.getValue(m_restrictParam))) {
bdot = User.BASE_DATA_OBJECT_TYPE; bdot = User.BASE_DATA_OBJECT_TYPE;
} else if (m_groups.getValue().equals(ps.getValue(m_restrictParam))) { } else if (m_groups.getValue().equals(ps.getValue(m_restrictParam))) {
bdot = Group.BASE_DATA_OBJECT_TYPE; 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( Filter nameFilter = parties.getFilterFactory().simple(
"lower(displayName) like lower(:term)"); "lower(displayName) like lower(:term)");
nameFilter.set("term", "%" + search + "%"); nameFilter.set("term", "%" + search + "%");
Filter emailFilter = parties.getFilterFactory().simple( Filter emailFilter = parties.getFilterFactory().simple(
"lower(primaryEmail) like lower(:term)"); "lower(primaryEmail) like lower(:term)");
emailFilter.set("term", "%" + search + "%"); emailFilter.set("term", "%" + search + "%");
or.addFilter(nameFilter); or.addFilter(nameFilter);
or.addFilter(emailFilter); or.addFilter(emailFilter);
parties.addFilter(or); parties.addFilter(or);
parties.addOrder(ACSObject.DISPLAY_NAME); parties.addOrder(ACSObject.DISPLAY_NAME);
return parties; return parties;
} }
protected String getDisplayName(DataQuery q) { protected String getDisplayName(DataQuery q) {
DataObject party = ((DataCollection) q).getDataObject(); DataObject party = ((DataCollection) q).getDataObject();
return (String) party.get(ACSObject.DISPLAY_NAME); return (String) party.get(ACSObject.DISPLAY_NAME);
} }
protected String getKey(DataQuery q) { protected String getKey(DataQuery q) {
DataObject party = ((DataCollection) q).getDataObject(); DataObject party = ((DataCollection) q).getDataObject();
return party.get(ACSObject.ID).toString(); return party.get(ACSObject.ID).toString();
} }
protected void addUser(PageState ps, BigDecimal userID) { protected void addUser(PageState ps, BigDecimal userID) {
Party party = null; Party party = null;
try { try {
party = (Party) DomainObjectFactory.newInstance(new OID( party = (Party) DomainObjectFactory.newInstance(new OID(
Party.BASE_DATA_OBJECT_TYPE, userID)); Party.BASE_DATA_OBJECT_TYPE, userID));
} catch (DataObjectNotFoundException ex) { } catch (DataObjectNotFoundException ex) {
throw new UncheckedWrapperException("cannot find user", ex); throw new UncheckedWrapperException("cannot find user", ex);
} }
Group group = getGroup(ps); Group group = getGroup(ps);
group.addMemberOrSubgroup(party); group.addMemberOrSubgroup(party);
group.save(); group.save();
} }
} }

View File

@ -15,7 +15,6 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
package com.arsdigita.portalworkspace.ui.admin; package com.arsdigita.portalworkspace.ui.admin;
import java.util.TooManyListenersException; import java.util.TooManyListenersException;
@ -41,77 +40,75 @@ import com.arsdigita.util.UncheckedWrapperException;
import com.arsdigita.web.Application; import com.arsdigita.web.Application;
import com.arsdigita.web.ui.ApplicationConfigFormSection; import com.arsdigita.web.ui.ApplicationConfigFormSection;
// Referenced in Initializer. // Referenced in Initializer.
// No other referebce found. // No other referebce found.
// TODO: What happens if omitted? // TODO: What happens if omitted?
// (2013-02-10pb) // (2013-02-10pb)
/** /**
* *
* *
*/ */
public class WorkspaceConfigFormSection extends ApplicationConfigFormSection { public class WorkspaceConfigFormSection extends ApplicationConfigFormSection {
private SingleSelect m_layout; private SingleSelect m_layout;
public WorkspaceConfigFormSection(ResourceType resType, public WorkspaceConfigFormSection(ResourceType resType,
RequestLocal parentAppRL) { RequestLocal parentAppRL) {
super(resType, parentAppRL); super(resType, parentAppRL);
} }
public WorkspaceConfigFormSection(RequestLocal application) { public WorkspaceConfigFormSection(RequestLocal application) {
super(application); super(application);
} }
protected void addWidgets() { protected void addWidgets() {
super.addWidgets(); super.addWidgets();
m_layout = new SingleSelect(new OIDParameter("layout")); m_layout = new SingleSelect(new OIDParameter("layout"));
m_layout.addValidationListener(new NotNullValidationListener()); m_layout.addValidationListener(new NotNullValidationListener());
try { try {
m_layout.addPrintListener(new PrintListener() { m_layout.addPrintListener(new PrintListener() {
public void prepare(PrintEvent ev) { public void prepare(PrintEvent ev) {
SingleSelect target = (SingleSelect) ev.getTarget(); SingleSelect target = (SingleSelect) ev.getTarget();
DomainCollection layouts = PageLayout.retrieveAll(); target.clearOptions();
layouts.addOrder(PageLayout.TITLE); DomainCollection layouts = PageLayout.retrieveAll();
while (layouts.next()) { layouts.addOrder(PageLayout.TITLE);
PageLayout layout = (PageLayout) layouts while (layouts.next()) {
.getDomainObject(); PageLayout layout = (PageLayout) layouts
target.addOption(new Option(layout.getOID().toString(), .getDomainObject();
layout.getTitle())); target.addOption(new Option(layout.getOID().toString(),
} layout.getTitle()));
} }
}); }
} catch (TooManyListenersException ex) { });
throw new UncheckedWrapperException("this cannot happen", ex); } catch (TooManyListenersException ex) {
} throw new UncheckedWrapperException("this cannot happen", ex);
add(new Label("Default Page Layout:", Label.BOLD), ColumnPanel.RIGHT); }
add(m_layout); add(new Label("Default Page Layout:", Label.BOLD), ColumnPanel.RIGHT);
} add(m_layout);
}
protected void initWidgets(PageState state, Application app) protected void initWidgets(PageState state, Application app)
throws FormProcessException { throws FormProcessException {
super.initWidgets(state, app); super.initWidgets(state, app);
if (app != null) { if (app != null) {
Workspace workspace = (Workspace) app; Workspace workspace = (Workspace) app;
m_layout.setValue(state, workspace.getDefaultLayout().getOID()); m_layout.setValue(state, workspace.getDefaultLayout().getOID());
} else { } else {
m_layout.setValue(state, PageLayout.getDefaultLayout().getOID()); m_layout.setValue(state, PageLayout.getDefaultLayout().getOID());
} }
} }
protected void processWidgets(PageState state, Application app) protected void processWidgets(PageState state, Application app)
throws FormProcessException { throws FormProcessException {
super.processWidgets(state, app); super.processWidgets(state, app);
Workspace workspace = (Workspace) app; Workspace workspace = (Workspace) app;
OID layoutOID = (OID) m_layout.getValue(state); OID layoutOID = (OID) m_layout.getValue(state);
PageLayout layout = (PageLayout) DomainObjectFactory PageLayout layout = (PageLayout) DomainObjectFactory
.newInstance(layoutOID); .newInstance(layoutOID);
workspace.setDefaultLayout(layout); workspace.setDefaultLayout(layout);
} }
} }

View File

@ -62,6 +62,7 @@ public class WorkspaceCreateForm extends ApplicationCreateForm<Workspace> {
layout.addPrintListener(new PrintListener() { layout.addPrintListener(new PrintListener() {
public void prepare(final PrintEvent event) { public void prepare(final PrintEvent event) {
final SingleSelect target = (SingleSelect) event.getTarget(); final SingleSelect target = (SingleSelect) event.getTarget();
target.clearOptions();
final DomainCollection layouts = PageLayout.retrieveAll(); final DomainCollection layouts = PageLayout.retrieveAll();
layouts.addOrder(PageLayout.TITLE); layouts.addOrder(PageLayout.TITLE);
while (layouts.next()) { while (layouts.next()) {

View File

@ -12,7 +12,6 @@
* rights and limitations under the License. * rights and limitations under the License.
* *
*/ */
package com.arsdigita.portalworkspace.ui.portlet; package com.arsdigita.portalworkspace.ui.portlet;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -55,134 +54,137 @@ import com.arsdigita.web.Web;
*/ */
public class ContentDirectoryPortletEditor extends PortletConfigFormSection { public class ContentDirectoryPortletEditor extends PortletConfigFormSection {
private static final Logger s_log = Logger private static final Logger s_log = Logger
.getLogger(ContentDirectoryPortletEditor.class); .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 * Constructor
*
* @param resType * @param resType
* @param parentAppRL * @param parentAppRL
*/ */
public ContentDirectoryPortletEditor(ResourceType resType, public ContentDirectoryPortletEditor(ResourceType resType,
RequestLocal parentAppRL) { RequestLocal parentAppRL) {
super(resType, parentAppRL); super(resType, parentAppRL);
} }
/** /**
* *
* @param application * @param application
*/ */
public ContentDirectoryPortletEditor(RequestLocal application) { public ContentDirectoryPortletEditor(RequestLocal application) {
super(application); super(application);
} }
/** /**
* *
*/ */
public void addWidgets() { public void addWidgets() {
super.addWidgets(); super.addWidgets();
m_root = new SingleSelect(new BigDecimalParameter("root")); m_root = new SingleSelect(new BigDecimalParameter("root"));
try { try {
m_root.addPrintListener(new CategoryPrintListener()); m_root.addPrintListener(new CategoryPrintListener());
} catch (TooManyListenersException ex) { } catch (TooManyListenersException ex) {
throw new UncheckedWrapperException("this cannot happen", ex); throw new UncheckedWrapperException("this cannot happen", ex);
} }
m_layout = new SingleSelect(new StringParameter("layout")); m_layout = new SingleSelect(new StringParameter("layout"));
m_layout.addOption(new Option("grid", "Grid")); m_layout.addOption(new Option("grid", "Grid"));
m_layout.addOption(new Option("panel", "Panel")); m_layout.addOption(new Option("panel", "Panel"));
m_depth = new SingleSelect(new IntegerParameter("depth")); m_depth = new SingleSelect(new IntegerParameter("depth"));
m_depth.addOption(new Option("1", "1 Level")); m_depth.addOption(new Option("1", "1 Level"));
m_depth.addOption(new Option("2", "2 Levels")); m_depth.addOption(new Option("2", "2 Levels"));
add(new Label("Root category:", Label.BOLD), ColumnPanel.RIGHT); add(new Label("Root category:", Label.BOLD), ColumnPanel.RIGHT);
add(m_root); add(m_root);
add(new Label("Layout:", Label.BOLD), ColumnPanel.RIGHT); add(new Label("Layout:", Label.BOLD), ColumnPanel.RIGHT);
add(m_layout); add(m_layout);
add(new Label("Depth:", Label.BOLD), ColumnPanel.RIGHT); add(new Label("Depth:", Label.BOLD), ColumnPanel.RIGHT);
add(m_depth); add(m_depth);
} }
/** /**
* *
* @param state * @param state
* @param portlet * @param portlet
* @throws FormProcessException * @throws FormProcessException
*/ */
public void initWidgets(PageState state, Portlet portlet) public void initWidgets(PageState state, Portlet portlet)
throws FormProcessException { throws FormProcessException {
super.initWidgets(state, portlet); super.initWidgets(state, portlet);
if (portlet != null) { if (portlet != null) {
ContentDirectoryPortlet myportlet = (ContentDirectoryPortlet) portlet; ContentDirectoryPortlet myportlet = (ContentDirectoryPortlet) portlet;
m_root.setValue(state, myportlet.getRoot().getID()); m_root.setValue(state, myportlet.getRoot().getID());
m_layout.setValue(state, myportlet.getLayout()); m_layout.setValue(state, myportlet.getLayout());
m_depth.setValue(state, new Integer(myportlet.getDepth())); m_depth.setValue(state, new Integer(myportlet.getDepth()));
} }
} }
/** /**
* *
* @param state * @param state
* @param portlet * @param portlet
* @throws FormProcessException * @throws FormProcessException
*/ */
public void processWidgets(PageState state, Portlet portlet) public void processWidgets(PageState state, Portlet portlet)
throws FormProcessException { throws FormProcessException {
super.processWidgets(state, portlet); super.processWidgets(state, portlet);
ContentDirectoryPortlet myportlet = (ContentDirectoryPortlet) portlet; ContentDirectoryPortlet myportlet = (ContentDirectoryPortlet) portlet;
myportlet.setLayout((String) m_layout.getValue(state)); myportlet.setLayout((String) m_layout.getValue(state));
myportlet.setDepth(((Integer) m_depth.getValue(state)).intValue()); myportlet.setDepth(((Integer) m_depth.getValue(state)).intValue());
BigDecimal id = (BigDecimal) m_root.getValue(state); BigDecimal id = (BigDecimal) m_root.getValue(state);
Category root; Category root;
try { try {
root = (Category) DomainObjectFactory.newInstance(new OID( root = (Category) DomainObjectFactory.newInstance(new OID(
Category.BASE_DATA_OBJECT_TYPE, id)); Category.BASE_DATA_OBJECT_TYPE, id));
} catch (DataObjectNotFoundException ex) { } catch (DataObjectNotFoundException ex) {
throw new UncheckedWrapperException("cannot find category", ex); throw new UncheckedWrapperException("cannot find category", ex);
} }
myportlet.setRoot(root); myportlet.setRoot(root);
} }
/** /**
* *
* @return * @return
*/ */
protected String getUseContext() { protected String getUseContext() {
return null; return null;
} }
/** /**
* *
*/ */
private class CategoryPrintListener implements PrintListener { private class CategoryPrintListener implements PrintListener {
public void prepare(PrintEvent e) {
SingleSelect target = (SingleSelect) e.getTarget();
Application app = Web.getWebContext().getApplication(); public void prepare(PrintEvent e) {
Category root = Category.getRootForObject(app, getUseContext()); SingleSelect target = (SingleSelect) e.getTarget();
target.clearOptions();
Map cats = CategorizationTree.getSubtreePath(root, " > "); Application app = Web.getWebContext().getApplication();
Iterator i = cats.keySet().iterator(); Category root = Category.getRootForObject(app, getUseContext());
while (i.hasNext()) {
String path = (String) i.next();
Category cat = (Category) cats.get(path);
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));
}
}
}
} }

View File

@ -15,7 +15,6 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
package com.arsdigita.portalworkspace.ui.portlet; package com.arsdigita.portalworkspace.ui.portlet;
import com.arsdigita.bebop.ColumnPanel; import com.arsdigita.bebop.ColumnPanel;
@ -39,8 +38,8 @@ import com.arsdigita.portal.Portlet;
/** /**
* @author <a href="https://sourceforge.net/users/terry_permeance/">terry_permeance</a> * @author <a href="https://sourceforge.net/users/terry_permeance/">terry_permeance</a>
*/ */
public class FlashPortletEditor extends PortletConfigFormSection public class FlashPortletEditor extends PortletConfigFormSection {
{
private TextField m_backgroundColour; private TextField m_backgroundColour;
private TextField m_detectKey; private TextField m_detectKey;
@ -63,25 +62,23 @@ public class FlashPortletEditor extends PortletConfigFormSection
private TextField m_xiRedirectUrl; private TextField m_xiRedirectUrl;
public FlashPortletEditor(ResourceType resType, RequestLocal parentAppRL) public FlashPortletEditor(ResourceType resType, RequestLocal parentAppRL) {
{
super(resType, parentAppRL); super(resType, parentAppRL);
} }
public FlashPortletEditor(RequestLocal application) public FlashPortletEditor(RequestLocal application) {
{
super(application); super(application);
} }
protected void addWidgets() protected void addWidgets() {
{
super.addWidgets(); super.addWidgets();
m_file = this.addTextField(FlashPortlet.SWF_FILE, "SWF file", 64, 2048, true); m_file = this.addTextField(FlashPortlet.SWF_FILE, "SWF file", 64, 2048, true);
m_width = this.addTextField(FlashPortlet.WIDTH, "Width", 8, 8, true); m_width = this.addTextField(FlashPortlet.WIDTH, "Width", 8, 8, true);
m_height = this.addTextField(FlashPortlet.HEIGHT, "Height", 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_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_backgroundColour.addValidationListener(new HTMLColourCodeValidationListener());
m_quality = this.addSingleSelect(FlashPortlet.QUALITY, "Quality", false); 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_variables = this.addTextArea(FlashPortlet.VARIABLES, "Variables", 4, 64, false);
m_detectKey = this.addTextField(FlashPortlet.DETECT_KEY, "Detect key", 32, 32, 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_redirectUrl = this.
m_xiRedirectUrl = this.addTextField(FlashPortlet.XI_REDIRECT_URL, "XI Redirect URL", 64, 2048, false); 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); super.initWidgets(state, portlet);
if (portlet != null) if (portlet != null) {
{
FlashPortlet flashPortlet = (FlashPortlet) portlet; FlashPortlet flashPortlet = (FlashPortlet) portlet;
// Load the form from the portlet // Load the form from the portlet
@ -123,12 +121,11 @@ public class FlashPortletEditor extends PortletConfigFormSection
m_width.setValue(state, flashPortlet.getWidth()); m_width.setValue(state, flashPortlet.getWidth());
m_xiRedirectUrl.setValue(state, flashPortlet.getXiRedirectUrl()); m_xiRedirectUrl.setValue(state, flashPortlet.getXiRedirectUrl());
m_quality.setValue(state, flashPortlet.getQuality()); m_quality.setValue(state, flashPortlet.getQuality());
} } else {
else
{
// Set defaults // Set defaults
m_backgroundColour.setValue(state, "#ffffff"); 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_width.setValue(state, "100%");
m_height.setValue(state, "100%"); m_height.setValue(state, "100%");
m_version.setValue(state, "8.0"); 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); super.processWidgets(state, portlet);
FlashPortlet flashPortlet = (FlashPortlet) portlet; FlashPortlet flashPortlet = (FlashPortlet) portlet;
@ -159,32 +155,27 @@ public class FlashPortletEditor extends PortletConfigFormSection
/** /**
* Add a new text field. * Add a new text field.
* *
* @param name * @param name the name of the parameter
* the name of the parameter * @param label the label to be displayed
* @param label * @param size the visible size of the text field
* the label to be displayed * @param maxLength the maximum length of text that can be entered
* @param size * @param mandatory denotes whether this text field requires a value
* 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 * @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)); TextField field = new TextField(new StringParameter(name));
field.setSize(size); field.setSize(size);
field.setMaxLength(maxLength); field.setMaxLength(maxLength);
// Add validation // Add validation
if (mandatory) if (mandatory) {
{
field.addValidationListener(new NotEmptyValidationListener()); field.addValidationListener(new NotEmptyValidationListener());
} }
// Add to the form // 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); add(field);
return field; return field;
} }
@ -192,30 +183,24 @@ public class FlashPortletEditor extends PortletConfigFormSection
/** /**
* Add a new text area. * Add a new text area.
* *
* @param name * @param name the name of the parameter
* the name of the parameter * @param label the label to be displayed
* @param label * @param rows the visible rows
* the label to be displayed * @param cols the visible cols
* @param rows * @param mandatory denotes whether this text field requires a value
* the visible rows
* @param cols
* the visible cols
* @param mandatory
* denotes whether this text field requires a value
* @return the text area * @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); TextArea field = new TextArea(new StringParameter(name), rows, cols, TextArea.SOFT);
// Add validation // Add validation
if (mandatory) if (mandatory) {
{
field.addValidationListener(new NotEmptyValidationListener()); field.addValidationListener(new NotEmptyValidationListener());
} }
// Add to the form // 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); add(field);
return field; return field;
} }
@ -223,26 +208,22 @@ public class FlashPortletEditor extends PortletConfigFormSection
/** /**
* Add a new single select. * Add a new single select.
* *
* @param name * @param name the name of the parameter
* the name of the parameter * @param label the label to be displayed
* @param label * @param mandatory denotes whether this text field requires a value
* the label to be displayed
* @param mandatory
* denotes whether this text field requires a value
* @return the text area * @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)); SingleSelect field = new SingleSelect(new StringParameter(name));
// Add validation // Add validation
if (mandatory) if (mandatory) {
{
field.addValidationListener(new NotEmptyValidationListener()); field.addValidationListener(new NotEmptyValidationListener());
} }
// Add to the form // 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); add(field);
return field; return field;
} }

View File

@ -12,7 +12,6 @@
* rights and limitations under the License. * rights and limitations under the License.
* *
*/ */
package com.arsdigita.portalworkspace.ui.portlet; package com.arsdigita.portalworkspace.ui.portlet;
import java.util.Iterator; import java.util.Iterator;
@ -39,140 +38,142 @@ import com.arsdigita.xml.Element;
public class RSSFeedPortletBrowserForm extends Form { 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() { public RSSFeedPortletBrowserForm() {
super("Browser"); super("Browser");
m_hosts_pnl = new BoxPanel(BoxPanel.HORIZONTAL); m_hosts_pnl = new BoxPanel(BoxPanel.HORIZONTAL);
m_feeds_pnl = new BoxPanel(BoxPanel.HORIZONTAL); m_feeds_pnl = new BoxPanel(BoxPanel.HORIZONTAL);
add(m_hosts_pnl); add(m_hosts_pnl);
add(m_feeds_pnl); add(m_feeds_pnl);
Label hosts_lbl = new Label("Hosts:"); Label hosts_lbl = new Label("Hosts:");
Label feeds_lbl = new Label("Feeds:"); Label feeds_lbl = new Label("Feeds:");
m_no_feeds = new Label("none available"); m_no_feeds = new Label("none available");
m_hosts_pnl.add(hosts_lbl); m_hosts_pnl.add(hosts_lbl);
m_feeds_pnl.add(feeds_lbl); m_feeds_pnl.add(feeds_lbl);
m_feeds_pnl.add(m_no_feeds); m_feeds_pnl.add(m_no_feeds);
m_hosts = new SingleSelect(new StringParameter("host")); m_hosts = new SingleSelect(new StringParameter("host"));
m_feeds = new SingleSelect(new StringParameter("feed")); m_feeds = new SingleSelect(new StringParameter("feed"));
m_hosts_pnl.add(m_hosts); m_hosts_pnl.add(m_hosts);
m_feeds_pnl.add(m_feeds); m_feeds_pnl.add(m_feeds);
m_back = new Submit("back", "Back"); m_back = new Submit("back", "Back");
m_cancel = new Submit("cancel", "Back"); m_cancel = new Submit("cancel", "Back");
m_display = new Submit("display", "Display feeds"); m_display = new Submit("display", "Display feeds");
m_select = new Submit("select", "Select feed"); m_select = new Submit("select", "Select feed");
m_feeds_pnl.add(m_back); m_feeds_pnl.add(m_back);
m_feeds_pnl.add(m_select); m_feeds_pnl.add(m_select);
m_hosts_pnl.add(m_cancel); m_hosts_pnl.add(m_cancel);
m_hosts_pnl.add(m_display); m_hosts_pnl.add(m_display);
addProcessListener(new FormProcessListener() { addProcessListener(new FormProcessListener() {
public void process(FormSectionEvent e) throws FormProcessException { public void process(FormSectionEvent e) throws FormProcessException {
PageState state = e.getPageState(); PageState state = e.getPageState();
if (m_select.isSelected(state)) { if (m_select.isSelected(state)) {
fireCompletionEvent(state); fireCompletionEvent(state);
} else if (m_display.isSelected(state)) { } else if (m_display.isSelected(state)) {
setDisplay(state, false); setDisplay(state, false);
} else if (m_back.isSelected(state)) { } else if (m_back.isSelected(state)) {
setDisplay(state, true); setDisplay(state, true);
} else if (m_cancel.isSelected(state)) { } else if (m_cancel.isSelected(state)) {
fireCompletionEvent(state); fireCompletionEvent(state);
} }
} }
}); });
try { try {
m_hosts.addPrintListener(new PrintListener() { m_hosts.addPrintListener(new PrintListener() {
public void prepare(PrintEvent e) { public void prepare(PrintEvent e) {
SingleSelect group = (SingleSelect) e.getTarget(); SingleSelect group = (SingleSelect) e.getTarget();
group.clearOptions();
Iterator hosts = RSSFeedPortletHelper.getACSJHosts(); Iterator hosts = RSSFeedPortletHelper.getACSJHosts();
while (hosts.hasNext()) { while (hosts.hasNext()) {
String host[] = (String[]) hosts.next(); String host[] = (String[]) hosts.next();
group.addOption(new Option(host[0], host[1])); group.addOption(new Option(host[0], host[1]));
} }
} }
}); });
} catch (TooManyListenersException ex) { } catch (TooManyListenersException ex) {
throw new UncheckedWrapperException("This can never happen", ex); throw new UncheckedWrapperException("This can never happen", ex);
} }
try { try {
m_feeds.addPrintListener(new PrintListener() { m_feeds.addPrintListener(new PrintListener() {
public void prepare(PrintEvent e) { public void prepare(PrintEvent e) {
SingleSelect group = (SingleSelect) e.getTarget(); SingleSelect group = (SingleSelect) e.getTarget();
group.clearOptions();
Iterator feeds = (Iterator) m_feed.get(e.getPageState()); Iterator feeds = (Iterator) m_feed.get(e.getPageState());
while (feeds != null && feeds.hasNext()) { while (feeds != null && feeds.hasNext()) {
String feed[] = (String[]) feeds.next(); String feed[] = (String[]) feeds.next();
group.addOption(new Option(feed[0], feed[1])); group.addOption(new Option(feed[0], feed[1]));
} }
} }
}); });
} catch (TooManyListenersException ex) { } catch (TooManyListenersException ex) {
throw new UncheckedWrapperException("This can never happen", ex); throw new UncheckedWrapperException("This can never happen", ex);
} }
} }
public String getFeedURL(PageState state) { public String getFeedURL(PageState state) {
return (String) m_feeds.getValue(state); return (String) m_feeds.getValue(state);
} }
public void register(Page p) { public void register(Page p) {
super.register(p); super.register(p);
p.setVisibleDefault(m_hosts_pnl, true); p.setVisibleDefault(m_hosts_pnl, true);
p.setVisibleDefault(m_feeds_pnl, false); p.setVisibleDefault(m_feeds_pnl, false);
} }
private void setDisplay(PageState state, boolean initial) { private void setDisplay(PageState state, boolean initial) {
m_hosts_pnl.setVisible(state, initial); m_hosts_pnl.setVisible(state, initial);
m_feeds_pnl.setVisible(state, !initial); m_feeds_pnl.setVisible(state, !initial);
} }
public void generateXML(PageState state, Element parent) { public void generateXML(PageState state, Element parent) {
if (m_hosts.getValue(state) == null) { if (m_hosts.getValue(state) == null) {
m_feed.set(state, null); m_feed.set(state, null);
setDisplay(state, true); setDisplay(state, true);
} else { } else {
String host = (String) m_hosts.getValue(state); String host = (String) m_hosts.getValue(state);
Iterator feed = RSSFeedPortletHelper.getACSJFeeds(host); Iterator feed = RSSFeedPortletHelper.getACSJFeeds(host);
m_feed.set(state, feed); m_feed.set(state, feed);
m_no_feeds.setVisible(state, !feed.hasNext()); m_no_feeds.setVisible(state, !feed.hasNext());
m_feeds.setVisible(state, feed.hasNext()); m_feeds.setVisible(state, feed.hasNext());
m_select.setVisible(state, feed.hasNext()); m_select.setVisible(state, feed.hasNext());
} }
super.generateXML(state, parent); super.generateXML(state, parent);
} }
} }

View File

@ -17,7 +17,8 @@
* *
*/ */
package com.arsdigita.simplesurvey.ui.admin; 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.FormSectionEvent;
import com.arsdigita.bebop.event.FormProcessListener; 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.ActionListener;
import com.arsdigita.bebop.event.PrintEvent; import com.arsdigita.bebop.event.PrintEvent;
import com.arsdigita.bebop.event.ActionEvent; 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.Form;
import com.arsdigita.bebop.Link; import com.arsdigita.bebop.Link;
import com.arsdigita.bebop.Page; import com.arsdigita.bebop.Page;
@ -62,11 +63,10 @@ import com.arsdigita.simplesurvey.ui.SurveySelectionModel;
import java.math.BigDecimal; 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 // 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 // Each of the answers contains a link that leads to a drop-down value selection widget
private SurveySelectionModel m_survey; private SurveySelectionModel m_survey;
private static final String QUESTION_TEXT = "questionText"; private static final String QUESTION_TEXT = "questionText";
private static final String ANSWER_TEXT = "answerText"; private static final String ANSWER_TEXT = "answerText";
@ -85,291 +85,316 @@ public class AnswerValuesPanel extends SimpleContainer {
private ActionLink m_complete; private ActionLink m_complete;
private Link m_back; private Link m_back;
private static org.apache.log4j.Logger s_log = private static org.apache.log4j.Logger s_log
org.apache.log4j.Logger.getLogger(AnswerValuesPanel.class.getName()); = org.apache.log4j.Logger.getLogger(
AnswerValuesPanel.class.getName());
private DataTable m_answerTable; private DataTable m_answerTable;
public AnswerValuesPanel(SurveySelectionModel survey) { public AnswerValuesPanel(SurveySelectionModel survey) {
super(); super();
m_survey = survey; m_survey = survey;
m_answerText = new RequestLocal(); m_answerText = new RequestLocal();
m_questionText = new RequestLocal(); m_questionText = new RequestLocal();
m_answerValue = new RequestLocal(); m_answerValue = new RequestLocal();
m_complete = new ActionLink( (String) GlobalizationUtil.globalize("simplesurvey.ui.admin.back_to_question_list").localize()); m_complete = new ActionLink((String) GlobalizationUtil.globalize(
m_complete.addActionListener(new ActionListener() { "simplesurvey.ui.admin.back_to_question_list").localize());
public void actionPerformed(ActionEvent e) { m_complete.addActionListener(new ActionListener() {
PageState ps = e.getPageState(); public void actionPerformed(ActionEvent e) {
m_answerTable.setVisible(ps, true); PageState ps = e.getPageState();
m_answerValuesForm.setVisible(ps, false); m_answerTable.setVisible(ps, true);
m_complete.setVisible(ps,false); m_answerValuesForm.setVisible(ps, false);
m_back.setVisible(ps, true); 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"); });
m_back = new Link(new Label(GlobalizationUtil.globalize(
"simplesurvey.ui.admin.back_to_survey_list")), "../admin");
add(m_complete); add(m_complete);
add(m_back); add(m_back);
setupAnswerTable(); setupAnswerTable();
setupAnswerValuesForm(); 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 || public void register(Page p) {
m_answerValuesForm.getFormData(ps).isSubmission()) { p.setVisibleDefault(m_answerValuesForm, false);
m_answerTable.setVisible(ps, true); m_optionID = new BigDecimalParameter("option_id");
m_answerValuesForm.setVisible(ps, false); m_surveyID = new BigDecimalParameter("survey_id");
m_complete.setVisible(ps,false); p.addGlobalStateParam(m_optionID);
m_back.setVisible(ps, true); p.addGlobalStateParam(m_surveyID);
} /*else { p.addRequestListener(new RequestListener() {
m_answerTable.setVisible(ps, false); public void pageRequested(RequestEvent e) {
m_answerValuesForm.setVisible(ps, true); PageState ps = e.getPageState();
BigDecimal optionID = (BigDecimal) ps.getValue(m_optionID); if (ps.getValue(m_optionID) == null || m_answerValuesForm.getFormData(ps).
final String query = "com.arsdigita.simplesurvey.getAnswerOption"; isSubmission()) {
DataQuery dq = SessionManager.getSession().retrieveQuery(query); m_answerTable.setVisible(ps, true);
dq.setParameter("optionID", optionID); 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);
if ( dq.next()) { BigDecimal optionID = (BigDecimal) ps.getValue(m_optionID);
m_questionText.set(ps, (String) dq.get(QUESTION_TEXT)); final String query = "com.arsdigita.simplesurvey.getAnswerOption";
m_answerText.set(ps, (String) dq.get(ANSWER_TEXT)); DataQuery dq = SessionManager.getSession().retrieveQuery(query);
m_answerValue.set(ps, (BigDecimal) dq.get(ANSWER_VALUE)); dq.setParameter("optionID", optionID);
m_select.setValue(ps,getAnswerValue(ps));
} if ( dq.next()) {
dq.close(); 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) { private String getQuestionText(PageState ps) {
String s = (String) m_questionText.get(ps); String s = (String) m_questionText.get(ps);
return s.substring(6, s.length()); 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 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() { private void setupAnswerTable() {
// This is the table that holds the list of all answer options in the survey // This is the table that holds the list of all answer options in the survey
m_answerTable = new DataTable(new AnswerListingBuilder()); 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());
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 // Add a single select box widget to each possible answer
// The admin can select a point value for each answer // The admin can select a point value for each answer
TableColumn editValueColumn = new TableColumn(); TableColumn editValueColumn = new TableColumn();
editValueColumn.setCellRenderer(new EditLinkRenderer()); editValueColumn.setCellRenderer(new EditLinkRenderer());
m_answerTable.getColumnModel().add(editValueColumn); m_answerTable.getColumnModel().add(editValueColumn);
m_answerTable.addTableActionListener(new AnswerValueActionListener()); m_answerTable.addTableActionListener(new AnswerValueActionListener());
add(m_answerTable); add(m_answerTable);
} }
private BigDecimal getSurveyID(PageState ps) {
BigDecimal surveyID = null; private BigDecimal getSurveyID(PageState ps) {
if ( ps.getValue(m_surveyID) == null ) { BigDecimal surveyID = null;
Survey s = m_survey.getSelectedSurvey(ps); if (ps.getValue(m_surveyID) == null) {
surveyID = s.getID(); Survey s = m_survey.getSelectedSurvey(ps);
} else { surveyID = s.getID();
surveyID = (BigDecimal) ps.getValue(m_surveyID); } else {
} surveyID = (BigDecimal) ps.getValue(m_surveyID);
return surveyID; }
} return surveyID;
}
private void setupAnswerValuesForm() { private void setupAnswerValuesForm() {
m_answerValuesForm = new AnswerValuesForm(); m_answerValuesForm = new AnswerValuesForm();
add(m_answerValuesForm); add(m_answerValuesForm);
} }
private class AnswerValueActionListener extends TableActionAdapter{
public void cellSelected(TableActionEvent e) { private class AnswerValueActionListener extends TableActionAdapter {
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); public void cellSelected(TableActionEvent e) {
final String query = "com.arsdigita.simplesurvey.getAnswerOption"; PageState ps = e.getPageState();
DataQuery dq = SessionManager.getSession().retrieveQuery(query); ps.setValue(m_optionID, new BigDecimal(e.getRowKey().toString()));
dq.setParameter("optionID", optionID); m_answerTable.setVisible(ps, false);
m_back.setVisible(ps, false);
m_complete.setVisible(ps, true);
m_answerValuesForm.setVisible(ps, true);
if ( dq.next()) { BigDecimal optionID = (BigDecimal) ps.getValue(m_optionID);
m_questionText.set(ps, (String) dq.get(QUESTION_TEXT)); final String query = "com.arsdigita.simplesurvey.getAnswerOption";
m_answerText.set(ps, (String) dq.get(ANSWER_TEXT)); DataQuery dq = SessionManager.getSession().retrieveQuery(query);
m_answerValue.set(ps, (BigDecimal) dq.get(ANSWER_VALUE)); dq.setParameter("optionID", optionID);
m_select.setValue(ps,getAnswerValue(ps));
}
dq.close();
} 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 class AnswerValuesForm extends Form {
private AnswerValuesForm() { private AnswerValuesForm() {
super("answerValuesForm"); super("answerValuesForm");
Label questionText = new Label(new PrintListener() { Label questionText = new Label(new PrintListener() {
public void prepare(PrintEvent e) { public void prepare(PrintEvent e) {
PageState ps = e.getPageState(); PageState ps = e.getPageState();
Label target = (Label) e.getTarget(); Label target = (Label) e.getTarget();
target.setLabel(getQuestionText(ps)); target.setLabel(getQuestionText(ps));
} }
}); });
Label answerText = new Label(new PrintListener() { Label answerText = new Label(new PrintListener() {
public void prepare(PrintEvent e) { public void prepare(PrintEvent e) {
PageState ps = e.getPageState(); PageState ps = e.getPageState();
Label target = (Label) e.getTarget(); Label target = (Label) e.getTarget();
target.setLabel(getAnswerText(ps)); target.setLabel(getAnswerText(ps));
} }
}); });
add(questionText); add(questionText);
add(answerText); add(answerText);
m_select = new SingleSelect(ANSWER_VALUE); m_select = new SingleSelect(ANSWER_VALUE);
m_select.addOption(new Option("0", new Label("0"))); m_select.addOption(new Option("0", new Label("0")));
m_select.addOption(new Option("1", new Label("1"))); m_select.addOption(new Option("1", new Label("1")));
m_select.addOption(new Option("2", new Label("2"))); m_select.addOption(new Option("2", new Label("2")));
m_select.addOption(new Option("3", new Label("3"))); m_select.addOption(new Option("3", new Label("3")));
m_select.addOption(new Option("4", new Label("4"))); m_select.addOption(new Option("4", new Label("4")));
m_select.addOption(new Option("5", new Label("5"))); m_select.addOption(new Option("5", new Label("5")));
m_select.addOption(new Option("6", new Label("6"))); m_select.addOption(new Option("6", new Label("6")));
m_select.addOption(new Option("7", new Label("7"))); m_select.addOption(new Option("7", new Label("7")));
m_select.addOption(new Option("8", new Label("8"))); m_select.addOption(new Option("8", new Label("8")));
m_select.addOption(new Option("9", new Label("9"))); m_select.addOption(new Option("9", new Label("9")));
m_select.addOption(new Option("10", new Label("10"))); m_select.addOption(new Option("10", new Label("10")));
add(m_select); add(m_select);
add(new Submit(GlobalizationUtil.globalize("simplesurvey.ui.admin.submit"))); add(new Submit(GlobalizationUtil.globalize("simplesurvey.ui.admin.submit")));
//add(new Submit(GlobalizationUtil.globalize("simplesurvey.ui.admin.done_editing"))); //add(new Submit(GlobalizationUtil.globalize("simplesurvey.ui.admin.done_editing")));
addProcessListener(new AnswerValuesProcessListener()); addProcessListener(new AnswerValuesProcessListener());
addInitListener(new AnswerValuesInitListener()); addInitListener(new AnswerValuesInitListener());
} }
} }
private class AnswerValuesProcessListener implements FormProcessListener { 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"); public void process(FormSectionEvent e) throws FormProcessException {
dao.setParameter("optionID", optionID); PageState ps = e.getPageState();
dao.setParameter("answerValue", answerValue); FormData fd = e.getFormData();
dao.execute(); BigDecimal optionID = (BigDecimal) ps.getValue(m_optionID);
ps.setValue(m_optionID, null); 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 { private class AnswerValuesInitListener implements FormInitListener {
public void init(FormSectionEvent e) throws FormProcessException {
PageState ps = e.getPageState(); public void init(FormSectionEvent e) throws FormProcessException {
s_log.warn("Setting value of select to " + getAnswerValue(ps)); PageState ps = e.getPageState();
m_select.setValue(ps, getAnswerValue(ps)); s_log.warn("Setting value of select to " + getAnswerValue(ps));
} m_select.setValue(ps, getAnswerValue(ps));
}
} }
private class GlobalizedHeaderRenderer implements TableCellRenderer { 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 // Removed. Is is the responsibility of the theme to position Labels
// appropriately. We have to check for side effects in older themes! // appropriately. We have to check for side effects in older themes!
// label.setVerticalAlignment(CENTER); // label.setVerticalAlignment(CENTER);
return label; 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() ) { private class QuestionTextRenderer implements TableCellRenderer {
lock();
} @Override
if ( value == null ) { public Component getComponent(Table table, PageState state, Object value,
return new Label(""); boolean isSelected, Object key, int row,
} int column) {
String question = (String) value;
// Cut off the 6 chars "label=" stored in the db if (!isLocked() && table != null && table.isLocked()) {
return new Label(question.substring(6,question.length())); 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 { private class EditLinkRenderer implements TableCellRenderer {
@Override @Override
public Component getComponent(Table table, PageState ps, Object value, public Component getComponent(Table table, PageState ps, Object value,
boolean isSelected, Object key, int row, boolean isSelected, Object key, int row,
int column) { int column) {
if ( ! isLocked() && table != null && table.isLocked() ) { if (!isLocked() && table != null && table.isLocked()) {
lock(); lock();
} }
if ( value == null ) { if (value == null) {
return new Label(""); return new Label("");
} }
/*Link l = new Link(new Label(GlobalizationUtil.globalize("simplesurvey.ui.admin.edit_value")),"../admin"); /*Link l = new Link(new Label(GlobalizationUtil.globalize("simplesurvey.ui.admin.edit_value")),"../admin");
BigDecimal surveyID = getSurveyID(ps); BigDecimal surveyID = getSurveyID(ps);
//Sometimes we can get the surveyID from the global parameter, sometimes from the selection //Sometimes we can get the surveyID from the global parameter, sometimes from the selection
l.setVar("survey_id", surveyID.toString()); l.setVar("survey_id", surveyID.toString());
l.setVar("option_id", ((BigDecimal) key).toString()); l.setVar("option_id", ((BigDecimal) key).toString());
return l; */ return l; */
ControlLink cl = new ControlLink(new Label (GlobalizationUtil.globalize("simplesurvey.ui.admin.edit_value"))); ControlLink cl = new ControlLink(new Label(GlobalizationUtil.globalize(
return cl; "simplesurvey.ui.admin.edit_value")));
} return cl;
}
} }
private class AnswerListingBuilder implements DataQueryBuilder { 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)); private final static String KEY_COLUMN = "optionID";
return dq; 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 String getKeyColumn() {
return KEY_COLUMN;
}
public void lock() { public void lock() {
m_locked = true; m_locked = true;
} }
public boolean isLocked() {
return m_locked; public boolean isLocked() {
} return m_locked;
}
} }

View File

@ -489,6 +489,8 @@ public class SiteForm extends Form {
@Override @Override
public void prepare(PrintEvent e) { public void prepare(PrintEvent e) {
final SingleSelect target = (SingleSelect) e.getTarget(); final SingleSelect target = (SingleSelect) e.getTarget();
target.clearOptions();
ApplicationCollection customApps; ApplicationCollection customApps;
target.addOption(new Option(DEFAULT_APP, target.addOption(new Option(DEFAULT_APP,
@ -525,6 +527,7 @@ public class SiteForm extends Form {
@Override @Override
public void prepare(PrintEvent e) { public void prepare(PrintEvent e) {
SingleSelect target = (SingleSelect) e.getTarget(); SingleSelect target = (SingleSelect) e.getTarget();
target.clearOptions();
PageState state = e.getPageState(); PageState state = e.getPageState();
Map themes = Subsite.getConfig().getThemes(); Map themes = Subsite.getConfig().getThemes();
Set entrySet = themes.entrySet(); Set entrySet = themes.entrySet();

View File

@ -142,6 +142,8 @@ public class ThemeControlPanel extends SelectionPanel
@Override @Override
public void prepare(final PrintEvent event) { public void prepare(final PrintEvent event) {
final SingleSelect target = (SingleSelect) event.getTarget(); final SingleSelect target = (SingleSelect) event.getTarget();
target.clearOptions();
final DataCollection options = SessionManager final DataCollection options = SessionManager
.getSession() .getSession()
.retrieve(Theme.BASE_DATA_OBJECT_TYPE); .retrieve(Theme.BASE_DATA_OBJECT_TYPE);

View File

@ -71,533 +71,522 @@ import com.arsdigita.xml.Document;
*/ */
public class WebpageCMSEditorPage extends CMSPage implements WebpageConstants { public class WebpageCMSEditorPage extends CMSPage implements WebpageConstants {
private static final Logger s_log = Logger.getLogger(WebpageCMSEditorPage.class); private static final Logger s_log = Logger.getLogger(WebpageCMSEditorPage.class);
private WebpageCMSEditorForm m_createForm; private WebpageCMSEditorForm m_createForm;
private WebpageCMSEditorForm m_editForm; private WebpageCMSEditorForm m_editForm;
public WebpageCMSEditorPage() { public WebpageCMSEditorPage() {
super("Story Editor", new SimpleContainer()); super("Story Editor", new SimpleContainer());
SimpleContainer header = new SimpleContainer(HEADER_ELEMENT, XML_NS); SimpleContainer header = new SimpleContainer(HEADER_ELEMENT, XML_NS);
SimpleContainer body = new SimpleContainer(BODY_ELEMENT, XML_NS); SimpleContainer body = new SimpleContainer(BODY_ELEMENT, XML_NS);
SimpleContainer footer = new SimpleContainer(FOOTER_ELEMENT, XML_NS); SimpleContainer footer = new SimpleContainer(FOOTER_ELEMENT, XML_NS);
m_createForm = new WebpageCMSEditorForm(true); m_createForm = new WebpageCMSEditorForm(true);
m_editForm = new WebpageCMSEditorForm(false); m_editForm = new WebpageCMSEditorForm(false);
body.add(m_createForm); body.add(m_createForm);
body.add(m_editForm); body.add(m_editForm);
add(header); add(header);
add(body); add(body);
add(footer); add(footer);
} }
protected void buildPage() { protected void buildPage() {
super.buildPage(); super.buildPage();
setClassAttr("webpage"); setClassAttr("webpage");
} }
public void generateXML(PageState state, Document parent) { public void generateXML(PageState state, Document parent) {
BigDecimal id = null; BigDecimal id = null;
try { try {
HttpServletRequest request = state.getRequest(); HttpServletRequest request = state.getRequest();
id = new BigDecimal(request.getParameter(Webpage.ID)); id = new BigDecimal(request.getParameter(Webpage.ID));
} } catch (Exception ex) {
catch (Exception ex) { }
} m_createForm.setVisible(state, id == null);
m_createForm.setVisible(state, id == null); m_editForm.setVisible(state, id != null);
m_editForm.setVisible(state, id != null); super.generateXML(state, parent);
super.generateXML(state, parent); }
}
public class WebpageCMSEditorForm extends Form implements FormInitListener, FormValidationListener, FormProcessListener { public class WebpageCMSEditorForm extends Form implements FormInitListener,
FormValidationListener,
FormProcessListener {
Hidden m_itemID; Hidden m_itemID;
TextField m_author, m_title; TextField m_author, m_title;
MultipleSelect m_categories; MultipleSelect m_categories;
CMSDHTMLEditor m_body; CMSDHTMLEditor m_body;
CMSDHTMLEditor m_desc; CMSDHTMLEditor m_desc;
Submit m_save; Submit m_save;
Date m_startDate; Date m_startDate;
TextField m_startHour; TextField m_startHour;
TextField m_startMinute; TextField m_startMinute;
SingleSelect m_startAmpm; SingleSelect m_startAmpm;
Date m_endDate; Date m_endDate;
TextField m_endHour; TextField m_endHour;
TextField m_endMinute; TextField m_endMinute;
SingleSelect m_endAmpm; SingleSelect m_endAmpm;
boolean m_displayDates; boolean m_displayDates;
public WebpageCMSEditorForm(boolean displayDates) { public WebpageCMSEditorForm(boolean displayDates) {
super("WebpageCMSEditorForm"); super("WebpageCMSEditorForm");
m_displayDates = displayDates; m_displayDates = displayDates;
m_title = new TextField(new StringParameter("title")); m_title = new TextField(new StringParameter("title"));
m_title.setSize(35); m_title.setSize(35);
add(new Label("Title:"), RIGHT | TOP); add(new Label("Title:"), RIGHT | TOP);
add(m_title); add(m_title);
m_author = new TextField(Webpage.AUTHOR); m_author = new TextField(Webpage.AUTHOR);
add(new Label(new AuthorLabelPrinter()), RIGHT | TOP); add(new Label(new AuthorLabelPrinter()), RIGHT | TOP);
add(m_author); add(m_author);
m_desc = new CMSDHTMLEditor("desc");//CMSDHTMLEditor.m_configWithoutToolbar m_desc = new CMSDHTMLEditor("desc");//CMSDHTMLEditor.m_configWithoutToolbar
m_desc.setRows(10); m_desc.setRows(10);
m_desc.setCols(80); m_desc.setCols(80);
add(new Label("Lead:", false), RIGHT | TOP);//<br /><font size=-1>(this field is currently not displayed on the website)</font> add(new Label("Lead:", false), RIGHT | TOP);//<br /><font size=-1>(this field is currently not displayed on the website)</font>
add(m_desc); add(m_desc);
add(new Label("Location:"), RIGHT | TOP); add(new Label("Location:"), RIGHT | TOP);
m_categories = new MultipleSelect("categories"); m_categories = new MultipleSelect("categories");
m_categories.setSize(5); m_categories.setSize(5);
add(m_categories); add(m_categories);
add(new Label("Body:"), RIGHT | TOP); add(new Label("Body:"), RIGHT | TOP);
StringParameter bodyParam = new StringParameter(Webpage.BODY); StringParameter bodyParam = new StringParameter(Webpage.BODY);
m_body = new CMSDHTMLEditor(bodyParam); m_body = new CMSDHTMLEditor(bodyParam);
m_body.setCols(80); m_body.setCols(80);
m_body.setRows(20); m_body.setRows(20);
add(m_body); add(m_body);
if (displayDates) { if (displayDates) {
add(new Label("Start date:"), RIGHT | TOP); add(new Label("Start date:"), RIGHT | TOP);
m_startDate = new Date(new DateParameter("start_date") { m_startDate = new Date(new DateParameter("start_date") {
protected final Calendar getCalendar(final HttpServletRequest sreq) { protected final Calendar getCalendar(final HttpServletRequest sreq) {
final Calendar cal = super.getCalendar(sreq); final Calendar cal = super.getCalendar(sreq);
cal.setLenient(false); cal.setLenient(false);
return cal; return cal;
} }
}); });
add(m_startDate); add(m_startDate);
add(new Label("Start time:"), RIGHT | TOP); add(new Label("Start time:"), RIGHT | TOP);
BoxPanel startTime = new BoxPanel(BoxPanel.HORIZONTAL); BoxPanel startTime = new BoxPanel(BoxPanel.HORIZONTAL);
m_startHour = new TextField(new IntegerParameter("start_hour")); m_startHour = new TextField(new IntegerParameter("start_hour"));
m_startHour.setSize(3); m_startHour.setSize(3);
startTime.add(m_startHour); startTime.add(m_startHour);
m_startMinute = new TextField(new IntegerParameter("start_minute")); m_startMinute = new TextField(new IntegerParameter("start_minute"));
m_startMinute.setSize(3); m_startMinute.setSize(3);
startTime.add(m_startMinute); startTime.add(m_startMinute);
m_startAmpm = new SingleSelect(new IntegerParameter("start_ampm")); m_startAmpm = new SingleSelect(new IntegerParameter("start_ampm"));
m_startAmpm.addOption(new Option("0", "am")); m_startAmpm.addOption(new Option("0", "am"));
m_startAmpm.addOption(new Option("1", "pm")); m_startAmpm.addOption(new Option("1", "pm"));
startTime.add(m_startAmpm); startTime.add(m_startAmpm);
startTime.add(new Label(new TimeZonePrinter())); startTime.add(new Label(new TimeZonePrinter()));
add(startTime); add(startTime);
add(new Label("End date:"), RIGHT | TOP); add(new Label("End date:"), RIGHT | TOP);
m_endDate = new Date(new DateParameter("end_date") { m_endDate = new Date(new DateParameter("end_date") {
protected final Calendar getCalendar(final HttpServletRequest sreq) { protected final Calendar getCalendar(final HttpServletRequest sreq) {
final Calendar cal = super.getCalendar(sreq); final Calendar cal = super.getCalendar(sreq);
cal.setLenient(false); cal.setLenient(false);
return cal; return cal;
} }
}); });
add(m_endDate); add(m_endDate);
add(new Label("End time:"), RIGHT | TOP); add(new Label("End time:"), RIGHT | TOP);
BoxPanel endTime = new BoxPanel(BoxPanel.HORIZONTAL); BoxPanel endTime = new BoxPanel(BoxPanel.HORIZONTAL);
m_endHour = new TextField(new IntegerParameter("end_hour")); m_endHour = new TextField(new IntegerParameter("end_hour"));
m_endHour.setSize(3); m_endHour.setSize(3);
endTime.add(m_endHour); endTime.add(m_endHour);
m_endMinute = new TextField(new IntegerParameter("end_minute")); m_endMinute = new TextField(new IntegerParameter("end_minute"));
m_endMinute.setSize(3); m_endMinute.setSize(3);
endTime.add(m_endMinute); endTime.add(m_endMinute);
m_endAmpm = new SingleSelect(new IntegerParameter("end_ampm")); m_endAmpm = new SingleSelect(new IntegerParameter("end_ampm"));
m_endAmpm.addOption(new Option("0", "am")); m_endAmpm.addOption(new Option("0", "am"));
m_endAmpm.addOption(new Option("1", "pm")); m_endAmpm.addOption(new Option("1", "pm"));
endTime.add(m_endAmpm); endTime.add(m_endAmpm);
endTime.add(new Label(new TimeZonePrinter())); endTime.add(new Label(new TimeZonePrinter()));
add(endTime); add(endTime);
} }
m_itemID = new Hidden(Webpage.ID); m_itemID = new Hidden(Webpage.ID);
add(m_itemID); add(m_itemID);
SimpleContainer buttons = new SimpleContainer(); SimpleContainer buttons = new SimpleContainer();
m_save = new Submit("Save"); m_save = new Submit("Save");
buttons.add(m_save); buttons.add(m_save);
buttons.add(new Label("")); buttons.add(new Label(""));
buttons.add(new Submit("Cancel")); buttons.add(new Submit("Cancel"));
add(new Label("")); add(new Label(""));
add(buttons); add(buttons);
addInitListener(this); addInitListener(this);
addValidationListener(this); addValidationListener(this);
addProcessListener(this); addProcessListener(this);
} }
public void init(FormSectionEvent e) throws FormProcessException { public void init(FormSectionEvent e) throws FormProcessException {
s_log.debug("init"); s_log.debug("init");
PageState state = e.getPageState(); PageState state = e.getPageState();
HttpServletRequest request = state.getRequest(); HttpServletRequest request = state.getRequest();
// ContentSection section = ContentSectionDispatcher.getContentSection(request); // ContentSection section = ContentSectionDispatcher.getContentSection(request);
ContentSection section = ContentSectionServlet.getContentSection(request); ContentSection section = ContentSectionServlet.getContentSection(request);
Webpage webpage = null; Webpage webpage = null;
try { try {
BigDecimal id = new BigDecimal(request.getParameter(Webpage.ID)); BigDecimal id = new BigDecimal(request.getParameter(Webpage.ID));
webpage = new Webpage(id); webpage = new Webpage(id);
if (!webpage.getContentSection().equals(section)) { if (!webpage.getContentSection().equals(section)) {
s_log.error("content section doesn't match! create new webpage entity."); s_log.error("content section doesn't match! create new webpage entity.");
webpage = null; webpage = null;
} }
} } catch (Exception ex) {
catch (Exception ex) { }
}
m_categories.setPrintListener(new CategoriesPrintListener(section)); m_categories.setPrintListener(new CategoriesPrintListener(section));
if (webpage != null) { if (webpage != null) {
m_itemID.setValue(state, webpage.getID().toString()); m_itemID.setValue(state, webpage.getID().toString());
m_author.setValue(state, webpage.getAuthor()); m_author.setValue(state, webpage.getAuthor());
m_title.setValue(state, webpage.getTitle()); m_title.setValue(state, webpage.getTitle());
m_desc.setValue(state, webpage.getDescription()); m_desc.setValue(state, webpage.getDescription());
m_body.setValue(state, webpage.getBody()); m_body.setValue(state, webpage.getBody());
ArrayList assignedCats = new ArrayList(); ArrayList assignedCats = new ArrayList();
CategoryCollection cc = webpage.getCategoryCollection(); CategoryCollection cc = webpage.getCategoryCollection();
while (cc.next()) { while (cc.next()) {
String catID = cc.getCategory().getID().toString(); String catID = cc.getCategory().getID().toString();
assignedCats.add(catID); assignedCats.add(catID);
} }
m_categories.setValue(state, assignedCats.toArray()); m_categories.setValue(state, assignedCats.toArray());
} } else {
else { m_categories.setValue(state, new String[]{request.getParameter("categoryID")});
m_categories.setValue(state, new String[]{request.getParameter("categoryID")}); if (m_displayDates) {
if (m_displayDates) { final java.util.Date start = new java.util.Date(System.currentTimeMillis());
final java.util.Date start = new java.util.Date(System.currentTimeMillis()); m_startDate.setValue(state, start);
m_startDate.setValue(state, start);
final Calendar calendar = Calendar.getInstance(); final Calendar calendar = Calendar.getInstance();
calendar.setTime(start); calendar.setTime(start);
// If the hour is 12, then Calendar.get(Calendar.HOUR) // If the hour is 12, then Calendar.get(Calendar.HOUR)
// returns 0 (from the 24 hour time - 12). We want it to // returns 0 (from the 24 hour time - 12). We want it to
// return 12. // return 12.
if (calendar.get(Calendar.HOUR) == 0) { if (calendar.get(Calendar.HOUR) == 0) {
m_startHour.setValue(state, new Integer(12)); m_startHour.setValue(state, new Integer(12));
} } else {
else { m_startHour.setValue(state, new Integer(calendar.get(Calendar.HOUR)));
m_startHour.setValue(state, new Integer(calendar.get(Calendar.HOUR))); }
} final Integer min = new Integer(calendar.get(Calendar.MINUTE));
final Integer min = new Integer(calendar.get(Calendar.MINUTE)); if (min.intValue() < 10) {
if (min.intValue() < 10) { m_startMinute.setValue(state, "0" + min.toString());
m_startMinute.setValue(state, "0" + min.toString()); } else {
} m_startMinute.setValue(state, min.toString());
else { }
m_startMinute.setValue(state, min.toString()); m_startAmpm.setValue(state, new Integer(calendar.get(Calendar.AM_PM)));
} }
m_startAmpm.setValue(state, new Integer(calendar.get(Calendar.AM_PM))); }
} }
}
}
public void validate(FormSectionEvent e) throws FormProcessException { public void validate(FormSectionEvent e) throws FormProcessException {
s_log.debug("validate"); s_log.debug("validate");
PageState state = e.getPageState(); PageState state = e.getPageState();
boolean valid = true; boolean valid = true;
if (m_save.isSelected(state)) { if (m_save.isSelected(state)) {
String title = (String) m_title.getValue(state); String title = (String) m_title.getValue(state);
if (title == null || title.length() == 0) { if (title == null || title.length() == 0) {
m_title.addError("This parameter is required"); m_title.addError("This parameter is required");
valid = false; valid = false;
} }
if (title != null && (title.length() < 1 || title.length() > 200)) { if (title != null && (title.length() < 1 || title.length() > 200)) {
m_title.addError("This parameter is not between 1 and 200 characters long"); m_title.addError("This parameter is not between 1 and 200 characters long");
valid = false; valid = false;
} }
String desc = (String) m_desc.getValue(state); String desc = (String) m_desc.getValue(state);
if (desc != null && (desc.length() < 1 || desc.length() > 4000)) { if (desc != null && (desc.length() < 1 || desc.length() > 4000)) {
m_desc.addError("This parameter is not between 1 and 4000 characters long"); m_desc.addError("This parameter is not between 1 and 4000 characters long");
valid = false; valid = false;
} }
if (m_displayDates) { if (m_displayDates) {
Integer startHour = (Integer) m_startHour.getValue(state); Integer startHour = (Integer) m_startHour.getValue(state);
if (startHour != null && (startHour.intValue() < 1 || startHour.intValue() > 12)) { if (startHour != null && (startHour.intValue() < 1 || startHour.intValue() > 12)) {
m_startHour.addError("This parameter is not between 1 and 12"); m_startHour.addError("This parameter is not between 1 and 12");
valid = false; valid = false;
} }
Integer startMin = (Integer) m_startMinute.getValue(state); Integer startMin = (Integer) m_startMinute.getValue(state);
if (startMin != null && (startMin.intValue() < 0 || startMin.intValue() > 59)) { if (startMin != null && (startMin.intValue() < 0 || startMin.intValue() > 59)) {
m_startMinute.addError("This parameter is not between 0 and 59"); m_startMinute.addError("This parameter is not between 0 and 59");
valid = false; valid = false;
} }
Integer endHour = (Integer) m_endHour.getValue(state); Integer endHour = (Integer) m_endHour.getValue(state);
if (endHour != null && (endHour.intValue() < 1 || endHour.intValue() > 12)) { if (endHour != null && (endHour.intValue() < 1 || endHour.intValue() > 12)) {
m_endHour.addError("This parameter is not between 1 and 12"); m_endHour.addError("This parameter is not between 1 and 12");
valid = false; valid = false;
} }
Integer endMin = (Integer) m_endMinute.getValue(state); Integer endMin = (Integer) m_endMinute.getValue(state);
if (endMin != null && (endMin.intValue() < 0 || endMin.intValue() > 59)) { if (endMin != null && (endMin.intValue() < 0 || endMin.intValue() > 59)) {
m_endMinute.addError("This parameter is not between 0 and 59"); m_endMinute.addError("This parameter is not between 0 and 59");
valid = false; valid = false;
} }
} }
} }
if (! valid) { if (!valid) {
throw new FormProcessException("There is an error on the form"); throw new FormProcessException("There is an error on the form");
} }
} }
public void process(FormSectionEvent e) throws FormProcessException { public void process(FormSectionEvent e) throws FormProcessException {
s_log.debug("process"); s_log.debug("process");
PageState state = e.getPageState(); PageState state = e.getPageState();
HttpServletRequest request = state.getRequest(); HttpServletRequest request = state.getRequest();
// ContentSection section = ContentSectionDispatcher.getContentSection(request); // ContentSection section = ContentSectionDispatcher.getContentSection(request);
ContentSection section = ContentSectionServlet.getContentSection(request); ContentSection section = ContentSectionServlet.getContentSection(request);
if (m_save.isSelected(state)) { if (m_save.isSelected(state)) {
Webpage webpage = null; Webpage webpage = null;
boolean commitTransaction = false; boolean commitTransaction = false;
boolean isMyTransaction = false; boolean isMyTransaction = false;
TransactionContext txn = null; TransactionContext txn = null;
try { try {
Session session = SessionManager.getSession(); Session session = SessionManager.getSession();
txn = session.getTransactionContext(); txn = session.getTransactionContext();
if (!txn.inTxn()) { if (!txn.inTxn()) {
txn.beginTxn(); txn.beginTxn();
isMyTransaction = true; isMyTransaction = true;
} }
try { try {
String idTxt = (String) m_itemID.getValue(state); String idTxt = (String) m_itemID.getValue(state);
if (idTxt != null && idTxt.length() > 0) { if (idTxt != null && idTxt.length() > 0) {
BigDecimal id = new BigDecimal(idTxt); BigDecimal id = new BigDecimal(idTxt);
webpage = new Webpage(id); webpage = new Webpage(id);
} }
} } catch (Exception ex) {
catch (Exception ex) { throw new FormProcessException(ex);
throw new FormProcessException(ex); }
}
if (section == null) { if (section == null) {
throw new FormProcessException("ContentSection is null"); throw new FormProcessException("ContentSection is null");
} }
SecurityManager sm = new SecurityManager(section); SecurityManager sm = new SecurityManager(section);
User user = Web.getWebContext().getUser(); User user = Web.getWebContext().getUser();
if (webpage != null) { if (webpage != null) {
if ( !sm.canAccess(user, SecurityConstants.EDIT_ITEM, webpage ) ) { if (!sm.canAccess(user, SecurityConstants.EDIT_ITEM, webpage)) {
throw new FormProcessException("Insufficient permissions"); throw new FormProcessException("Insufficient permissions");
} }
if (!webpage.getContentSection().equals(section)) { if (!webpage.getContentSection().equals(section)) {
throw new FormProcessException("content section doesn't match!"); throw new FormProcessException("content section doesn't match!");
} }
webpage.setTitle((String) m_title.getValue(state)); webpage.setTitle((String) m_title.getValue(state));
webpage.setName("webpage" + webpage.getID()); webpage.setName("webpage" + webpage.getID());
webpage.setBody((String) m_body.getValue(state)); webpage.setBody((String) m_body.getValue(state));
webpage.setAuthor((String) m_author.getValue(state)); webpage.setAuthor((String) m_author.getValue(state));
webpage.setCategories((String[]) m_categories.getValue(state)); webpage.setCategories((String[]) m_categories.getValue(state));
webpage.setDescription((String) m_desc.getValue(state)); webpage.setDescription((String) m_desc.getValue(state));
webpage.save(); webpage.save();
} } else {
else { if (!sm.canAccess(user, SecurityConstants.NEW_ITEM)) {
if ( !sm.canAccess(user, SecurityConstants.NEW_ITEM ) ) { throw new FormProcessException("Insufficient permissions");
throw new FormProcessException("Insufficient permissions"); }
} webpage = new Webpage();
webpage = new Webpage(); webpage.setLanguage("en");
webpage.setLanguage("en"); webpage.setName("webpage" + webpage.getID());
webpage.setName("webpage" + webpage.getID()); webpage.setTitle((String) m_title.getValue(state));
webpage.setTitle((String) m_title.getValue(state)); webpage.setBody((String) m_body.getValue(state));
webpage.setBody((String) m_body.getValue(state)); webpage.setAuthor((String) m_author.getValue(state));
webpage.setAuthor((String) m_author.getValue(state)); webpage.setDescription((String) m_desc.getValue(state));
webpage.setDescription((String) m_desc.getValue(state)); webpage.save();
webpage.save();
ContentBundle bundle = new ContentBundle(webpage); ContentBundle bundle = new ContentBundle(webpage);
bundle.setContentSection(section); bundle.setContentSection(section);
bundle.setParent(section.getRootFolder()); bundle.setParent(section.getRootFolder());
webpage.setCategories((String[]) m_categories.getValue(state)); webpage.setCategories((String[]) m_categories.getValue(state));
// get lifecycleDefinition // get lifecycleDefinition
LifecycleDefinitionCollection lfColl = null; LifecycleDefinitionCollection lfColl = null;
LifecycleDefinition lifecycleDefinition = null; LifecycleDefinition lifecycleDefinition = null;
try { try {
lfColl = section.getLifecycleDefinitions(); lfColl = section.getLifecycleDefinitions();
if (lfColl.next()) { if (lfColl.next()) {
lifecycleDefinition = lfColl.getLifecycleDefinition(); lifecycleDefinition = lfColl.getLifecycleDefinition();
} }
} } finally {
finally { if (lfColl != null) {
if (lfColl != null) { lfColl.close();
lfColl.close(); }
} }
}
// set workflow // set workflow
TaskCollection taskColl = null; TaskCollection taskColl = null;
try { try {
taskColl = section.getWorkflowTemplates(); taskColl = section.getWorkflowTemplates();
if (taskColl.next()) { if (taskColl.next()) {
Task task = taskColl.getTask(); Task task = taskColl.getTask();
final WorkflowTemplate wfTemp = new WorkflowTemplate(task.getID()); final WorkflowTemplate wfTemp = new WorkflowTemplate(task.getID());
final Workflow flow = wfTemp.instantiateNewWorkflow(); final Workflow flow = wfTemp.instantiateNewWorkflow();
flow.setObjectID(webpage.getID()); flow.setObjectID(webpage.getID());
flow.start(Web.getWebContext().getUser()); flow.start(Web.getWebContext().getUser());
flow.save(); flow.save();
} }
} } finally {
finally { if (taskColl != null) {
if (taskColl != null) { taskColl.close();
taskColl.close(); }
} }
}
// finish all task // finish all task
Workflow workflow = Workflow.getObjectWorkflow(webpage); Workflow workflow = Workflow.getObjectWorkflow(webpage);
Engine engine = Engine.getInstance(); Engine engine = Engine.getInstance();
Assert.exists(engine, Engine.class); Assert.exists(engine, Engine.class);
Iterator i = engine.getEnabledTasks(Web.getWebContext().getUser(), workflow.getID()).iterator(); Iterator i = engine.getEnabledTasks(Web.getWebContext().getUser(), workflow.
CMSTask task; getID()).iterator();
do { CMSTask task;
while (i.hasNext()) { do {
task = (CMSTask) i.next(); while (i.hasNext()) {
try { task = (CMSTask) i.next();
task.finish(); try {
} task.finish();
catch (Exception ex) { } catch (Exception ex) {
throw new FormProcessException(ex); throw new FormProcessException(ex);
} }
} }
i = engine.getEnabledTasks(Web.getWebContext().getUser(), workflow.getID()).iterator(); i = engine.getEnabledTasks(Web.getWebContext().getUser(), workflow.
} getID()).iterator();
while (i.hasNext()); } while (i.hasNext());
// publish // publish
if (lifecycleDefinition != null) { if (lifecycleDefinition != null) {
if (m_displayDates) { if (m_displayDates) {
final Integer startHour = (Integer) m_startHour.getValue(state); final Integer startHour = (Integer) m_startHour.getValue(state);
Integer startMinute = (Integer) m_startMinute.getValue(state); Integer startMinute = (Integer) m_startMinute.getValue(state);
if (startMinute == null) { if (startMinute == null) {
startMinute = new Integer(0); startMinute = new Integer(0);
} }
final Integer startAmpm = (Integer) m_startAmpm.getValue(state); final Integer startAmpm = (Integer) m_startAmpm.getValue(state);
final Integer endHour = (Integer) m_endHour.getValue(state); final Integer endHour = (Integer) m_endHour.getValue(state);
Integer endMinute = (Integer) m_endMinute.getValue(state); Integer endMinute = (Integer) m_endMinute.getValue(state);
if (endMinute == null) { if (endMinute == null) {
endMinute = new Integer(0); endMinute = new Integer(0);
} }
final Integer endAmpm = (Integer) m_endAmpm.getValue(state); final Integer endAmpm = (Integer) m_endAmpm.getValue(state);
java.util.Date startDate = (java.util.Date) m_startDate.getValue(state); java.util.Date startDate = (java.util.Date) m_startDate.getValue(
final Calendar start = Calendar.getInstance(); state);
start.setTime(startDate); final Calendar start = Calendar.getInstance();
start.set(Calendar.AM_PM, startAmpm.intValue()); start.setTime(startDate);
start.set(Calendar.MINUTE, startMinute.intValue()); start.set(Calendar.AM_PM, startAmpm.intValue());
start.set(Calendar.AM_PM, startAmpm.intValue()); start.set(Calendar.MINUTE, startMinute.intValue());
if (startHour.intValue() != 12) { start.set(Calendar.AM_PM, startAmpm.intValue());
start.set(Calendar.HOUR_OF_DAY, 12 * startAmpm.intValue() + startHour.intValue()); if (startHour.intValue() != 12) {
start.set(Calendar.HOUR, startHour.intValue()); start.set(Calendar.HOUR_OF_DAY, 12 * startAmpm.intValue()
} + startHour.intValue());
else { start.set(Calendar.HOUR, startHour.intValue());
if (startAmpm.intValue() == 0) { } else {
start.set(Calendar.HOUR_OF_DAY, 0); if (startAmpm.intValue() == 0) {
start.set(Calendar.HOUR, 0); start.set(Calendar.HOUR_OF_DAY, 0);
} start.set(Calendar.HOUR, 0);
else { } else {
start.set(Calendar.HOUR_OF_DAY, 12); start.set(Calendar.HOUR_OF_DAY, 12);
start.set(Calendar.HOUR, 0); start.set(Calendar.HOUR, 0);
} }
} }
startDate = start.getTime(); startDate = start.getTime();
java.util.Date endDate = (java.util.Date) m_endDate.getValue(state); java.util.Date endDate = (java.util.Date) m_endDate.getValue(state);
if (endDate != null) { if (endDate != null) {
final Calendar end = Calendar.getInstance(); final Calendar end = Calendar.getInstance();
end.setTime(endDate); end.setTime(endDate);
end.set(Calendar.AM_PM, endAmpm.intValue()); end.set(Calendar.AM_PM, endAmpm.intValue());
end.set(Calendar.MINUTE, endMinute.intValue()); end.set(Calendar.MINUTE, endMinute.intValue());
end.set(Calendar.AM_PM, endAmpm.intValue()); end.set(Calendar.AM_PM, endAmpm.intValue());
if (endHour.intValue() != 12) { if (endHour.intValue() != 12) {
end.set(Calendar.HOUR_OF_DAY, 12 * endAmpm.intValue() + endHour.intValue()); end.set(Calendar.HOUR_OF_DAY, 12 * endAmpm.intValue()
end.set(Calendar.HOUR, endHour.intValue()); + endHour.intValue());
} end.set(Calendar.HOUR, endHour.intValue());
else { } else {
if (endAmpm.intValue() == 0) { if (endAmpm.intValue() == 0) {
end.set(Calendar.HOUR_OF_DAY, 0); end.set(Calendar.HOUR_OF_DAY, 0);
end.set(Calendar.HOUR, 0); end.set(Calendar.HOUR, 0);
} } else {
else { end.set(Calendar.HOUR_OF_DAY, 12);
end.set(Calendar.HOUR_OF_DAY, 12); end.set(Calendar.HOUR, 0);
end.set(Calendar.HOUR, 0); }
} }
} endDate = end.getTime();
endDate = end.getTime(); }
}
webpage.publish(lifecycleDefinition, startDate); webpage.publish(lifecycleDefinition, startDate);
if (endDate != null) { if (endDate != null) {
final Lifecycle lifecycle = webpage.getLifecycle(); final Lifecycle lifecycle = webpage.getLifecycle();
// update individual phases // update individual phases
final PhaseCollection phases = lifecycle.getPhases(); final PhaseCollection phases = lifecycle.getPhases();
while (phases.next()) { while (phases.next()) {
final Phase phase = phases.getPhase(); final Phase phase = phases.getPhase();
java.util.Date thisEnd = phase.getEndDate(); java.util.Date thisEnd = phase.getEndDate();
if (thisEnd == null || thisEnd.compareTo(endDate) > 0) { if (thisEnd == null || thisEnd.compareTo(endDate) > 0) {
phase.setEndDate(endDate); phase.setEndDate(endDate);
phase.save(); phase.save();
} }
} }
} }
} } else {
else { webpage.publish(lifecycleDefinition, new java.util.Date());
webpage.publish(lifecycleDefinition, new java.util.Date()); }
}
// Force the lifecycle scheduler to run to avoid any // Force the lifecycle scheduler to run to avoid any
// scheduler delay for items that should be published // scheduler delay for items that should be published
// immediately. // immediately.
webpage.getLifecycle().start(); webpage.getLifecycle().start();
webpage.save(); webpage.save();
} }
} }
commitTransaction = true; commitTransaction = true;
} } finally {
finally { if (txn != null && isMyTransaction) {
if (txn != null && isMyTransaction) { if (commitTransaction) {
if (commitTransaction) { txn.commitTxn();
txn.commitTxn(); } else {
} txn.abortTxn();
else { }
txn.abortTxn(); }
} }
} }
}
}
try { try {
DispatcherHelper.sendRedirect(request, state.getResponse(), section.getPath()); DispatcherHelper.sendRedirect(request, state.getResponse(), section.getPath());
} } catch (IOException ex) {
catch (IOException ex) { throw new FormProcessException(ex);
throw new FormProcessException(ex); }
} }
}
public class TimeZonePrinter implements PrintListener { 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) { public void prepare(PrintEvent e) {
mStart.setTime((java.util.Date) m_startDate.getValue(state)); 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);
final String zone = mStart.getTimeZone().getDisplayName(true, TimeZone.SHORT); if (st != null) {
mStart.setTime((java.util.Date) m_startDate.getValue(state));
}
target.setLabel(zone); final String zone = mStart.getTimeZone().getDisplayName(true, TimeZone.SHORT);
}
} target.setLabel(zone);
} }
}
}
} }