Ticket #1747: SecurityPropertyEditor kann jetzt GlobalizedMessage verarbeiten, Labels als String deprecated.

git-svn-id: https://svn.libreccm.org/ccm/trunk@2207 8810af33-2d31-482b-a856-94f89814c4df
master
pb 2013-06-14 10:11:45 +00:00
parent 972b8dd775
commit da31fae9e3
3 changed files with 224 additions and 40 deletions

View File

@ -32,6 +32,7 @@ import com.arsdigita.bebop.form.Submit;
import com.arsdigita.cms.SecurityManager; import com.arsdigita.cms.SecurityManager;
import com.arsdigita.cms.dispatcher.Utilities; import com.arsdigita.cms.dispatcher.Utilities;
import com.arsdigita.cms.util.GlobalizationUtil; import com.arsdigita.cms.util.GlobalizationUtil;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.toolbox.ui.ComponentAccess; import com.arsdigita.toolbox.ui.ComponentAccess;
import com.arsdigita.util.Assert; import com.arsdigita.util.Assert;
@ -113,12 +114,28 @@ public class SecurityPropertyEditor extends PropertyEditor {
* for this <code>PropertyEditor</code> * for this <code>PropertyEditor</code>
* @param label The label for the link * @param label The label for the link
* @param ca The component access * @param ca The component access
* @deprecated use addComponent(String,GlobalizedMessage,ComponentAccess)
* instead.
*/ */
public void addComponent(String key, String label, ComponentAccess ca) { public void addComponent(String key, String label, ComponentAccess ca) {
addComponent(key, ca); addComponent(key, ca);
getLabelsMap().put(key, label); getLabelsMap().put(key, label);
} }
/**
* Add a component to the list of links. It is up to the
* component to correctly call showDisplayPane when it's done.
*
* @param key The symbolic key for the component; must be unique
* for this <code>PropertyEditor</code>
* @param label The label for the link
* @param ca The component access
*/
public void addComponent(String key, GlobalizedMessage label, ComponentAccess ca) {
addComponent(key, ca);
getLabelsMap().put(key, label);
}
/** /**
* Specify a new {@link ComponentAccess} for a component which has already * Specify a new {@link ComponentAccess} for a component which has already
* been added to the <code>SecurityPropertyEditor</code>. * been added to the <code>SecurityPropertyEditor</code>.
@ -144,8 +161,10 @@ public class SecurityPropertyEditor extends PropertyEditor {
* *
* @param key The symbolic key for the form; must be unique * @param key The symbolic key for the form; must be unique
* for this <code>PropertyEditor</code> * for this <code>PropertyEditor</code>
* @param label The label for the link * @param label The label for the link to access the form
* @param ca The form ComponentAccess * @param ca The form ComponentAccess
*
* @deprecated use add(String,GlobalizedMessage,ComponentAccess)
*/ */
public void add(String key, String label, ComponentAccess ca) { public void add(String key, String label, ComponentAccess ca) {
Component c = ca.getComponent(); Component c = ca.getComponent();
@ -165,17 +184,63 @@ public class SecurityPropertyEditor extends PropertyEditor {
} }
} }
/**
* Add a form to the set of forms which could be used to edit the
* properties.
*
* @param key The symbolic key for the form; must be unique
* for this <code>PropertyEditor</code>
* @param label The label for the link to access the form
* @param ca The form ComponentAccess
*/
public void add(String key, GlobalizedMessage label, ComponentAccess ca) {
Component c = ca.getComponent();
if (c instanceof Form) {
Form form = (Form) c;
m_accessChecks.put(key, ca);
add(key, label, form);
addSecurityListener(form);
} else if (c instanceof FormSection) {
FormSection section = (FormSection) ca.getComponent();
m_accessChecks.put(key, ca);
add(key, label, section);
addSecurityListener(section);
} else {
throw new IllegalArgumentException(
"The ComponentAccess object did not contain a form section.");
}
}
/** /**
* Add a form to the set of forms which could be used to edit the * Add a form to the set of forms which could be used to edit the
* properties * properties
* *
* @param key The symbolic key for the form; must be unique * @param key The symbolic key for the form; must be unique
* for this <code>PropertyEditor</code> * for this <code>PropertyEditor</code>
* @param label The label for the link * @param label The label for the link to access the form.
* @param ca The form ComponentAccess
* @param cancelButton The Cancel button on the form.
*
* @deprecated use add(String,GlobalizedMessage,ComponentAccess,Submit)
* instead
*/
public void add(String key, String label,
ComponentAccess ca, Submit cancelButton) {
add(key, label, ca);
addCancelListener((FormSection) ca.getComponent(), cancelButton);
}
/**
* Add a form to the set of forms which could be used to edit the
* properties
*
* @param key The symbolic key for the form; must be unique
* for this <code>PropertyEditor</code>
* @param label The label for the link to access the form.
* @param ca The form ComponentAccess * @param ca The form ComponentAccess
* @param cancelButton The Cancel button on the form. * @param cancelButton The Cancel button on the form.
*/ */
public void add(String key, String label, public void add(String key, GlobalizedMessage label,
ComponentAccess ca, Submit cancelButton) { ComponentAccess ca, Submit cancelButton) {
add(key, label, ca); add(key, label, ca);
addCancelListener((FormSection) ca.getComponent(), cancelButton); addCancelListener((FormSection) ca.getComponent(), cancelButton);

View File

@ -59,18 +59,20 @@ public class Label extends BlockStylable implements Cloneable {
* <code>Label</code> with the specified text. * <code>Label</code> with the specified text.
* *
* @param label the text to display * @param label the text to display
*
* @deprecated refactor to use Label(GlobalizedMessage label) instad
*/ */
public Label(String label) { public Label(String label) {
this(label, true); this(label, true);
} }
/** /**
* Creates a new * Creates a new <code>Label</code> with the specified text and
* <code>Label</code> with the specified text and output escaping turned on * output escaping turned on if
* if
* <code>escaping</code> is * <code>escaping</code> is
* <code>true</code>. The setting foroutput escaping affects how markup in * <code>true</code>.
* the *
* The setting foroutput escaping affects how markup in the
* <code>label</code> is handled. For example: <UL><LI>If output escaping is * <code>label</code> is handled. For example: <UL><LI>If output escaping is
* in effect, &lt;b>text&lt;/b> will appear literally.</LI> <LI>If output * in effect, &lt;b>text&lt;/b> will appear literally.</LI> <LI>If output
* escaping is disabled, &lt;b>text&lt;/b> appears as the word "text" in * escaping is disabled, &lt;b>text&lt;/b> appears as the word "text" in
@ -79,6 +81,9 @@ public class Label extends BlockStylable implements Cloneable {
* @param label the text to display * @param label the text to display
* @param <code>true</code> if output escaping will be in effect; * @param <code>true</code> if output escaping will be in effect;
* <code>false</code> if output escaping will be disabled * <code>false</code> if output escaping will be disabled
*
* @deprecated refactor to Label(GlobalizedMessage label, boolean escaping)
* instead
*/ */
public Label(String label, boolean escaping) { public Label(String label, boolean escaping) {
setLabel(label); setLabel(label);
@ -109,8 +114,8 @@ public class Label extends BlockStylable implements Cloneable {
} }
/** /**
* Creates a new * Creates a new <code>Label</code> that uses the print listener to
* <code>Label</code> that uses the print listener to generate output. * generate output.
* *
* @param l the print listener used to produce output * @param l the print listener used to produce output
*/ */
@ -124,6 +129,10 @@ public class Label extends BlockStylable implements Cloneable {
* *
* @param label The text to display * @param label The text to display
* @param fontWeight The fontWeight e.g., Label.BOLD * @param fontWeight The fontWeight e.g., Label.BOLD
*
* @deprecated without dir3ect replacement. Refactor to use
* Label(GlobalizedMEssage) instead and modify the theme to
* use proper text marking.
*/ */
public Label(String label, String fontWeight) { public Label(String label, String fontWeight) {
this(label, true); this(label, true);

View File

@ -27,13 +27,13 @@ import com.arsdigita.bebop.event.FormSubmissionListener;
import com.arsdigita.bebop.list.DefaultListCellRenderer; import com.arsdigita.bebop.list.DefaultListCellRenderer;
import com.arsdigita.bebop.list.ListModelBuilder; import com.arsdigita.bebop.list.ListModelBuilder;
import com.arsdigita.bebop.list.ListModel; import com.arsdigita.bebop.list.ListModel;
import com.arsdigita.bebop.List;
import com.arsdigita.util.Assert; import com.arsdigita.util.Assert;
import com.arsdigita.util.LockableImpl; import com.arsdigita.util.LockableImpl;
import com.arsdigita.util.SequentialMap; import com.arsdigita.util.SequentialMap;
import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.form.FormErrorDisplay; import com.arsdigita.bebop.form.FormErrorDisplay;
import com.arsdigita.bebop.form.Submit; import com.arsdigita.bebop.form.Submit;
import com.arsdigita.globalization.GlobalizedMessage;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
@ -228,14 +228,17 @@ public class PropertyEditor extends SimpleContainer {
setModelBuilder(new DefaultModelBuilder()); setModelBuilder(new DefaultModelBuilder());
m_model = new RequestLocal() { m_model = new RequestLocal() {
@Override
protected Object initialValue(PageState s) { protected Object initialValue(PageState s) {
return getModelBuilder().makeModel(PropertyEditor.this, s); return getModelBuilder().makeModel(PropertyEditor.this, s);
} }
}; };
} }
// Set the display component visible by default, and the /** Set the display component visible by default, and the
// form(s) invisible by default * form(s) invisible by default.
*/
@Override
public void register(Page p) { public void register(Page p) {
Assert.exists(m_display, "display component"); Assert.exists(m_display, "display component");
@ -319,15 +322,30 @@ public class PropertyEditor extends SimpleContainer {
} }
/** /**
* Adds a component to the list of links. It is up to the * Adds a component to the list of links. It is up to the component to
* component to correctly call {@link #showDisplayPane(PageState)} when it is done. * correctly call {@link #showDisplayPane(PageState)} when it is done.
*
* @param key the symbolic key for the component (must be unique
* for this <code>PropertyEditor</code>)
* @param label the label for the link
* @param c the component
* @deprecated use addComponent(String,GlobalizedMessage,Component) instead
*/
public void addComponent(String key, String label, Component c) {
addComponent(key, c);
m_labels.put(key, label);
}
/**
* Adds a component to the list of links. It is up to the component to
* correctly call {@link #showDisplayPane(PageState)} when it is done.
* *
* @param key the symbolic key for the component (must be unique * @param key the symbolic key for the component (must be unique
* for this <code>PropertyEditor</code>) * for this <code>PropertyEditor</code>)
* @param label the label for the link * @param label the label for the link
* @param c the component * @param c the component
*/ */
public void addComponent(String key, String label, Component c) { public void addComponent(String key, GlobalizedMessage label, Component c) {
addComponent(key, c); addComponent(key, c);
m_labels.put(key, label); m_labels.put(key, label);
} }
@ -340,12 +358,27 @@ public class PropertyEditor extends SimpleContainer {
* for this <code>PropertyEditor</code>) * for this <code>PropertyEditor</code>)
* @param label the label for the link * @param label the label for the link
* @param form the form component * @param form the form component
* @deprecated use add(String,GlobalizedMessage,Form) instead.
*/ */
public void add(String key, String label, Form form) { public void add(String key, String label, Form form) {
addComponent(key, label, form); addComponent(key, label, form);
addProcessListener(form); addProcessListener(form);
} }
/**
* Adds a form to the set of forms that can be used to edit the
* properties.
*
* @param key the symbolic key for the form (must be unique
* for this <code>PropertyEditor</code>)
* @param label the label for the link
* @param form the form component
*/
public void add(String key, GlobalizedMessage label, Form form) {
addComponent(key, label, form);
addProcessListener(form);
}
/** /**
* Adds a form to the set of forms that can be used to edit the * Adds a form to the set of forms that can be used to edit the
* properties. * properties.
@ -355,12 +388,28 @@ public class PropertyEditor extends SimpleContainer {
* @param label the label for the link * @param label the label for the link
* @param form the form component * @param form the form component
* @param cancelButton the Cancel button on the form * @param cancelButton the Cancel button on the form
* @deprecated use add(String,GlobalizedMessage,Form,Submit) instead.
*/ */
public void add(String key, String label, Form form, Submit cancelButton) { public void add(String key, String label, Form form, Submit cancelButton) {
add(key, label, form); add(key, label, form);
addListeners(form, cancelButton); addListeners(form, cancelButton);
} }
/**
* Adds a form to the set of forms that can be used to edit the
* properties.
*
* @param key the symbolic key for the form (must be unique
* for this <code>PropertyEditor</code>)
* @param label the label for the link
* @param form the form component
* @param cancelButton the Cancel button on the form
*/
public void add(String key, GlobalizedMessage label, Form form, Submit cancelButton) {
add(key, label, form);
addListeners(form, cancelButton);
}
/** /**
* Adds a form to the set of forms that can be used to edit the * Adds a form to the set of forms that can be used to edit the
* properties. * properties.
@ -371,6 +420,7 @@ public class PropertyEditor extends SimpleContainer {
* @param formSection the form component * @param formSection the form component
* *
* @pre !(formSection instanceof Form) * @pre !(formSection instanceof Form)
* @deprecated use add(String,GlobalizedMessage,FormSection) instead.
*/ */
public void add(String key, String label, FormSection formSection) { public void add(String key, String label, FormSection formSection) {
if (formSection instanceof Form) { if (formSection instanceof Form) {
@ -384,6 +434,29 @@ public class PropertyEditor extends SimpleContainer {
add(key, label , form); add(key, label , form);
} }
/**
* Adds a form to the set of forms that can be used to edit the
* properties.
*
* @param key the symbolic key for the form (must be unique
* for this <code>PropertyEditor</code>)
* @param label the label for the link
* @param formSection the form component
*
* @pre !(formSection instanceof Form)
*/
public void add(String key, GlobalizedMessage label, FormSection formSection) {
if (formSection instanceof Form) {
throw new IllegalArgumentException("formSection is an instance of Form");
}
Form form = new Form("property" + key);
form.add(new FormErrorDisplay(form), ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT);
form.add(formSection);
form.setMethod(Form.POST);
form.setEncType("multipart/form-data");
add(key, label , form);
}
/** /**
* Adds a form to the set of forms that can be used to edit the * Adds a form to the set of forms that can be used to edit the
* properties. * properties.
@ -393,6 +466,7 @@ public class PropertyEditor extends SimpleContainer {
* @param label the label for the link * @param label the label for the link
* @param formSection the form component * @param formSection the form component
* @param cancelButton the Cancel button on the form * @param cancelButton the Cancel button on the form
* @deprecated use add(String,GlobalizedMessage,FormSection,Submit) instead.
*/ */
public void add(String key, public void add(String key,
String label, String label,
@ -406,6 +480,28 @@ public class PropertyEditor extends SimpleContainer {
add(key, label , form, cancelButton); add(key, label , form, cancelButton);
} }
/**
* Adds a form to the set of forms that can be used to edit the
* properties.
*
* @param key the symbolic key for the form (must be unique
* for this <code>PropertyEditor</code>)
* @param label the label for the link as a GlobalizedMessage
* @param formSection the form component
* @param cancelButton the Cancel button on the form
*/
public void add(String key,
GlobalizedMessage label,
FormSection formSection,
Submit cancelButton) {
Form form = new Form("property" + key);
form.add(new FormErrorDisplay(form), ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT);
form.add(formSection);
form.setMethod(Form.POST);
form.setEncType("multipart/form-data");
add(key, label , form, cancelButton);
}
/** /**
* Retrieves the component at the specified key. * Retrieves the component at the specified key.
* *
@ -484,8 +580,8 @@ public class PropertyEditor extends SimpleContainer {
* *
* @param l the {@link ActionLink} * @param l the {@link ActionLink}
* @param key the key of the component that will be shown when the link * @param key the key of the component that will be shown when the link
* is clicked, as specified in the {@link #addComponent(String, Component)} * is clicked, as specified in the
* method * {@link #addComponent(String, Component)} method
* @see #addComponent(String, Component) * @see #addComponent(String, Component)
*/ */
public void addVisibilityListener(ActionLink l, String key) { public void addVisibilityListener(ActionLink l, String key) {
@ -567,6 +663,7 @@ public class PropertyEditor extends SimpleContainer {
/** /**
* Locks this component. * Locks this component.
*/ */
@Override
public void lock() { public void lock() {
getModelBuilder().lock(); getModelBuilder().lock();
super.lock(); super.lock();
@ -577,6 +674,7 @@ public class PropertyEditor extends SimpleContainer {
*/ */
protected static class IdentityCellRenderer extends DefaultListCellRenderer { protected static class IdentityCellRenderer extends DefaultListCellRenderer {
@Override
public Component getComponent(List list, PageState state, Object value, public Component getComponent(List list, PageState state, Object value,
String key, int index, boolean isSelected) { String key, int index, boolean isSelected) {
return (Component)value; return (Component)value;
@ -614,12 +712,11 @@ public class PropertyEditor extends SimpleContainer {
} }
/** /**
* Default implementation of the {@link PropertyEditorModel}. * Internal class with default implementation of the {@link PropertyEditorModel}.
* Takes in an iterator of key->label pairs, and constructs a ControlLink for each * Takes in an iterator of key->label pairs, and constructs a ControlLink
* label. * for each label.
*/ */
protected static class DefaultModel protected static class DefaultModel implements PropertyEditorModel {
implements PropertyEditorModel {
protected Iterator m_iter; protected Iterator m_iter;
protected Map.Entry m_entry; protected Map.Entry m_entry;
@ -638,11 +735,24 @@ public class PropertyEditor extends SimpleContainer {
return true; return true;
} }
/**
* Actually retrieve action link and label. Will be executed at each
* request to ensure proper localization.
* @return
*/
public Component getComponent() { public Component getComponent() {
Assert.exists(m_entry); Assert.exists(m_entry);
ControlLink l = new ControlLink(new Label((String)m_entry.getValue())); if ( m_entry.getValue() instanceof GlobalizedMessage ) {
ControlLink l = new ControlLink(new
Label((GlobalizedMessage)m_entry.getValue()));
l.setClassAttr("actionLink"); l.setClassAttr("actionLink");
return l; return l;
} else {
ControlLink l = new ControlLink(new Label((String)m_entry.getValue()));
l.setClassAttr("actionLink");
return l;
}
} }
public Object getKey() { public Object getKey() {