KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.calipso.reportgenerator.userinterface;
2
3 import com.calipso.reportgenerator.common.InfoException;
4 import com.calipso.reportgenerator.common.LanguageTraslator;
5 import com.calipso.reportgenerator.common.ReportQuery;
6 import com.calipso.reportgenerator.common.ShowExceptionMessageDialog;
7
8 import javax.swing.*;
9 import java.awt.event.KeyEvent JavaDoc;
10 import java.awt.event.KeyListener JavaDoc;
11 import java.awt.event.MouseEvent JavaDoc;
12 import java.awt.event.MouseListener JavaDoc;
13 import java.util.*;
14
15 /**
16  * CheckDataListener se encarga de publicar los eventos de teclado y mouse que soporta la JList donde se ubican los
17  * valores de las dimensiones
18  */

19 public class CheckDataListener implements MouseListener JavaDoc, KeyListener JavaDoc {
20   protected DimensionColumnValue m_parent;
21   private PivotTable pivotTable;
22   protected JList m_list;
23   private ColumnProperties properties;
24   private boolean uppdateQuery;
25   private Vector dataValues;
26   private Object JavaDoc[][] indexUnchecked;
27
28   /**
29    * Crea un objeto CheckDataListener e inicializa
30    * @param parent
31    */

32   public CheckDataListener(DimensionColumnValue parent, PivotTable pivotTable) {
33     m_parent = parent;
34     this.pivotTable = pivotTable;
35     m_list = parent.getList();
36     dataValues = (Vector) m_parent.getJcheckVector().clone();
37     indexUnchecked = new Object JavaDoc[dataValues.size()][2];
38     for (int index = 0; index < m_parent.getJcheckVector().size(); index++) {
39       indexUnchecked[index][0] = new Integer JavaDoc(index);
40       Object JavaDoc[] o = (Object JavaDoc[]) m_parent.getJcheckVector().get(index);
41       indexUnchecked[index][1] = new Boolean JavaDoc(o[1].toString());
42     }
43   }
44
45   /**
46    * En caso de hacer un click con el mouse en el JCheckBox realizo doCheck
47    * @param e
48    */

49   public void mouseClicked(MouseEvent JavaDoc e) {
50     if (e.getX() < 20) {
51       doCheck(e.isControlDown());
52     }
53   }
54
55   /**
56    * Implementacion de la interface MouseListener
57    * @param e
58    */

59   public void mousePressed(MouseEvent JavaDoc e) {
60   }
61
62   /**
63    * Implementacion de la interface MouseListener
64    * @param e
65    */

66   public void mouseReleased(MouseEvent JavaDoc e) {
67   }
68
69   /**
70    * Implementacion de la interface MouseListener
71    * @param e
72    */

73   public void mouseEntered(MouseEvent JavaDoc e) {
74   }
75
76   /**
77    * Implementacion de la interface MouseListener
78    * @param e
79    */

80   public void mouseExited(MouseEvent JavaDoc e) {
81   }
82
83   /**
84    * Implementacion de la interface KeyListener
85    * @param e
86    */

87   public void keyPressed(KeyEvent JavaDoc e) {
88     if (e.getKeyChar() == ' ') {
89       doCheck(false);
90     }
91   }
92
93   /**
94    * Implementacion de la interface KeyListener
95    * @param e
96    */

97   public void keyTyped(KeyEvent JavaDoc e) {
98   }
99
100   /**
101    * Implementacion de la interface KeyListener
102    * @param e
103    */

104   public void keyReleased(KeyEvent JavaDoc e) {
105   }
106
107   /**
108    * Marca op desmarca el JCheckBox de la Jlist seleccionado
109    */

110   protected void doCheck(boolean isControlDown) {
111     ArrayList list = (ArrayList) pivotTable.getTableProperties().getColumnProperties().clone();
112     int index = m_list.getSelectedIndex();
113     if (index < 0)
114       return;
115     int position = pivotTable.getColumnPropertiesIndex(m_parent.getPanelName());
116     properties = (ColumnProperties) list.get(position);
117     Set set = properties.getExcludeValue();
118     ListDataModel data = (ListDataModel) m_list.getModel().getElementAt(index);
119     data.invertSelected();
120     Object JavaDoc[] value = (Object JavaDoc[]) dataValues.get(index);
121     if(! isControlDown) {
122       if (!data.isSelected()) {
123         if (canUncheckedValue()) {
124           uppdateQuery = true;
125           m_list.repaint();
126           m_list.revalidate();
127         }
128         else {
129           uppdateQuery = false;
130           ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("153"), new Exception JavaDoc());
131         }
132       } else {
133       if (!set.isEmpty() && set.contains(value[0])) {
134         //set.remove(value[0]); //BUG, MODIFICA LA INSTANCIA EN LA
135
properties.setExcludeValue(set); //PROXIMA EJECUCION
136
pivotTable.getTableProperties().newColumnPropertiesArrayList(list);
137         uppdateQuery = true;
138       }
139     }
140    } else if(data.isSelected()){
141       int modelSize = m_list.getModel().getSize();
142       for(int i = 0 ; i < modelSize ; i++) {
143         ListDataModel dataModel = (ListDataModel) m_list.getModel().getElementAt(i);
144         dataModel.invertSelected();
145         dataModel.setSelected(true);
146       }
147      uppdateQuery = true;
148       m_list.repaint();
149       m_list.revalidate();
150       m_parent.validate();
151       m_parent.repaint();
152     } else {
153       int modelSize = m_list.getModel().getSize();
154       for(int i = 0 ; i < modelSize ; i++) {
155         ListDataModel dataModel = (ListDataModel) m_list.getModel().getElementAt(i);
156         dataModel.invertSelected();
157         dataModel.setSelected(false);
158       }
159      uppdateQuery = true;
160       m_list.repaint();
161       m_list.revalidate();
162       m_parent.validate();
163       m_parent.repaint();
164    }
165   }
166
167   private boolean canUncheckedValue() {
168     if (getCountCheckedValues() >= 1) {
169       return true;
170     }
171     else {
172       return false;
173     }
174   }
175
176   public int getCountCheckedValues() {
177     int count = 0;
178     for (int index = 0; index < m_list.getModel().getSize(); index++) {
179       ListDataModel data = (ListDataModel) m_list.getModel().getElementAt(index);
180       if (data.isSelected()) {
181         count++;
182       }
183     }
184     return count;
185   }
186
187
188   /**
189    * Modifica el columnProperties correspondiente y ejecuta la nueva query
190    * @throws InfoException
191    */

