1 32 33 package it.businesslogic.ireport.gui.queryexecuters; 34 35 import it.businesslogic.ireport.*; 36 import it.businesslogic.ireport.SubDataset; 37 import it.businesslogic.ireport.gui.MainFrame; 38 39 import javax.swing.table.*; 40 import javax.swing.*; 41 import javax.swing.event.*; 42 import it.businesslogic.ireport.*; 43 import it.businesslogic.ireport.util.*; 44 45 import java.util.*; 46 50 public class QueryExecutersDialog extends javax.swing.JDialog { 51 52 53 public QueryExecutersDialog(java.awt.Dialog parent, boolean modal) { 54 super(parent, modal); 55 initAll(); 56 } 57 public QueryExecutersDialog(java.awt.Frame parent, boolean modal) { 58 super(parent, modal); 59 initAll(); 60 } 61 62 public void initAll() 63 { 64 initComponents(); 65 this.setSize(420, 250); 66 DefaultTableColumnModel dtcm = (DefaultTableColumnModel)jTableProperties.getColumnModel(); 67 68 dtcm.getColumn(0).setWidth(150); 69 dtcm.getColumn(0).setPreferredWidth(150); 70 71 DefaultListSelectionModel dlsm = (DefaultListSelectionModel)this.jTableProperties.getSelectionModel(); 72 dlsm.addListSelectionListener(new javax.swing.event.ListSelectionListener () { 73 public void valueChanged(ListSelectionEvent e) { 74 jTablePropertiesListSelectionValueChanged(e); 75 } 76 }); 77 78 applyI18n(); 79 it.businesslogic.ireport.util.Misc.centerFrame(this); 81 82 83 javax.swing.KeyStroke escape = javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0, false); 84 javax.swing.Action escapeAction = new javax.swing.AbstractAction () { 85 public void actionPerformed(java.awt.event.ActionEvent e) { 86 jButtonSaveActionPerformed(e); 87 } 88 }; 89 90 getRootPane().getInputMap(javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE"); 91 getRootPane().getActionMap().put("ESCAPE", escapeAction); 92 93 94 this.getRootPane().setDefaultButton(this.jButtonSave); 96 97 this.updateQueryExecuters(); 98 99 } 100 101 102 public void jTablePropertiesListSelectionValueChanged(javax.swing.event.ListSelectionEvent e) 103 { 104 if (this.jTableProperties.getSelectedRowCount() > 0) { 105 this.jButtonModifyProperty.setEnabled(true); 106 this.jButtonDeleteProperty.setEnabled(true); 107 this.jButtonMoveUp.setEnabled(true); 108 this.jButtonMoveDown.setEnabled(true); 109 } 110 else { 111 this.jButtonModifyProperty.setEnabled(false); 112 this.jButtonDeleteProperty.setEnabled(false); 113 this.jButtonMoveUp.setEnabled(false); 114 this.jButtonMoveDown.setEnabled(false); 115 } 116 } 117 118 123 private void initComponents() { 125 java.awt.GridBagConstraints gridBagConstraints; 126 127 jPanelFields = new javax.swing.JPanel (); 128 jScrollPane3 = new javax.swing.JScrollPane (); 129 jTableProperties = new it.businesslogic.ireport.gui.JDragTable(); 130 jPanelButtons2 = new javax.swing.JPanel (); 131 jButtonNewProperty = new javax.swing.JButton (); 132 jButtonModifyProperty = new javax.swing.JButton (); 133 jButtonDeleteProperty = new javax.swing.JButton (); 134 jButtonSave = new javax.swing.JButton (); 135 jButtonMoveUp = new javax.swing.JButton (); 136 jButtonMoveDown = new javax.swing.JButton (); 137 jPanel1 = new javax.swing.JPanel (); 138 139 setTitle("Values"); 140 addWindowListener(new java.awt.event.WindowAdapter () { 141 public void windowClosing(java.awt.event.WindowEvent evt) { 142 closeDialog(evt); 143 } 144 }); 145 146 jPanelFields.setLayout(new java.awt.GridBagLayout ()); 147 148 jScrollPane3.setBackground(new java.awt.Color (255, 255, 255)); 149 jScrollPane3.addMouseListener(new java.awt.event.MouseAdapter () { 150 public void mouseClicked(java.awt.event.MouseEvent evt) { 151 jScrollPane3MouseClicked(evt); 152 } 153 }); 154 155 jTableProperties.setModel(new javax.swing.table.DefaultTableModel ( 156 new Object [][] { 157 158 }, 159 new String [] { 160 "Language", "Factory class", "Fields Provider" 161 } 162 ) { 163 Class [] types = new Class [] { 164 java.lang.Object .class, java.lang.String .class, java.lang.String .class 165 }; 166 boolean[] canEdit = new boolean [] { 167 false, false, false 168 }; 169 170 public Class getColumnClass(int columnIndex) { 171 return types [columnIndex]; 172 } 173 174 public boolean isCellEditable(int rowIndex, int columnIndex) { 175 return canEdit [columnIndex]; 176 } 177 }); 178 jTableProperties.addMouseListener(new java.awt.event.MouseAdapter () { 179 public void mouseClicked(java.awt.event.MouseEvent evt) { 180 jTablePropertiesMouseClicked(evt); 181 } 182 }); 183 184 jScrollPane3.setViewportView(jTableProperties); 185 186 gridBagConstraints = new java.awt.GridBagConstraints (); 187 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 188 gridBagConstraints.weightx = 1.0; 189 gridBagConstraints.weighty = 1.0; 190 gridBagConstraints.insets = new java.awt.Insets (4, 4, 4, 0); 191 jPanelFields.add(jScrollPane3, gridBagConstraints); 192 193 jPanelButtons2.setLayout(new java.awt.GridBagLayout ()); 194 195 jPanelButtons2.setMinimumSize(new java.awt.Dimension (100, 10)); 196 jPanelButtons2.setPreferredSize(new java.awt.Dimension (130, 100)); 197 jButtonNewProperty.setText("New"); 198 jButtonNewProperty.addActionListener(new java.awt.event.ActionListener () { 199 public void actionPerformed(java.awt.event.ActionEvent evt) { 200 jButtonNewPropertyActionPerformed(evt); 201 } 202 }); 203 204 gridBagConstraints = new java.awt.GridBagConstraints (); 205 gridBagConstraints.gridx = 0; 206 gridBagConstraints.gridy = 0; 207 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 208 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 209 gridBagConstraints.weightx = 1.0; 210 gridBagConstraints.insets = new java.awt.Insets (0, 4, 0, 4); 211 jPanelButtons2.add(jButtonNewProperty, gridBagConstraints); 212 213 jButtonModifyProperty.setText("Modify"); 214 jButtonModifyProperty.setEnabled(false); 215 jButtonModifyProperty.addActionListener(new java.awt.event.ActionListener () { 216 public void actionPerformed(java.awt.event.ActionEvent evt) { 217 jButtonModifyPropertyActionPerformed(evt); 218 } 219 }); 220 221 gridBagConstraints = new java.awt.GridBagConstraints (); 222 gridBagConstraints.gridx = 0; 223 gridBagConstraints.gridy = 1; 224 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 225 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 226 gridBagConstraints.weightx = 1.0; 227 gridBagConstraints.insets = new java.awt.Insets (3, 4, 0, 4); 228 jPanelButtons2.add(jButtonModifyProperty, gridBagConstraints); 229 230 jButtonDeleteProperty.setText("Delete"); 231 jButtonDeleteProperty.setEnabled(false); 232 jButtonDeleteProperty.addActionListener(new java.awt.event.ActionListener () { 233 public void actionPerformed(java.awt.event.ActionEvent evt) { 234 jButtonDeletePropertyActionPerformed(evt); 235 } 236 }); 237 238 gridBagConstraints = new java.awt.GridBagConstraints (); 239 gridBagConstraints.gridx = 0; 240 gridBagConstraints.gridy = 2; 241 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 242 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 243 gridBagConstraints.weightx = 1.0; 244 gridBagConstraints.insets = new java.awt.Insets (4, 4, 4, 4); 245 jPanelButtons2.add(jButtonDeleteProperty, gridBagConstraints); 246 247 jButtonSave.setMnemonic('c'); 248 jButtonSave.setText("Close"); 249 jButtonSave.addActionListener(new java.awt.event.ActionListener () { 250 public void actionPerformed(java.awt.event.ActionEvent evt) { 251 jButtonSaveActionPerformed(evt); 252 } 253 }); 254 255 gridBagConstraints = new java.awt.GridBagConstraints (); 256 gridBagConstraints.gridx = 0; 257 gridBagConstraints.gridy = 20; 258 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 259 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 260 gridBagConstraints.weightx = 1.0; 261 gridBagConstraints.insets = new java.awt.Insets (4, 4, 0, 4); 262 jPanelButtons2.add(jButtonSave, gridBagConstraints); 263 264 jButtonMoveUp.setText("Move up"); 265 jButtonMoveUp.setEnabled(false); 266 jButtonMoveUp.addActionListener(new java.awt.event.ActionListener () { 267 public void actionPerformed(java.awt.event.ActionEvent evt) { 268 jButtonDeletePropertyActionPerformed1(evt); 269 } 270 }); 271 272 gridBagConstraints = new java.awt.GridBagConstraints (); 273 gridBagConstraints.gridx = 0; 274 gridBagConstraints.gridy = 3; 275 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 276 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 277 gridBagConstraints.weightx = 1.0; 278 gridBagConstraints.insets = new java.awt.Insets (4, 4, 4, 4); 279 jPanelButtons2.add(jButtonMoveUp, gridBagConstraints); 280 281 jButtonMoveDown.setText("Move down"); 282 jButtonMoveDown.setEnabled(false); 283 jButtonMoveDown.addActionListener(new java.awt.event.ActionListener () { 284 public void actionPerformed(java.awt.event.ActionEvent evt) { 285 jButtonDeletePropertyActionPerformed2(evt); 286 } 287 }); 288 289 gridBagConstraints = new java.awt.GridBagConstraints (); 290 gridBagConstraints.gridx = 0; 291 gridBagConstraints.gridy = 4; 292 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 293 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 294 gridBagConstraints.weightx = 1.0; 295 gridBagConstraints.insets = new java.awt.Insets (4, 4, 4, 4); 296 jPanelButtons2.add(jButtonMoveDown, gridBagConstraints); 297 298 jPanel1.setLayout(new java.awt.BorderLayout ()); 299 300 gridBagConstraints = new java.awt.GridBagConstraints (); 301 gridBagConstraints.gridx = 0; 302 gridBagConstraints.gridy = 10; 303 gridBagConstraints.weighty = 1.0; 304 jPanelButtons2.add(jPanel1, gridBagConstraints); 305 306 gridBagConstraints = new java.awt.GridBagConstraints (); 307 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 308 gridBagConstraints.weightx = 0.1; 309 gridBagConstraints.weighty = 1.0; 310 gridBagConstraints.insets = new java.awt.Insets (4, 0, 4, 4); 311 jPanelFields.add(jPanelButtons2, gridBagConstraints); 312 313 getContentPane().add(jPanelFields, java.awt.BorderLayout.CENTER); 314 315 pack(); 316 } 318 private void jButtonDeletePropertyActionPerformed2(java.awt.event.ActionEvent evt) { 320 321 if (jTableProperties.getSelectedRowCount() > 0) 322 { 323 DefaultTableModel dtm = (DefaultTableModel)jTableProperties.getModel(); 324 int[] indices = jTableProperties.getSelectedRows(); 325 for (int i=indices.length-1; i>=0; --i) 326 { 327 if (indices[i] >= jTableProperties.getRowCount() -1 ) continue; 328 Object val = jTableProperties.getValueAt( indices[i], 0); 329 dtm.removeRow( indices[i]); 330 dtm.insertRow( indices[i]+1, new Object []{val, ((QueryExecuterDef)val).getClassName(),((QueryExecuterDef)val).getFieldsProvider() }); 331 indices[i]++; 332 } 333 for (int i=0; i<indices.length; ++i) 334 { 335 jTableProperties.addRowSelectionInterval(indices[i], indices[i]); 336 } 337 338 saveAll(); 339 } 340 341 } 343 private void jButtonDeletePropertyActionPerformed1(java.awt.event.ActionEvent evt) { 345 346 if (jTableProperties.getSelectedRowCount() > 0) 347 { 348 DefaultTableModel dtm = (DefaultTableModel)jTableProperties.getModel(); 349 int[] indices = jTableProperties.getSelectedRows(); 350 for (int i=0; i<indices.length; ++i) 351 { 352 if (indices[i] == 0) continue; 353 Object val = jTableProperties.getValueAt( indices[i], 0); 354 dtm.removeRow( indices[i]); 355 dtm.insertRow( indices[i]-1, new Object []{val, ((QueryExecuterDef)val).getClassName(),((QueryExecuterDef)val).getFieldsProvider()}); 356 indices[i]--; 357 } 358 for (int i=0; i<indices.length; ++i) 359 { 360 jTableProperties.addRowSelectionInterval(indices[i], indices[i]); 361 } 362 363 saveAll(); 364 } 365 366 } 368 private void jButtonSaveActionPerformed(java.awt.event.ActionEvent evt) { setVisible(false); 370 } 372 private void jScrollPane3MouseClicked(java.awt.event.MouseEvent evt) { } 376 private void jTablePropertiesMouseClicked(java.awt.event.MouseEvent evt) { if (evt.getClickCount() == 2 && evt.getButton() == evt.BUTTON1 && jTableProperties.getSelectedRow() >=0 ) { 378 jButtonModifyPropertyActionPerformed(new java.awt.event.ActionEvent ( jButtonModifyProperty,0, "")); 379 } 380 } 382 private void jButtonNewPropertyActionPerformed(java.awt.event.ActionEvent evt) { java.awt.Frame parent = Misc.frameFromComponent(this); 384 QueryExecuterDialog jrpd = new QueryExecuterDialog( parent, true); 385 jrpd.setVisible(true); 386 if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) { 387 QueryExecuterDef qe = jrpd.getQueryExecuterDef(); 388 ((DefaultTableModel)jTableProperties.getModel()).addRow(new Object []{qe, qe.getClassName(),qe.getFieldsProvider()}); 389 saveAll(); 390 } 391 392 393 } 395 private void jButtonModifyPropertyActionPerformed(java.awt.event.ActionEvent evt) { QueryExecuterDef qe = (QueryExecuterDef)jTableProperties.getValueAt( jTableProperties.getSelectedRow(), 0); 397 398 java.awt.Frame parent = Misc.frameFromComponent(this); 399 QueryExecuterDialog jrpd = new QueryExecuterDialog( parent, true); 400 jrpd.setQueryExecuterDef( qe ); 401 jrpd.setVisible(true); 402 403 if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) { 404 jTableProperties.setValueAt( jrpd.getQueryExecuterDef(), jTableProperties.getSelectedRow(), 0); 405 jTableProperties.setValueAt( jrpd.getQueryExecuterDef().getClassName(), jTableProperties.getSelectedRow(), 1); 406 jTableProperties.setValueAt( jrpd.getQueryExecuterDef().getFieldsProvider(), jTableProperties.getSelectedRow(), 2); 407 saveAll(); 408 } 409 } 411 private void jButtonDeletePropertyActionPerformed(java.awt.event.ActionEvent evt) { int[] rows= jTableProperties.getSelectedRows(); 413 DefaultTableModel dtm = (DefaultTableModel)jTableProperties.getModel(); 414 for (int i=rows.length-1; i>=0; --i) { 415 dtm.removeRow(rows[i]); 416 } 417 saveAll(); 418 } 420 421 private void closeDialog(java.awt.event.WindowEvent evt) { setVisible(false); 423 } 425 426 public void updateQueryExecuters() { 427 428 DefaultTableModel dtm = (DefaultTableModel)jTableProperties.getModel(); 429 dtm.setRowCount(0); 430 431 Enumeration e = MainFrame.getMainInstance().getQueryExecuters().elements(); 432 433 while (e.hasMoreElements()) 434 { 435 QueryExecuterDef qe = (QueryExecuterDef)e.nextElement(); 436 Vector row = new Vector(); 437 row.addElement( qe ); 438 row.addElement( qe.getClassName()); 439 row.addElement( qe.getFieldsProvider()); 440 441 dtm.addRow(row); 442 } 443 } 444 public void applyI18n(){ 445 jButtonNewProperty.setText(it.businesslogic.ireport.util.I18n.getString("new","New")); 448 jButtonModifyProperty.setText(it.businesslogic.ireport.util.I18n.getString("modify","Modify")); 449 jButtonDeleteProperty.setText(it.businesslogic.ireport.util.I18n.getString("delete","Delete")); 450 jButtonMoveUp.setText(it.businesslogic.ireport.util.I18n.getString("moveUp","Move up")); 451 jButtonMoveDown.setText(it.businesslogic.ireport.util.I18n.getString("moveDown","Move down")); 452 jButtonSave.setText(it.businesslogic.ireport.util.I18n.getString("close","Close")); 453 454 jTableProperties.getColumnModel().getColumn(0).setHeaderValue( I18n.getString("queryExecutersDialog.tablecolumn.language","Language") ); 455 jTableProperties.getColumnModel().getColumn(1).setHeaderValue( I18n.getString("queryExecutersDialog.tablecolumn.factoryClass","Factory class") ); 456 jTableProperties.getColumnModel().getColumn(2).setHeaderValue( I18n.getString("queryExecutersDialog.tablecolumn.fieldsProvider","Fields Provider") ); 457 458 } 459 public void languageChanged(LanguageChangedEvent evt) { 460 461 this.applyI18n(); 462 } 463 464 private javax.swing.JButton jButtonDeleteProperty; 466 private javax.swing.JButton jButtonModifyProperty; 467 private javax.swing.JButton jButtonMoveDown; 468 private javax.swing.JButton jButtonMoveUp; 469 private javax.swing.JButton jButtonNewProperty; 470 private javax.swing.JButton jButtonSave; 471 private javax.swing.JPanel jPanel1; 472 private javax.swing.JPanel jPanelButtons2; 473 private javax.swing.JPanel jPanelFields; 474 private javax.swing.JScrollPane jScrollPane3; 475 private it.businesslogic.ireport.gui.JDragTable jTableProperties; 476 478 479 public void saveAll() 480 { 481 Vector v = MainFrame.getMainInstance().getQueryExecuters(); 482 v.clear(); 483 484 for (int i=0; i<jTableProperties.getRowCount(); ++i) 485 { 486 QueryExecuterDef qe = (QueryExecuterDef)jTableProperties.getValueAt(i,0); 487 v.add(qe); 488 } 489 490 MainFrame.getMainInstance().saveiReportConfiguration(); 491 } 492 } 493 | Popular Tags |