Fixed display of FormHeading and FormText in the Content Centre.

git-svn-id: https://svn.libreccm.org/ccm/trunk@3493 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2015-06-22 07:43:17 +00:00
parent e83147bbfe
commit c9db46ce01
3 changed files with 115 additions and 85 deletions

View File

@ -28,14 +28,18 @@ import com.arsdigita.persistence.DataObject;
import com.arsdigita.persistence.metadata.ObjectType;
// ACS objects are identified by a number
import java.math.BigDecimal;
// The factory creates Bebop Components
// Every PersistentComponentFactory can create a Bebop Component
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.Label;
// ACS 5 uses Log4J for logging
import org.apache.log4j.Logger;
@ -121,6 +125,7 @@ public class PersistentHeading extends PersistentText {
public Component createComponent() {
Component component = super.createComponent();
component.setClassAttr("persistenceHeading");
((Label) component).setOutputEscaping(false);
return component;
}

View File

@ -119,9 +119,11 @@ public class PersistentText extends PersistentComponent {
* Create the Text whose persistence is managed
* by this domain object.
*/
@Override
public Component createComponent() {
Label label = new Label(getText());
label.setClassAttr("persistenceText");
label.setOutputEscaping(false);
return label;
}

View File

@ -18,7 +18,6 @@
*/
package com.arsdigita.formbuilder.ui;
import com.arsdigita.bebop.BaseLink;
import com.arsdigita.bebop.BoxPanel;
import com.arsdigita.bebop.ColumnPanel;
@ -64,13 +63,14 @@ import org.apache.log4j.Logger;
/**
* This class provides a basic UI component for editing the controls on a
* persistent form.
*
* It is designed to be dropped into any page without requiring any significant
* persistent form.
*
* It is designed to be dropped into any page without requiring any significant
* additional infrasructure
*/
public class ControlEditor extends SimpleContainer {
private static final Logger s_log = Logger.getLogger( ControlEditor.class );
private static final Logger s_log = Logger.getLogger(ControlEditor.class);
private ParameterSingleSelectionModel m_control;
@ -83,12 +83,12 @@ public class ControlEditor extends SimpleContainer {
private MoveControl m_move_control;
/**
* Constructor creates a new control editor widget, for editing the form
* Constructor creates a new control editor widget, for editing the form
* specified in the single selection model. The key returned by the single
* selection model should be an instance of the
* {@link java.math.BigDecimal} class.
* selection model should be an instance of the {@link java.math.BigDecimal}
* class.
*
* @param app the application type
* @param app the application type
* @param form the form to edit
*/
public ControlEditor(String app,
@ -97,19 +97,19 @@ public class ControlEditor extends SimpleContainer {
}
/**
* Constructor creates a new control editor widget, for editing the form
* Constructor creates a new control editor widget, for editing the form
* specified in the single selection model. The key returned by the single
* selection model should be an instance of the
* {@link java.math.BigDecimal} class.
* selection model should be an instance of the {@link java.math.BigDecimal}
* class.
*
* This constructor also allows the programmer to turn on the use of
* form sections, although they must also call the setFormSectionModelBuilder
* This constructor also allows the programmer to turn on the use of form
* sections, although they must also call the setFormSectionModelBuilder
* method to populate the list box.
*
* @param app the application type
* @param form the form to edit
* @param wantFormSeciton whether to display list box for
* adding form sections.
* @param app the application type
* @param form the form to edit
* @param wantFormSeciton whether to display list box for adding form
* sections.
*/
public ControlEditor(String app,
SingleSelectionModel form,
@ -123,12 +123,13 @@ public class ControlEditor extends SimpleContainer {
// system doesn't work at all. Config should return null constant.
String helpURL = FormBuilderUtil.getConfig().getControlsHelpLink();
if (helpURL != null) {
add(new Link(new Label(GlobalizationUtil.globalize
("formbuilder.ui.help")), helpURL));
add(new Link(new Label(GlobalizationUtil.globalize(
"formbuilder.ui.help")), helpURL));
add(new Label("")); // spacer
}
m_control = new ParameterSingleSelectionModel(new BigDecimalParameter("control"));
m_control = new ParameterSingleSelectionModel(new BigDecimalParameter(
"control"));
m_view_form = new BoxPanel(BoxPanel.VERTICAL);
@ -150,7 +151,8 @@ public class ControlEditor extends SimpleContainer {
m_new_section.addProcessListener(new NewSectionProcessListener());
m_new_control.addProcessListener(new NewControlProcessListener());
m_control_props.addCompletionListener(new ControlPropsCompletionListener());
m_control_props.addCompletionListener(
new ControlPropsCompletionListener());
m_move_control.addActionListener(new MoveControlActionListener());
add(m_view_form);
@ -164,20 +166,19 @@ public class ControlEditor extends SimpleContainer {
}
protected PersistentComponent getFormSection(PageState state,
BigDecimal sectionID) {
OID componentOID = new OID( PersistentComponent.BASE_DATA_OBJECT_TYPE,
sectionID );
return (PersistentComponent)
DomainObjectFactory.newInstance( componentOID );
BigDecimal sectionID) {
OID componentOID = new OID(PersistentComponent.BASE_DATA_OBJECT_TYPE,
sectionID);
return (PersistentComponent) DomainObjectFactory.newInstance(
componentOID);
}
// XXX PrintListener will change to ListModel when (if)
// optiongroups finally become model driven
/**
* Sets the form section model builder for populating
* the drop down list of form sections. The model
* builder is actually a PrintListener, which should
* add new Options to the select box
* Sets the form section model builder for populating the drop down list of
* form sections. The model builder is actually a PrintListener, which
* should add new Options to the select box
*
* @param l the print listener for populating the list
*/
@ -186,7 +187,7 @@ public class ControlEditor extends SimpleContainer {
}
public void respond(PageState state)
throws javax.servlet.ServletException {
throws javax.servlet.ServletException {
super.respond(state);
String name = state.getControlEventName();
@ -199,22 +200,23 @@ public class ControlEditor extends SimpleContainer {
} else if (name.equals("delete")) {
m_control.setSelectedKey(state, new BigDecimal(value));
OID formOID = new OID( PersistentFormSection.BASE_DATA_OBJECT_TYPE,
m_form.getSelectedKey(state) );
PersistentFormSection fs = (PersistentFormSection)
DomainObjectFactory.newInstance( formOID );
OID formOID = new OID(PersistentFormSection.BASE_DATA_OBJECT_TYPE,
m_form.getSelectedKey(state));
PersistentFormSection fs
= (PersistentFormSection) DomainObjectFactory
.newInstance(formOID);
OID controlOID = new OID(PersistentComponent.BASE_DATA_OBJECT_TYPE,
m_control.getSelectedKey(state));
PersistentComponent c = (PersistentComponent) DomainObjectFactory
.newInstance(controlOID);
OID controlOID = new OID( PersistentComponent.BASE_DATA_OBJECT_TYPE,
m_control.getSelectedKey(state) );
PersistentComponent c = (PersistentComponent)
DomainObjectFactory.newInstance( controlOID );
fs.removeComponent(c);
try {
PersistentWidget w = (PersistentWidget)c;
PersistentWidget w = (PersistentWidget) c;
WidgetLabel label = WidgetLabel.findByWidget(w);
if( null != label ) {
if (null != label) {
fs.removeComponent(label);
label.delete();
}
@ -222,8 +224,9 @@ public class ControlEditor extends SimpleContainer {
// Nada
}
if (!(c instanceof PersistentFormSection))
if (!(c instanceof PersistentFormSection)) {
c.delete();
}
m_control.setSelectedKey(state, null);
} else if (name.equals("move")) {
m_control.setSelectedKey(state, new BigDecimal(value));
@ -234,9 +237,9 @@ public class ControlEditor extends SimpleContainer {
state.clearControlEvent();
try {
throw new RedirectSignal( state.stateAsURL(), true );
} catch( IOException ex ) {
throw new UncheckedWrapperException( ex );
throw new RedirectSignal(state.stateAsURL(), true);
} catch (IOException ex) {
throw new UncheckedWrapperException(ex);
}
}
@ -255,61 +258,70 @@ public class ControlEditor extends SimpleContainer {
}
private class NewSectionProcessListener implements FormProcessListener {
public void process(FormSectionEvent e)
throws FormProcessException {
s_log.debug( "NewSectionProcessListener().process()" );
s_log.debug("NewSectionProcessListener().process()");
PageState state = e.getPageState();
OID formOID = new OID( PersistentFormSection.BASE_DATA_OBJECT_TYPE,
m_form.getSelectedKey(state) );
PersistentFormSection form = (PersistentFormSection)
DomainObjectFactory.newInstance( formOID );
OID formOID = new OID(PersistentFormSection.BASE_DATA_OBJECT_TYPE,
m_form.getSelectedKey(state));
PersistentFormSection form
= (PersistentFormSection) DomainObjectFactory
.newInstance(formOID);
BigDecimal id = m_new_section.getSelectedSection(state);
PersistentComponent section = getFormSection(state, id);
form.addComponent(section);
}
}
private class NewControlProcessListener implements FormProcessListener {
public void process(FormSectionEvent e)
throws FormProcessException {
s_log.debug( "NewControlProcessListener.process()" );
s_log.debug("NewControlProcessListener.process()");
m_control.setSelectedKey(e.getPageState(), null);
m_view_form.setVisible(e.getPageState(), false);
m_control_props.setVisible(e.getPageState(), true);
}
}
private class ControlPropsCompletionListener implements FormCompletionListener {
private class ControlPropsCompletionListener implements
FormCompletionListener {
public void complete(FormSectionEvent e)
throws FormProcessException {
s_log.debug( "ControlPropsCompletionListener.complete()" );
s_log.debug("ControlPropsCompletionListener.complete()");
m_control.setSelectedKey(e.getPageState(), null);
m_view_form.setVisible(e.getPageState(), true);
m_control_props.setVisible(e.getPageState(), false);
}
}
private class MoveControlActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
s_log.debug( "MoveControlActionListener.actionPerformed()" );
s_log.debug("MoveControlActionListener.actionPerformed()");
m_control.setSelectedKey(e.getPageState(), null);
m_view_form.setVisible(e.getPageState(), true);
m_move_control.setVisible(e.getPageState(), false);
}
}
/**
/**
* Allows subclasses to control when to add the edit/move/delete links
*/
protected boolean addItemEditObserver(PageState state) {
@ -317,51 +329,56 @@ public class ControlEditor extends SimpleContainer {
}
private class FormItemControlsForm extends MetaForm {
public FormItemControlsForm(String name) {
super(name);
}
public Form buildForm(PageState state) {
OID formOID = new OID( PersistentFormSection.BASE_DATA_OBJECT_TYPE,
m_form.getSelectedKey(state) );
PersistentFormSection section = (PersistentFormSection)
DomainObjectFactory.newInstance( formOID );
OID formOID = new OID(PersistentFormSection.BASE_DATA_OBJECT_TYPE,
m_form.getSelectedKey(state));
PersistentFormSection section
= (PersistentFormSection) DomainObjectFactory
.newInstance(formOID);
if (addItemEditObserver(state)) {
section.setComponentAddObserver(new
ItemEditAddObserver(ControlEditor.this, state));
section.setComponentAddObserver(new ItemEditAddObserver(
ControlEditor.this, state));
section.setFormContainer(new ColumnPanel(3));
} else {
section.setFormContainer(new ColumnPanel(2));
}
Form f = null;
if (section instanceof PersistentForm) {
f = (Form)section.createComponent();
f = (Form) section.createComponent();
} else {
f = new Form("view_form", new ColumnPanel(1));
f.add((FormSection)section.createComponent());
f.add((FormSection) section.createComponent());
}
f.addInitListener(new PlaceholdersInitListener());
// Make the controls readonly
Traversal t = new Traversal() {
public void act(Component c) {
try {
Widget widget = (Widget)c;
widget.setDisabled();
widget.setReadOnly();
} catch (ClassCastException ex) {
// Nada
}
public void act(Component c) {
try {
Widget widget = (Widget) c;
widget.setDisabled();
widget.setReadOnly();
} catch (ClassCastException ex) {
// Nada
}
};
}
};
t.preorder(f);
return f;
}
private class ItemEditAddObserver extends BaseEditAddObserver {
Component m_handler;
PageState m_state;
@ -372,15 +389,17 @@ public class ControlEditor extends SimpleContainer {
}
/**
*
*
* @param dest
* @param component
* @return
*
* @return
*
* @deprecated
*/
protected BaseLink createLink(String dest,
PersistentComponent component) {
GlobalizedMessage label;
if (dest == "delete") {
label = GlobalizationUtil.globalize("formbuilder.ui.delete");
@ -389,16 +408,16 @@ public class ControlEditor extends SimpleContainer {
} else {
label = GlobalizationUtil.globalize("formbuilder.ui.edit");
}
return new CallbackLink(m_handler,
// "[" + dest + "]",
// "[" + dest + "]",
label,
dest,
component.getID().toString());
}
/**
*
*
*/
private class CallbackLink extends ControlLink {
@ -431,7 +450,11 @@ public class ControlEditor extends SimpleContainer {
public void setControlEvent(PageState state) {
state.setControlEvent(m_handler, m_action, m_component);
}
}
}
}
}