Designing Reusable Web Components

92
Joonas Lehtinen, PhD Vaadin Ltd - CEO vaadin.com/vaadin Designing Reusable Web Components @joonaslehtinen 18. heinäkuuta 12

Transcript of Designing Reusable Web Components

Page 1: Designing Reusable Web Components

Joonas Lehtinen, PhDVaadin Ltd - CEO

vaadin.com/vaadin

Designing Reusable Web Components

@joonaslehtinen

18. heinäkuuta 12

Page 2: Designing Reusable Web Components

Q & A

Designing Web ComponentStep-by-step

Goal• Test app

Technology•HTML5 / Canvas•Google Web Toolkit•Vaadin Framework

Agenda

18. heinäkuuta 12

Page 3: Designing Reusable Web Components

1Goal

18. heinäkuuta 12

Page 4: Designing Reusable Web Components

http://jole.virtuallypreinstalled.com/spreadsheet

18. heinäkuuta 12

Page 5: Designing Reusable Web Components

18. heinäkuuta 12

Page 6: Designing Reusable Web Components

2Technology

18. heinäkuuta 12

Page 7: Designing Reusable Web Components

18. heinäkuuta 12

Page 8: Designing Reusable Web Components

<!doctype html>

18. heinäkuuta 12

Page 9: Designing Reusable Web Components

Element Description

<article> An independent piece of content for a document e.g. blog entry, forum entry

<aside> A piece of content that is somehow related to the rest of the page

<audio> Audio media content

<canvas> A component for rendering dynamic bitmap graphics on the fly. e.g games

<command> A command that the user can invoke: a button, radio button or checkbox

<datalist> Together with the new list attribute for the <input> element can be used to make combo boxes

<details> Additional information or controls that the user can obtain on demand, to provide details on the document, or parts of it

<embed> Used for plug-in content

<figure> A piece of self-contained flow content referenced as a single unit from the main flow of the document

<figcaption> Caption for a �ÀJXUH!

<footer> Footer for a section; may contain information about author, copyright information, etc.

<header> A group of introductory or navigation aids

<hgroup> Header of a section

<keygen> A key pair generation control for user authentication in forms

<mark> A run of text in one document marker or highlighted for reference purposes

18. heinäkuuta 12

Page 10: Designing Reusable Web Components

“new shiny”

18. heinäkuuta 12

Page 11: Designing Reusable Web Components

Canvas

Drag-and-drop

Microdata

Cross-documentmessaging

Historymanagement

Document editing

Multimedia

Offline storage

Markup improvements

Forms

File APIGeolocation

CSS3

WebGL

18. heinäkuuta 12

Page 12: Designing Reusable Web Components

state

Canvas

18. heinäkuuta 12

Page 14: Designing Reusable Web Components

DZone, Inc. | www.dzone.com

Get

Mo

re R

efca

rdz!

Vis

it r

efca

rdz.

com

#151

HTM

L5 C

anva

s

By Simon Sarris

INTRODUCTION TO CANVAS

The HTML <canvas> element allows for on-the-fly creation of graphs, diagrams, games, and other visual elements and interactive media. It also allows for the rendering of 2D and 3D shapes and images, typically via JavaScript.

<canvas id=”canvas1” width=”500” height=”500”></canvas>

<script type=”text/javascript”>var can = document.getElementById(‘canvas1’);var ctx = can.getContext(‘2d’);

FW[�ÀOO7H[W�“Hello World!”, 50, 50);</script>

Canvas is perhaps the most visible part of the new HTML5 feature set, with new demos, projects, and proofs of concept appearing daily.

Canvas is a very low-level drawing surface with commands for making lines, curves, rectangles, gradients and clipping regions built in. There is very little else in the way of graphics drawing, which allows programmers to create their own methods for several basic drawing functions such as blurring, tweening, and animation. Even drawing a dotted line is something that must be done by the programmer from scratch.

Canvas is an immediate drawing surface and has no scene graph. This means that once an image or shape is drawn to it, neither the Canvas nor its drawing context have any knowledge of what was just drawn.

For instance, to draw a line and have it move around, you need to do much more than simply change the points of the line. You must clear the Canvas (or part of it) and redraw the line with the new points. This contrasts greatly with SVG, where you would simply give the line a new position and be done with it.

Hot Tip

You can visit the evolving specification for Canvas at the WHATWG site: http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html.

Browser Support and Hardware Acceleration Canvas is supported by Firefox 1.5 and later; Opera 9 and later; and newer versions of Safari, Chrome, and Internet Explorer 9 and 10.

The latest versions of these browsers support nearly all abilities of the Canvas element. A notable exception is drawFocusRing, which no browser supports effects.

Hardware acceleration is supported in some variation by all current browsers, though the performance gains differ. It is difficult to benchmark between the modern browsers because they are changing frequently, but so far IE9 seems to consistently get the most out of having a good GPU. On a machine with a good video card it is almost always the fastest at rendering massive amounts of images or canvas-to-canvas draws.

Accelerated IE9 also renders fillRect more than twice as fast as the other major browsers, allowing for impressive 2D particle effects [1]. Chrome often has the fastest path rendering but can be inconsistent between releases. All browsers render images and rects much faster than paths or text, so it is best to use images and rects if you can regardless of which browsers you are targeting.

Canvas SVG

SupportSafari, Firefox, and Opera have at least some support. Internet Explorer 9+ has support. Almost all modern smart phones.

limited support through the excanvas library.

-ers. Almost all modern smart phones.

Stateful-ness surface

remembered about their state.

surface

Other Consider-ations

must be programmed yourself.

(rendering nothing) if scripting is disabled.

10,000 objects.

objects, statefulness is built in and event handling is much easier.

many programs such as Illustrator can output SVG

animation.

Accessi-bility DOM objects

-ment functionality is strongly advised against, even in the specification itself.

disabled.

objects.

and web crawlers.

brought to you by...

CONTENTS INCLUDE:Q� Introduction to CanvasQ� �

Q�

Q� A Comparison with SVGQ� Canvas PerformanceQ� Creating a Canvas and More!

HTML 5 Canvas

18. heinäkuuta 12

Page 15: Designing Reusable Web Components

Google Web Toolkit

18. heinäkuuta 12

Page 16: Designing Reusable Web Components

Java toJavaScriptCompiler

Subset of

java.lang, java.util

Widgetset

Your Application UI

IE6

IE7

Firefox

Safari

18. heinäkuuta 12

Page 17: Designing Reusable Web Components

simpler• 100% Java• Static typing• Object oriented• Excellent tooling

18. heinäkuuta 12

Page 18: Designing Reusable Web Components

less bugs • Stop debugging

JavaScript spaghetti • Ignore most

browser differences

18. heinäkuuta 12

Page 19: Designing Reusable Web Components

client-side• UI in client• Asyncronous RPC• Services (for UI)

18. heinäkuuta 12

Page 20: Designing Reusable Web Components

18. heinäkuuta 12

Page 21: Designing Reusable Web Components

Vaadin is a UI framework

for rich web applications

18. heinäkuuta 12

Page 22: Designing Reusable Web Components

htmljava

18. heinäkuuta 12

Page 23: Designing Reusable Web Components

javascriptjavajson / xmlany language any language

Layers of abstraction

browserbrowserfrontendserver

backendserver

required optional optionalrequired

RPC

optional

Vaa

din

required optionalrequired

GW

T

requiredrequired

Ext

JS

requiredrequired

required requiredX

18. heinäkuuta 12

Page 24: Designing Reusable Web Components

Vaadin UI component architecture

Java

• Google Web Toolkit

Server UI comp.• Button, Table, Tree, ...• API you program with• State

Client UI comp. • Rendering• Event handling• Runs on JavaScript

HTTP(S)

Java

• Compiled with JDK

18. heinäkuuta 12

Page 25: Designing Reusable Web Components

How does it work, really?

18. heinäkuuta 12

Page 26: Designing Reusable Web Components

18. heinäkuuta 12

Page 27: Designing Reusable Web Components

• Initial HTML• CSS (theme)• Images• JavaScript

120k total

18. heinäkuuta 12

Page 28: Designing Reusable Web Components

• name=”Joonas”• button clicked

150 bytes

18. heinäkuuta 12

Page 29: Designing Reusable Web Components

18. heinäkuuta 12

Page 30: Designing Reusable Web Components

• name=”Joonas”• button clicked

150 bytes

• Add notification

466 bytes

18. heinäkuuta 12

Page 32: Designing Reusable Web Components

18. heinäkuuta 12

Page 33: Designing Reusable Web Components

18. heinäkuuta 12

Page 34: Designing Reusable Web Components

Download for Free

4th Edition

US $29.95

Vaadin is an open source Java framework for building modern web applications that look great, perform well and make you and

your users happy. http://vaadin.com/

2675387895299

ISBN 978-952-92-6753-890000

vaadin.com/book

674 pages

18. heinäkuuta 12

Page 35: Designing Reusable Web Components

By Marko Grönroos

ABOUT VAADIN

ww

w.d

zone

.co

m

G

et M

ore

Ref

card

z! V

isit

ref

card

z.co

m

#85

Getting Started with VaadinCONTENTS INCLUDE:�� About Vaadin�� Creating An Application�� Components �� Layout Components�� Themes�� Data Binding and more...

Vaadin is a server-side Ajax web application development framework that allows you to build web applications just like with traditional desktop frameworks, such as AWT or Swing. An application is built from user interface components contained hierarchically in layout components.

In the server-driven model, the application code runs on a server, while the actual user interaction is handled by a client-side engine running in the browser. The client-server communications and any client-side technologies, such as HTML and JavaScript, are invisible to the developer. As the client-side engine runs as JavaScript in the browser, there is no need to install plug-ins. Vaadin is released under the Apache License 2.0.

Figure 1: Vaadin Client-Server Architecture

If the built-in selection of components is not enough, you can develop new components with the Google Web Toolkit (GWT)

Figure 2: Architecture for Vaadin Applications

Hot Tip

You can get a reference to the application object from any component attached to the application with ��$!!����$� ���

Event ListenersIn the event-driven model, user interaction with user interface components triggers server-side events, which you can handle

Web BrowserClient-Side Engine

JavaWeb Server

VaadinUIComponents

YourJavaApplication

WebService

EJB

DB

Servlet Container

UserApplication

EventListener

DataModel

ApplicationThemes

ApplicationResources

DefaultTheme

FileResources

ExternalResources

Database

DataBinding

Inherits Events Changes

AJAX Requests

Inherits

UIComponent

JavaServlet

ApplicationClass

Web BrowserClient-Side Engine

brought to you by...

18. heinäkuuta 12

Page 36: Designing Reusable Web Components

DesigningStep-by-step

18. heinäkuuta 12

Page 37: Designing Reusable Web Components

3DesigningStep-by-step

18. heinäkuuta 12

Page 38: Designing Reusable Web Components

18. heinäkuuta 12

Page 39: Designing Reusable Web Components

18. heinäkuuta 12

Page 40: Designing Reusable Web Components

NeedWe can not get

the UX we need with the existing

widgets

18. heinäkuuta 12

Page 41: Designing Reusable Web Components

Goals• List of • real• quantifiable• requirements• for UX

18. heinäkuuta 12

Page 42: Designing Reusable Web Components

• Load and view data in XLS files• Show visual overview for numeric cols• Must support 1000 cell tables• Supports the latest Firefox & Chrome

Example goals

18. heinäkuuta 12

Page 43: Designing Reusable Web Components

Nail downthe minimum viable

set of supportedbrowser versionswith the customer

18. heinäkuuta 12

Page 44: Designing Reusable Web Components

Idea =UX [how it is used]+ Tech [how it works]

18. heinäkuuta 12

Page 45: Designing Reusable Web Components

18. heinäkuuta 12

Page 46: Designing Reusable Web Components

18. heinäkuuta 12

Page 47: Designing Reusable Web Components

Always start fromdefined goals -

never let idea torule your design

18. heinäkuuta 12

Page 48: Designing Reusable Web Components

18. heinäkuuta 12

Page 49: Designing Reusable Web Components

Works with target browsers?

18. heinäkuuta 12

Page 50: Designing Reusable Web Components

Interactions work with target browsers?

Performance is good enough for target data?

18. heinäkuuta 12

Page 51: Designing Reusable Web Components

Proto DOD • Includes main use-cases• Works in target browsers• Handles enough data

18. heinäkuuta 12

Page 52: Designing Reusable Web Components

Never start design or implementation before

prototyping browser compatibility

and performance

18. heinäkuuta 12

Page 53: Designing Reusable Web Components

18. heinäkuuta 12

Page 54: Designing Reusable Web Components

Design UX and API first. Never continue from

the prototypeimplementation

18. heinäkuuta 12

Page 55: Designing Reusable Web Components

Drawing detailedwireframes and mockups

and testing them withusers will save

time later

18. heinäkuuta 12

Page 56: Designing Reusable Web Components

18. heinäkuuta 12

Page 57: Designing Reusable Web Components

Shamelessly copy UX.Then your users already

know how to use it.

18. heinäkuuta 12

Page 58: Designing Reusable Web Components

18. heinäkuuta 12

Page 59: Designing Reusable Web Components

Aim for multilayereddesign that lets yourusers (developers)change behavior of

your component

18. heinäkuuta 12

Page 60: Designing Reusable Web Components

18. heinäkuuta 12

Page 61: Designing Reusable Web Components

DOM classes and CSS restrictions

must be documentedto make styling easy

18. heinäkuuta 12

Page 62: Designing Reusable Web Components

18. heinäkuuta 12

Page 63: Designing Reusable Web Components

Keep componentproject separatefrom your real

application project

18. heinäkuuta 12

Page 64: Designing Reusable Web Components

Demo applicationmust include all features

and serve as examplefor your users

18. heinäkuuta 12

Page 65: Designing Reusable Web Components

18. heinäkuuta 12

Page 66: Designing Reusable Web Components

Invest in projectsetup with a rapid

save-to-see cycle and a robust build script. These

might not be the samething.

18. heinäkuuta 12

Page 67: Designing Reusable Web Components

https://vaadin.com/wiki/-/wiki/Main/Component+Add-on+Project+Setup+HOWTO

18. heinäkuuta 12

Page 68: Designing Reusable Web Components

18. heinäkuuta 12

Page 69: Designing Reusable Web Components

There is no substitutefor manual testing anduser experience testing

18. heinäkuuta 12

Page 70: Designing Reusable Web Components

Skip test driven development, but invest

in regression testing

18. heinäkuuta 12

Page 71: Designing Reusable Web Components

Pixel level regression tests take time to set up, but will be worth it

18. heinäkuuta 12

Page 72: Designing Reusable Web Components

Never trust thatyour changes would notbreak other browsers

and skip cross-browser testing

18. heinäkuuta 12

Page 73: Designing Reusable Web Components

It is impossible to usetoo much time in polishing UX for a

reusable component.

18. heinäkuuta 12

Page 74: Designing Reusable Web Components

18. heinäkuuta 12

Page 75: Designing Reusable Web Components

commit 7453f467b1

Latest commit to the master branch

Update README.markdown

jojule authored 4 hours ago

Tags Downloads

jojulejojule / / spreadsheetspreadsheet

Files Commits Branches

1 1AdminAdmin UnwatchUnwatch ForkFork Pull RequestPull Request

CodeCode NetworkNetwork Pull Requests Pull Requests Issues Issues Wiki Wiki Stats & GraphsStats & Graphs00 00 00

SSHSSH HTTPHTTP Git Read-OnlyGit Read-Only [email protected]:jojule/spreadsheet.git Read+Write access

Simple spreadsheet component for Vaadin — Read morehttps://vaadin.com/addon/spreadsheet

Clone in Mac Clone in Mac ZIPZIP

master masterbranch:branch: 1

historyhistorynamename ageage messagemessage

design a day ago Developing [Joonas Lehtinen]

src 19 hours ago Version 0.1 [Joonas Lehtinen]

README.markdown 4 hours ago Update README.markdown [jojule]

licensing.txt 19 hours ago Version 0.1 [Joonas Lehtinen]

pom.xml 18 hours ago Fixed add-on name [Joonas Lehtinen]

README.markdown README.markdown

Spreadsheet for VaadinThe widget shows a spreadsheet - either from XLS file or by setting the cell contents programmatically.

This version is very limited and should be considered to be an early alpha -version. Try out the demo to see if it would be useful for you. Imainly built it for an upcoming presentation.

SpreadsheetView class should be also usable in GWT without Vaadin Framework, but then you must implement SpreadsheetModel byyourself.

Dependencies

Apache POI 3.8 - http://poi.apache.org/

Apache Commons Codec 1.5 - Required by POI - http://commons.apache.org/codec/

Release notes

Initial release with severe limitations:

All columns and rows have fixed sizes

No cell styling is supported

No graphs are supported

No merged cells are supported

Performance for larger spreadsheets is really bad

Only one spreadsheet widget is supported on screen at once

License & Author

Apache License 2.0

Joonas Lehtinen - https://vaadin.com/joonas

spreadsheet /

ExploreExplore GistGist BlogBlog HelpHelp jojulejojuleSearch…35

https://github.com/jojule/spreadsheet

18. heinäkuuta 12

Page 76: Designing Reusable Web Components

commit 7453f467b1

Latest commit to the master branch

Update README.markdown

jojule authored 4 hours ago

Tags Downloads

jojulejojule / / spreadsheetspreadsheet

Files Commits Branches

1 1AdminAdmin UnwatchUnwatch ForkFork Pull RequestPull Request

CodeCode NetworkNetwork Pull Requests Pull Requests Issues Issues Wiki Wiki Stats & GraphsStats & Graphs00 00 00

SSHSSH HTTPHTTP Git Read-OnlyGit Read-Only [email protected]:jojule/spreadsheet.git Read+Write access

Simple spreadsheet component for Vaadin — Read morehttps://vaadin.com/addon/spreadsheet

Clone in Mac Clone in Mac ZIPZIP

master master 1

historyhistorynamename ageage messagemessage

design a day ago Developing [Joonas Lehtinen]

src 19 hours ago Version 0.1 [Joonas Lehtinen]

README.markdown 4 hours ago Update README.markdown [jojule]

licensing.txt 19 hours ago Version 0.1 [Joonas Lehtinen]

pom.xml 18 hours ago Fixed add-on name [Joonas Lehtinen]

README.markdown README.markdown

Spreadsheet for VaadinThe widget shows a spreadsheet - either from XLS file or by setting the cell contents programmatically.

This version is very limited and should be considered to be an early alpha -version. Try out the demo to see if it would be useful for you. Imainly built it for an upcoming presentation.

SpreadsheetView class should be also usable in GWT without Vaadin Framework, but then you must implement SpreadsheetModel byyourself.

Dependencies

Apache POI 3.8 - http://poi.apache.org/

Apache Commons Codec 1.5 - Required by POI - http://commons.apache.org/codec/

Release notes

Initial release with severe limitations:

All columns and rows have fixed sizes

No cell styling is supported

No graphs are supported

No merged cells are supported

Performance for larger spreadsheets is really bad

Only one spreadsheet widget is supported on screen at once

License & Author

Apache License 2.0

Joonas Lehtinen - https://vaadin.com/joonas

spreadsheet /

ExploreExplore GistGist BlogBlog HelpHelp jojulejojuleSearch…35

18. heinäkuuta 12

Page 77: Designing Reusable Web Components

18. heinäkuuta 12

Page 78: Designing Reusable Web Components

18. heinäkuuta 12

Page 79: Designing Reusable Web Components

18. heinäkuuta 12

Page 80: Designing Reusable Web Components

18. heinäkuuta 12

Page 81: Designing Reusable Web Components

18. heinäkuuta 12

Page 82: Designing Reusable Web Components

18. heinäkuuta 12

Page 83: Designing Reusable Web Components

18. heinäkuuta 12

Page 84: Designing Reusable Web Components

PaperStack notes = new PaperStack();!! @Override! public void init() {

// === Layout ========================================================! ! HorizontalLayout lo= new HorizontalLayout();! ! Window mainWindow = new Window("Postitnotes Application", lo);! ! lo.setSizeFull();! ! lo.addComponent(notes);! ! lo.setComponentAlignment(notes, Alignment.MIDDLE_CENTER);! ! setMainWindow(mainWindow);!!! ! notes.setWidth("350px");! ! notes.setHeight("350px");! !

// === Note 1 ========================================================! ! notes.addComponent(new Label("<h1>TODO / Today</h1><div style='font-size: 24px'>” +

“<p>Enjoy the conference...</p></div>", Label.CONTENT_XHTML), "#fef49c");

// === Note 2 ========================================================! ! notes.addComponent(new Label("<h1>TODO / Tomorrow</h1><div style='font-size: 24px'>” +

“<p>Learn Vaadin!</p></div>", Label.CONTENT_XHTML), "#b2ffa1");

// === Note 3 ========================================================! ! notes.addComponent(new Label("<div style='font-size: 60px'><center><br/><br/><br/>” +

“DOUBLE<br/><br/><br/>SPEED</center></div>", Label.CONTENT_XHTML), "#b2ffa1");

// === Note 4 ========================================================! ! com.vaadin.ui.RichTextArea rta = new RichTextArea();! ! rta.setSizeFull();! ! notes.addComponent(rta);! ! rta.setValue("<span style='font-size: 35pt; color: green;'>You can use any “ +

“Vaadin components here...</span>");! }

18. heinäkuuta 12

Page 85: Designing Reusable Web Components

Try out my Spreadsheet!vaadin.com/addon/spreadsheet

18. heinäkuuta 12

Page 87: Designing Reusable Web Components

18. heinäkuuta 12

Page 88: Designing Reusable Web Components

18. heinäkuuta 12

Page 89: Designing Reusable Web Components

Issue reported by actual user!

Fix immediately and thank the user who reported it

Fix after 6 months, maybe...

Ignore. wont-fix in best case.(the usual open source way)

Support HOWTO

18. heinäkuuta 12

Page 90: Designing Reusable Web Components

Q&A

18. heinäkuuta 12

Page 91: Designing Reusable Web Components

4Q&A

18. heinäkuuta 12

Page 92: Designing Reusable Web Components

Expert servicesOnline support

TrainingTools

vaadin.com/pro

[email protected] vaadin.com/joonas

@joonaslehtinen#vaadin

Slides available onslideshare

Questions?Comments?

BetterResultsFaster

18. heinäkuuta 12