<?xml version="1.0" encoding="UTF-8"?>
<otrunk id="33754150-b594-11d9-9669-0800200c9a66" >
  <imports>
    <import class="org.concord.otrunk.OTSystem"/>
    <import class="org.concord.otrunk.view.OTFolderObject"/>
    <import class="org.concord.otrunk.view.OTViewEntry"/>
    <import class="org.concord.otrunk.view.OTViewBundle"/>
    <import class="org.concord.otrunk.view.prototype.OTPrototypeViewEntry"/>
    <import class="org.concord.otrunk.view.prototype.OTPrototypeEventController"/>
    <import class="org.concord.otrunk.view.prototype.OTPrototypeMapEntry"/>
    <import class="org.concord.otrunk.view.prototype.OTPropertyReference"/>
    <import class="org.concord.otrunk.ui.OTButton"/>
    <import class="org.concord.framework.otrunk.view.OTFrame"/>
    <import class="org.concord.otrunk.ui.OTText"/>
    <import class="org.concord.otrunk.ui.OTListBox"/>
    <import class="org.concord.otrunk.ui.OTChoice"/>
    <import class="org.concord.otrunk.view.document.OTCompoundDoc"/>
    <import class="org.concord.otrunk.velocity.OTVelocityXHTMLViewEntry"/>
    <import class="org.concord.otrunk.velocity.OTVelocityTemplate"/>

    <import class="org.concord.otrunk.template.OTTemplateEngineBundle"/>
    <import class="org.concord.otrunk.template.OTTemplateEngineEntry"/>
    <import class="org.concord.otrunk.template.OTTemplateObject"/>
    <import class="org.concord.otrunk.template.OTTemplateVariable"/>
    
    <import class="org.concord.otrunk.script.js.OTJavascript" />
    <import class="org.concord.otrunk.script.OTScriptEngineBundle" />
    <import class="org.concord.otrunk.script.OTScriptEngineEntry" />
    <import class="org.concord.otrunk.script.view.OTPrototypeScriptController" />
  </imports>
  <objects>
    <OTSystem>
      <bundles>
        <OTTemplateEngineBundle>
          <engines>
            <OTTemplateEngineEntry objectClass="org.concord.otrunk.velocity.OTVelocityTemplate"
            	engineClass="org.concord.otrunk.velocity.OTVelocityTemplateEngine"/>            
          </engines>
        </OTTemplateEngineBundle>
        <OTScriptEngineBundle>
          <engines>
            <OTScriptEngineEntry
              objectClass="org.concord.otrunk.script.js.OTJavascript"
              engineClass="org.concord.otrunk.script.js.OTJavascriptEngine" />
          </engines>
        </OTScriptEngineBundle>
        <OTViewBundle>
          <viewEntries>
            <OTViewEntry local_id="text_edit"
              objectClass="org.concord.otrunk.ui.OTText" 
              viewClass="org.concord.otrunk.ui.swing.OTTextEditView"/>
            <OTViewEntry local_id="list_edit"
              objectClass="org.concord.otrunk.ui.OTListBox" 
              viewClass="org.concord.otrunk.ui.swing.OTListBoxView"/>
            <OTViewEntry local_id="choice_edit"
              objectClass="org.concord.otrunk.ui.OTChoice"
              viewClass="org.concord.otrunk.ui.swing.OTChoiceComboBoxView"/>
            <OTViewEntry
              objectClass="org.concord.otrunk.ui.OTButton"
              viewClass="org.concord.otrunk.ui.swing.OTButtonView"/>
            
            <OTPrototypeViewEntry local_id="primitive_editor"
            	objectClass="org.concord.otrunk.view.prototype.OTPropertyReference"
            	viewClass="org.concord.otrunk.view.prototype.OTPrototypePropertyView"
            	viewEntry="${text_edit}">
            	<prototype>
            		<OTText text="default" />
            	</prototype>
            	<controller>
            		<OTPrototypeEventController>
            			<mapping>
            			   <OTPrototypeMapEntry prototypeProperty="text"/>
            			</mapping>
            		</OTPrototypeEventController>
            	</controller>
            </OTPrototypeViewEntry>

            <OTPrototypeViewEntry local_id="boolean_editor"
            	objectClass="org.concord.otrunk.view.prototype.OTPropertyReference"
            	viewClass="org.concord.otrunk.view.prototype.OTPrototypePropertyView"
            	viewEntry="${choice_edit}">
            	<prototype>
            	    <OTChoice>
            	      <choices>
	            		<OTText name="true" />
    	        		<OTText name="false" />
            	      </choices>
            	    </OTChoice>
            	</prototype>
            	<!--  FIXME we need to hook up a script controller here to match the choice with the model -->
            </OTPrototypeViewEntry>

            <OTPrototypeViewEntry local_id="list_editor"
            	objectClass="org.concord.otrunk.view.prototype.OTPropertyReference"
            	viewClass="org.concord.otrunk.view.prototype.OTPrototypePropertyView"
            	viewEntry="${list_edit}">
            	<prototype>
            		<OTListBox />
            	</prototype>
            	<controller>
            		<OTPrototypeEventController>
            			<mapping>
            			   <OTPrototypeMapEntry prototypeProperty="items"/>
            			</mapping>
            		</OTPrototypeEventController>
            	</controller>
            </OTPrototypeViewEntry>

            <OTViewEntry local_id="document_view"
              objectClass="org.concord.otrunk.view.document.OTDocument" 
              viewClass="org.concord.otrunk.view.document.OTDocumentView"/>                         
			<OTViewEntry local_id="template_object_view"
				objectClass="org.concord.otrunk.template.OTTemplateObject"
				viewClass="org.concord.otrunk.template.OTTemplateObjectView"/>

            <OTPrototypeViewEntry local_id="object_editor"
            	objectClass="org.concord.framework.otrunk.OTObject"
            	viewClass="org.concord.otrunk.view.prototype.OTPrototypeView"
            	viewEntry="${template_object_view}">
            	<prototype>
            		<OTTemplateObject name="Template Document"
            			template="${object_editing_template}">
            			<variables>
            				<OTTemplateVariable name="model"/>
            				<OTTemplateVariable name="properties">
            					<reference>
            					    <!--  this object will get filled in by the script when 
            					    it initializes the prototype copy -->
            						<OTFolderObject/>
            					</reference>
            				</OTTemplateVariable>
            			</variables>
            		</OTTemplateObject>
            	</prototype>
            	<controller>
            		<OTPrototypeScriptController>
            			<script>
            				<OTJavascript src="object-editor-6.js" />
            			</script>
            		</OTPrototypeScriptController>
            	</controller>
            </OTPrototypeViewEntry>

          </viewEntries>
        </OTViewBundle>
      </bundles>
      <library>
      	<OTVelocityTemplate local_id="object_editing_template">
      		<template>
      			Name: $model.name
      			<table>
      				#foreach( $property in $properties.children.vector)
      				<tr>
      					<td>$property.property :</td>
      					<td width="300">
      					  #set( $classProperty = $model.otClass().getProperty($property.property) )
      					
      					  #if( $classProperty.primitive )
      						#if( $classProperty.type.primitiveName == "boolean" )
        						<object refid="$property.globalId" viewid="${boolean_editor}"/>
      						#else
        						<object refid="$property.globalId" viewid="${primitive_editor}"/>
      						#end
      					  #elseif ( $classProperty.list )
      						<object refid="$property.globalId" viewid="${list_editor}"/>      					    
      					  #end
      					</td>
      				</tr>
      				#end
      			</table>
      		</template>
      	</OTVelocityTemplate>
      </library>
      <root>
        <OTCompoundDoc name="root">
          <bodyText>
            This is an example of using a prototype view, where the prototype is a template object.
 With OTPropertyReferences pointing to the properties being displayed.  These PropertyReferences are not
 bound to a particular instance in the prototype, but the prototype view's controller binds them when the view
 is first requested.  This should make the view work for any instance of the particular object type (OTClass).
   		  </bodyText>   		  
   		  <children>
			<OTCompoundDoc name="Button Editing Doc">
			  <bodyText>
			     Document for pointing to the editing view of the button object.<br/>
			     <object refid="${button}" viewid="${object_editor}"/>
			  </bodyText>
			</OTCompoundDoc>   		  
   		    <OTButton local_id="button" name="button name" text="Click Me"/>
   		  </children>
   	    </OTCompoundDoc>
      </root>
    </OTSystem>
  </objects>
</otrunk>
