KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.calipso.reportgenerator.userinterface;
2
3 import com.calipso.reportgenerator.common.*;
4 import com.calipso.reportgenerator.userinterface.PivotTable;
5
6 import javax.swing.*;
7 import java.awt.*;
8 import java.awt.event.ActionListener JavaDoc;
9 import java.awt.event.ActionEvent JavaDoc;
10 import java.util.Vector JavaDoc;
11 import java.util.List JavaDoc;
12 import java.util.Iterator JavaDoc;
13
14 /**
15  * Interfaz grafica para realizar las busquedas de
16  * valores para las dimensiones
17  */

18
19 public class DimensionValuesSearcherUI extends JDialog implements ActionListener JavaDoc {
20
21   private DimensionValuesSearcher searcher;
22   private ReportResult reportResult;
23   private JComboBox cboDimension;
24   private JTextField tfValue;
25   private JRadioButton btRow;
26   private JRadioButton btColumn;
27   private JButton btAccept;
28   private JButton btCancel;
29   private int searchLastIndex;
30
31   /**
32    * Inicializa una instancia de <code>DimensionValuesSearcherUI</code>
33    * @param owner
34    * @param modal
35    * @param reportResult
36    * @param table
37    * @throws HeadlessException
38    */

39   public DimensionValuesSearcherUI(Frame owner, boolean modal, ReportResult reportResult, PivotTable table, ReportGeneratorConfiguration conf) throws HeadlessException {
40     super(owner, modal);
41     Image icon = conf.getImage("icon");
42     if(icon != null) {
43       owner.setIconImage(icon);
44     }
45     this.reportResult = reportResult;
46     searcher = new DimensionValuesSearcher(table);
47     searchLastIndex = 0;
48     setTitle(LanguageTraslator.traslate("332"));
49     java.awt.Dimension JavaDoc screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
50     setLocation((screenSize.width - 250) / 2, (screenSize.height - 200) / 2);
51     initialize(reportResult.getReportSpec().getDimensions());
52   }
53
54   /**
55    * Inicializa la interfaz
56    * @param dimensions
57    */

58   private void initialize(Object JavaDoc [] dimensions) {
59     getContentPane().setLayout(new BorderLayout());
60     JPanel centerPanel = new JPanel(new BorderLayout());
61     JPanel valuesSearchingPanel = new JPanel(new GridLayout(2, 2));
62     valuesSearchingPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), com.calipso.reportgenerator.common.LanguageTraslator.traslate("282")));
63     JLabel lbDimension = new JLabel(com.calipso.reportgenerator.common.LanguageTraslator.traslate("280"));
64     cboDimension = new JComboBox(getDimensions(dimensions));
65     JLabel lbValue = new JLabel(com.calipso.reportgenerator.common.LanguageTraslator.traslate("281"));
66     tfValue = new JTextField();
67     valuesSearchingPanel.add(lbDimension);
68     valuesSearchingPanel.add(cboDimension);
69     valuesSearchingPanel.add(lbValue);
70     valuesSearchingPanel.add(tfValue);
71     JPanel typeSearchingPanel = new JPanel(new GridLayout(1, 2));
72     typeSearchingPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), com.calipso.reportgenerator.common.LanguageTraslator.traslate("191")));
73     ButtonGroup btGroup = new ButtonGroup();
74     btRow = new JRadioButton(com.calipso.reportgenerator.common.LanguageTraslator.traslate("110"));
75     btRow.addActionListener(this);
76     btColumn = new JRadioButton(com.calipso.reportgenerator.common.LanguageTraslator.traslate("111"));
77     btColumn.addActionListener(this);
78     btRow.setSelected(true);
79     btGroup.add(btRow);
80     btGroup.add(btColumn);
81     typeSearchingPanel.add(btRow);
82     typeSearchingPanel.add(btColumn);
83     centerPanel.add(valuesSearchingPanel, BorderLayout.CENTER);
84     centerPanel.add(typeSearchingPanel, BorderLayout.SOUTH);
85     JPanel southPanel = new JPanel(new BorderLayout());
86     JPanel decidePanel = new JPanel();
87     JPanel decideEastPanel = new JPanel(new FlowLayout());
88     btAccept = new JButton(com.calipso.reportgenerator.common.LanguageTraslator.traslate("284"));
89     btAccept.addActionListener(this);
90     btCancel = new JButton(com.calipso.reportgenerator.common.LanguageTraslator.traslate("132"));
91     btCancel.addActionListener(this);
92     decideEastPanel.add(btAccept);
93     decideEastPanel.add(btCancel);
94     decidePanel.add(decideEastPanel, BorderLayout.WEST);
95     southPanel.add(decidePanel, BorderLayout.CENTER);
96     getContentPane().add(centerPanel, BorderLayout.CENTER);
97     getContentPane().add(southPanel, BorderLayout.SOUTH);
98     pack();
99   }
100
101   /**
102    * Devuelve un Vector con los nombres de
103    * todas las dimensiones
104    * @param dimensions
105    * @return
106    */

