Revision 25826
tags/tmp_build/extensions/extNormalization/build.xml | ||
---|---|---|
1 |
<project name="extGeocoding" default="generate-without-source" basedir="."> |
|
2 |
<description> |
|
3 |
Install the Normalization plugin |
|
4 |
</description> |
|
5 |
|
|
6 |
<!-- set global properties for this build --> |
|
7 |
<property name="src" location="src" /> |
|
8 |
<property name="src-test" location="src-test" /> |
|
9 |
<property name="build-test" location="bin-test" /> |
|
10 |
<property name="build" location="bin" /> |
|
11 |
<property name="dist" location="dist" /> |
|
12 |
<property name="plugin" value="org.gvsig.normalization" /> |
|
13 |
<property name="extension-dir" location="../_fwAndami/gvSIG/extensiones" /> |
|
14 |
<import file="../binaries/ant/utilities.xml" /> |
|
15 |
|
|
16 |
<target name="init"> |
|
17 |
<!-- Create the time stamp --> |
|
18 |
<tstamp /> |
|
19 |
<echo>Compiling ${ant.project.name}...</echo> |
|
20 |
<buildnumber /> |
|
21 |
</target> |
|
22 |
|
|
23 |
<target name="generate-without-source" description="generate the distribution without the source file" > |
|
24 |
|
|
25 |
<!-- Create the distribution directory --> |
|
26 |
<mkdir dir="${dist}" /> |
|
27 |
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file --> |
|
28 |
<jar jarfile="${dist}/${plugin}.jar" basedir="${build}" /> |
|
29 |
<copy file="config/config.xml" todir="${dist}" /> |
|
30 |
<copy todir="${dist}"> |
|
31 |
<fileset dir="config" includes="text*.properties" /> |
|
32 |
<fileset dir="lib" includes="**/**" /> |
|
33 |
</copy> |
|
34 |
<copy todir="${dist}/images"> |
|
35 |
<fileset dir="images/" includes="*" /> |
|
36 |
</copy> |
|
37 |
<move todir="${extension-dir}/${plugin}/"> |
|
38 |
<fileset dir="${dist}" includes="**/**" /> |
|
39 |
</move> |
|
40 |
</target> |
|
41 |
|
|
42 |
|
|
43 |
<target name="compile" description="compile the source"> |
|
44 |
<!-- Compile the Java code from ${src} to ${build} --> |
|
45 |
<!-- <antcall target="gvSIG-import-build-number"/> --> |
|
46 |
<mkdir dir="${build}" /> |
|
47 |
<loadEclipseClasspath project="${basedir}" /> |
|
48 |
<gvSIG-javac classpath="${eclipseClasspath}" /> |
|
49 |
</target> |
|
50 |
|
|
51 |
<target name="create-jar" description="Creates the plugin jar"> |
|
52 |
<mkdir dir="${dist}" /> |
|
53 |
<jar jarfile="${dist}/${jarName}" basedir="${build}" /> |
|
54 |
</target> |
|
55 |
|
|
56 |
<target name="copy-data-files"> |
|
57 |
<copy file="config/config.xml" todir="${dist}" /> |
|
58 |
<copy file="build.number" todir="${dist}" /> |
|
59 |
<copy todir="${dist}"> |
|
60 |
<fileset dir="config" includes="text*.properties" /> |
|
61 |
</copy> |
|
62 |
<copy todir="${dist}/images"> |
|
63 |
<fileset dir="images/" includes="*" /> |
|
64 |
</copy> |
|
65 |
</target> |
|
66 |
|
|
67 |
<target name="move-to-installDir"> |
|
68 |
<move todir="${installDir}"> |
|
69 |
<fileset dir="${dist}" includes="**/**" /> |
|
70 |
</move> |
|
71 |
</target> |
|
72 |
|
|
73 |
<target name="batch-build" description="compile the sources, create the jar file" depends="init,compile,create-jar,copy-data-files,move-to-installDir"> |
|
74 |
</target> |
|
75 |
|
|
76 |
<target name="install" description="compile the sources, create the jar file" depends="init,create-jar,copy-data-files,move-to-installDir"> |
|
77 |
</target> |
|
78 |
|
|
79 |
|
|
80 |
</project> |
tags/tmp_build/extensions/extNormalization/.classpath | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<classpath> |
|
3 |
<classpathentry kind="src" path="src"/> |
|
4 |
<classpathentry kind="src" path="src-test"/> |
|
5 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> |
|
6 |
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/> |
|
7 |
<classpathentry kind="lib" path="/_fwAndami/lib/gvsig-i18n.jar" sourcepath="/libInternationalization/src"/> |
|
8 |
<classpathentry kind="lib" path="/_fwAndami/lib/iver-utiles.jar" sourcepath="/libIverUtiles"/> |
|
9 |
<classpathentry kind="lib" path="/_fwAndami/lib/log4j-1.2.8.jar"/> |
|
10 |
<classpathentry kind="lib" path="/_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/lib/com.iver.cit.gvsig.jar"/> |
|
11 |
<classpathentry kind="lib" path="/_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/lib/driver-manager-1.1.jar"/> |
|
12 |
<classpathentry kind="lib" path="/_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/lib/fmap.jar"/> |
|
13 |
<classpathentry kind="lib" path="/_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/lib/org.cresques.cts.jar"/> |
|
14 |
<classpathentry kind="lib" path="/_fwAndami/andami.jar"/> |
|
15 |
<classpathentry kind="lib" path="/_fwAndami/lib/org.gvsig.exceptions.jar" sourcepath="/libExceptions"/> |
|
16 |
<classpathentry kind="lib" path="/_fwAndami/lib/org.gvsig.ui.jar" sourcepath="/libUIComponent/src"/> |
|
17 |
<classpathentry kind="lib" path="lib/org.gvsig.tools.storage.jar" sourcepath="/libStorage"/> |
|
18 |
<classpathentry combineaccessrules="false" kind="src" path="/libGeocoding"/> |
|
19 |
<classpathentry kind="lib" path="/_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/lib/gdbms-0.8-SNAPSHOT.jar"/> |
|
20 |
<classpathentry kind="output" path="bin"/> |
|
21 |
</classpath> |
tags/tmp_build/extensions/extNormalization/.project | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<projectDescription> |
|
3 |
<name>extNormalization</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/extNormalization/config/config.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<plugin-config> |
|
3 |
<libraries library-dir="." /> |
|
4 |
<depends plugin-name="com.iver.cit.gvsig" /> |
|
5 |
<depends plugin-name="com.iver.cit.gvsig.cad" /> |
|
6 |
<depends plugin-name="org.gvsig.scripting" /> |
|
7 |
<resourceBundle name="text" /> |
|
8 |
<extensions> |
|
9 |
|
|
10 |
<extension |
|
11 |
class-name="org.gvsig.normalization.extensions.NormalizationExtension" |
|
12 |
description="Extension for the preferences of Normalization." |
|
13 |
active="true"> |
|
14 |
</extension> |
|
15 |
<extension |
|
16 |
class-name="org.gvsig.normalization.extensions.NormalizationFileExtension" |
|
17 |
description="Extension that normalize a file with strings." |
|
18 |
active="true"> |
|
19 |
<menu text="Tabla/normalizefile" tooltip="normalizefile" |
|
20 |
action-command="NORMALIZE_FILE" icon="images/normalizefileicon.png" |
|
21 |
position="9997" /> |
|
22 |
<!-- |
|
23 |
<tool-bar name="field_toolbar"> |
|
24 |
<action-tool icon="images/normalizefileicon.png" |
|
25 |
action-command="NORMALIZE_FILE" tooltip="normalizefile" |
|
26 |
position="9997" /> |
|
27 |
</tool-bar> |
|
28 |
--> |
|
29 |
</extension> |
|
30 |
<extension |
|
31 |
class-name="org.gvsig.normalization.extensions.NormalizationTableExtension" |
|
32 |
description="Extension that normalize a table field with strings." |
|
33 |
active="true"> |
|
34 |
<menu text="Tabla/normalizetable" tooltip="normalizetable" |
|
35 |
action-command="NORMALIZE_TABLE" |
|
36 |
icon="images/normalizetableicon.png" position="9998" /> |
|
37 |
<tool-bar name="field_toolbar"> |
|
38 |
<action-tool icon="images/normalizetableicon.png" |
|
39 |
action-command="NORMALIZE_TABLE" tooltip="normalizetable" |
|
40 |
position="9998" /> |
|
41 |
</tool-bar> |
|
42 |
</extension> |
|
43 |
<!-- |
|
44 |
<extension class-name="org.gvsig.geocoding.extension.AboutGeocodingExtension" |
|
45 |
description="Extension to add about panel." |
|
46 |
active="false" |
|
47 |
priority="1"> |
|
48 |
</extension> |
|
49 |
--> |
|
50 |
</extensions> |
|
51 |
</plugin-config> |
tags/tmp_build/extensions/extNormalization/config/text.properties | ||
---|---|---|
1 |
#Extension |
|
2 |
|
|
3 |
#Normalization |
|
4 |
#Normalization |
|
5 |
#Normalization |
|
6 |
|
|
7 |
#labels |
|
8 |
normalize=Normalizaci?n |
|
9 |
normalizefile=Normalizar fichero de texto |
|
10 |
normalizetable=Normalizar un campo de tabla |
|
11 |
|
|
12 |
normtitle=Normalizaci?n de |
|
13 |
|
|
14 |
normsource=Fuente de datos |
|
15 |
normfirstrows=No normalizar las primeras |
|
16 |
normfirstnumberrows=filas |
|
17 |
normfields=Nuevos campos |
|
18 |
normfieldsettings=Configuraci?n del nuevo campo |
|
19 |
normfieldname=Nombre nuevo campo |
|
20 |
normdontimport=No importar |
|
21 |
normfieldtype=Tipo de campo |
|
22 |
normfielddecimal=Decimal |
|
23 |
normfieldinteger=Integer |
|
24 |
normfieldstring=String |
|
25 |
normfielddate=Date |
|
26 |
normdelimetersnext=Separadores con el siguiente |
|
27 |
normcharacter=Car?cter |
|
28 |
normfixedwidth=Ancho fijo |
|
29 |
normfieldseparators=Separadores |
|
30 |
normtab=Tab |
|
31 |
normspace=Espacio |
|
32 |
normcolon=Coma |
|
33 |
normsemicolon=Punto y coma |
|
34 |
normother=Otros |
|
35 |
normjoin=Unir delimitadores consecutivos |
|
36 |
norminfieldseparators=Identificador |
|
37 |
normdecimal=Decimal |
|
38 |
normthousand=Miles |
|
39 |
normtextdelimiter=Texto |
|
40 |
normsampleout=Muestra de salida |
|
41 |
normoutputopt=Opciones de salida |
|
42 |
normaltertable=En la tabla actual |
|
43 |
normnewtable=En una nueva tabla |
|
44 |
normjoinfield=Campo com?n |
|
45 |
normconsole=C?nsola de informaci?n |
|
46 |
|
|
47 |
#buttons |
|
48 |
normload=Cargar... |
|
49 |
normsave=Guardar... |
|
50 |
normcancel=Salir |
|
51 |
normrun=Ejecutar |
|
52 |
normtest=Testear |
|
53 |
|
|
54 |
|
|
55 |
save_norm_pattern=Guardar patr?n de normalizaci?n |
|
56 |
load_norm_pattern=Cargar el patr?n de normalizaci?n |
|
57 |
normerrorloadingfile= Error cargando el archivo |
|
58 |
normerrorreadingfile= Error leyendo el archivo |
|
59 |
load_text_file=Cargar fichero de texto |
|
60 |
txt_file=Fichero de texto (*.txt, *.csv) |
|
61 |
pattern_norm_file=Fichero Patr?n Normalizaci?n (*.xml) |
|
62 |
|
|
63 |
|
|
64 |
Normalizating= Normalizando ... |
|
65 |
generate_news_fields= Generando los nuevos campos |
|
66 |
cant_alter_table=Tabla no editable |
|
67 |
already_exists_fields=Algunos de los nuevos campos ya existen en la tabla original |
|
68 |
chains_normalizated= cadenas normalizadas |
|
69 |
new_table=Nueva tabla |
|
70 |
nofield=Selecciona un campo de la tabla |
|
71 |
|
|
72 |
none_field=Ning?n campo |
|
73 |
all_fields=Todos los campos |
|
74 |
|
|
75 |
gdbmsdbfdriver=Driver dbf |
|
76 |
|
|
77 |
file_exists=El fichero ya existe, ?desea sobreexcribirlo? |
|
78 |
filenotfound=Fichero no se ha encontrado |
|
79 |
parsingpatternxml=Leyendo el patr?n de normalizaci?n |
|
80 |
loadsuccess=cargado correctamente |
|
81 |
savesuccess=guardado correctamente |
|
82 |
savingpat=Guardando el patr?n de normalizaci?n |
|
83 |
fileexists= El fichero ya existe, proceso de normalizaci?n cancelado |
|
84 |
finishprocess=Proceso de normalizaci?n terminado |
|
85 |
filenotsave=El fichero no se ha guardado |
|
86 |
filenotoverwrite=El fichero no se ha sobreescrito |
|
87 |
startprocess=Empieza la normalizaci?n... |
|
88 |
|
|
89 |
errorformattingdate=Formateando la fecha |
|
90 |
errorformattingnumberrow=Formateando un n?mero en la fila |
|
91 |
errorformattingdaterow=Formateando la fecha en la fila |
|
92 |
errorformattingintegerrow=Formateando un entero en la fila |
|
93 |
errorformattingdecimalrow=Formateando un decimal en la fila |
|
94 |
errorformattingstringrow=Formateando una cadena de texto en la fila |
|
95 |
errornullsubstring=Subcadena nula reemplazada por blanco en la fila |
|
96 |
errornotselectedfield=No hay un campo seleccionado en la tabla |
|
97 |
errordoubledname=Hay campos con el mismo nombre en la tabla |
|
98 |
errormodifyoritable=Modificando la tabla principal |
|
99 |
erroraddfieldstable=A?adiendo nuevos campos a la tabla principal |
|
100 |
errortabledontaltered=Tabla no modificada |
|
101 |
normalizing=Normalizando ... |
|
102 |
endnormalizing=Fin del proceso de normalizacion |
|
103 |
writtingdbf=Escribiendo fichero dbf ... |
|
104 |
|
|
105 |
noload=Cancelada la carga del patr?n |
|
106 |
nosave=Cancelado el guardado del patr?n |
|
107 |
|
|
108 |
pref_title_folder=Carpeta para almacenar patrones de normalizaci?n |
|
109 |
pref_change_folder=Cambiar carpeta |
|
110 |
pref_dialog_forder=Indicar carpeta para ubicar patrones |
|
111 |
pref_normalization=Normalizaci?n |
|
112 |
pref_path_folder=Ubicaci?n de la carpeta |
|
113 |
|
tags/tmp_build/extensions/extNormalization/config/text_en.properties | ||
---|---|---|
1 |
#Extension |
|
2 |
|
|
3 |
#Normalization |
|
4 |
#Normalization |
|
5 |
|
|
6 |
#labels |
|
7 |
normalize=Normalization |
|
8 |
normalizefile= |
|
9 |
normalizetable= |
|
10 |
|
|
11 |
normtitle=Normalizaci?n de |
|
12 |
|
|
13 |
normsource=Data source |
|
14 |
normfirstrows=Don`t normalize the first |
|
15 |
normfirstnumberrows=rows |
|
16 |
normfields=New fields |
|
17 |
normfieldsettings=Field settings |
|
18 |
normfieldname=Field name |
|
19 |
normdontimport=Don`t import |
|
20 |
normfieldtype=Field type |
|
21 |
normfielddecimal=Decimal |
|
22 |
normfieldinteger=Integer |
|
23 |
normfieldstring=String |
|
24 |
normfielddate=Date |
|
25 |
normdelimetersnext=Set how field delimiters with next one |
|
26 |
normfixedwidth=Fixed width |
|
27 |
normcharacter=Character |
|
28 |
normfieldseparators=Select field separators |
|
29 |
normtab=Tab |
|
30 |
normspace=Space |
|
31 |
normcolon=Colon |
|
32 |
normsemicolon=Semicolon |
|
33 |
normother=Other |
|
34 |
normjoin=Join consecutive delimiters |
|
35 |
norminfieldseparators=Identificator |
|
36 |
normdecimal=Decimal |
|
37 |
normthousand=Thousand |
|
38 |
normtextdelimiter=Text |
|
39 |
normsampleout=Sample output |
|
40 |
normoutputopt=Output options |
|
41 |
normaltertable=Alter table |
|
42 |
normnewtable=Create new table |
|
43 |
normjoinfield=Select join field |
|
44 |
normconsole=Info console |
|
45 |
|
|
46 |
#buttons |
|
47 |
normload=Load... |
|
48 |
normsave=Save... |
|
49 |
normcancel=Exit |
|
50 |
normrun=Run |
|
51 |
normtest=Test |
|
52 |
|
|
53 |
|
|
54 |
normerrorloadingfile= Error loading file |
|
55 |
normerrorreadingfile= Error reading file |
|
56 |
load_text_file=Load text file |
|
57 |
txt_file=Text File (*.txt, *.csv) |
|
58 |
pattern_norm_file=Normalization Pattern File (*.xml) |
|
59 |
save_norm_pattern=Save Normalization Pattern |
|
60 |
load_norm_pattern=Load Normalization Pattern |
|
61 |
|
|
62 |
Normalizating= Normalizating ... |
|
63 |
|
|
64 |
generate_news_fields= Generating new fields |
|
65 |
cant_alter_table=Can`t alter this table |
|
66 |
already_exists_fields=Some new fields already exist in the original table |
|
67 |
chains_normalizated= chains normalizated |
|
68 |
new_table=New table |
|
69 |
nofield=Select a table field |
|
70 |
|
|
71 |
|
|
72 |
preference_file=Address Elements |
|
73 |
preference_location=File location |
|
74 |
preference_edit=You can edit the list with new address elements |
|
75 |
|
|
76 |
nolayersinview=No layer in view |
|
77 |
combodefaulttext=... |
|
78 |
combonamefields=Fields Names |
|
79 |
comboaddresselements=Address Elements |
|
80 |
|
|
81 |
none_field=None fields |
|
82 |
all_fields=All fields |
|
83 |
|
|
84 |
gdbmsdbfdriver=Driver dbf |
|
85 |
|
|
86 |
file_exists=file already exists, you wish to overwrite it? |
|
87 |
filenotfound=File not found |
|
88 |
parsingpatternxml=Reading the pattern |
|
89 |
loadsuccess= loaded |
|
90 |
savesuccess= saved |
|
91 |
savingpat=Saving the pattern |
|
92 |
fileexists= File exists, process canceled |
|
93 |
finishprocess=Process finished |
|
94 |
filenotsave=File don't save |
|
95 |
filenotoverwrite=File don't overwrite |
|
96 |
startprocess=Start normalization... |
|
97 |
|
|
98 |
errorformattingdate=Formatting the date |
|
99 |
errorformattingnumberrow=Formatting the number in the row |
|
100 |
errorformattingdaterow=Formatting the date in the row |
|
101 |
errorformattingintegerrow=Formatting the integer in the row |
|
102 |
errorformattingdecimalrow=Formatting the double in the row |
|
103 |
errorformattingstringrow=Formatting the string in the row |
|
104 |
errornullsubstring=Null substring replaced for white in the row |
|
105 |
errornotselectedfield=There isn`t field selected in the main table |
|
106 |
errordoubledname=There are fields with the name doubled in the main table |
|
107 |
errormodifyoritable=Altering original table |
|
108 |
erroraddfieldstable=Adding news fields main table |
|
109 |
errortabledontaltered=Table didn't alter |
|
110 |
normalizing=Normalizing ... |
|
111 |
endnormalizing= Normalization process ended |
|
112 |
writtingdbf=Writing dbf file ... |
|
113 |
|
|
114 |
noload=Loading pattern canceled |
|
115 |
nosave=Saving pattern canceled |
|
116 |
|
|
117 |
pref_title_folder=Normalization patterns folder path |
|
118 |
pref_change_folder=Change folder |
|
119 |
pref_dialog_forder=Select folder to store patterns |
|
120 |
pref_normalization=Normalization |
|
121 |
pref_path_folder=Folder path |
|
122 |
|
tags/tmp_build/extensions/extNormalization/build.number | ||
---|---|---|
1 |
#Build Number for ANT. Do not edit! |
|
2 |
#Thu Jun 19 14:52:24 CEST 2008 |
|
3 |
build.number=5 |
tags/tmp_build/extensions/extNormalization/src/org/gvsig/normalization/gui/NormalizationTask.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 Prodevelop S.L. main development |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.normalization.gui; |
|
29 |
|
|
30 |
import org.apache.log4j.Logger; |
|
31 |
import org.gvsig.normalization.operations.Normalization; |
|
32 |
|
|
33 |
import com.iver.andami.PluginServices; |
|
34 |
import com.iver.utiles.swing.threads.AbstractMonitorableTask; |
|
35 |
|
|
36 |
/** |
|
37 |
* Normalization task |
|
38 |
* |
|
39 |
* @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a> |
|
40 |
* @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a> |
|
41 |
*/ |
|
42 |
public class NormalizationTask extends AbstractMonitorableTask { |
|
43 |
|
|
44 |
@SuppressWarnings("unused") |
|
45 |
private static final Logger log = Logger.getLogger(NormalizationTask.class); |
|
46 |
|
|
47 |
private Normalization normalization; |
|
48 |
private long finalStep; |
|
49 |
|
|
50 |
/** |
|
51 |
* @param na |
|
52 |
* @param normPanelModel |
|
53 |
* panel model |
|
54 |
* |
|
55 |
*/ |
|
56 |
public NormalizationTask(Normalization na, INormPanelModel normPanelModel) { |
|
57 |
this.normalization = na; |
|
58 |
|
|
59 |
// configure task |
|
60 |
setInitialStep(0); |
|
61 |
setStatusMessage(PluginServices.getText(this, "Normalizating")); |
|
62 |
setDeterminatedProcess(true); |
|
63 |
|
|
64 |
finalStep = normalization.getEstimatedRowCount(); |
|
65 |
setFinalStep((int) finalStep); |
|
66 |
} |
|
67 |
|
|
68 |
/* |
|
69 |
* (non-Javadoc) |
|
70 |
* |
|
71 |
* @see com.iver.utiles.swing.threads.ITask#run() |
|
72 |
*/ |
|
73 |
public void run() throws Exception { |
|
74 |
String log = PluginServices.getText(this, "chains_normalizated"); |
|
75 |
int firstRow = normalization.getPattern().getNofirstrows() == 0 ? 1 |
|
76 |
: normalization.getPattern().getNofirstrows() + 1; |
|
77 |
|
|
78 |
for (int i = firstRow; i < finalStep + 1; i++) { |
|
79 |
if (!isCanceled()) { |
|
80 |
setCurrentStep(i); |
|
81 |
setNote(i + " " + log); |
|
82 |
normalization.fillRow(i - 1); |
|
83 |
} else { |
|
84 |
return; |
|
85 |
} |
|
86 |
} |
|
87 |
|
|
88 |
normalization.postProcess(); |
|
89 |
normalization.removeAllListeners(); |
|
90 |
|
|
91 |
} |
|
92 |
} |
tags/tmp_build/extensions/extNormalization/src/org/gvsig/normalization/gui/NormPanelModel.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 Prodevelop S.L. main development |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.normalization.gui; |
|
29 |
|
|
30 |
import java.awt.Component; |
|
31 |
import java.io.File; |
|
32 |
import java.io.FileNotFoundException; |
|
33 |
import java.io.FileReader; |
|
34 |
import java.io.FileWriter; |
|
35 |
import java.text.DecimalFormatSymbols; |
|
36 |
import java.util.ArrayList; |
|
37 |
import java.util.List; |
|
38 |
import java.util.Locale; |
|
39 |
|
|
40 |
import javax.swing.DefaultListModel; |
|
41 |
import javax.swing.JFileChooser; |
|
42 |
import javax.swing.JOptionPane; |
|
43 |
import javax.swing.event.ChangeListener; |
|
44 |
|
|
45 |
import org.apache.log4j.Logger; |
|
46 |
import org.gvsig.normalization.operations.JoinedTableNormalization; |
|
47 |
import org.gvsig.normalization.operations.NormAlgorithm; |
|
48 |
import org.gvsig.normalization.operations.Normalization; |
|
49 |
import org.gvsig.normalization.operations.NormalizationNewTable; |
|
50 |
import org.gvsig.normalization.operations.StringListNormalization; |
|
51 |
import org.gvsig.normalization.operations.TableNormalization; |
|
52 |
import org.gvsig.normalization.patterns.Element; |
|
53 |
import org.gvsig.normalization.patterns.Fieldseparator; |
|
54 |
import org.gvsig.normalization.patterns.Fieldtype; |
|
55 |
import org.gvsig.normalization.patterns.Infieldseparators; |
|
56 |
import org.gvsig.normalization.patterns.Patternnormalization; |
|
57 |
import org.gvsig.normalization.patterns.Stringvalue; |
|
58 |
import org.gvsig.tools.storage.IStorage; |
|
59 |
import org.gvsig.tools.storage.StorageXML; |
|
60 |
|
|
61 |
import sun.text.Normalizer; |
|
62 |
|
|
63 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
64 |
import com.hardcode.gdbms.engine.data.DataSource; |
|
65 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
|
66 |
import com.iver.andami.PluginServices; |
|
67 |
import com.iver.cit.gvsig.ProjectExtension; |
|
68 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
|
69 |
import com.iver.cit.gvsig.fmap.edition.EditableAdapter; |
|
70 |
import com.iver.cit.gvsig.fmap.edition.IEditableSource; |
|
71 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
|
72 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
|
73 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
|
74 |
import com.iver.cit.gvsig.project.Project; |
|
75 |
import com.iver.cit.gvsig.project.ProjectFactory; |
|
76 |
import com.iver.cit.gvsig.project.documents.ProjectDocumentFactory; |
|
77 |
import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
|
78 |
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory; |
|
79 |
import com.iver.cit.gvsig.project.documents.table.gui.Table; |
|
80 |
import com.iver.utiles.GenericFileFilter; |
|
81 |
import com.iver.utiles.XMLEntity; |
|
82 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
|
83 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
|
84 |
|
|
85 |
/** |
|
86 |
* Model of the Normalization panel |
|
87 |
* |
|
88 |
* @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a> |
|
89 |
* @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a> |
|
90 |
*/ |
|
91 |
|
|
92 |
public class NormPanelModel implements INormPanelModel { |
|
93 |
|
|
94 |
/* ATTRIBUTES */ |
|
95 |
|
|
96 |
private static final Logger log = PluginServices.getLogger(); |
|
97 |
|
|
98 |
private static final String ERROR = "ERROR: "; |
|
99 |
|
|
100 |
private static final String INFO = "INFO: "; |
|
101 |
|
|
102 |
private static StringBuffer infob = new StringBuffer(); |
|
103 |
|
|
104 |
private String fieldToNormalize; |
|
105 |
|
|
106 |
private String[] samples; |
|
107 |
|
|
108 |
private Patternnormalization pattern; |
|
109 |
|
|
110 |
private Table tab; |
|
111 |
|
|
112 |
private boolean inNewTable; |
|
113 |
|
|
114 |
private int selectedFieldInList = 0; |
|
115 |
|
|
116 |
private int contador = 1; |
|
117 |
|
|
118 |
private String[] relateNames; |
|
119 |
|
|
120 |
private ArrayList<String> fileChains; |
|
121 |
|
|
122 |
private boolean isFile; |
|
123 |
|
|
124 |
private String nameFile; |
|
125 |
|
|
126 |
/* SINGLETON DEFINITION */ |
|
127 |
private volatile static INormPanelModel uniqueInstance; |
|
128 |
|
|
129 |
/** |
|
130 |
* Get the instance of panel model |
|
131 |
* |
|
132 |
* @return panel model |
|
133 |
*/ |
|
134 |
public static INormPanelModel getInstance() { |
|
135 |
if (uniqueInstance == null) { |
|
136 |
synchronized (NormPanelModel.class) { |
|
137 |
if (uniqueInstance == null) { |
|
138 |
uniqueInstance = new NormPanelModel(); |
|
139 |
} |
|
140 |
} |
|
141 |
} |
|
142 |
return uniqueInstance; |
|
143 |
} |
|
144 |
|
|
145 |
/* BUILDERS */ |
|
146 |
|
|
147 |
private NormPanelModel() { |
|
148 |
initPattern(); |
|
149 |
} |
|
150 |
|
|
151 |
// Constructors prior to the singleton pattern adoption |
|
152 |
|
|
153 |
// private NormPanelModel(Table tab2) { |
|
154 |
// this(); |
|
155 |
// isFile = false; |
|
156 |
// /* Table */ |
|
157 |
// this.tab = tab2; |
|
158 |
// } |
|
159 |
// |
|
160 |
// private NormPanelModel(ArrayList<String> arr, String _nameFile) { |
|
161 |
// this(); |
|
162 |
// isFile = true; |
|
163 |
// /* all strings from file */ |
|
164 |
// fileChains = arr; |
|
165 |
// /* file name */ |
|
166 |
// nameFile = _nameFile; |
|
167 |
// /* Samples of strings */ |
|
168 |
// getSamplesFromFile(); |
|
169 |
// } |
|
170 |
|
|
171 |
/* METHODS */ |
|
172 |
|
|
173 |
/** |
|
174 |
* This method fills the GUI sample table with the samples |
|
175 |
* |
|
176 |
* @return Object[][] |
|
177 |
*/ |
|
178 |
@SuppressWarnings("unchecked") |
|
179 |
public Object[][] normalizeSamples() { |
|
180 |
|
|
181 |
int numFields = pattern.getElements().size(); |
|
182 |
Object[][] results = new Object[NormalizationPanel.SAMPLES][numFields]; |
|
183 |
|
|
184 |
NormAlgorithm na = new NormAlgorithm(this.pattern); |
|
185 |
List<String> chains; |
|
186 |
for (int i = 0; i < NormalizationPanel.SAMPLES; i++) { |
|
187 |
chains = na.splitChain(samples[i]); |
|
188 |
numFields = chains.size(); |
|
189 |
for (int j = 0; j < numFields; j++) { |
|
190 |
results[i][j] = chains.get(j); |
|
191 |
} |
|
192 |
} |
|
193 |
return results; |
|
194 |
} |
|
195 |
|
|
196 |
/** |
|
197 |
* This method updates the model of the names FieldList |
|
198 |
* |
|
199 |
* @return list model |
|
200 |
*/ |
|
201 |
public DefaultListModel updateListModel() { |
|
202 |
|
|
203 |
DefaultListModel dlmodel = new DefaultListModel(); |
|
204 |
Element[] adr = this.pattern.getArrayElements(); |
|
205 |
String name = ""; |
|
206 |
for (int i = 0; i < adr.length; i++) { |
|
207 |
name = adr[i].getFieldname(); |
|
208 |
dlmodel.add(i, name); |
|
209 |
} |
|
210 |
return dlmodel; |
|
211 |
} |
|
212 |
|
|
213 |
/** |
|
214 |
* Run the process of normalization |
|
215 |
* |
|
216 |
* @return process ok |
|
217 |
*/ |
|
218 |
public boolean runModel(ChangeListener listener) { |
|
219 |
|
|
220 |
Normalization normAction = null; |
|
221 |
// REQUEST FILE TO OUPUT THE DBF |
|
222 |
File thefile = null; |
|
223 |
if (this.isFile || (!this.isFile && this.inNewTable)) { |
|
224 |
thefile = getDBFFile(); |
|
225 |
if (thefile == null) { |
|
226 |
addInfo(INFO + PluginServices.getText(null, "endnormalizing") |
|
227 |
+ " \n"); |
|
228 |
return false; |
|
229 |
} |
|
230 |
if (thefile.exists()) { |
|
231 |
addInfo(ERROR + PluginServices.getText(null, "fileexists") |
|
232 |
+ " \n"); |
|
233 |
addInfo(INFO + PluginServices.getText(null, "endnormalizing") |
|
234 |
+ " \n"); |
|
235 |
return false; |
|
236 |
} |
|
237 |
} |
|
238 |
|
|
239 |
// FILE NORMALIZATION |
|
240 |
if (this.isFile) { |
|
241 |
normAction = new StringListNormalization(pattern, fileChains, |
|
242 |
thefile); |
|
243 |
} else { |
|
244 |
IEditableSource source = tab.getModel().getModelo(); |
|
245 |
int index = tab.getSelectedFieldIndices().nextSetBit(0); |
|
246 |
|
|
247 |
if (!this.inNewTable) { |
|
248 |
// ONE TALBE |
|
249 |
log.debug("New fields in the original table"); |
|
250 |
normAction = new TableNormalization(source, index, pattern); |
|
251 |
} else { |
|
252 |
// JOINED TABLE |
|
253 |
normAction = new JoinedTableNormalization(source, index, |
|
254 |
pattern, relateNames, thefile); |
|
255 |
} |
|
256 |
} |
|
257 |
|
|
258 |
normAction.registerListener(listener); |
|
259 |
boolean pre = normAction.preProcess(); |
|
260 |
|
|
261 |
if (pre) { |
|
262 |
PluginServices.cancelableBackgroundExecution(new NormalizationTask( |
|
263 |
normAction, this)); |
|
264 |
} else { |
|
265 |
log.error("Error preprocessing tables"); |
|
266 |
return false; |
|
267 |
} |
|
268 |
|
|
269 |
if (normAction instanceof NormalizationNewTable) { |
|
270 |
NormalizationNewTable normTable = (NormalizationNewTable) normAction; |
|
271 |
this.loadTable(normTable); |
|
272 |
} |
|
273 |
|
|
274 |
return true; |
|
275 |
} |
|
276 |
|
|
277 |
/** |
|
278 |
* This method up the selected element one position in the list of Elements |
|
279 |
* |
|
280 |
* @param pos |
|
281 |
*/ |
|
282 |
public void fieldUp(int pos) { |
|
283 |
|
|
284 |
int nu = pattern.getElements().size(); |
|
285 |
|
|
286 |
if (pos > 0 && nu > 1) { |
|
287 |
int newpos = pos - 1; |
|
288 |
Element[] ad = pattern.getArrayElements(); |
|
289 |
Element ele21 = ad[pos]; |
|
290 |
Element ele12 = ad[newpos]; |
|
291 |
|
|
292 |
ad[newpos] = ele21; |
|
293 |
ad[pos] = ele12; |
|
294 |
List<Element> elems = new ArrayList<Element>(); |
|
295 |
for (int i = 0; i < ad.length; i++) { |
|
296 |
elems.add(ad[i]); |
|
297 |
} |
|
298 |
|
|
299 |
pattern.setElements(elems); |
|
300 |
} |
|
301 |
} |
|
302 |
|
|
303 |
/** |
|
304 |
* This method down the selected element one position in the list of |
|
305 |
* Elements |
|
306 |
* |
|
307 |
* @param pos |
|
308 |
*/ |
|
309 |
public void fieldDown(int pos) { |
|
310 |
int nu = pattern.getElements().size(); |
|
311 |
|
|
312 |
if (pos != (nu - 1) && nu > 1) { |
|
313 |
int newpos = pos + 1; |
|
314 |
Element[] ad = pattern.getArrayElements(); |
|
315 |
Element ele21 = ad[pos]; |
|
316 |
Element ele12 = ad[newpos]; |
|
317 |
|
|
318 |
ad[newpos] = ele21; |
|
319 |
ad[pos] = ele12; |
|
320 |
List<Element> elems = new ArrayList<Element>(); |
|
321 |
for (int i = 0; i < ad.length; i++) { |
|
322 |
elems.add(ad[i]); |
|
323 |
} |
|
324 |
|
|
325 |
pattern.setElements(elems); |
|
326 |
} |
|
327 |
} |
|
328 |
|
|
329 |
/** |
|
330 |
* This method adds a new element to the pattern |
|
331 |
*/ |
|
332 |
|
|
333 |
@SuppressWarnings("unchecked") |
|
334 |
public void addField() { |
|
335 |
|
|
336 |
contador++; |
|
337 |
int tam = pattern.getElements().size(); |
|
338 |
Element elem = new Element(); |
|
339 |
|
|
340 |
Fieldseparator fsep = new Fieldseparator(); |
|
341 |
fsep.setSemicolonsep(true); |
|
342 |
fsep.setJoinsep(false); |
|
343 |
fsep.setColonsep(false); |
|
344 |
fsep.setSpacesep(false); |
|
345 |
fsep.setTabsep(false); |
|
346 |
|
|
347 |
String nam = ""; |
|
348 |
boolean isOkName = true; |
|
349 |
do { |
|
350 |
isOkName = true; |
|
351 |
nam = "NewField" + contador; |
|
352 |
for (int i = 0; i < tam; i++) { |
|
353 |
String napat = ((Element) pattern.getElements().get(i)) |
|
354 |
.getFieldname(); |
|
355 |
if (napat.compareToIgnoreCase(nam) == 0) { |
|
356 |
isOkName = false; |
|
357 |
break; |
|
358 |
} |
|
359 |
} |
|
360 |
if (!isOkName) { |
|
361 |
contador++; |
|
362 |
} |
|
363 |
|
|
364 |
} while (!isOkName); |
|
365 |
|
|
366 |
// validate the new field name |
|
367 |
elem.setFieldname(validateFieldName(nam)); |
|
368 |
elem.setFieldseparator(fsep); |
|
369 |
elem.setInfieldseparators(getDefaultInfieldseparators()); |
|
370 |
elem.setFieldtype(getDefaultNewFieldType()); |
|
371 |
elem.setFieldwidth(0); |
|
372 |
elem.setImportfield(true); |
|
373 |
|
|
374 |
pattern.getElements().add(tam, elem); |
|
375 |
} |
|
376 |
|
|
377 |
/** |
|
378 |
* This method erases a selected element to the list |
|
379 |
* |
|
380 |
* @param pos |
|
381 |
* position |
|
382 |
*/ |
|
383 |
public void deleteField(int pos) { |
|
384 |
int conta = pattern.getElements().size(); |
|
385 |
if (conta > 1) { |
|
386 |
pattern.getElements().remove(pos); |
|
387 |
} |
|
388 |
} |
|
389 |
|
|
390 |
/** |
|
391 |
* This method saves a Normalization pattern to XML file * |
|
392 |
*/ |
|
393 |
public void savePatternXML() { |
|
394 |
|
|
395 |
JFileChooser jfc = new JFileChooser(); |
|
396 |
jfc.setDialogTitle(PluginServices.getText(this, "save_norm_pattern")); |
|
397 |
String[] extensions = { "xml" }; |
|
398 |
jfc.setCurrentDirectory(new File(getFolderPattern())); |
|
399 |
jfc.addChoosableFileFilter(new GenericFileFilter(extensions, |
|
400 |
PluginServices.getText(this, "pattern_norm_file"))); |
|
401 |
int returnval = jfc.showSaveDialog((Component) PluginServices |
|
402 |
.getMainFrame()); |
|
403 |
|
|
404 |
if (returnval == JFileChooser.APPROVE_OPTION) { |
|
405 |
File thefile = jfc.getSelectedFile(); |
|
406 |
// Check if the file has extension |
|
407 |
if (!(thefile.getPath().toLowerCase().endsWith(".xml"))) { |
|
408 |
thefile = new File(thefile.getPath() + ".xml"); |
|
409 |
} |
|
410 |
|
|
411 |
if (thefile.exists()) { |
|
412 |
|
|
413 |
int n = JOptionPane.showConfirmDialog(null, PluginServices |
|
414 |
.getText(null, "file_exists"), PluginServices.getText( |
|
415 |
null, "save_norm_pattern"), JOptionPane.YES_NO_OPTION); |
|
416 |
if (n == JOptionPane.YES_OPTION) { |
|
417 |
writeSaveFile(thefile); |
|
418 |
log.debug("overwrite file"); |
|
419 |
} else if (n == JOptionPane.NO_OPTION) { |
|
420 |
log.debug("Don't save the file"); |
|
421 |
addInfo(INFO |
|
422 |
+ PluginServices.getText(null, "filenotoverwrite") |
|
423 |
+ " \n"); |
|
424 |
} else { |
|
425 |
log.debug("Don't save the file"); |
|
426 |
addInfo(INFO + PluginServices.getText(null, "filenotsave") |
|
427 |
+ " \n"); |
|
428 |
} |
|
429 |
} else { |
|
430 |
writeSaveFile(thefile); |
|
431 |
} |
|
432 |
} else { |
|
433 |
addInfo(INFO + PluginServices.getText(null, "nosave") + " \n"); |
|
434 |
} |
|
435 |
} |
|
436 |
|
|
437 |
/** |
|
438 |
* This method loads a Normalization pattern from a XML file and return the |
|
439 |
* pattern and the String info |
|
440 |
* |
|
441 |
* @return pattern |
|
442 |
*/ |
|
443 |
public Patternnormalization loadPatternXML() { |
|
444 |
|
|
445 |
Patternnormalization pat = new Patternnormalization(); |
|
446 |
File thefile = null; |
|
447 |
StringBuffer infob = new StringBuffer(); |
|
448 |
|
|
449 |
// Show the FileChooser to select a pattern |
|
450 |
JFileChooser jfc = new JFileChooser(); |
|
451 |
jfc.setCurrentDirectory(new File(getFolderPattern())); |
|
452 |
jfc.setDialogTitle(PluginServices.getText(this, "load_norm_pattern")); |
|
453 |
String[] extensions = { "xml" }; |
|
454 |
jfc.addChoosableFileFilter(new GenericFileFilter(extensions, |
|
455 |
PluginServices.getText(this, "pattern_norm_file"))); |
|
456 |
|
|
457 |
int returnval = jfc.showOpenDialog((Component) PluginServices |
|
458 |
.getMainFrame()); |
|
459 |
|
|
460 |
if (returnval == JFileChooser.APPROVE_OPTION) { |
|
461 |
thefile = jfc.getSelectedFile(); |
|
462 |
log.debug("file to open: " + thefile); |
|
463 |
} else { |
|
464 |
addInfo(INFO + PluginServices.getText(null, "noload") + " \n"); |
|
465 |
return null; |
|
466 |
} |
|
467 |
FileReader red; |
|
468 |
IStorage storage; |
|
469 |
|
|
470 |
try { |
|
471 |
red = new FileReader(thefile); |
|
472 |
storage = new StorageXML(); |
|
473 |
storage.load(red); |
|
474 |
pat.setstate(storage); |
|
475 |
addInfo(INFO + thefile.getName() + " " |
|
476 |
+ PluginServices.getText(null, "loadsuccess") + " \n"); |
|
477 |
} catch (FileNotFoundException e) { |
|
478 |
pat = null; |
|
479 |
addInfo(ERROR + PluginServices.getText(null, "filenotfound") |
|
480 |
+ " \n"); |
|
481 |
log.error("File not found", e); |
|
482 |
} catch (Exception e) { |
|
483 |
pat = null; |
|
484 |
addInfo(ERROR + PluginServices.getText(null, "parsingpatternxml") |
|
485 |
+ " \n"); |
|
486 |
log.error("ERROR Parsing xml", e); |
|
487 |
} |
|
488 |
|
|
489 |
addInfo(infob.toString()); |
|
490 |
return pat; |
|
491 |
} |
|
492 |
|
|
493 |
/* GETTERS Y SETTERS */ |
|
494 |
|
|
495 |
/** |
|
496 |
* Return the name of the field to normalize |
|
497 |
* |
|
498 |
* @return field name |
|
499 |
*/ |
|
500 |
public String getFieldToNormalize() { |
|
501 |
return fieldToNormalize; |
|
502 |
} |
|
503 |
|
|
504 |
/** |
|
505 |
* Set the name of the field to normalize |
|
506 |
* |
|
507 |
* @param fieldToNormalize |
|
508 |
*/ |
|
509 |
public void setFieldToNormalize(String fieldToNormalize) { |
|
510 |
|
|
511 |
this.fieldToNormalize = fieldToNormalize; |
|
512 |
|
|
513 |
/* Get samples to put in the GUI table */ |
|
514 |
getSamplesFromTable(); |
|
515 |
} |
|
516 |
|
|
517 |
/** |
|
518 |
* This method returns the names of the fields from the pattern |
|
519 |
* |
|
520 |
* @return new fields names |
|
521 |
*/ |
|
522 |
public String[] getNewFieldNames() { |
|
523 |
|
|
524 |
int numFields = pattern.getElements().size(); |
|
525 |
String[] res = new String[numFields]; |
|
526 |
|
|
527 |
for (int i = 0; i < numFields; i++) { |
|
528 |
res[i] = ((Element) pattern.getElements().get(i)).getFieldname(); |
|
529 |
} |
|
530 |
return res; |
|
531 |
} |
|
532 |
|
|
533 |
/** |
|
534 |
* Get the first or random samples from data source (FILE) |
|
535 |
*/ |
|
536 |
public void getSamplesFromFile(int numNoRows) { |
|
537 |
|
|
538 |
int num = NormalizationPanel.SAMPLES; |
|
539 |
String[] res = new String[num]; |
|
540 |
for (int i = 0; i < num; i++) { |
|
541 |
try { |
|
542 |
res[i] = (String) fileChains.get(i + numNoRows); |
|
543 |
} catch (Exception e) { |
|
544 |
res[i] = ""; |
|
545 |
} |
|
546 |
} |
|
547 |
this.samples = res; |
|
548 |
} |
|
549 |
|
|
550 |
/** |
|
551 |
* Return the samples Table |
|
552 |
* |
|
553 |
* @return samples from table |
|
554 |
*/ |
|
555 |
public String[] getSamplesTable() { |
|
556 |
return samples; |
|
557 |
} |
|
558 |
|
|
559 |
/** |
|
560 |
* Return the samples File |
|
561 |
* |
|
562 |
* @return samples from file |
|
563 |
*/ |
|
564 |
public String[] getSamplesFile() { |
|
565 |
return samples; |
|
566 |
} |
|
567 |
|
|
568 |
/** |
|
569 |
* This method sets the original table to the model |
|
570 |
* |
|
571 |
* @param _table |
|
572 |
*/ |
|
573 |
public void setTable(Table _table) { |
|
574 |
tab = _table; |
|
575 |
} |
|
576 |
|
|
577 |
/** |
|
578 |
* This method says if the process will be in a new table (true) or in the |
|
579 |
* original table (false) |
|
580 |
* |
|
581 |
* @return |
|
582 |
*/ |
|
583 |
public boolean isInNewTable() { |
|
584 |
return inNewTable; |
|
585 |
} |
|
586 |
|
|
587 |
/** |
|
588 |
* Assign value the flag |
|
589 |
* |
|
590 |
* @param inNewTable |
|
591 |
*/ |
|
592 |
public void setInNewTable(boolean inNewTable) { |
|
593 |
this.inNewTable = inNewTable; |
|
594 |
} |
|
595 |
|
|
596 |
/** |
|
597 |
* This method returns a Element of one position |
|
598 |
* |
|
599 |
* @param index |
|
600 |
* @return |
|
601 |
*/ |
|
602 |
public Element getElement(int index) { |
|
603 |
Element[] adrs = pattern.getArrayElements(); |
|
604 |
return adrs[index]; |
|
605 |
} |
|
606 |
|
|
607 |
/** |
|
608 |
* This method gets the position of the selected element in the List of |
|
609 |
* names |
|
610 |
* |
|
611 |
* @return position in the list |
|
612 |
*/ |
|
613 |
public int getSelectedFieldInList() { |
|
614 |
return selectedFieldInList; |
|
615 |
} |
|
616 |
|
|
617 |
/** |
|
618 |
* This method set the position of the selected element in the List |
|
619 |
* |
|
620 |
* @param selectedFieldInList |
|
621 |
*/ |
|
622 |
public void setSelectedFieldInList(int selectedFieldInList) { |
|
623 |
this.selectedFieldInList = selectedFieldInList; |
|
624 |
} |
|
625 |
|
|
626 |
/** |
|
627 |
* This method returns the fields names of the original table |
|
628 |
* |
|
629 |
* @return list model |
|
630 |
*/ |
|
631 |
public DefaultListModel getAllOriginalFields() { |
|
632 |
|
|
633 |
FieldDescription[] fields = tab.getModel().getModelo() |
|
634 |
.getFieldsDescription(); |
|
635 |
int num = fields.length; |
|
636 |
String names = ""; |
|
637 |
DefaultListModel dlm = new DefaultListModel(); |
|
638 |
dlm.add(0, PluginServices.getText(this, "none_field")); |
|
639 |
dlm.add(1, PluginServices.getText(this, "all_fields")); |
|
640 |
for (int i = 0; i < num; i++) { |
|
641 |
names = fields[i].getFieldName(); |
|
642 |
dlm.addElement(names); |
|
643 |
} |
|
644 |
return dlm; |
|
645 |
} |
|
646 |
|
|
647 |
/** |
|
648 |
* This method generates and returns field separators |
|
649 |
* |
|
650 |
* @return default separators between fields |
|
651 |
*/ |
|
652 |
public Fieldseparator getDefaultFieldseparators() { |
|
653 |
|
|
654 |
Fieldseparator filsep = new Fieldseparator(); |
|
655 |
filsep.setSemicolonsep(true); |
|
656 |
filsep.setJoinsep(false); |
|
657 |
filsep.setColonsep(false); |
|
658 |
filsep.setSpacesep(false); |
|
659 |
filsep.setTabsep(false); |
|
660 |
|
|
661 |
return filsep; |
|
662 |
} |
|
663 |
|
|
664 |
/** |
|
665 |
* Set the names of the relate Fields |
|
666 |
* |
|
667 |
* @param list |
|
668 |
* of the names |
|
669 |
*/ |
|
670 |
|
|
671 |
public void setNameRelateFields(String[] names) { |
|
672 |
relateNames = names; |
|
673 |
} |
|
674 |
|
|
675 |
/** |
|
676 |
* This method returns the fields names of the original table |
|
677 |
* |
|
678 |
* @return fields names of the main table |
|
679 |
*/ |
|
680 |
public String[] getFieldNamesMainTable() { |
|
681 |
FieldDescription[] fds = tab.getModel().getModelo() |
|
682 |
.getFieldsDescription(); |
|
683 |
String[] na = new String[fds.length]; |
|
684 |
for (int i = 0; i < fds.length; i++) { |
|
685 |
na[i] = fds[i].getFieldName(); |
|
686 |
} |
|
687 |
return na; |
|
688 |
} |
|
689 |
|
|
690 |
/** |
|
691 |
* This method sets the pattern |
|
692 |
* |
|
693 |
* @pat pattern |
|
694 |
*/ |
|
695 |
public void setPattern(Patternnormalization pat) { |
|
696 |
pattern = pat; |
|
697 |
} |
|
698 |
|
|
699 |
/** |
|
700 |
* This method returns the debug info |
|
701 |
* |
|
702 |
* @return info about the process |
|
703 |
*/ |
|
704 |
public String getInfo() { |
|
705 |
return infob.toString(); |
|
706 |
} |
|
707 |
|
|
708 |
/** |
|
709 |
* This method adds info about the process |
|
710 |
* |
|
711 |
* @param chain |
|
712 |
* message |
|
713 |
*/ |
|
714 |
public void addInfo(String chain) { |
|
715 |
infob.append(chain); |
|
716 |
} |
|
717 |
|
|
718 |
/** |
|
719 |
* This method returns the File name to normalize |
|
720 |
* |
|
721 |
* @return file name |
|
722 |
*/ |
|
723 |
public String getFileName() { |
|
724 |
return nameFile; |
|
725 |
} |
|
726 |
|
|
727 |
/** |
|
728 |
* set the number of first rows that not normalize |
|
729 |
* |
|
730 |
* @param first |
|
731 |
* select the first row |
|
732 |
*/ |
|
733 |
public void setFirstRows(int first) { |
|
734 |
pattern.setNofirstrows(first); |
|
735 |
|
|
736 |
} |
|
737 |
|
|
738 |
/** |
|
739 |
* Set the table |
|
740 |
* |
|
741 |
* @param tab |
|
742 |
* the tab to set |
|
743 |
*/ |
|
744 |
public void setTab(Table tab) { |
|
745 |
this.tab = tab; |
|
746 |
} |
|
747 |
|
|
748 |
/** |
|
749 |
* Set the file strings |
|
750 |
* |
|
751 |
* @param fileChains |
|
752 |
* the fileChains to set |
|
753 |
*/ |
|
754 |
public void setFileChains(ArrayList<String> fileChains) { |
|
755 |
this.fileChains = fileChains; |
|
756 |
this.isFile = true; |
|
757 |
getSamplesFromFile(getFirstRows()); |
|
758 |
} |
|
759 |
|
|
760 |
/** |
|
761 |
* Get the file strings |
|
762 |
* |
|
763 |
* @return the file strings |
|
764 |
*/ |
|
765 |
public ArrayList<String> getFileChains() { |
|
766 |
return fileChains; |
|
767 |
} |
|
768 |
|
|
769 |
/** |
|
770 |
* Get the file name |
|
771 |
* |
|
772 |
* @return the nameFile |
|
773 |
*/ |
|
774 |
public String getNameFile() { |
|
775 |
return nameFile; |
|
776 |
} |
|
777 |
|
|
778 |
/** |
|
779 |
* Get the table |
|
780 |
* |
|
781 |
* @return the tab |
|
782 |
*/ |
|
783 |
public Table getTab() { |
|
784 |
return tab; |
|
785 |
} |
|
786 |
|
|
787 |
/** |
|
788 |
* Set the file name |
|
789 |
* |
|
790 |
* @param nameFile |
|
791 |
* the nameFile to set |
|
792 |
*/ |
|
793 |
public void setNameFile(String nameFile) { |
|
794 |
this.nameFile = nameFile; |
|
795 |
} |
|
796 |
|
|
797 |
/** |
|
798 |
* get Normalize the first row |
|
799 |
* |
|
800 |
* @return normalize first row |
|
801 |
*/ |
|
802 |
public int getFirstRows() { |
|
803 |
return pattern.getNofirstrows(); |
|
804 |
|
|
805 |
} |
|
806 |
|
|
807 |
/** |
|
808 |
* Set the file type |
|
809 |
* |
|
810 |
* @param file |
|
811 |
*/ |
|
812 |
public void isFile(boolean file) { |
|
813 |
this.isFile = file; |
|
814 |
} |
|
815 |
|
|
816 |
/** |
|
817 |
* This method cleans the information about the process |
|
818 |
*/ |
|
819 |
public void clearConsole() { |
|
820 |
int con = infob.length() > 0 ? infob.length() - 1 : 0; |
|
821 |
if (con > 0) { |
|
822 |
infob.delete(0, con); |
|
823 |
} |
|
824 |
} |
|
825 |
|
|
826 |
/** |
|
827 |
* This method creates the default Normalization pattern |
|
828 |
*/ |
|
829 |
public void initPattern() { |
|
830 |
|
|
831 |
Patternnormalization pat = new Patternnormalization(); |
|
832 |
|
|
833 |
pat.setPatternname("defaultPattern"); |
|
834 |
pat.setPatternurl("\\"); |
|
835 |
pat.setNofirstrows(0); |
|
836 |
|
|
837 |
/* Create the first Address Element */ |
|
838 |
Element elem = new Element(); |
|
839 |
|
|
840 |
elem.setFieldname("NewField"); |
|
841 |
elem.setFieldseparator(getDefaultFieldseparators()); |
|
842 |
elem.setInfieldseparators(getDefaultInfieldseparators()); |
|
843 |
elem.setFieldtype(getDefaultNewFieldType()); |
|
844 |
elem.setFieldwidth(0); |
|
845 |
elem.setImportfield(true); |
|
846 |
|
|
847 |
List<Element> elems = new ArrayList<Element>(); |
|
848 |
elems.add(elem); |
|
849 |
|
|
850 |
pat.setElements(elems); |
|
851 |
|
|
852 |
this.pattern = pat; |
|
853 |
} |
|
854 |
|
|
855 |
/* METHODS PRIVATES */ |
|
856 |
|
|
857 |
/** |
|
858 |
* This method loads the new table |
|
859 |
* |
|
860 |
* @param normTable |
|
861 |
*/ |
|
862 |
private void loadTable(NormalizationNewTable normTable) { |
|
863 |
String name = normTable.getOuputFile().getName(); |
|
864 |
|
|
865 |
LayerFactory.getDataSourceFactory().addDataSource( |
|
866 |
normTable.getDriver(), name); |
|
867 |
|
|
868 |
EditableAdapter editAdapterSecond = null; |
|
869 |
|
|
870 |
DataSource dtSecond; |
|
871 |
try { |
|
872 |
dtSecond = LayerFactory.getDataSourceFactory() |
|
873 |
.createRandomDataSource(name, |
|
874 |
DataSourceFactory.AUTOMATIC_OPENING); |
|
875 |
|
|
876 |
editAdapterSecond = new EditableAdapter(); |
Also available in: Unified diff