Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extTableSummarize / src / org / gvsig / app / documents / table / summarize / gui / SummarizeForm.java @ 27691

History | View | Annotate | Download (27.4 KB)

1
/* gvSIG. Sistema de Informacion Geografica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2009 IVER T.I.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  IVER T.I.
22
 *   C/ Lerida, 20
23
 *   46009 Valencia
24
 *   SPAIN
25
 *   http://www.iver.es
26
 *   dac@iver.es
27
 *   +34 963163400
28
 *   
29
 *  or
30
 *  
31
 *  Generalitat Valenciana
32
 *   Conselleria d'Infraestructures i Transport
33
 *   Av. Blasco Iba?ez, 50
34
 *   46010 VALENCIA
35
 *   SPAIN
36
 */
37
package org.gvsig.app.documents.table.summarize.gui;
38

    
39
import java.awt.Component;
40
import java.awt.event.ItemEvent;
41
import java.io.File;
42
import java.io.IOException;
43
import java.sql.Types;
44
import java.util.ArrayList;
45

    
46
import javax.swing.JFileChooser;
47
import javax.swing.JOptionPane;
48
import javax.swing.table.DefaultTableModel;
49
import javax.swing.table.TableColumnModel;
50

    
51
import org.apache.log4j.Logger;
52
import org.gvsig.app.documents.table.summarize.Summarize;
53
import org.gvsig.app.documents.table.summarize.exceptions.DBFExportException;
54
import org.gvsig.app.documents.table.summarize.exceptions.GroupByFieldNotExistsException;
55
import org.gvsig.app.documents.table.summarize.exceptions.GroupingErrorException;
56
import org.gvsig.app.documents.table.summarize.exceptions.InitializationException;
57
import org.gvsig.app.documents.table.summarize.exceptions.SummarizeException;
58
import org.gvsig.app.documents.table.summarize.utils.SelectedStatistics;
59
import org.jdesktop.swingx.decorator.AlternateRowHighlighter;
60

    
61
import com.hardcode.driverManager.DriverLoadException;
62
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
63
import com.hardcode.gdbms.engine.data.DataSource;
64
import com.hardcode.gdbms.engine.data.DataSourceFactory;
65
import com.hardcode.gdbms.engine.data.NoSuchTableException;
66
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
67
import com.iver.andami.PluginServices;
68
import com.iver.andami.messages.NotificationManager;
69
import com.iver.andami.ui.mdiManager.IWindow;
70
import com.iver.andami.ui.mdiManager.WindowInfo;
71
import com.iver.cit.gvsig.ProjectExtension;
72
import com.iver.cit.gvsig.fmap.edition.EditableAdapter;
73
import com.iver.cit.gvsig.fmap.layers.FBitSet;
74
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
75
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
76
import com.iver.cit.gvsig.project.Project;
77
import com.iver.cit.gvsig.project.ProjectFactory;
78
import com.iver.cit.gvsig.project.documents.ProjectDocumentFactory;
79
import com.iver.cit.gvsig.project.documents.table.ProjectTable;
80
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory;
81
import com.iver.cit.gvsig.project.documents.table.gui.Table;
82
import com.iver.utiles.extensionPoints.ExtensionPoint;
83
import com.iver.utiles.extensionPoints.ExtensionPoints;
84
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
85
import com.iver.utiles.swing.fileFilter.ExampleFileFilter;
86
import com.iver.utiles.swing.threads.SwingWorker;
87

    
88
/**
89
 * Contains the GUI of the Summarize tool for tables. 
90
 * 
91
 * @author IVER T.I. <http://www.iver.es> 01/02/2009
92
 */