107   private Vector JavaDoc getDimensions(Object JavaDoc [] dimensions) {
108     Vector JavaDoc elements = new Vector JavaDoc();
109     for(int i = 0 ; i < dimensions.length ; i++) {
110       ReportDimensionSpec dimensionSpec = (ReportDimensionSpec) dimensions[i];
111       elements.add(dimensionSpec.getCaption());
112     }
113     return elements;
114   }
115
116   /**
117    * Retorna el tipo de busqueda, ya sea por filas
118    * o por columnas.
119    * @return
120    */

121   private boolean getSearchType() {
122     if(btRow.isSelected()) {
123       return true;
124     }
125     return false;
126   }
127
128   /**
129    * Retorna el indice de la dimension especificada
130    * de la coleccion que contiene las especificaciones
131    * de las dimensiones.
132    * @param dimensions
133    * @param dimension
134    * @return
135    */

136   private int getDimensionIndex(List JavaDoc dimensions, String JavaDoc dimension) {
137     Iterator JavaDoc iterator = dimensions.iterator();
138     for(int i = 0 ; iterator.hasNext() ; i++) {
139       QueryDimension queryDimension = (QueryDimension) iterator.next();
140       if(reportResult.getReportSpec().getDimensionFromName(queryDimension.getName()).getCaption().equals(dimension)) {
141         return i;
142       }
143     }
144     return -1;
145   }
146
147   /**
148    * Metodo implementado de ActionListener
149    * @param e
150    */

151   public void actionPerformed(ActionEvent JavaDoc e) {
152     if(e.getSource() == btAccept) {
153       findValue();
154       return;
155     }
156     if(e.getSource() == btCancel) {
157       dispose();
158       return;
159     }
160   }
161
162   /**
163    * Encuentra el valor especificado por el usuario.
164    */

165   private void findValue() {
166     if(getSearchType()) {
167         int index = getDimensionIndex(reportResult.getReportQuery().getRowDimensions(), cboDimension.getSelectedItem().toString());
168         if(index != -1){
169           searchLastIndex = searcher.searchDimensionValues(searchLastIndex, tfValue.getText(), index, true);
170         }
171         if(searchLastIndex == -1 || index == -1) {
172           searchLastIndex = 0;
173           JOptionPane.showMessageDialog(this, com.calipso.reportgenerator.common.LanguageTraslator.traslate("285") + tfValue.getText().trim());
174         }
175       } else {
176         int index = getDimensionIndex(reportResult.getReportQuery().getColumnDimensions(), cboDimension.getSelectedItem().toString());
177         if(index != -1){
178           searchLastIndex = searcher.searchDimensionValues(searchLastIndex, tfValue.getText(), index, false);
179         }
180         if(searchLastIndex == -1 || index == -1) {
181           searchLastIndex = 0;
182           JOptionPane.showMessageDialog(this, com.calipso.reportgenerator.common.LanguageTraslator.traslate("285") + tfValue.getText().trim());
183         }
184       }
185   }
186 }
187
Popular Tags