001: package com.calipso.reportgenerator.userinterface;
002:
003: import com.calipso.reportgenerator.common.*;
004: import com.calipso.reportgenerator.userinterface.PivotTable;
005:
006: import javax.swing.*;
007: import java.awt.*;
008: import java.awt.event.ActionListener;
009: import java.awt.event.ActionEvent;
010: import java.util.Vector;
011: import java.util.List;
012: import java.util.Iterator;
013:
014: /**
015: * Interfaz grafica para realizar las busquedas de
016: * valores para las dimensiones
017: */
018:
019: public class DimensionValuesSearcherUI extends JDialog implements
020: ActionListener {
021:
022: private DimensionValuesSearcher searcher;
023: private ReportResult reportResult;
024: private JComboBox cboDimension;
025: private JTextField tfValue;
026: private JRadioButton btRow;
027: private JRadioButton btColumn;
028: private JButton btAccept;
029: private JButton btCancel;
030: private int searchLastIndex;
031:
032: /**
033: * Inicializa una instancia de <code>DimensionValuesSearcherUI</code>
034: * @param owner
035: * @param modal
036: * @param reportResult
037: * @param table
038: * @throws HeadlessException
039: */
040: public DimensionValuesSearcherUI(Frame owner, boolean modal,
041: ReportResult reportResult, PivotTable table,
042: ReportGeneratorConfiguration conf) throws HeadlessException {
043: super (owner, modal);
044: Image icon = conf.getImage("icon");
045: if (icon != null) {
046: owner.setIconImage(icon);
047: }
048: this .reportResult = reportResult;
049: searcher = new DimensionValuesSearcher(table);
050: searchLastIndex = 0;
051: setTitle(LanguageTraslator.traslate("332"));
052: java.awt.Dimension screenSize = java.awt.Toolkit
053: .getDefaultToolkit().getScreenSize();
054: setLocation((screenSize.width - 250) / 2,
055: (screenSize.height - 200) / 2);
056: initialize(reportResult.getReportSpec().getDimensions());
057: }
058:
059: /**
060: * Inicializa la interfaz
061: * @param dimensions
062: */
063: private void initialize(Object[] dimensions) {
064: getContentPane().setLayout(new BorderLayout());
065: JPanel centerPanel = new JPanel(new BorderLayout());
066: JPanel valuesSearchingPanel = new JPanel(new GridLayout(2, 2));
067: valuesSearchingPanel
068: .setBorder(BorderFactory
069: .createTitledBorder(
070: BorderFactory.createEtchedBorder(),
071: com.calipso.reportgenerator.common.LanguageTraslator
072: .traslate("282")));
073: JLabel lbDimension = new JLabel(
074: com.calipso.reportgenerator.common.LanguageTraslator
075: .traslate("280"));
076: cboDimension = new JComboBox(getDimensions(dimensions));
077: JLabel lbValue = new JLabel(
078: com.calipso.reportgenerator.common.LanguageTraslator
079: .traslate("281"));
080: tfValue = new JTextField();
081: valuesSearchingPanel.add(lbDimension);
082: valuesSearchingPanel.add(cboDimension);
083: valuesSearchingPanel.add(lbValue);
084: valuesSearchingPanel.add(tfValue);
085: JPanel typeSearchingPanel = new JPanel(new GridLayout(1, 2));
086: typeSearchingPanel.setBorder(BorderFactory.createTitledBorder(
087: BorderFactory.createEtchedBorder(),
088: com.calipso.reportgenerator.common.LanguageTraslator
089: .traslate("191")));
090: ButtonGroup btGroup = new ButtonGroup();
091: btRow = new JRadioButton(
092: com.calipso.reportgenerator.common.LanguageTraslator
093: .traslate("110"));
094: btRow.addActionListener(this );
095: btColumn = new JRadioButton(
096: com.calipso.reportgenerator.common.LanguageTraslator
097: .traslate("111"));
098: btColumn.addActionListener(this );
099: btRow.setSelected(true);
100: btGroup.add(btRow);
101: btGroup.add(btColumn);
102: typeSearchingPanel.add(btRow);
103: typeSearchingPanel.add(btColumn);
104: centerPanel.add(valuesSearchingPanel, BorderLayout.CENTER);
105: centerPanel.add(typeSearchingPanel, BorderLayout.SOUTH);
106: JPanel southPanel = new JPanel(new BorderLayout());
107: JPanel decidePanel = new JPanel();
108: JPanel decideEastPanel = new JPanel(new FlowLayout());
109: btAccept = new JButton(
110: com.calipso.reportgenerator.common.LanguageTraslator
111: .traslate("284"));
112: btAccept.addActionListener(this );
113: btCancel = new JButton(
114: com.calipso.reportgenerator.common.LanguageTraslator
115: .traslate("132"));
116: btCancel.addActionListener(this );
117: decideEastPanel.add(btAccept);
118: decideEastPanel.add(btCancel);
119: decidePanel.add(decideEastPanel, BorderLayout.WEST);
120: southPanel.add(decidePanel, BorderLayout.CENTER);
121: getContentPane().add(centerPanel, BorderLayout.CENTER);
122: getContentPane().add(southPanel, BorderLayout.SOUTH);
123: pack();
124: }
125:
126: /**
127: * Devuelve un Vector con los nombres de
128: * todas las dimensiones
129: * @param dimensions
130: * @return
131: */
132: private Vector getDimensions(Object[] dimensions) {
133: Vector elements = new Vector();
134: for (int i = 0; i < dimensions.length; i++) {
135: ReportDimensionSpec dimensionSpec = (ReportDimensionSpec) dimensions[i];
136: elements.add(dimensionSpec.getCaption());
137: }
138: return elements;
139: }
140:
141: /**
142: * Retorna el tipo de busqueda, ya sea por filas
143: * o por columnas.
144: * @return
145: */
146: private boolean getSearchType() {
147: if (btRow.isSelected()) {
148: return true;
149: }
150: return false;
151: }
152:
153: /**
154: * Retorna el indice de la dimension especificada
155: * de la coleccion que contiene las especificaciones
156: * de las dimensiones.
157: * @param dimensions
158: * @param dimension
159: * @return
160: */
161: private int getDimensionIndex(List dimensions, String dimension) {
162: Iterator iterator = dimensions.iterator();
163: for (int i = 0; iterator.hasNext(); i++) {
164: QueryDimension queryDimension = (QueryDimension) iterator
165: .next();
166: if (reportResult.getReportSpec().getDimensionFromName(
167: queryDimension.getName()).getCaption().equals(
168: dimension)) {
169: return i;
170: }
171: }
172: return -1;
173: }
174:
175: /**
176: * Metodo implementado de ActionListener
177: * @param e
178: */
179: public void actionPerformed(ActionEvent e) {
180: if (e.getSource() == btAccept) {
181: findValue();
182: return;
183: }
184: if (e.getSource() == btCancel) {
185: dispose();
186: return;
187: }
188: }
189:
190: /**
191: * Encuentra el valor especificado por el usuario.
192: */
193: private void findValue() {
194: if (getSearchType()) {
195: int index = getDimensionIndex(reportResult.getReportQuery()
196: .getRowDimensions(), cboDimension.getSelectedItem()
197: .toString());
198: if (index != -1) {
199: searchLastIndex = searcher
200: .searchDimensionValues(searchLastIndex, tfValue
201: .getText(), index, true);
202: }
203: if (searchLastIndex == -1 || index == -1) {
204: searchLastIndex = 0;
205: JOptionPane
206: .showMessageDialog(
207: this ,
208: com.calipso.reportgenerator.common.LanguageTraslator
209: .traslate("285")
210: + tfValue.getText().trim());
211: }
212: } else {
213: int index = getDimensionIndex(reportResult.getReportQuery()
214: .getColumnDimensions(), cboDimension
215: .getSelectedItem().toString());
216: if (index != -1) {
217: searchLastIndex = searcher.searchDimensionValues(
218: searchLastIndex, tfValue.getText(), index,
219: false);
220: }
221: if (searchLastIndex == -1 || index == -1) {
222: searchLastIndex = 0;
223: JOptionPane
224: .showMessageDialog(
225: this ,
226: com.calipso.reportgenerator.common.LanguageTraslator
227: .traslate("285")
228: + tfValue.getText().trim());
229: }
230: }
231: }
232: }
|