3

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

pistolPanties
  • 1,880
  • 13
  • 18

2 Answers2

3

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:

pistolPanties
  • 1,880
  • 13
  • 18
0

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.

Tahir Akhtar
  • 10,902
  • 7
  • 40
  • 67
  • Thank you, but unfortunately I can't find what I am looking for at those links. I have copy-pasted GWT VerticalPanel class and all of its parents until upto the Widget class, under a different name in a different package. I expect it to have same functionality of VerticalPanel. Indeed it does have the same functionality but gwt designer does not treat it as a panel, meaning I can't drag and drop widgets inside it. So the question is how does GWT Designer know the difference? – pistolPanties Aug 12 '11 at 16:24