Reporting With Eclipse BIRT and Java Objects (POJO's) - Tutorial PDF
Reporting With Eclipse BIRT and Java Objects (POJO's) - Tutorial PDF
47
Freetutorial,donateto support
ReportingwithEclipseBIRTandJavaObjects (POJO's)Tutorial
LarsVogelHendrikStill
Training Books
07.03.2008 07.03.200926.06.2011 HendrikStill,LarsVogel Lars Vogel CreatedArticle bugfixesandenhancements
byLarsVogel
Revision0.10.2 Revision0.31.2
TableofContents
1.EclipseBIRT 1.1.Overview 1.2.Example 2.Installation 3.CreateProjectandREport 4.Javaclasses 5.DatasourceandDataset 5.1.CreateDataSource 5.2.TheDataset 5.3.JavaScript 6.Displaythedatainatable 6.1.Overview 6.2.Createatable 7.Chart 7.1.CreateaChart 8.DeployinginTomcat 8.1.Overview 8.2.InstallBIRTinTomcat 8.3.InstallyourBIRTreportsinTomcat 9.DeployinginEclipseRCPapplication 9.1.BIRTdeployingtoanRCPApplication 10.Thankyou 11.QuestionsandDiscussion 12.LinksandLiterature 12.1.SourceCode 12.2.EclipseBIRTresources
www.vogella.com/articles/EclipseBIRT/article.html
1/19
27/04/13
1.EclipseBIRT
1.1.Overview
EclipseBIRTallowsthecreationofreportsbasedondatafromdifferentdatasources.Datasources definewherethedataisstored. BIRTprovidesforexamplethefollowingdatasources: Databases(viaJDBC) TextFiles(cvs,XML) WebServices(viaWSDLFiles) ScriptingDatasources YouuseinBIRT"Datasets"todefinesqueriesondatasource.Thesedatasetscanbeusedinareport. InaJavaprogramitisoftenconvenienttouseJavaobjectsasadatasourceforreports.Thisarticlewill focusontheusageofplainoldJavaobjects(POJO)asdatasourcesforBIRTreports.
1.2.Example
Inthistutorialwewillbuildareportwhichwillshowusinformationaboutthestockmarket.Wegetthe informationfromaJavaObject.Thedatawillbedisplayedinachartandinatablewithdetailed information.Theresultshouldlooklikethis:
2.Installation
UsetheEclipseUpdateManagertoinstall"BusinessIntelligence,ReportingandCharting">BIRT Framework.
3.CreateProjectandREport
CreateanewJavaProjectwiththename"de.vogella.birt.stocks".
www.vogella.com/articles/EclipseBIRT/article.html
2/19
27/04/13
Createanewreport"stock_report.rptdesign"viaFile>New>Other>BusinessIntelligenceand Reporting>Report.
www.vogella.com/articles/EclipseBIRT/article.html
3/19
27/04/13
Thenewreportisdisplayedinthe"ReportDesign"perspective.Deleteeverythingintheexamplereport exceptthereportheader.Theresultshouldlooklikethefollowing.
4.Javaclasses
Thereportwilldisplaystockdata.TodemonstrateBIRTweuseaMockobjectforprovidingthedata. Createpackage"de.vogella.birt.stocks.model"andthenthefollowingclass.Thisclasswillrepresent thedomainmodel.
p a c k a g ed e . v o g e l l a . b i r t . s t o c k s . m o d e l ; i m p o r tj a v a . u t i l . D a t e ; / * * *D o m a i nm o d e lf o rs t o c kd a t a *@ a u t h o rL a r sV o g e l * /
www.vogella.com/articles/EclipseBIRT/article.html
4/19
27/04/13
www.vogella.com/articles/EclipseBIRT/article.html
5/19
27/04/13
5.DatasourceandDataset
TouseJavaObjects(POJO's)asdatasourceinEclipseBIRTyouhavetomapthefieldsofyourJava classestoJavaScript.ThisJavaScriptisusedinyourreportandwillaccesstheJavaObject.
5.1.CreateDataSource
Thedatasourceconnectsyourdatawithyourreport.BIRTprovidesdifferenttypesofdatasources,we usethe"ScriptedDataSource".Gobacktoyourstocks_report,usethe"ReportDesign"perspective andselectthe"DataExplorer"View.
Youhavetoselectyourreporttodisplaythecontentofthedatasourceview. Createanewdatasource,named"srcStocks"inyourreport.
5.2.TheDataset
www.vogella.com/articles/EclipseBIRT/article.html
6/19
27/04/13
ThedatasetdefinesthemappingforthedatasourcedataandtheBIRTdata.Createanewdataset named"dataSetSocks".
Pressnextanddefinethecolumnsforyourreport.
5.3.JavaScript
NowwehavetowritetheJavaScriptforourdataset.Selectthedatasetandchoose"open"asscript. Theopenscriptiscalledbeforethefirstaccesstothedataset.WeusethistoloadourListwiththestock objects.ToaccessaJavaclassyouonlyhavetousethefollowingsyntax:Packages.myJavaClass wheremyJavaClassisthefullqualifiedJavaclassname.
Incaseyoudonotseethescriptpleasenodethattheeditorforthereporthasseveraltab. Oneofitislabeled"source".
www.vogella.com/articles/EclipseBIRT/article.html
7/19
27/04/13
Placethefollowingcodinginthefetchscript.
i f ( c o u n t<s t o c k . s i z e ( ) ) { r o w [ " c o l u m n D a t e " ]=s t o c k . g e t ( c o u n t ) . g e t D a t e ( ) ; r o w [ " c o l u m n O p e n " ]=s t o c k . g e t ( c o u n t ) . g e t O p e n ( ) ; r o w [ " c o l u m n H i g h " ]=s t o c k . g e t ( c o u n t ) . g e t H i g h ( ) ; r o w [ " c o l u m n L o w " ]=s t o c k . g e t ( c o u n t ) . g e t L o w ( ) ; r o w [ " c o l u m n C l o s e " ]=s t o c k . g e t ( c o u n t ) . g e t C l o s e ( ) ; r o w [ " c o l u m n V o l u m e " ]=s t o c k . g e t ( c o u n t ) . g e t V o l u m e ( ) ; c o u n t + + ; r e t u r nt r u e ; } r e t u r nf a l s e ;
CheckifyourScriptworksbydoubleclickingonthedataset>PreviewResult.
6.Displaythedatainatable
6.1.Overview
Wewillnowdisplaythedatainatable.
6.2.Createatable
Switchfrom"DataExplorer"tothe"Palette".Selectthetab"Layout".
www.vogella.com/articles/EclipseBIRT/article.html
8/19
27/04/13
Draganddropthetableelementonthereport.
Definethefollowingsettingsforthetable.
Changebacktothe"DataExplorer".Anddraganddropthedatasetcolumnsintothe"Detailsrow"of thetable.
www.vogella.com/articles/EclipseBIRT/article.html
9/19
27/04/13
Theresultshouldlooklikethefollowing.
Done.Youcanseeapreviewofthereportifyouclickonthe"Review"Tab.Theresultshouldlooklike thefollowing:
7.Chart
7.1.CreateaChart
SwitchbacktothePalette,selectachartanddraganddropitonyourreport. ChoosetheLineChartwiththestandardsettings.
www.vogella.com/articles/EclipseBIRT/article.html
10/19
27/04/13
PressNextandselectyourdataset.
www.vogella.com/articles/EclipseBIRT/article.html
11/19
27/04/13
Atthenextstepwehavetoassignthecolumnstotheaxis.Weassignthedatetothexaxisandthe openvaluetotheyaxisviadraganddrop.
Define5seriesintotal.AssignthecolumnstotheseseriesbydraggingthecolumntotheSumsign.
www.vogella.com/articles/EclipseBIRT/article.html
12/19
27/04/13
Currentlythexaxisshowsfirstthenewestdate.Reversethexaxisbyyouhavetosortthedata ascending.Pressthehighlightedbutton.
Gotothenexttabandgivetitlestoyourcolumns.Hidethelastone.
www.vogella.com/articles/EclipseBIRT/article.html
13/19
27/04/13
Thedisplayofthedatesusealongformat,wewouldliketochangethis.Performthefollowingand choose"short"asdatetypeofthexaxis
Changethedisplayofthelinesviathefollowing.
Pressfinishtoincludeyourchartintoyourreport.
8.DeployinginTomcat
8.1.Overview
www.vogella.com/articles/EclipseBIRT/article.html
14/19
27/04/13
8.2.InstallBIRTinTomcat
WewilluseastandaloneTomcat6.0whichweassumeisalreadyinstalled.SeeApacheTomcat Tutorialfordetails. Youneedthe"DeploymentcomponentsofBIRT"http://download.eclipse.org/birt/downloads/. Copythebirt.warofthisdownloadintotheTomcatwebappsfolder.
8.3.InstallyourBIRTreportsinTomcat
Torunyourownreportsyouhavetocopythe.rptdesignfileintherootofthebirtfolderinTomcat.To makeyourJavaclassesavailableexportyourprojectintoajarfile.
www.vogella.com/articles/EclipseBIRT/article.html
15/19
27/04/13
vogella.com
Tutorials
Training
Services
Publications
Connect
BACKTOTOP
AfterthatthejarfilehastobecopiedtotheTomcatwebapps/birt/WEBINF/lib/directory.Restartthe Tomcatandnavigatetoyourreport.
www.vogella.com/articles/EclipseBIRT/article.html
16/19
27/04/13
Yourreportshouldbefoundunderhttp://localhost:8080/birt/frameset?__report=stock_report.rptdesign
9.DeployinginEclipseRCPapplication
9.1.BIRTdeployingtoanRCPApplication
WecanusetheBirtvieweralsoinalocalRCPApplication,itisn'tmorethananbrowserviewwhich showsaHTMLPagegeneratedbyanintegratedWebserver. ThefollowingassumesthatyouarealreadyfamiliarwithEclipseRCPdevelopment.SeeEclipseRCP Tutorialincaseyouneedanintroduction. Convert"de.vogella.birt.stocks"toapluginproject,viarightclick>Configure>"Converttoplugin project". Createannewpluginproject"de.vogella.birt.stocks.rcp".Selectthetemplate"RCPApplicationwitha view". Addthefollowingpluginsasdependendiesto"de.vogella.birt.stocks.rcp".
M a n i f e s t V e r s i o n :1 . 0 B u n d l e M a n i f e s t V e r s i o n :2 B u n d l e N a m e :R c p B u n d l e S y m b o l i c N a m e :d e . v o g e l l a . b i r t . s t o c k s . r c p ;s i n g l e t o n : = t r u e B u n d l e V e r s i o n :1 . 0 . 0 . q u a l i f i e r B u n d l e A c t i v a t o r :d e . v o g e l l a . b i r t . s t o c k s . r c p . A c t i v a t o r
www.vogella.com/articles/EclipseBIRT/article.html
17/19
27/04/13
Copyyourreportto"stock_report_rcp.rptdesign"intothisnewproject.Openthisreportandchangethe "open"JavaScripttothefollowing.
c o u n t=0 ; / * *l o a da n di n i td a t ar e a d e r *i m p o r tP l a t f o r mf r o mo r g . e c l i p s e . c o r e . r u n t i m e * / i m p o r t P a c k a g e ( P a c k a g e s . o r g . e c l i p s e . c o r e . r u n t i m e ) ; / *l o a db u n d l ew i t hP O J O sa n dd a t al o a d i n gc l a s s* / m y B u n d l e=P l a t f o r m . g e t B u n d l e ( " d e . v o g e l l a . b i r t . s t o c k s " ) ; / *l o a dd a t ar e a d e rc l a s s* / r e a d e r C l a s s=m y B u n d l e . l o a d C l a s s ( " d e . v o g e l l a . b i r t . s t o c k s . d a o m o c k . S t o c k D a o M o c k " ) ; / *c r e a t en e wi n s t a n c eo fD a t a R e a d e r* / r e a d e r I n s t a n c e=r e a d e r C l a s s . n e w I n s t a n c e ( ) ;
UsethiscodeasView.java.
p a c k a g ed e . v o g e l l a . b i r t . s t o c k s . r c p ; i m p o r tj a v a . i o . I O E x c e p t i o n ; i m p o r tj a v a . n e t . M a l f o r m e d U R L E x c e p t i o n ; i m p o r tj a v a . n e t . U R L ; i m p o r to r g . e c l i p s e . b i r t . r e p o r t . v i e w e r . u t i l i t i e s . W e b V i e w e r ; i m p o r to r g . e c l i p s e . c o r e . r u n t i m e . F i l e L o c a t o r ; i m p o r to r g . e c l i p s e . c o r e . r u n t i m e . P a t h ; i m p o r to r g . e c l i p s e . c o r e . r u n t i m e . P l a t f o r m ; i m p o r to r g . e c l i p s e . s w t . S W T ; i m p o r to r g . e c l i p s e . s w t . b r o w s e r . B r o w s e r ; i m p o r to r g . e c l i p s e . s w t . w i d g e t s . C o m p o s i t e ; i m p o r to r g . e c l i p s e . u i . p a r t . V i e w P a r t ; i m p o r to r g . o s g i . f r a m e w o r k . B u n d l e ; p u b l i cc l a s sV i e we x t e n d sV i e w P a r t{ p u b l i cs t a t i cf i n a lS t r i n gI D=" d e . v o g e l l a . b i r t . s t o c k s . r c p . v i e w " ; p u b l i cv o i dc r e a t e P a r t C o n t r o l ( C o m p o s i t ep a r e n t ){ S t r i n gp a t h=" " ; t r y{ B u n d l eb u n d l e=P l a t f o r m . g e t B u n d l e ( " d e . v o g e l l a . b i r t . s t o c k s . r c p " ) ; U R Lu r l=F i l e L o c a t o r . f i n d ( b u n d l e ,n e wP a t h ( " s t o c k _ r e p o r t _ r c p . r p t d e s i g n " ) ,n u l l ) ; p a t h=F i l e L o c a t o r . t o F i l e U R L ( u r l ) . g e t P a t h ( ) ; }c a t c h( M a l f o r m e d U R L E x c e p t i o nm e ){ S y s t e m . o u t . p r i n t l n ( " F e h l e rb e iU R L"+m e . g e t S t a c k T r a c e ( ) ) ; }c a t c h( I O E x c e p t i o ne ){ e . p r i n t S t a c k T r a c e ( ) ; } B r o w s e rb r o w s e r=n e wB r o w s e r ( p a r e n t ,S W T . N O N E ) ; / /U s et h ef i l e n a m eo fy o u rr e p o r t W e b V i e w e r . d i s p l a y ( p a t h ,W e b V i e w e r . H T M L ,b r o w s e r ," f r a m e s e t " ) ; }
www.vogella.com/articles/EclipseBIRT/article.html
18/19
27/04/13
10.Thankyou
Pleasehelpmetosupportthisarticle:
11.QuestionsandDiscussion
Beforepostingquestions,pleaseseethevogellaFAQ.Ifyouhavequestionsorfindanerrorinthis articlepleaseusethewww.vogella.comGoogleGroup.Ihavecreatedashortlisthowtocreate goodquestionswhichmightalsohelpyou.
12.LinksandLiterature
12.1.SourceCode
SourceCodeofExamples
12.2.EclipseBIRTresources
http://wiki.eclipse.org/index.php/BIRT_Project EclipseBIRTWiki
12.3.vogellaResources
vogellaTrainingAndroidandEclipseTrainingfromthevogellateam AndroidTutorialIntroductiontoAndroidProgramming GWTTutorialPrograminJavaandcompiletoJavaScriptandHTML EclipseRCPTutorialCreatenativeapplicationsinJava JUnitTutorialTestyourapplication GitTutorialPuteverythingyouhaveunderdistributedversioncontrolsystem
www.vogella.com/articles/EclipseBIRT/article.html
19/19