KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.calipso.reportgenerator.userinterface;
2
3 import com.calipso.reportgenerator.reportdefinitions.types.ReportDefinitionReportTypeType;
4 import com.calipso.reportgenerator.reportdefinitions.ReportView;
5 import com.calipso.reportgenerator.reportdefinitions.ReportDefinition;
6 import com.calipso.reportgenerator.reportdefinitions.Roles;
7 import com.calipso.reportgenerator.userinterface.dinamicchart.ChartPivotTable;
8 import com.calipso.reportgenerator.common.*;
9 import com.calipso.reportgenerator.client.ReportManagerService;
10
11 import javax.swing.*;
12 import java.awt.*;
13 import java.awt.event.ActionListener JavaDoc;
14 import java.awt.event.ActionEvent JavaDoc;
15 import java.util.*;
16 import java.io.*;
17 import java.net.URL JavaDoc;
18 import java.net.InetAddress JavaDoc;
19 import java.net.UnknownHostException JavaDoc;
20
21 import com.calipso.reportgenerator.common.InfoException;
22 import com.calipso.reportgenerator.usermanager.UserManagerFrame;
23 import com.calipso.xmleditor.XmlEditorConnectionPane;
24
25 /**
26  * Visualizador de reportes
27  */

28 public class ReportViewer extends JFrame implements IReportFrame {
29
30   public static final String JavaDoc defaultRol = "ANY";
31   private ReportViewerToolBar reportViewerToolBar;
32   private JPanel mainPanel;
33   private JPanel toolBarPanel;
34   private JPanel reportPanel;
35   private JMenu menu;
36   private JMenuBar menuBar;
37   private JComboBox comboReports;
38   private JComboBox comboProfiles;
39   private JButton executeNewReportBtn;
40   private PivotTableFrame pivotTableFrame;
41   private JLabel reportsLabel;
42   private int btnWIDTH = 90;
43   private int btnHEIGTH = 45;
44   private IReportManager reportManager;
45   private String JavaDoc userID;
46   private String JavaDoc userData;
47   private String JavaDoc reportDefinitionID;
48   private String JavaDoc reportViewID;
49   private ReportGeneratorConfiguration reportGeneratorConfiguration;
50   private String JavaDoc propertiesPath="";
51   private boolean visibleActions;
52   private Map params;
53   private JToolBar jToolBar;
54   private JToggleButton btSizes;
55   private JMenuItem miXmlExporter;
56   private JToggleButton btTotals;
57   private boolean btTotalsState;
58   private boolean btSizesState;
59   private JToggleButton printButton;
60   private JToggleButton exportMicroReportButton;
61   private JToggleButton graphicButton;
62   private JToggleButton semaforo;
63   private JToggleButton searcher;
64   private JToggleButton excel;
65   private JToggleButton viewBtn;
66   private JToggleButton editDimensionValueBtn;
67   private JToggleButton ordenBtn;
68   private JPanel actionsToolBarPanel;
69   private JPanel comboReportPanel;
70   private JMenu mnuReportTools;
71   private JMenuItem mnuItemGenerateReportFromSQL;
72   private JMenuItem mnuItemGenerateReportView;
73   private JMenuItem mnuItemGenerateReportLayout;
74   private JMenuItem mnuEditReportDefinition;
75   private JMenuItem mnuEditReportSourceDefinition;
76   private JMenuItem mnuUsersMannager;
77   private XmlEditorConnectionPane connectionPane;
78
79   /**
80    * Inicializa el visualizador con un usuario
81    * @param userID
82    * @param visibleActions Indica si se muesttran las acciones
83    * @throws InfoException
84    */

85   public ReportViewer(String JavaDoc userID, boolean visibleActions) throws InfoException {
86     this.userID = userID;
87     this.visibleActions = visibleActions;
88     initViewer();
89   }
90
91   public ReportViewer(String JavaDoc userID, String JavaDoc reportDefinitionID, boolean visibleActions, Map params) throws InfoException {
92     this.userID = userID;
93     this.reportDefinitionID = reportDefinitionID;
94     this.visibleActions = visibleActions;
95     this.params = params;
96     initViewer();
97     executeInitialReport();
98   }
99
100   public ReportViewer(String JavaDoc userID, String JavaDoc microReportFileName, boolean inServer, String JavaDoc propertiesPath, IReportManager reportManager, boolean visibleActions, Map params) throws InfoException {
101     this.userID = userID;
102     this.propertiesPath = propertiesPath;
103     this.reportManager = reportManager;
104     this.visibleActions = visibleActions;
105     this.params = params;
106     this.reportDefinitionID = "";
107     this.reportViewID = "";
108     initViewer();
109     //if(!inServer){
110
executeMicroReport(microReportFileName, inServer);
111     //}else{
112
// executeMicroReport(microReportFileName);
113
//}
114
}
115
116
117   public ReportViewer(String JavaDoc userID, String JavaDoc reportDefinitionID, String JavaDoc reportViewID, boolean visibleActions, Map params) throws InfoException {
118     this.userID = userID;
119     this.reportDefinitionID = reportDefinitionID;
120     this.reportViewID = reportViewID;
121     this.visibleActions = visibleActions;
122     this.params = params;
123     initViewer();
124     executeInitialReport();
125   }
126
127   public ReportViewer(String JavaDoc userID, String JavaDoc reportDefinitionID, String JavaDoc reportViewID, String JavaDoc propertiesPath, boolean visibleActions, Map params) throws InfoException {
128     this.userID = userID;
129     this.reportDefinitionID = reportDefinitionID;
130     this.reportViewID = reportViewID;
131     this.propertiesPath = propertiesPath;
132     this.visibleActions = visibleActions;
133     this.params = params;
134     initViewer();
135     executeInitialReport();
136   }
137
138   public ReportViewer(String JavaDoc userID, String JavaDoc reportDefinitionID, String JavaDoc reportViewID, String JavaDoc propertiesPath, IReportManager reportManager, boolean visibleActions, Map params) throws InfoException {
139     this.userID = userID;
140     this.reportDefinitionID = reportDefinitionID;
141     this.reportViewID = reportViewID;
142     this.propertiesPath = propertiesPath;
143     this.reportManager = reportManager;
144     this.visibleActions = visibleActions;
145     this.params = params;
146     initViewer();
147     executeInitialReport();
148   }
149
150   public ReportViewer(String JavaDoc userID, String JavaDoc reportDefinitionID, String JavaDoc reportViewID, String JavaDoc propertiesPath, IReportManager reportManager, ReportGeneratorConfiguration configuration, boolean visibleActions, Map params) throws InfoException {
151     this.userID = userID;
152     this.reportDefinitionID = reportDefinitionID;
153     this.reportViewID = reportViewID;
154     this.propertiesPath = propertiesPath;
155     this.reportManager = reportManager;
156     this.reportGeneratorConfiguration = configuration;
157     this.visibleActions = visibleActions;
158     this.params = params;
159     initViewer();
160     executeInitialReport();
161   }
162
163   /**
164    * Inicializa el Visualizador
165    * @throws InfoException
166    */

167   protected void initViewer() throws InfoException {
168     Image icon = null;
169     try{
170       icon = getReportGeneratorConfiguration().getImage("icon");
171       /*if(icon == null){
172         URL url = this.getClass().getClassLoader().getResource("com/calipso/reportgenerator/userinterface/images/" + getReportGeneratorConfiguration().getFrameworkPlatform() + "/icon.jpg");
173         icon = Toolkit.getDefaultToolkit().getImage(url);
174       }*/

175     }catch (Exception JavaDoc e){
176       e.printStackTrace();
177     }
178     if(icon != null) {
179       setIconImage(icon);
180     }
181     setTitle(LanguageTraslator.traslate("313") + " - " + LanguageTraslator.traslate("141") + ": " + getUserData(userID));
182     launchSplash();
183     loadComboReports();
184     initComponents();
185     logClientData("Loggin");
186   }
187
188   private void logClientData(String JavaDoc log) throws InfoException {
189     InetAddress JavaDoc addr = null;
190     try {
191       addr = InetAddress.getLocalHost();
192     } catch (UnknownHostException JavaDoc e) {
193       e.printStackTrace();
194     }
195     getReportManager().logClientData(System.getProperty("user.name") + " - " + addr.getHostName() + " - " + addr.getHostAddress() + " - User: " + userID + " - " + log);
196   }
197
198   private void launchSplash() throws InfoException {
199     String JavaDoc splashPath = getApplicationSplashPath();
200     //if(splashPath != null) {
201
ApplicationSplash splash = new ApplicationSplash(this, splashPath, getReportGeneratorConfiguration().getFrameworkPlatform());
202       splash.showSplashScreen();
203     //}
204
}
205
206   private String JavaDoc getApplicationSplashPath() throws InfoException {
207     String JavaDoc splashPath = null;
208     splashPath = getReportGeneratorConfiguration().getImagePath("SPLASH");
209     return splashPath;
210   }
211
212   /**
213    * Si está indicado el reporte lo ejecuta
214    */

215   private void executeInitialReport() throws InfoException {
216     if (!getUserID().equals("")&&((!reportViewID.equals(""))||(!reportDefinitionID.equals("")))){
217       try{
218         executeReport(reportDefinitionID, reportViewID, params);//executeReport(reportDefinitionID,"");
219
}finally{
220         setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
221       }
222     }
223   }
224
225   /**
226    * Carga el combo de reportes disponibles
227    * @throws InfoException
228    */

229   private void loadComboReports() throws InfoException {
230     if (visibleActions) {
231       DefaultComboBoxModel model = new DefaultComboBoxModel(getComboModelVector());
232       getComboReports().setModel(model);
233       updateComboProfiles();
234     }
235   }
236
237   private void updateComboProfiles() {
238     DefaultComboBoxModel model = null;
239     try {
240       model = new DefaultComboBoxModel(getComboProfilesModelVector());
241       getComboProfiles().setModel(model);
242     } catch (InfoException e) {
243       ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("369"), e);
244     }
245
246   }
247
248   private Vector getComboProfilesModelVector() throws InfoException {
249     Vector result = new Vector();
250     Map definitionsMap;
251     DefinitionInfo definitionInfo;
252     Map.Entry entry;
253     Object JavaDoc selectedItem = getComboReports().getSelectedItem();
254     if (selectedItem != null){
255       String JavaDoc id = ((DefinitionInfo)getComboReports().getSelectedItem()).getId();
256       definitionsMap = getReportManager().getReportViews(id,userID);
257       definitionInfo = new DefinitionInfo("",LanguageTraslator.traslate("184"));
258       result.add(definitionInfo);
259       if (definitionsMap != null){
260         Iterator iterator = definitionsMap.entrySet().iterator();
261         while (iterator.hasNext()) {
262           entry = (Map.Entry) iterator.next();
263           definitionInfo = (DefinitionInfo)entry.getValue();
264           result.add(definitionInfo);
265         }
266       }
267     }
268     return result;
269   }
270
271   /**
272    * Inicializa los componentes
273    */

