IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

BIRT Discussion :

[2.1.2] Changer le format de sortie et NullPointerException avc org.eclipse.birt.core


Sujet :

BIRT

  1. #1
    Membre à l'essai
    Inscrit en
    Mai 2007
    Messages
    37
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 37
    Points : 19
    Points
    19
    Par défaut [2.1.2] Changer le format de sortie et NullPointerException avc org.eclipse.birt.core
    Bonjour,
    je voudrais essayer avec autre "output format", peut-être c'est ça le problème...
    Quelqu'un peut me dire quelle funtion je dois utiliser??

    Merci

    [EDIT]ça marche pas... J'ai changé le format, mais aucun résultat...
    J'ai lu sur internet que le fichier "org.eclipse.birt.core" est utilisé. Si je l'ajoute à mon Java Build Path, j'ai une exception "NullPointerException" à la ligne "engine = factory.createDesignEngine( config );", parce que factory est null... mais si je ne l'ajoute pas, je n'ai plus d'exception.. Pourquoi?
    Qu'est-ce que je dois faire avec "org.eclipse.birt.core", l'ajouter ou pas (si je dois l'ajouter comment je dois avec l'exception?)

    Quelqu'un a d'idée???

    Merci de votre aide[/EDIT]

    [EDIT BIS]Bonjour,
    je veux créer un rapport avec des tables et des charts. J'ai lu que je va utiliser le jar org.eclipse.birt.core.
    Si je l'ajoute, j'ai une exception "NullPointerException" à la ligne 'engine = factory.createDesignEngine( config );', parce qu'il dit que factory est null.
    C'est necessaire d'ajouter ce jar?? S'il faut, comment je dois faire pour resoudre l'exception??

    Merci à tous
    Mon code c'est le suivante:

    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    public class miChartDesign
    {
    	ReportDesignHandle designHandle = null;
    	ElementFactory designFactory = null;
    	StructureFactory structFactory = null;	
    	String[] cols = {"PROD","SUMA"};
    	//String[] cols = {"CITY", "CUSTOMERNUMBER"};
    	OdaDataSetHandle dsHandle = null;
    	//MetaDataDictionary dict;
    	public static void main( String[] args )
    	{
    		try
    		{
    			miChartDesign bc = new miChartDesign();
     
    			bc.buildReport( );
    			//bc.runReport();
    		}
    		catch ( IOException e )
    		{
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		catch ( SemanticException e )
    		{
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		/*catch ( EngineException e )
    		{
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}*/
    	}
     
    	void buildDataSource( ) throws SemanticException
    	{
     
    		OdaDataSourceHandle dsHandle = designFactory.newOdaDataSource(
    				"ChartDataSource", "org.eclipse.birt.report.data.oda.jdbc" );
    		dsHandle.setProperty( "odaDriverClass",
    				"org.eclipse.birt.report.data.oda.sampledb.Driver" );
    		dsHandle.setProperty( "odaURL", "jdbc:classicmodels:sampledb" );
    		dsHandle.setProperty( "odaUser", "ClassicModels" );
    		dsHandle.setProperty( "odaPassword", "" );
     
    		designHandle.getDataSources( ).add( dsHandle );
     
    	}
     
    	void buildDataSet( ) throws SemanticException
    	{
     
    		dsHandle = designFactory.newOdaDataSet( "ChartData",
    				"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
    		dsHandle.setDataSource( "ChartDataSource" );
    		String qry = "SELECT Products.ProductLine AS PROD, sum(OrderDetails.QuantityOrdered) AS SUMA FROM OrderDetails, Products WHERE Products.ProductCode=OrderDetails.ProductCode GROUP BY Products.ProductLine ORDER BY Products.ProductLine";
    		//String qry = "SELECT CITY, CUSTOMERNUMBER FROM CUSTOMERS WHERE CUSTOMERNUMBER < 150 GROUP BY CITY,CUSTOMERNUMBER";
     
    		dsHandle.setQueryText( qry );
     
    		designHandle.getDataSets( ).add( dsHandle );
     
     
     
    	}
    	void buildReport( ) throws IOException, SemanticException
    	{
    		//Configure the Engine and start the Platform
    		DesignConfig config = new DesignConfig( );
     
    		config.setProperty("BIRT_HOME", "C:/Program Files/birtruntime/birt-runtime-2_1_2/ReportEngine");
     		IDesignEngine engine = null;
    		try{
     
     
    			Platform.startup( config );
    			IDesignEngineFactory factory = (IDesignEngineFactory) Platform.createFactoryObject( IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
    			if (factory == null) System.out.println("FACTORY IS NULL");
    			else System.out.println("FACTORY ISN'T NULL");
    			engine = factory.createDesignEngine( config );
     
    		}catch( Exception ex){
     			ex.printStackTrace();
    		}		
     
    		SessionHandle session = engine.newSessionHandle( ULocale.ENGLISH ) ;
     
    		try{
    			//open a design or a template
    			//designHandle = session.openDesign("D:/stage/Report.rptdesign");
    			designHandle = session.createDesign();
     
    			designFactory = designHandle.getElementFactory( );
     
    			DesignElementHandle simpleMasterPage = designFactory.newSimpleMasterPage( "Master Page" );//$NON-NLS-1$
    	        designHandle.getMasterPages( ).add( simpleMasterPage );
     
    			buildDataSource();
     			buildDataSet();
     
     			createBody();
     			createTable();			
     
    			// Save the design and close it. 
    			designHandle.saveAs( "D:/stage/HOY.rptdesign" ); //$NON-NLS-1$
     
    			designHandle.close( );
     
    			Platform.shutdown();
     
     			System.out.println("Finished");
    		}catch (Exception e){
    			e.printStackTrace();
    		}		
    	}
     
     
    	private void createBody() throws SemanticException{
     
    		TableHandle table = designFactory.newTableItem(null,1,1,1,1);
            table.setWidth("100%");
            table.setDataSet(designHandle.findDataSet("ChartData"));
            designHandle.getBody().add(table);
            //designHandle.getBody().add((DesignElementHandle)createMultiYSeriesChart( ));
            designHandle.getBody().add(createMultiYSeriesChart());
            //RowHandle rowHandle = (RowHandle) table.getDetail( ).get( 0 );
            //RowHandle rowHandle = (RowHandle)table.getDetail().get(0);
            //CellHandle cellHandle = (CellHandle)rowHandle.getCells().get(0);
          //  cellHandle.getContent().add((Chart)createMultiYSeriesChart( ));
     
        }
     
        protected  ExtendedItemHandle createMultiYSeriesChart( )
        {
        	/*if (dsHandle == null) System.out.println("dsHandle es nulo");
        	else System.out.println("dsHandle no es nulo");
           */
            ExtendedItemHandle eih = designFactory.newExtendedItem ( null, "Chart" );//$NON-NLS-1$
            try
            {
                eih.setHeight( "7.51in" );//$NON-NLS-1$
                eih.setWidth( "4.447in" );//$NON-NLS-1$
                //eih.setDataSet(dsHandle);
                eih.setProperty ( ExtendedItemHandle.DATA_SET_PROP, "ChartData" );//$NON-NLS-1$
                eih.setProperty("outputFormat", "PNG");
            }
            catch ( SemanticException e )
            {
                e.printStackTrace( );
            }
     
            ChartWithAxes cwaBar = ChartWithAxesImpl.create( );
            cwaBar.setType("Bar Chart");
            cwaBar.setSubType("Side-by-side");
     
     
            // Plot
            cwaBar.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) );
            Plot p = cwaBar.getPlot( );
            p.getClientArea( )
                    .setBackground( GradientImpl.create( ColorDefinitionImpl.create( 225,
                            225,
                            255 ),
                            ColorDefinitionImpl.create( 255, 255, 225 ),
                            -35,
                            false ) );
            p.getOutline( ).setVisible( true );
     
            // Title
            cwaBar.getTitle( )
                    .getLabel( )
                    .getCaption( )
                    .setValue( "Bar Chart with Multiple Y Series" );//$NON-NLS-1$
     
            // Legend
            Legend lg = cwaBar.getLegend( );
            lg.getText( ).getFont( ).setSize( 16 );
            lg.getText( ).getFont( ).setBold( true );
            lg.getInsets( ).set( 10, 5, 0, 0 );
            lg.setAnchor( Anchor.NORTH_LITERAL );
            lg.setVisible(true);
     
            // X-Axis
            Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0];
            xAxisPrimary.setType( AxisType.TEXT_LITERAL );
            xAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.BELOW_LITERAL );
            xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL );
            xAxisPrimary.getTitle( ).getCaption( ).setValue( "Eje X" ); //$NON-NLS-1$   
            xAxisPrimary.setLabelPosition ( Position.BELOW_LITERAL );
            xAxisPrimary.setTitlePosition( Position.BELOW_LITERAL );
     
            // Y-Axis
            Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary );
            yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );
            yAxisPrimary.getTitle( )
                    .getCaption( )
                    .setValue( "Eje Y" );//$NON-NLS-1$
     
            // Data Set
    //        TextDataSet categoryValues = TextDataSetImpl.create( new String[]{
    //                "Europe", "Asia", "North America"} );//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
    //        NumberDataSet orthoValues1 = NumberDataSetImpl.create( new double[]{
    //                26.17, 34.21, 21.5
    //        } );
    //        NumberDataSet orthoValues2 = NumberDataSetImpl.create( new double[]{
    //                4.81, 3.55, -5.26
    //        } );
     
            // X-Series
            Series seCategory = SeriesImpl.create( );
            Query query = QueryImpl.create( "row[\"" + (String)cols[0] + "\"]" );//$NON-NLS-1$
            seCategory.getDataDefinition( ).add( query );
            //eCategory.setDataSet( categoryValues );
     
            SeriesDefinition sdX = SeriesDefinitionImpl.create( );
            xAxisPrimary.getSeriesDefinitions( ).add( sdX );
            sdX.getSeries( ).add( seCategory );
     
            // Y-Series (1)
            BarSeries bs = (BarSeries) BarSeriesImpl.create( );
            bs.setSeriesIdentifier( "Sales" );//$NON-NLS-1$
            Query query1 = QueryImpl.create( "row[\"" + (String)cols[1] + "\"]" );//$NON-NLS-1$
            bs.getDataDefinition( ).add( query1 );
     
            /*SeriesDefinition seGroup = SeriesDefinitionImpl.create( );
            Query query1 = QueryImpl.create( "row[\"" + (String)cols[1] + "\"]" );//$NON-NLS-1$
            seGroup.setQuery( query1 );
            */
     
            //bs.setDataSet( orthoValues1 );
            bs.setRiserOutline( null );
            bs.getLabel( ).setVisible( true );
            bs.setLabelPosition( Position.INSIDE_LITERAL );
     
            SeriesDefinition sdY1 = SeriesDefinitionImpl.create( );
            sdY1.getSeriesPalette( ).update( -2 );
            yAxisPrimary.getSeriesDefinitions( ).add( sdY1 );
            sdY1.getSeries( ).add( bs );
     
            // Y-Series (2)
    //        BarSeries bs2 = (BarSeries) BarSeriesImpl.create( );
    //        bs2.setSeriesIdentifier( "Net Profit" );//$NON-NLS-1$
    //        Query query2 = QueryImpl.create( "row[\"customerNumber\"]" );//$NON-NLS-1$
    //        bs2.getDataDefinition( ).add( query2 );
    //        bs2.setRiserOutline( null );
    //        bs2.getLabel( ).setVisible( true );
    //        bs2.setLabelPosition( Position.INSIDE_LITERAL );
     
    //        SeriesDefinition sdY2 = SeriesDefinitionImpl.create( );
    //        sdY2.getSeriesPalette( ).update( -3 );
    //        yAxisPrimary.getSeriesDefinitions( ).add( sdY2 );
    //        sdY2.getSeries( ).add( bs2 );
     
            ChartReportItemImpl crii = null;
     
            try
            {
                //Add ChartReportItemImpl to ExtendedItemHandle
                crii = (ChartReportItemImpl) eih.getReportItem( );
                //Add chart instance to ChartReportItemImpl
                crii.setProperty( "chart.instance", cwaBar );//$NON-NLS-1$
            }
            catch ( ExtendedElementException e )
            {
                e.printStackTrace( );
            }
     
            return eih;
     
     
     
        }
     
        void createTable(){
     
        	try{
        		TableHandle table = designFactory.newTableItem( "table", cols.length);
        		table.setWidth( "100%" );
    			table.setDataSet( designHandle.findDataSet( "ChartData" ) );
     
    			PropertyHandle computedSet = table.getColumnBindings( ); 
    			ComputedColumn  cs1 = null;
     
    			for( int i=0; i < cols.length; i++){
    				cs1 = StructureFactory.createComputedColumn();
    					cs1.setName((String)cols[i]);
    				cs1.setExpression("dataSetRow[\"" + (String)cols[i] + "\"]");
    				computedSet.addItem(cs1);
    			}
     
     
    			// table header
    			RowHandle tableheader = (RowHandle) table.getHeader( ).get( 0 );
     
    			tableheader.setProperty( StyleHandle.BACKGROUND_COLOR_PROP, "Gray" );
    			tableheader.setProperty(IStyleModel.TEXT_ALIGN_PROP,DesignChoiceConstants.BACKGROUND_POSITION_CENTER);
     
    				for( int i=0; i < cols.length; i++){
    					LabelHandle label1 = designFactory.newLabel( (String)cols[i] );	
    					label1.setText((String)cols[i]);
    					CellHandle cell = (CellHandle) tableheader.getCells( ).get( i );
    					cell.getContent( ).add( label1 );
    			}							
     
    				// table detail
    				RowHandle tabledetail = (RowHandle) table.getDetail( ).get( 0 );
    				for( int i=0; i < cols.length; i++){
    				CellHandle cell = (CellHandle) tabledetail.getCells( ).get( i );
    					DataItemHandle data = designFactory.newDataItem( "data_"+(String)cols[i] );
    					data.setResultSetColumn( (String)cols[i]);
    					cell.getContent( ).add( data );
    				}
     
    				designHandle.getBody( ).add( table );
     
        	}catch(Exception e){
        		System.out.println("Exception at createTable: " + e);
        	}
        }
     
        /*******************************************/
     
     
     
    }
    [/EDIT]

  2. #2
    BiM
    BiM est déconnecté
    Expert éminent sénior
    Avatar de BiM
    Femme Profil pro
    Consultante/Formatrice BIRT & Ingénieur Java/J2EE/GWT
    Inscrit en
    Janvier 2005
    Messages
    7 796
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 38
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Consultante/Formatrice BIRT & Ingénieur Java/J2EE/GWT

    Informations forums :
    Inscription : Janvier 2005
    Messages : 7 796
    Points : 10 765
    Points
    10 765
    Par défaut
    Bonjour,

    org.eclipse.birt.core n'est pas un fichier mais un package. Tu dois ajouter la librairie contenant ce package à ton projet (coreapi.jar).

    Ensuite, pour changer le format de sortie tu devrais avoir un objet de type RenderOptionBase instancié de cette manière :
    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    RenderOptionBase option = new RenderOptionBase();
    Puis pour choisir le format de sortie :
    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    option.setOutputFormat(RenderOptionBase.OUTPUT_FORMAT_PDF); //...pour le format PDF et RenderOptionBase.OUTPUT_FORMAT_HTML pour le format HTML
    Un peu plus loin, tu instancies ceci qui te permettra de paramétrer ton fichier de sortie :
    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    IRunAndRenderTask task = engine.createRunAndRenderTask(...); //engine est de type ReportEngine
    Puis tu relies le RenderOptionBase à la "tâche" de génération de cette façon :
    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    task.setRenderOption(option);

    Et voilou, je ne vois pas où et comment tu te compliques la vie

  3. #3
    Membre à l'essai
    Inscrit en
    Mai 2007
    Messages
    37
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 37
    Points : 19
    Points
    19
    Par défaut
    J'ai déjà ajouté le package coreapi.jar, mais je vois pas mes charts. C'est pour ça que j'avais pensé d'ajouter plus de packages... Mais je ne sais pas lesquels.
    J'ai les jars suivantes dans mon Java Build Path (j'ai pas ecrit la chaîne '.jar' et la version non plus):
    chartengineapi
    com.ibm.icu
    commons-cli
    commons-codec
    coreapi
    dataadapterapi
    dteapi
    engineapi
    flute
    iText1.3
    iTextAsian
    js
    modelapi
    org.eclipse.birt.chart.device.extension
    org.eclipse.birt.chart.device.pdf
    org.eclipse.birt.chart.device.svg
    org.eclipse.birt.chart.device.swt
    org.eclipse.birt.chart.engine
    org.eclipse.birt.chart.engine.extension
    org.eclipse.emf.common
    org.eclipse.emf.ecore
    org.eclipse.emf.ecore.xmi
    sac
    scriptapi
    servlet

    C'est bon comme ça? Pourquoi je ne vois pas mes charts?

    J'attends ta réponse...

    Je me complique la vie??? Oui ça c'est vrai...
    Merci BiM

  4. #4
    Membre à l'essai
    Inscrit en
    Mai 2007
    Messages
    37
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 37
    Points : 19
    Points
    19
    Par défaut
    Bonjour,
    le code c'était bon, seulement il faudrait ajouter
    cwaBar.getBlock( ).setBounds( BoundsImpl.create( 0, 0, 252, 288 ) );

    avec ça, ça marche!!!!
    Merci Jason pour m'avoir résolu cette question

    [EDIT]Bon, je vous explique...
    J'ai ajouté tous les packages de BirtReport/lib et aussi Reportitem.jar du plugin d'Eclipse.

    Avec le code que j'ai vous écrit quelque jours avant et la ligne que j'ai ajouté aujord'hui ça marche.[/EDIT]

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [T-SQL] comment changer le format de l'ouput ?
    Par jm.alfonsi dans le forum Adaptive Server Enterprise
    Réponses: 3
    Dernier message: 05/03/2007, 11h05
  2. Changer le format de l'output ?
    Par jm.alfonsi dans le forum Langage SQL
    Réponses: 4
    Dernier message: 16/11/2005, 12h02
  3. Changer le format de numérotation d'un <fo:list-item
    Par elitost dans le forum XSL/XSLT/XPATH
    Réponses: 1
    Dernier message: 05/09/2005, 17h37
  4. Awk - changer le flux de sortie
    Par Longrais dans le forum Linux
    Réponses: 1
    Dernier message: 16/08/2005, 17h11
  5. [VisualC++] Changer le format d'une image
    Par dananchet dans le forum MFC
    Réponses: 1
    Dernier message: 06/05/2005, 15h05

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo