Revision 28534

View differences:

tags/tmp_build/extensions/extTableSummarize/build.xml
1
<project name="extTableSummarize" default="generate-without-source" basedir=".">
2
    <description>
3
        Instala el plugin de DBF Table Summarize en Andami.
4
    </description>
5
  <!-- set global properties for this build -->
6
  <property name="src" location="src"/>
7
  <property name="without_src"  location="without_src"/>
8
  <property name="src-test" location="src-test"/>
9
  <property name="build" location="bin"/>
10
  <property name="build-test" location="bin-test"/>
11
  <property name="dist"  location="dist"/>
12
  <property name="lib"  location="lib"/>
13
  <property name="plugin" value="org.gvsig.tableSummarize"/>
14
  <property name="extension-dir" location="../_fwAndami/gvSIG/extensiones"/>
15
  <property name="gvSIGlib-dir" value="${extension-dir}/com.iver.cit.gvsig/lib"/>
16
  <property name="andami-dir" location="../_fwAndami"/>
17

  
18
	<import file="../binaries/ant/utilities.xml"/>
19

  
20
  <target name="init">
21
    <!-- Create the time stamp -->
22
    <tstamp/>
23
  	<echo>
24
  			Compiling ${ant.project.name}...</echo>
25
    <!-- Create the build directory structure used by compile -->
26
    <mkdir dir="${build}"/>
27
    <mkdir dir="${dist}"/>
28
  </target>
29

  
30
	<target name="buildNumber">  
31
	  <propertyfile     file="build.number"
32
	      comment="Build Number for ANT. Do not edit!">
33
	    <entry key="build.number" default="0" type="int" operation="+" />
34
	  </propertyfile>
35
	  <property file="build.number" />
36
	</target>
37

  
38
  <target name="distribution" depends="buildNumber, copy-data-files, generate-without-source">
39
  </target>
40

  
41
  <target name="compile"
42
          description="compile the source" >
43
      <!-- Compile the Java code from ${src} to ${bin} -->
44
		<antcall target="gvSIG-import-build-number"/>
45
		<loadEclipseClasspath project="${basedir}"/>
46
		<gvSIG-javac
47
			classpath="${eclipseClasspath}"
48
		/>
49
      <!--<javac      srcdir="${src}"
50
                  destdir="${build}"
51
                  source="${JavaSourceVersion}"
52
                  target="${JavaTargetVersion}"
53
                  debug="${debug}"
54
                  debuglevel="${debuglevel}"
55
                  encoding="${encoding}"
56
	   			  classpath="${extension-dir}/com.iver.cit.gvsig/lib/fmap.jar:${extension-dir}/com.iver.cit.gvsig/lib/com.iver.cit.gvsig.jar:../FMap/lib/cms.jar:../Andami/lib/iver-utiles.jar:../FMap/lib/gdbms-0.8-SNAPSHOT.jar:../Andami/andami.jar"/>
57
	  -->
58
    </target>
59

  
60
  <target name="generate-without-source" description="generate the distribution without the source file" >
61
    <!-- Create the distribution directory -->
62
    <mkdir dir="${dist}"/>
63

  
64
  	<loadproperties srcFile="build.number"/>
65

  
66
  	<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
67
    <jar jarfile="${dist}/${plugin}.jar" basedir="${build}"/>
68

  
69
  	<copy file="config/config.xml" todir="${dist}"/>
70
  	<copy file="build.number" todir="${dist}"/>
71

  
72
  	<copy todir="${dist}/images">
73
  	  	    	<fileset dir="images/" includes="*"/>
74
  	  	</copy>
75
  	<copy todir="${dist}">
76
    	<fileset dir="config" includes="text*.properties"/>
77
    </copy>  	
78
    <move todir="${extension-dir}/${plugin}/">
79
    	<fileset dir="${dist}" includes="**/**"/>
80
    </move>
81

  
82
  	<!--mkdir dir="${extension-dir}/${plugin}/data"/>
83
  	<copy todir="${extension-dir}/${plugin}/data">
84
  	    	<fileset dir="data" includes="**/**"/>
85
  	</copy-->
86
	<copy todir="${extension-dir}/${plugin}/">
87
		<fileset dir="${lib}" includes="**/*.jar"/>
88
	</copy>
89

  
90
  </target>
