XWorker
简介
特点
下载

 面向事物
面向事物的概念
面向事物和面向对象对比
面向事物的哲学

 示例
事物的创建过程 
SWT
WEB
代码生成
YahooYUI

 关于
协议
联系我们

 

 事物的创建过程演示

     面向事物的特点是任何事物都是通过元事物直接或者间接的创建出来的,所以本示例将展示如何从元事物一直到创建出一个SWT窗体的过程。

    通过本演示可以了解创建事物的一般过程,也能够了解到如何从无到有的创建一个应用。

 创建子系统中第一个事物core:things:lang.MetaDescriptor1

    MetaDescriptor1是使用元系统Java代码定义的MetaThing来创建的。

    以下会连续创建MetaDescriptor2和MetaDescriptor3,MetaDescriptor1、MetaDescriptor2、MetaDescriptor3和元系统中的元事物作用一样,只是元系统中的元事物过于简单,不太符合实际应用的需求,因此连续创建MetaDescriptor1、MetaDescriptor2、MetaDescriptor3,其中MetaDescriptor3已经足够复杂,能够适合大部分应用的需求。

    MetaDescriptor1用XML表示大致如下:

<thing id="MetaDescriptor1" name="thing" label="MetaDescriptor1" descriptors="MetaThing">
    <attribute name="name"/>
    <attribute name="label"/>
    <attribute name="descriptors"/>
    <attribute name="extends"/>
    <thing name="attribute">
        <attribute name="name"/>
        <attribute name="label"/>
        <attribute name="type"/>
        <attribute name="size"/>
        <attribute name="inputtype"/>
        <attribute name="description"/>
        <attribute name="colspan"/>
        <attribute name="rowspan"/>
        <attribute name="inputattrs"/>
        <attribute name="default"/>
        <thing>
            <attribute name="name"/>
            <attribute name="label"/>
            <attribute name="value"/>
        </thing>
    </thing>
    <thing name="thing" extends="_root"/>
</thing>

 创建子系统第二个事物core:things:lang.MetaDescriptor2

    MetaDescriptor2是使用MetaDescriptor1创建的,其中通过MetaDescriptor1创建的动态输入表单大致如下:

事物编辑表单

属性编辑表单

    MetaDescriptor2使用XML表示大致如下:

<thing name="thing" label="MetaDescriptor2" descriptors="core:things:lang.MetaDescriptor1">
    <attribute label="名称" description="数据对象的名称,如果数据对象没有id属性,那么名称会做为id,如果有相同的名称时,应手工设定不同的id属性。" name="name"/>
    <attribute label="标签" description="数据对象的标签,标签是数据对象的一个简短描述字符串,可以用于多国语言的用途。" name="label"/>
    <attribute colspan="2" label="描述者" inputtype="dataSelector" size="60" description="数据对象的主结构描述对象,在保存数据对象时以主结构数据对象为依据。&lt;br/&gt;&lt;/br/&gt;由于一个数据对象可以使用不同的结构来读取,这样读取出来的内容也不同,但使用其他结构读取的数据对象也可以保存,这时为了避免属性的丢失,使用主结构数据对象为依据来保存。" name="descriptors"/>
    <attribute colspan="2" label="继承" inputtype="dataSelector" size="60" description="数据对象从其他数据对象继承,如果有多个继承的数据对象用&apos;,&apos;号隔开。" name="extends"/>
    <attribute label="允许多个" inputtype="truefalse" default="true" description="数据对象在一个节点下的个数可以是多个,如果是false,那么在一个节点下该对象类型的数据对象只能有0或1个。" name="mang">
        <value name="false" value="false" label="false"/>
        <value name="true" value="true" label="true"/>
    </attribute>
    <attribute label="编辑列数" size="5" default="2" description="在编辑时页面布局的分列控制。" name="editCols"/>
    <attribute colspan="2" inputattrs="Width=&apos;480&apos;;Height=&apos;200&apos;;ToolbarSet=&quot;Default&quot;" label="描述" type="text" inputtype="html" description="数据对象的描述。" name="description"/>
    <thing name="attribute" label="属性" descriptors="core:things:lang.MetaDescriptor1:/@thing">
        <attribute label="名称" description="字段的名称。" name="name"/>
        <attribute label="标签" description="字段的标签。" name="label"/>
        <attribute description="字段的类型,主要是用于正确保存为XML时数据属性的保存方法。&lt;br/&gt;&lt;br/&gt;字符串:xx=&quot;xxx&quot;&lt;br/&gt;文本:&amp;lt;propertyName&amp;gt;xxx&amp;lt;/propertyName&amp;gt;&lt;br/&gt;CDATA:&amp;lt;propertyName&amp;gt;&amp;lt;![CDATA[xxxx]]&amp;gt;&amp;lt;/propertyName&amp;gt;" name="type" label="类型" inputtype="select">
            <value name="string" value="string" label="字符串"/>
        </attribute>
        <attribute name="default" label="默认值"/>
        <attribute label="长度" name="size"/>
        <attribute description="编辑时的属性数据的录入方式。" name="inputtype" label="输入方式" inputtype="select">
            <value name="text" value="text" label="输入框"/>
            <value name="textarea" value="textarea" label="文本输入框"/>
            <value name="select" value="select" label="下拉选择框"/>
            <value name="truefalse" value="truefalse" label="TrueFalse"/>
            <value name="checkBox" value="checkBox" label="复选框"/>
            <value name="html" value="html" label="html文档"/>
            <value name="datepick" value="datepick" label="日期选择器"/>
            <value name="dataSelector" value="dataSelector" label="数据选择器"/>
            <value name="colorpicker" value="colorpicker" label="颜色选择器"/>
            <value name="inputSelect" value="inputSelect" label="输入选择"/>
            <value name="hidden" value="hidden" label="隐藏输入"/>
        </attribute>
        <attribute label="跨列" size="5" description="属性编辑控件在编辑页面布局时所占的列数。" name="colspan"/>
        <attribute label="跨行" size="5" description="属性编辑控件在编辑页面布局中所占的行数。" name="rowspan"/>
        <attribute name="group" label="分组"/>
        <attribute name="groupIndex" label="分组序号"/>
        <attribute colspan="2" inputattrs="Width=&apos;480&apos;;Height=&apos;200&apos;;ToolbarSet=&quot;Default&quot;" label="描述" rowspan="1" type="cdata" inputtype="html" description="对属性的描述。在编辑用这个结构描述的对象时,会以tol tip的方式显示在编辑界面上。" name="description"/>
        <attribute colspan="2" label="输入扩展属性" inputtype="text" size="60" description="可以输入一些输入控件的属性来增加控件的属性,如输入方式为文本区时可以增加扩充属性:rows=&quot;3&quot; cols=&quot;80&quot;。" name="inputattrs"/>
        <thing name="value" label="可选值" descriptors="core:things:lang.MetaDescriptor1:/@thing">
            <attribute name="name" label="名称"/>
            <attribute name="label" label="标签"/>
            <attribute name="value" label="值"/>
        </thing>
    </thing>
    <thing extends="_root" name="thing" label="子事物" descriptors="core:things:lang.MetaDescriptor1:/@thing"/>
</thing>

 创建子系统第三个事物core:things:lang.MetaDescriptor3

    MetaDescriptor3是使用MetaDescriptor2创建的,其中通过MetaDescriptor2创建的动态输入表单大致如下:

 

事物编辑表单

属性编辑表单

    MetaDescriptor3用XML表示大致如下:

