- fixing issue where comboboxes and lists had a bogus value inside them due to a weird constraint being put on the parent repeat rather than the control's binding.

- also doing some more cleanup and strong typing



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3944 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ariel Backenroth
2006-09-26 19:21:45 +00:00
parent 5fdef3896a
commit 88acdd33fc
2 changed files with 133 additions and 177 deletions

View File

@@ -700,28 +700,27 @@ public abstract class AbstractSchemaFormBuilder
* @param choicesElement __UNDOCUMENTED__ * @param choicesElement __UNDOCUMENTED__
* @param choiceValues __UNDOCUMENTED__ * @param choiceValues __UNDOCUMENTED__
*/ */
protected void addChoicesForSelectControl(Document xForm, protected void addChoicesForSelectControl(final Document xForm,
Element choicesElement, final Element choicesElement,
Vector choiceValues) { final List<String> choiceValues) {
// sort the enums values and then add them as choices // sort the enums values and then add them as choices
// //
// TODO: Should really put the default value (if any) at the top of the list. // TODO: Should really put the default value (if any) at the top of the list.
// //
List sortedList = choiceValues.subList(0, choiceValues.size()); // List sortedList = choiceValues.subList(0, choiceValues.size());
Collections.sort(sortedList); // Collections.sort(sortedList);
Iterator iterator = sortedList.iterator(); // Iterator iterator = sortedList.iterator();
while (iterator.hasNext()) for (String textValue : choiceValues)
{ {
String textValue = (String) iterator.next(); Element item = xForm.createElementNS(XFORMS_NS,
Element item = SchemaFormBuilder.XFORMS_NS_PREFIX + "item");
xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "item");
this.setXFormsId(item); this.setXFormsId(item);
choicesElement.appendChild(item); choicesElement.appendChild(item);
Element captionElement = Element captionElement = xForm.createElementNS(XFORMS_NS,
xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "label"); SchemaFormBuilder.XFORMS_NS_PREFIX + "label");
this.setXFormsId(captionElement); this.setXFormsId(captionElement);
item.appendChild(captionElement); item.appendChild(captionElement);
captionElement.appendChild(xForm.createTextNode(createCaption(textValue))); captionElement.appendChild(xForm.createTextNode(createCaption(textValue)));
@@ -735,20 +734,16 @@ public abstract class AbstractSchemaFormBuilder
} }
//protected void addChoicesForSelectSwitchControl(Document xForm, Element choicesElement, Vector choiceValues, String bindIdPrefix) { //protected void addChoicesForSelectSwitchControl(Document xForm, Element choicesElement, Vector choiceValues, String bindIdPrefix) {
protected void addChoicesForSelectSwitchControl(Document xForm, protected Map<String, Element> addChoicesForSelectSwitchControl(final Document xForm,
Element choicesElement, final Element choicesElement,
Vector choiceValues, final List<XSTypeDefinition> choiceValues)
HashMap case_types)
{ {
if (LOGGER.isDebugEnabled()) if (LOGGER.isDebugEnabled())
{ {
LOGGER.debug("addChoicesForSelectSwitchControl, values="); LOGGER.debug("addChoicesForSelectSwitchControl, values=");
Iterator it = choiceValues.iterator(); for (XSTypeDefinition type : choiceValues)
while (it.hasNext())
{ {
XSTypeDefinition type = (XSTypeDefinition) it.next(); LOGGER.debug(" - " + type.getName());
String name = type.getName();
LOGGER.debug(" - " + name);
} }
} }
@@ -761,38 +756,36 @@ public abstract class AbstractSchemaFormBuilder
Collections.sort(sortedList); Collections.sort(sortedList);
Iterator iterator = sortedList.iterator();*/ Iterator iterator = sortedList.iterator();*/
// -> no, already sorted // -> no, already sorted
Iterator iterator = choiceValues.iterator(); final Map<String, Element> result = new HashMap<String, Element>();
while (iterator.hasNext()) for (XSTypeDefinition type : choiceValues)
{ {
XSTypeDefinition type = (XSTypeDefinition) iterator.next();
String textValue = type.getName(); String textValue = type.getName();
//String textValue = (String) iterator.next(); //String textValue = (String) iterator.next();
if (LOGGER.isDebugEnabled()) if (LOGGER.isDebugEnabled())
LOGGER.debug("addChoicesForSelectSwitchControl, processing " + textValue); LOGGER.debug("addChoicesForSelectSwitchControl, processing " + textValue);
Element item = Element item = xForm.createElementNS(XFORMS_NS,
xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "item"); SchemaFormBuilder.XFORMS_NS_PREFIX + "item");
this.setXFormsId(item); this.setXFormsId(item);
choicesElement.appendChild(item); choicesElement.appendChild(item);
Element captionElement = Element captionElement = xForm.createElementNS(XFORMS_NS,
xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "label"); SchemaFormBuilder.XFORMS_NS_PREFIX + "label");
this.setXFormsId(captionElement); this.setXFormsId(captionElement);
item.appendChild(captionElement); item.appendChild(captionElement);
captionElement.appendChild(xForm.createTextNode(createCaption(textValue))); captionElement.appendChild(xForm.createTextNode(createCaption(textValue)));
Element value = Element value = xForm.createElementNS(XFORMS_NS,
xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "value"); SchemaFormBuilder.XFORMS_NS_PREFIX + "value");
this.setXFormsId(value); this.setXFormsId(value);
item.appendChild(value); item.appendChild(value);
value.appendChild(xForm.createTextNode(textValue)); value.appendChild(xForm.createTextNode(textValue));
/// action in the case /// action in the case
Element action = Element action = xForm.createElementNS(XFORMS_NS,
xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "action");
SchemaFormBuilder.XFORMS_NS_PREFIX + "action");
this.setXFormsId(action); this.setXFormsId(action);
item.appendChild(action); item.appendChild(action);
@@ -805,10 +798,10 @@ public abstract class AbstractSchemaFormBuilder
this.setXFormsId(toggle); this.setXFormsId(toggle);
//build the case element //build the case element
Element caseElement = Element caseElement = xForm.createElementNS(XFORMS_NS,
xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "case"); SchemaFormBuilder.XFORMS_NS_PREFIX + "case");
String case_id = this.setXFormsId(caseElement); String case_id = this.setXFormsId(caseElement);
case_types.put(textValue, caseElement); result.put(textValue, caseElement);
toggle.setAttributeNS(XFORMS_NS, toggle.setAttributeNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "case", SchemaFormBuilder.XFORMS_NS_PREFIX + "case",
@@ -817,6 +810,7 @@ public abstract class AbstractSchemaFormBuilder
//toggle.setAttributeNS(XFORMS_NS,SchemaFormBuilder.XFORMS_NS_PREFIX + "case",bindIdPrefix + "_" + textValue +"_case"); //toggle.setAttributeNS(XFORMS_NS,SchemaFormBuilder.XFORMS_NS_PREFIX + "case",bindIdPrefix + "_" + textValue +"_case");
action.appendChild(toggle); action.appendChild(toggle);
} }
return result;
} }
/** /**
@@ -1375,27 +1369,22 @@ public abstract class AbstractSchemaFormBuilder
this.setXFormsId(choices); this.setXFormsId(choices);
//get possible values //get possible values
Vector enumValues = new Vector(); List<XSTypeDefinition> enumValues = new LinkedList<XSTypeDefinition>();
//add the type (if not abstract) //add the type (if not abstract)
if (!((XSComplexTypeDefinition) controlType).getAbstract()) if (!((XSComplexTypeDefinition) controlType).getAbstract())
enumValues.add(controlType); enumValues.add(controlType);
//enumValues.add(typeName);
//add compatible types //add compatible types
Iterator it = compatibleTypes.iterator(); enumValues.addAll(compatibleTypes);
while (it.hasNext())
{
enumValues.add(it.next());
}
if (enumValues.size() == 1) if (enumValues.size() == 1)
{ {
// only one compatible type, set the controlType value // only one compatible type, set the controlType value
// and fall through // and fall through
// //
//controlType = getSchema().getComplexType((String)enumValues.get(0)); //controlType = schema.getTypeDefinition((String)enumValues.get(0),
controlType = schema.getTypeDefinition((String)enumValues.get(0), // this.targetNamespace);
this.targetNamespace); controlType = enumValues.get(0);
} }
else if (enumValues.size() > 1) else if (enumValues.size() > 1)
{ {
@@ -1410,11 +1399,9 @@ public abstract class AbstractSchemaFormBuilder
// multiple compatible types for this element exist // multiple compatible types for this element exist
// in the schema - allow the user to choose from // in the schema - allow the user to choose from
// between compatible non-abstract types // between compatible non-abstract types
Element bindElement = Element bindElement = xForm.createElementNS(XFORMS_NS,
xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "bind");
SchemaFormBuilder.XFORMS_NS_PREFIX + "bind"); String bindId = this.setXFormsId(bindElement);
String bindId =
this.setXFormsId(bindElement);
bindElement.setAttributeNS(XFORMS_NS, bindElement.setAttributeNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "nodeset", SchemaFormBuilder.XFORMS_NS_PREFIX + "nodeset",
@@ -1428,48 +1415,39 @@ public abstract class AbstractSchemaFormBuilder
//add the "element" bind, in addition //add the "element" bind, in addition
Element bindElement2 = xForm.createElementNS(XFORMS_NS, Element bindElement2 = xForm.createElementNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "bind"); SchemaFormBuilder.XFORMS_NS_PREFIX + "bind");
String bindId2 = String bindId2 = this.setXFormsId(bindElement2);
this.setXFormsId(bindElement2);
bindElement2.setAttributeNS(XFORMS_NS, bindElement2.setAttributeNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "nodeset", SchemaFormBuilder.XFORMS_NS_PREFIX + "nodeset",
pathToRoot); pathToRoot);
modelSection.appendChild(bindElement2); modelSection.appendChild(bindElement2);
if (enumValues.size() < Long.parseLong(getProperty(SELECTONE_LONG_LIST_SIZE_PROP))) control.setAttributeNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "appearance",
(enumValues.size() < Long.parseLong(getProperty(SELECTONE_LONG_LIST_SIZE_PROP))
? getProperty(SELECTONE_UI_CONTROL_SHORT_PROP)
: getProperty(SELECTONE_UI_CONTROL_LONG_PROP)));
if (enumValues.size() >= Long.parseLong(getProperty(SELECTONE_LONG_LIST_SIZE_PROP)))
{ {
control.setAttributeNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "appearance",
getProperty(SELECTONE_UI_CONTROL_SHORT_PROP));
}
else
{
control.setAttributeNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "appearance",
getProperty(SELECTONE_UI_CONTROL_LONG_PROP));
// add the "Please select..." instruction item for the combobox // add the "Please select..." instruction item for the combobox
// and set the isValid attribute on the bind element to check for the "Please select..." // and set the isValid attribute on the bind element to check for the "Please select..."
// item to indicate that is not a valid value // item to indicate that is not a valid value
// //
String pleaseSelect = String pleaseSelect = "[Select1 " + caption + "]";
"[Select1 " + caption + "]"; Element item = xForm.createElementNS(XFORMS_NS,
Element item = SchemaFormBuilder.XFORMS_NS_PREFIX + "item");
xForm.createElementNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "item");
this.setXFormsId(item); this.setXFormsId(item);
choices.appendChild(item); choices.appendChild(item);
Element captionElement = Element captionElement = xForm.createElementNS(XFORMS_NS,
xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "label");
SchemaFormBuilder.XFORMS_NS_PREFIX + "label");
this.setXFormsId(captionElement); this.setXFormsId(captionElement);
item.appendChild(captionElement); item.appendChild(captionElement);
captionElement.appendChild(xForm.createTextNode(pleaseSelect)); captionElement.appendChild(xForm.createTextNode(pleaseSelect));
Element value = Element value = xForm.createElementNS(XFORMS_NS,
xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "value");
SchemaFormBuilder.XFORMS_NS_PREFIX + "value");
this.setXFormsId(value); this.setXFormsId(value);
item.appendChild(value); item.appendChild(value);
value.appendChild(xForm.createTextNode(pleaseSelect)); value.appendChild(xForm.createTextNode(pleaseSelect));
@@ -1480,9 +1458,7 @@ public abstract class AbstractSchemaFormBuilder
String isValidExpr = "not( . = '" + pleaseSelect + "')"; String isValidExpr = "not( . = '" + pleaseSelect + "')";
//check if there was a constraint //check if there was a constraint
String constraint = String constraint = bindElement.getAttributeNS(XFORMS_NS, "constraint");
bindElement.getAttributeNS(XFORMS_NS,
"constraint");
constraint = (constraint != null && constraint.length() != 0 constraint = (constraint != null && constraint.length() != 0
? constraint + " && " + isValidExpr ? constraint + " && " + isValidExpr
@@ -1494,21 +1470,16 @@ public abstract class AbstractSchemaFormBuilder
constraint); constraint);
} }
Element choicesControlWrapper = Element choicesControlWrapper = _wrapper.createControlsWrapper(choices);
_wrapper.createControlsWrapper(choices);
control.appendChild(choicesControlWrapper); control.appendChild(choicesControlWrapper);
Element controlWrapper = Element controlWrapper = _wrapper.createControlsWrapper(control);
_wrapper.createControlsWrapper(control);
formSection.appendChild(controlWrapper); formSection.appendChild(controlWrapper);
///////////////// /////////////// ///////////////// ///////////////
// add content to select1 // add content to select1
HashMap case_types = new HashMap(); final Map<String, Element> caseTypes =
addChoicesForSelectSwitchControl(xForm, this.addChoicesForSelectSwitchControl(xForm, choices, enumValues);
choices,
enumValues,
case_types);
///////////////// /////////////////
//add a trigger for this control (is there a way to not need it ?) //add a trigger for this control (is there a way to not need it ?)
@@ -1549,7 +1520,7 @@ public abstract class AbstractSchemaFormBuilder
//formSection.appendChild(switchElement); //formSection.appendChild(switchElement);
/////////////// add this type ////////////// /////////////// add this type //////////////
Element firstCaseElement = (Element) case_types.get(controlType.getName()); Element firstCaseElement = caseTypes.get(controlType.getName());
switchElement.appendChild(firstCaseElement); switchElement.appendChild(firstCaseElement);
this.addComplexType(xForm, this.addComplexType(xForm,
modelSection, modelSection,
@@ -1563,17 +1534,15 @@ public abstract class AbstractSchemaFormBuilder
false); false);
/////////////// add sub types ////////////// /////////////// add sub types //////////////
it = compatibleTypes.iterator();
// add each compatible type within // add each compatible type within
// a case statement // a case statement
while (it.hasNext()) for (XSTypeDefinition type : compatibleTypes)
{ {
/*String compatibleTypeName = (String) it.next(); /*String compatibleTypeName = (String) it.next();
//WARNING: order of parameters inversed from the doc for 2.6.0 !!! //WARNING: order of parameters inversed from the doc for 2.6.0 !!!
XSTypeDefinition type =getSchema().getTypeDefinition( XSTypeDefinition type =getSchema().getTypeDefinition(
compatibleTypeName, compatibleTypeName,
targetNamespace);*/ targetNamespace);*/
XSTypeDefinition type = (XSTypeDefinition) it.next();
String compatibleTypeName = type.getName(); String compatibleTypeName = type.getName();
if (LOGGER.isDebugEnabled()) if (LOGGER.isDebugEnabled())
@@ -1589,7 +1558,7 @@ public abstract class AbstractSchemaFormBuilder
//Element caseElement = (Element) xForm.createElementNS(XFORMS_NS,SchemaFormBuilder.XFORMS_NS_PREFIX + "case"); //Element caseElement = (Element) xForm.createElementNS(XFORMS_NS,SchemaFormBuilder.XFORMS_NS_PREFIX + "case");
//caseElement.setAttributeNS(XFORMS_NS,SchemaFormBuilder.XFORMS_NS_PREFIX + "id",bindId + "_" + type.getName() +"_case"); //caseElement.setAttributeNS(XFORMS_NS,SchemaFormBuilder.XFORMS_NS_PREFIX + "id",bindId + "_" + type.getName() +"_case");
//String case_id=this.setXFormsId(caseElement); //String case_id=this.setXFormsId(caseElement);
Element caseElement = (Element)case_types.get(type.getName()); Element caseElement = caseTypes.get(type.getName());
switchElement.appendChild(caseElement); switchElement.appendChild(caseElement);
this.addComplexType(xForm, this.addComplexType(xForm,
@@ -2247,6 +2216,8 @@ public abstract class AbstractSchemaFormBuilder
SchemaFormBuilder.XFORMS_NS_PREFIX + "nodeset", SchemaFormBuilder.XFORMS_NS_PREFIX + "nodeset",
"."); ".");
bindElement.appendChild(bindElement2); bindElement.appendChild(bindElement2);
bindElement = bindElement2;
bindId = bindId2; bindId = bindId2;
} }
@@ -2614,7 +2585,7 @@ public abstract class AbstractSchemaFormBuilder
} }
} }
else if (controlType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE && else if (controlType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE &&
controlType.getName().equals("anyType")) "anyType".equals(controlType.getName()))
{ {
formControl = createControlForAnyType(xForm, caption, controlType); formControl = createControlForAnyType(xForm, caption, controlType);
} }