91
  	
92
	<target name="copy-data-files">
93
			<copy file="config/config.xml" todir="${without_src}"/>
94
			<copy file="build.number" todir="${without_src}"/>
95
			<copy file="config/about.htm" todir="${without_src}"/>
96
			<loadproperties srcFile="build.number"/>
97
			<replace casesensitive="true"
98
	  		file="${without_src}/about.htm"
99
	  	  	token="#build.number#"
100
	  		value="${build.number}"/>
101
			<copy todir="${without_src}">
102
				<fileset dir="config" includes="text*.properties"/>
103
			</copy>
104
			<copy todir="${without_src}/images">
105
				<fileset dir="images/" includes="*"/>
106
			</copy>
107
	</target>
108

  
109
	<target name="batch-build"
110
			description="compile the sources, create the jar file"
111
			depends="init,compile,generate-without-source">
112
	</target>
113

  
114
	<target name="clean"
115
		    description="cleans the build directories">
116
		<delete dir="${build}"/>
117
		<delete dir="${dist}"/>
118
	</target>
119
	
120
	<!--target name="run-tests" depends="batch-build,compile-tests">
121
		<antcall target="generic-run-tests">
122
			<param name="TestSuite.Name" value="org.gvsig.crs.AllTests"/>
123
		</antcall>
124
	</target-->
125
</project>
126

  
127

  
tags/tmp_build/extensions/extTableSummarize/.classpath
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
4
	<classpathentry kind="src" path="src"/>
5
	<classpathentry excluding="org/gvsig/crs/test/" kind="src" path="src-test"/>
6
	<classpathentry combineaccessrules="false" kind="src" path="/libJCRS"/>
7
	<classpathentry kind="src" path="/_fwAndami"/>
8
	<classpathentry combineaccessrules="false" kind="src" path="/appgvSIG"/>
9
	<classpathentry combineaccessrules="false" kind="src" path="/libFMap"/>
10
	<classpathentry combineaccessrules="false" kind="src" path="/libUIComponent"/>
11
	<classpathentry kind="lib" path="/libFMap/lib/gdbms-0.8-SNAPSHOT.jar" sourcepath="/libGDBMS"/>
12
	<classpathentry kind="lib" path="/_fwAndami/lib/org.gvsig.exceptions.jar"/>
13
	<classpathentry kind="lib" path="/libFMap/lib/driver-manager-1.1.jar" sourcepath="/libDriverManager"/>
14
	<classpathentry kind="lib" path="lib/swing-layout-1.0.jar"/>
15
	<classpathentry kind="lib" path="lib/swingx-2007_07_22.jar"/>
16
	<classpathentry kind="lib" path="/_fwAndami/lib/iver-utiles.jar" sourcepath="/libIverUtiles"/>
17
	<classpathentry kind="lib" path="/_fwAndami/lib/log4j-1.2.8.jar"/>
18
	<classpathentry kind="output" path="bin"/>
19
</classpath>
tags/tmp_build/extensions/extTableSummarize/LICENSE.txt
1
This extension is copyright of:
2
  IVER.T.I.
3
  C/ LERIDA, 20
4
  46009 VALENCIA (SPAIN)
5
  http://www.iver.es
6

  
7
It can be used under the terms of the GPL license, version 2
8
(or any later version):
9
http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10

  
11
Source code can be obtained from gvSIG public SVN:
12
http://subversion.gvsig.org/gvSIG/
13

  
14
The following third-party libraries are used by this gvSIG extension:
15

  
16
swingx: https://swingx.dev.java.net/
17
License: LGPL
18

  
19
swing-layout: https://swing-layout.dev.java.net/
20
License: LGPL
21
 
0 22

  
tags/tmp_build/extensions/extTableSummarize/.project
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>extTableSummarize</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
	</buildSpec>
14
	<natures>
15
		<nature>org.eclipse.jdt.core.javanature</nature>
16
	</natures>
