如何编写 GWT Designer 可识别的完全自定义的小部件?

发布于 2024-11-29 00:05:26 字数 330 浏览 1 评论 0原文

当我使用 GWT Designer 添加标准 GWT VerticalPanel 时,我可以通过拖放小部件将它们添加到此面板。 GWT Designer 提供了一条红线,指示我正在向 VerticalPanel 添加一个小部件。

假设我想从头开始创建自己的面板,并且不想扩展标准 GWT 面板。我希望 GWT Designer 能够识别我的面板并提供与我使用标准 gwt 面板时相同的功能。

据我所知,诸如 Ext-GWT 之类的框架是从头开始编写其小部件库的,但它们与 GWT Designer 协同工作。我是否需要在自定义面板中实现某些方法才能实现此功能?任何指导或想法都将受到高度赞赏。

谢谢

When I add let's say, a standard GWT VerticalPanel, with GWT Designer I can add widgets to this panel by drag and dropping them. GWT Designer provides a red line indicating I am adding a widget to my VerticalPanel.

Suppose that I want to create my own panel from scratch, and I don't want to extend standard GWT panels. I want GWT Designer to recognize my panel and provide the same functionality it provides when I use standard gwt panels.

As far as I know frameworks such as Ext-GWT wrote their widget libraries from scratch and yet they work in unison with GWT Designer. Do I need to implement certain methods in my custom panel to achieve this functionality? Any guidance or ideas are well appreciated.

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

海夕 2024-12-06 00:05:26

总而言之,对新组件的支持需要在 GWT Designer 中添加对此组件的特殊支持。假设我有一个自定义组件,我希望它像 VerticalPanel 一样运行,但实际上是复合类型:

public class CustomPanel extends Composite implements HasWidgets{
    private VerticalPanel panel = new VerticalPanel();
    public CustomPanel() {
        initWidget(panel);
    }   
    @Override
    public void add(Widget w) {panel.add(w);}
    @Override
    public void clear() {panel.clear();}
    @Override
    public Iterator<Widget> iterator() {return panel.iterator();}
    @Override
    public boolean remove(Widget w) {return panel.remove(w);}
}

这将作为 VerticalPanel 工作,但当您从设计者的角度看时,它仍然是一个 Composite。因此,您无法将小部件放入其中。在最简单的情况下,为了使其设计者友好,您应该做的是按照给定的名称约定在 CustomPanel 的同一包中创建 CustomPanel.wbp-component.xml。一个简单的提供像小部件添加行为这样的流程的方法是,

<?xml version="1.0" encoding="UTF-8"?>
<component xmlns="http://www.eclipse.org/wb/WBPComponent">
    <description>This is a simple Composite acting like VerticalPanel</description>
    <!-- CREATION -->
    <creation>
        <source><![CDATA[new org.test.client.CustomPanel()]]></source>
    </creation>
    <parameters>
        <parameter name="flowContainer">true</parameter>
        <parameter name="flowContainer.horizontal">false</parameter>
        <parameter name="flowContainer.association">%parent%.add(%child%)</parameter>   
    </parameters>
</component>

添加此步骤后,gwt 设计器也应该将您的组合视为垂直面板(将小部件放在支持内)。当仅此 XML 还不够时,意味着您需要一些更复杂的行为,您需要开始编写 java 模型类,该类定义组件的自定义行为给 Designer,并使用 在组件 xml 中引用它; 标签。在这种情况下,您需要编写一个插件来托管您的模型和策略。

以下是此摘要的参考资料和有用链接:

To summarize, support for a new component requires adding special support for this component into GWT Designer. Assume I have a custom component which I want it to act like a VerticalPanel but which infact is type composite :

public class CustomPanel extends Composite implements HasWidgets{
    private VerticalPanel panel = new VerticalPanel();
    public CustomPanel() {
        initWidget(panel);
    }   
    @Override
    public void add(Widget w) {panel.add(w);}
    @Override
    public void clear() {panel.clear();}
    @Override
    public Iterator<Widget> iterator() {return panel.iterator();}
    @Override
    public boolean remove(Widget w) {return panel.remove(w);}
}

This will work as a VerticalPanel, but when you are looking from the Designers perspective this still is a Composite. As a result you can not drop widgets inside it. In the simplest case, what you should do to make it designer friendly is to create a CustomPanel.wbp-component.xml in the same package of CustomPanel following given name convention. A simple one to give flow like widget adding behaviour would be,

<?xml version="1.0" encoding="UTF-8"?>
<component xmlns="http://www.eclipse.org/wb/WBPComponent">
    <description>This is a simple Composite acting like VerticalPanel</description>
    <!-- CREATION -->
    <creation>
        <source><![CDATA[new org.test.client.CustomPanel()]]></source>
    </creation>
    <parameters>
        <parameter name="flowContainer">true</parameter>
        <parameter name="flowContainer.horizontal">false</parameter>
        <parameter name="flowContainer.association">%parent%.add(%child%)</parameter>   
    </parameters>
</component>

After adding this step your composite should be treated like a vertical panel (dropping widgets inside support) by the gwt designer as well. When this XML alone is not enough, meaning you need some behavior more of a complex nature, you need to start writing java model classes that defines custom behaviour of your component to Designer and reference it in your component xml using <model> tag. In this case you need to write a plugin to host your models and policies.

Here are the references for this summary and useful links:

忆梦 2024-12-06 00:05:26

GWT Designer 文档有一个关于自定义组合和面板的页面,但是这些与 Swing 和 SWT 组件有关。至于 GWT,文档建议使用 GWT 的布局管理器以获得最大的便携性。

GWT Designer documentation have a page about custom composites and panels but these pertain to Swing and SWT components. As for GWT, the documentation recommends using GWT's layout managers for maximum portability.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文