KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > birt > chart > examples > api > data > MinSliceOld


1 /***********************************************************************
2  * Copyright (c) 2004 Actuate Corporation.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * Actuate Corporation - initial API and implementation
10  ***********************************************************************/

11
12 package org.eclipse.birt.chart.examples.api.data;
13
14 /**
15  * Presents a pie chart with min slice, which could be acheived via SQL.
16  *
17  */

18 import java.io.IOException JavaDoc;
19
20 import org.eclipse.birt.chart.model.Chart;
21 import org.eclipse.birt.report.model.api.DesignEngine;
22 import org.eclipse.birt.report.model.api.DesignFileException;
23 import org.eclipse.birt.report.model.api.ExtendedItemHandle;
24 import org.eclipse.birt.report.model.api.OdaDataSetHandle;
25 import org.eclipse.birt.report.model.api.ReportDesignHandle;
26 import org.eclipse.birt.report.model.api.SessionHandle;
27 import org.eclipse.birt.report.model.api.activity.SemanticException;
28 import org.eclipse.birt.report.model.api.extension.ExtendedElementException;
29
30 import com.ibm.icu.util.ULocale;
31
32 public class MinSliceOld
33 {
34
35     /**
36      * execute application
37      *
38      * @param args
39      */

40     public static void main( String JavaDoc[] args )
41     {
42         new MinSliceOld( ).pieMinSlice( );
43
44     }
45
46     /**
47      * Get the chart instance from the design file and set min slice.
48      *
49      * @return An instance of the simulated runtime chart model (containing
50      * filled datasets)
51      */

52     void pieMinSlice( )
53     {
54         SessionHandle sessionHandle = new DesignEngine( null ).newSessionHandle( (ULocale) null );
55         ReportDesignHandle designHandle = null;
56
57         String JavaDoc path = "src/org/eclipse/birt/chart/examples/api/data/";//$NON-NLS-1$
58

59         try
60         {
61             designHandle = sessionHandle.openDesign( path
62                     + "NonMinSlice.rptdesign" );//$NON-NLS-1$
63
}
64         catch ( DesignFileException e )
65         {
66             // TODO Auto-generated catch block
67
e.printStackTrace( );
68         }
69
70         OdaDataSetHandle dataSet = (OdaDataSetHandle) designHandle
71                 .getDataSets( ).get( 0 );
72         String JavaDoc query = dataSet
73                 .getQueryText( )
74                 .concat(
75                         "\nhaving SUM(CLASSICMODELS.ORDERDETAILS.QUANTITYORDERED) > 7000\n"//$NON-NLS-1$
76
+ "union\n"//$NON-NLS-1$
77
+ "select (MIN(CLASSICMODELS.ORDERDETAILS.ORDERLINENUMBER)-MIN(CLASSICMODELS.ORDERDETAILS.ORDERLINENUMBER)) as ORDERLINENUMBER,\n"//$NON-NLS-1$
78
+ "SUM(CLASSICMODELS.ORDERDETAILS.QUANTITYORDERED) as TotalQuantities\n"//$NON-NLS-1$
79
+ "from CLASSICMODELS.ORDERDETAILS\n"//$NON-NLS-1$
80
+ "where CLASSICMODELS.ORDERDETAILS.ORDERLINENUMBER in\n"//$NON-NLS-1$
81
+ "(select CLASSICMODELS.ORDERDETAILS.ORDERLINENUMBER\n"//$NON-NLS-1$
82
+ "from CLASSICMODELS.ORDERDETAILS\n"//$NON-NLS-1$
83
+ "group by CLASSICMODELS.ORDERDETAILS.ORDERLINENUMBER\n"//$NON-NLS-1$
84
+ "having SUM(CLASSICMODELS.ORDERDETAILS.QUANTITYORDERED)<=7000)"//$NON-NLS-1$
85
);
86         try
87         {
88             dataSet.setQueryText( query );
89         }
90         catch ( SemanticException e )
91         {
92             e.printStackTrace( );
93         }
94
95         ExtendedItemHandle eih = (ExtendedItemHandle) designHandle.getBody( )
96                 .getContents( ).get( 0 );
97
98         Chart cm = null;
99         try
100         {
101             cm = (Chart) eih.getReportItem( ).getProperty( "chart.instance" ); //$NON-NLS-1$
102
}
103         catch ( ExtendedElementException e )
104         {
105             // TODO Auto-generated catch block
106
e.printStackTrace( );
107         }
108         
109         cm.getTitle( ).getLabel( ).getCaption( ).setValue( "MinSlice" );//$NON-NLS-1$
110

111         try
112         {
113             designHandle.saveAs( path + "MinSlice.rptdesign" );//$NON-NLS-1$
114
}
115         catch ( IOException JavaDoc e )
116         {
117             e.printStackTrace( );
118         }
119     }
120 }
121
Popular Tags