17
</projectDescription>
tags/tmp_build/extensions/extTableSummarize/config/text.properties
1
#Translations for language [es]
2
#Tue Jan 20 17:39:04 CET 2009
3
GROUP=GRUPO
4
COUNT=CANTIDAD
5
MAX=MAX
6
MIN=MIN
7
SUM=SUM
8
MEAN=MED
9
STDEV=DT
10
VAR=VAR
11
Not_possible_generate_unique_field_name=No es posible generar un nombre de campo ?nico
12
Summarize_Error_accessing_the_table=Resumen de tabla: Error accediendo a la tabla
13
Unknown_summarize_error=Resumen de tabla: Error desconocido
14
Operation_not_initialized=Operaci?n no inicializada
15
Data_source_not_initialized=Fuente de datos no inicializada
16
GroupByField_not_initialized=Campo de agrupaci?n no inicializado
17
Summarize_Table_has_no_fields=Error: La tabla a resumir no contiene campos
18
SummarizeForm_columna_id=Columna
19
SummarizeForm_columna_minimum=M\u00ednimo
20
SummarizeForm_columna_maximum=M\u00e1ximo
21
SummarizeForm_columna_average=Media
22
SummarizeForm_columna_sum=Suma
23
SummarizeForm_columna_sd=Desv. T?pica
24
SummarizeForm_columna_variance=Varianza
25
SummarizeForm_fichero_destino=Por favor, debes escoger un fichero destino antes de realizar las operaciones.
26
SummarizeForm_seleccionar_operaciones=Por favor, debes escoger las operaciones a realizar antes de intentar ejecutarlas.
27
Error_creating_new_table=Error creando la nueva tabla
28
File_exists_Do_you_want_to_overwrite_it=El fichero ya existe. ?Desea sobreescribirlo?
29
Warning_Output_File=Aviso: Fichero de Salida
30
Summarize_Group_by_field_does_not_exist=Resumen de tabla: El campo para agrupar no existe
31
Summarize_Error_saving_the_output_DBF_file=Resumen de tabla: Error guardando el DBF de salida
32
Summarize_Error_calculating_the_groups=Resumen de tabla: Error calculando los grupos
33
Summarize_Field_does_not_exist=Resumen de tabla: El campo no existe
34
Error_summarizing_table=Error en el resumen de tabla
35
Choose_target_file_DBF=Escoja fichero destino (en formato .DBF)
36
DBF_files=Ficheros DBF
37
title_summarize=Resumen de tablas
38
table_summarize=Resumen de tablas
39
lbl_SummarizeForm_descripcion1=<html>Resumen de Tabla: Crea una nueva tabla que contiene un registro\n por cada valor \u00fanico del campo seleccionado, adem\u00e1s de las estad\u00edsticas del resto de campos.</html>
40
lbl_SummarizeForm_punto1=1. Selecciona el campo por el que se agrupar?:
41
lbl_SummarizeForm_punto2=2. Selecciona una o m\u00e1s estad\u00edsticas\n para ser incluidas en la tabla de resultados:
42
lbl_SummarizeForm_punto3=3. Especificar fichero de destino:
43
btn_SummarizeForm_aceptar=Aceptar
44
btn_SummarizeForm_cancelar=Cancelar
tags/tmp_build/extensions/extTableSummarize/config/text_en.properties
1
#Translations for language [en]
2
GROUP=GROUP
3
COUNT=COUNT
4
MAX=MAX
5
MIN=MIN
6
SUM=SUM
7
MEAN=MEAN
8
STDEV=STDEV
9
VAR=VAR
10
Not_possible_generate_unique_field_name=It is not possible to generate a unique field name
11
Summarize_Error_accessing_the_table=Summarize: Error accessing the table
12
Unknown_summarize_error=Unknown summarize error
13
Operation_not_initialized=Operation not initialized
14
Data_source_not_initialized=Data source not initialized
15
GroupByField_not_initialized=GroupByField not initialized
16
Summarize_Table_has_no_fields=Summarize Error: Selected table has no fields
17
SummarizeForm_columna_id=Field
18
SummarizeForm_columna_minimum=Minimum
19
SummarizeForm_columna_maximum=Maximum
20
SummarizeForm_columna_average=Mean
21
SummarizeForm_columna_sum=Sum
22
SummarizeForm_columna_sd=Std. Deviation
23
SummarizeForm_columna_variance=Variance
24
SummarizeForm_fichero_destino=Please, choose the target file
25
SummarizeForm_seleccionar_operaciones=Please, choose some operations to calculate
26
Error_creating_new_table=Error creating the new table
27
File_exists_Do_you_want_to_overwrite_it=File already exists. Do you want to overwrite it?
28
Warning_Output_File=Warning: Output File
29
Summarize_Group_by_field_does_not_exist=Summarize: Group by field does not exist
30
Summarize_Error_saving_the_output_DBF_file=Summarize: Error saving the output DBF
31
Summarize_Error_calculating_the_groups=Summarize: Error calculating the groups
32
Summarize_Field_does_not_exist=Summarize: Field does not exist
33
Error_summarizing_table=Error_summarizing_table
34
Choose_target_file_DBF=Choose target file (.DBF)
35
DBF_files=DBF files
36
title_summarize=Table Summarize
37
table_summarize=Table Summarize
38
lbl_SummarizeForm_descripcion1=<html>Summarize Table: creates a new table which contains a register for each unique value from the groupBy field, plus the selected statistics from the rest of the fields.</html>
39
lbl_SummarizeForm_punto1=1. Choose the groupBy field:
40
lbl_SummarizeForm_punto2=2. Choose one or more statistics to be included in the result table:
41
lbl_SummarizeForm_punto3=3. Choose the target file:
42
btn_SummarizeForm_aceptar=OK
43
btn_SummarizeForm_cancelar=Cancel
tags/tmp_build/extensions/extTableSummarize/config/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<plugin-config>
3
	<depends plugin-name="com.iver.cit.gvsig"/>