<thing description="&lt;p&gt;MetaDescriptor3的描述者是MetaDescriptor2,是对元事物的一个比较实用的扩展。&lt;/p&gt;&lt;p&gt;关于元事物可以参看&lt;a href=&quot;do?sc=ui:worldExplorer:swt.http.ThingDoc:/@desc&amp;amp;thing=core:things:lang.MetaThing&quot;&gt;MetaThing&lt;/a&gt;。&lt;/p&gt;" name="thing" label="MetaDescriptor3" descriptors="core:things:lang.MetaDescriptor2">
    <attribute label="名称" description="&lt;p&gt;事物的名称。&lt;/p&gt;" name="name"/>
    <attribute label="标签" description="&lt;p&gt;事物的标签属性,当显示事物或事物名时通常用标签属性来代替。&lt;/p&gt;" name="label"/>
    <attribute colspan="2" label="描述者" inputtype="dataSelector" size="60" description="&lt;p&gt;事物的描述者列表,如果有多个用逗号&amp;quot;,&amp;quot;隔开。&lt;/p&gt;" name="descriptors"/>
    <attribute colspan="2" label="继承" inputtype="dataSelector" size="60" description="&lt;p&gt;事物的继承者,如果有多个用逗号&amp;quot;,&amp;quot;隔开。&lt;/p&gt;" name="extends"/>
    <attribute default="true" description="&lt;p&gt;该事物在子事物里出现时允许出现的次数,最多1次或任意次。&lt;br /&gt;" name="many" label="允许多个" inputtype="truefalse"/>
    <attribute label="编辑列数" size="5" groupIndex="1" default="2" description="在编辑时输入表单布局的分列数,输入表单使用类似TableLayout的布局。&lt;br /&gt;" name="editCols"/>
    <attribute label="初始化" inputtype="truefalse" default="false" description="如果此事物在装载时需要自动运行init行为。" name="initialization"/>
    <attribute label="分组" groupIndex="1" description="当一个事物有很多个子事物时,那么在事物编辑器里选择需要添加那一个子事物会比较麻烦,因此定义了分组属性,这样在添加子事物的界面里子事物可以按照此字段来分组。&lt;br /&gt;。在添加子事物的界面里多级是按照树形结构显示。" name="group"/>
    <attribute colspan="2" inputattrs="Width=&apos;480&apos;;Height=&apos;200&apos;;ToolbarSet=&quot;SwtEdit&quot;" label="描述" inputtype="html" description="&lt;p&gt;事物的一段描述文字。&lt;br /&gt;" name="description"/>
    <thing description="属性事物,元事物中的属性事物的扩展。" name="attribute" label="属性" descriptors="core:things:lang.MetaDescriptor2:/@thing">
        <attribute description="属性的名称。" name="name" label="名称"/>
        <attribute description="属性的标签。" name="label" label="标签"/>
        <attribute colspan="2" description="继承属性,如果有多个继承用,号隔开。" name="extends" label="继承" size="60" inputtype="dataSelector"/>
        <attribute description="&lt;p&gt;属性的类型。&lt;br /&gt;" name="type" label="类型" inputtype="select">
            <value name="string" value="string" label="string"/>
            <value name="bigDecimal" value="bigDecimal" label="bigDecimal"/>
            <value name="bigInteger" value="bigInteger" label="bigInteger"/>
            <value name="boolean" value="boolean" label="boolean"/>
            <value name="byte" value="byte" label="byte"/>
            <value name="bytes" value="bytes" label="byte[]"/>
            <value name="char" value="char" label="char"/>
            <value name="date" value="date" label="date"/>
            <value name="double" value="double" label="double"/>
            <value name="float" value="float" label="float"/>
            <value name="int" value="int" label="int"/>
            <value name="long" value="long" label="long"/>
            <value name="short" value="short" label="short"/>
            <value name="object" value="object" label="object"/>
        </attribute>
        <attribute description="属性的编辑控件定义。" name="inputtype" label="输入方式" inputtype="select">
            <value name="text" value="text" label="文本框"/>
            <value name="textarea" value="textarea" label="文本区"/>
            <value name="select" value="select" label="下拉选择框"/>
            <value name="truefalse" value="truefalse" label="真假"/>
            <value name="checkBox" value="checkBox" label="复选框"/>
            <value name="radio" value="radio" label="单选按钮"/>
            <value name="html" value="html" label="HTML文档输入"/>
            <value name="datePick" value="datePick" label="日期选择器"/>
            <value name="dataSelector" value="dataSelector" label="数据选择器"/>
            <value name="pathSelector" value="pathSelector" label="路径选择器"/>
            <value name="codeEditor" value="codeEditor" label="代码编辑器"/>
            <value name="fontSelect" value="fontSelect" label="字体选择器"/>
            <value name="colorpicker" value="colorpicker" label="颜色选择器"/>
            <value name="inputSelect" value="inputSelect" label="输入选择"/>
            <value name="hidden" value="hidden" label="隐藏输入"/>
            <value name="password" value="password" label="密码框"/>
        </attribute>
        <attribute description="属性的默认值。" name="default" label="默认值"/>
        <attribute default="true" description="如果此属性为不可选,那么表示必须输入。" name="optional" label="可选" inputtype="truefalse"/>
        <attribute description="属性的长度没有限制,这里在编辑属性时用来控制编辑控件的长度。" name="size" label="长度" size="5"/>
        <attribute label="模式" description="属性的格式,如yyyy-MM-dd。" name="pattern"/>
        <attribute label="跨行" size="5" groupIndex="1" description="&lt;p&gt;属性编辑控件在编辑页面布局中所占的行数。&lt;/p&gt;" name="rowspan"/>
        <attribute label="跨列" size="5" groupIndex="1" description="属性编辑控件在编辑页面布局时所占的列数。" name="colspan"/>
        <attribute label="分组" groupIndex="1" description="&lt;p&gt;属性在编辑表单里的分组。&lt;/p&gt;" name="group"/>
        <attribute label="分组索引" groupIndex="1" description="&lt;p&gt;决定这个分组的排序先后的索引。&lt;/p&gt;" name="groupIndex"/>
        <attribute colspan="2" label="输入扩展属性" inputtype="text" size="60" groupIndex="1" description="" name="inputattrs"/>
        <attribute colspan="2" label="保留" size="60" description="&lt;p&gt;保留字段。&lt;/p&gt;" name="reserve"/>
        <attribute colspan="2" inputattrs="Width=&apos;470&apos;;Height=&apos;150&apos;;ToolbarSet=&quot;SwtEdit&quot;" label="描述" rowspan="1" inputtype="html" description="属性的一段文字描述。在编辑用这个结构描述的事物时,当鼠标移动在事物的属性标签上时会以tol tip的方式显示。" name="description"/>
        <thing description="当属性的输入方式是下拉选择框、复选框或者输入选择时,可选值提供候选值。" name="value" label="可选值" descriptors="core:things:lang.MetaDescriptor2:/@thing">
            <attribute name="name" label="名称"/>
            <attribute name="label" label="标签"/>
            <attribute name="value" label="值"/>
        </thing>
        <thing name="SwtObject" label="SWT编辑设置" descriptors="core:things:lang.MetaDescriptor2:/@thing">
            <thing extends="ui:local:swt.Commons" description="" name="inputExtend" label="输入扩充" descriptors="core:things:lang.MetaDescriptor2:/@thing"/>
            <thing extends="ui:local:swt.Widgets" description="&lt;p&gt;自定义的属性编辑器。" name="inputEditor" label="输入编辑器" descriptors="core:things:lang.MetaDescriptor2:/@thing">
                <actions name="actions">
                    <GroovyAction name="create" code=""/>
                </actions>
            </thing>
            <thing extends="ui:local:swt.model.Model" description="&lt;p&gt;属性编辑器的Model,如果定义此节点事物,那么会替代通过其他任何方式创建的属性Model。&lt;/p&gt;" name="inputModel" label="输入模型" descriptors="core:things:lang.MetaDescriptor2:/@thing"/>
        </thing>
    </thing>
    <thing extends="_root" description="" name="thing" label="事物" descriptors="core:things:lang.MetaDescriptor2:/@thing"/>
    <thing extends="core:things:lang.actions.Actions" name="actions" label="动作" descriptors="core:things:lang.MetaDescriptor2:/@thing">
        <attribute name="name"/>
    </thing>
    <thing description="&lt;p&gt;自定义的事物编辑器。" name="SwtEditSetting" label="SWT编辑设置" descriptors="core:things:lang.MetaDescriptor2:/@thing">
        <thing extends="ui:local:swt.Widgets" description="" name="SwtEditor" label="SWT编辑器" descriptors="core:things:lang.MetaDescriptor2:/@thing">
            <actions name="actions">
                <GroovyAction name="create" code=""/>
            </actions>
        </thing>
        <thing extends="ui:local:swt.widgets.Composite" description="&lt;p&gt;SWT编辑器控件扩充虽然继承了Composite,但实际只使用Composite的子事物。&lt;/p&gt;" name="SwtEditorExtends" label="SWT编辑器输入扩充" descriptors="core:things:lang.MetaDescriptor2:/@thing"/>
    </thing>
    <thing description="&lt;p&gt;通过SWT方式编辑时和此事物关联的菜单定义。&lt;/p&gt;" name="swtMenus" label="Swt菜单集合" descriptors="core:things:lang.MetaDescriptor2:/@thing">
        <thing extends="core:things:lang.ThingMenu:/@menuSetting" name="menuSetting" label="菜单设置" descriptors="core:things:lang.MetaDescriptor2:/@thing"/>
        <thing extends="core:things:lang.ThingMenu:/@menuDefine" name="menuDefine" label="菜单定义" descriptors="core:things:lang.MetaDescriptor2:/@thing"/>
    </thing>
    <thing description="&lt;p&gt;通过HTML方式编辑时和此事物关联的菜单定义。&lt;/p&gt;" name="htmlMenus" label="Html菜单集合" descriptors="core:things:lang.MetaDescriptor2:/@thing">
        <thing extends="core:things:lang.ThingMenu:/@menuSetting" name="menuSetting" label="菜单设置" descriptors="core:things:lang.MetaDescriptor2:/@thing"/>
        <thing extends="core:things:lang.ThingMenu:/@menuDefine" name="menuDefine" label="菜单集合" descriptors="core:things:lang.MetaDescriptor2:/@thing"/>
    </thing>
    <thing name="templates" label="模板列表" descriptors="core:things:lang.MetaDescriptor2:/@thing">
        <thing extends="core:things:util.ThingCreator" name="template" label="事物模板" descriptors="core:things:lang.MetaDescriptor2:/@thing"/>
    </thing>