93
public class SummarizeForm extends javax.swing.JPanel implements IWindow {
94

    
95
        private static final long serialVersionUID = -1184150355136852507L;
96
        private static Logger logger = Logger.getLogger(SummarizeForm.class.getName());
97
        private WindowInfo moWindowInfo = null;
98
        public Table table;
99
        public String selectedColumn;
100
        public FBitSet allrows;
101
        public long tempNumFilteredRows;
102
        
103
        public ArrayList<SelectedStatistics> operations = new ArrayList<SelectedStatistics>(); 
104
        
105
        SwingWorker loader = null;
106
        
107
        /** Creates new form SummarizeForm */
108
    public SummarizeForm() {
109
        initComponents();
110
        
111
        setTranslation();
112
        loadDBFColumnsInComboBox();
113
        setFormatTableHeaders();
114
                loadTable();
115
    }
116
    
117
    public void show(Table table, String selectedColumn){
118
            this.jLabelLoader.setVisible(false);
119
            this.table = table;
120
            this.selectedColumn = selectedColumn;
121
            
122
            //SET AS SELECTED THE COLUMN THAT THE USER HAS SELECTED IN THE ORIGINAL DBF TABLE
123
                String item = null;
124
                for (int i = 0; i < jComboBoxExtGroupByField.getItemCount(); i++) {
125
                        item = (String) jComboBoxExtGroupByField.getItemAt(i);
126
                        if (item.equals(selectedColumn)) {
127
                                jComboBoxExtGroupByField.setSelectedItem(item);
128
                        }
129
                }
130

    
131
            PluginServices.getMDIManager().addCentredWindow(this);
132
    }
133

    
134
    public void show(Table table) throws SummarizeException{
135
            if (jComboBoxExtGroupByField.getItemCount()>0) {
136
                    show(table, (String) jComboBoxExtGroupByField.getItemAt(0));
137
            }        
138
            else {
139
                    throw new SummarizeException(
140
                                    PluginServices.getText(this, "Summarize_Table_has_no_fields"));
141
            }
142
    }
143
    
144
    public boolean isDBFFile(){
145
            IWindow v = PluginServices.getMDIManager().getActiveWindow();
146
            if (v instanceof Table) return true;
147
            else return false;
148
    }
149
    
150
    
151
    public void loadDBFColumnsInComboBox(){
152
            
153
            if(isDBFFile()){
154
                        Table table = (Table) PluginServices.getMDIManager().getActiveWindow();
155
                        
156
                         try {
157
                                DataSource sds = table.getModel().getModelo().getRecordset();
158
                                //BitSet indices = table.getSelectedFieldIndices();
159
                                //System.out.println("columna seleccionada: " +sds.getFieldName(indices.nextSetBit(0)));
160
                                for(int i=0; i < sds.getFieldCount(); i++){
161
                                        jComboBoxExtGroupByField.addItem(sds.getFieldName(i));
162
                                }
163
                        } catch (ReadDriverException e) {
164
                                NotificationManager.showMessageError(PluginServices.getText(this, "Summarize_Error_accessing_the_table"), e);
165
                        }
166
                }
167
        }
168
    
169
    /**
170
         * Formatea los headers del grid.
171
         */
172
        public void setFormatTableHeaders(){
173
            DefaultTableModel model = (DefaultTableModel) jXTableSeleccion.getModel();
174
            Object[] newIdentifiers = new Object[]{PluginServices.getText(this, "SummarizeForm_columna_id"),
175
                                                                                       PluginServices.getText(this, "SummarizeForm_columna_minimum"),
176
                                                                               PluginServices.getText(this, "SummarizeForm_columna_maximum"),
177
                                                                               PluginServices.getText(this, "SummarizeForm_columna_average"),
178
                                                                               PluginServices.getText(this, "SummarizeForm_columna_sum"),
179
                                                                               PluginServices.getText(this, "SummarizeForm_columna_sd"),
180
                                                                               PluginServices.getText(this, "SummarizeForm_columna_variance")};
181
            
182
            model.setColumnIdentifiers(newIdentifiers);
183
            
184
//                TableColumnModel columnModel = jXTableSeleccion.getColumnModel();
185
//
186
//                columnModel.getColumn(0).setPreferredWidth(50);
187
//                columnModel.getColumn(1).setPreferredWidth(50);
188
//                columnModel.getColumn(2).setPreferredWidth(50);
189
//                columnModel.getColumn(3).setPreferredWidth(50);
190
//                columnModel.getColumn(4).setPreferredWidth(50);
191
//                columnModel.getColumn(5).setPreferredWidth(60);
192
//                columnModel.getColumn(6).setPreferredWidth(50);
193
                
194
                jXTableSeleccion.setHorizontalScrollEnabled(true);
195
                jXTableSeleccion.setHighlighters(new AlternateRowHighlighter());
196
    }
197
    
198
        /**
199
         * Loads the table rows, selecting only the ones which has numeric format.
200
         * Thats because statistics can not be done over alphanumeric values.
201
         */
202
    public void loadTable(){
203
            
204
            DefaultTableModel model = (DefaultTableModel) jXTableSeleccion.getModel();
205
                while (model.getRowCount() > 0){
206
                        model.removeRow(0);
207
                }
208
            
209
            if(isDBFFile()){
210
                    Table table = (Table) PluginServices.getMDIManager().getActiveWindow();
211
                        
212
                         try {
213
                                DataSource sds = table.getModel().getModelo().getRecordset();
214
                                
215
                                for(int i=0; i < sds.getFieldCount(); i++){
216
                                        //only numeric columns will be set on the table
217
                                        if(sds.getFieldType(i) == Types.BIGINT || sds.getFieldType(i) == Types.DECIMAL || sds.getFieldType(i) == Types.DOUBLE || 
218
                                                sds.getFieldType(i) == Types.FLOAT || sds.getFieldType(i) == Types.INTEGER || sds.getFieldType(i) == Types.NUMERIC || 
219
                                                sds.getFieldType(i) == Types.REAL || sds.getFieldType(i) == Types.SMALLINT || sds.getFieldType(i) == Types.TINYINT){
220
                                                
221
                                                Object[] fila = new Object[]{sds.getFieldName(i), false, false, false, false, false, false};
222
                                                model.addRow(fila);
223
                                        }
224
                                }
225
                                //set the edit mode on on every cell
226
                                for(int i=0; i < jXTableSeleccion.getRowCount();i++){
227
                                        jXTableSeleccion.setEditingRow(i);
228
                                        for(int j=0; j < jXTableSeleccion.getColumnCount();j++){
229
                                                jXTableSeleccion.setEditingColumn(j);
230
                                        }
231
                                }
232
                        } catch (ReadDriverException e) {
233
                                NotificationManager.showMessageError(PluginServices.getText(this, "Summarize_Error_accessing_the_table"), e);
234
                        }
235
            }
236
    }
237
    
238
    /**
239
         * Traduccion de todos los componentes del formulario.
240
         */
241
        private void setTranslation() {
242
                jLabelDescription.setText(PluginServices.getText(this, "lbl_SummarizeForm_descripcion1"));
243
                jLabelPunto1.setText(PluginServices.getText(this, "lbl_SummarizeForm_punto1"));
244
                jLabelPunto2.setText(PluginServices.getText(this, "lbl_SummarizeForm_punto2"));
245
                jLabelPunto3.setText(PluginServices.getText(this, "lbl_SummarizeForm_punto3"));
246
                jButtonAceptar.setText(PluginServices.getText(this, "btn_SummarizeForm_aceptar"));
247
                jButtonCancel.setText(PluginServices.getText(this, "btn_SummarizeForm_cancelar"));
248
        }
249

    
250
public void createTableDocument(String documentName, String driverName, String filePath) {
251
        // basically copied from ProjectTableFactory.createFromGUI
252
        LayerFactory.getDataSourceFactory().addFileDataSource(driverName,
253
                        documentName, filePath);
254

    
255
        DataSource dataSource;
256
                try {
257
                        dataSource = LayerFactory.getDataSourceFactory()
258
                                                            .createRandomDataSource(documentName,
259
                                DataSourceFactory.AUTOMATIC_OPENING);
260
                          SelectableDataSource sds = new SelectableDataSource(dataSource);
261
                        EditableAdapter auxea = new EditableAdapter();
262
                        auxea.setOriginalDataSource(sds);
263
                                     
264
                        ProjectTable projectTable = ProjectFactory.createTable(documentName,
265
                                auxea);
266

    
267
                        ProjectDocumentFactory pde = null;
268
                                ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
269
                                
270
                                ExtensionPoint extPoint=((ExtensionPoint)extensionPoints.get("Documents"));
271
                                try {
272
                                        pde = (ProjectDocumentFactory) extPoint.create(ProjectTableFactory.registerName);
273
                                        if (pde==null){
274
                                                Exception e=new Exception(PluginServices.getText(this,"Error_creating_new_table"));
275
                                                NotificationManager.showMessageError(PluginServices.getText(this,"Error_creating_new_table"), e);
276
                                                return;
277
                                        }
278
                                        
279
                                        projectTable.setProjectDocumentFactory(pde);
280
                                        ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
281
                                        Project project = pe.getProject();
282
                                        project.addDocument(projectTable);
283
                                        project.setModified(true);
284
                                        IWindow table = projectTable.createWindow();
285
                                        PluginServices.getMDIManager().addWindow(table);
286

    
287

    
288
                                } catch (InstantiationException e) {
289
                                        NotificationManager.showMessageError(PluginServices.getText(this,"Error_creating_new_table"), e);
290
                                } catch (IllegalAccessException e) {
291
                                        NotificationManager.showMessageError(PluginServices.getText(this,"Error_creating_new_table"), e);
292
                                }catch (Exception e) {
293
                                        NotificationManager.showMessageError(PluginServices.getText(this,"Error_creating_new_table"), e);
294
                                }
295

    
296
                } catch (DriverLoadException e1) {
297
                        NotificationManager.showMessageError(PluginServices.getText(this,"Error_creating_new_table"), e1);
298
                } catch (NoSuchTableException e1) {
299
                        NotificationManager.showMessageError(PluginServices.getText(this,"Error_creating_new_table"), e1);
300
                } catch (ReadDriverException e1) {
301
                        NotificationManager.showMessageError(PluginServices.getText(this,"Error_creating_new_table"), e1);
302
                }
303
        
304
      }
305
        
306
    /** This method is called from within the constructor to
307
     * initialize the form.
308
     * WARNING: Do NOT modify this code. The content of this method is
309
     * always regenerated by the Form Editor.
310
     */
311
    @SuppressWarnings("unchecked")
312
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
313
    private void initComponents() {
314

    
315
        jLabelDescription = new javax.swing.JLabel();
316
        jPanelMain = new javax.swing.JPanel();
317
        jLabelPunto1 = new javax.swing.JLabel();
318
        jComboBoxExtGroupByField = new org.gvsig.app.documents.table.summarize.utils.JComboBoxExt();
319
        jLabelPunto2 = new javax.swing.JLabel();
320
        jScrollPaneTree = new javax.swing.JScrollPane();
321
        jXTableSeleccion = new org.jdesktop.swingx.JXTable();
322
        jLabelPunto3 = new javax.swing.JLabel();
323
        jTextFieldExtFile = new org.gvsig.app.documents.table.summarize.utils.JTextFieldExt();
324
        jButtonFileChooser = new javax.swing.JButton();
325
        jLabelLoader = new javax.swing.JLabel();
326
        jButtonAceptar = new javax.swing.JButton();
327
        jButtonCancel = new javax.swing.JButton();
328

    
329
        jLabelDescription.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
330
        jLabelDescription.setText("description1");
331

    
332
        jPanelMain.setBorder(javax.swing.BorderFactory.createEtchedBorder());
333

    
334
        jLabelPunto1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
335
        jLabelPunto1.setText("point1");
336

    
337
        jComboBoxExtGroupByField.addItemListener(new java.awt.event.ItemListener() {
338
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
339
                jComboBoxExtGroupByFieldItemStateChanged(evt);
340
            }
341
        });
342

    
343
        jLabelPunto2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
344
        jLabelPunto2.setText("punto2");
345
        jLabelPunto2.setVerticalAlignment(javax.swing.SwingConstants.TOP);
346

    
347
        jXTableSeleccion.setModel(new javax.swing.table.DefaultTableModel(
348
                new Object [][] {
349

    
350
                },
351
                new String [] {
352
                                PluginServices.getText(this, "SummarizeForm_columna_id"), 
353
                                PluginServices.getText(this, "SummarizeForm_columna_minimum"), 
354
                                PluginServices.getText(this, "SummarizeForm_columna_maximum"), 
355
                                PluginServices.getText(this, "SummarizeForm_columna_average"), 
356
                                PluginServices.getText(this, "SummarizeForm_columna_sum"), 
357
                                PluginServices.getText(this, "SummarizeForm_columna_sd"),
358
                                PluginServices.getText(this, "SummarizeForm_columna_variance")
359
                }
360
            ) {
361
                Class[] tableModelTypes = new Class [] {
362
                    java.lang.String.class, 
363
                    java.lang.Boolean.class, 
364
                    java.lang.Boolean.class, 
365
                    java.lang.Boolean.class, 
366
                    java.lang.Boolean.class,
367
                    java.lang.Boolean.class,
368
                    java.lang.Boolean.class
369
                };
370
                boolean[] canEdit = new boolean [] {
371
                    false, true, true, true, true, true, true
372
                };
373

    
374
                public Class getColumnClass(int columnIndex) {
375
                    return tableModelTypes [columnIndex];
376
                }
377

    
378
                public boolean isCellEditable(int rowIndex, int columnIndex) {
379
                    return canEdit [columnIndex];
380
                }
381
            });
382
        jXTableSeleccion.addMouseListener(new java.awt.event.MouseAdapter() {
383
            public void mouseClicked(java.awt.event.MouseEvent evt) {
384
                jXTableSeleccionMouseClicked(evt);
385
            }
386
        });
387
        jScrollPaneTree.setViewportView(jXTableSeleccion);
388

    
389
        jLabelPunto3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
390
        jLabelPunto3.setText("punto3");
391

    
392
        jButtonFileChooser.setText("...");
393
        jButtonFileChooser.addActionListener(new java.awt.event.ActionListener() {
394
            public void actionPerformed(java.awt.event.ActionEvent evt) {
395
                jButtonFileChooserActionPerformed(evt);
396
            }
397
        });
398

    
399
        org.jdesktop.layout.GroupLayout jPanelMainLayout = new org.jdesktop.layout.GroupLayout(jPanelMain);
400
        jPanelMain.setLayout(jPanelMainLayout);
401
        jPanelMainLayout.setHorizontalGroup(
402
            jPanelMainLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
403
            .add(jPanelMainLayout.createSequentialGroup()
404
                .addContainerGap()
405
                .add(jPanelMainLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
406
                    .add(jScrollPaneTree, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE)
407
                    .add(jLabelPunto2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE)
408
                    .add(jLabelPunto3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE)
409
                    .add(jComboBoxExtGroupByField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE)
410
                    .add(jLabelPunto1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE)
411
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanelMainLayout.createSequentialGroup()
412
                        .add(jTextFieldExtFile, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 474, Short.MAX_VALUE)
413
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
414
                        .add(jButtonFileChooser)))
415
                .addContainerGap())
416
        );