274   private void initComponents() throws InfoException {
275     getContentPane().setLayout(new BorderLayout());
276     this.setJMenuBar(createMenu());
277     getContentPane().add(createMainPanel());//,BorderLayout.CENTER);
278

279     pack();
280     java.awt.Dimension JavaDoc screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
281     setSize(new java.awt.Dimension JavaDoc(800,550));
282     setLocation((screenSize.width - 800) / 2, (screenSize.height - 550) / 2);
283   }
284
285   private ReportViewerToolBar createReportViewerToolBar() {
286     if(reportViewerToolBar == null) {
287       reportViewerToolBar = new ReportViewerToolBar();
288     }
289     return reportViewerToolBar;
290   }
291
292
293   private Object JavaDoc makeNavigationButton(String JavaDoc imageName,
294                                       String JavaDoc actionCommand,
295                                       String JavaDoc toolTipText,
296                                       String JavaDoc altText,
297                                       boolean isToggle) {
298
299
300     ClassLoader JavaDoc loader = this.getClass().getClassLoader();
301       URL JavaDoc url = loader.getResource("com/calipso/reportgenerator/userinterface/images/" + imageName + ".gif");
302
303     /*String imgLocation = com.calipso.reportgenerator.userinterface.images
304                           reportGeneratorConfiguration.getImagesPath()
305                          + "\\" + imageName
306                          + ".gif"; */

307
308     //Create and initialize the button.
309

310     Object JavaDoc button = null;
311     if(isToggle) {
312       button = new JToggleButton();
313       ((JToggleButton)button).setActionCommand(actionCommand);
314       ((JToggleButton)button).setToolTipText(toolTipText);
315       if (url!= null) {
316         ((JToggleButton)button).setIcon(new ImageIcon(url, altText));
317       } else {
318         ((JToggleButton)button).setText(altText);
319       }
320     } else {
321       button = new JButton();
322       ((JButton)button).setActionCommand(actionCommand);
323       ((JButton)button).setToolTipText(toolTipText);
324       if (url != null) {
325         ((JButton)button).setIcon(new ImageIcon(url, altText));
326       } else {
327         ((JButton)button).setText(altText);
328       }
329     }
330
331     return button;
332   }
333
334
335   /**
336    * Crea el menu
337    * @return
338    */