4
	<libraries library-dir="."/>
5
	<resourceBundle name="text"/>
6
	<extensions>
7
		<extension class-name="org.gvsig.app.documents.table.summarize.TableSummarizeExtension"
8
			description="M?dulo para el c?lculo de estadisticas sobre tablas DBF." 
9
			active="true" 
10
			priority="1">
11
			<tool-bar name="Herramientas" position="12">
12
				<action-tool icon="tableSummarize-statistics" tooltip="table_summarize" position="9"/>
13
			</tool-bar>
14
		</extension>
15
	</extensions>		
16
</plugin-config>
tags/tmp_build/extensions/extTableSummarize/build.number
1
#Build Number for ANT. Do not edit!
2
#Fri Apr 24 13:12:16 CEST 2009
3
build.number=1231
tags/tmp_build/extensions/extTableSummarize/src/org/gvsig/app/documents/table/summarize/TableSummarizeExtension.java
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;
38

  
39
import java.util.BitSet;
40

  
41
import org.gvsig.app.documents.table.summarize.gui.SummarizeForm;
42

  
43
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
44
import com.hardcode.gdbms.engine.data.DataSource;
45
import com.iver.andami.PluginServices;
46
import com.iver.andami.messages.NotificationManager;
47
import com.iver.andami.plugins.Extension;
48
import com.iver.andami.plugins.PluginClassLoader;
49
import com.iver.andami.ui.mdiManager.IWindow;
50
import com.iver.cit.gvsig.project.documents.table.gui.Table;
51

  
52
/**
53
 * Adds a Summarize tool for Tables.
54
 * 
55
 * @author IVER T.I. <http://www.iver.es> 01/02/2009
56
 */