417
        jPanelMainLayout.setVerticalGroup(
418
            jPanelMainLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
419
            .add(jPanelMainLayout.createSequentialGroup()
420
                .addContainerGap()
421
                .add(jLabelPunto1)
422
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
423
                .add(jComboBoxExtGroupByField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
424
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
425
                .add(jLabelPunto2)
426
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
427
                .add(jScrollPaneTree, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 251, Short.MAX_VALUE)
428
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
429
                .add(jLabelPunto3)
430
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
431
                .add(jPanelMainLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
432
                    .add(jButtonFileChooser)
433
                    .add(jTextFieldExtFile, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
434
                .addContainerGap())
435
        );
436

    
437
        jButtonAceptar.setText("Aceptar");
438

    
439
        jButtonCancel.setText("Cancelar");
440

    
441
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
442
        this.setLayout(layout);
443
        layout.setHorizontalGroup(
444
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
445
            .add(layout.createSequentialGroup()
446
                .addContainerGap()
447
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
448
                    .add(layout.createSequentialGroup()
449
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 367, Short.MAX_VALUE)
450
                        .add(jLabelLoader)
451
                        .add(192, 192, 192))
452
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
453
                        .add(jButtonAceptar)
454
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
455
                        .add(jButtonCancel)
456
                        .addContainerGap())
457
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
458
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
459
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jLabelDescription, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 549, Short.MAX_VALUE)
460
                            .add(jPanelMain, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
461
                        .addContainerGap())))
