KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > efs > openreports > actions > admin > EditChartAction


1 /*
2  * Copyright (C) 2003 Erik Swenson - erik@oreports.com
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the Free
6  * Software Foundation; either version 2 of the License, or (at your option)
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16  * Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */

19
20 package org.efs.openreports.actions.admin;
21
22 import java.util.*;
23
24 import com.opensymphony.xwork.ActionContext;
25 import com.opensymphony.xwork.ActionSupport;
26
27 import org.apache.log4j.Logger;
28
29 import org.efs.openreports.ORStatics;
30 import org.efs.openreports.engine.ChartReportEngine;
31 import org.efs.openreports.objects.ReportChart;
32 import org.efs.openreports.objects.ReportParameter;
33 import org.efs.openreports.objects.ReportUser;
34 import org.efs.openreports.objects.chart.ChartValue;
35 import org.efs.openreports.providers.*;
36 import org.efs.openreports.util.ORUtil;
37
38 public class EditChartAction extends ActionSupport
39         implements
40             DataSourceProviderAware,
41             ChartProviderAware,
42             ParameterProviderAware,
43             ReportProviderAware,
44             DirectoryProviderAware,
45             PropertiesProviderAware
46 {
47     protected static Logger log =
48         Logger.getLogger(EditChartAction.class);
49
50     private String JavaDoc command;
51     
52     private boolean submitOk;
53     private boolean submitValidate;
54
55     private int id;
56     private String JavaDoc name;
57     private String JavaDoc description;
58     private String JavaDoc query;
59     private int dataSourceId = Integer.MIN_VALUE;
60     private int reportId = Integer.MIN_VALUE;
61     private int chartType;
62     private int width = 600;
63     private int height = 400;
64     private String JavaDoc xAxisLabel;
65     private String JavaDoc yAxisLabel;
66     private int orientation;
67     private boolean showLegend;
68     private boolean showTitle;
69     private boolean showValues;
70
71     private ReportChart reportChart;
72     private ChartValue[] chartValues;
73
74     private DataSourceProvider dataSourceProvider;
75     private ChartProvider chartProvider;
76     private ParameterProvider parameterProvider;
77     private ReportProvider reportProvider;
78     private PropertiesProvider propertiesProvider;
79     private DirectoryProvider directoryProvider;
80
81     public String JavaDoc execute()
82     {
83         try
84         {
85             if (command.equals("edit"))
86             {
87                 reportChart =
88                     chartProvider.getReportChart(new Integer JavaDoc(id));
89             }
90             else
91             {
92                 reportChart = new ReportChart();
93             }
94
95             if (command.equals("edit") && !submitOk && !submitValidate)
96             {
97                 name = reportChart.getName();
98                 description = reportChart.getDescription();
99                 query = reportChart.getQuery();
100                 chartType = reportChart.getChartType();
101                 width = reportChart.getWidth();
102                 height = reportChart.getHeight();
103                 xAxisLabel = reportChart.getXAxisLabel();
104                 yAxisLabel = reportChart.getYAxisLabel();
105                 orientation = reportChart.getPlotOrientation();
106                 showLegend = reportChart.isShowLegend();
107                 showTitle = reportChart.isShowTitle();
108                 showValues = reportChart.isShowValues();
109                 id = reportChart.getId().intValue();
110                 
111                 if (reportChart.getDataSource() != null)
112                 {
113                     dataSourceId =
114                         reportChart.getDataSource().getId().intValue();
115                 }
116                 
117                 if (reportChart.getDrillDownReport() != null)
118                 {
119                     reportId = reportChart.getDrillDownReport().getId().intValue();
120                 }
121                 
122             }
123
124             if (!submitOk && !submitValidate)
125                 return INPUT;
126
127             reportChart.setName(name);
128             reportChart.setDescription(description);
129             reportChart.setQuery(query);
130             reportChart.setChartType(chartType);
131             reportChart.setWidth(width);
132             reportChart.setHeight(height);
133             reportChart.setXAxisLabel(xAxisLabel);
134             reportChart.setYAxisLabel(yAxisLabel);
135             reportChart.setShowLegend(new Boolean JavaDoc(showLegend));
136             reportChart.setShowTitle(new Boolean JavaDoc(showTitle));
137             reportChart.setShowValues(new Boolean JavaDoc(showValues));
138             reportChart.setPlotOrientation(new Integer JavaDoc(orientation));
139             
140             if (dataSourceId != -1) reportChart.setDataSource(dataSourceProvider
141                     .getDataSource(new Integer JavaDoc(dataSourceId)));
142             
143             if (reportId != -1)
144             {
145                 reportChart.setDrillDownReport(reportProvider.getReport(new Integer JavaDoc(reportId)));
146             }
147             else
148             {
149                 reportChart.setDrillDownReport(null);
150             }
151             
152             if (submitValidate)
153             {
154                 Map map = new HashMap();
155                 if (query.toUpperCase().indexOf("$P") > -1)
156                 {
157                     ReportUser reportUser = (ReportUser) ActionContext.getContext().getSession().get(ORStatics.REPORT_USER);
158                     map = ORUtil.buildQueryParameterMap(reportUser, query, parameterProvider);
159                 }
160                 
161                 ChartReportEngine chartReportEngine = new ChartReportEngine(
162                         dataSourceProvider, directoryProvider, propertiesProvider);
163                 
164                 chartValues = chartReportEngine.getChartValues(reportChart, map);
165
166                 return INPUT;
167             }
168
169             if (command.equals("edit"))
170             {
171                 chartProvider.updateReportChart(reportChart);
172             }
173
174             if (command.equals("add"))
175             {
176                 chartProvider.insertReportChart(reportChart);
177             }
178
179             return SUCCESS;
180         }
181         catch (Exception JavaDoc e)
182         {
183             addActionError(e.getMessage());
184             return INPUT;
185         }
186     }
187
188     public String JavaDoc getCommand()
189     {
190         return command;
191     }
192
193     public void setCommand(String JavaDoc command)
194     {
195         this.command = command;
196     }
197     
198     public void setSubmitOk(String JavaDoc submitOk)
199     {
200         if (submitOk != null) this.submitOk = true;
201     }
202     
203     public void setSubmitValidate(String JavaDoc submitValidate)
204     {
205         if (submitValidate != null) this.submitValidate = true;
206     }
207     
208     public int getDataSourceId()
209     {
210         return dataSourceId;
211     }
212
213     public String JavaDoc getName()
214     {
215         return name;
216     }
217
218     public void setDataSourceId(int dataSourceId)
219     {
220         this.dataSourceId = dataSourceId;
221     }
222
223     public void setName(String JavaDoc name)
224     {
225         this.name = name;
226     }
227
228     public List getDataSources()
229     {
230         try
231         {
232             return dataSourceProvider.getDataSources();
233         }
234         catch (Exception JavaDoc e)
235         {
236             addActionError(e.getMessage());
237             return null;
238         }
239     }
240     
241     public List getReports()
242     {
243         try
244         {
245             return reportProvider.getReports();
246         }
247         catch (Exception JavaDoc e)
248         {
249             addActionError(e.getMessage());
250             return null;
251         }
252     }
253
254     public String JavaDoc[] getTypes()
255     {
256         return ReportParameter.TYPES;
257     }
258
259     public String JavaDoc[] getClassNames()
260     {
261         return ReportParameter.CLASS_NAMES;
262     }
263
264     public int getId()
265     {
266         return id;
267     }
268
269     public void setId(int id)
270     {
271         this.id = id;
272     }
273
274     public void setDataSourceProvider(DataSourceProvider dataSourceProvider)
275     {
276         this.dataSourceProvider = dataSourceProvider;
277     }
278
279     public String JavaDoc getDescription()
280     {
281         return description;
282     }
283
284     public void setDescription(String JavaDoc description)
285     {
286         this.description = description;
287     }
288
289     public void setChartProvider(ChartProvider chartProvider)
290     {
291         this.chartProvider = chartProvider;
292     }
293
294     public String JavaDoc getQuery()
295     {
296         return query;
297     }
298
299     public void setQuery(String JavaDoc query)
300     {
301         this.query = query;
302     }
303
304     public int getChartType()
305     {
306         return chartType;
307     }
308
309     public void setChartType(int chartType)
310     {
311         this.chartType = chartType;
312     }
313
314     public int getHeight()
315     {
316         return height;
317     }
318
319     public void setHeight(int height)
320     {
321         this.height = height;
322     }
323
324     public int getWidth()
325     {
326         return width;
327     }
328
329     public void setWidth(int width)
330     {
331         this.width = width;
332     }
333
334     public ChartValue[] getChartValues()
335     {
336         return chartValues;
337     }
338
339     public String JavaDoc getXAxisLabel()
340     {
341         return xAxisLabel;
342     }
343
344     public void setXAxisLabel(String JavaDoc axisLabel)
345     {
346         xAxisLabel = axisLabel;
347     }
348
349     public String JavaDoc getYAxisLabel()
350     {
351         return yAxisLabel;
352     }
353
354     public void setYAxisLabel(String JavaDoc axisLabel)
355     {
356         yAxisLabel = axisLabel;
357     }
358
359     public void setParameterProvider(ParameterProvider parameterProvider)
360     {
361         this.parameterProvider = parameterProvider;
362     }
363
364     public int getOrientation()
365     {
366         return orientation;
367     }
368
369     public void setOrientation(int orientation)
370     {
371         this.orientation = orientation;
372     }
373
374     public boolean isShowLegend()
375     {
376         return showLegend;
377     }
378
379     public void setShowLegend(boolean showLegend)
380     {
381         this.showLegend = showLegend;
382     }
383
384     public boolean isShowTitle()
385     {
386         return showTitle;
387     }
388
389     public void setShowTitle(boolean showTitle)
390     {
391         this.showTitle = showTitle;
392     }
393
394     public int getReportId()
395     {
396         return reportId;
397     }
398
399     public void setReportId(int reportId)
400     {
401         this.reportId = reportId;
402     }
403
404     public void setReportProvider(ReportProvider reportProvider)
405     {
406         this.reportProvider = reportProvider;
407     }
408
409     public boolean isShowValues()
410     {
411         return showValues;
412     }
413
414     public void setShowValues(boolean showValues)
415     {
416         this.showValues = showValues;
417     }
418
419     public void setDirectoryProvider(DirectoryProvider directoryProvider)
420     {
421         this.directoryProvider = directoryProvider;
422     }
423
424     public void setPropertiesProvider(PropertiesProvider propertiesProvider)
425     {
426         this.propertiesProvider = propertiesProvider;
427     }
428 }
Popular Tags