|
From: <mb...@re...> - 2005-03-11 19:06:34
|
Author: mbooth
Date: 2005-03-11 20:04:37 +0100 (Fri, 11 Mar 2005)
New Revision: 315
Modified:
ccm-cms-types-formsectionitem/trunk/src/com/arsdigita/cms/formbuilder/FormSectionWrapper.java
ccm-core/trunk/src/com/arsdigita/formbuilder/CompoundComponent.java
ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentComponent.java
ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentContainer.java
ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentFormSection.java
ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentHorizontalRule.java
ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentSubmit.java
ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentText.java
ccm-core/trunk/src/com/arsdigita/formbuilder/ui/BaseAddObserver.java
ccm-core/trunk/src/com/arsdigita/formbuilder/ui/BaseEditAddObserver.java
ccm-core/trunk/src/com/arsdigita/formbuilder/ui/editors/TemplateEmailForm.java
ccm-core/trunk/src/com/arsdigita/formbuilder/ui/editors/WidgetForm.java
ccm-core/trunk/src/com/arsdigita/formbuilder/util/PersistentContainerHelper.java
Log:
Display components of a formsection in TemplateEmailForm controls widget.
Required refactorisation to allow components to be retrieved from CompoundComponent.
Modified: ccm-cms-types-formsectionitem/trunk/src/com/arsdigita/cms/formbuilder/FormSectionWrapper.java
===================================================================
--- ccm-cms-types-formsectionitem/trunk/src/com/arsdigita/cms/formbuilder/FormSectionWrapper.java 2005-03-11 18:26:14 UTC (rev 314)
+++ ccm-cms-types-formsectionitem/trunk/src/com/arsdigita/cms/formbuilder/FormSectionWrapper.java 2005-03-11 19:04:37 UTC (rev 315)
@@ -32,6 +32,7 @@
import org.apache.log4j.Logger;
import java.math.BigDecimal;
+import java.util.Iterator;
public class FormSectionWrapper extends PersistentComponent
implements CompoundComponent {
@@ -147,24 +148,6 @@
return section.createComponent();
}
- /*
- public void save() {
- super.save();
- }
-
- public void delete() {
- super.delete();
- }
-
- public BigDecimal getID() {
- super.getID();
- }
-
- public boolean isNew() {
- super.isNew();
- }
- */
-
public void addComponent(PersistentComponent component) {
FormSectionItem item = getFormSectionItem();
Assert.exists(item, FormSectionItem.class);
@@ -196,4 +179,12 @@
Assert.exists(item, FormSectionItem.class);
item.getFormSection().clearComponents();
}
+
+ public Iterator getComponentsIter() {
+ return getFormSectionItem().getFormSection().getComponentsIter();
+ }
+
+ public boolean isEditable() {
+ return false;
+ }
}
Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/CompoundComponent.java
===================================================================
--- ccm-core/trunk/src/com/arsdigita/formbuilder/CompoundComponent.java 2005-03-11 18:26:14 UTC (rev 314)
+++ ccm-core/trunk/src/com/arsdigita/formbuilder/CompoundComponent.java 2005-03-11 19:04:37 UTC (rev 315)
@@ -18,9 +18,16 @@
*/
package com.arsdigita.formbuilder;
+import java.util.Iterator;
+/**
+ * A CompoundComponent is a container of components which should themselves be
+ * treated like top level components. FormSection is an example of this.
+ */
+
public interface CompoundComponent {
public void setComponentAddObserver(ComponentAddObserver observer);
+ public Iterator getComponentsIter();
}
Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentComponent.java
===================================================================
--- ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentComponent.java 2005-03-11 18:26:14 UTC (rev 314)
+++ ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentComponent.java 2005-03-11 19:04:37 UTC (rev 315)
@@ -230,4 +230,21 @@
return list;
}
+
+ // Metadata for authoring
+
+ /**
+ * Is this object editable after creation? eg A form section isn't, you must
+ * edit the target item.
+ */
+ public boolean isEditable() {
+ return true;
+ }
+
+ /**
+ * Does this widget have an associated label? eg A horizontal rule doesn't.
+ */
+ public boolean hasLabel() {
+ return true;
+ }
}
Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentContainer.java
===================================================================
--- ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentContainer.java 2005-03-11 18:26:14 UTC (rev 314)
+++ ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentContainer.java 2005-03-11 19:04:37 UTC (rev 315)
@@ -18,9 +18,8 @@
*/
package com.arsdigita.formbuilder;
+import java.util.Iterator;
-
-
/**
* Implemented by classes that contain persistent Bebop components. The
* components are added via their corresponding PersistentComponent that
@@ -69,4 +68,9 @@
* Delete all component associations from this container
*/
public void clearComponents();
+
+ /**
+ * Return an Iterator over all components in the container
+ */
+ public Iterator getComponentsIter();
}
Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentFormSection.java
===================================================================
--- ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentFormSection.java 2005-03-11 18:26:14 UTC (rev 314)
+++ ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentFormSection.java 2005-03-11 19:04:37 UTC (rev 315)
@@ -33,9 +33,9 @@
import com.arsdigita.persistence.metadata.ObjectType;
import java.math.BigDecimal;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
-import java.util.ArrayList;
import org.apache.log4j.Logger;
@@ -240,6 +240,13 @@
return m_container.getComponents();
}
+ /**
+ * Return an Iterator over all child components
+ */
+ public Iterator getComponentsIter() {
+ return m_container.getComponentsIter();
+ }
+
// *** Internal Helper Methods
/**
@@ -397,4 +404,8 @@
public Container getFormContainer() {
return m_form_container;
}
+
+ public boolean isEditable() {
+ return false;
+ }
}
Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentHorizontalRule.java
===================================================================
--- ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentHorizontalRule.java 2005-03-11 18:26:14 UTC (rev 314)
+++ ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentHorizontalRule.java 2005-03-11 19:04:37 UTC (rev 315)
@@ -92,4 +92,8 @@
public Component createComponent() {
return new HorizontalLine();
}
+
+ public boolean hasLabel() {
+ return false;
+ }
}
Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentSubmit.java
===================================================================
--- ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentSubmit.java 2005-03-11 18:26:14 UTC (rev 314)
+++ ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentSubmit.java 2005-03-11 19:04:37 UTC (rev 315)
@@ -166,4 +166,8 @@
public String getButtonLabel() {
return (String)getDefaultValue();
}
+
+ public boolean hasLabel() {
+ return false;
+ }
}
Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentText.java
===================================================================
--- ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentText.java 2005-03-11 18:26:14 UTC (rev 314)
+++ ccm-core/trunk/src/com/arsdigita/formbuilder/PersistentText.java 2005-03-11 19:04:37 UTC (rev 315)
@@ -139,4 +139,8 @@
public String getText() {
return getDescription();
}
+
+ public boolean hasLabel() {
+ return false;
+ }
}
Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/ui/BaseAddObserver.java
===================================================================
--- ccm-core/trunk/src/com/arsdigita/formbuilder/ui/BaseAddObserver.java 2005-03-11 18:26:14 UTC (rev 314)
+++ ccm-core/trunk/src/com/arsdigita/formbuilder/ui/BaseAddObserver.java 2005-03-11 19:04:37 UTC (rev 315)
@@ -45,14 +45,12 @@
PersistentComponent component,
int componentPosition) {
// Padding
- if (component instanceof PersistentSubmit ||
- component instanceof PersistentText ||
- component instanceof PersistentHorizontalRule) {
+ if (!component.hasLabel()) {
formSection.add(new Label(""));
}
// Make sure we process nested form sections
- if( component instanceof CompoundComponent ) {
+ if (component instanceof CompoundComponent) {
CompoundComponent fs = (CompoundComponent)component;
fs.setComponentAddObserver(new BaseAddObserver());
}
Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/ui/BaseEditAddObserver.java
===================================================================
--- ccm-core/trunk/src/com/arsdigita/formbuilder/ui/BaseEditAddObserver.java 2005-03-11 18:26:14 UTC (rev 314)
+++ ccm-core/trunk/src/com/arsdigita/formbuilder/ui/BaseEditAddObserver.java 2005-03-11 19:04:37 UTC (rev 315)
@@ -30,6 +30,7 @@
import com.arsdigita.bebop.FormSection;
import com.arsdigita.bebop.Label;
+import org.apache.log4j.Logger;
/**
* This is an extension of the BaseAddObserver which
@@ -37,6 +38,8 @@
* adding additional links on each row.
*/
public abstract class BaseEditAddObserver extends BaseAddObserver {
+ private static final Logger s_log =
+ Logger.getLogger(BaseEditAddObserver.class);
public void beforeAddingComponent(FormSection formSection,
PersistentComponent component,
@@ -79,7 +82,10 @@
if(!(component instanceof PersistentLabel)) {
BoxPanel b = new BoxPanel(BoxPanel.HORIZONTAL);
- if (!(component instanceof CompoundComponent)) {
+ if (s_log.isDebugEnabled())
+ s_log.debug("Adding widget " + component.getClass().getName());
+
+ if (component.isEditable()) {
BaseLink edit = createLink("edit", component);
b.add(edit);
}
Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/ui/editors/TemplateEmailForm.java
===================================================================
--- ccm-core/trunk/src/com/arsdigita/formbuilder/ui/editors/TemplateEmailForm.java 2005-03-11 18:26:14 UTC (rev 314)
+++ ccm-core/trunk/src/com/arsdigita/formbuilder/ui/editors/TemplateEmailForm.java 2005-03-11 19:04:37 UTC (rev 315)
@@ -18,6 +18,7 @@
*/
package com.arsdigita.formbuilder.ui.editors;
+import com.arsdigita.formbuilder.CompoundComponent;
import com.arsdigita.formbuilder.PersistentComponent;
import com.arsdigita.formbuilder.PersistentFormSection;
import com.arsdigita.formbuilder.PersistentProcessListener;
@@ -120,21 +121,7 @@
PersistentFormSection form = (PersistentFormSection)
DomainObjectFactory.newInstance( formOID );
- DataAssociationCursor components = form.getComponents();
- while( components.next() ) {
- PersistentComponent c = (PersistentComponent)
- DomainObjectFactory.newInstance( components.getDataObject() );
-
- if( c instanceof PersistentWidget ) {
- PersistentWidget w = (PersistentWidget) c;
-
- if (!"::user.email::".equals(w.getParameterName())) {
- String parameter = "::form." +
- w.getParameterName() + "::";
- m_controls.addOption(new Option(parameter, w.getParameterName()), ps);
- }
- }
- }
+ addComponents(ps, form.getComponentsIter(), m_controls);
}
});
} catch (TooManyListenersException ex) {
@@ -147,6 +134,26 @@
section.add(m_body);
}
+ private void addComponents(PageState ps, Iterator components,
+ SingleSelect controls) {
+ while( components.hasNext() ) {
+ PersistentComponent c = (PersistentComponent) components.next();
+
+ if( c instanceof PersistentWidget ) {
+ PersistentWidget w = (PersistentWidget) c;
+
+ if (!"::user.email::".equals(w.getParameterName())) {
+ String parameter = "::form." +
+ w.getParameterName() + "::";
+ controls.addOption(new Option(parameter, w.getParameterName()), ps);
+ }
+ } else if (c instanceof CompoundComponent) {
+ CompoundComponent compound = (CompoundComponent) c;
+ addComponents(ps, compound.getComponentsIter(), controls);
+ }
+ }
+ }
+
protected PersistentProcessListener getProcessListener() {
return new TemplateEmailListener();
}
Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/ui/editors/WidgetForm.java
===================================================================
--- ccm-core/trunk/src/com/arsdigita/formbuilder/ui/editors/WidgetForm.java 2005-03-11 18:26:14 UTC (rev 314)
+++ ccm-core/trunk/src/com/arsdigita/formbuilder/ui/editors/WidgetForm.java 2005-03-11 19:04:37 UTC (rev 315)
@@ -310,7 +310,8 @@
*/
//m_name.setVisible(state, false);
- m_required.setValue( state, new Boolean( widget.isRequired() ) );
+ if(includeRequiredRadioGroup())
+ m_required.setValue(state, new Boolean(widget.isRequired()));
}
}
Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/util/PersistentContainerHelper.java
===================================================================
--- ccm-core/trunk/src/com/arsdigita/formbuilder/util/PersistentContainerHelper.java 2005-03-11 18:26:14 UTC (rev 314)
+++ ccm-core/trunk/src/com/arsdigita/formbuilder/util/PersistentContainerHelper.java 2005-03-11 19:04:37 UTC (rev 315)
@@ -19,11 +19,8 @@
package com.arsdigita.formbuilder.util;
-import java.math.BigDecimal;
-
import com.arsdigita.formbuilder.PersistentComponent;
import com.arsdigita.formbuilder.PersistentContainer;
-import com.arsdigita.formbuilder.util.FormBuilderUtil;
import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.domain.DomainServiceInterfaceExposer;
@@ -34,12 +31,10 @@
import com.arsdigita.persistence.DataQuery;
import com.arsdigita.persistence.DataOperation;
-// Child components are returned in a collection
-import java.util.Collection;
-import java.util.List;
-import java.util.ArrayList;
+import java.math.BigDecimal;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
-// ACS 5 uses Log4J for logging
import org.apache.log4j.Logger;
@@ -67,8 +62,6 @@
// We are using lazy initialization here
private int m_numberOfComponents = -1;
- private List m_selectedComponents = new ArrayList();
-
public PersistentContainerHelper(PersistentComponent component) {
m_component = component;
@@ -354,4 +347,44 @@
// Decrement the counter
--m_numberOfComponents;
}
+
+ public Iterator getComponentsIter() {
+ class DACIterator implements Iterator {
+ boolean m_hasNext = false;
+ Object m_obj = null;
+ DataAssociationCursor m_cursor;
+
+ DACIterator(DataAssociationCursor cursor) {
+ m_cursor = cursor;
+ iterate();
+ }
+
+ public boolean hasNext() {
+ return m_hasNext;
+ }
+
+ public Object next() {
+ if (!m_hasNext) throw new NoSuchElementException();
+
+ Object next = m_obj;
+ iterate();
+ return next;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void iterate() {
+ m_hasNext = m_cursor.next();
+ if (m_hasNext) {
+ m_obj = DomainObjectFactory.newInstance(m_cursor.getDataObject());
+ } else {
+ m_obj = null;
+ }
+ }
+ };
+
+ return new DACIterator(getComponents());
+ }
}
|