462
        );
463
        layout.setVerticalGroup(
464
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
465
            .add(layout.createSequentialGroup()
466
                .addContainerGap()
467
                .add(jLabelDescription, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
468
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
469
                .add(jPanelMain, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
470
                .add(6, 6, 6)
471
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
472
                    .add(jLabelLoader)
473
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
474
                        .add(jButtonCancel)
475
                        .add(jButtonAceptar)))
476
                .addContainerGap())
477
        );
478
    }// </editor-fold>//GEN-END:initComponents
479

    
480
private void jXTableSeleccionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jXTableSeleccionMouseClicked
481
        
482
        int indiceFila = jXTableSeleccion.getSelectedRow();
483
        int indiceColumna = jXTableSeleccion.getSelectedColumn();
484
        
485
        if(indiceFila!=-1 && indiceColumna!=-1){
486
                boolean check = Boolean.valueOf(String.valueOf(jXTableSeleccion.getValueAt(indiceFila, indiceColumna)));
487
                jXTableSeleccion.setValueAt(!check, indiceFila, indiceColumna);
488
        }
489
}//GEN-LAST:event_jXTableSeleccionMouseClicked
490

    
491
private void jComboBoxExtGroupByFieldItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxExtGroupByFieldItemStateChanged
492
        if(evt.getStateChange() == ItemEvent.SELECTED) {
493
                this.selectedColumn = (String) jComboBoxExtGroupByField.getSelectedItem();
494
        }
