可以把一个模型程序定义成控件模型,定义成控件模型后可以方便的被其它模型所使用。
我们以WebBrowser为例,一个使用了WebBrowser的模型如下。
<?xml version="1.0" encoding="utf-8"?> <Shell name="shell" descriptors="xworker.swt.widgets.Shell" text="Web Browser" RESIZE="true" width="640" height="480" label="TestWebBrowser"> <FillLayout name="FillLayout"></FillLayout> <WebBrowser name="WebBrowser"></WebBrowser> </Shell>
运行后的截图如下。
<?xml version="1.0" encoding="utf-8"?> <thing name="WebBrowser" descriptors="xworker.lang.MetaDescriptor3" extends="xworker.swt.layout.LayoutDatas"> <actions> <CreateWidget name="create" descriptors="xworker.swt.actions.CommonActions/@CreateWidgets" widgetPath="xworker.ide.worldExplorer.swt.util.WebBrowser/@shell/@mainComposite" newActionContext="true" newActionCotnextDataName="actionContext" isSwtCreateMethod="true"></CreateWidget> </actions> <attribute name="name" modifier=""></attribute> <attribute name="label" modifier=""></attribute> <attribute name="description" inputtype="html" modifier=""></attribute> </thing>
注意,控件一般需要继承xworker.swt.layout.LayoutDatas,这样可以添加布局数据子节点。
在这里WebBrowser只是简单的把一个已有的模型重复创建了。
<CreateWidget name="create" descriptors="xworker.swt.actions.CommonActions/@CreateWidgets" widgetPath="xworker.ide.worldExplorer.swt.util.WebBrowser/@shell/@mainComposite" newActionContext="true" newActionCotnextDataName="actionContext" isSwtCreateMethod="true"></CreateWidget>
如果使用Java代码来实现create方法,那么需要注意Designer的使用,这里可以避免复合的子控件可以被设计器动态修改。
Designer.pushCreator(self); try{ control = (Control) controlThing.doAction("create", ac); }finally{ Designer.popCreator(); }
在最后用attachCreator。
Designer.attachCreator(control, self.getMetadata().getPath(), actionContext);
其它注意事项,如创建子节点,保存到全局变量中等,和集成Java控件等一致。
Copyright © 2007-2014 XWorker.org 版权所有