Thursday, April 29, 2010

Extending SmartGWT widgets to be UIBinder-compliant

SmartGWT canvas widgets can seldom share space with GWT widgets. The SmartGWT canvas would push itself in-front to obstruct the visibility of GWT widgets. To share a space between the two sets of widgets, the page design needs to carefully avoid having GWT widgets intersecting into SmartGWT canvas, vice versa. Especially that any part of a GWT sub-menu or pop-up that pops into SmartGWT canvas space would not be visible.

Having understood this constraint, this article describes placing extension wrappers around SmartGWT canvas widgets to allow them to be used as UIBinder widgets. Also note that certain newer SmartGWT widgets do not work well with UIBinder.

As described in a previous article, any GWT to be used as UIBinder widgets should
be
  • an extension class of com.google.gwt.user.client.ui.Widget and
  • implement com.google.gwt.user.client.ui.HasWidgets.

The first SmartGWT widget to extend is, of course, com.smartgwt.client.widgets.Canvas, because all SmartGWT has to be placed onto a Canvas.

import org.synthful.smartgwt.client.HasWidgetsUtil;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;
import com.smartgwt.client.widgets.Canvas;

public class UICanvas
    extends Canvas
    implements HasWidgets
{
    @Override
    public void add(Widget w) {
        super.addChild(w);
    }

    @Override
    public Iterator<Widget> iterator() {
        return HasWidgetsUtil.iterator(this);
    }

    @Override
    public boolean remove(Widget w) {
        return HasWidgetsUtil.remove(this, w);
    }

}
Notice the HasWidgetsUtil import highlighted in crimson. HasWidgetsUtil contains common static methods which could be used in most wrappers.

For a Canvas object that does not inherit from com.google.gwt.user.client.ui.Widget, we need to wrap it with a class that extends Widget and expose all the methods of that Canvas object. For example, while com.smartgwt.client.widgets.tab.TabSet inherits Widget, com.smartgwt.client.widgets.tab.Tab does not.

Wrapping Tabset is as simple as wrapping Canvas:

public class UITabset
    extends TabSet
    implements HasWidgets
{   
    @Override
    public void add(Widget w){
        if (w instanceof UITab)
            super.addTab(((UITab)w).tab);
        else
            super.addChild(w);
    }
   
    @Override
    public Iterator<Widget> iterator(){
        return HasWidgetsUtil.iterator(this);
    }

    @Override
    public boolean remove(Widget w){
        return HasWidgetsUtil.remove(this, w);
    }
}
However, to be able to use UIBinder to assign a Tab as a child of a Tabset, we need to wrap the Tab class this way:

package holymoly.smartgwt.ui

import java.util.ArrayList;
import java.util.Iterator;
import org.synthful.smartgwt.client.HasWidgetsUtil;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.tab.Tab;

public class UITab
    extends Widget
    implements HasWidgets
{
    public UITab(){
        this.tab = new Tab();
    }
       
    public void add(Canvas w){
        if (this.canvas==null){
                this.canvas = (Canvas)w;
                tab.setPane(this.canvas);
            }
    }
   
    @Override
    public void add(Widget w){
        try{
            this.add((Canvas)w);
        }
        catch(Exception e){}
    }
   
    @Override
    public void clear()    {
    }
   
    @Override
    public Iterator iterator()    {
        ArrayList<Widget> wx = new ArrayList();
        wx.add(this.canvas);
        return wx.iterator();
    }

    @Override
    public boolean remove(Widget w){
        return HasWidgetsUtil.remove(this, w);
    }

    public void setCloseable(boolean closeable){
        this.tab.setCanClose(closeable);
    }
   
    public void setCloseIcon(String closeIcon){
        this.tab.setCloseIcon(closeIcon);
    }
   
    public void setCloseIconSize(String closeIconSize){
        try{
            int z = Integer.parseInt(closeIconSize);
            this.tab.setCloseIconSize(z);
        }
        catch (Exception e){}
    }
   
    public void setDisabled(boolean disabled){
        this.tab.setDisabled(disabled);
    }
   
    public void setTitle(String title){
        this.tab.setTitle(title);
    }
   
    public void setWidth(String width){
        try{
            int z = Integer.parseInt(width);
            this.tab.setWidth(z);
        }
        catch (Exception e){}
    }
   
   
    final protected Tab tab;
    private Canvas canvas;
}