495
}//GEN-LAST:event_jComboBoxExtGroupByFieldItemStateChanged
496

    
497
private void jButtonFileChooserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonFileChooserActionPerformed
498
        
499
        String dbfDir="";
500
        JFileChooser filechooser = new JFileChooser();
501
        filechooser.setDialogTitle(
502
                        PluginServices.getText(this, "Choose_target_file_DBF"));
503
        
504
        //Aplicamos el filtro para mostarar solo ficheros dbf en el arbol de directorios
505
        ExampleFileFilter filter = new ExampleFileFilter();
506
    filter.addExtension("dbf");
507
    filter.setDescription(
508
                    PluginServices.getText(this, "DBF_files"));
509
    filechooser.setFileFilter(filter);
510
    
511
    int returnVal = filechooser.showOpenDialog((Component)PluginServices.getMDIManager().getActiveWindow());
512
        if (returnVal == JFileChooser.APPROVE_OPTION) {
513
                try {
514
                        File file = filechooser.getSelectedFile();
515
                        dbfDir = file.getCanonicalPath();
516
                        if(!dbfDir.endsWith(".dbf")) dbfDir += ".dbf";
517
                        
518
                        File aux = new File(dbfDir);
519
                        if(aux.exists()){ 
520
                                //si no se elige sobreescribir el fichero, entonces se busca un numero para numerarlo (1), (2)...
521
                                dbfDir = dbfDir.substring(0, dbfDir.indexOf(".dbf"));
522
                                boolean flag = true;
523
                                int i = 0;
524
                                while(flag){
525
                                        i++;
526
                                        aux = new File(dbfDir+"("+i+").dbf");
527
                                        if(aux. exists()) flag = true;
528
                                        else flag = false;
529
                                }
530
                                file = new File(dbfDir+"("+i+")");
531
                        }
532

    
533
                        dbfDir = file.getCanonicalPath();
534
                        if(!dbfDir.endsWith(".dbf")) dbfDir += ".dbf";
535
                        jTextFieldExtFile.setText(dbfDir);
536
                        
537
                } catch (IOException e) {
538
                        PluginServices.getLogger().error("Error selecting output file", e);
539
                }
540
        }
