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.

Rapid prototyping of eclipse rcp applications 2017

227 views

Published on

Quick prototyping of Eclipse RCP Applications using JPA, JAXB, Eclipse E4 and WindowBuilder. Presentation at Eclipse Con France 2017.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Rapid prototyping of eclipse rcp applications 2017

  1. 1. Rapid Prototyping of Eclipse RCP Applications So, you want to create a quick RCP prototype for a client?
  2. 2. About us • Speaker • Patrik Suzzi, www.asegno.com Eclipse Platform Committer, Consultant Software Engineer • Audience • Are you familiar with JAXB, JPA, Eclipse E4 and WindowBuilder?
  3. 3. IDE and Tools • Eclipse IDE for RCP and RAP development (Oxygen RC3) + Nebula Widgets (to use XY Graph) http://download.eclipse.org/nebula/releases/latest + WindowBuilder (if not already installed in Eclipse IDE for RCP..) http://download.eclipse.org/windowbuilder/WB/integration/4.7/ • Libraries + EclipseLink (JPA and JAXB) https://www.eclipse.org/eclipselink/downloads/
  4. 4. Steps to build a prototype (Banking) • Data Model • JAXB and JPA Annotations • Test persistence • E4 Application • Simple UI • Complex UI • Working Example
  5. 5. Data Model • Customer • Account • Transaction
  6. 6. Mock Data Bank bank = new Bank(); // bank.setName("Demo Bank"); // create customers Customer c1 = new Customer("Tom", "Jones", "Garden Street 8", "tjones@test.com", "1998-04-06"); Customer c2 = new Customer("Diana", "Jones", "Garden Street 8", "djones@test.com", "1999-11-12"); Customer c3 = new Customer("Mark", "Reuters", "Maple Street 122", "mr@dot.com", "1958-03-18"); Customer c4 = new Customer("Spencer", "White", "Avenue Pontida 1", "swhite@site.com", "2000-01-05"); Customer c5 = new Customer("Alex", "Michaelson", "Red Square 14b", "alex@oxygen.com", "1982-05-06"); Customer c6 = new Customer("Francois", "Berger", "Frederickstrasse 87", "fberger@main.com", "1998-04-06"); bank.addCustomers(c1,c2,c3,c4,c5,c6); // add accounts and link to customers Account a1 = new Account().link(c1); Account a2 = new Account().link(c1, c2); Account a3 = new Account().link(c3); Account a4 = new Account().link(c4); Account a5 = new Account().link(c5); Account a6 = new Account().link(c6); Account a7 = new Account().link(c6); bank.addAccounts(a1,a2,a3,a4,a5,a6,a7); // add transactions Transaction t1 = new Deposit().create(5000, a1).confirm("2016-02-20").process(); Transaction t2 = new Charge().create(250, a1).confirm("2016-03-10").process(); Transaction t3 = new Transfer().create(1000, a1, a2).confirm("2016-04-05").process(); Transaction t4 = new Deposit().create(10000, a3).confirm("2016-04-06").process(); Transaction t5 = new Deposit().create(5000, a3).confirm("2016-04-10").process(); Transaction t6 = new Deposit().create(5000, a3).confirm("2016-06-21").process(); Transaction t7 = new Deposit().create(10000, a3).confirm("2016-06-23").process(); Transaction t8 = new Withdrawal().create(2500, a3).confirm("2016-07-01").process(); Transaction t9 = new Charge().create(1500, a3).confirm("2016-07-03").process(); Transaction t10 = new Transfer().create(1000, a3, a2).confirm("2016-07-05").process(); bank.addTransactions(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10);
  7. 7. JAXB Annotations @XmlSeeAlso Super/subclasses @XmlRootElement @XmlElement @XmlAttribute, @XmlID ID as attribute @XmlList, @XmlIDREF List of references
  8. 8. XML Persistence • Save and Load with JAXB public static void persistXml(File xmlFile, Bank bank) { JAXBContext jaxbContext = JAXBContext.newInstance(Bank.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(bank, xmlFile); } public static Bank loadXml(File xmlFile) { JAXBContext jaxbContext = JAXBContext.newInstance(Bank.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); Bank bank = (Bank) unmarshaller.unmarshal(xmlFile); return bank; } Usage: TestPersistence.java
  9. 9. JPA 2 Annotations @MappedSuperclass Superclasses @Entity, @Table @OneToMany, @JoinColumn One-way association with reference @ID @Inheritance, @DiscriminatorColumn Single-table Inheritance, superclass @DiscriminatorValue Single-table Inheritance, subclass
  10. 10. DB Persistence • Persist and Load with JPA public static void persistDB(Bank bank){ EntityManager em = instance().getEntityManager(); em.getTransaction().begin(); em.merge(bank); em.flush(); em.getTransaction().commit(); } public static Bank loadDB() throws JAXBException { EntityManager em = instance().getEntityManager(); em.getTransaction().begin(); TypedQuery<Bank> query = em.createQuery(SELECT_BANK, Bank.class); Bank bank = query.getSingleResult(); return bank; } Usage: TestPersistence.java
  11. 11. E4 RCP Application • E4 Model Editor • Perspectives • Views • ... • 3 perspectives • Customers • Accounts • Transactions demo/step1: E4 App
  12. 12. Customers perspective • Search • Select • Edit user Filter/search select edit
  13. 13. Window Builder, Simple UI • Visual Designer • Data Binding • Custom code public void setModel(Bank model) { if(model==null) return; disposeBindings(m_bindingContext); super.setModel(model); if(listViewer==null) return; m_bindingContext = initDataBindings(); update(); } @Inject @Optional private void modelModified(@UIEventTopic(EventConstants.TOPIC_MODEL_MODIFIED) Account account) { update(); } // User Interaction .. demo/step2: simple UI
  14. 14. Window Builder, Complex UI • Canvas • Table Data Binding • Custom code private void update() { tableViewer.refresh(); tableViewer_1.refresh(); resizeColumns(table); resizeColumns(table_1); LightweightSystem lws = new LightweightSystem(canvas); ChartHelper.generateGraph(lws, getModel()); } demo/step3: complex UI
  15. 15. Accounts perspective • Search • Balance chart • Tables Filter/search
  16. 16. Transactions perspective • Search • Edit • Create new • Process transaction (...)
  17. 17. Working application • Customers • Persistence demo/step4: working application
  18. 18. Concluding • Rapid prototype, fully customizable, persist your data • Source: https://github.com/psuzzi/eclipsecon.git • Project: ecf2017/com.asegno.e4.banking • Branch demo/step1, model and persistence tests • Branch demo/step2, E4 App with Customers perspective • Branch demo/step3, E4 App with Accounts perspective • Branch demo/step4, Final prototype • Please, get in touch if you need more information. psuzzi[at]gmail[dot]com www.asegno.com
  19. 19. -1 0 Sign in and vote at eclipsecon.org

×