Top Banner
HOW TO IMPROVE YOUR PRODUCTIVITY USING GWTP CHRISTIAN GOUDREAU GWT.create 2015
38

How to improve your productivity using GWTP

Jul 16, 2015

Download

Technology

Arcbees
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: How to improve your productivity using GWTP

HOW TO IMPROVE YOUR PRODUCTIVITY USING GWTPCHRISTIAN GOUDREAU

GWT.create 2015

Page 2: How to improve your productivity using GWTP

Motivations

HOW TO IMPROVE YOUR PRODUCTIVITY USING GWTP

➔ Scalability➔ Maintainability➔ Extensibility

Page 3: How to improve your productivity using GWTP

Architecture

HOW TO IMPROVE YOUR PRODUCTIVITY USING GWTP

➔ SOLID - Uncle Bob➔ MVP - Martin Fowler➔ Iterative and incremental

development - Craig Larman

Page 4: How to improve your productivity using GWTP

THERE’S JUST TOO MANY GOOD PRACTICES

Page 5: How to improve your productivity using GWTP

Frontend

HOW TO IMPROVE YOUR PRODUCTIVITY USING GWTP

➔ GWTP➔ REST-Dispatch➔ GSS

Page 6: How to improve your productivity using GWTP

MODEL

PRESENTER

VIEW

MVP PATTERN

Page 7: How to improve your productivity using GWTP

Presenter

HOW TO IMPROVE YOUR PRODUCTIVITY USING GWTP

Page 8: How to improve your productivity using GWTP

public class ApplicationPresenter extends Presenter<ApplicationPresenter.MyView, ApplicationPresenter.MyProxy> {

interface MyView extends View { }

@ProxyStandard interface MyProxy extends Proxy<ApplicationPresenter> { }

@ContentSlot public static final Type<RevealContentHandler<?>> SLOT_MAIN = new Type<RevealContentHandler<?>>();

@Inject ApplicationPresenter(EventBus eventBus, MyView view, MyProxy proxy) { super(eventBus, view, proxy, RevealType.RootLayout); }

@Override protected void onReveal() { }

@Override protected void onBind() { }}

Page 9: How to improve your productivity using GWTP

View

HOW TO IMPROVE YOUR PRODUCTIVITY USING GWTP

Page 10: How to improve your productivity using GWTP

public class ApplicationView extends ViewImpl implements ApplicationPresenter.MyView { interface Binder extends UiBinder<Widget, ApplicationView> { }

@UiField SimplePanel main;

@Inject ApplicationView(Binder uiBinder) { initWidget(uiBinder.createAndBindUi(this)); }

@Override public void setInSlot(Object slot, IsWidget content) { if (slot == ApplicationPresenter.SLOT_MAIN) { main.setWidget(content); } }}

Page 11: How to improve your productivity using GWTP

Model

HOW TO IMPROVE YOUR PRODUCTIVITY USING GWTP

Page 12: How to improve your productivity using GWTP

public class Dashboard { private int id;

public int getId() { return id; }

public void setId(int id) { this.id = id; }}

Page 13: How to improve your productivity using GWTP

GWTP Lifecycle

Page 14: How to improve your productivity using GWTP

Tips

HOW TO IMPROVE YOUR PRODUCTIVITY USING GWTP

➔ Use UiHandlers➔ Use the EventBus➔ Use collaborators

Page 15: How to improve your productivity using GWTP

UiHandlers and Presenter

HOW TO IMPROVE YOUR PRODUCTIVITY USING GWTP

Page 16: How to improve your productivity using GWTP

public interface FeedbackUiHandlers extends UiHandlers { void performMail(Feedback currentFeedback);}

public class FeedbackPresenter extends Presenter<FeedbackPresenter.MyView, FeedbackPresenter.MyProxy>

implements FeedbackUiHandlers {

...

@Inject FeedbackPresenter(...) { super(...);

getView().setUiHandlers(this); }

@Override public void performMail(Feedback currentFeedback) { ... }}

Page 17: How to improve your productivity using GWTP

View

HOW TO IMPROVE YOUR PRODUCTIVITY USING GWTP

Page 18: How to improve your productivity using GWTP

public class FeedbackView extends ViewWithUiHandlers<FeedbackUiHandlers> implements FeedbackPresenter.MyView {

...

@UiHandler("submit") void onClick(ClickEvent e) { getUiHandlers().performMail(feedback); }}

Page 19: How to improve your productivity using GWTP

EventBus

HOW TO IMPROVE YOUR PRODUCTIVITY USING GWTP

Page 20: How to improve your productivity using GWTP

@Overrideprotected void onReveal() { themeService.withCallback(new AbstractAsyncCallback<Theme>() { @Override public void onSuccess(Theme result) { super.onSuccess(result);

getView().edit(result); } }).getByOrganizationId(currentUser.getOrganizationId());

UpdateBreadcrumbEvent.fire(this, breadcrumbBuilder.theme());}

Page 21: How to improve your productivity using GWTP

Collaborators

HOW TO IMPROVE YOUR PRODUCTIVITY USING GWTP

Page 22: How to improve your productivity using GWTP

