KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > userinterface > ReportApplet


1 package com.calipso.reportgenerator.userinterface;
2
3 import com.calipso.reportgenerator.userinterface.ReportViewer;
4 import com.calipso.reportgenerator.common.IReportManager;
5 import com.calipso.reportgenerator.common.ReportGeneratorConfiguration;
6 import com.calipso.reportgenerator.client.ReportManagerService;
7
8 import javax.swing.*;
9 import java.awt.*;
10
11 import java.awt.event.*;
12 import java.io.*;
13 import java.rmi.RemoteException JavaDoc;
14 import java.util.Map JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.StringTokenizer JavaDoc;
17 //import java.util.regex.Matcher;
18

19 import org.apache.commons.configuration.PropertiesConfiguration;
20 import com.calipso.reportgenerator.common.InfoException;
21
22
23 /**
24
25  */

26 public class ReportApplet extends JApplet implements ActionListener{
27   private IReportManager reportManager;
28   private Container contentpane;
29   private JPanel jTreeSelectorPanel;
30   private PropertiesConfiguration configuration;
31
32   public void init(){
33     try{
34       contentpane = getContentPane();
35       initReportManager();
36       contentpane.add(jTreeSelectorPanel);
37     }catch (Exception JavaDoc e){
38         e.printStackTrace();
39     }
40
41   }
42
43   public void actionPerformed (ActionEvent e){
44
45   }
46
47   public void initReportManager() throws RemoteException JavaDoc {
48     try {
49       String JavaDoc userId = getParameter("UserId") != null ? getParameter("UserId") : "" ;
50       String JavaDoc reportDefinitionId = getParameter("ReportDefinitionId") != null ? getParameter("ReportDefinitionId") : "";
51       String JavaDoc reportViewId = getParameter("ReportViewId") != null ? getParameter("ReportViewId") : "";
52       String JavaDoc propertiesPath = getParameter("PropertiesPath") != null ? getParameter("PropertiesPath") : "";
53       boolean visibleActions = true;
54       if ( getParameter("VisibleActions") != null ){
55         visibleActions = Boolean.valueOf(getParameter("VisibleActions")).booleanValue();
56       }
57       Map JavaDoc params = getFilterParameters();
58
59       ReportViewer reportViewer = new ReportViewer(userId, reportDefinitionId, reportViewId, propertiesPath, getReportManager(), new ReportGeneratorConfiguration(configuration), visibleActions, params);
60       jTreeSelectorPanel = reportViewer.getMainPanel();
61      } catch (Exception JavaDoc e) {
62       e.printStackTrace();
63     }
64   }
65
66   private Map JavaDoc getFilterParameters() {
67     if(getParameter("FilterParamNames") == null || getParameter("FilterParamValues") == null) {
68       return new HashMap JavaDoc();
69     } else {
70       return getFilterParameters(getParameter("FilterParamNames"), getParameter("FilterParamValues"));
71     }
72   }
73
74   private Map JavaDoc getFilterParameters(String JavaDoc paramNames, String JavaDoc paramValues) {
75     StringTokenizer JavaDoc namesTokenizer = new StringTokenizer JavaDoc(paramNames, ",");
76     String JavaDoc [] names = new String JavaDoc[namesTokenizer.countTokens()];
77     for(int i = 0 ; namesTokenizer.hasMoreTokens() ; i++) {
78       names [i] = namesTokenizer.nextToken();
79     }
80
81     StringTokenizer JavaDoc valuesTokenizer = new StringTokenizer JavaDoc(paramValues, ",");
82     String JavaDoc [] values = new String JavaDoc[valuesTokenizer.countTokens()];
83     for(int i = 0 ; valuesTokenizer.hasMoreTokens() ; i++) {
84       values [i] = valuesTokenizer.nextToken();
85     }
86
87     return fillMapFrom(names, values);
88   }
89
90   private Map JavaDoc fillMapFrom(String JavaDoc [] names, String JavaDoc [] values) {
91     Map JavaDoc params = new HashMap JavaDoc();
92     for(int i = 0 ; i < names.length ; i++) {
93       params.put(names [i], values [i]);
94     }
95     return params;
96   }
97
98   public IReportManager getReportManager() throws InfoException {
99     if (reportManager == null) {
100       try {
101         ReportManagerService reportManagerService = new ReportManagerService();
102         ClassLoader JavaDoc loader = this.getClass().getClassLoader();
103         System.out.println("loader resource");
104         InputStream inputStream = loader.getResourceAsStream("ReportGeneratorConfiguration.properties");
105         System.out.println("new properties");
106
107         configuration= new PropertiesConfiguration();
108         System.out.println("stream");
109         System.out.println(inputStream.toString());
110         System.out.println("load");
111         configuration.load(inputStream);
112         System.out.println("init");
113         reportManagerService.init(configuration, "");
114         System.out.println(configuration.getString("ReportDefinitionRepositoryPath"));
115         reportManager = reportManagerService;
116       }
117       catch (Exception JavaDoc e) {
118         System.out.println("Error instanciando ReportManager"+e.getMessage());
119         System.exit(1);
120       }
121     }
122     return reportManager;
123   }
124
125 }
126
Popular Tags