auto-gwt : better gwt programming with xtend

20
AUTO-GWT Better GWT Programming with Xtend Anton Kosyakov (@akosyakov), Sven Efftinge (@svenefftinge) itemis

Upload: sven-efftinge

Post on 16-Jul-2015

3.985 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Auto-GWT : Better GWT Programming with Xtend

AUTO-GWT Better GWT Programming with Xtend

Anton Kosyakov (@akosyakov), Sven Efftinge (@svenefftinge) itemis

Page 2: Auto-GWT : Better GWT Programming with Xtend

Java Interoperability Low Signal-To-Noise Ratio

Powerful Concepts

Page 3: Auto-GWT : Better GWT Programming with Xtend

Java Interoperability• Familiar Syntax • Compiles to readable Java source code • Uses JDK (no own collection types) • No messing with generics, primitives, nullable • Integrates with Java Tools

Page 4: Auto-GWT : Better GWT Programming with Xtend

Low Signal-To-Noise Ratio• Type Inference • property access • good defaults

• sweet Lambdas • optional parenthesis • optional semicolons

Page 5: Auto-GWT : Better GWT Programming with Xtend

Powerful Concepts

• Macros • Extension Methods • Enhanced Switch

• Template Expressions • operator overloading • Dispatch methods

Page 6: Auto-GWT : Better GWT Programming with Xtend

Demo

Page 7: Auto-GWT : Better GWT Programming with Xtend
Page 8: Auto-GWT : Better GWT Programming with Xtend

clearCompletedButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { List<Todo> result = new ArrayList<Todo>(); for (Todo t : getTodos()) { if (!t.isDone()) { result.add(t); } } setTodos(result); } });

Clearing Completed Tasks

Page 9: Auto-GWT : Better GWT Programming with Xtend

clearCompletedButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { List<Todo> result = new ArrayList<Todo>(); for (Todo t : getTodos()) { if (!t.isDone()) { result.add(t); } } setTodos(result); } });

clearCompletedButton.addClickHandler [ ]

todos = todos.filter[!done].toList

Page 10: Auto-GWT : Better GWT Programming with Xtend

Client Server Communication

Page 11: Auto-GWT : Better GWT Programming with Xtend

public class TodoServiceImpl extends RemoteServiceServlet implements TodoService { public List<Todo> load(final String name) { return (List<Todo>) getMemcacheService().get(name); } public void save(final List<Todo> todos, final String name) { getMemcacheService().put(name, todos); }}

@RemoteServiceRelativePath("todoService")public interface TodoService extends RemoteService { public List<Todo> load(final String name); public void save(final List<Todo> todos, final String name);}

public interface TodoServiceAsync { public void load(final String name, final AsyncCallback<List<Todo>> result); public void save(final List<Todo> todos, final String name, final AsyncCallback<Void> result);}

1) Server-Side Service Implementation

2) Server-Side Service Interface

3) Client-Side Async-Interface

GWT-RPC in Java

Page 12: Auto-GWT : Better GWT Programming with Xtend

1) Server-Side Service Implementation

GWT-RPC in Xtend

@GwtServiceclass TodoServiceImpl {

override List<Todo> load(String name) {return memcacheService.get(name) as List<Todo>

}

override void save(List<Todo> todos, String name) {memcacheService.put(name, todos)

}}

@GwtService adds the needed boilerplate during compilation.

Page 13: Auto-GWT : Better GWT Programming with Xtend

Building UIs Programmaticallywith Xtend

Page 14: Auto-GWT : Better GWT Programming with Xtend

FlowPanel view = new FlowPanel();view.setStyleName("view");...Label label = new Label();label.setText(todo.getText());view.add(label);Button button = new Button();button.setStyleName("destroy");view.add(button);button.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { deleteTodo(todo); }});

Imperative UIs in Java

Page 15: Auto-GWT : Better GWT Programming with Xtend

flowPanel [ styleName = 'view' ... label [ text = todo.text ] button [ styleName = 'destroy' onClick [ deleteTodo(todo) ] ]]

Declarative UIs in Xtend

That’s a so called Builder API

Page 16: Auto-GWT : Better GWT Programming with Xtend

Declarative UI Design using

Page 17: Auto-GWT : Better GWT Programming with Xtend

<section id="todoapp"><header id="header">

<h1>todos</h1><g:TextBox ui:field="todoText"/>

</header>

<section ui:field="mainSection"><input ui:field="toggleAll" type="checkbox"></input><label for="toggle-all">Mark all as complete</label><ul id="todo-list"> <g:FlowPanel ui:field="todoPanel"></g:FlowPanel></ul>

</section>

<footer ui:field="todoStatsContainer"><span id="todo-count">

<strong class="number" ui:field="remainingTodosCount"></strong><span class="word" ui:field="remainingTodosLabel"></span>left.

</span><g:Button ui:field="clearCompleted">

Clear completed (<span class="number-done" ui:field="clearTodosCount"></span>)</g:Button>

</footer></section>

The XML

Page 18: Auto-GWT : Better GWT Programming with Xtend

public class ToDoView extends Composite { interface ToDoViewUiBinder extends UiBinder<Widget,ToDoView> { } private static ToDoViewUiBinder uiBinder = GWT.create(ToDoViewUiBinder.class); @UiField protected SpanElement clearTodosCount; @UiField protected SpanElement remainingTodosLabel; @UiField protected FlowPanel todoPanel; @UiField protected InputElement toggleAll; @UiField protected Element remainingTodosCount; @UiField protected Button clearCompleted; @UiField protected TextBox todoText; @UiField protected Element mainSection; @UiField protected Element todoStatsContainer;

// ... actual implementation}

Here’s the boilerplate!

Page 19: Auto-GWT : Better GWT Programming with Xtend

Active Annotations Once More

@WithUiBindingclass ToDoView extends Composite { // ... actual implementation}

@WithUiBinding looks up the XML and adds the boilerplate for you.

Page 20: Auto-GWT : Better GWT Programming with Xtend

Xtend - xtendlang.org auto-gwt - auto-gwt.org todomvc - github.com/DJCordhose/todomvc-xtend-gwt

Questions?