Search code examples
gwtgwt2uibinder

Sample GWT2.5 application


Please give me sample GWT2.5 application with all additional features in 2.5. Please give I've tried it for UiBinder Enhancements. But it is not working.

Please reply me as quick as possible. Its urgent

The following are the code,

MainEntryPoint

package com.MyApp.client;

import com.google.gwt.core.client.EntryPoint;
 import com.google.gwt.user.client.ui.RootPanel;


public class MainEntryPoint implements EntryPoint {


/** 
 * Creates a new instance of MainEntryPoint
 */
public MainEntryPoint() {
}

/** 
 * The entry point method, called automatically by loading a module
 * that declares an implementing class as an entry-point
 */
@Override
public void onModuleLoad() {
    final MainViewClass mainView = new MainViewClass();
    RootPanel.get().add(mainView);
}

}


MyActionCell

package com.Rajaa.client;

import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.cell.client.Cell.Context;
import com.google.gwt.cell.client.ValueUpdater;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.uibinder.client.UiRenderer;
import com.google.gwt.user.client.Window;


public class MyActionCell extends AbstractCell<String> {

interface MyUiRenderer extends UiRenderer {

    void render(SafeHtmlBuilder sb, String name);

    void onBrowserEvent(EmployeeMain o, NativeEvent e, Element p, String n);
}
private static MyUiRenderer renderer = GWT.create(MyUiRenderer.class);

@Override
public void render(Context context, String value, SafeHtmlBuilder builder) {
    renderer.render(builder, value);
}

@Override
public void onBrowserEvent(Context context, Element parent, String value,
        NativeEvent event, ValueUpdater<String> updater) {
    renderer.onBrowserEvent(this, event, parent, value);
}

public MyActionCell() {
    super("click");
}

@UiHandler("nameSpan")
void onNameGotPressed(ClickEvent event, Element parent, String name) {
    Window.alert(name + " was pressed!");
}

}


MyMainView

package com.MyApp.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
 import com.google.gwt.uibinder.client.UiBinder;
 import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.ui.Composite;
 import com.google.gwt.user.client.ui.Widget;
 import java.util.Arrays;
 import java.util.List;

public class MyMainView extends Composite {

@UiField
CellTable<Student> table;

private static EmployeeUiBinder uiBinder = GWT.create(EmployeeUiBinder.class);

interface EmployeeUiBinder extends UiBinder<Widget, MyMainView> {
}

public Employee() {
    super.initWidget(uiBinder.createAndBindUi(this));
    TextColumn<Student> nameColumn = new TextColumn<Student>() {

        @Override
        public String getValue(Student object) {
            return object.name;
        }
    };
    table.addColumn(nameColumn, "Name");

    final TextColumn<Student> ageColumn = new TextColumn<Student>() {

        @Override
        public String getValue(Student object) {
            return object.age;
        }
    };
    table.addColumn(ageColumn, "Age");

    final TextColumn<Student> addressColumn = new TextColumn<Student>() {

        @Override
        public String getValue(Student object) {
            return object.address;
        }
    };
    table.addColumn(addressColumn, "Address");

    Column<Student, String> editColumn = new Column<Student, String>(new MyActionCell()) {

        @Override
        public String getValue(Student object) {
            return "Edit";
        }
    };
    table.addColumn(editColumn, "Edit");

    table.setRowCount(DETAILS.size(), true);

    table.setRowData(0, DETAILS);
}

private static class Student {

    private final String name;

    private final String age;

    private final String address;

    public Student(String name, String age, String address) {
        this.name = name;
        this.age = age;
        this.address = address;
    }
}
private static final List<Student> DETAILS = Arrays.asList(
        new Student("xxx", "50", "vvvvvvvvv"),
        new Student("xxxxxx", "37", "dfdfdfdf"),
        new Student("xxxx", "52", "fvxfxcfxdf"));

@UiHandler("nameSpan")
void onNameGotPressed(ClickEvent event) {
    Window.alert("Yes!");
}

}


MyMainView.ui.xml

<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
    xmlns:h="urn:import:com.google.gwt.user.cellview.client">
        <ui:with field='name' type='java.lang.String'/>

<ui:style>

</ui:style>
<g:HTMLPanel>
    <h:CellTable ui:field="table"/>

'

 <g:Button ui:field='nameSpan'><ui:text from='{name}'/></g:Button>.

</ui:UiBinder>

Thanks in advance, Gnik


Solution

  • The Google Web Toolkit documentation has been updated with the latest (for now, 2.5) version. As you said, UiBinder has new improvements.

    According to the Google blog post What's new in GWT 2.5:

    GWT 2.5 adds extensions to UiBinder that allow it to support Cell rendering and event handling. In particular, this design enables UiBinder to generate a UiRenderer implementation to assist with rendering SafeHtml, and dispatching events to methods specified by @UiHandler tags. See Rendering HTML for Cells for more information.

    We’ve also introduced the IsRenderable/RenderablePanel types. When used by an application instead of HTMLPanel, they can significantly improve rendering time and reduce the latency of complex UiBinder UIs.

    The documentation shows multiple examples about that feature in 2.5. You can see the examples here: Rendering HTML for Cells.