From: <mb...@re...> - 2004-11-05 20:03:50
|
Author: mbooth Date: 2004-11-05 20:56:43 +0100 (Fri, 05 Nov 2004) New Revision: 82 Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/ui/MoveControl.java ccm-core/trunk/web/packages/formbuilder/xsl/formbuilder.xsl Log: Fix repositioning of form widgets Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/ui/MoveControl.java =================================================================== --- ccm-core/trunk/src/com/arsdigita/formbuilder/ui/MoveControl.java 2004-11-05 12:02:47 UTC (rev 81) +++ ccm-core/trunk/src/com/arsdigita/formbuilder/ui/MoveControl.java 2004-11-05 19:56:43 UTC (rev 82) @@ -18,44 +18,41 @@ */ package com.arsdigita.formbuilder.ui; - +import com.arsdigita.formbuilder.PersistentComponent; +import com.arsdigita.formbuilder.PersistentComponentFactory; +import com.arsdigita.formbuilder.PersistentForm; +import com.arsdigita.formbuilder.PersistentFormSection; +import com.arsdigita.formbuilder.PersistentWidget; +import com.arsdigita.formbuilder.WidgetLabel; +import com.arsdigita.formbuilder.ui.BaseAddObserver; +import com.arsdigita.formbuilder.util.FormBuilderUtil; +import com.arsdigita.formbuilder.util.FormBuilderUtil; import com.arsdigita.formbuilder.util.GlobalizationUtil ; - -import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.ColumnPanel; +import com.arsdigita.bebop.Component; +import com.arsdigita.bebop.ControlLink; +import com.arsdigita.bebop.event.ActionEvent; +import com.arsdigita.bebop.event.ActionListener; import com.arsdigita.bebop.Form; - - -import com.arsdigita.formbuilder.util.FormBuilderUtil; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.MetaForm; -import java.math.BigDecimal; -import com.arsdigita.domain.DataObjectNotFoundException; -import com.arsdigita.formbuilder.PersistentComponentFactory; -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.ColumnPanel; import com.arsdigita.bebop.FormSection; import com.arsdigita.bebop.GridPanel; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.MetaForm; +import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.SingleSelectionModel; -import com.arsdigita.bebop.ControlLink; -import com.arsdigita.bebop.event.ActionEvent; -import com.arsdigita.bebop.event.ActionListener; +import com.arsdigita.domain.DataObjectNotFoundException; -import com.arsdigita.formbuilder.PersistentFormSection; -import com.arsdigita.formbuilder.util.FormBuilderUtil; -import com.arsdigita.formbuilder.PersistentForm; -import com.arsdigita.formbuilder.ui.BaseAddObserver; +import java.math.BigDecimal; import java.util.ArrayList; -import com.arsdigita.bebop.event.ActionListener; -import com.arsdigita.bebop.event.ActionEvent; -import com.arsdigita.formbuilder.PersistentWidget; -import com.arsdigita.formbuilder.WidgetLabel; +import java.util.HashSet; import java.util.Iterator; -import com.arsdigita.formbuilder.PersistentComponent; -import java.util.HashSet; +import org.apache.log4j.Logger; public class MoveControl extends MetaForm { + private static final Logger s_log = Logger.getLogger( MoveControl.class ); + private SingleSelectionModel m_form; private SingleSelectionModel m_control; @@ -71,42 +68,70 @@ m_listeners = new ArrayList(); addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - PageState state = e.getPageState(); + public void actionPerformed(ActionEvent e) { + PageState state = e.getPageState(); - String name = state.getControlEventName(); - String value = state.getControlEventValue(); + String name = state.getControlEventName(); + String value = state.getControlEventValue(); - if (name.equals("move")) { - Integer pos = new Integer(value); - BigDecimal control_id = (BigDecimal)m_control.getSelectedKey(state); - BigDecimal form_id = (BigDecimal)m_form.getSelectedKey(state); + if (name.equals("move")) { + Integer pos = new Integer(value); + BigDecimal control_id = (BigDecimal)m_control.getSelectedKey(state); + BigDecimal form_id = (BigDecimal)m_form.getSelectedKey(state); - PersistentFormSection form = (PersistentFormSection)FormBuilderUtil.instantiateObject(form_id); - PersistentComponent control = (PersistentComponent)FormBuilderUtil.instantiateObject(control_id); + PersistentFormSection form = (PersistentFormSection)FormBuilderUtil.instantiateObject(form_id); + PersistentComponent control = (PersistentComponent)FormBuilderUtil.instantiateObject(control_id); - WidgetLabel label = null; + WidgetLabel label = null; - if (control instanceof PersistentWidget) { - try { - label = WidgetLabel.findByWidget((PersistentWidget)control); - } catch (DataObjectNotFoundException ex) { - // Nada - } + if (control instanceof PersistentWidget) { + try { + label = WidgetLabel.findByWidget((PersistentWidget)control); + } catch (DataObjectNotFoundException ex) { + // Nada } + } - if (label != null) - form.removeComponent(label); - form.removeComponent(control); - if (label != null) - form.addComponent(label, pos.intValue()); - form.addComponent(control, (label == null ? pos.intValue() : pos.intValue() + 1)); - //form.moveComponent(label, pos.intValue()); - //form.moveComponent(control, pos.intValue()+1); + if( s_log.isDebugEnabled() ) { + StringBuffer buf = new StringBuffer(); + + buf.append( "form: " ); + buf.append( form.getOID().toString() ); + + buf.append( "\ncontrol: " ); + buf.append( control.getOID().toString() ); + + buf.append( "\nwidget: " ); + if( null != label ) { + buf.append( label.getOID().toString() ); + } else { + buf.append( "null" ); + } + + buf.append( "\nnew pos: " ); + buf.append( pos ); + + s_log.debug( buf.toString() ); } + + int newPos = pos.intValue(); + + if (label != null) + form.removeComponent(label); + form.removeComponent(control); + + if (label != null) { + if( 1 == newPos ) { + form.addComponent( label, newPos ); + newPos++; + } else { + form.addComponent(label, newPos - 1); + } + } + form.addComponent(control, newPos); } - }); - + } + }); } public Form buildForm(PageState state) { @@ -207,7 +232,7 @@ if (!(componentFactory instanceof WidgetLabel) && m_after) { - addLink(formSection, componentPosition-1); + addLink(formSection, componentPosition); } if (componentFactory.getID().equals(m_moving)) { Modified: ccm-core/trunk/web/packages/formbuilder/xsl/formbuilder.xsl =================================================================== --- ccm-core/trunk/web/packages/formbuilder/xsl/formbuilder.xsl 2004-11-05 12:02:47 UTC (rev 81) +++ ccm-core/trunk/web/packages/formbuilder/xsl/formbuilder.xsl 2004-11-05 19:56:43 UTC (rev 82) @@ -69,9 +69,11 @@ <!-- TODO: we should also check the link/orderNumber to make sure that the order number of this label is the current link/orderNumber -1 --> - <xsl:if test="following-sibling::component[defaultDomainClass='com.arsdigita.formbuilder.WidgetLabel'][1]"> - <xsl:apply-templates select="following-sibling::component[defaultDomainClass='com.arsdigita.formbuilder.WidgetLabel'][1]"/> - </xsl:if> + <xsl:variable name="labelOrder"> + <xsl:value-of select="link/orderNumber - 1"/> + </xsl:variable> + + <xsl:apply-templates select="../component[defaultDomainClass='com.arsdigita.formbuilder.WidgetLabel' and link/orderNumber=$labelOrder]"/> </xsl:template> <!-- a utility template to print out error messages --> |