57
public class TableSummarizeExtension extends Extension  {
58

  
59
	public void execute(String actionCommand) {
60
		try{
61
			
62
			IWindow v = PluginServices.getMDIManager().getActiveWindow();
63
		    if (v instanceof Table){
64
		    	
65
				Table table = (Table) PluginServices.getMDIManager().getActiveWindow();
66
				 try {
67
					DataSource sds = table.getModel().getModelo().getRecordset();
68
					BitSet indices = table.getSelectedFieldIndices();
69
					SummarizeForm st = new SummarizeForm();
70
					if (indices.cardinality()>0) {
71
						st.show(table, sds.getFieldName(indices.nextSetBit(0)));
72
					}
73
					else {
74
						st.show(table);
75
					}
76
				} catch (ReadDriverException e) {
77
					NotificationManager.showMessageError(PluginServices.getText(this, "Summarize_Error_accessing_the_table"), e);
78
				}
79
		    }
80
		} 
81
		catch (Exception e){
82
			NotificationManager.showMessageError(PluginServices.getText(this, "Unknown_summarize_error"), e);
83
		}
84
	}
85

  
86
	public void initialize() {
87
		initilializeIcons();
88
	}
89
	
90
	private void initilializeIcons(){
91
		PluginClassLoader loader = PluginServices.getPluginServices(this).getClassLoader();
92
		PluginServices.getIconTheme().registerDefault(
93
				"tableSummarize-statistics",
94
				loader.getResource("images/tableSummarize16.png")
95
			);
96
		PluginServices.getIconTheme().registerDefault(
97
				"tableSummarize-statistics-22x22",
98
				loader.getResource("images/tableSummarize22.png")
99
			);
100
	}
101

  
102
	/**
103
	 * @see com.iver.andami.plugins.IExtension#isEnabled()
104
	 */
105
	public boolean isEnabled() {
106
		return true;
107
//		IWindow v = PluginServices.getMDIManager().getActiveWindow();
108
//
109
//		if (v == null) {
110
//			return false;
111
//		}
112
//
113
//		if (v instanceof Table) {
114
//			Table table = (Table) v;
115
//			return doIsEnabled(table);
116
//		}
117
	}
118

  
119
//	protected boolean doIsEnabled(Table table){
120
//		BitSet indices = table.getSelectedFieldIndices();
121
//		//one column must be selected to activate the extension button
122
//		if (indices.cardinality() == 1) return true;
123
//		else return false;
124
//	}
125
	
126

  
127

  
128
	/**
129
	 * @see com.iver.andami.plugins.IExtension#isVisible()
130
	 */
131
	public boolean isVisible() {
132
		IWindow v = PluginServices.getMDIManager().getActiveWindow();
133

  
134
		if (v == null) {
135
			return false;
136
		}
137

  
138
		if (v instanceof Table) {
139
			return true;
140
		}
141
		return false;
142
	}
143

  
144
}
tags/tmp_build/extensions/extTableSummarize/src/org/gvsig/app/documents/table/summarize/exceptions/GroupByFieldNotExistsException.java
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.exceptions;
38

  
39
public class GroupByFieldNotExistsException extends Exception {
40

  
41
	public GroupByFieldNotExistsException() {
42
		super();
43
	}
44

  
45
	public GroupByFieldNotExistsException(String message, Throwable cause) {
46
		super(message, cause);
47
	}
48

  
49
	public GroupByFieldNotExistsException(String message) {
50
		super(message);
51
	}
52

  
53
	public GroupByFieldNotExistsException(Throwable cause) {
54
		super(cause);
55
	}
56
	
57
}
tags/tmp_build/extensions/extTableSummarize/src/org/gvsig/app/documents/table/summarize/exceptions/SummarizeException.java
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.exceptions;
38

  
39
public class SummarizeException extends Exception {
40

  
41
	public SummarizeException() {
42
		super();
43
	}
44

  
45
	public SummarizeException(String message, Throwable cause) {
46
		super(message, cause);
47
	}
48

  
49
	public SummarizeException(String message) {
50
		super(message);
51
	}
52

  
53
	public SummarizeException(Throwable cause) {
54
		super(cause);
55
	}
56
	
57
}
tags/tmp_build/extensions/extTableSummarize/src/org/gvsig/app/documents/table/summarize/exceptions/DBFExportException.java
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.exceptions;
38

  
39
public class DBFExportException extends Exception {
40

  
41
	public DBFExportException() {
42
		super();
43
	}
44

  
45
	public DBFExportException(String message, Throwable cause) {
46
		super(message, cause);
47
	}
48

  
49
	public DBFExportException(String message) {
50
		super(message);
51
	}
52

  
53
	public DBFExportException(Throwable cause) {
54
		super(cause);
55
	}
56
	
57
}
tags/tmp_build/extensions/extTableSummarize/src/org/gvsig/app/documents/table/summarize/exceptions/GroupingErrorException.java
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.exceptions;
38

  
39
public class GroupingErrorException extends Exception {
40

  
41
	public GroupingErrorException() {
42
		super();
43
	}
44

  
45
	public GroupingErrorException(String message, Throwable cause) {
46
		super(message, cause);
47
	}
48

  
49
	public GroupingErrorException(String message) {
50
		super(message);
51
	}
52

  
53
	public GroupingErrorException(Throwable cause) {
54
		super(cause);
55
	}	
56
}
tags/tmp_build/extensions/extTableSummarize/src/org/gvsig/app/documents/table/summarize/exceptions/InitializationException.java
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.exceptions;
38

  
39
public class InitializationException extends Exception {
40

  
41
	public InitializationException() {
42
		super();
43
	}
44

  
45
	public InitializationException(String message, Throwable cause) {
46
		super(message, cause);
47
	}
48

  
49
	public InitializationException(String message) {
50
		super(message);
51
	}
52

  
53
	public InitializationException(Throwable cause) {
54
		super(cause);
55
	}
56
	
57
}
tags/tmp_build/extensions/extTableSummarize/src/org/gvsig/app/documents/table/summarize/gui/SummarizeForm.java
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

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

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

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

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

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

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

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

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

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

  
286

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

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

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

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

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

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

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

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

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

  
349
                },