541
        
542
}//GEN-LAST:event_jButtonFileChooserActionPerformed
543

    
544
/**
545
 * Loads the user chosen operations in these structures:
546
 * ArrayList<String> headers, ArrayList<Integer> types y ArrayList<SelectedStatistics> operations
547
 * Headers has the header names, types has the type of each field and operations has the selected statistics operations on every field.
548
 * @param flag
549
 * @return
550
 * @throws ReadDriverException 
551
 * @throws GroupByFieldNotExistsException 
552
 * @throws FieldNotFoundException 
553
 */
554
public boolean loadSelectedOperations(boolean flag) throws ReadDriverException, FieldNotFoundException{
555
        DataSource sds = table.getModel().getModelo().getRecordset();
556
        
557
        operations.clear();
558
        
559
        //recorremos la tabla para tomar los datos de las operaciones marcadas por el usuario 
560
        //y lo introducimos en la estructura SelectedStatistics.
561
        //Solo se introduciran filas si alguna de las operaciones de esa columna ha sido seleccionada (para evitar proceso porsterior en los bucles).
562
        for(int j=0; j<jXTableSeleccion.getRowCount(); j++){
563

    
564
                if((Boolean)jXTableSeleccion.getValueAt(j, 1) || (Boolean)jXTableSeleccion.getValueAt(j, 2) ||
565
                                (Boolean)jXTableSeleccion.getValueAt(j, 3) || (Boolean)jXTableSeleccion.getValueAt(j, 4) ||
566
                                (Boolean)jXTableSeleccion.getValueAt(j, 5) || (Boolean)jXTableSeleccion.getValueAt(j, 6)){
567

    
568
                        flag = true;
569

    
570
                        //SELECTED OPERATIONS STORAGE ARRAY
571
                        SelectedStatistics fila = new SelectedStatistics();
572

    
573
                        fila.setColumnName((String)jXTableSeleccion.getValueAt(j, 0));
574
                        fila.setColumnNumber(j);
575
                        fila.setMin((Boolean)jXTableSeleccion.getValueAt(j, 1));
576
                        fila.setMax((Boolean)jXTableSeleccion.getValueAt(j, 2));
577
                        fila.setMean((Boolean)jXTableSeleccion.getValueAt(j, 3));
578
                        fila.setSum((Boolean)jXTableSeleccion.getValueAt(j, 4));
579
                        fila.setSd((Boolean)jXTableSeleccion.getValueAt(j, 5));
580
                        fila.setVar((Boolean)jXTableSeleccion.getValueAt(j, 6));
581
                        
582
                        String currFieldName = (String)jXTableSeleccion.getValueAt(j, 0);
583
                        int currFieldIdx = sds.getFieldIndexByName(currFieldName);
584
                        if (currFieldIdx==-1) {
585
                                throw new FieldNotFoundException();
586
                        }
587
                        int currFieldType = sds.getFieldType(currFieldIdx);
588
                        fila.setColumnType(currFieldType);
589
                        operations.add(fila);
590
                }
591
        }
592
        
593
        return flag;
594
}
595

    
596
    // Variables declaration - do not modify//GEN-BEGIN:variables
597
    private javax.swing.JButton jButtonAceptar;
598
    private javax.swing.JButton jButtonCancel;
599
    private javax.swing.JButton jButtonFileChooser;
600
    private org.gvsig.app.documents.table.summarize.utils.JComboBoxExt jComboBoxExtGroupByField;
601
    private javax.swing.JLabel jLabelDescription;
602
    private javax.swing.JLabel jLabelLoader;
603
    private javax.swing.JLabel jLabelPunto1;
604
    private javax.swing.JLabel jLabelPunto2;
605
    private javax.swing.JLabel jLabelPunto3;
606
    private javax.swing.JPanel jPanelMain;
607
    private javax.swing.JScrollPane jScrollPaneTree;
608
    private org.gvsig.app.documents.table.summarize.utils.JTextFieldExt jTextFieldExtFile;
609
    private org.jdesktop.swingx.JXTable jXTableSeleccion;
610
    // End of variables declaration//GEN-END:variables
611
        public WindowInfo getWindowInfo() {
612
                //Este metodo lo invoca el framework (Andami) para obtener informacion
613
                //acerca de la ventana en la que debe mostrar el panel.
614
                if (moWindowInfo == null) {
615
                        moWindowInfo = new WindowInfo(WindowInfo.MODALDIALOG |WindowInfo.RESIZABLE);
616
                        //moWindowInfo = new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE);
617
                        moWindowInfo.setHeight(515);
618
                        moWindowInfo.setWidth(600);
619
                        moWindowInfo.setTitle(PluginServices.getText(this, "title_summarize"));
620
                }
621
                return moWindowInfo;
622
        }
623

    
624
        public Object getWindowProfile() {
625
                return WindowInfo.DIALOG_PROFILE;
626
        }
627
}