root / trunk / extensions / extTableSummarize / src / org / gvsig / app / documents / table / summarize / gui / SummarizeForm.java @ 27644
History | View | Annotate | Download (31.7 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 |
jLabelDescription2.setText(PluginServices.getText(this, "lbl_SummarizeForm_descripcion2")); |
244 |
jLabelPunto1.setText(PluginServices.getText(this, "lbl_SummarizeForm_punto1")); |
245 |
jLabelPunto2.setText(PluginServices.getText(this, "lbl_SummarizeForm_punto2")); |
246 |
jLabelPunto3.setText(PluginServices.getText(this, "lbl_SummarizeForm_punto3")); |
247 |
jButtonAceptar.setText(PluginServices.getText(this, "btn_SummarizeForm_aceptar")); |
248 |
jButtonCancel.setText(PluginServices.getText(this, "btn_SummarizeForm_cancelar")); |
249 |
} |
250 |
|
251 |
public void createTableDocument(String documentName, String driverName, String filePath) { |
252 |
// basically copied from ProjectTableFactory.createFromGUI
|
253 |
LayerFactory.getDataSourceFactory().addFileDataSource(driverName, |
254 |
documentName, filePath); |
255 |
|
256 |
DataSource dataSource;
|
257 |
try {
|
258 |
dataSource = LayerFactory.getDataSourceFactory() |
259 |
.createRandomDataSource(documentName, |
260 |
DataSourceFactory.AUTOMATIC_OPENING); |
261 |
SelectableDataSource sds = new SelectableDataSource(dataSource);
|
262 |
EditableAdapter auxea = new EditableAdapter();
|
263 |
auxea.setOriginalDataSource(sds); |
264 |
|
265 |
ProjectTable projectTable = ProjectFactory.createTable(documentName, |
266 |
auxea); |
267 |
|
268 |
ProjectDocumentFactory pde = null;
|
269 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
270 |
|
271 |
ExtensionPoint extPoint=((ExtensionPoint)extensionPoints.get("Documents"));
|
272 |
try {
|
273 |
pde = (ProjectDocumentFactory) extPoint.create(ProjectTableFactory.registerName); |
274 |
if (pde==null){ |
275 |
Exception e=new Exception(PluginServices.getText(this,"Error_creating_new_table")); |
276 |
NotificationManager.showMessageError(PluginServices.getText(this,"Error_creating_new_table"), e); |
277 |
return;
|
278 |
} |
279 |
|
280 |
projectTable.setProjectDocumentFactory(pde); |
281 |
ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class); |
282 |
Project project = pe.getProject(); |
283 |
project.addDocument(projectTable); |
284 |
project.setModified(true);
|
285 |
IWindow table = projectTable.createWindow(); |
286 |
PluginServices.getMDIManager().addWindow(table); |
287 |
|
288 |
|
289 |
} catch (InstantiationException e) { |
290 |
NotificationManager.showMessageError(PluginServices.getText(this,"Error_creating_new_table"), e); |
291 |
} catch (IllegalAccessException e) { |
292 |
NotificationManager.showMessageError(PluginServices.getText(this,"Error_creating_new_table"), e); |
293 |
}catch (Exception e) { |
294 |
NotificationManager.showMessageError(PluginServices.getText(this,"Error_creating_new_table"), e); |
295 |
} |
296 |
|
297 |
} catch (DriverLoadException e1) {
|
298 |
NotificationManager.showMessageError(PluginServices.getText(this,"Error_creating_new_table"), e1); |
299 |
} catch (NoSuchTableException e1) {
|
300 |
NotificationManager.showMessageError(PluginServices.getText(this,"Error_creating_new_table"), e1); |
301 |
} catch (ReadDriverException e1) {
|
302 |
NotificationManager.showMessageError(PluginServices.getText(this,"Error_creating_new_table"), e1); |
303 |
} |
304 |
|
305 |
} |
306 |
|
307 |
/** This method is called from within the constructor to
|
308 |
* initialize the form.
|
309 |
* WARNING: Do NOT modify this code. The content of this method is
|
310 |
* always regenerated by the Form Editor.
|
311 |
*/
|
312 |
@SuppressWarnings("unchecked") |
313 |
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
314 |
private void initComponents() { |
315 |
|
316 |
jLabelDescription = new javax.swing.JLabel();
|
317 |
jPanelMain = new javax.swing.JPanel();
|
318 |
jLabelPunto1 = new javax.swing.JLabel();
|
319 |
jComboBoxExtGroupByField = new com.iver.swingext.JComboBoxExt();
|
320 |
jLabelPunto2 = new javax.swing.JLabel();
|
321 |
jScrollPaneTree = new javax.swing.JScrollPane();
|
322 |
jXTableSeleccion = new org.jdesktop.swingx.JXTable();
|
323 |
jLabelPunto3 = new javax.swing.JLabel();
|
324 |
jTextFieldExtFile = new com.iver.swingext.JTextFieldExt();
|
325 |
jButtonFileChooser = new javax.swing.JButton();
|
326 |
jButtonAceptar = new javax.swing.JButton();
|
327 |
jButtonCancel = new javax.swing.JButton();
|
328 |
jLabelDescription2 = new javax.swing.JLabel();
|
329 |
jLabelLoader = new javax.swing.JLabel();
|
330 |
|
331 |
jLabelDescription.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); |
332 |
jLabelDescription.setText("description1");
|
333 |
jLabelDescription.setVerticalAlignment(javax.swing.SwingConstants.TOP); |
334 |
|
335 |
jPanelMain.setBorder(javax.swing.BorderFactory.createEtchedBorder()); |
336 |
|
337 |
jLabelPunto1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); |
338 |
jLabelPunto1.setText("point1");
|
339 |
|
340 |
jComboBoxExtGroupByField.addItemListener(new java.awt.event.ItemListener() {
|
341 |
public void itemStateChanged(java.awt.event.ItemEvent evt) { |
342 |
jComboBoxExtGroupByFieldItemStateChanged(evt); |
343 |
} |
344 |
}); |
345 |
|
346 |
jLabelPunto2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); |
347 |
jLabelPunto2.setText("punto2");
|
348 |
jLabelPunto2.setVerticalAlignment(javax.swing.SwingConstants.TOP); |
349 |
|
350 |
jXTableSeleccion.setModel(new javax.swing.table.DefaultTableModel(
|
351 |
new Object [][] { |
352 |
|
353 |
}, |
354 |
new String [] { |
355 |
PluginServices.getText(this, "SummarizeForm_columna_id"), |
356 |
PluginServices.getText(this, "SummarizeForm_columna_minimum"), |
357 |
PluginServices.getText(this, "SummarizeForm_columna_maximum"), |
358 |
PluginServices.getText(this, "SummarizeForm_columna_average"), |
359 |
PluginServices.getText(this, "SummarizeForm_columna_sum"), |
360 |
PluginServices.getText(this, "SummarizeForm_columna_sd"), |
361 |
PluginServices.getText(this, "SummarizeForm_columna_variance") |
362 |
} |
363 |
) { |
364 |
Class[] tableModelTypes = new Class [] { |
365 |
java.lang.String.class, |
366 |
java.lang.Boolean.class, |
367 |
java.lang.Boolean.class, |
368 |
java.lang.Boolean.class, |
369 |
java.lang.Boolean.class, |
370 |
java.lang.Boolean.class, |
371 |
java.lang.Boolean.class |
372 |
}; |
373 |
boolean[] canEdit = new boolean [] { |
374 |
false, true, true, true, true, true, true |
375 |
}; |
376 |
|
377 |
public Class getColumnClass(int columnIndex) { |
378 |
return tableModelTypes [columnIndex];
|
379 |
} |
380 |
|
381 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
382 |
return canEdit [columnIndex];
|
383 |
} |
384 |
}); |
385 |
jXTableSeleccion.addMouseListener(new java.awt.event.MouseAdapter() {
|
386 |
public void mouseClicked(java.awt.event.MouseEvent evt) { |
387 |
jXTableSeleccionMouseClicked(evt); |
388 |
} |
389 |
}); |
390 |
jScrollPaneTree.setViewportView(jXTableSeleccion); |
391 |
|
392 |
jLabelPunto3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); |
393 |
jLabelPunto3.setText("punto3");
|
394 |
|
395 |
jButtonFileChooser.setText("...");
|
396 |
jButtonFileChooser.addActionListener(new java.awt.event.ActionListener() {
|
397 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
398 |
jButtonFileChooserActionPerformed(evt); |
399 |
} |
400 |
}); |
401 |
|
402 |
org.jdesktop.layout.GroupLayout jPanelMainLayout = new org.jdesktop.layout.GroupLayout(jPanelMain);
|
403 |
jPanelMain.setLayout(jPanelMainLayout); |
404 |
jPanelMainLayout.setHorizontalGroup( |
405 |
jPanelMainLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
406 |
.add(jPanelMainLayout.createSequentialGroup() |
407 |
.addContainerGap() |
408 |
.add(jPanelMainLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
409 |
.add(jScrollPaneTree, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 535, Short.MAX_VALUE) |
410 |
.add(jLabelPunto2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 535, Short.MAX_VALUE) |
411 |
.add(jLabelPunto3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 535, Short.MAX_VALUE) |
412 |
.add(jComboBoxExtGroupByField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 535, Short.MAX_VALUE) |
413 |
.add(jLabelPunto1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 535, Short.MAX_VALUE) |
414 |
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanelMainLayout.createSequentialGroup() |
415 |
.add(jTextFieldExtFile, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 484, Short.MAX_VALUE) |
416 |
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
417 |
.add(jButtonFileChooser))) |
418 |
.addContainerGap()) |
419 |
); |
420 |
jPanelMainLayout.setVerticalGroup( |
421 |
jPanelMainLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
422 |
.add(jPanelMainLayout.createSequentialGroup() |
423 |
.addContainerGap() |
424 |
.add(jLabelPunto1) |
425 |
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) |
426 |
.add(jComboBoxExtGroupByField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) |
427 |
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
428 |
.add(jLabelPunto2) |
429 |
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
430 |
.add(jScrollPaneTree, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 258, Short.MAX_VALUE) |
431 |
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
432 |
.add(jLabelPunto3) |
433 |
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
434 |
.add(jPanelMainLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) |
435 |
.add(jButtonFileChooser) |
436 |
.add(jTextFieldExtFile, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) |
437 |
.add(19, 19, 19)) |
438 |
); |
439 |
|
440 |
jButtonAceptar.setText("Aceptar");
|
441 |
jButtonAceptar.addActionListener(new java.awt.event.ActionListener() {
|
442 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
443 |
jButtonAceptarActionPerformed(evt); |
444 |
} |
445 |
}); |
446 |
|
447 |
jButtonCancel.setText("Cancelar");
|
448 |
jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
|
449 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
450 |
jButtonCancelActionPerformed(evt); |
451 |
} |
452 |
}); |
453 |
|
454 |
jLabelDescription2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); |
455 |
jLabelDescription2.setText("description2");
|
456 |
jLabelDescription2.setVerticalAlignment(javax.swing.SwingConstants.TOP); |
457 |
|
458 |
jLabelLoader.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/loader.gif"))); // NOI18N |
459 |
|
460 |
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); |
461 |
this.setLayout(layout);
|
462 |
layout.setHorizontalGroup( |
463 |
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
464 |
.add(layout.createSequentialGroup() |
465 |
.addContainerGap() |
466 |
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
467 |
.add(layout.createSequentialGroup() |
468 |
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) |
469 |
.add(layout.createSequentialGroup() |
470 |
.add(jLabelLoader) |
471 |
.add(18, 18, 18) |
472 |
.add(jButtonAceptar) |
473 |
.add(18, 18, 18) |
474 |
.add(jButtonCancel) |
475 |
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)) |
476 |
.add(org.jdesktop.layout.GroupLayout.LEADING, jPanelMain, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) |
477 |
.add(10, 10, 10)) |
478 |
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() |
479 |
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) |
480 |
.add(org.jdesktop.layout.GroupLayout.LEADING, jLabelDescription, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 559, Short.MAX_VALUE) |
481 |
.add(jLabelDescription2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 559, Short.MAX_VALUE)) |
482 |
.addContainerGap()))) |
483 |
); |
484 |
layout.setVerticalGroup( |
485 |
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
486 |
.add(layout.createSequentialGroup() |
487 |
.addContainerGap() |
488 |
.add(jLabelDescription) |
489 |
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
490 |
.add(jLabelDescription2) |
491 |
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) |
492 |
.add(jPanelMain, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
493 |
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
494 |
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) |
495 |
.add(jButtonCancel) |
496 |
.add(jButtonAceptar) |
497 |
.add(jLabelLoader)) |
498 |
.addContainerGap()) |
499 |
); |
500 |
}// </editor-fold>//GEN-END:initComponents
|
501 |
|
502 |
private void jButtonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAceptarActionPerformed |
503 |
|
504 |
//if a file has been allready selected...
|
505 |
if(!jTextFieldExtFile.getText().equals("") && jTextFieldExtFile.getText().endsWith(".dbf")){ |
506 |
|
507 |
loader = new SwingWorker() {
|
508 |
public Object construct() { |
509 |
jLabelLoader.setVisible(true);
|
510 |
return true; |
511 |
} |
512 |
public void finished() { |
513 |
jLabelLoader.setVisible(false);
|
514 |
} |
515 |
}; |
516 |
loader.start(); |
517 |
|
518 |
//carga las operaciones escogidas por el usuario en las estructuras
|
519 |
//ArrayList<String> headers, ArrayList<Integer> types y ArrayList<SelectedStatistics> operations
|
520 |
try {
|
521 |
boolean flag = loadSelectedOperations(false); |
522 |
|
523 |
if(!flag) {
|
524 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "SummarizeForm_seleccionar_operaciones")); |
525 |
} |
526 |
else {
|
527 |
File endFile = new File(jTextFieldExtFile.getText()); |
528 |
if (endFile.exists()) {
|
529 |
int returnValue = JOptionPane.showConfirmDialog(this, |
530 |
PluginServices.getText(this, "File_exists_Do_you_want_to_overwrite_it?"), |
531 |
PluginServices.getText(this, "Warning_Output_File"), |
532 |
JOptionPane.YES_NO_OPTION,
|
533 |
JOptionPane.WARNING_MESSAGE);
|
534 |
if (returnValue==JOptionPane.NO_OPTION) { |
535 |
return;
|
536 |
} |
537 |
endFile.delete(); |
538 |
} |
539 |
Summarize sumCalculator = new Summarize();
|
540 |
sumCalculator.setDataSource(this.table.getModel().getModelo().getRecordset());
|
541 |
sumCalculator.setGroupByField(selectedColumn); |
542 |
sumCalculator.setOperations(operations); |
543 |
sumCalculator.summarizeToDbf(endFile); |
544 |
createTableDocument(endFile.getName(), "gdbms dbf driver", endFile.getAbsolutePath());
|
545 |
PluginServices.getMDIManager().closeWindow(this);
|
546 |
} |
547 |
} |
548 |
catch (GroupByFieldNotExistsException e) {
|
549 |
NotificationManager.showMessageError( |
550 |
PluginServices.getText(this, "Summarize_Group_by_field_does_not_exist"), e); |
551 |
} catch (ReadDriverException e) {
|
552 |
NotificationManager.showMessageError( |
553 |
PluginServices.getText(this, "Summarize_Error_accessing_the_table"), e); |
554 |
} catch (DBFExportException e) {
|
555 |
NotificationManager.showMessageError( |
556 |
PluginServices.getText(this, "Summarize_Error_saving_the_output_DBF_file"), e); |
557 |
} catch (GroupingErrorException e) {
|
558 |
NotificationManager.showMessageError( |
559 |
PluginServices.getText(this, "Summarize_Error_calculating_the_groups"), e); |
560 |
} catch (FieldNotFoundException e) {
|
561 |
NotificationManager.showMessageError( |
562 |
PluginServices.getText(this, "Summarize_Field_does_not_exist"), e); |
563 |
} catch (InitializationException e) {
|
564 |
NotificationManager.showMessageError(e.getMessage(), e); |
565 |
} catch (SummarizeException e) {
|
566 |
NotificationManager.showMessageError( |
567 |
PluginServices.getText(this, "Error_summarizing_table"), e); |
568 |
} |
569 |
|
570 |
loader.interrupt(); |
571 |
}else{
|
572 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "SummarizeForm_fichero_destino")); |
573 |
} |
574 |
|
575 |
}//GEN-LAST:event_jButtonAceptarActionPerformed
|
576 |
|
577 |
private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed |
578 |
PluginServices.getMDIManager().closeWindow(SummarizeForm.this); |
579 |
}//GEN-LAST:event_jButtonCancelActionPerformed
|
580 |
|
581 |
private void jXTableSeleccionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jXTableSeleccionMouseClicked |
582 |
|
583 |
int indiceFila = jXTableSeleccion.getSelectedRow();
|
584 |
int indiceColumna = jXTableSeleccion.getSelectedColumn();
|
585 |
|
586 |
if(indiceFila!=-1 && indiceColumna!=-1){ |
587 |
boolean check = Boolean.valueOf(String.valueOf(jXTableSeleccion.getValueAt(indiceFila, indiceColumna))); |
588 |
jXTableSeleccion.setValueAt(!check, indiceFila, indiceColumna); |
589 |
} |
590 |
}//GEN-LAST:event_jXTableSeleccionMouseClicked
|
591 |
|
592 |
private void jComboBoxExtGroupByFieldItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxExtGroupByFieldItemStateChanged |
593 |
if(evt.getStateChange() == ItemEvent.SELECTED) { |
594 |
this.selectedColumn = (String) jComboBoxExtGroupByField.getSelectedItem(); |
595 |
} |
596 |
}//GEN-LAST:event_jComboBoxExtGroupByFieldItemStateChanged
|
597 |
|
598 |
private void jButtonFileChooserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonFileChooserActionPerformed |
599 |
|
600 |
String dbfDir=""; |
601 |
JFileChooser filechooser = new JFileChooser(); |
602 |
filechooser.setDialogTitle( |
603 |
PluginServices.getText(this, "Choose_target_file_DBF")); |
604 |
|
605 |
//Aplicamos el filtro para mostarar solo ficheros dbf en el arbol de directorios
|
606 |
ExampleFileFilter filter = new ExampleFileFilter();
|
607 |
filter.addExtension("dbf");
|
608 |
filter.setDescription( |
609 |
PluginServices.getText(this, "DBF_files")); |
610 |
filechooser.setFileFilter(filter); |
611 |
|
612 |
int returnVal = filechooser.showOpenDialog((Component)PluginServices.getMDIManager().getActiveWindow()); |
613 |
if (returnVal == JFileChooser.APPROVE_OPTION) { |
614 |
try {
|
615 |
File file = filechooser.getSelectedFile();
|
616 |
dbfDir = file.getCanonicalPath(); |
617 |
if(!dbfDir.endsWith(".dbf")) dbfDir += ".dbf"; |
618 |
|
619 |
File aux = new File(dbfDir); |
620 |
if(aux.exists()){
|
621 |
//si no se elige sobreescribir el fichero, entonces se busca un numero para numerarlo (1), (2)...
|
622 |
dbfDir = dbfDir.substring(0, dbfDir.indexOf(".dbf")); |
623 |
boolean flag = true; |
624 |
int i = 0; |
625 |
while(flag){
|
626 |
i++; |
627 |
aux = new File(dbfDir+"("+i+").dbf"); |
628 |
if(aux. exists()) flag = true; |
629 |
else flag = false; |
630 |
} |
631 |
file = new File(dbfDir+"("+i+")"); |
632 |
} |
633 |
|
634 |
dbfDir = file.getCanonicalPath(); |
635 |
if(!dbfDir.endsWith(".dbf")) dbfDir += ".dbf"; |
636 |
jTextFieldExtFile.setText(dbfDir); |
637 |
|
638 |
} catch (IOException e) { |
639 |
PluginServices.getLogger().error("Error selecting output file", e);
|
640 |
} |
641 |
} |
642 |
|
643 |
}//GEN-LAST:event_jButtonFileChooserActionPerformed
|
644 |
|
645 |
/**
|
646 |
* Loads the user chosen operations in these structures:
|
647 |
* ArrayList<String> headers, ArrayList<Integer> types y ArrayList<SelectedStatistics> operations
|
648 |
* Headers has the header names, types has the type of each field and operations has the selected statistics operations on every field.
|
649 |
* @param flag
|
650 |
* @return
|
651 |
* @throws ReadDriverException
|
652 |
* @throws GroupByFieldNotExistsException
|
653 |
* @throws FieldNotFoundException
|
654 |
*/
|
655 |
public boolean loadSelectedOperations(boolean flag) throws ReadDriverException, FieldNotFoundException{ |
656 |
DataSource sds = table.getModel().getModelo().getRecordset();
|
657 |
|
658 |
operations.clear(); |
659 |
|
660 |
//recorremos la tabla para tomar los datos de las operaciones marcadas por el usuario
|
661 |
//y lo introducimos en la estructura SelectedStatistics.
|
662 |
//Solo se introduciran filas si alguna de las operaciones de esa columna ha sido seleccionada (para evitar proceso porsterior en los bucles).
|
663 |
for(int j=0; j<jXTableSeleccion.getRowCount(); j++){ |
664 |
|
665 |
if((Boolean)jXTableSeleccion.getValueAt(j, 1) || (Boolean)jXTableSeleccion.getValueAt(j, 2) || |
666 |
(Boolean)jXTableSeleccion.getValueAt(j, 3) || (Boolean)jXTableSeleccion.getValueAt(j, 4) || |
667 |
(Boolean)jXTableSeleccion.getValueAt(j, 5) || (Boolean)jXTableSeleccion.getValueAt(j, 6)){ |
668 |
|
669 |
flag = true;
|
670 |
|
671 |
//SELECTED OPERATIONS STORAGE ARRAY
|
672 |
SelectedStatistics fila = new SelectedStatistics();
|
673 |
|
674 |
fila.setColumnName((String)jXTableSeleccion.getValueAt(j, 0)); |
675 |
fila.setColumnNumber(j); |
676 |
fila.setMin((Boolean)jXTableSeleccion.getValueAt(j, 1)); |
677 |
fila.setMax((Boolean)jXTableSeleccion.getValueAt(j, 2)); |
678 |
fila.setMean((Boolean)jXTableSeleccion.getValueAt(j, 3)); |
679 |
fila.setSum((Boolean)jXTableSeleccion.getValueAt(j, 4)); |
680 |
fila.setSd((Boolean)jXTableSeleccion.getValueAt(j, 5)); |
681 |
fila.setVar((Boolean)jXTableSeleccion.getValueAt(j, 6)); |
682 |
|
683 |
String currFieldName = (String)jXTableSeleccion.getValueAt(j, 0); |
684 |
int currFieldIdx = sds.getFieldIndexByName(currFieldName);
|
685 |
if (currFieldIdx==-1) { |
686 |
throw new FieldNotFoundException(); |
687 |
} |
688 |
int currFieldType = sds.getFieldType(currFieldIdx);
|
689 |
fila.setColumnType(currFieldType); |
690 |
operations.add(fila); |
691 |
} |
692 |
} |
693 |
|
694 |
return flag;
|
695 |
} |
696 |
|
697 |
// Variables declaration - do not modify//GEN-BEGIN:variables
|
698 |
private javax.swing.JButton jButtonAceptar;
|
699 |
private javax.swing.JButton jButtonCancel;
|
700 |
private javax.swing.JButton jButtonFileChooser;
|
701 |
private com.iver.swingext.JComboBoxExt jComboBoxExtGroupByField;
|
702 |
private javax.swing.JLabel jLabelDescription;
|
703 |
private javax.swing.JLabel jLabelDescription2;
|
704 |
private javax.swing.JLabel jLabelLoader;
|
705 |
private javax.swing.JLabel jLabelPunto1;
|
706 |
private javax.swing.JLabel jLabelPunto2;
|
707 |
private javax.swing.JLabel jLabelPunto3;
|
708 |
private javax.swing.JPanel jPanelMain;
|
709 |
private javax.swing.JScrollPane jScrollPaneTree;
|
710 |
private com.iver.swingext.JTextFieldExt jTextFieldExtFile;
|
711 |
private org.jdesktop.swingx.JXTable jXTableSeleccion;
|
712 |
// End of variables declaration//GEN-END:variables
|
713 |
public WindowInfo getWindowInfo() {
|
714 |
//Este metodo lo invoca el framework (Andami) para obtener informacion
|
715 |
//acerca de la ventana en la que debe mostrar el panel.
|
716 |
if (moWindowInfo == null) { |
717 |
moWindowInfo = new WindowInfo(WindowInfo.MODALDIALOG |WindowInfo.RESIZABLE);
|
718 |
//moWindowInfo = new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE);
|
719 |
moWindowInfo.setHeight(515);
|
720 |
moWindowInfo.setWidth(600);
|
721 |
moWindowInfo.setTitle(PluginServices.getText(this, "title_summarize")); |
722 |
} |
723 |
return moWindowInfo;
|
724 |
} |
725 |
|
726 |
public Object getWindowProfile() { |
727 |
return WindowInfo.DIALOG_PROFILE;
|
728 |
} |
729 |
} |