350
                new String [] {
351
                		PluginServices.getText(this, "SummarizeForm_columna_id"), 
352
                		PluginServices.getText(this, "SummarizeForm_columna_minimum"), 
353
                		PluginServices.getText(this, "SummarizeForm_columna_maximum"), 
354
                		PluginServices.getText(this, "SummarizeForm_columna_average"), 
355
                		PluginServices.getText(this, "SummarizeForm_columna_sum"), 
356
                		PluginServices.getText(this, "SummarizeForm_columna_sd"),
357
                		PluginServices.getText(this, "SummarizeForm_columna_variance")
358
                }
359
            ) {
360
                Class[] tableModelTypes = new Class [] {
361
                    java.lang.String.class, 
362
                    java.lang.Boolean.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
                };
369
                boolean[] canEdit = new boolean [] {
370
                    false, true, true, true, true, true, true
371
                };
372

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

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

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

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

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

  
436
        jLabelLoader.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/loader.gif"))); // NOI18N
437

  
438
        jButtonAceptar.setText("Aceptar");
439
        jButtonAceptar.addActionListener(new java.awt.event.ActionListener() {
440
            public void actionPerformed(java.awt.event.ActionEvent evt) {
441
                jButtonAceptarActionPerformed(evt);
442
            }
443
        });
444

  
445
        jButtonCancel.setText("Cancelar");
446
        jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
447
            public void actionPerformed(java.awt.event.ActionEvent evt) {
448
                jButtonCancelActionPerformed(evt);
449
            }
450
        });
451

  
452
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
453
        this.setLayout(layout);
454
        layout.setHorizontalGroup(
455
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
456
            .add(layout.createSequentialGroup()
457
                .addContainerGap()
458
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
459
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
460
                        .add(jLabelLoader, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 29, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
461
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
462
                        .add(jButtonAceptar)
463
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
464
                        .add(jButtonCancel))
465
                    .add(jLabelDescription, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 549, Short.MAX_VALUE)
466
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanelMain, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
467
                .addContainerGap())
468
        );