192   public void run(Vector jcheckVector) throws InfoException {
193     if (uppdateQuery) {
194       Set set = getUncheckedValues();
195       properties.setExcludeValue(set);
196       properties.setExcludeValue(set);
197       ReportQuery reportQuery = pivotTable.getPivotTableFrame().getReportManager().getDefaultReportQuery(pivotTable.getPivotTableFrame().getReportHandle());
198       pivotTable.getPivotTableFrame().buildNewQueryExcludeValue(pivotTable.getTableProperties(), reportQuery, true, false);
199       pivotTable.setTableProperties(pivotTable.getTableProperties());
200       pivotTable.fillContents(pivotTable.getReportResult());
201     }
202     else {
203       for (int index = 0; index < indexUnchecked.length; index++) {
204         boolean estado = ((Boolean JavaDoc) indexUnchecked[index][1]).booleanValue();
205         ListDataModel model = (ListDataModel) m_list.getModel().getElementAt(index);
206         model.setSelected(estado);
207       }
208     }
209     m_list.revalidate();
210     m_list.repaint();
211   }
212
213   private Set getUncheckedValues() {
214     Set set = new TreeSet();
215     for (int index = 0; index < m_list.getModel().getSize(); index++) {
216       ListDataModel model = (ListDataModel) m_list.getModel().getElementAt(index);
217       if (!model.isSelected()) {
218         set.add(model.getName());
219       }
220     }
221     return set;
222   }
223
224 }
225
Popular Tags