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 ; 10 import java.awt.event.KeyListener ; 11 import java.awt.event.MouseEvent ; 12 import java.awt.event.MouseListener ; 13 import java.util.*; 14 15 19 public class CheckDataListener implements MouseListener , KeyListener { 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 [][] indexUnchecked; 27 28 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 [dataValues.size()][2]; 38 for (int index = 0; index < m_parent.getJcheckVector().size(); index++) { 39 indexUnchecked[index][0] = new Integer (index); 40 Object [] o = (Object []) m_parent.getJcheckVector().get(index); 41 indexUnchecked[index][1] = new Boolean (o[1].toString()); 42 } 43 } 44 45 49 public void mouseClicked(MouseEvent e) { 50 if (e.getX() < 20) { 51 doCheck(e.isControlDown()); 52 } 53 } 54 55 59 public void mousePressed(MouseEvent e) { 60 } 61 62 66 public void mouseReleased(MouseEvent e) { 67 } 68 69 73 public void mouseEntered(MouseEvent e) { 74 } 75 76 80 public void mouseExited(MouseEvent e) { 81 } 82 83 87 public void keyPressed(KeyEvent e) { 88 if (e.getKeyChar() == ' ') { 89 doCheck(false); 90 } 91 } 92 93 97 public void keyTyped(KeyEvent e) { 98 } 99 100 104 public void keyReleased(KeyEvent e) { 105 } 106 107 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 [] value = (Object []) 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 ()); 131 } 132 } else { 133 if (!set.isEmpty() && set.contains(value[0])) { 134 properties.setExcludeValue(set); 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 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 ) 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 |