Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

JSR377: Desktop Java

408 views

Published on

JSR377: Desktop Java

Published in: Technology
  • Be the first to comment

  • Be the first to like this

JSR377: Desktop Java

  1. 1. ANDRES ALMIRAY @AALMIRAY ANDRESALMIRAY.COM JSR 377 DESKTOP JAVA
  2. 2. @aalmiray
  3. 3. @aalmiray JCP Executive Committee Associate Seat Committer Committer JSR377 Specification Lead
  4. 4. @aalmiray PREVIOUS ATTEMPTS JSR 193 – Client Side Container JSR 296 – Swing Application Framework JSR 295 – Beans Binding JSR 296 had the following goals application life cycle localized resources (and injection) persisted session state loosely coupled actions targeted only Swing for obvious reasons
  5. 5. @aalmiray WHICH UI TOOLKIT?
  6. 6. @aalmiray FRAMEWORKS Eclipse 4 Platform, NetBeans Griffon, Basilisk, Gluon Particle, DataFX, JacpFX, MvvmFX, JVx, JRebirth, and more …
  7. 7. @aalmiray FRAMEWORKS Many of the listed frameworks offer the following capabilities implemented in different ways: application life cycle localized resources (and injection) persisted session state loosely coupled actions dependency injection event system centralized error management extension points via plugins
  8. 8. @aalmiray TARGET ENVIRONMENT All of the listed frameworks support the Desktop as target environment. Only a few can be used in an Embedded environment (where Java SE is supported). Embedded Java UI applications can be built as applications that target the Desktop; share codebase even.
  9. 9. @aalmiray GOALS OF JSR 377 Target Desktop and Embedded environments Support several toolkits Be an standalone JSR, i.e, no need to include it in the JDK Leverage existing JSRs: JSR 330 – Dependency Injection JSR 382 – JavaConfig (?)
  10. 10. @aalmiray CORE FEATURES application life cycle localized resources (and injection) configuration (*) loosely coupled actions dependency injection event system centralized error management extension points via plugins
  11. 11. @aalmiray APPLICATION PHASES package javax.application; public enum ApplicationPhase { INITIALIZE, STARTUP, READY, MAIN, SHUTDOWN }
  12. 12. @aalmiray APPLICATION LIFECYCLE packahe javax.application; public interface Application { void initialize(); void startup(); void ready(); boolean shutdown(); boolean canShutdown(); void addShutdownHandler(ShutdownHandler handler); void removeShutdownHandler(ShutdownHandler handler); }
  13. 13. @aalmiray APPLICATION PROPERTIES package javax.application; public interface Application { . . . Configuration getConfiguration(); ApplicationPhase getPhase(); Locale getLocale(); String[] getStartupArguments(); . . . }
  14. 14. @aalmiray UI THREADING Toolkit | isUIThread | runSync | runAsync Swing | yes | yes | yes JavaFX | yes | no | yes SWT | yes | yes | yes Pivot | yes | yes | yes Lanterna | yes | yes | no
  15. 15. @aalmiray UI THREADING package javax.application; public interface ThreadingHandler { boolean isUIThread(); void executeInsideUIAsync(Runnable r); void executeInsideUISync(Runnable r); <R> R executeInsideUISync(Callable<R> c); void executeOutsideUI(Runnable r); void executeOutsideUIAsync(Runnable r); <R> CompletionStage<R> executeOutsideUIAsync(Callable<R> c); <R> CompletionStage<R> executeInsideUIAsync(Callable<R> c); }
  16. 16. @aalmiray I18N package javax.application; public interface MessageSource { String getMessage(String key) throws NoSuchMessageException; String getMessage(String key, String defaultValue); } Combined arguments (Object[] and/or List), Locale
  17. 17. @aalmiray RESOURCE INJECTION (1) package javax.application; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.METHOD}) public @interface InjectedResource { String key() default ""; String[] args() default {}; String defaultValue() default ""; String format() default ""; }
  18. 18. @aalmiray RESOURCE INJECTION (1) import javax.application.resources.InjectedResource; import javafx.scene.paint.LinearGradient; public class SomeBean { @InjectedResource private LinearGradient gradient; }
  19. 19. @aalmiray RESOURCE INJECTION (2) import javax.application.resources.Resource; import javax.inject.Inject; import javafx.scene.paint.LinearGradient; public class SomeBean { @Inject @Resource private LinearGradient gradient; }
  20. 20. @aalmiray ACTIONS import javax.application.action.ActionHandler; public class SampleController { @ActionHandler public void click() { // do some work } }
  21. 21. @aalmiray ACTIONS Action Metadata will be derived from context -  method name -> action name Action Metadata may be configured via resources -  Name -  Description (possibly used as tooltip text) -  Icon -  Enabled state -  and more …
  22. 22. @aalmiray EVENTS (PRODUCER) import javax.application.event.EventPublisher; public class SampleController { @Inject private EventBus eventBus; public void click() { // do some work eventBus.publishAsync( new PurchaseOrderPlacedEvent()); } }
  23. 23. @aalmiray EVENTS (CONSUMER) import javax.application.event.EventPublisher; import javax.application.event.EventHandler; public class SampleService { @Inject private EventBus eventBus; @PostConstruct private void init() { eventBus.subscribe(this); } @PreDestroy private void destroy() { eventBus.unsubscribe(this); } @EventHandler public void handlePurchaseOrderPlaced(PurchaseOrderPlacedEvent evt) { // handle the event } }
  24. 24. @aalmiray CONFIGURATION (1) •  Configuration is typically read-only. •  Configuration sources will discovered from the classpath •  Configuration sources may use any available format -  Text => properties files, XML, JSON, YAML, etc. -  Code => Java Resource bundle, Groovy Script, etc. •  Type conversion may be required •  Support 2 modes: •  explicit: pull values out form a Configuration instance. •  implicit: injected values via @Inject @Configuration.
  25. 25. @aalmiray CONFIGURATION (2) •  JSR-382 (JavaConfig) provides some of the features we require. •  However ist API is not fully compatible (yet) with our needs. •  Converter API assumes source type to be always a String •  The Converter API must be reused with the Resources API, where source types may not be of type String.
  26. 26. @aalmiray RESOURCES Desktop|Embedded Application API https://jcp.org/en/jsr/detail?id=377 https://github.com/jsr377/ http://jsr377.github.io/site/
  27. 27. @aalmiray
  28. 28. @aalmiray HTTP://ANDRESALMIRAY.COM/NEWSLETTER HTTP://ANDRESALMIRAY.COM/EDITORIAL
  29. 29. THANK YOU! ANDRES ALMIRAY @AALMIRAY ANDRESALMIRAY.COM

×