1 32 33 package it.businesslogic.ireport.crosstab.gui; 34 35 import it.businesslogic.ireport.SubDataset; 36 import it.businesslogic.ireport.util.Misc; 37 import java.awt.event.ActionEvent ; 38 import java.util.Vector ; 39 import javax.swing.border.TitledBorder ; 40 import it.businesslogic.ireport.util.I18n; 41 42 46 public class GroupByFieldPanel extends javax.swing.JPanel { 47 48 private Vector objects = new Vector (); 49 50 51 public GroupByFieldPanel() { 52 initComponents(); 53 applyI18n(); 54 } 55 56 public void addVoidItem() 57 { 58 if (jComboBoxColumnGroup1.getItemCount() == 0 || 59 jComboBoxColumnGroup1.getSelectedItem() instanceof WizardFieldObject) 60 { 61 jComboBoxColumnGroup1.insertItemAt("",0); 62 } 63 jComboBoxColumnGroup1.setSelectedIndex(0); 64 } 65 66 public void setTitle(String title) 67 { 68 ((TitledBorder )this.getBorder()).setTitle(title); 69 } 70 71 public void addObject(Object obj) 72 { 73 if (obj == null) return; 74 75 WizardFieldObject wo = new WizardFieldObject(obj); 76 jComboBoxColumnGroup1.addItem(wo); 77 78 80 } 81 82 85 public String getFieldName() 86 { 87 if (jComboBoxColumnGroup1.getSelectedItem() != null && jComboBoxColumnGroup1.getSelectedItem() instanceof WizardFieldObject) 88 { 89 return ((WizardFieldObject)jComboBoxColumnGroup1.getSelectedItem()).getName(); 90 } 91 92 return null; 93 } 94 95 public String getExpression() 96 { 97 if (jComboBoxColumnGroup1.getSelectedItem() != null && jComboBoxColumnGroup1.getSelectedItem() instanceof WizardFieldObject) 98 { 99 return ((WizardFieldObject)jComboBoxColumnGroup1.getSelectedItem()).getExpression(jComboBoxColumnGroupBy1.getSelectedItem()+""); 100 } 101 102 return ""; 103 } 104 105 public String getExpressionClass() 106 { 107 if (jComboBoxColumnGroup1.getSelectedItem() != null && jComboBoxColumnGroup1.getSelectedItem() instanceof WizardFieldObject) 108 { 109 return ((WizardFieldObject)jComboBoxColumnGroup1.getSelectedItem()).getExpressionClass(jComboBoxColumnGroupBy1.getSelectedItem()+""); 110 } 111 112 return "java.lang.String"; 113 } 114 115 120 private void initComponents() { 122 java.awt.GridBagConstraints gridBagConstraints; 123 124 jLabelColumnGroup1 = new javax.swing.JLabel (); 125 jComboBoxColumnGroup1 = new javax.swing.JComboBox (); 126 jComboBoxColumnGroupBy1 = new javax.swing.JComboBox (); 127 jLabelColumnGroupBy1 = new javax.swing.JLabel (); 128 129 setLayout(new java.awt.GridBagLayout ()); 130 131 setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font ("Dialog", 0, 11))); 132 jLabelColumnGroup1.setText("Group"); 133 gridBagConstraints = new java.awt.GridBagConstraints (); 134 gridBagConstraints.gridx = 0; 135 gridBagConstraints.gridy = 0; 136 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 137 gridBagConstraints.insets = new java.awt.Insets (0, 4, 0, 0); 138 add(jLabelColumnGroup1, gridBagConstraints); 139 140 jComboBoxColumnGroup1.setPreferredSize(new java.awt.Dimension (55, 20)); 141 jComboBoxColumnGroup1.addActionListener(new java.awt.event.ActionListener () { 142 public void actionPerformed(java.awt.event.ActionEvent evt) { 143 jComboBoxColumnGroup1ActionPerformed(evt); 144 } 145 }); 146 147 gridBagConstraints = new java.awt.GridBagConstraints (); 148 gridBagConstraints.gridx = 1; 149 gridBagConstraints.gridy = 0; 150 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 151 gridBagConstraints.weightx = 1.0; 152 gridBagConstraints.insets = new java.awt.Insets (0, 4, 0, 4); 153 add(jComboBoxColumnGroup1, gridBagConstraints); 154 155 jComboBoxColumnGroupBy1.setEnabled(false); 156 jComboBoxColumnGroupBy1.setPreferredSize(new java.awt.Dimension (55, 20)); 157 gridBagConstraints = new java.awt.GridBagConstraints (); 158 gridBagConstraints.gridx = 1; 159 gridBagConstraints.gridy = 1; 160 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 161 gridBagConstraints.weightx = 1.0; 162 gridBagConstraints.insets = new java.awt.Insets (4, 4, 4, 4); 163 add(jComboBoxColumnGroupBy1, gridBagConstraints); 164 165 jLabelColumnGroupBy1.setText("Group by"); 166 jLabelColumnGroupBy1.setEnabled(false); 167 gridBagConstraints = new java.awt.GridBagConstraints (); 168 gridBagConstraints.gridx = 0; 169 gridBagConstraints.gridy = 1; 170 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 171 gridBagConstraints.insets = new java.awt.Insets (4, 4, 4, 0); 172 add(jLabelColumnGroupBy1, gridBagConstraints); 173 174 } 176 public void populateBySubdataset(SubDataset sd) 177 { 178 populateBySubdataset(sd, false); 179 } 180 181 public void populateBySubdataset(SubDataset sd, boolean addVoidEntry) 182 { 183 jComboBoxColumnGroup1.removeAllItems(); 184 if (addVoidEntry) addVoidItem(); 185 for (int i=0; i<sd.getFields().size(); ++i) 186 { 187 addObject(sd.getFields().get(i)); 188 } 189 for (int i=0; i<sd.getVariables().size(); ++i) 190 { 191 addObject(sd.getVariables().get(i)); 192 } 193 for (int i=0; i<sd.getParameters().size(); ++i) 194 { 195 addObject(sd.getParameters().get(i)); 196 } 197 198 if (jComboBoxColumnGroup1.getItemCount() > 0) 199 { 200 jComboBoxColumnGroup1.setSelectedIndex(0); 201 } 202 } 203 204 private void jComboBoxColumnGroup1ActionPerformed(java.awt.event.ActionEvent evt) { 206 207 jComboBoxColumnGroupBy1.removeAllItems(); 208 if (jComboBoxColumnGroup1.getSelectedItem() != null && jComboBoxColumnGroup1.getSelectedItem() instanceof WizardFieldObject) 209 { 210 Vector itemsGroupByValues = ((WizardFieldObject)jComboBoxColumnGroup1.getSelectedItem()).getGroupByValues(); 211 Misc.updateComboBox( jComboBoxColumnGroupBy1,itemsGroupByValues,false); 212 } 213 214 if (jComboBoxColumnGroupBy1.getItemCount() <= 1) 215 { 216 jComboBoxColumnGroupBy1.setEnabled(false); 217 jLabelColumnGroupBy1.setEnabled(false); 218 } 219 else 220 { 221 jComboBoxColumnGroupBy1.setEnabled(true); 222 jLabelColumnGroupBy1.setEnabled(true); 223 } 224 225 this.fireActionListenerActionPerformed(new ActionEvent (this,0,"")); 226 227 } 229 230 private javax.swing.JComboBox jComboBoxColumnGroup1; 232 private javax.swing.JComboBox jComboBoxColumnGroupBy1; 233 private javax.swing.JLabel jLabelColumnGroup1; 234 private javax.swing.JLabel jLabelColumnGroupBy1; 235 237 240 private javax.swing.event.EventListenerList listenerList = null; 241 242 246 public synchronized void addActionListener(java.awt.event.ActionListener listener) { 247 248 if (listenerList == null ) { 249 listenerList = new javax.swing.event.EventListenerList (); 250 } 251 listenerList.add (java.awt.event.ActionListener .class, listener); 252 } 253 254 258 public synchronized void removeActionListener(java.awt.event.ActionListener listener) { 259 260 listenerList.remove (java.awt.event.ActionListener .class, listener); 261 } 262 263 268 private void fireActionListenerActionPerformed(java.awt.event.ActionEvent event) { 269 270 if (listenerList == null) return; 271 Object [] listeners = listenerList.getListenerList (); 272 for (int i = listeners.length - 2; i >= 0; i -= 2) { 273 if (listeners[i]==java.awt.event.ActionListener .class) { 274 ((java.awt.event.ActionListener )listeners[i+1]).actionPerformed (event); 275 } 276 } 277 } 278 279 public void applyI18n(){ 280 jLabelColumnGroup1.setText(I18n.getString("groupByFieldPanel.labelColumnGroup1","Group")); 282 jLabelColumnGroupBy1.setText(I18n.getString("groupByFieldPanel.labelColumnGroupBy1","Group by")); 283 } 285 } 286 | Popular Tags |