Dojo on Google Web Toolkit

Dojo marrying Google Web Toolkit

  • Back in Time

    November 2009
    M T W T F S S
    « Oct    
     1
    2345678
    9101112131415
    16171819202122
    23242526272829
    30  
  • Historical Data

  • Tags

  • Recent Comments

    Archive for the 'Dijit' Category


    The Phoenix

    Posted by Gaurav Vaish on 16th October 2008

    No no… don’t think that Dwt is dead just because there seems no visible activity for last two months.

    In fact, I just got so busy that there was hardly any time to look into Dwt. Can’t help, I’m not 100%-time into Dwt.

    Anyway… that was recent past.

    Ok… now coming to the rebirth of Dwt - that I don’t think should happen again, at least in near future, here are the latest updates:

    1. Focus continues to have on the core design, for the moment, to ensure that we do not have half-cooked or uncooked design.
    2. Refactoring of dijit.Widget class: It does not use several class-level fields to store styleClass, dir, lang etc. It uses a HashMap<String, Object>, and additionally provides get/set apart from getXXX and setXXX.
    3. Added JavaScriptObjectWrapper class since interconversion from JavaScriptObject to Java-Object was troublesome area in quite a few scenarios. The benefits will be visible at several places.
    4. Refactoring of IJavaScriptFunction interface to use JavaScriptObjectWrapper class.
    5. TemplatedWidget uses HashMap<String, List<Element>> for dojoAttachPoints and HashMap<String, HashMap<Integer, List<EventListener>>> as event-listeners store.
    6. TemplatedWidget, at least for now - until we get the magical wand, does not support dojoAttachEvent.
    7. The immediate next step is get TemplatedWidget back in shape because after these changes, the code breaks. :)
    8. Subsequently, implement the replaceProperties method.
    9. And then, provide overloaded addEventListener methods as discussed in the previous entry.

    I would be committing the code sometime tomorrow. It’s been quite hectic recently.

    Catch up with lot of action…

    Posted in Architecture, Dijit, Updates, mastergaurav | No Comments »

    Template Based Widgets in DWT

    Posted by Gaurav Vaish on 29th August 2008

    Download the PDF document (for better readability here).

    The challenge:

    There are several architectural and feature differences in JavaScript and Java.

    Java is statically typed where as JavaScript is dynamically typed.

    Java does not support function references where as JavaScript supports.

    As such, it becomes very difficult to support template-based widgets in DWT, as is the case in Dojo Widget System – Dijit.

    Added to it, Google Web Toolkit (GWT) differentiates JavaScriptObject inherited types v/s other Object-inherited types. Though finally non-JavaScriptObject types are compiled to JavaScript types, the hosted-mode (emulation layer) fails to recognize “dynamic” properties and result in errors.

    Proposed Solution:

    Statically typed languages can be converted to dynamically typed language using collections like an array or a map (java.util.List and java.util.Map).

    List provides an index-based access to the properties where as Map provides a name-based access.

    As such, what I propose is the following:

    • All properties would be stored in a combination of Map<String, Object>. This includes even simple items like the ID, widget-ID or other attributes. The key is the name of the property.
    • All dojoAttachPoint-s would be stored in Map<String, Element>. The key is the name of the attach-point.
    • All dojoAttachEvent-s would be stored in a slightly more elaborated Map<String, Map<String, List<EventListener>>>

    Widget Properties:

    All widget properties would be stored in a variable – say, properties – of the type Map<String, Object>.

    It will contain all properties that are required for the working of the widgets. As such, the class will not contain any fields other than what is required to manage the system.

    The Widget-inherited types may introduce custom fields as may be required.

    Access to the values would be made available through the methods get(String) and set(String, Object)

    Dojo Attach Point-s:

    All attach points, as parsed from the templates, would be stored in a variable – say, attachPoints – of the type Map<String, List<Element>>.

    The basic question – why should the value be List<Element> rather than Element? The answer lies in the file dijit/_Templated.js (part of Dojo distribution).

    The following is the code snippet from the file (lines 144 – 149, version 1.1.1):

    while((point = points.shift())){
       if(dojo.isArray(this[point])){
          this[point].push(baseNode);
       }else{
          this[point]=baseNode;
       }
    }

    As such, I decided to make it a List<Element>.

    The methods getAttachPoints(String), getAttachPoint(String) can be used access the attach-points programmatically.

    Methods addAttachPoint, setAttachPoints, removeAttachPoint and removeAttachPoints may be used for further programmatic manipulation [1].

    I propose to keep all the methods public unless there is a pressing reason against it.

    Dojo Attach Event-s:

    dojoAttachEvent-s is a trickier part since Java does not support method references. As such, dojoAttachEvent-s are not supported in the form as in Dojo.

    A widget-author can use the following methods to register attach-events programmatically:

    • registerAttachEvents(Map<String, Map<String, List(<EventListener>>)
    • registerAttachEvents(Map<String, Map<int, List(<EventListener>>>)
    • registerAttachEvents(Map<Element, Map<String, List(<EventListener>>>)
    • registerAttachEvents(Map<Element, Map<int, List(<EventListener>>>)
    • addAttachEvent(String, String, EventListener)
    • addAttachEvent(Element, String, EventListener)
    • addAttachEvent(String, int, EventListener)
    • addAttachEvent(Element, int, EventListener)

    The Map<String, Map<String, EventListener>> comprises of the main key as attach-point-name and the sub-key as the DOM-event-name or the ID (as defined by GWT).

    registerAttachEvents is a protected method and would be called during the build-up process. addAttachEvent is a public method for further manipulation.

    Overloaded methods removeAttachEvent can be used to remove the listeners [1].

    The field – say, eventListeners – of type Map<String, Map<int, List<EventListener>>> would be used to manage all event listeners.

    Widgets may publish helper methods, say for example, addClickListener for Button or addChangeListener for TextBox or simply addListener for the ease of the developer.

    [1]: Not sure if it is really required.

    Final Structure:

    public class Widget
    {
       private Map<String, Object> properties;
    
       public Object get(String name);
    
       public set(String name, Object value);
    
    }
    
    public class TemplatedWidget extends Widget
    {
       private Map<String, List<Element>> attachPoints;
       private Map<String, Map<int, List<EventListener>>> eventListeners;
    
       public List<Element> getAttachPoints(String name);
       public Element getAttachPoint(String name);
    
       public void addAttachPoint(String name, Element element);
       public void addAAttachPoints(String name, List<Element> elements);
    
       protected void registerAttachEvents
          (Map<String, Map<String, List(<EventListener>>);
       protected void registerAttachEvents
          (Map<String, Map<int, List(<EventListener>>);
    
       protected void registerAttachEvents
          (Map<Element, Map<String, List(<EventListener>>>);
       protected void registerAttachEvents
          (Map<Element, Map<int, List(<EventListener>>>);
    
       public void addAttachEvent(String, String, EventListener);
       public void addAttachEvent(String, int, EventListener);
       public void addAttachEvent(Element, String, EventListener);
       public void addAttachEvent(Element, int, EventListener);
    
       public void removeAttachEvent(String, String, EventListener);
       public void removeAttachEvent(String, int, EventListener);
       public void removeAttachEvent(Element, String, EventListener);
       public void removeAttachEvent(Element, int, EventListener);
    }

    Feedback:

    The DWT team looks forward to your inputs – critics and suggestions on the approach.

    Feel free to drop in a comment at http://dwt.sourceforge.net/blog or write a mail to dwt@edujini-labs.com or dwt-users@lists.sourceforge.net.

    Mailing-list URL: http://sourceforge.net/mailarchive/forum.php?forum_name=dwt-users

    Posted in Architecture, Dijit, Proposals, Templated Widget | No Comments »

    Templated Widget Design

    Posted by Gaurav Vaish on 29th August 2008

    Yesterday, we accomplish a kind-of breakthrough. We were able to process the template for a template-based-widget and extract the dojoAttachPoint-s.

    The tougher challenge for us is to work with dojoAttachEvent. At this point, I am not quite too sure if and how we will support it because Java does not support function-pointers whereas JavaScript does.

    Yesterday, I did try out sinking some events and capturing them (onBrowserEvent). Worked fine in trivial case. I think it’s time to look at EventListener and define custom event listeners, and methods to add/remove/fire them.

    I intend to pen-down a small architecture / design document today (hey, I’m traveling tonight and will be off action for next 4-5 days) highlighting the templated widgets.

    And once the templated widget is done, creating further widgets would be straight forward and quite speedy.

    Posted in Architecture, Dijit, Proposals, Templated Widget, Widgets | No Comments »

    Dwt Project Commences

    Posted by Gaurav Vaish on 18th August 2008

    Dwt project finally takes off formally.

    We today checked in a few classes in the dijit package (com.edujinilabs.dwt.client.dijit).

    Browse SVN for Dwt Root or directly checkout the Eclipse project here.

    We started with porting the dijit._Widget data-type, which is available as com.edujinilabs.dwt.client.dijit.Widget class.

    The life so far seems interesting and we hope to publish an architecture and a roadmap document soon.

    Posted in Dijit, Updates | No Comments »