KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > birt > chart > examples > builder > ChartWizardLauncher


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.builder;
13
14 import java.io.File JavaDoc;
15 import java.io.FileInputStream JavaDoc;
16 import java.io.FileOutputStream JavaDoc;
17
18 import org.eclipse.birt.chart.model.Chart;
19 import org.eclipse.birt.chart.model.Serializer;
20 import org.eclipse.birt.chart.model.impl.SerializerImpl;
21 import org.eclipse.birt.chart.ui.swt.DefaultUIServiceProviderImpl;
22 import org.eclipse.birt.chart.ui.swt.wizard.ChartWizard;
23 import org.eclipse.birt.chart.ui.swt.wizard.ChartWizardContext;
24 import org.eclipse.birt.chart.ui.swt.wizard.TaskFormatChart;
25 import org.eclipse.birt.chart.ui.swt.wizard.TaskSelectData;
26 import org.eclipse.birt.chart.ui.swt.wizard.TaskSelectType;
27 import org.eclipse.birt.core.ui.frameworks.taskwizard.TasksManager;
28 import org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBase;
29 import org.eclipse.birt.core.ui.utils.UIHelper;
30 import org.eclipse.swt.widgets.Display;
31
32 /**
33  * A wizard launcher for Chart builder.
34  * <p>
35  * All used icons should be moved into current root folder from
36  * <b>org.eclipse.birt.chart.ui/icons</b>.
37  * <p>
38  * If the eclipse extension is expected to use, append the argument in VM,
39  * <b>-DBIRT_HOME=birt_home_directory</b>; or append <b>-DSTANDALONE</b> to
40  * use hard-coded manifest, in
41  * <code>org.eclipse.birt.chart.ui.swt.wizard.ChartUIExtensionImpl</code> and
42  * <code>org.eclipse.birt.chart.util.PluginSettings</code>.
43  *
44  */

45 public class ChartWizardLauncher
46 {
47
48     public static void main( String JavaDoc[] args )
49     {
50         init( );
51
52         Chart chart = null;
53         Serializer serializer = null;
54         File JavaDoc chartFile = new File JavaDoc( "testChart.chart" ); //$NON-NLS-1$
55

56         // Reads the chart model
57
try
58         {
59             serializer = SerializerImpl.instance( );
60             if ( chartFile.exists( ) )
61             {
62
63                 chart = serializer.read( new FileInputStream JavaDoc( chartFile ) );
64             }
65         }
66         catch ( Exception JavaDoc e )
67         {
68             WizardBase.displayException( e );
69         }
70
71         // Configures the chart wizard.
72
ChartWizard chartWizard = new ChartWizard( );
73         ChartWizardContext context = new ChartWizardContext( chart );
74
75         /*
76          * Used to fetch data. Default implementation of <code>IDataServiceProvider</code>.
77          *
78          * @see the implementation for BIRT, <code>org.eclipse.birt.chart.reportitem.ReportDataServiceProvider</code>
79          *
80          */

81         context.setDataServiceProvider( new DefaultDataServiceProviderImpl( ) );
82         /*
83          * Used to invoke some builders outside. Default implementation of
84          * <code>IUIServiceProvider</code>.
85          *
86          * @see the implementation for BIRT, <code>org.eclipse.birt.chart.reportitem.ChartReportItemBuilderImpl</code>
87          *
88          */

89         context.setUIServiceProvider( new DefaultUIServiceProviderImpl( ) );
90
91         // Opens the wizard
92
context = (ChartWizardContext) chartWizard.open( context );
93
94         // Writes the chart model
95
if ( context != null )
96         {
97             chart = context.getModel( );
98             try
99             {
100                 serializer.write( chart, new FileOutputStream JavaDoc( chartFile ) );
101             }
102             catch ( Exception JavaDoc e )
103             {
104                 WizardBase.displayException( e );
105             }
106         }
107         else
108         {
109             System.out.println( "Wizard was cancelled!" ); //$NON-NLS-1$
110
}
111     }
112
113     static void init( )
114     {
115         // Create display
116
Display.getDefault( );
117
118         if ( !UIHelper.isEclipseMode( ) )
119         {
120             // Registers the wizard task and the chart wizard
121
try
122             {
123                 TasksManager.instance( )
124                         .registerTask( "org.eclipse.birt.chart.ui.swt.wizard.TaskSelectType", //$NON-NLS-1$
125
new TaskSelectType( ) );
126                 TasksManager.instance( )
127                         .registerTask( "org.eclipse.birt.chart.ui.swt.wizard.TaskSelectData", //$NON-NLS-1$
128
new TaskSelectData( ) );
129                 TasksManager.instance( )
130                         .registerTask( "org.eclipse.birt.chart.ui.swt.wizard.TaskFormatChart", //$NON-NLS-1$
131
new TaskFormatChart( ) );
132                 String JavaDoc sChartTasks = "org.eclipse.birt.chart.ui.swt.wizard.TaskSelectType,org.eclipse.birt.chart.ui.swt.wizard.TaskSelectData,org.eclipse.birt.chart.ui.swt.wizard.TaskFormatChart"; //$NON-NLS-1$
133
TasksManager.instance( )
134                         .registerWizard( "org.eclipse.birt.chart.ui.ChartWizard", //$NON-NLS-1$
135
sChartTasks,
136                                 "" ); //$NON-NLS-1$
137
}
138             catch ( Exception JavaDoc e )
139             {
140                 WizardBase.displayException( e );
141             }
142         }
143     }
144 }
145
Popular Tags