339   private JMenuBar createMenu() {
340     menuBar = new JMenuBar();
341     if (visibleActions){
342       menu = new JMenu(LanguageTraslator.traslate("294"));
343       JMenuItem menuItem;
344       menuItem = new JMenuItem(LanguageTraslator.traslate("249"));
345       menuItem.addActionListener(new ActionListener JavaDoc() {
346         public void actionPerformed(ActionEvent JavaDoc e) {
347           try{
348             registerDefinitions();
349           }
350           catch (Exception JavaDoc e1) {
351             ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("257"), e1);
352           }
353
354         }
355       });
356       menu.add(menuItem);
357
358       menuItem = new JMenuItem(LanguageTraslator.traslate("248"));
359       menuItem.addActionListener(new ActionListener JavaDoc() {
360         public void actionPerformed(ActionEvent JavaDoc e) {
361           try{
362             clearRepository();
363           }
364           catch (Exception JavaDoc e1) {
365             ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("257"), e1);
366           }
367
368         }
369       });
370       menu.add(menuItem);
371
372       miXmlExporter = new JMenuItem(LanguageTraslator.traslate("354"));
373       miXmlExporter.addActionListener(new ActionListener JavaDoc() {
374         public void actionPerformed(ActionEvent JavaDoc e) {
375           try{
376             exportToXml();
377           }
378           catch (Exception JavaDoc e1) {
379             ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("263"), e1);
380           }
381         }
382       });
383       menu.add(miXmlExporter);
384
385       menuItem = new JMenuItem(LanguageTraslator.traslate("264"));
386       menuItem.addActionListener(new ActionListener JavaDoc() {
387         public void actionPerformed(ActionEvent JavaDoc e) {
388           try{
389             loadMicroReport();
390           }
391           catch (Exception JavaDoc e1) {
392             ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("263"), e1);
393           }
394         }
395       });
396       menu.add(menuItem);
397
398       menu.add(new JSeparator());
399
400       menuItem = new JMenuItem(LanguageTraslator.traslate("144"));
401       menuItem.addActionListener(new ActionListener JavaDoc() {
402         public void actionPerformed(ActionEvent JavaDoc e) {
403           try{
404             saveLastView();
405             dispose();
406             System.exit(0);
407           }
408           catch (Exception JavaDoc e1) {
409             ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("263"), e1);
410           }
411         }
412       });
413       menu.add(menuItem);
414       menuBar.add(menu);
415       if (!reportGeneratorConfiguration.getIsDistributed()){
416         menuBar.add(CreateReportToolMenu());
417       }
418       menuBar.add(CreateHelpMenu());
419     }
420     return menuBar;
421   }
422
423   private JMenu CreateReportToolMenu() {
424     mnuReportTools = new JMenu(LanguageTraslator.traslate("535"));
425
426     mnuItemGenerateReportFromSQL = new JMenuItem(LanguageTraslator.traslate("560"));
427     mnuItemGenerateReportFromSQL.addActionListener( new ActionListener JavaDoc() {
428               public void actionPerformed(ActionEvent JavaDoc e) {
429                 try{
430                   reportFromSQL();
431                 }
432                 catch (Exception JavaDoc e1) {
433                   ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("536"), e1);
434                 }
435               }
436
437     });
438
439     mnuReportTools.add(mnuItemGenerateReportFromSQL);
440
441     mnuItemGenerateReportView = new JMenuItem(LanguageTraslator.traslate("561"));
442     mnuItemGenerateReportView.addActionListener(new ActionListener JavaDoc() {
443               public void actionPerformed(ActionEvent JavaDoc e) {
444                 try{
445                   createReportFrame();
446                 }
447                 catch (Exception JavaDoc e1) {
448                   ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("536"), e1);
449                 }
450               }
451
452     });
453     //mnuReportTools.add(mnuItemGenerateReportView);
454