View File

@@ -20,8 +20,7 @@ import org.apache.xerces.xs.*;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Text; import org.w3c.dom.Text;
import java.util.*;
import java.util.Vector;
/* /*
* Search for TODO for things remaining to-do in this implementation. * Search for TODO for things remaining to-do in this implementation.
@@ -271,87 +270,82 @@ public class BaseSchemaFormBuilder
// //
// For now, use radio if enumValues < DEFAULT_LONG_LIST_MAX_SIZE otherwise use combobox // For now, use radio if enumValues < DEFAULT_LONG_LIST_MAX_SIZE otherwise use combobox
// //
StringList enumFacets = controlType.getLexicalEnumeration(); final StringList enumFacets = controlType.getLexicalEnumeration();
int nbFacets = enumFacets.getLength(); if (enumFacets.getLength() <= 0)
if (nbFacets <= 0)
return null; return null;
Vector enumValues = new Vector();
Element control = xForm.createElementNS(XFORMS_NS, Element control = xForm.createElementNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "select1"); SchemaFormBuilder.XFORMS_NS_PREFIX + "select1");
this.setXFormsId(control); this.setXFormsId(control);
//label //label
Element captionElement1 = (Element) Element captionElement1 = xForm.createElementNS(XFORMS_NS,
control.appendChild(xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "label");
SchemaFormBuilder.XFORMS_NS_PREFIX + "label")); control.appendChild(captionElement1);
this.setXFormsId(captionElement1); this.setXFormsId(captionElement1);
captionElement1.appendChild(xForm.createTextNode(caption)); captionElement1.appendChild(xForm.createTextNode(caption));
Element choices = xForm.createElementNS(XFORMS_NS, Element choices = xForm.createElementNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "choices"); SchemaFormBuilder.XFORMS_NS_PREFIX + "choices");
this.setXFormsId(choices); this.setXFormsId(choices);
for (int i = 0; i < nbFacets; i++) { final List<String> enumValues = new ArrayList(enumFacets.getLength());
String facet = enumFacets.item(i); for (int i = 0; i < enumFacets.getLength(); i++)
enumValues.add(facet); {
enumValues.add(enumFacets.item(i));
} }
control.setAttributeNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "appearance",
(enumFacets.getLength() < Long.parseLong(getProperty(SELECTONE_LONG_LIST_SIZE_PROP))
? getProperty(SELECTONE_UI_CONTROL_SHORT_PROP)
: getProperty(SELECTONE_UI_CONTROL_LONG_PROP)));
if (nbFacets < Long.parseLong(getProperty(SELECTONE_LONG_LIST_SIZE_PROP))) { if (enumFacets.getLength() >= Long.parseLong(getProperty(SELECTONE_LONG_LIST_SIZE_PROP)))
control.setAttributeNS(XFORMS_NS, {
SchemaFormBuilder.XFORMS_NS_PREFIX + "appearance",
getProperty(SELECTONE_UI_CONTROL_SHORT_PROP));
} else {
control.setAttributeNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "appearance",
getProperty(SELECTONE_UI_CONTROL_LONG_PROP));
// add the "Please select..." instruction item for the combobox // add the "Please select..." instruction item for the combobox
// and set the isValid attribute on the bind element to check for the "Please select..." // and set the isValid attribute on the bind element to check for the "Please select..."
// item to indicate that is not a valid value // item to indicate that is not a valid value
// //
{ String pleaseSelect = "[Select1 " + caption + "]";
String pleaseSelect = "[Select1 " + caption + "]"; Element item = xForm.createElementNS(XFORMS_NS,
Element item = xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "item");
SchemaFormBuilder.XFORMS_NS_PREFIX + "item"); this.setXFormsId(item);
this.setXFormsId(item); choices.appendChild(item);
choices.appendChild(item);
Element captionElement = Element captionElement =
xForm.createElementNS(XFORMS_NS, xForm.createElementNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "label"); SchemaFormBuilder.XFORMS_NS_PREFIX + "label");
this.setXFormsId(captionElement); this.setXFormsId(captionElement);
item.appendChild(captionElement); item.appendChild(captionElement);
captionElement.appendChild(xForm.createTextNode(pleaseSelect)); captionElement.appendChild(xForm.createTextNode(pleaseSelect));
Element value = Element value =
xForm.createElementNS(XFORMS_NS, xForm.createElementNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "value"); SchemaFormBuilder.XFORMS_NS_PREFIX + "value");
this.setXFormsId(value); this.setXFormsId(value);
item.appendChild(value); item.appendChild(value);
value.appendChild(xForm.createTextNode(pleaseSelect)); value.appendChild(xForm.createTextNode(pleaseSelect));
// not(purchaseOrder/state = '[Choose State]') // not(purchaseOrder/state = '[Choose State]')
//String isValidExpr = "not(" + bindElement.getAttributeNS(XFORMS_NS,"nodeset") + " = '" + pleaseSelect + "')"; //String isValidExpr = "not(" + bindElement.getAttributeNS(XFORMS_NS,"nodeset") + " = '" + pleaseSelect + "')";
// ->no, not(. = '[Choose State]') // ->no, not(. = '[Choose State]')
String isValidExpr = "not( . = '" + pleaseSelect + "')"; String isValidExpr = "not( . = '" + pleaseSelect + "')";
//check if there was a constraint //check if there was a constraint
String constraint = bindElement.getAttributeNS(XFORMS_NS, "constraint"); String constraint = bindElement.getAttributeNS(XFORMS_NS, "constraint");
constraint = (constraint != null && constraint.length() != 0 constraint = (constraint != null && constraint.length() != 0
? constraint + " and " + isValidExpr ? constraint + " and " + isValidExpr
: isValidExpr); : isValidExpr);
bindElement.setAttributeNS(XFORMS_NS, bindElement.setAttributeNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "constraint", SchemaFormBuilder.XFORMS_NS_PREFIX + "constraint",
constraint); constraint);
} }
}
control.appendChild(choices); control.appendChild(choices);
addChoicesForSelectControl(xForm, choices, enumValues); this.addChoicesForSelectControl(xForm, choices, enumValues);
return control; return control;
} }
@@ -365,29 +359,29 @@ public class BaseSchemaFormBuilder
* @param bindElement __UNDOCUMENTED__ * @param bindElement __UNDOCUMENTED__
* @return __UNDOCUMENTED__ * @return __UNDOCUMENTED__
*/ */
public Element createControlForListType(Document xForm, public Element createControlForListType(final Document xForm,
XSSimpleTypeDefinition listType, final XSSimpleTypeDefinition listType,
String caption, final String caption,
Element bindElement) { final Element bindElement) {
XSSimpleTypeDefinition controlType = listType.getItemType(); XSSimpleTypeDefinition controlType = listType.getItemType();
StringList enumFacets = controlType.getLexicalEnumeration(); final StringList enumFacets = controlType.getLexicalEnumeration();
int nbFacets = enumFacets.getLength(); if (enumFacets.getLength() <= 0)
if (nbFacets <= 0)
return null; return null;
Element control = xForm.createElementNS(XFORMS_NS, Element control = xForm.createElementNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "select"); SchemaFormBuilder.XFORMS_NS_PREFIX + "select");
this.setXFormsId(control); this.setXFormsId(control);
//label //label
Element captionElement = (Element) Element captionElement = xForm.createElementNS(XFORMS_NS,
control.appendChild(xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "label");
SchemaFormBuilder.XFORMS_NS_PREFIX + "label")); control.appendChild(captionElement);
this.setXFormsId(captionElement); this.setXFormsId(captionElement);
captionElement.appendChild(xForm.createTextNode(caption)); captionElement.appendChild(xForm.createTextNode(caption));
Vector enumValues = new Vector(); List<String> enumValues = new ArrayList<String>(enumFacets.getLength());
for (int i = 0; i < nbFacets; i++) { for (int i = 0; i < enumFacets.getLength(); i++)
{
enumValues.add(enumFacets.item(i)); enumValues.add(enumFacets.item(i));
} }
@@ -397,22 +391,13 @@ public class BaseSchemaFormBuilder
// //
// For now, use checkbox if there are < DEFAULT_LONG_LIST_MAX_SIZE items, otherwise use long control // For now, use checkbox if there are < DEFAULT_LONG_LIST_MAX_SIZE items, otherwise use long control
// //
if (enumValues.size() < Long.parseLong(getProperty(SELECTMANY_LONG_LIST_SIZE_PROP))) control.setAttributeNS(XFORMS_NS,
{ SchemaFormBuilder.XFORMS_NS_PREFIX + "appearance",
control.setAttributeNS(XFORMS_NS, (enumValues.size() < Long.parseLong(getProperty(SELECTMANY_LONG_LIST_SIZE_PROP))
SchemaFormBuilder.XFORMS_NS_PREFIX + "appearance", ? getProperty(SELECTMANY_UI_CONTROL_SHORT_PROP)
getProperty(SELECTMANY_UI_CONTROL_SHORT_PROP)); : getProperty(SELECTMANY_UI_CONTROL_LONG_PROP)));
} Element choices = xForm.createElementNS(XFORMS_NS,
else SchemaFormBuilder.XFORMS_NS_PREFIX + "choices");
{
control.setAttributeNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "appearance",
getProperty(SELECTMANY_UI_CONTROL_LONG_PROP));
}
Element choices =
xForm.createElementNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "choices");
this.setXFormsId(choices); this.setXFormsId(choices);
control.appendChild(choices); control.appendChild(choices);