469
        layout.setVerticalGroup(
470
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
471
            .add(layout.createSequentialGroup()
472
                .addContainerGap()
473
                .add(jLabelDescription, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
474
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
475
                .add(jPanelMain, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
476
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
477
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
478
                    .add(jButtonCancel)
479
                    .add(jButtonAceptar)
480
                    .add(jLabelLoader, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 18, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
481
                .addContainerGap())
482
        );
483
    }// </editor-fold>//GEN-END:initComponents
484

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

  
496
private void jComboBoxExtGroupByFieldItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxExtGroupByFieldItemStateChanged
497
	if(evt.getStateChange() == ItemEvent.SELECTED) {
498
		this.selectedColumn = (String) jComboBoxExtGroupByField.getSelectedItem();
499
	}
500
}//GEN-LAST:event_jComboBoxExtGroupByFieldItemStateChanged
501

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

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

  
549
private void jButtonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAceptarActionPerformed
550
	//if a file has been allready selected...
551
	if(!jTextFieldExtFile.getText().equals("") && jTextFieldExtFile.getText().endsWith(".dbf")){
552

  
553
		loader = new SwingWorker() {
554
	        public Object construct() {
555
	           	jLabelLoader.setVisible(true);
556
	            return true;
557
	        }
558
	        public void finished() {
559
	        	jLabelLoader.setVisible(false);
560
	        }
561
	    };
562
	    loader.start();
563
	
564
	    //carga las operaciones escogidas por el usuario en las estructuras 
565
	    //ArrayList<String> headers, ArrayList<Integer> types y ArrayList<SelectedStatistics> operations
566
	    try {
567
	    	boolean flag = loadSelectedOperations(false);
568

  
569
	    	if(!flag) {
570
	    		JOptionPane.showMessageDialog(this, PluginServices.getText(this, "SummarizeForm_seleccionar_operaciones"));
571
	    	}
572
	    	else {
573
	    		File endFile = new File(jTextFieldExtFile.getText());
574
	    		if (endFile.exists()) {
575
	    			int returnValue = JOptionPane.showConfirmDialog(this,
576
	    					PluginServices.getText(this, "File_exists_Do_you_want_to_overwrite_it?"),
577
	    					PluginServices.getText(this, "Warning_Output_File"),
578
	    					JOptionPane.YES_NO_OPTION,
579
	    					JOptionPane.WARNING_MESSAGE);
580
	    			if (returnValue==JOptionPane.NO_OPTION) {
581
	    				return;
582
	    			}
583
	    			endFile.delete();
584
	    		}
585
	    		Summarize sumCalculator = new Summarize();
586
	    		sumCalculator.setDataSource(this.table.getModel().getModelo().getRecordset());
587
	    		sumCalculator.setGroupByField(selectedColumn);
588
	    		sumCalculator.setOperations(operations);
589
	    		sumCalculator.summarizeToDbf(endFile);
590
	    		createTableDocument(endFile.getName(), "gdbms dbf driver", endFile.getAbsolutePath());
591
	    		PluginServices.getMDIManager().closeWindow(this);
592
	    	}
593
	    }
594
	    catch (GroupByFieldNotExistsException e) {
595
	    	NotificationManager.showMessageError(
596
	    			PluginServices.getText(this, "Summarize_Group_by_field_does_not_exist"), e);
597
		} catch (ReadDriverException e) {
598
			NotificationManager.showMessageError(
599
					PluginServices.getText(this, "Summarize_Error_accessing_the_table"), e);
600
		} catch (DBFExportException e) {
601
			NotificationManager.showMessageError(
602
					PluginServices.getText(this, "Summarize_Error_saving_the_output_DBF_file"), e);
603
		} catch (GroupingErrorException e) {
604
			NotificationManager.showMessageError(
605
					PluginServices.getText(this, "Summarize_Error_calculating_the_groups"), e);
606
		} catch (FieldNotFoundException e) {
607
			NotificationManager.showMessageError(
608
	    			PluginServices.getText(this, "Summarize_Field_does_not_exist"), e);
609
		} catch (InitializationException e) {
610
			NotificationManager.showMessageError(e.getMessage(), e);
611
		} catch (SummarizeException e) {
612
			NotificationManager.showMessageError(
613
	    			PluginServices.getText(this, "Error_summarizing_table"), e);
614
		}
615
		
616
		loader.interrupt();	
617
	}else{
618
		JOptionPane.showMessageDialog(this, PluginServices.getText(this, "SummarizeForm_fichero_destino"));
619
	}
620
}//GEN-LAST:event_jButtonAceptarActionPerformed
621

  
622
private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
623
	PluginServices.getMDIManager().closeWindow(SummarizeForm.this);
624
}//GEN-LAST:event_jButtonCancelActionPerformed
625

  
626
/**
627
 * Loads the user chosen operations in these structures:
628
 * ArrayList<String> headers, ArrayList<Integer> types y ArrayList<SelectedStatistics> operations
629
 * Headers has the header names, types has the type of each field and operations has the selected statistics operations on every field.
630
 * @param flag
631
 * @return
632
 * @throws ReadDriverException 
633
 * @throws GroupByFieldNotExistsException 
634
 * @throws FieldNotFoundException 
635
 */
636
public boolean loadSelectedOperations(boolean flag) throws ReadDriverException, FieldNotFoundException{
637
	DataSource sds = table.getModel().getModelo().getRecordset();
638
	
639
	operations.clear();
640
	
641
	//recorremos la tabla para tomar los datos de las operaciones marcadas por el usuario 
642
	//y lo introducimos en la estructura SelectedStatistics.
643
	//Solo se introduciran filas si alguna de las operaciones de esa columna ha sido seleccionada (para evitar proceso porsterior en los bucles).
644
	for(int j=0; j<jXTableSeleccion.getRowCount(); j++){
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff