Pro Java Fx – Developing Enterprise Applications

42
Pro JavaFX – Developing Enterprise Applications Stephen Chin Inovis, Inc.

Transcript of Pro Java Fx – Developing Enterprise Applications

Page 1: Pro Java Fx – Developing Enterprise Applications

Pro JavaFX – Developing Enterprise Applications

Stephen ChinInovis, Inc.

Page 2: Pro Java Fx – Developing Enterprise Applications

About the PresenterDirector SWE,

Inovis, Inc.> MBA> Belotti Award> Uber

ScrumMaster> XP Coach> Agile

Evangelist

Open-Source JavaFX Hacker

> WidgetFX> JFXtras> FEST-JavaFX> Piccolo2D> Java Champion> JavaOne Rockstar> JUG Leader> Pro JavaFX Author

2

Motorcyclist

Family Man

Page 3: Pro Java Fx – Developing Enterprise Applications

LearnFX and Win at Devoxx

Tweet to answer:> @projavafxcourse your-answer-here

3

Page 4: Pro Java Fx – Developing Enterprise Applications

Enterprise JavaFX Agenda

> JFXtras Layouts and Controls

> Automated JavaFX Testing

> Sample Enterprise Applications

4

HttpRequest { location: http://steveonjava.com/ onResponseMessage: function(m) { println(m); FX.exit()}}.start();@projavafxcourse answer

4

Page 5: Pro Java Fx – Developing Enterprise Applications

5

JFXtras Layouts and Controls

HttpRequest { location: http://steveonjava.com/ onResponseMessage: function(m) { println(m); FX.exit()}}.start();@projavafxcourse answer

Page 6: Pro Java Fx – Developing Enterprise Applications

6

JFXtras 0.6 Controls

> XCalendarPicker> XMenu> XMultiLineTextBox> XPane> XPasswordPane> XPicker

> XScrollView> XShelfView> XSpinnerWheel> XTableView> XTreeView

Page 7: Pro Java Fx – Developing Enterprise Applications

XPicker

> Multiple Picker Types Side Scroll Drop Down Thumb Wheel Side/Thumb Nudge

> Supports All Events Mouse Clicks Mouse Wheel Keyboard

7

Page 8: Pro Java Fx – Developing Enterprise Applications

XCalendarPicker

> Configurable Locale> Multiple Selection Modes

Single Multiple Range

> Completely Skinnable

8

Page 9: Pro Java Fx – Developing Enterprise Applications

JFXtras Data Providers

DataProvider

ObjectDataProvider SequenceObject-DataProvider

ParallelSequence-DataProvider

SequenceData-Provider

MapDataProvider

9

Page 10: Pro Java Fx – Developing Enterprise Applications

XShelfView

> High Performance> Features:

Scrollbar Image Title Reflection Effect Aspect Ratio Infinite Repeat

> Integrates With JFXtras Data Providers> Automatically Updates on Model Changes

10

Page 11: Pro Java Fx – Developing Enterprise Applications

XTreeView

> Hierarchical data representation> Supports JFXtras Data Model> Can add arbitrary nodes> Vertical and horizontal scrollbars> Mouse wheel navigation

11

Page 12: Pro Java Fx – Developing Enterprise Applications

XTableView> Insanely Scalable

Up to 16 million rows> Extreme Performance

Pools rendered nodes Caches images Optimized scene graph

> Features: Drag-and-Drop Column Reordering Dynamic Updating from Model Automatically Populates Column Headers Fully Styleable via CSS

12

Page 13: Pro Java Fx – Developing Enterprise Applications

SpeedReaderFX

> Read News, Twitter, and RSS in one place!> Showcases use of JFXtras Layouts and Controls

XMenu XTableView XPicker

> Contributed back to the JFXtras Samples Project

13

Written by Jim Weaver

Page 14: Pro Java Fx – Developing Enterprise Applications

JFXtras 0.6 Release Date: 11/23/2009

14

Open Source Project (BSD License)Join and help us out at:http://jfxtras.org/

Page 15: Pro Java Fx – Developing Enterprise Applications

15

Testing With FEST-JavaFX

HttpRequest { location: http://steveonjava.com/ onResponseMessage: function(m) { println(m); FX.exit()}}.start();@projavafxcourse answer

Page 16: Pro Java Fx – Developing Enterprise Applications

16

GUI Tests

Acceptance Tests

Unit Testing

Mike Cohn’s Testing Pyramid

BDD

Robot(coming soon)

FluentAssertions

Page 17: Pro Java Fx – Developing Enterprise Applications

17

Basic Test Format

Test { say: "A sequence should initially be empty" do: function() { var sequence:String[]; return sequence.size(); } expect: equalTo(0)}.perform();

Page 18: Pro Java Fx – Developing Enterprise Applications

Fluent Assertions

> anything> is> isNot> equalTo> closeTo> greaterThan

> lessThanOrCloseTo> greaterThanOrCloseTo> lessThanOrEqualTo> greaterThanorEqualTo> typeIs> instanceOf

18

> import org.jfxtras.test.Expect.*;Make sure to include this static import:

And then chain any of these assertions:

Page 19: Pro Java Fx – Developing Enterprise Applications

Fluent Assertion Examples

> isNot(null)> isNot(closeTo(floor(i*1.5)))

> lessThanOrEqualTo(2.0)> greaterThanOrCloseTo(123.10, 0.0100000)> isNot(lessThanOrCloseTo(2.1435, 0.00011))

> typeIs("org.jfxtras.test.UserXException")> instanceOf(UserXException {}.getJFXClass())

19

Page 20: Pro Java Fx – Developing Enterprise Applications

Testing Quiz: Which test will fail?

Test { say: "ranges" do: function() { seq[0..2] } expect: equalTo([1, 3, 5])}

Test { say: "exclusive ends" do: function() { seq[0..<2] } expect: equalTo([1, 3])}

Test { say: "open ends" do: function() { seq[2..] } expect: equalTo([5])}

Test { say: "open exclusive ends" do: function() { seq[2..<] } expect: equalTo([5, 7])}

20

var seq = [1, 3, 5, 7, 9];

1

3

2

4

Page 21: Pro Java Fx – Developing Enterprise Applications

Parameterized Testing

Test { say: "A Calculator should" var calculator = Calculator {} test: [ for (a in [0..9], b in [0..9]) { Test { say: "add {a} + {b}" do: function() {calculator.add(a, b)} expect: equalTo("{a + b}") } } ]}.perform();

21

Page 22: Pro Java Fx – Developing Enterprise Applications

Parameterized Testing - Output

> test: A Calculator should add 0 + 0.> test: A Calculator should add 0 + 1.> test: A Calculator should add 0 + 2.> test: A Calculator should add 0 + 3.> test: A Calculator should add 0 + 4.> test: A Calculator should add 0 + 5.> test: A Calculator should add 0 + 6.> test: A Calculator should add 0 + 7.> test: A Calculator should add 0 + 8.> test: A Calculator should add 0 + 9.> test: A Calculator should add 1 + 0.> ...> Test Results: 100 passed, 0 failed, 0 skipped.> Test run was successful!

22

Page 23: Pro Java Fx – Developing Enterprise Applications

Parameterized Testing with AssumeTest { say: "A Calculator should" var calculator = Calculator {} test: [ for (aInt in [0..9], bInt in [1..9]) { var a = aInt as Number; var b = bInt as Number; [ Test { assume: that(a / b, closeTo(floor(a / b))) say: "divide {a} / {b} without a decimal" do: function() {calculator.divide(a, b)} expect: equalTo("{(a / b) as Integer}") }, Test { assume: that(a / b, isNot(closeTo(floor(a / b)))) say: "divide {a} / {b} with a decimal" do: function() {calculator.divide(a, b)} expect: equalTo("{a / b}") } ] } ]}.perform();

23

Page 24: Pro Java Fx – Developing Enterprise Applications

Parameterized Testing with Assume - Outputtest: A Calculator should divide 0.0 / 1.0 without a decimal.test: A Calculator should divide 0.0 / 2.0 without a decimal.test: A Calculator should divide 0.0 / 3.0 without a decimal.test: A Calculator should divide 0.0 / 4.0 without a decimal.test: A Calculator should divide 0.0 / 5.0 without a decimal.test: A Calculator should divide 0.0 / 6.0 without a decimal.test: A Calculator should divide 0.0 / 7.0 without a decimal.test: A Calculator should divide 0.0 / 8.0 without a decimal.test: A Calculator should divide 0.0 / 9.0 without a decimal.test: A Calculator should divide 1.0 / 1.0 without a decimal.test: A Calculator should divide 1.0 / 2.0 with a decimal.test: A Calculator should divide 1.0 / 3.0 with a decimal.test: A Calculator should divide 1.0 / 4.0 with a decimal.test: A Calculator should divide 1.0 / 5.0 with a decimal.test: A Calculator should divide 1.0 / 6.0 with a decimal.test: A Calculator should divide 1.0 / 7.0 with a decimal.test: A Calculator should divide 1.0 / 8.0 with a decimal.test: A Calculator should divide 1.0 / 9.0 with a decimal....Test Results: 90 passed, 0 failed, 90 skipped.Test run was successful!

24

Page 25: Pro Java Fx – Developing Enterprise Applications

Run Tests in JUnit Part 1: Extend Test

public class BasicTest extends Test {}

public function run() { Test { say: "A sequence should initially be empty" do: function() { var sequence:String[]; return sequence.size(); } expect: equalTo(0) }.perform();}

25

Page 26: Pro Java Fx – Developing Enterprise Applications

Run Tests in JUnit Part 2: Create Ant Target

26

<junit dir="${work.dir}" fork="true" showoutput="true"> <batchtest todir="${build.test.results.dir}"> <fileset dir="${build.classes.dir}" excludes="**/*$*.class" includes=" **/*?Test.class"/> </batchtest> <classpath refid="test.classpath"/> <formatter type="brief" usefile="false"/> <formatter type="xml"/></junit>

Run off classes dir Exclude inner classes

Include class files ending in Test

Page 27: Pro Java Fx – Developing Enterprise Applications

Run Tests in JUnit Part 3: Execute Ant Script

27

Page 28: Pro Java Fx – Developing Enterprise Applications

REST or SOAP – Have it your way!

28

Sample Enterprise Applications

Soap bars in Lille, Northern France. 

http://www.flickr.com/photos/gpwarlow/ / CC BY 2.0

Page 29: Pro Java Fx – Developing Enterprise Applications

29

Calling a REST Service

> REST URL:http://api.meetup.com/rsvps.json/event_id=

{eventId}&key={apiKey}Output:{ "results": [ {"zip":"94044","lon":"-

122.48999786376953","photo_url":"http:\/\/photos1.meetupstatic.com\/photos\/member\/1\/4\/b\/a\/member_5333306.jpeg","response":"no","name":"Andres Almiray","comment":"Can't make it :-("}

]}

Page 30: Pro Java Fx – Developing Enterprise Applications

JUG Spinner - JSONHandler in 3 Stepspublic class Member { public var place:Integer; public var photoUrl:String; public var name:String; public var comment:String;}

var memberParser:JSONHandler = JSONHandler {  rootClass: "org.jfxtras.jugspinner.data.MemberSearch “  onDone: function(obj, isSequence): Void {    members = (obj as MemberSearch).results;}}

req = HttpRequest { location: rsvpQuery onInput: function(is: java.io.InputStream) { memberParser.parse(is);}}

30

1POJfxO

2JSONHandler

3HttpRequest

Page 31: Pro Java Fx – Developing Enterprise Applications

JUG Prize Spinner Demo

31

Featured in:Enterprise Web 2.0 FundamentalsBy Oswald Campesato & Kevin Nilson

Page 32: Pro Java Fx – Developing Enterprise Applications

32

Enterprise Widget Tutorial

Page 33: Pro Java Fx – Developing Enterprise Applications

Use Case: Tracking Agile Development

33

Page 34: Pro Java Fx – Developing Enterprise Applications

Architecture: WidgetFX Framework

> Reasons for choosing WidgetFX:

Supports Widgets in JavaFX and Java

Commercial Friendly Open-Source

Robust Security Model

Cross-platform Support

34

Page 35: Pro Java Fx – Developing Enterprise Applications

Design: Using the Production Suite 1

35

Page 36: Pro Java Fx – Developing Enterprise Applications

Design: Using the Production Suite 2

36

Page 37: Pro Java Fx – Developing Enterprise Applications

Develop: Binding the Code to Graphics

1. Add the FXZ to your project

2. Right click and Generate UI stub

3. Choose a filename and generate

4. Construct a UI Node and add it to the Scene:var rallyWidgetUI:RallyWidgetUI = RallyWidgetUI {}

37

Page 38: Pro Java Fx – Developing Enterprise Applications

Develop: Calling SOAP From JavaFX

> Generate SOAP Stubs off WSDL:WSDL2Java -uri Rally.wsdl -o src -p rallyws.api

> Create a new Service:rallyService = new

RallyServiceServiceLocator().getRallyService();

> Invoke the Service from Java or JavaFX:QueryResult result = rallyService.query(null,

"Iteration", queryString, "Name", true, 0, 100); or JavaFX code:

38

Page 39: Pro Java Fx – Developing Enterprise Applications

RallyWidget Demo

39

Page 40: Pro Java Fx – Developing Enterprise Applications

JavaFXpert RIA Exemplar Challenge

> "Create an application in JavaFX that exemplifies the appearance and behavior of a next-generation enterprise RIA (rich internet application)".

> Grand Prize: $2,000 USD

> (split between a two-man graphics artist and application developer team)

> Deadline: 10 January, 2010> For more info: http://learnjavafx.typepad.com/

40

Page 41: Pro Java Fx – Developing Enterprise Applications

LearnFX and Win at Devoxx

41

Page 42: Pro Java Fx – Developing Enterprise Applications

42

Stephen Chinhttp://steveonjava.com/Tweet: steveonjava

Thank You