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.

20 comments:

  1. If you have a history of illness that is difficult to recover, maybe our next article will help you to recover

    Walatra Gamat Emas Kapsul
    Obat untuk Penyakit Rubella
    Obat penghilang kapalan pada kaki
    Obat Rematik
    Obat kista ateroma

    ReplyDelete
  2. Ce sac cartable Michael Kors est si universel qu'il pourrait plaire à tout le monde. Dans cet article, je vais essayer de passer en revue les caractéristiques principales et les éléments qui distinguent ce sac à main des autres.

    tags:Bolsos Michael Kors Rebajas,Bolsos Michael Kors Baratos,Bolsos Michael Kors El Corte Ingles

    L’extérieur de ce fourre-tout Michael Kors est un cuir métallisé de laiton froncé et froncé. Si vous connaissez les sacs à main Michael Kors, vous savez que ce cuir sera doux et souple. Les deux grandes poignées supérieures sont attachées au sac avec quelques centimètres de chaînes dorées, puis les moitiés supérieures des bretelles présentent le même cuir couleur laiton.

    tags:Bolsos Michael Kors Baratos,Michael Kors Örhängen

    La diversité des couleurs et la taille utilisable de ce sac le rendent parfait pour un usage quotidien. Les poches intérieures ne manquent pas pour aider à garder les choses en ordre. Il y a des endroits parfaits pour votre téléphone ou votre Blackberry. Le zip top empêche les malfaiteurs de saisir votre sac dans un bar et aide également à contenir tout ce qui se trouve à l'intérieur lorsque vous courez pour créer ce train.

    tags:Windguru Longchamps,Longchamp Soldes Destockage,Pronote College Longchamp

    ReplyDelete
  3. Michael Kors Outlet Online was a huge success there and became very well known. The designer Kors then branched out into accessories including Michael Kors Handbags Clearance. He never lost focus on his American chic styling. Some of his most notable collections include the Michael Kors Totes, Michael Kors satchel and the Designer MK Outlet and Michael Kors Outlet Online Store.

    No one has to know that they are cheap Ray Ban Sale UK and no one will know unless you tell them. Each of the cheap designer Ray Ban Sunglasses Sale UK carries the signature brand on the lens to let you know that you do have authentic designer Cheap Ray Ban Sunglasses UK.

    tags: Cheap Oakley Sunglasses UK,MK Outlet

    ReplyDelete
  4. Check out the seller's feedback rating to know if they have built a good reputation in selling discount Coach Handbag Clearance. Because of this, shoppers are on the lookout for more places offering discount Coach 25 Off Coupon. The problem now is determining whether or not to buy your Coach Outlet Online 80 Off, at a thrift store or at a traditional brick and mortar location. (tags: Michael Kors Handbags Macys,Macys Michael Kors Handbags Sale,Michael Kors Handbags On Sale Outlet)

    It is just as important to arm yourself with knowledge about how to determine whether or not your Coach Store Locator is real or a replica because outside of purchasing one from a Coach Outlet Online Clearance or a Coach Factory Online Sale Invitation, there are no guarantees.(tags: Coach Leather Handbags,Michael Kors Clearance Bags,Coach Outlet Website)

    ReplyDelete
  5. Both things are possible if you carry Michael Kors Handbags Wholesale. If you are a woman who goes for innovative designs, a designer Michael Kors Bags On Sale is perfect for you. Offering a huge selection of chic purses, handbags, shoes and accessories, Michael Kors Outlet Online Store celebrates womanhood in an entirely unique way. Michael Kors Factory Outlet Online Store At Wholesale Price are one of the most sought-after handbags worldwide. We all agree that diamonds are a woman's best friend; however Official Coach Factory Outlet Online are absolutely next in line. To Coach Outlet Sale aficionados, don't fret because we have great news: a discount Official Coach Outlet Online isn't hard to find. If you are a smart shopper looking for a good buy and great deals on your next handbag purchase, you can go to Official Coach Outlet Online.

    Friendly Links: Toms Shoes Womens | Toms Clearance

    ReplyDelete
  6. 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
  7. 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