简体   繁体   English

如何在Eclipse RCP中创建自定义UI构建器

[英]How create custom UI builder in Eclipse RCP

I have an application based on Eclipse RCP and I would like it to create custom UI builder, in which the end user can create their own dashboard (View), which will contain a variety of gauges, buttons, text, etc. I would just like some implemented several UI builder (similarly as for WindowBuilder SWT ), ie to include the palette with UI elements, property elements UI builder, etc. the result would be stored in an XML file, which would RCP applications loaded and in this XML file should be created the View. 我有一个基于Eclipse RCP的应用程序,我希望它能够创建自定义UI构建器,最终用户可以在其中创建自己的仪表板(View),其中包含各种仪表,按钮,文本等。我​​会像一些实现了几个UI构建器(类似于WindowBuilder SWT ),即包含具有UI元素的调色板,属性元素UI构建器等,结果将存储在XML文件中,这将加载RCP应用程序并在此XML文件中应该创建视图。 Unfortunately I do not know where to start (what the catch), an example for creating a custom UI builder? 不幸的是我不知道从哪里开始(捕获什么),创建自定义UI构建器的示例?

EDIT: I already have one UI builder I have done, so I'm a complete beginner, but I want to write a new and better. 编辑:我已经有一个UI构建器,所以我是一个完整的初学者,但我想写一个新的更好。 Saving / loading xml files do not need to solve. 保存/加载xml文件不需要解决。 What bothers me (do not know how to do it) is the actual UI builder, ie creating a palette UI elements, copy and move elements using the mouse, select multiple elements (to move), etc. 令我烦恼的是(不知道该怎么做)是实际的UI构建器,即创建调色板UI元素,使用鼠标复制和移动元素,选择多个元素(移动)等。

Thanks for any advice. 谢谢你的建议。

I had a very similar requirement, but I didn't use RCP. 我有一个非常相似的要求,但我没有使用RCP。 I understand you want to save the structure of the created UI in an XML that will be loaded then whenever you want to load again the UI. 我知道您希望将创建的UI的结构保存在XML中,然后在您再次加载UI时加载该XML。 So I think, if you're using XML, you have to use an schema or XSD template for the XML standard document that will represent the UI. 所以我认为,如果您使用XML,则必须使用模式或XSD模板来表示UI的XML标准文档。 Define what elements are allowed in your UI, sample: buttons, textfields, labels, etc. You need to have a well-defined template because whenever you write a xml or to read a xml it has to be as standard as possible. 定义UI中允许的元素,示例:按钮,文本字段,标签等。您需要有一个定义良好的模板,因为无论何时编写xml或读取xml,它都必须尽可能标准化。

If you don't get along well with xsd, you can define your xml first and then use an xsd generator, there are many of them online. 如果你与xsd不相处,你可以先定义你的xml,然后使用xsd生成器,其中有很多是在线的。

For instance: 例如:

<UIBuilder>
<ownerProperties>
<username>Marcelo Tataje</username>
</ownerProperties>
<ui>
<header>
<textlabel label="Welcome" />
</header>
<menu>
<button label="Home" name="btnHome">goHome()</button>
<button label="Contacts" name="btnContacts">showContacts()</button>
</menu>
<mainFrame>
<textfield label="Name:" name="txtName" canEdit=false />
<button label="Show name" name="btnProcess">processData()</button>
</mainFrame>
<footer></footer>
</ui>
<UIBuilder>

And based on this, you can create an schema: 基于此,您可以创建一个模式:

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="UIBuilder">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="ownerProperties">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:string" name="username"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="ui">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="header">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="textlabel">
                      <xs:complexType>
                        <xs:simpleContent>
                          <xs:extension base="xs:string">
                            <xs:attribute type="xs:string" name="label"/>
                          </xs:extension>
                        </xs:simpleContent>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="menu">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="button" maxOccurs="unbounded" minOccurs="0">
                      <xs:complexType>
                        <xs:simpleContent>
                          <xs:extension base="xs:string">
                            <xs:attribute type="xs:string" name="label" use="optional"/>
                            <xs:attribute type="xs:string" name="name" use="optional"/>
                          </xs:extension>
                        </xs:simpleContent>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="mainFrame">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="textfield">
                      <xs:complexType>
                        <xs:simpleContent>
                          <xs:extension base="xs:string">
                            <xs:attribute type="xs:string" name="label"/>
                            <xs:attribute type="xs:string" name="name"/>
                            <xs:attribute type="xs:string" name="canEdit"/>
                          </xs:extension>
                        </xs:simpleContent>
                      </xs:complexType>
                    </xs:element>
                    <xs:element name="button">
                      <xs:complexType>
                        <xs:simpleContent>
                          <xs:extension base="xs:string">
                            <xs:attribute type="xs:string" name="label"/>
                            <xs:attribute type="xs:string" name="name"/>
                          </xs:extension>
                        </xs:simpleContent>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element type="xs:string" name="footer"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

I used http://www.freeformatter.com/xsd-generator.html 我使用了http://www.freeformatter.com/xsd-generator.html

And use Jaxb to create the logical processing to create the UI based on the defined well-formed XML documents. 并使用Jaxb创建逻辑处理,以基于定义的格式良好的XML文档创建UI。

One starts a large project by decomposing it into smaller and smaller pieces, until you can write the code for a piece. 一个人通过分解成越来越小的片段来开始一个大型项目,直到你可以编写一个片段的代码。

You can start from the bottom and work up, or you can start from the top and work down. 您可以从底部开始工作,也可以从顶部开始工作。

Here are a couple of questions that will help you in your decomposition. 以下是一些可以帮助您解决问题的问题。

What components (gauges, buttons, text, etc.) will your project support? 您的项目将支持哪些组件(仪表,按钮,文本等)?

How many different components will a user have available for a panel? 用户可以为面板提供多少个不同的组件?

As far as coding, go ahead and set up an Eclipse RCP project with a multi panel editor. 至于编码,请继续使用多面板编辑器设置Eclipse RCP项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM