Saturday, October 13, 2007

Dehydrated Eyes Open Unresponsive

Drag & Drop in GWT

Since I came up GWT has passed a lot of time, so it can no longer be viewed not only in terms of whether Google's proposed approach is precisely that for which the developers are waiting webowi who knit in JavaScriptcie simply does not answer, but it can also be assessed in terms of popularity that wins, and admit that browsing the Internet resources it is clear that leaves the competition behind, such as YUI framework developed by Yahoo.

Another important element that contributes significantly to the popularity of the framework is to support the He gets open-source environment, mainly I mean the number of free expansion which is formed by a group of programmers.
hours searching the Internet I came across a very interesting library gwt-dnd that the really little effort, you will build the user interface elements of Drag & Drop.

main advantage of this library is that we can benefit from standarowych widgets and panels supplied by GWT - they do not need to implement special classes or interfaces, simply use the existing widgets and panels. I will not be focused in the following description of the functionality that the library provides, and will present a piece of code that present the ease of use with this extension.

In the first step we create the main panel, except that they can not go dragging elements:
  AbsolutePanel AbsolutePanel boundaryPanel = new (); 
boundaryPanel.setPixelSize (400, 300);
RootPanel.get (). Add (boundaryPanel);
Then inside of the panel, create another panel, this time it will be determined the area outside where you can not drop the widget (in our case it will simply label):
  AbsolutePanel AbsolutePanel targetPanel = new (); 
targetPanel.setPixelSize (300, 200);
boundaryPanel.add (targetPanel, 10, 10);
The next step is to create a so-called. DragControllera in which the panel put off that you can not drag widgets (which does not mean that you will drop it in him):
  DragController dragController = new PickupDragController (boundaryPanel, true);  
Now we add the so-called analogy. DropController, which put the panel within which it can be dropped widgets:
  DropController dropController = New AbsolutePositionDropController (targetPanel);  
register the DropController in DragControllerze:
  dragController.registerDropController (dropController);  
create the label, which we will be dragged and dropped around targetPanel:
  Label label = new Label ("Move me:) ', false); 
targetPanel.add (label, 10, 1);
Through DragControllera do with the label widget that can be dragged:
  dragController.makeDraggable (label);  
strength of this library lies in its simplicity of use in 12 lines of code can make a huge difference confusion:)

sources which I use and recommend everyone read them:
http://code.google.com/p/gwt-dnd/
http://code.google.com/p/ gwt-dnd/wiki/GettingStarted

For those interested, I put the source code.

source code file MyApplication.gwt.xml :
  \u0026lt;module> 
\u0026lt;inherits name="com.google.gwt.user.User"/>
\u0026lt;inherits name = "com.allen_sauer . gwt.dragdrop.DragAndDrop "/>
\u0026lt;entry-point class="com.mycompany.project.client.MyApplication"/>
\u0026lt;/ module>
source code file MyApplication.java :
  com.mycompany.project.client package; 

com.allen_sauer.gwt.dragdrop.client.DragController import, import
com.allen_sauer. gwt.dragdrop.client.PickupDragController;
com.allen_sauer.gwt.dragdrop.client.drop.AbsolutePositionDropController import, import
com.allen_sauer.gwt.dragdrop.client.drop.DropController;
com.google.gwt.core import. client.EntryPoint;
com.google.gwt.user.client.ui.AbsolutePanel import, import
com.google.gwt.user.client.ui.Label;
com.google.gwt.user.client.ui import. RootPanel;

public class implements MyApplication EntryPoint {

public void onModuleLoad() {
AbsolutePanel boundaryPanel = new AbsolutePanel();
boundaryPanel.setPixelSize(400, 300);
RootPanel.get().add(boundaryPanel);

AbsolutePanel targetPanel = new AbsolutePanel();
targetPanel.setPixelSize(300, 200);
boundaryPanel.add(targetPanel, 10, 10);

DragController dragController = new PickupDragController(boundaryPanel, true);
DropController dropController = new AbsolutePositionDropController(targetPanel);
dragController.registerDropController(dropController);

Label label = new Label("Rusz me:) ", false);
targetPanel.add (label, 10, 1);

dragController.makeDraggable (label);}

}

0 comments:

Post a Comment