Author: adrianc
Date: Sun Jan 4 13:39:35 2015 New Revision: 1649329 URL: http://svn.apache.org/r1649329 Log: Update tree widget schemas & models to reuse shared actions. Modified: ofbiz/trunk/framework/widget/dtd/widget-tree.xsd ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTree.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTreeAction.java Modified: ofbiz/trunk/framework/widget/dtd/widget-tree.xsd URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/dtd/widget-tree.xsd?rev=1649329&r1=1649328&r2=1649329&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/dtd/widget-tree.xsd (original) +++ ofbiz/trunk/framework/widget/dtd/widget-tree.xsd Sun Jan 4 13:39:35 2015 @@ -64,6 +64,7 @@ under the License. <xs:sequence> <xs:element name="condition" type="ConditionRootType" minOccurs="0" /> <xs:choice minOccurs="0"> + <xs:element ref="actions" /> <xs:element ref="entity-one" /> <xs:element ref="service" /> </xs:choice> @@ -95,6 +96,7 @@ under the License. <xs:complexType> <xs:sequence> <xs:choice> + <xs:element ref="actions" /> <xs:element ref="entity-and" /> <xs:element ref="service" /> <xs:element ref="entity-condition" /> @@ -104,7 +106,6 @@ under the License. <xs:attribute type="xs:string" name="node-name" use="required" /> </xs:complexType> </xs:element> - <xs:element name="include-screen"> <xs:complexType> <xs:attribute type="xs:string" name="name" use="required" /> @@ -202,7 +203,13 @@ under the License. </xs:attribute> </xs:complexType> </xs:element> - + <xs:element name="actions"> + <xs:complexType> + <xs:sequence> + <xs:element minOccurs="0" maxOccurs="unbounded" ref="AllActions"/> + </xs:sequence> + </xs:complexType> + </xs:element> <xs:element name="service"> <xs:complexType> <xs:sequence> @@ -216,12 +223,10 @@ under the License. </xs:annotation> </xs:attribute> <xs:attribute type="xs:string" name="result-map-list" /> - <!-- deprecated, use result-map-list instead <xs:attribute type="xs:string" name="result-map-list-iterator-name"/> --> <xs:attribute type="xs:string" name="result-map-value" /> <xs:attribute type="xs:string" name="value" /> </xs:complexType> </xs:element> - <xs:element name="entity-and"> <xs:complexType> <xs:sequence> @@ -312,170 +317,10 @@ under the License. </xs:attribute> </xs:complexType> </xs:element> - <xs:element name="entity-one"> - <xs:complexType> - <xs:sequence> - <xs:element minOccurs="0" maxOccurs="unbounded" ref="field-map" /> - <xs:element minOccurs="0" maxOccurs="unbounded" ref="select-field" /> - </xs:sequence> - <xs:attribute name="entity-name" type="xs:string" use="required" /> - <xs:attribute name="value-field" type="xs:string" /> - <xs:attribute name="use-cache" default="false"> - <xs:simpleType> - <xs:restriction base="xs:token"> - <xs:enumeration value="true" /> - <xs:enumeration value="false" /> - </xs:restriction> - </xs:simpleType> - </xs:attribute> - <xs:attribute name="auto-field-map" default="true"> - <xs:simpleType> - <xs:restriction base="xs:token"> - <xs:enumeration value="true" /> - <xs:enumeration value="false" /> - </xs:restriction> - </xs:simpleType> - </xs:attribute> - </xs:complexType> - </xs:element> - - <xs:element name="order-by"> - <xs:complexType> - <xs:attribute type="xs:string" name="field-name" use="required" /> - </xs:complexType> - </xs:element> - <xs:element name="select-field"> - <xs:complexType> - <xs:attribute type="xs:string" name="field-name" use="required" /> - </xs:complexType> - </xs:element> - <xs:element name="limit-range"> - <xs:complexType> - <xs:attribute name="start" type="xs:string" use="required"> - <xs:annotation> - <xs:documentation>Should resolve into a non-negative integer.</xs:documentation> - </xs:annotation> - </xs:attribute> - <xs:attribute name="size" type="xs:string" use="required"> - <xs:annotation> - <xs:documentation>Should resolve into a non-negative integer.</xs:documentation> - </xs:annotation> - </xs:attribute> - </xs:complexType> - </xs:element> - <xs:element name="limit-view"> - <xs:complexType> - <xs:attribute name="view-index" type="xs:string" use="required"> - <xs:annotation> - <xs:documentation>Should resolve into a non-negative integer.</xs:documentation> - </xs:annotation> - </xs:attribute> - <xs:attribute name="view-size" type="xs:string" use="required"> - <xs:annotation> - <xs:documentation>Should resolve into a positive integer.</xs:documentation> - </xs:annotation> - </xs:attribute> - </xs:complexType> - </xs:element> - <xs:element name="use-iterator" /> - <xs:element name="field-map"> - <xs:complexType> - <xs:attribute type="xs:string" name="field-name" use="required" /> - <xs:attribute type="xs:string" name="from-field" /> - <xs:attribute type="xs:string" name="value" /> - </xs:complexType> - </xs:element> <xs:element name="out-field-map"> <xs:complexType> <xs:attribute type="xs:string" name="field-name" use="required" /> <xs:attribute type="xs:string" name="to-field-name" /> </xs:complexType> </xs:element> - - <xs:element name="condition-list"> - <xs:complexType> - <xs:choice maxOccurs="unbounded"> - <xs:element ref="condition-expr" /> - <xs:element ref="condition-list" /> - </xs:choice> - <xs:attribute name="combine" default="and"> - <xs:simpleType> - <xs:restriction base="xs:token"> - <xs:enumeration value="and" /> - <xs:enumeration value="or" /> - </xs:restriction> - </xs:simpleType> - </xs:attribute> - </xs:complexType> - </xs:element> - <xs:element name="having-condition-list"> - <xs:complexType> - <xs:choice maxOccurs="unbounded"> - <xs:element ref="condition-expr" /> - <xs:element ref="condition-list" /> - </xs:choice> - <xs:attribute name="combine" default="and"> - <xs:simpleType> - <xs:restriction base="xs:token"> - <xs:enumeration value="and" /> - <xs:enumeration value="or" /> - </xs:restriction> - </xs:simpleType> - </xs:attribute> - </xs:complexType> - </xs:element> - <xs:element name="condition-expr"> - <xs:complexType> - <xs:attribute name="field-name" type="xs:string" use="required" /> - <xs:attribute name="operator" default="equals"> - <xs:simpleType> - <xs:restriction base="xs:token"> - <xs:enumeration value="less" /> - <xs:enumeration value="greater" /> - <xs:enumeration value="less-equals" /> - <xs:enumeration value="greater-equals" /> - <xs:enumeration value="equals" /> - <xs:enumeration value="not-equals" /> - <xs:enumeration value="in" /> - <xs:enumeration value="between" /> - <xs:enumeration value="like" /> - </xs:restriction> - </xs:simpleType> - </xs:attribute> - <xs:attribute name="from-field" type="xs:string" /> - <xs:attribute name="value" type="xs:string" /> - <xs:attribute name="ignore-if-null" default="false"> - <xs:simpleType> - <xs:restriction base="xs:token"> - <xs:enumeration value="true" /> - <xs:enumeration value="false" /> - </xs:restriction> - </xs:simpleType> - </xs:attribute> - <xs:attribute name="ignore-if-empty" default="false"> - <xs:simpleType> - <xs:restriction base="xs:token"> - <xs:enumeration value="true" /> - <xs:enumeration value="false" /> - </xs:restriction> - </xs:simpleType> - </xs:attribute> - <xs:attribute name="ignore-case" default="false"> - <xs:simpleType> - <xs:restriction base="xs:token"> - <xs:enumeration value="true" /> - <xs:enumeration value="false" /> - </xs:restriction> - </xs:simpleType> - </xs:attribute> - <xs:attribute name="ignore" default="false"> - <xs:annotation> - <xs:documentation> - Ignore the condition if flag is true. - Defaults to false. - </xs:documentation> - </xs:annotation> - </xs:attribute> - </xs:complexType> - </xs:element> </xs:schema> \ No newline at end of file Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTree.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTree.java?rev=1649329&r1=1649328&r2=1649329&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTree.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTree.java Sun Jan 4 13:39:35 2015 @@ -224,19 +224,11 @@ public class ModelTree extends ModelWidg } /** - * Renders this tree to a String, i.e. in a text format, as defined with the - * TreeStringRenderer implementation. + * Renders this model. * - * @param buf the StringBuffer Object - * @param context Map containing the tree context; the following are - * reserved words in this context: parameters (Map), isError (Boolean), - * itemIndex (Integer, for lists only, otherwise null), bshInterpreter, - * treeName (String, optional alternate name for tree, defaults to the - * value of the name attribute) - * @param treeStringRenderer An implementation of the TreeStringRenderer - * interface that is responsible for the actual text generation for - * different tree elements; implementing your own makes it possible to - * use the same tree definitions for many types of tree UIs + * @param writer + * @param context + * @param treeStringRenderer */ @SuppressWarnings("rawtypes") public void renderTreeString(Appendable writer, Map<String, Object> context, TreeStringRenderer treeStringRenderer) @@ -302,11 +294,11 @@ public class ModelTree extends ModelWidg this.entityName = nodeElement.getAttribute("entity-name"); this.pkName = nodeElement.getAttribute("join-field-name"); ArrayList<ModelWidgetAction> actions = new ArrayList<ModelWidgetAction>(); + // FIXME: Validate child elements, should be only one of actions, entity-one, service, script. Element actionsElement = UtilXml.firstChildElement(nodeElement, "actions"); if (actionsElement != null) { actions.addAll(ModelTreeAction.readNodeActions(this, actionsElement)); } - // FIXME: Validate child elements, should be only one of entity-one, service, script. Element actionElement = UtilXml.firstChildElement(nodeElement, "entity-one"); if (actionElement != null) { actions.add(new ModelWidgetAction.EntityOne(this, actionElement)); @@ -667,6 +659,11 @@ public class ModelTree extends ModelWidg return showPeers; } + /** + * Models the <image> element. + * + * @see <code>widget-tree.xsd</code> + */ public static class Image { private final FlexibleStringExpander borderExdr; @@ -727,6 +724,11 @@ public class ModelTree extends ModelWidg } } + /** + * Models the <label> element. + * + * @see <code>widget-tree.xsd</code> + */ public static final class Label { private final FlexibleStringExpander idExdr; private final FlexibleStringExpander styleExdr; @@ -769,6 +771,11 @@ public class ModelTree extends ModelWidg } } + /** + * Models the <link> element. + * + * @see <code>widget-tree.xsd</code> + */ public static class Link { private final boolean encode; private final boolean fullPath; @@ -953,9 +960,10 @@ public class ModelTree extends ModelWidg this.rootNode = modelNode; this.nodeNameExdr = FlexibleStringExpander.getInstance(subNodeElement.getAttribute("node-name")); ArrayList<ModelWidgetAction> actions = new ArrayList<ModelWidgetAction>(); + // FIXME: Validate child elements, should be only one of actions, entity-and, entity-condition, service, script. Element actionsElement = UtilXml.firstChildElement(subNodeElement, "actions"); if (actionsElement != null) { - actions.addAll(ModelTreeAction.readNodeActions(this, actionsElement)); + actions.addAll(ModelTreeAction.readSubNodeActions(this, actionsElement)); } Element actionElement = UtilXml.firstChildElement(subNodeElement, "entity-and"); if (actionElement != null) { Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTreeAction.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTreeAction.java?rev=1649329&r1=1649328&r2=1649329&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTreeAction.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTreeAction.java Sun Jan 4 13:39:35 2015 @@ -45,7 +45,6 @@ import org.ofbiz.service.DispatchContext import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.ModelService; import org.ofbiz.widget.ModelActionVisitor; -import org.ofbiz.widget.ModelWidget; import org.ofbiz.widget.ModelWidgetAction; import org.ofbiz.widget.WidgetWorker; import org.ofbiz.widget.tree.ModelTree.ModelNode; @@ -74,12 +73,36 @@ public abstract class ModelTreeAction ex public static final String module = ModelTreeAction.class.getName(); - public static List<ModelWidgetAction> readNodeActions(ModelWidget modelNode, Element actionsElement) { + public static List<ModelWidgetAction> readNodeActions(ModelNode modelNode, Element actionsElement) { List<? extends Element> actionElementList = UtilXml.childElementList(actionsElement); List<ModelWidgetAction> actions = new ArrayList<ModelWidgetAction>(actionElementList.size()); for (Element actionElement : actionElementList) { - // TODO: Check for tree-specific actions - actions.add(ModelWidgetAction.newInstance(modelNode, actionElement)); + if ("service".equals(actionElement.getNodeName())) { + actions.add(new Service(modelNode, actionElement)); + } else if ("script".equals(actionElement.getNodeName())) { + actions.add(new Script(modelNode, actionElement)); + } else { + actions.add(ModelWidgetAction.newInstance(modelNode, actionElement)); + } + } + return actions; + } + + public static List<ModelWidgetAction> readSubNodeActions(ModelNode.ModelSubNode modelSubNode, Element actionsElement) { + List<? extends Element> actionElementList = UtilXml.childElementList(actionsElement); + List<ModelWidgetAction> actions = new ArrayList<ModelWidgetAction>(actionElementList.size()); + for (Element actionElement : actionElementList) { + if ("service".equals(actionElement.getNodeName())) { + actions.add(new Service(modelSubNode, actionElement)); + } else if ("entity-and".equals(actionElement.getNodeName())) { + actions.add(new EntityAnd(modelSubNode, actionElement)); + } else if ("entity-condition".equals(actionElement.getNodeName())) { + actions.add(new EntityCondition(modelSubNode, actionElement)); + } else if ("script".equals(actionElement.getNodeName())) { + actions.add(new Script(modelSubNode, actionElement)); + } else { + actions.add(ModelWidgetAction.newInstance(modelSubNode, actionElement)); + } } return actions; } |
Free forum by Nabble | Edit this page |