rapid prototyping of eclipse rcp applications-ece2017 · transfer withdrawal #amount: double...
TRANSCRIPT
Aboutus
• Speaker• PatrikSuzzi,www.itemis.chSoftwareEngineerEclipsePlatformCommitter
• Audience• AreyoufamiliarwithJAXB,JPA?• EclipseE4andWindowBuilder?
IDEandTools
• EclipseIDEforRCPandRAPdevelopment(Oxygen.1a)+NebulaWidgets (touseXYGraph)
http://download.eclipse.org/nebula/releases/latest+WindowBuilder(ifnotalreadyinstalledinEclipseIDEforRCP..)
http://download.eclipse.org/windowbuilder/WB/integration/4.8/
• Libraries+EclipseLink(JPAandJAXB)
https://www.eclipse.org/eclipselink/downloads/+Database(Derby)
https://db.apache.org/derby/
Getting started – buildaRCPprototype
• Build your DataModel• Add Xml/DBpersistence• Testthedatamodel• Build your E4Application• StartwithaSimpleUI• Evolveit inaComplex UI• Run your prototype
DataModel
• Bank• Customer• Account• Transaction• Subtypes
• Useproperty changelisteners!
*
transactions
*customers
*
transactions
*
accounts
*
customers
*
accounts
recipientAccount
sourceAccount-creationDate: Date-balance: double
Account
Deposit
Charge
Bank
-firstName: String-lastName: String-address: String
Customer
Transfer
Withdrawal
#amount: double#confirmed: boolean#processed: boolean
Transaction
TestDataModelBank bank = new Bank();
// create customersCustomer c1 = new Customer("Tom", "Jones", "Garden Street 8");Customer c2 = new Customer("Diana", "Jones", "Garden Street 8");Customer c3 = new Customer("Mark", "Reuters", "Maple Street 122");Customer c4 = new Customer("Spencer", "White", "Avenue Pontida 1");Customer c5 = new Customer("Alex", "Michaelson", "Red Square 14b");Customer c6 = new Customer("Francois", "Berger", "Frederickstrasse 87");bank.addCustomers(c1,c2,c3,c4,c5,c6);
// add accounts and link to customersAccount 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 transactionsTransaction 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);
// test mock dataassertEquals("Nr. of Customers", 6, bank.getCustomers().size());assertEquals("Nr. of Accounts", 7, bank.getAccounts().size());assertEquals("Nr. of Transactions", 10, bank.getTransactions().size());
// test containmentassertThat("Account's customer", a1.getCustomers().contains(c1));assertThat("Customer's account", c1.getAccounts().contains(a1));assertThat("Transaction's account", t1.getSourceAccount().equals(a1));
• Testthevalidityofyourdata!
AddJAXBAnnotations@XmlRootElementpublic class Bank {...}
@XmlAttribute@XmlIDpublic String getId() {...}
@XmlList@XmlIDREFpublic List<Account> getAccounts() { ... }
• XMLtags
• AttributerepresentingID
• XMLAggregation,aslistofIDsreferencingentities
• Subclassesimplementingabstractsuperclass
@XmlSeeAlso({Deposit.class, Charge.class, Withdrawal.class, Transfer.class})@XmlRootElementpublic abstract class Transaction {...}
XMLPersistenceTest
• Save andLoadwithJAXBpublic 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
<bank id="59340">
<customers id="2711"><accounts>143365 170217</accounts><address>Garden Street 8</address><firstName>Tom</firstName><lastName>Jones</lastName>
</customers>
<accounts id="143365"><balance>3750.0</balance><creationDate>2016-02-01T00:00:00+01:00</creationDate><customers>2711</customers><transactions>110290 79075 91111</transactions>
</accounts>
<transactions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="deposit" id="110290">
<amount>5000.0</amount><confirmed>true</confirmed><confirmedDate>2016-02-20T00:00:00+01:00</confirmedDate><processed>true</processed><processedDate>2016-02-20T00:00:00+01:00</processedDate><sourceAccount>143365</sourceAccount>
</transactions></bank>
AggregationIDlist
IDattribute
Subclass
AddJPA2Annotations
• Superclasswithnotabledefinedforit
• Entitywithatabledefinedforit
• Onewayassociationwithreference
• Singletableinheritance,bydiscriminatingcolumn
• Subclasswithgivendiscriminator
@MappedSuperclasspublic class BaseModel {...}
@Entitypublic class Bank extends BaseModel{...}
@OneToMany@JoinColumn(name="BANK_ID")public List<Customer> getCustomers() {...}
@Entity@Inheritance(strategy = InheritanceType.SINGLE_TABLE)@Table(name="T_TRANSACTION")@DiscriminatorColumn(name="T_TYPE")public abstract class Transaction {...}
@Entity@DiscriminatorValue("D")public class Deposit extends Transaction {...}
DBPersistenceTest
• PersistandLoadwithJPA
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
E4RCPApplication
• Plugin project• Rich ClientApplication• E4RCPTemplate
• ModelEditor• ApplicationStructure
• Perspectives• Customers• Accounts• Transactions
SettingtheDataModel
• Application• Modelchange• TriggerEvents
• UserInterface• Frameworktriggers• InitializeUI
@Executepublic void execute(MApplication app, IEventBroker eventBroker) {
Bank bank = new Bank();app.getContext().set(Bank.class, bank);eventBroker.send(EventConstants.TOPIC_MODEL_MODIFIED, bank);
}
@Inject@Optionalprivate void modelModified(@UIEventTopic(
EventConstants.TOPIC_MODEL_MODIFIED) Bank model) {
setModel(model);}
Example - Customers perspective
• Search
• Select
• Edit user• Modelchange• UIUpdate
Filter/search
select
edit
UI- SimpleUIwithWindow Builder
• VisualDesigner• Draganddrop• Layouting
• DataBinding• UI<->Model
• UIInteraction• Initialize Model• Modelchanges• Selection changes• Widget events
UIInteraction- model
• InitializeUIModel• Resetbindings• UpdateUI
public void setModel(Bank model) {if(model==null)
return;disposeBindings(m_bindingContext);super.setModel(model);if(listViewer==null)
return;m_bindingContext = initDataBindings();update();
}
@Inject@Optionalprivate void modelModified(@UIEventTopic(
EventConstants.TOPIC_MODEL_MODIFIED) Account account) {update();
}
• ModelChanges• UpdateUI
UIInteraction- events
• SelectionChanges• Resetbindings• UpdateUI
• WidgetEvents• UpdateUI
listViewer.addSelectionChangedListener((e)->{selectionService.setSelection(
listViewer.getStructuredSelection().getFirstElement());});
@Injectprotected ESelectionService selectionService;
btnSearch.addSelectionListener(new SelectionAdapter() {public void widgetSelected(SelectionEvent e) {
update();}
});
UI- ComplexUIwithWindowBuilder
• Canvas• TableDataBinding• Customcode
private void update() {tableViewer.refresh();tableViewer_1.refresh();resizeColumns(table);resizeColumns(table_1);ChartHelper.generateGraph(lws, getModel());
}
AddingCharts
• NebulaXYGraph
// don't instantiate the lightweigt twice.// it won't refresh the chart on Maclws = new LightweightSystem(canvas);
void generateGraph(LightweightSystem lws, Account account) {XYGraph xyGraph = new XYGraph();lws.setContents(xyGraph);xyGraph.setTitle("Balance chart");// create the traceCircularBufferDataProvider provider = ...Trace trace = new Trace("Trace1", xyGraph.getPrimaryXAxis(),
xyGraph.getPrimaryYAxis(), provider);// add the trace to xyGraphxyGraph.addTrace(trace);
}
Concluding
• Rapidprototype,fullycustomizable,persistyour data
• Source:• https://github.com/psuzzi/eclipsecon/tree/ece2017/democode Project:ece2017/com.itemis.e4.banking
• Please,getintouchifyouneedmoreinformation.• www.itemis.com