455     mnuItemGenerateReportLayout = new JMenuItem(LanguageTraslator.traslate("562"));
456     mnuItemGenerateReportLayout.addActionListener(new ActionListener JavaDoc() {
457               public void actionPerformed(ActionEvent JavaDoc e) {
458                 try{
459                   createReportLayout();
460                 }
461                 catch (Exception JavaDoc e1) {
462                   ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("536"), e1);
463                 }
464               }
465     });
466
467     mnuReportTools.add(mnuItemGenerateReportLayout);
468     mnuReportTools.setMnemonic("g".charAt(0));
469
470     mnuEditReportDefinition = new JMenuItem(LanguageTraslator.traslate("537"));
471     mnuEditReportDefinition.addActionListener(new ActionListener JavaDoc() {
472               public void actionPerformed(ActionEvent JavaDoc e) {
473                 try{
474                   if (!reportDefinitionID.equalsIgnoreCase("")){
475                     editReportDefinition();
476                   }else {
477                     throw new InfoException(LanguageTraslator.traslate("557"));
478                   }
479                 }
480                 catch (Exception JavaDoc e1) {
481                   ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("539"), e1);
482                 }
483               }
484
485     });
486     mnuReportTools.add(mnuEditReportDefinition);
487
488     mnuEditReportSourceDefinition = new JMenuItem(LanguageTraslator.traslate("538"));
489     mnuEditReportSourceDefinition.addActionListener(new ActionListener JavaDoc() {
490               public void actionPerformed(ActionEvent JavaDoc e) {
491                 try{
492                   if (!reportDefinitionID.equalsIgnoreCase("")){
493                     editReportSourceDefinition();
494                   }else {
495                     throw new InfoException(LanguageTraslator.traslate("557"));
496                   }
497
498                 }
499                 catch (Exception JavaDoc e1) {
500                   ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("540"), e1);
501                 }
502               }
503     });
504     mnuReportTools.add(mnuEditReportSourceDefinition);
505
506
507     mnuUsersMannager = new JMenuItem(LanguageTraslator.traslate("587"));
508     mnuUsersMannager.addActionListener(new ActionListener JavaDoc() {
509               public void actionPerformed(ActionEvent JavaDoc e) {
510                 try {
511                   if (userID.equalsIgnoreCase("root")&&(!reportGeneratorConfiguration.getIsDistributed())){
512                     editUserManager();
513                   } else {
514                     throw new InfoException(LanguageTraslator.traslate("589"));
515                   }
516                 }catch (Exception JavaDoc e1) {
517                   ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("588"), e1);
518                 }
519               }
520     });
521     mnuReportTools.add(mnuUsersMannager);
522
523     return mnuReportTools;
524   }
525
526   private void editUserManager() throws InfoException {
527     UserManagerFrame userManagerFrame = new UserManagerFrame(true,getReportGeneratorConfiguration());
528     userManagerFrame.setVisible(true);
529   }
530
531
532   private void reportFromSQL() throws InfoException {
533     ReportFromSQL reportFromSQL = new ReportFromSQL(this,reportGeneratorConfiguration);
534     reportFromSQL.createReportFrame();
535   }
536
537   private void editReportDefinition() throws InfoException {
538     DefinitionEditor.reportDefinitionEditor(reportDefinitionID, getReportGeneratorConfiguration());
539   }
540
541
542   private void editReportSourceDefinition() throws InfoException {
543     DefinitionEditor.reportSourceDefinitionEditor(reportDefinitionID, getReportGeneratorConfiguration());
544   }
545
546   private JMenu CreateHelpMenu() {
547     JMenu menuHelp;
548     menuHelp = new JMenu();
549     menuHelp = new JMenu(LanguageTraslator.traslate("383"));
550     JMenuItem menuItem;
551     menuItem = new JMenuItem(LanguageTraslator.traslate("384"));
552     menuItem.addActionListener(new ActionListener JavaDoc() {
553       public void actionPerformed(ActionEvent JavaDoc e) {
554         JOptionPane.showMessageDialog(null,LanguageTraslator.traslate("313")+ " - "+ LanguageTraslator.traslate("385")+" "+VersionProperties.versionNumber );
555         //showExceptionMessageDialog. initExceptionDialogMessage()
556
}
557     });
558     menuHelp.add(menuItem);
559     return menuHelp;
560   }
561
562   /**
563    * Permite grabar la última vista del reporte para tenerla posteriormente disponible
564    */

565   private void saveLastView() {
566     if ((pivotTableFrame != null ) && (pivotTableFrame.getPivotTable() !=null)&& (pivotTableFrame.getReportResult().getReportSpec().getDefinitionId().equals(reportDefinitionID))) {
567       int result = JOptionPane.showConfirmDialog(this, LanguageTraslator.traslate("370"), LanguageTraslator.traslate("109"),JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
568       if(result==JOptionPane.YES_OPTION){
569         try {
570           pivotTableFrame.getPivotTable().executeAplicationView();
571         } catch (InfoException e) {
572           ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("371"), e);
573         }
574       }
575     }
576   }
577
578
579   private void exportToXml() {
580     try {
581       JFileChooser fileChooser = new JFileChooser();
582       int result = fileChooser.showSaveDialog(this);
583       if(result == JFileChooser.APPROVE_OPTION) {
584         File file = fileChooser.getSelectedFile();
585         FileWriter fileWriter = new FileWriter(file);
586         String JavaDoc xml = getReportManager().getXML(pivotTableFrame.getReportHandle());
587         BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
588         char [] cbuff = new char[xml.length()];
589         for(int i = 0 ; i < cbuff.length ; i++) {
590           cbuff [i] = xml.charAt(i);
591         }
592         bufferedWriter.write(cbuff);
593         bufferedWriter.close();
594         fileWriter.close();
595       }
596     } catch (Exception JavaDoc e) {
597       ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("195"), e);
598     }
599   }
600
601   /**
602    * Borra los repositorios
603    * @throws InfoException
604    */

605   private void clearRepository() throws InfoException {
606     getReportManager().deleteAllDefinitions();
607     updateReportComboBox();
608   }
609
610   /**
611    * Registra las definiciones
612    *
613    */

614   private void registerDefinitions() throws InfoException {
615     try{
616       Vector vector = getReportManager().registerReportDefinitions(new Vector());
617       showExceptionsFrom(vector);
618     }
619     catch (Exception JavaDoc e1) {
620       ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("257"), e1);
621     }
622     try{
623       Vector vector = getReportManager().registerReportSourceDefinitions(new Vector());
624       showExceptionsFrom(vector);
625     }
626     catch (Exception JavaDoc e1) {
627       ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("257"), e1);
628     }
629     try{
630       Vector vector = getReportManager().registerReportViews(new Vector());
631       showExceptionsFrom(vector);
632     }
633     catch (Exception JavaDoc e1) {
634       ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("257"), e1);
635     }
636     updateReportComboBox();
637   }
638
639   private void showExceptionsFrom(Vector vector) {
640     if(vector.size() > 0) {
641       for(int i = 0 ; i < vector.size() ; i++) {
642         ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("257"), (Exception JavaDoc) vector.elementAt(i));
643       }
644     }
645   }
646
647   /**
648    * Carga un MicroReport
649    */

650   private void loadMicroReport() {
651     JFileChooser fileChooser = new JFileChooser();
652     fileChooser.setMultiSelectionEnabled(true);
653     int mode = fileChooser.showDialog(this, LanguageTraslator.traslate("270"));
654     if (mode == JFileChooser.APPROVE_OPTION) {
655       File file = fileChooser.getSelectedFile();
656       executeMicroReport(file.getAbsolutePath(), false);
657     }
658   }
659
660   private void executeMicroReport(String JavaDoc fileName, boolean serverLocated){
661     try {
662       reportViewerToolBar = createReportViewerToolBar();
663       reportViewerToolBar.microReportLoaded();
664       MicroReport micro;
665       if(!serverLocated){
666         micro = new MicroReport(fileName ,getReportGeneratorConfiguration());
667       }else{
668         micro = getReportManager().getMicroReport(fileName);
669       }
670       String JavaDoc[] roles = getRoles(micro.getReportDefinition()); //TODO pasar esto urgente al ReportManager
671
if(!getReportManager().validateRol(roles, getUserID(), getReportGeneratorConfiguration().getRolsRepositoryPath())){
672         throw new InfoException(LanguageTraslator.traslate("396"));
673       }
674       pivotTableFrame = new PivotTableFrame(this, micro, getReportManager(), getUserID(),getReportGeneratorConfiguration());
675       reportViewerToolBar.setPivotTableFrame(pivotTableFrame);
676       reportPanel.setLayout(new GridLayout(1, 1));
677       reportPanel.removeAll();
678       reportPanel.add(pivotTableFrame.getCenterPanel());
679       validate();
680       reportPanel.repaint();
681     }catch(Exception JavaDoc e){
682       ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("269"), e);
683     }
684
685   }
686
687   private String JavaDoc[] getRoles(ReportDefinition reportDefinition) {
688     Roles roles = reportDefinition.getRoles();
689     if(roles==null){
690       return new String JavaDoc[]{defaultRol} ;
691     }
692     int rolCount = roles.getRolCount();
693     ArrayList rolesNames = new ArrayList();
694     for(int i=0; i < rolCount; i++){
695       if(roles.getRol(i)!=null && roles.getRol(i).getName()!=null && !roles.getRol(i).getName().equalsIgnoreCase("")){
696         rolesNames.add(roles.getRol(i).getName());
697       }
698     }
699     if(rolesNames.size()==0){
700       rolesNames.add(defaultRol);
701     }
702     String JavaDoc[] rolesArray = fillArray(rolesNames);
703     return rolesArray;
704   }
705
706   private String JavaDoc[] fillArray(ArrayList rolesNames) {
707     Iterator iterator = rolesNames.iterator();
708     String JavaDoc[] result = new String JavaDoc[rolesNames.size()];
709     for(int i=0; iterator.hasNext(); i++){
710       result[i] = iterator.next().toString().toUpperCase();
711     }
712     return result;
713   }
714
715   /**
716    * Acualiza en como de reportes disponibles
717    * @throws InfoException
718    */

719   private void updateReportComboBox() throws InfoException {
720     comboReports.removeAllItems();
721     loadComboReports();
722     comboReports.repaint();
723   }
724
725   /**
726    * Crea el panel central
727    * @return
728    */

729   private JPanel createMainPanel() throws InfoException {
730     mainPanel = new JPanel();
731     mainPanel.setLayout(new BorderLayout());
732     mainPanel.add(createToolbarPanel(),BorderLayout.NORTH);
733     mainPanel.add(createPivotTablePanel(),BorderLayout.CENTER);
734     return mainPanel;
735   }
736
737   private JPanel createActionsToolbarPanel() {
738     actionsToolBarPanel = new JPanel();
739     //if (visibleActions){
740
FlowLayout layout = new FlowLayout(FlowLayout.LEFT);
741       layout.setHgap(1);
742       actionsToolBarPanel.setPreferredSize(new Dimension(300, 40));
743       actionsToolBarPanel.setLayout(layout);
744       actionsToolBarPanel.add(createReportViewerToolBar());
745       reportViewerToolBar.definitionExecuted();
746     //}
747
return actionsToolBarPanel;
748   }
749
750   private JPanel createPivotTablePanel() throws InfoException {
751     Toolkit tk;
752     Image image=null;
753     tk = Toolkit.getDefaultToolkit();
754     try{
755       image = getReportGeneratorConfiguration().getImage("backgroundreportviewer");
756       /*String imagePath = getReportGeneratorConfiguration().getImagePath("BACKGROUNDREPORTVIEWER");
757       if(imagePath!=null){
758         image = tk.getImage(imagePath);
759       }
760       if(image == null){
761         //Viene de jar
762         URL url = this.getClass().getClassLoader().getResource("com/calipso/reportgenerator/userinterface/images/" + getReportGeneratorConfiguration().getFrameworkPlatform() + "/" + "BACKGROUNDREPORTVIEWER.jpg");
763         image = tk.getImage(url);
764       }*/

765     }catch(Exception JavaDoc e){
766       ReportManagerLogger.debug(LanguageTraslator.traslate("318"),e);
767     }
768     reportPanel = new ImagePanel(image);
769 // reportPanel = new JPanel();
770
return reportPanel;
771   }
772
773
774
775   /**
776    * Crea el panel de barra de herramientas
777    * @return
778    */

779   private JPanel createToolbarPanel() {
780     toolBarPanel = new JPanel(new BorderLayout());
781     toolBarPanel.add(createActionsToolbarPanel(),BorderLayout.NORTH);
782     toolBarPanel.add(createComboReportPanel(),BorderLayout.SOUTH);
783     return toolBarPanel;
784   }
785
786   private JPanel createComboReportPanel() {
787     comboReportPanel = new JPanel();
788     if (visibleActions){
789       comboReportPanel.setPreferredSize(new Dimension(300, 30));
790       comboReportPanel.setLayout(new javax.swing.BoxLayout JavaDoc(comboReportPanel, javax.swing.BoxLayout.X_AXIS));
791       comboReportPanel.setBorder(new javax.swing.border.TitledBorder JavaDoc(""));
792       comboReportPanel.add(createNewReportLabel());
793       comboReportPanel.add(createNewReportComboBox());
794       comboReportPanel.add(createProfilesComboBox());
795       comboReportPanel.add(createNewReportBtn());
796     }
797     return comboReportPanel;
798   }
799
800   private Component createProfilesComboBox() {
801     getComboProfiles().setBounds(240, 22, 20, 10);
802     return getComboProfiles();
803   }
804
805   /**
806    * Crea el combo de reportes
807    * @return
808    */

809   private Component createNewReportComboBox() {
810     getComboReports().setBounds(100, 22, 140, 10);
811     return getComboReports();
812   }
813
814   /**
815    * Crea el boton de ejecución de un nuevo reporte
816    * @return
817    */

818   private Component createNewReportBtn() {
819     executeNewReportBtn = (JButton) makeNavigationButton("play", "EJECUTAR", LanguageTraslator.traslate("353"), "", false);
820     executeNewReportBtn.setMaximumSize(new java.awt.Dimension JavaDoc(btnWIDTH, btnHEIGTH));
821     executeNewReportBtn.setMinimumSize(new java.awt.Dimension JavaDoc(btnWIDTH, btnHEIGTH));
822     executeNewReportBtn.setPreferredSize(new java.awt.Dimension JavaDoc(btnWIDTH, btnHEIGTH));
823     executeNewReportBtn.addActionListener(new ActionListener JavaDoc() {
824       public void actionPerformed(ActionEvent JavaDoc e) {
825         try {
826           saveLastView();
827           executeReport(((DefinitionInfo)comboReports.getSelectedItem()).getId(),((DefinitionInfo)comboProfiles.getSelectedItem()).getId(), new HashMap());
828           updateComboProfiles();
829           reportDefinitionID = ((DefinitionInfo)comboReports.getSelectedItem()).getId();
830         }catch (Exception JavaDoc ex) {
831           ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("293"), ex);
832         }finally{
833           setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
834         }
835       }
836     });
837     return executeNewReportBtn;
838   }
839
840   /**
841    * Crea la etiqueta de nuevo reporte
842    * @return
843    */

844   private Component createNewReportLabel() {
845     reportsLabel = new JLabel();
846     reportsLabel.setText(LanguageTraslator.traslate("290"));
847     reportsLabel.setMaximumSize(new java.awt.Dimension JavaDoc(btnWIDTH, btnHEIGTH));
848     reportsLabel.setMinimumSize(new java.awt.Dimension JavaDoc(btnWIDTH, btnHEIGTH));
849     reportsLabel.setPreferredSize(new java.awt.Dimension JavaDoc(btnWIDTH, btnHEIGTH));
850     return reportsLabel;
851   }
852
853   /**
854    * Devuelve el combo de reportes
855    * @return
856    */

857   public JComboBox getComboReports() {
858       if (comboReports == null) {
859         comboReports = new JComboBox();
860         comboReports.addActionListener(new ActionListener JavaDoc() {
861         public void actionPerformed(ActionEvent JavaDoc e) {
862           updateComboProfiles();
863         }
864       });
865       }
866       return comboReports;
867     }
868
869   public JComboBox getComboProfiles() {
870       if (comboProfiles == null) {
871         comboProfiles = new JComboBox();
872       }
873       return comboProfiles;
874     }
875
876
877   /**
878    * Ejecute el reporte indicado
879    */

880   private void executeReport(String JavaDoc reportDefinitionId,String JavaDoc viewId, Map existingParams) throws InfoException {
881     ReportSpec reportSpec = getReportManager().getReportSpec(reportDefinitionId);
882     String JavaDoc[] roles = getRoles(getReportManager().getReportDefinitionFromID(reportDefinitionId));
883     if(!getReportManager().validateRol(roles, getUserID(), getReportGeneratorConfiguration().getRolsRepositoryPath())){
884       throw new InfoException(LanguageTraslator.traslate("396"));
885     }
886     logClientData(reportDefinitionId);
887     params = UPDialog.getParams(this, reportSpec, reportGeneratorConfiguration, existingParams);
888     reportSpec.setPosParamValues(params);
889     if (params != null) {
890       if (reportSpec.getReportType().getType() == ReportDefinitionReportTypeType.CUBE_TYPE) {
891         setCursor(new Cursor(Cursor.WAIT_CURSOR));
892         if ((!reportDefinitionId.equals("")) && (!getUserID().equals(""))){
893           pivotTableFrame=null;
894           if (!viewId.equals("")){
895             pivotTableFrame = new PivotTableFrame(this, reportDefinitionId,getReportManager(),getParams(),getUserID(),viewId,getReportGeneratorConfiguration());
896           }else if (!reportViewID.equals("")){
897             pivotTableFrame = new PivotTableFrame(this, reportDefinitionId,getReportManager(),getParams(),getUserID(),reportViewID,getReportGeneratorConfiguration());
898           }else if (!reportDefinitionId.equals("")){
899             String JavaDoc defaultReportView = getReportManager().getDefaultReportViewId(reportDefinitionId,getUserID());
900             if (defaultReportView == null || defaultReportView.equals("")){
901               pivotTableFrame = new PivotTableFrame(this, reportDefinitionId,getReportManager(),getParams(),getUserID(),getReportGeneratorConfiguration());
902             }else{
903               pivotTableFrame = new PivotTableFrame(this, reportDefinitionId,getReportManager(),getParams(),getUserID(),defaultReportView,getReportGeneratorConfiguration());
904             }
905           }
906           String JavaDoc tittle = pivotTableFrame.getReportResult().getReportSpec().getTitle();
907           setTitle(LanguageTraslator.traslate("313") + " - " + LanguageTraslator.traslate("141") + ": " + getUserData(userID) + " - " + tittle);
908
909           reportViewerToolBar.setPivotTableFrame(pivotTableFrame);
910           if (pivotTableFrame!=null){
911             JPanel pnlCenter = pivotTableFrame.getCenterPanel();
912             reportPanel.setLayout(new GridLayout(1, 1));
913             reportPanel.removeAll();
914             reportPanel.add(pnlCenter);
915             validate();
916             reportPanel.repaint();
917           }
918         }
919         reportViewerToolBar.cubeExecuted();
920         setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
921       } else if(reportSpec.getReportType().getType() == ReportDefinitionReportTypeType.CHARTCUBE_TYPE) {
922         setCursor(new Cursor(Cursor.WAIT_CURSOR));
923         ChartPivotTable chartPivotTable = new ChartPivotTable(reportSpec, getReportManager() , getParams(), userID, reportDefinitionId, this);
924         chartPivotTable.paintComponents(true);
925         reportPanel.setLayout(new GridLayout(1, 1));
926         reportPanel.removeAll();
927         reportPanel.add(chartPivotTable, BorderLayout.CENTER);
928         validate();
929         setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
930         reportViewerToolBar.chartcubeExecuted();
931       }else if(reportSpec.getReportType().getType() == ReportDefinitionReportTypeType.STATICSQL_TYPE){
932         try{
933           ReportUI reportUI = null;
934           String JavaDoc reportView = !viewId.equalsIgnoreCase("") ? viewId : reportViewID;
935           ReportView view = null;
936           try{
937             view = getReportManager().getReportViewFromID(reportView, reportSpec.getDefinitionId(), getUserID());
938           }catch (Exception JavaDoc e){
939             //No obtiene ninguna view
940
}
941           reportUI = new ReportUI(null, reportSpec, getReportManager(), getReportGeneratorConfiguration(), view, this.getSize());
942           reportUI.show();
943         }catch (Exception JavaDoc e){
944           throw new InfoException(LanguageTraslator.traslate("222"), e);
945         }
946       }else {
947         try {
948           ReportResult reportResult = getReportManager().ExecReportQuery(reportSpec.getDefinitionId(), getParams());
949           ReportUI reportUI = null;
950           String JavaDoc reportView = !viewId.equalsIgnoreCase("") ? viewId : reportViewID;
951           ReportView view = null;
952           if(reportView!=null && !reportView.equalsIgnoreCase("")){
953             view = getReportManager().getReportViewFromID(reportView, reportSpec.getDefinitionId(), getUserID());
954           }
955           reportUI = new ReportUI(reportResult,reportResult.getReportSpec(), getReportManager(),getReportGeneratorConfiguration(), view, this.getSize());
956           if(reportUI!=null){
957             reportUI.show();
958           }
959         }
960         catch (Exception JavaDoc e) {
961           throw new InfoException(LanguageTraslator.traslate("222"), e);
962         }
963       }
964     }
965   }
966
967   /**
968    * Devuelve el usuario
969    * @return
970    */

971   private String JavaDoc getUserID() {
972     if (userID.equals("")){
973       LoginFrame loginFrame = new LoginFrame("user",new ReportLoginValidator());
974       loginFrame.login();
975       if (loginFrame.getLoginResult() == 0){
976         userID = loginFrame.getUserNameText().getText();
977       }
978     }
979     return userID;
980   }
981
982   public String JavaDoc getUserData(String JavaDoc userID) throws InfoException{
983     if(userData==null){
984       userData = "";
985       Collection dataCollection = getReportManager().getUserData(userID, getReportGeneratorConfiguration().getUserDataRepositoryPath());
986       if(dataCollection!=null){
987         Iterator data = dataCollection.iterator();
988         while(data.hasNext()){
989           if(!userData.equalsIgnoreCase("")){
990             userData += ", ";
991           }
992           userData += data.next().toString();
993         }
994       }
995     }
996     return userData;
997   }
998
999   /**
1000   * Devuelve un vector con los reportes
1001   * @return
1002   * @throws InfoException
1003   */

1004  private Vector getComboModelVector() throws InfoException {
1005    Vector result = new Vector();
1006    Map definitionsMap;
1007    DefinitionInfo definitionInfo;
1008    Map.Entry entry;
1009    definitionsMap = getReportManager().getReportDefinitions();
1010    if (definitionsMap != null){
1011      Iterator iterator = definitionsMap.entrySet().iterator();
1012      while (iterator.hasNext()) {
1013        entry = (Map.Entry) iterator.next();
1014        definitionInfo = (DefinitionInfo)entry.getValue();
1015        result.add(definitionInfo);
1016      }
1017    }
1018    return result;
1019  }
1020
1021  /**
1022   * Instancia un reportmanager service y lo devuelve
1023   * @return
1024   */

1025  public IReportManager getReportManager() {
1026    if (reportManager == null) {
1027      try {
1028        String JavaDoc distributedHost = (String JavaDoc)getParams().get("DistributedHost");
1029        reportManager = ReportManagerService.getReportManagerService("",null, distributedHost);
1030      }
1031      catch (Exception JavaDoc e) {
1032        ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("223"), e);
1033        System.exit(3);
1034      }
1035    }
1036    return reportManager;
1037  }
1038
1039
1040  /**
1041   * Devuelve un reportGeneratorConfigurator
1042   * @return
1043   * @throws InfoException
1044   */

1045  public ReportGeneratorConfiguration getReportGeneratorConfiguration() throws InfoException {
1046    if (reportGeneratorConfiguration == null) {
1047      reportGeneratorConfiguration = new ReportGeneratorConfiguration(ReportGeneratorConfiguration.getConfiguration(propertiesPath));
1048    }
1049    return reportGeneratorConfiguration;
1050  }
1051
1052  public JPanel getMainPanel() {
1053    return mainPanel;
1054  }
1055
1056  private Map getParams(){
1057    if (params==null){
1058      params = new HashMap();
1059    }
1060    return params;
1061  }
1062
1063  public JToggleButton getSizesButton() {
1064    return btSizes;
1065  }
1066
1067  public void setBtSizesState(boolean state) {
1068    btSizesState = state;
1069  }
1070
1071  public ReportViewerToolBar getToolBar() {
1072    return reportViewerToolBar;
1073  }
1074
1075  public Frame owner() {
1076    return this;
1077  }
1078
1079  public JPanel getToolBarPanel() {
1080    if (toolBarPanel == null){
1081      createToolbarPanel();
1082    }
1083    return toolBarPanel;
1084  }
1085
1086  public JPanel getActionsBarPanel() {
1087    if (actionsToolBarPanel== null){
1088      createActionsToolbarPanel();
1089    }
1090    return actionsToolBarPanel;
1091  }
1092
1093  public void applyView(String JavaDoc reportViewId){
1094    this.reportViewID = reportViewId;
1095    try {
1096      pivotTableFrame.getPivotTable().applyView(reportViewID);
1097    }catch (Exception JavaDoc ex) {
1098      ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("293"), ex);
1099    }finally{
1100      setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
1101    }
1102  }
1103
1104  private void createReportFrame() {
1105  }
1106
1107  private void createReportLayout() throws InfoException {
1108    if (!reportDefinitionID.equalsIgnoreCase("")){
1109      ReportLayoutGenerator reportLayoutGenerator = new ReportLayoutGenerator(getReportManager().getReportDefinitionFromID(reportDefinitionID),getReportGeneratorConfiguration(),getReportManager(),this);
1110      reportLayoutGenerator.generateReportLayout();
1111    }else {
1112      throw new InfoException(LanguageTraslator.traslate("557"));
1113    }
1114  }
1115
1116
1117}
1118
1119
Popular Tags