<?xml version="1.0"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<!--
  Model for the Swan form-binding editor.

  @version $Id: binding_model.xml 449149 2006-09-23 03:58:05Z crossley $
-->

<fd:form
  xmlns:fd="http://apache.org/cocoon/forms/1.0#definition"
  xmlns:i18n="http://apache.org/cocoon/i18n/2.1">

  <fd:widgets>

    <fd:messages id="messages"/>

    <fd:new id="items-class"/>

    <fd:class id="items-class">
      <fd:widgets>
        <fd:repeater id="items" initial-size="0">
          <fd:label>Items</fd:label>
          <fd:widgets>
            <fd:new id="item-row-class"/>
          </fd:widgets>
        </fd:repeater>
        <fd:repeater-action id="addItem" action-command="add-row" repeater="items">
          <fd:label>Add Child</fd:label>
          <fd:hint>Add child</fd:hint>
          <fd:on-action>
            <javascript>
              var repeater = event.getSourceWidget().lookupWidget("../items");
              var view = repeater.getRow(repeater.getSize() - 1).getChild("view-selector");
              view.value = "edit";
            </javascript>
          </fd:on-action>
        </fd:repeater-action>
      </fd:widgets>
    </fd:class>

    <fd:class id="view-selector-class">
      <fd:widgets>
        <fd:field id="view-selector" state="invisible">
          <fd:label>View</fd:label>
          <fd:datatype base="string"/>
          <fd:selection-list>
            <fd:item value="fold"><fd:label>Fold</fd:label></fd:item>
            <fd:item value="view"><fd:label>View</fd:label></fd:item>
            <fd:item value="edit"><fd:label>Edit</fd:label></fd:item>
          </fd:selection-list>
          <fd:on-value-changed>
            <javascript>
              var widget = event.getSourceWidget();
              var union = widget.lookupWidget("../union");
              var type = widget.lookupWidget("../type-selector");
              var stuff = union.lookupWidget(union.getValue() + "/stuff");
              if("edit".equals(widget.getValue())) {
                union.state = WidgetState.ACTIVE;
                if(stuff != null) {
                  stuff.state = WidgetState.ACTIVE;
                }
                type.state = WidgetState.ACTIVE;
              } else if("view".equals(widget.getValue())){
                union.state = WidgetState.ACTIVE;
                if(stuff != null) {
                  stuff.state = WidgetState.DISABLED;
                }
                type.state = WidgetState.DISABLED;
              } else { // "fold"
                union.state = WidgetState.DISABLED;
                type.state = WidgetState.DISABLED;
              }
            </javascript>
          </fd:on-value-changed>
        </fd:field>
        <fd:action id="fold-view" action-command="fold-view">
          <fd:label>F</fd:label>
          <fd:hint>Fold</fd:hint>
          <fd:on-action>
            <javascript>
              var view = event.getSourceWidget().lookupWidget("../view-selector");
              view.value = "fold";
            </javascript>
          </fd:on-action>
        </fd:action>
        <fd:action id="view-view" action-command="view-view">
          <fd:label>V</fd:label>
          <fd:hint>View</fd:hint>
          <fd:on-action>
            <javascript>
              var view = event.getSourceWidget().lookupWidget("../view-selector");
              view.value = "view";
            </javascript>
          </fd:on-action>
        </fd:action>
        <fd:action id="edit-view" action-command="edit-view">
          <fd:label>E</fd:label>
          <fd:hint>Edit</fd:hint>
          <fd:on-action>
            <javascript>
              var view = event.getSourceWidget().lookupWidget("../view-selector");
              view.value = "edit";
            </javascript>
          </fd:on-action>
        </fd:action>
      </fd:widgets>
    </fd:class>

    <fd:class id="type-selector-class">
      <fd:widgets>
        <fd:field id="type-selector">
          <fd:label>Type</fd:label>
          <fd:datatype base="string"/>
          <fd:selection-list>
            <fd:item value=""><fd:label>Nothing</fd:label></fd:item>
            <fd:item value="action"><fd:label>Action</fd:label></fd:item>
            <fd:item value="aggregatefield"><fd:label>AggregateField</fd:label></fd:item>
            <fd:item value="booleanfield"><fd:label>BooleanField</fd:label></fd:item>
            <fd:item value="class"><fd:label>Class</fd:label></fd:item>
            <fd:item value="field"><fd:label>Field</fd:label></fd:item>
            <fd:item value="group"><fd:label>Group</fd:label></fd:item>
            <fd:item value="new"><fd:label>New</fd:label></fd:item>
            <fd:item value="output"><fd:label>Output</fd:label></fd:item>
            <fd:item value="repeater"><fd:label>Repeater</fd:label></fd:item>
            <fd:item value="temp-repeater"><fd:label>Repeater</fd:label></fd:item>
            <fd:item value="row-action"><fd:label>RowAction</fd:label></fd:item>
            <fd:item value="struct"><fd:label>Struct</fd:label></fd:item>
            <fd:item value="submit"><fd:label>Submit</fd:label></fd:item>
            <fd:item value="union"><fd:label>Union</fd:label></fd:item>
            <fd:item value="value"><fd:label>Value</fd:label></fd:item>
          </fd:selection-list>
        </fd:field>
      </fd:widgets>
    </fd:class>

    <fd:class id="item-row-class">
      <fd:widgets>

        <fd:row-action id="up" action-command="move-up">
          <fd:label>^</fd:label>
          <fd:hint>Move up</fd:hint>
        </fd:row-action>

        <fd:row-action id="down" action-command="move-down">
          <fd:label>v</fd:label>
          <fd:hint>Move down</fd:hint>
        </fd:row-action>

        <fd:row-action id="add" action-command="add-after">
          <fd:label>+</fd:label>
          <fd:hint>Add after</fd:hint>
          <fd:on-action>
            <javascript>
              var cur_row = Repeater.getParentRow(event.getSourceWidget());
              var repeater = cur_row.getParent();
              var new_row = repeater.getChild(repeater.indexOf(cur_row)+1);
              var view = new_row.getChild("view-selector");
              view.value = "edit";
            </javascript>
          </fd:on-action>
        </fd:row-action>

        <fd:row-action id="delete" action-command="delete">
          <fd:label>X</fd:label>
          <fd:hint>Delete</fd:hint>
        </fd:row-action>

        <fd:new id="view-selector-class"/>

        <fd:new id="type-selector-class"/>

        <fd:union id="union" default="" case="type-selector">
          <fd:label>Type</fd:label>
          <fd:widgets>

            <fd:group id="class">
              <fd:label>Class</fd:label>
              <fd:widgets>
                <fd:group id="stuff">
                  <fd:widgets>
                    <fd:new id="id-class"/>
                  </fd:widgets>
                </fd:group>
                <fd:new id="items-class"/>
              </fd:widgets>
            </fd:group>

            <fd:group id="javascript">
              <fd:label>Javascript</fd:label>
              <fd:widgets>
                <fd:group id="stuff">
                  <fd:widgets>
                    <fd:new id="text-class"/>
                    <fd:new id="path-class"/>
                  </fd:widgets>
                </fd:group>
              </fd:widgets>
            </fd:group>

            <fd:group id="new">
              <fd:label>New</fd:label>
              <fd:widgets>
                <fd:group id="stuff">
                  <fd:widgets>
                    <fd:new id="id-class"/>
                  </fd:widgets>
                </fd:group>
              </fd:widgets>
            </fd:group>

            <fd:group id="union">
              <fd:label>Union</fd:label>
              <fd:widgets>
                <fd:group id="stuff">
                  <fd:widgets>
                    <fd:new id="id-class"/>
                    <fd:new id="path-class"/>
                  </fd:widgets>
                </fd:group>
                <fd:new id="items-class"/>
              </fd:widgets>
            </fd:group>

            <fd:group id="value">
              <fd:label>Value</fd:label>
              <fd:widgets>
                <fd:group id="stuff">
                  <fd:widgets>
                    <fd:new id="id-class"/>
                    <fd:new id="path-class"/>
                  </fd:widgets>
                </fd:group>
              </fd:widgets>
            </fd:group>


            <fd:group id="action">
              <fd:label>Action</fd:label>
              <fd:widgets>
                <fd:group id="stuff">
                  <fd:widgets>
                    <fd:new id="id-class"/>
                    <fd:new id="label-class"/>
                  </fd:widgets>
                </fd:group>
              </fd:widgets>
            </fd:group>

            <fd:group id="aggregatefield">
              <fd:label>AggregateField</fd:label>
              <fd:widgets>
                <fd:group id="stuff">
                  <fd:widgets>
                    <fd:new id="id-class"/>
                    <fd:new id="label-class"/>
                    <fd:new id="required-class"/>
                  </fd:widgets>
                </fd:group>
                <fd:new id="items-class"/>
              </fd:widgets>
            </fd:group>

            <fd:group id="booleanfield">
              <fd:label>BooleanField</fd:label>
              <fd:widgets>
                <fd:group id="stuff">
                  <fd:widgets>
                    <fd:new id="id-class"/>
                    <fd:new id="label-class"/>
                  </fd:widgets>
                </fd:group>
              </fd:widgets>
            </fd:group>

            <fd:group id="field">
              <fd:label>Field</fd:label>
              <fd:widgets>
                <fd:group id="stuff">
                  <fd:widgets>
                    <fd:new id="id-class"/>
                    <fd:new id="label-class"/>
                    <fd:new id="required-class"/>
                  </fd:widgets>
                </fd:group>
              </fd:widgets>
            </fd:group>

            <fd:group id="group">
              <fd:label>Group</fd:label>
              <fd:widgets>
                <fd:group id="stuff">
                  <fd:widgets>
                    <fd:new id="id-class"/>
                    <fd:new id="label-class"/>
                  </fd:widgets>
                </fd:group>
                <fd:new id="items-class"/>
              </fd:widgets>
            </fd:group>

            <fd:group id="output">
              <fd:label>Output</fd:label>
              <fd:widgets>
                <fd:group id="stuff">
                  <fd:widgets>
                    <fd:new id="id-class"/>
                    <fd:new id="label-class"/>
                  </fd:widgets>
                </fd:group>
              </fd:widgets>
            </fd:group>

            <fd:group id="repeater">
              <fd:label>Repeater</fd:label>
              <fd:widgets>
                <fd:group id="stuff">
                  <fd:widgets>
                    <fd:new id="id-class"/>
                    <fd:new id="label-class"/>
                    <fd:new id="initial-size-class"/>
                  </fd:widgets>
                </fd:group>
                <fd:new id="items-class"/>
              </fd:widgets>
            </fd:group>

            <fd:group id="temp-repeater">
              <fd:label>Repeater</fd:label>
              <fd:widgets>
                <fd:group id="stuff">
                  <fd:widgets>
                    <fd:new id="id-class"/>
                    <fd:new id="parent-path-class"/>
                  </fd:widgets>
                </fd:group>
                <fd:new id="items-class"/>
              </fd:widgets>
            </fd:group>

            <fd:group id="row-action">
                <fd:label>RowAction</fd:label>
              <fd:widgets>
                <fd:group id="stuff">
                  <fd:widgets>
                    <fd:new id="id-class"/>
                    <fd:new id="label-class"/>
                  </fd:widgets>
                </fd:group>
              </fd:widgets>
            </fd:group>

            <fd:group id="struct">
              <fd:label>Struct</fd:label>
              <fd:widgets>
                <fd:group id="stuff">
                  <fd:widgets>
                    <fd:new id="id-class"/>
                    <fd:new id="label-class"/>
                  </fd:widgets>
                </fd:group>
                <fd:new id="items-class"/>
              </fd:widgets>
            </fd:group>

            <fd:group id="submit">
              <fd:label>Submit</fd:label>
              <fd:widgets>
                <fd:group id="stuff">
                  <fd:widgets>
                    <fd:new id="id-class"/>
                    <fd:new id="label-class"/>
                  </fd:widgets>
                </fd:group>
              </fd:widgets>
            </fd:group>

          </fd:widgets>

        </fd:union>
      </fd:widgets>
    </fd:class>
 
    <fd:class id="id-class">
      <fd:widgets>
        <fd:field id="id" required="true">
          <fd:label>Id</fd:label>
          <fd:datatype base="string"/>
        </fd:field>
      </fd:widgets>
    </fd:class>

    <fd:class id="text-class">
      <fd:widgets>
        <fd:field id="text">
          <fd:label>Text</fd:label>
          <fd:datatype base="string"/>
        </fd:field>
      </fd:widgets>
    </fd:class>

    <fd:class id="parent-path-class">
      <fd:widgets>
        <fd:field id="parent-path" required="true">
          <fd:label>Parent Path</fd:label>
          <fd:datatype base="string"/>
        </fd:field>
      </fd:widgets>
    </fd:class>

    <fd:class id="path-class">
      <fd:widgets>
        <fd:field id="path" required="true">
          <fd:label>Path</fd:label>
          <fd:datatype base="string"/>
        </fd:field>
      </fd:widgets>
    </fd:class>


    <fd:class id="label-class">
      <fd:widgets>
        <fd:field id="label">
          <fd:label>Label</fd:label>
          <fd:datatype base="string"/>
        </fd:field>
      </fd:widgets>
    </fd:class>

    <fd:class id="required-class">
      <fd:widgets>
        <fd:booleanfield id="required">
          <fd:label>Required</fd:label>
        </fd:booleanfield>
      </fd:widgets>
    </fd:class>

    <fd:class id="initial-size-class">
      <fd:widgets>
        <fd:field id="initial-size">
          <fd:label>Initial Size</fd:label>
          <fd:datatype base="long"/>
        </fd:field>
      </fd:widgets>
    </fd:class>

  </fd:widgets>

</fd:form>