Now we could comfortably use these SmartGWT widgets with UIBinder:
<ui:uibinder
  xmlns:ui="urn:ui:com.google.gwt.uibinder"
  xmlns:z="urn:import:holymoly.smartgwt.ui"
  xmlns:g="urn:import:com.google.gwt.user.client.ui">
  <z:UICanvas ui:field="canvas">
   <z:UITabset ui:field="tabset">
    <z:UITab ui:field="tab1"> closeable="true"
     closeIcon="{someResource.someicon}"
     <g:Label ui:field="tab1content">
      Hello Galaticals!
     </g:Label>
    </z:UITab>
   </z:UITabset>
 </z:UICanvas>
</ui:uibinder>

More examples are found at
http://code.google.com/p/synthfuljava/source/browse/#svn/trunk/gwt/smartgwt.

9 comments:

  1. This is what it is all about, enjoy the moment and prepare to play well, and we did that today and we have throughout the series. They have to go out and embrace it and to me that is the simplest message we can give to our players. Bruins took a 3 1 lead in the series before the Leafs rallied behind goalie Frederik Andersen to force the deciding game. (Michael Kors Black Over The Shoulder Bag)

    Feel better on the ice. My first couple of steps, I feel faster, said Rantanen, who turned 22 on Monday and leads the league in points with five goals and 16 assists. Think there are still things I can work on and maybe get better next year. (Michael Kors Studded Bag Black)

    Whenever gun control is discussed in the United States, someone pops up to talk about how the Holocaust would never have happened if the Jews had been packing heat. Ben Carson, the embodiment of what would happen if Droopy Dog became HUD secretary, said, "I think the likelihood of Hitler being able to accomplish his goals would have been greatly diminished if the people had been armed." Some versions of this argument further suppose that because Germany had a gun registry, Hitler's goons knew exactly who to round up. This view also comes in convenient meme form.. (Michael Kors Fulton Hobo Bag Black)

    July 18 in the 1100 block of East Galena Boulevard after he allegedly. 26, 2018" > >Yorkville woman charged with delivering heroin and fentanylA 28 year old Yorkville woman has been charged with delivering heroin and fentanyl. Kristina L. (Michael Kors Black Leather Messenger Bag)

    Coach Bags Outlet America, There are no detention facilities. They have to re establish law and order in a country as big as France with just twelve thousand troops. Human Rights Watch Director gave a dark vision of the African country current predicament but he was joined in the interview by a living symbol of hope in the future, Father Bernard Kinvi..

    ReplyDelete
  2. Jordan Eclipse Black And Purple, The bottoms of the clouds rise with warmer temperatures, while the top of the cloud stays the same so the clouds become thinner, explained Del Genio. "When low clouds are present, warmer air flowing over land tends to be drier. As a parcel of dry air rises, it has to rise farther before it saturates with enough water to form the cloud base.".

    There are a large number of password managers available for use. You need to research which service you want to use. A lot of these solutions have reports or blogs on their site discussing how it works and what they do to protect your details, for instance 1Password has a white paper going into a lot of depth on their service and mission. {tag: Yeezy Boost 350 V2 Cloud White Ebay}

    Air Jordan Retro 9 White Black Wolf Grey, She's in a club of one: The 2K, 1K, 1K. We've never seen anything she has a resume and you can argue her as arguably the greatest player to ever play women's basketball in college. The one thing she was missing and that I was confident she was going to get this year was that national championship.

    Using subscriptions for telemarketing or call centre operations; Re selling subscription minutes; Sharing subscriptions between users whether via a PBX, call centre, computer or any other means; Calling numbers (whether singly, sequentially or automatically) to generate income for yourself or others as a result of placing the call, other than for your individual business communications: and Unusual calling patterns inconsistent with normal, individual subscription use, for example, regular calls of short duration or calls to multiple numbers in a short period of time. Other practices may be relevant in determining Legitimate Use and Skype reserves the right to take any unlawful, prohibited, abnormal or unusual activity into account in making its determination. Skype may at its option, terminate or suspend its relationship with you, and your use of any Skype product immediately if it determines you are using the product contrary to this FUP.. {tag: Yeezy White Core Black Red}

    ReplyDelete