</thing>

 创建SWT的控件Shell事物

    Shell是使用MetaDescriptor3创建的,其中通过MetaDescriptor3创建的动态输入表单大致如下:

 

事物编辑表单

属性编辑表单

    Shell事物使用XML表示大致如下:

<thing extends="ui:local:swt.widgets.Composite" name="Shell" label="Shell" descriptors="core:things:lang.MetaDescriptor3">
    <actions name="scripts">
        <GroovyAction name="create" throwException="false" code="..."/>
        <GroovyAction name="runShellThreadMenu" throwException="false" code="..."/>
        <GroovyAction name="runDesign" throwException="false" code="..."/>
    </actions>
    <attribute colspan="2" name="name" label="name" size="40"/>
    <attribute colspan="2" name="text" label="text" size="60"/>
    <attribute colspan="2" name="style" label="style" inputtype="select">
        <value name="APPLICATION_MODAL" value="APPLICATION_MODAL" label="APPLICATION_MODAL"/>
        <value name="MODELESS" value="MODELESS" label="MODELESS"/>
        <value name="PRIMARY_MODAL" value="PRIMARY_MODAL" label="PRIMARY_MODAL"/>
        <value name="SYSTEM_MODAL" value="SYSTEM_MODAL" label="SYSTEM_MODAL"/>
    </attribute>
    <attribute default="false" name="NO_TRIM" label="NO_TRIM" inputtype="truefalse"/>
    <attribute default="true" name="CLOSE" label="CLOSE" inputtype="truefalse"/>
    <attribute default="true" name="TITLE" label="TITLE" inputtype="truefalse"/>
    <attribute default="true" name="MIN" label="MIN" inputtype="truefalse"/>
    <attribute default="true" name="MAX" label="MAX" inputtype="truefalse"/>
    <attribute default="false" name="BORDER" label="BORDER" inputtype="truefalse"/>
    <attribute default="false" name="RESIZE" label="RESIZE" inputtype="truefalse"/>
    <attribute default="false" name="ON_TOP" label="ON_TOP" inputtype="truefalse"/>
    <attribute default="false" name="TOOL" label="TOOL" inputtype="truefalse"/>
    <attribute default="false" name="NO_FOCUS" inputtype="truefalse"/>
    <attribute default="-1" name="width" label="width"/>
    <attribute default="-1" name="height" label="height"/>
    <attribute default="true" name="centerScreen" inputtype="truefalse"/>
    <attribute default="false" name="pack" inputtype="truefalse"/>
    <attribute default="false" name="maximized" inputtype="truefalse"/>
    <swtMenus>
        <menuDefine>
            <menu name="swt" label="SWT"/>
        </menuDefine>
        <menuSetting name="runShell" menuType="swt" type="data">
            <menu name="runShell" label="运行" url="ui:local:swt.widgets.Shell:/@scripts/@runShellMenu"/>
            <menu name="runShellAnotherThread" label="运行于新线程" url="ui:local:swt.widgets.Shell:/@scripts/@runShellThreadMenu"/>
            <menu isSplit="true" name="shellSplit1"/>
            <menu name="runShellDesign" label="设计" url="ui:local:swt.widgets.Shell:/@scripts/@runDesign"/>
        </menuSetting>
    </swtMenus>
    <thing extends="ui:local:swt.events.ShellListener" name="ShellListener" descriptors="core:things:lang.MetaDescriptor3:/@thing" group="events"/>
    <attribute description="&lt;p&gt;Sets the receiver&apos;s alpha value.&lt;/p&gt;" name="alpha"/>
    <attribute inputtype="truefalse" default="false" name="fullScreen"/>
    <attribute inputtype="select" name="imeInputMode">
        <value name="NONE" value="NONE" label="NONE"/>
        <value name="ROMAN" value="ROMAN" label="ROMAN"/>
        <value name="DBCS" value="DBCS" label="DBCS"/>
        <value name="PHONETIC" value="PHONETIC" label="PHONETIC"/>
        <value name="NATIVE" value="NATIVE" label="NATIVE"/>
        <value name="ALPHA" value="ALPHA" label="ALPHA"/>
    </attribute>
</thing>

 创建和运行一个Shell窗体

    ShellExample是使用Shell创建的,其中通过Shell创建的动态输入表单大致如下:

 

Shell编辑表单

    选择ShellExample的菜单可以运行该窗体:

选择功能菜单

Shell窗体的运行结果

    ShellExample事物使用XML表示大致如下:

<Shell height="300" name="ShellExample" 
    text="&quot;一个Shell表单示例&quot;" width="400" RESIZE="true"/>

 

Copyright ©  2007-2008 XWorker.org  版权所有

沪ICP备08000575号