public interface LocationFacade { /** * Adds a new browser history entry. Calling this method will cause * {@link com.google.gwt.event.logical.shared.ValueChangeHandler * #onValueChange(com.google.gwt.event.logical.shared.ValueChangeEvent)} * to be called as well if and only if issueEvent is true. * * @param historyToken the token to associate with the new history item * @param issueEvent true if a * {@link com.google.gwt.event.logical.shared.ValueChangeHandler * #onValueChange(com.google.gwt.event.logical.shared.ValueChangeEvent)} * event should be issued */ void newItem(String historyToken, boolean issueEvent);

/** * Reloads the current browser window. All GWT state will be lost. */ void reload();

String getCurrentHash();}

Page 23: How to improve your productivity using GWTP

public class LocationFacadeImpl implements LocationFacade { @Override public void newItem(String newUrl, boolean fireEvent) { History.newItem(newUrl, fireEvent); }

@Override public native void reload() /*-{ $wnd.location.reload(true); }-*/;

@Override public String getCurrentHash() { return Location.getHash(); }}

Page 24: How to improve your productivity using GWTP

RESTDispatch

HOW TO IMPROVE YOUR PRODUCTIVITY USING GWTP

➔ JAX-RS➔ Command pattern➔ Simplest implementation

Page 25: How to improve your productivity using GWTP

RESTDispatch

HOW TO IMPROVE YOUR PRODUCTIVITY USING GWTP

➔ JAX-RS➔ Command pattern➔ Simplest implementation

Bonus

➔ Response - RestCallback➔ GWTP-Extensions - Rest-

delegatesDownside - not type safe

Page 26: How to improve your productivity using GWTP

REST Dispatch setup

HOW TO IMPROVE YOUR PRODUCTIVITY USING GWTP

Page 27: How to improve your productivity using GWTP

public class ServiceModule extends AbstractGinModule { @Override protected void configure() { install(new RestDispatchAsyncModule.Builder().build()); }

@Provides @RestApplicationPath String getApplicationPath() { String baseUrl = GWT.getHostPageBaseURL(); if (baseUrl.endsWith("/")) { baseUrl = baseUrl.substring(0, baseUrl.length() - 1); }

return baseUrl + API; }}

<inherits name="com.gwtplatform.dispatch.rest.delegates.ResourceDelegate"/><inherits name='com.gwtplatform.mvp.MvpWithEntryPoint'/>

Page 28: How to improve your productivity using GWTP

REST Dispatch usage

HOW TO IMPROVE YOUR PRODUCTIVITY USING GWTP

Page 29: How to improve your productivity using GWTP

@Path(DASHBOARDS)public interface DashboardService { @GET @Path(DASHBOARD) Dashboard getByOrganizationId(@PathParam(ORGANIZATION_ID) int organizationId);

@PUT @Path(DASHBOARD) void update(@PathParam(ORGANIZATION_ID) int organizationId, Dashboard dashboard);}

private void loadTemplate() { dashboardService.withCallback(new AbstractAsyncCallback<Dashboard>() { @Override public void onSuccess(Dashboard result) { setInSlot(SLOT_TEMPLATE, templateSelector.createTemplate(result)); } }).getByOrganizationId(currentUser.getOrganizationId());}

Page 30: How to improve your productivity using GWTP

UIDesign

HOW TO IMPROVE YOUR PRODUCTIVITY USING GWTP

➔ GSS + GSSS➔ UiBinder➔ CSS expert

Page 31: How to improve your productivity using GWTP

GSS + GSSS

HOW TO IMPROVE YOUR PRODUCTIVITY USING GWTP

Page 32: How to improve your productivity using GWTP

@Source({"com/arcbees/gsss/mixin/client/mixins.gss", "css/colors.gss", "fonts/geometria/geometria.gss", "css/style.gss"})Style style();

@Source({"com/arcbees/website/client/resources/css/gridSettings.gss", "com/arcbees/gsss/grid/client/grid.gss"})GridResources.Grid grid();

http://dev.arcbees.com/gsss/mixins/

Page 33: How to improve your productivity using GWTP

@require "colors";@require "geometria";@require "gsss-mixins";

* { box-sizing: border-box;}

html { font-size: 62.5%;}

@media (max-width: 979px) { html { font-size: 59%; }}

.selectedFile { background-color: C_PRIMARY; color: #fff;

display: inline-block; padding: .5rem .5rem .5rem 1rem;

@mixin rounded(4px);}

Page 34: How to improve your productivity using GWTP

What’s next?

HOW TO IMPROVE YOUR PRODUCTIVITY USING GWTP

➔ Full JAX-RS coverage➔ XML and custom

serializers/deserializers➔ New way of writing Presenters➔ Generator rewrite for extensibility➔ Pushstate

https://docs.google.com/a/arcbees.com/document/d/1N9dMDxTFmZzF3xNTpnP3HIuwZC9OGtPPm_QVEikMP4g/

Page 35: How to improve your productivity using GWTP

@Presenter(token = HOME, for = MyView.class, slot = ApplicationPresenter.SLOT_MAIN)@UseCodeSplit@UseGatekeeper(AclGatekeeper.class)@GatekeeperParams(ORGANIZATION_SETTINGS_DASHBOARD_READ)public class DashboardPresenter { interface MyView extends View { }

@Inject DashboardPresenter() { }

@OnReveal void onReveal() { }

@OnBind void onBind() { }

...}

Page 36: How to improve your productivity using GWTP

THANK YOU

Page 37: How to improve your productivity using GWTP

Christian GoudreauCo-Founder and Bee-EO

at Arcbees

+ChristianGoudreau@imchrisgoudreau

Page 38: How to improve your productivity using GWTP

QUESTIONS ?