Revision 36974
tags/v2_0_0_Build_2038/extensions/org.gvsig.app.document.table.app/.project | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<projectDescription> |
|
3 |
<name>org.gvsig.app.document.table.app</name> |
|
4 |
<comment></comment> |
|
5 |
<projects> |
|
6 |
</projects> |
|
7 |
<buildSpec> |
|
8 |
</buildSpec> |
|
9 |
<natures> |
|
10 |
</natures> |
|
11 |
</projectDescription> |
tags/v2_0_0_Build_2038/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/distribution/distribution.xml | ||
---|---|---|
1 |
<assembly> |
|
2 |
<id>distribution</id> |
|
3 |
<formats> |
|
4 |
<format>dir</format> |
|
5 |
</formats> |
|
6 |
<fileSets> |
|
7 |
<!-- Estructure for the extension --> |
|
8 |
<fileSet> |
|
9 |
<directory>src/main/resources</directory> |
|
10 |
<outputDirectory>${extension.install.dir.name} |
|
11 |
</outputDirectory> |
|
12 |
</fileSet> |
|
13 |
</fileSets> |
|
14 |
<files> |
|
15 |
<file> |
|
16 |
<source>package.info</source> |
|
17 |
<outputDirectory>${extension.install.dir.name}</outputDirectory> |
|
18 |
</file> |
|
19 |
</files> |
|
20 |
<dependencySets> |
|
21 |
<dependencySet> |
|
22 |
<outputDirectory>${extension.install.dir.name}/${library-dir} |
|
23 |
</outputDirectory> |
|
24 |
<includes> |
|
25 |
<include>org.gvsig:org.gvsig.app.document.table.app.mainplugin</include> |
|
26 |
</includes> |
|
27 |
</dependencySet> |
|
28 |
</dependencySets> |
|
29 |
</assembly> |
tags/v2_0_0_Build_2038/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/buildNumber.properties | ||
---|---|---|
1 |
#maven.buildNumber.plugin properties file |
|
2 |
#Mon Oct 24 14:20:38 CEST 2011 |
|
3 |
buildNumber=4 |
tags/v2_0_0_Build_2038/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/test/resources/README.txt | ||
---|---|---|
1 |
Put into this folder the resources needed by your test classes. |
|
2 |
|
|
3 |
This folder is added to the Tests classpath, so you can load any resources |
|
4 |
through the ClassLoader. |
|
5 |
|
|
6 |
By default, in this folder you can find an example of log4j configuration, |
|
7 |
prepared to log messages through the console, so logging works when you |
|
8 |
run your tests classes. |
tags/v2_0_0_Build_2038/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/test/resources/log4j.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1" ?> |
|
2 |
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> |
|
3 |
|
|
4 |
<!-- |
|
5 |
Log4J configuration file for unit tests execution. |
|
6 |
--> |
|
7 |
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> |
|
8 |
|
|
9 |
<!-- Appender configuration to show logging messages through the console --> |
|
10 |
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> |
|
11 |
<layout class="org.apache.log4j.PatternLayout"> |
|
12 |
<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n %m%n" /> |
|
13 |
</layout> |
|
14 |
</appender> |
|
15 |
|
|
16 |
<!-- |
|
17 |
Activate logging messages of DEBUG level of higher only for the |
|
18 |
org.gvsig.tools packages. |
|
19 |
You can put full classes names or packages instead, to configure |
|
20 |
logging for all the classes and subpackages of the package. |
|
21 |
--> |
|
22 |
<category name="org.gvsig.tools"> |
|
23 |
<priority value="DEBUG" /> |
|
24 |
</category> |
|
25 |
<category name="org.gvsig.app.document.table"> |
|
26 |
<priority value="DEBUG" /> |
|
27 |
</category> |
|
28 |
|
|
29 |
<!-- |
|
30 |
By default, show only logging messages of INFO level or higher, |
|
31 |
through the previously configured CONSOLE appender. |
|
32 |
--> |
|
33 |
<root> |
|
34 |
<priority value="INFO" /> |
|
35 |
<appender-ref ref="CONSOLE" /> |
|
36 |
</root> |
|
37 |
</log4j:configuration> |
tags/v2_0_0_Build_2038/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/resources/config.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<plugin-config> |
|
3 |
<libraries library-dir="lib"/> |
|
4 |
<depends plugin-name="org.gvsig.app" /> |
|
5 |
<resourceBundle name="text"/> |
|
6 |
<extensions> |
|
7 |
<extension class-name="org.gvsig.app.extension.TableExtension" |
|
8 |
description="Extensi?n encargada de a?adir soporte a documentos tabla." |
|
9 |
active="true" |
|
10 |
priority="10"> |
|
11 |
|
|
12 |
<menu text="Tabla" |
|
13 |
position="400" |
|
14 |
is_separator="true"/> |
|
15 |
|
|
16 |
</extension> |
|
17 |
|
|
18 |
<extension class-name="org.gvsig.app.extension.ClearSelectionExtension" |
|
19 |
description="Extensi?n encargada de limpiar la selecci?n." |
|
20 |
active="true"> |
|
21 |
<menu text="Capa/clear_selection" position="35010" action-command="DEL_SELECTION" icon="view-clear-selection"/> |
|
22 |
<tool-bar name="Tools_Select" position="6"> |
|
23 |
<action-tool icon="view-clear-selection" action-command="DEL_SELECTION" tooltip="clear_selection" position="4"/> |
|
24 |
</tool-bar> |
|
25 |
</extension> |
|
26 |
|
|
27 |
<extension class-name="org.gvsig.app.extension.ShowTable" |
|
28 |
description="Extensi?n encargada de abrir la tabla asociada a la capa seleccionado." |
|
29 |
active="true"> |
|
30 |
<menu text="Capa/ver_tabla_atributos" position="35020" icon="layer-show-attribute-table"/> |
|
31 |
<tool-bar name="Acciones" position="13"> |
|
32 |
<action-tool icon="layer-show-attribute-table" |
|
33 |
enableText="Un_Layer" |
|
34 |
tooltip="Muestra_atributos" position="1"/> |
|
35 |
</tool-bar> |
|
36 |
</extension> |
|
37 |
|
|
38 |
<extension class-name="org.gvsig.app.extension.TableOperations" |
|
39 |
description="Extensi?n encargada de gestionar las operaciones sobre las tablas." |
|
40 |
active="true"> |
|
41 |
<menu text="Tabla/link" position="40010" icon="table-link" action-command="LINK"/> |
|
42 |
<tool-bar name="Herramientas" position="12"> |
|
43 |
<action-tool icon="table-link" action-command="LINK" tooltip="link" position="2"/> |
|
44 |
</tool-bar> |
|
45 |
</extension> |
|
46 |
|
|
47 |
<extension class-name="org.gvsig.app.extension.RedoTableExtension" |
|
48 |
description="Extensi?n encargada de rehacer la edici?n sobre la capa activa." |
|
49 |
active="true"> |
|
50 |
<menu text="Tabla/rehacer" position="40014" action-command="REDO" icon="table-redo"/> |
|
51 |
<tool-bar name="modificar" position="12"> |
|
52 |
<action-tool name="rehacer" icon="table-redo" action-command="REDO" tooltip="rehacer" group="tabla" position="2"/> |
|
53 |
</tool-bar> |
|
54 |
</extension> |
|
55 |
|
|
56 |
<extension class-name="org.gvsig.app.extension.UndoTableExtension" |
|
57 |
description="Extensi?n encargada de dehacer la edici?n sobre la capa activa." |
|
58 |
active="true"> |
|
59 |
<menu text="Tabla/deshacer" position="40016" action-command="UNDO" icon="table-undo"/> |
|
60 |
<tool-bar name="modificar" position="12"> |
|
61 |
<action-tool name="deshacer" icon="table-undo" action-command="UNDO" tooltip="deshacer" group="tabla" position="1"/> |
|
62 |
</tool-bar> |
|
63 |
</extension> |
|
64 |
|
|
65 |
<extension class-name="org.gvsig.app.extension.TableEditStopExtension" |
|
66 |
description="Extensi?n encargada de gestionar las operaciones de edici?n sobre las tablas." |
|
67 |
active="true"> |
|
68 |
<menu text="Tabla/stop_edition" position="40020" action-command="STOPEDITING"/> |
|
69 |
</extension> |
|
70 |
<extension class-name="org.gvsig.app.extension.TableEditStartExtension" |
|
71 |
description="Extensi?n encargada de gestionar las operaciones de edici?n sobre las tablas." |
|
72 |
active="true"> |
|
73 |
<menu text="Tabla/start_edition" position="40024" action-command="STARTEDIT"/> |
|
74 |
</extension> |
|
75 |
<extension class-name="org.gvsig.app.extension.TableEditInsertExtension" |
|
76 |
description="Extensi?n encargada de gestionar las operaciones de edici?n sobre las tablas." |
|
77 |
active="true"> |
|
78 |
<menu text="Tabla/insert_row" position="40026" action-command="INSERTROW"/> |
|
79 |
</extension> |
|
80 |
<extension class-name="org.gvsig.app.extension.TableEditRemoveRowExtension" |
|
81 |
description="Extensi?n encargada de gestionar las operaciones de edici?n sobre las tablas." |
|
82 |
active="true"> |
|
83 |
<menu text="Tabla/remove_row" position="40030" action-command="REMOVEROW"/> |
|
84 |
</extension> |
|
85 |
<extension class-name="org.gvsig.app.extension.TableEditChangeColumnsExtension" |
|
86 |
description="Extensi?n encargada de gestionar las operaciones de edici?n de columnas sobre las tablas." |
|
87 |
active="true"> |
|
88 |
<menu text="Tabla/add_column" position="40034" action-command="ADDCOLUMN"/> |
|
89 |
<menu text="Tabla/rename_column" position="40036" action-command="RENAMECOLUMN"/> |
|
90 |
<menu text="Tabla/remove_column" position="40040" action-command="REMOVECOLUMN"/> |
|
91 |
</extension> |
|
92 |
<extension class-name="org.gvsig.app.extension.TableEditAttributes" |
|
93 |
description="Extensi?n encargada de gestionar los campos de las tablas." |
|
94 |
active="true"> |
|
95 |
<menu text="Tabla/manage_fields" position="40044" action-command="MANAGE_FIELDS"/> |
|
96 |
</extension> |
|
97 |
|
|
98 |
<extension class-name="org.gvsig.app.extension.TableEditCopyExtension" |
|
99 |
description="Extensi?n encargada de gestionar las operaciones de edici?n sobre las tablas." |
|
100 |
active="true"> |
|
101 |
<menu text="Tabla/copy" position="40046" icon="edit-copy" action-command="COPY"/> |
|
102 |
</extension> |
|
103 |
|
|
104 |
<extension class-name="org.gvsig.app.extension.TableEditCutExtension" |
|
105 |
description="Extensi?n encargada de gestionar las operaciones de edici?n sobre las tablas." |
|
106 |
active="true"> |
|
107 |
<menu text="Tabla/cut" position="40050" icon="edit-cut" action-command="CUT"/> |
|
108 |
</extension> |
|
109 |
|
|
110 |
<extension class-name="org.gvsig.app.extension.TableEditPasteExtension" |
|
111 |
description="Extensi?n encargada de gestionar las operaciones de edici?n sobre las tablas." |
|
112 |
active="true"> |
|
113 |
<menu text="Tabla/paste" position="40054" icon="edit-paste" action-command="PASTE"/> |
|
114 |
</extension> |
|
115 |
|
|
116 |
<extension active="true" class-name="org.gvsig.app.extension.TableFieldOperations" |
|
117 |
description="Operaciones sobre los campos de las tablas"> |
|
118 |
<menu text="Tabla/ascending_order" position="40056" icon="table-order-asc" action-command="ORDERASC"/> |
|
119 |
<menu text="Tabla/descending_order" position="40060" icon="table-order-desc" action-command="ORDERDESC"/> |
|
120 |
<tool-bar name="Herramientas" position="12"> |
|
121 |
<action-tool icon="table-order-asc" tooltip="ascending_order_tooltip" action-command="ORDERASC" position="3"/> |
|
122 |
<action-tool icon="table-order-desc" tooltip="descending_order_tooltip" action-command="ORDERDESC" position="4"/> |
|
123 |
</tool-bar> |
|
124 |
</extension> |
|
125 |
|
|
126 |
<extension class-name="org.gvsig.app.extension.TableNumericFieldOperations" |
|
127 |
description="Extensi?n encargada de gestionar las operaciones sobre los campos num?ricos." |
|
128 |
active="true"> |
|
129 |
<menu text="Tabla/statistics" position="40064" icon="table-statistics"/> |
|
130 |
<tool-bar name="Herramientas" position="12"> |
|
131 |
<action-tool icon="table-statistics" tooltip="statistics" position="5"/> |
|
132 |
</tool-bar> |
|
133 |
</extension> |
|
134 |
|
|
135 |
<extension class-name="org.gvsig.app.extension.TableRowsOperations" |
|
136 |
description="Extensi?n encargada de gestionar la selecci?n en la tabla." |
|
137 |
active="true"> |
|
138 |
<menu text="Tabla/selection_up" position="40066" action-command="SELECTIONUP" icon="table-selection-up"/> |
|
139 |
<menu text="Tabla/invert_selection" position="40070" action-command="INVERTSELECTION" icon="table-invert"/> |
|
140 |
<tool-bar name="Herramientas" position="12"> |
|
141 |
<action-tool icon="table-selection-up" action-command="SELECTIONUP" tooltip="selection_up" position="6"/> |
|
142 |
<action-tool icon="table-invert" action-command="INVERTSELECTION" tooltip="invert_selection" position="7"/> |
|
143 |
</tool-bar> |
|
144 |
</extension> |
|
145 |
|
|
146 |
<extension class-name="org.gvsig.app.extension.RemoveTableLink" |
|
147 |
description="Extensi?n encargada de quitar los enlaces de las tablas." |
|
148 |
active="true"> |
|
149 |
<menu text="Tabla/quitar_enlaces" position="40076" /> |
|
150 |
</extension> |
|
151 |
|
|
152 |
<extension class-name="org.gvsig.app.extension.PrintTable" |
|
153 |
description="Extensi?n encargada de la impresi?n de las tablas." |
|
154 |
active="true"> |
|
155 |
<menu text="Tabla/Imprimir" position="40080" icon="document-print" action-command="PRINTTABLE" tooltip="Imprimir"/> |
|
156 |
<tool-bar name="Tabla" position="10"> |
|
157 |
<action-tool icon="document-print" action-command="PRINTTABLE" tooltip="Imprimir"/> |
|
158 |
</tool-bar> |
|
159 |
</extension> |
|
160 |
|
|
161 |
<extension class-name="org.gvsig.app.extension.ZoomToSelectExtension" |
|
162 |
description="Extensi?n encargada de gestionar los eventos realizados sobre una capa." |
|
163 |
active="true"> |
|
164 |
<menu text="Vista/navegacion/Zoom_Select" position="3002090" action-command="ZOOM_SELECT" icon="view-zoom-to-seleccion"/> |
|
165 |
<tool-bar name="View_Tools_Zooms" position="3"> |
|
166 |
<action-tool icon="view-zoom-to-seleccion" action-command="ZOOM_SELECT" tooltip="Zoom_Select" position="7"/> |
|
167 |
</tool-bar> |
|
168 |
</extension> |
|
169 |
|
|
170 |
<extension class-name="org.gvsig.app.extension.ClearSelectionExtension" |
|
171 |
description="Extensi?n encargada de limpiar la selecci?n." |
|
172 |
active="true"> |
|
173 |
<menu text="Tabla/clear_selection" position="35010" action-command="DEL_SELECTION" icon="view-clear-selection"/> |
|
174 |
<tool-bar name="Tools_Select" position="6"> |
|
175 |
<action-tool icon="view-clear-selection" action-command="DEL_SELECTION" tooltip="clear_selection" position="4"/> |
|
176 |
</tool-bar> |
|
177 |
</extension> |
|
178 |
|
|
179 |
<extension class-name="org.gvsig.app.extension.FiltroExtension" |
|
180 |
description="Extensi?n encargada de abrir el di?logo para filtrar una tabla." |
|
181 |
active="true"> |
|
182 |
<menu text="Tabla/filtro" position="40074" icon="table-filter" action-command="FILTRO"/> |
|
183 |
<tool-bar name="Herramientas" position="12"> |
|
184 |
<action-tool icon="table-filter" action-command="FILTRO" tooltip="filtro" position="7"/> |
|
185 |
</tool-bar> |
|
186 |
</extension> |
|
187 |
|
|
188 |
</extensions> |
|
189 |
<icon src="gvsig-logo-icon" text="gvSIG"/> |
|
190 |
</plugin-config> |
tags/v2_0_0_Build_2038/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/TableDocument.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 {DiSiD Technologies} {TableDocument implementation based on the gvSIG DAL API} |
|
26 |
*/ |
|
27 |
package org.gvsig.app.project.documents.table; |
|
28 |
|
|
29 |
import java.text.MessageFormat; |
|
30 |
import java.util.ArrayList; |
|
31 |
import java.util.Iterator; |
|
32 |
import java.util.List; |
|
33 |
|
|
34 |
import org.slf4j.Logger; |
|
35 |
import org.slf4j.LoggerFactory; |
|
36 |
|
|
37 |
import org.gvsig.andami.messages.NotificationManager; |
|
38 |
import org.gvsig.app.project.ProjectManager; |
|
39 |
import org.gvsig.app.project.documents.AbstractDocument; |
|
40 |
import org.gvsig.app.project.documents.DocumentManager; |
|
41 |
import org.gvsig.fmap.dal.exception.DataException; |
|
42 |
import org.gvsig.fmap.dal.feature.Feature; |
|
43 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
44 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
45 |
import org.gvsig.fmap.dal.feature.FeatureQueryOrder; |
|
46 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
47 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
48 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
49 |
import org.gvsig.fmap.dal.feature.FeatureStoreNotification; |
|
50 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
51 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
52 |
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.FeatureStoreModel; |
|
53 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
54 |
import org.gvsig.tools.evaluator.Evaluator; |
|
55 |
import org.gvsig.tools.exception.BaseException; |
|
56 |
import org.gvsig.tools.observer.Observable; |
|
57 |
import org.gvsig.tools.observer.Observer; |
|
58 |
import org.gvsig.tools.persistence.Persistent; |
|
59 |
import org.gvsig.tools.persistence.PersistentState; |
|
60 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
61 |
|
|
62 |
/** |
|
63 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
|
64 |
*/ |
|
65 |
public class TableDocument extends AbstractDocument implements Observer { |
|
66 |
|
|
67 |
private static final long serialVersionUID = -1842181135614158881L; |
|
68 |
|
|
69 |
final static private Logger logger = LoggerFactory |
|
70 |
.getLogger(TableDocument.class); |
|
71 |
|
|
72 |
private FeatureStore store; |
|
73 |
|
|
74 |
private String featureTypeId; |
|
75 |
|
|
76 |
private String[] attributeNames; |
|
77 |
|
|
78 |
private List<TableLink> linkTable; |
|
79 |
|
|
80 |
private FLyrVect associatedLayer; |
|
81 |
|
|
82 |
private FeatureQuery query; |
|
83 |
|
|
84 |
private Evaluator baseFilter; |
|
85 |
|
|
86 |
private FeatureQueryOrder baseOrder; |
|
87 |
|
|
88 |
private FeatureStoreModel featureStoreModel; |
|
89 |
|
|
90 |
private Object lock = new Object(); |
|
91 |
|
|
92 |
public TableDocument(DocumentManager factory) { |
|
93 |
super(factory); |
|
94 |
this.store = null; |
|
95 |
this.query = null; |
|
96 |
this.featureTypeId = null; |
|
97 |
this.baseFilter = null; |
|
98 |
this.baseOrder = null; |
|
99 |
} |
|
100 |
|
|
101 |
public TableDocument() { |
|
102 |
this(null); |
|
103 |
} |
|
104 |
|
|
105 |
public TableDocument(DocumentManager factory, FeatureStore store) { |
|
106 |
this(factory); |
|
107 |
setStore(store); |
|
108 |
} |
|
109 |
|
|
110 |
public FeatureStoreModel getFeatureStoreModel() { |
|
111 |
synchronized (lock) { |
|
112 |
if (this.featureStoreModel == null) { |
|
113 |
try { |
|
114 |
this.featureStoreModel = |
|
115 |
new FeatureStoreModel(getStore(), getQuery()); |
|
116 |
} catch (BaseException e) { |
|
117 |
NotificationManager.addError(e); |
|
118 |
} |
|
119 |
} |
|
120 |
} |
|
121 |
return this.featureStoreModel; |
|
122 |
} |
|
123 |
|
|
124 |
public void setStore(FeatureStore store) { |
|
125 |
if (this.store != null) { |
|
126 |
throw new UnsupportedOperationException( |
|
127 |
"can't set store. store already set."); |
|
128 |
} |
|
129 |
this.store = store; |
|
130 |
this.store.addObserver(this); |
|
131 |
this.query = null; // setQuery(store.createFeatureQuery()); |
|
132 |
} |
|
133 |
|
|
134 |
@SuppressWarnings("unchecked") |
|
135 |
public FeatureQuery getQuery() { |
|
136 |
if (this.query == null) { |
|
137 |
try { |
|
138 |
FeatureType fType = null; |
|
139 |
this.query = this.store.createFeatureQuery(); |
|
140 |
if (this.featureTypeId != null) { |
|
141 |
Iterator<FeatureType> iter; |
|
142 |
iter = this.store.getFeatureTypes().iterator(); |
|
143 |
while (iter.hasNext()) { |
|
144 |
fType = iter.next(); |
|
145 |
if (this.featureTypeId.equals(fType.getId())) { |
|
146 |
this.query.setFeatureType(fType); |
|
147 |
break; |
|
148 |
} |
|
149 |
} |
|
150 |
if (fType == null) { |
|
151 |
throw new RuntimeException(MessageFormat.format( |
|
152 |
"frature type {1} not found.", this.featureTypeId)); |
|
153 |
} |
|
154 |
|
|
155 |
} else { |
|
156 |
fType = store.getDefaultFeatureType(); |
|
157 |
} |
|
158 |
|
|
159 |
if (this.attributeNames != null) { |
|
160 |
ArrayList<String> newNames = new ArrayList<String>(); |
|
161 |
for (String name : this.attributeNames) { |
|
162 |
if (fType.getIndex(name) > -1) { |
|
163 |
newNames.add(name); |
|
164 |
} |
|
165 |
} |
|
166 |
if (newNames.size() > 0) { |
|
167 |
this.query.setAttributeNames(newNames |
|
168 |
.toArray(this.attributeNames)); |
|
169 |
} |
|
170 |
} |
|
171 |
|
|
172 |
this.query.setFilter(this.baseFilter); // TODO check is valid |
|
173 |
this.query.setOrder(this.baseOrder); |
|
174 |
|
|
175 |
} catch (DataException e) { |
|
176 |
NotificationManager.addError(e); |
|
177 |
return null; |
|
178 |
} |
|
179 |
|
|
180 |
} |
|
181 |
return this.query; |
|
182 |
} |
|
183 |
|
|
184 |
/** |
|
185 |
* @return the store |
|
186 |
*/ |
|
187 |
public FeatureStore getStore() { |
|
188 |
return store; |
|
189 |
} |
|
190 |
|
|
191 |
/** |
|
192 |
* Return information about the table links. |
|
193 |
* |
|
194 |
* @return List of TableLink information. |
|
195 |
*/ |
|
196 |
public List<TableLink> getLinks() { |
|
197 |
return this.linkTable; |
|
198 |
} |
|
199 |
|
|
200 |
/** |
|
201 |
* Returns if this table document has links with other tables. |
|
202 |
* |
|
203 |
* @return if this table document has links with other tables |
|
204 |
*/ |
|
205 |
public boolean hasLinks() { |
|
206 |
return this.linkTable != null && this.linkTable.size() > 0; |
|
207 |
} |
|
208 |
|
|
209 |
/** |
|
210 |
* Devuelve el identificador de la tabla que contiene el link. |
|
211 |
* |
|
212 |
* @return identificador ?nico de la tabla. |
|
213 |
* @deprecated see {{@link #getLinks()} |
|
214 |
*/ |
|
215 |
public String getLinkTable() { |
|
216 |
if (linkTable == null || linkTable.isEmpty()) { |
|
217 |
return null; |
|
218 |
} |
|
219 |
return linkTable.get(0).getTargetTable().getName(); |
|
220 |
} |
|
221 |
|
|
222 |
/** |
|
223 |
* Devuelve el nombre del campo de la tabla a enlazar. |
|
224 |
* |
|
225 |
* @return Nombre del campo de la tabla a enlazar. |
|
226 |
* @deprecated see {{@link #getLink()} |
|
227 |
*/ |
|
228 |
public String getField1() { |
|
229 |
if (linkTable.isEmpty()) { |
|
230 |
return null; |
|
231 |
} |
|
232 |
return this.linkTable.get(0).getSourceFieldName(); |
|
233 |
} |
|
234 |
|
|
235 |
/** |
|
236 |
* Devuelve el nombre del campo de la tabla enlazada. |
|
237 |
* |
|
238 |
* @return Nombre del campo de la tabla enlazada. |
|
239 |
* @deprecated see {{@link #getLink()} |
|
240 |
*/ |
|
241 |
public String getField2() { |
|
242 |
if (linkTable.isEmpty()) { |
|
243 |
return null; |
|
244 |
} |
|
245 |
return this.linkTable.get(0).getTargetFieldName(); |
|
246 |
} |
|
247 |
|
|
248 |
/** |
|
249 |
* Enlaza la seleccion de esta tabla con la de la tabla indicada |
|
250 |
* |
|
251 |
* @deprecated see {@link #addLinkTable(String, String, String)} |
|
252 |
*/ |
|
253 |
public void setLinkTable(String targetTable, String fieldSource, |
|
254 |
String fieldTarget) { |
|
255 |
this.addLinkTable(targetTable, fieldSource, fieldTarget); |
|
256 |
} |
|
257 |
|
|
258 |
/** |
|
259 |
* Add a table link to this document. |
|
260 |
* |
|
261 |
* @param targetTable |
|
262 |
* @param fieldSource |
|
263 |
* @param fieldTarget |
|
264 |
*/ |
|
265 |
public void addLinkTable(String targetTable, String fieldSource, |
|
266 |
String fieldTarget) { |
|
267 |
TableDocument target = |
|
268 |
(TableDocument) ProjectManager.getInstance().getCurrentProject() |
|
269 |
.getDocument(targetTable, TableManager.TYPENAME); |
|
270 |
TableLink link = new TableLink(this, target, fieldSource, fieldTarget); |
|
271 |
link.setEnabled(true); |
|
272 |
if (this.linkTable == null) { |
|
273 |
this.linkTable = new ArrayList<TableLink>(); |
|
274 |
} |
|
275 |
this.linkTable.add(link); |
|
276 |
} |
|
277 |
|
|
278 |
/** |
|
279 |
* remove the last link to table added. |
|
280 |
* |
|
281 |
*/ |
|
282 |
public void removeLinkTable() { |
|
283 |
if (linkTable.isEmpty()) { |
|
284 |
return; |
|
285 |
} |
|
286 |
TableLink link = this.linkTable.remove(this.linkTable.size() - 1); |
|
287 |
link.setEnabled(false); |
|
288 |
this.linkTable = null; |
|
289 |
} |
|
290 |
|
|
291 |
/** |
|
292 |
* Remove the link to the table document. |
|
293 |
* |
|
294 |
* @param name |
|
295 |
* of table document to remove. |
|
296 |
*/ |
|
297 |
public void removeLinkTable(String name) { |
|
298 |
for (TableLink link : this.linkTable) { |
|
299 |
if (name.equals(link.target.getName())) { |
|
300 |
link.setEnabled(false); |
|
301 |
this.linkTable.remove(link); |
|
302 |
} |
|
303 |
} |
|
304 |
} |
|
305 |
|
|
306 |
public FLyrVect getAssociatedLayer() { |
|
307 |
return associatedLayer; |
|
308 |
} |
|
309 |
|
|
310 |
public void setAssociatedLayer(FLyrVect associatedLayer) { |
|
311 |
this.associatedLayer = associatedLayer; |
|
312 |
} |
|
313 |
|
|
314 |
public void update(Observable arg0, Object arg1) { |
|
315 |
if (this.store.equals(arg0)) { |
|
316 |
if (arg1 instanceof FeatureStoreNotification) { |
|
317 |
FeatureStoreNotification event = |
|
318 |
(FeatureStoreNotification) arg1; |
|
319 |
if (event.getType() == FeatureStoreNotification.TRANSFORM_CHANGE |
|
320 |
|| event.getType() == FeatureStoreNotification.RESOURCE_CHANGED) { |
|
321 |
this.query = null; |
|
322 |
} |
|
323 |
} |
|
324 |
|
|
325 |
} |
|
326 |
|
|
327 |
} |
|
328 |
|
|
329 |
@SuppressWarnings("unchecked") |
|
330 |
public void loadFromState(PersistentState state) |
|
331 |
throws PersistenceException { |
|
332 |
super.loadFromState(state); |
|
333 |
|
|
334 |
this.store = (FeatureStore) state.get("store"); |
|
335 |
this.featureTypeId = state.getString("featureTypeId"); |
|
336 |
this.attributeNames = |
|
337 |
(String[]) state.getArray("attributeNames", String.class); |
|
338 |
this.linkTable = state.getList("linkTable"); |
|
339 |
this.associatedLayer = (FLyrVect) state.get("associatedLayer"); |
|
340 |
this.query = (FeatureQuery) state.get("query"); |
|
341 |
this.baseFilter = (Evaluator) state.get("baseFilter"); |
|
342 |
this.baseOrder = (FeatureQueryOrder) state.get("baseOrder"); |
|
343 |
} |
|
344 |
|
|
345 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
346 |
super.saveToState(state); |
|
347 |
|
|
348 |
state.set("store", store); |
|
349 |
state.set("featureTypeId", featureTypeId); |
|
350 |
state.set("attributeNames", attributeNames); |
|
351 |
state.set("linkTable", linkTable); |
|
352 |
state.set("associatedLayer", associatedLayer); |
|
353 |
state.set("query", query); |
|
354 |
// state.set("baseFilter", baseFilter); |
|
355 |
state.set("baseOrder", baseOrder); |
|
356 |
} |
|
357 |
|
|
358 |
public static class TableLink implements Observer, Persistent { |
|
359 |
|
|
360 |
private TableDocument source; |
|
361 |
private FeatureStore storeSource; |
|
362 |
private int fieldSource; |
|
363 |
|
|
364 |
private TableDocument target; |
|
365 |
private FeatureStore storeTarget; |
|
366 |
private int fieldTarget; |
|
367 |
|
|
368 |
private boolean enabled; |
|
369 |
|
|
370 |
TableLink() { |
|
371 |
this.source = null; |
|
372 |
this.target = null; |
|
373 |
this.fieldSource = -1; |
|
374 |
this.fieldTarget = -1; |
|
375 |
this.storeSource = null; |
|
376 |
this.storeTarget = null; |
|
377 |
this.enabled = false; |
|
378 |
} |
|
379 |
|
|
380 |
public TableLink(TableDocument source, TableDocument target, |
|
381 |
String fieldSource, String fieldTarget) { |
|
382 |
this(); |
|
383 |
this.initialize(source, target, fieldSource, fieldTarget); |
|
384 |
} |
|
385 |
|
|
386 |
private void initialize(TableDocument source, TableDocument target, |
|
387 |
String fieldSource, String fieldTarget) { |
|
388 |
this.source = source; |
|
389 |
this.target = target; |
|
390 |
|
|
391 |
this.storeSource = this.source.getStore(); |
|
392 |
this.storeTarget = this.target.getStore(); |
|
393 |
try { |
|
394 |
this.fieldSource = |
|
395 |
storeSource.getDefaultFeatureType().getIndex(fieldSource); |
|
396 |
this.fieldTarget = |
|
397 |
storeTarget.getDefaultFeatureType().getIndex(fieldTarget); |
|
398 |
} catch (DataException ex) { |
|
399 |
logger.error("Can't initialize TableLink", ex); |
|
400 |
throw new RuntimeException("Can't initialize TableLink", ex); |
|
401 |
} |
|
402 |
} |
|
403 |
|
|
404 |
public void setEnabled(boolean enabled) { |
|
405 |
if (enabled) { |
|
406 |
this.storeSource.addObserver(this); |
|
407 |
} else { |
|
408 |
this.storeSource.deleteObserver(this); |
|
409 |
} |
|
410 |
this.enabled = enabled; |
|
411 |
} |
|
412 |
|
|
413 |
public boolean getEnabled() { |
|
414 |
return this.enabled; |
|
415 |
} |
|
416 |
|
|
417 |
public TableDocument getTargetTable() { |
|
418 |
return this.target; |
|
419 |
} |
|
420 |
|
|
421 |
public TableDocument getSourceTable() { |
|
422 |
return this.source; |
|
423 |
} |
|
424 |
|
|
425 |
public String getSourceFieldName() { |
|
426 |
try { |
|
427 |
return ((FeatureAttributeDescriptor) this.storeSource |
|
428 |
.getDefaultFeatureType().get(this.fieldSource)).getName(); |
|
429 |
} catch (DataException e) { |
|
430 |
logger.warn("Can't get source field name.", e); |
|
431 |
return null; |
|
432 |
} |
|
433 |
} |
|
434 |
|
|
435 |
public String getTargetFieldName() { |
|
436 |
try { |
|
437 |
return ((FeatureAttributeDescriptor) this.storeTarget |
|
438 |
.getDefaultFeatureType().get(this.fieldTarget)).getName(); |
|
439 |
} catch (DataException e) { |
|
440 |
logger.warn("Can't get target field name.", e); |
|
441 |
return null; |
|
442 |
} |
|
443 |
} |
|
444 |
|
|
445 |
public void update(Observable arg0, Object arg1) { |
|
446 |
try { |
|
447 |
FeatureSet fCollection1 = |
|
448 |
(FeatureSet) storeSource.getSelection(); |
|
449 |
FeatureSelection fCollection2 = |
|
450 |
(FeatureSelection) storeTarget.createSelection(); |
|
451 |
List<Object> idx = new ArrayList<Object>(); |
|
452 |
|
|
453 |
// Construimos el ?ndice |
|
454 |
DisposableIterator iterator1 = null; |
|
455 |
try { |
|
456 |
iterator1 = fCollection1.fastIterator(); |
|
457 |
while (iterator1.hasNext()) { |
|
458 |
Feature feature = (Feature) iterator1.next(); |
|
459 |
Object obj = feature.get(fieldSource); |
|
460 |
if (!idx.contains(obj)) { |
|
461 |
idx.add(obj); |
|
462 |
} |
|
463 |
} |
|
464 |
} finally { |
|
465 |
if (iterator1 != null) { |
|
466 |
iterator1.dispose(); |
|
467 |
} |
|
468 |
} |
|
469 |
FeatureSet set = null; |
|
470 |
DisposableIterator iterator2 = null; |
|
471 |
|
|
472 |
try { |
|
473 |
set = storeTarget.getFeatureSet(); |
|
474 |
iterator2 = set.fastIterator(); |
|
475 |
while (iterator2.hasNext()) { |
|
476 |
Feature feature = (Feature) iterator2.next(); |
|
477 |
Object obj = feature.get(fieldTarget); |
|
478 |
if (idx.contains(obj)) { |
|
479 |
fCollection2.select(feature); |
|
480 |
} |
|
481 |
} |
|
482 |
} catch (DataException e1) { |
|
483 |
NotificationManager.addError(e1); |
|
484 |
return; |
|
485 |
} finally { |
|
486 |
if (iterator2 != null) { |
|
487 |
iterator2.dispose(); |
|
488 |
} |
|
489 |
if (set != null) { |
|
490 |
set.dispose(); |
|
491 |
} |
|
492 |
} |
|
493 |
|
|
494 |
// this applies the selection to the linked table |
|
495 |
if (storeSource != storeTarget) { |
|
496 |
storeTarget.setSelection(fCollection2); |
|
497 |
} |
|
498 |
} catch (DataException e2) { |
|
499 |
NotificationManager.addError(e2); |
|
500 |
return; |
|
501 |
} |
|
502 |
} |
|
503 |
|
|
504 |
public void loadFromState(PersistentState state) |
|
505 |
throws PersistenceException { |
|
506 |
this.initialize((TableDocument) state.get("source"), |
|
507 |
(TableDocument) state.get("target"), |
|
508 |
state.getString("fieldSource"), state.getString("fieldTarget")); |
|
509 |
this.setEnabled(state.getBoolean("enabled")); |
|
510 |
} |
|
511 |
|
|
512 |
public void saveToState(PersistentState state) |
|
513 |
throws PersistenceException { |
|
514 |
state.set("source", this.source); |
|
515 |
state.set("target", this.target); |
|
516 |
state.set("fieldSource", this.getSourceFieldName()); |
|
517 |
state.set("fieldTarget", this.getTargetFieldName()); |
|
518 |
state.set("enabled", this.getEnabled()); |
|
519 |
} |
|
520 |
|
|
521 |
} |
|
522 |
|
|
523 |
} |
tags/v2_0_0_Build_2038/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/FieldSelectionModel.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 |
package org.gvsig.app.project.documents.table; |
|
23 |
|
|
24 |
import java.util.ArrayList; |
|
25 |
import java.util.Iterator; |
|
26 |
import java.util.List; |
|
27 |
|
|
28 |
import org.gvsig.fmap.dal.exception.DataException; |
|
29 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
30 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
31 |
import org.gvsig.tools.dataTypes.DataTypes; |
|
32 |
import org.gvsig.utils.swing.objectSelection.ObjectSelectionModel; |
|
33 |
import org.gvsig.utils.swing.objectSelection.SelectionException; |
|
34 |
|
|
35 |
/** |
|
36 |
* @author Fernando Gonz?lez Cort?s |
|
37 |
*/ |
|
38 |
public class FieldSelectionModel implements ObjectSelectionModel { |
|
39 |
|
|
40 |
// final static private Logger logger = |
|
41 |
// LoggerFactory.getLogger(FieldSelectionModel.class); |
|
42 |
|
|
43 |
private FeatureStore fs; |
|
44 |
private String msg; |
|
45 |
private int type = DataTypes.INVALID; |
|
46 |
private boolean selectAll = false; |
|
47 |
|
|
48 |
/** |
|
49 |
* Crea un nuevo FirstFieldSelectionModel. |
|
50 |
* |
|
51 |
*/ |
|
52 |
public FieldSelectionModel(FeatureStore fs, String msg, int type) { |
|
53 |
this.fs = fs; |
|
54 |
this.msg = msg; |
|
55 |
this.type = type; |
|
56 |
} |
|
57 |
|
|
58 |
public FieldSelectionModel(FeatureStore fs, String msg) { |
|
59 |
this(fs, msg, DataTypes.UNKNOWN); |
|
60 |
selectAll = true; |
|
61 |
} |
|
62 |
|
|
63 |
@SuppressWarnings("unchecked") |
|
64 |
public Object[] getObjects() throws SelectionException { |
|
65 |
|
|
66 |
List<String> fields = new ArrayList<String>(); |
|
67 |
Iterator<FeatureAttributeDescriptor> iterator = null; |
|
68 |
try { |
|
69 |
iterator = fs.getDefaultFeatureType().iterator(); |
|
70 |
} catch (DataException e) { |
|
71 |
throw new SelectionException( |
|
72 |
"Can't create iterator for the atribute of feature type", e); |
|
73 |
} |
|
74 |
while (iterator.hasNext()) { |
|
75 |
FeatureAttributeDescriptor descriptor = iterator.next(); |
|
76 |
if (type != DataTypes.INVALID) { |
|
77 |
if ((descriptor.getType() == type) || selectAll) { |
|
78 |
fields.add(descriptor.getName()); |
|
79 |
} |
|
80 |
} else { |
|
81 |
fields.add(descriptor.getName()); |
|
82 |
} |
|
83 |
} |
|
84 |
|
|
85 |
return (String[]) fields.toArray(new String[fields.size()]); |
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* @see org.gvsig.utils.swing.objectSelection.ObjectSelectionModel#getMsg() |
|
90 |
*/ |
|
91 |
public String getMsg() { |
|
92 |
return msg; |
|
93 |
} |
|
94 |
} |
tags/v2_0_0_Build_2038/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/TableOperations.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 |
package org.gvsig.app.project.documents.table; |
|
23 |
|
|
24 |
import java.awt.Component; |
|
25 |
import java.text.ParseException; |
|
26 |
import java.util.ArrayList; |
|
27 |
import java.util.Iterator; |
|
28 |
|
|
29 |
import javax.swing.JOptionPane; |
|
30 |
|
|
31 |
import org.gvsig.andami.PluginServices; |
|
32 |
import org.gvsig.andami.messages.NotificationManager; |
|
33 |
import org.gvsig.app.project.documents.table.gui.CreateNewAttributePanel; |
|
34 |
import org.gvsig.fmap.dal.DataTypes; |
|
35 |
import org.gvsig.fmap.dal.exception.DataException; |
|
36 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
37 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
|
38 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
39 |
import org.gvsig.fmap.dal.feature.Feature; |
|
40 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
41 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
42 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
43 |
import org.gvsig.fmap.mapcontrol.dal.feature.swing.FeatureTable; |
|
44 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
45 |
|
|
46 |
/** |
|
47 |
* Feature Table Operations. |
|
48 |
* |
|
49 |
* @author Vicente Caballero Navarro |
|
50 |
* |
|
51 |
*/ |
|
52 |
public class TableOperations { |
|
53 |
|
|
54 |
public static final int MAX_FIELD_LENGTH = 254; |
|
55 |
private static TableOperations fto = null; |
|
56 |
private FeatureStore featureStore; |
|
57 |
private ArrayList<Feature> selectedFeatures = new ArrayList<Feature>(); |
|
58 |
private boolean cutting = false; |
|
59 |
|
|
60 |
public static TableOperations getInstance() { |
|
61 |
if (fto == null) { |
|
62 |
fto = new TableOperations(); |
|
63 |
} |
|
64 |
return fto; |
|
65 |
} |
|
66 |
|
|
67 |
public void setStore(FeatureStore store) { |
|
68 |
featureStore = store; |
|
69 |
} |
|
70 |
|
|
71 |
public void copyFeatures() throws DataException { |
|
72 |
cutting = false; |
|
73 |
copy(); |
|
74 |
} |
|
75 |
|
|
76 |
public boolean hasSelection() { |
|
77 |
return !selectedFeatures.isEmpty(); |
|
78 |
} |
|
79 |
|
|
80 |
public void pasteFeatures() throws DataException { |
|
81 |
if (cutting) { |
|
82 |
delete(); |
|
83 |
cutting = false; |
|
84 |
} |
|
85 |
Iterator<Feature> features = selectedFeatures.iterator(); |
|
86 |
while (features.hasNext()) { |
|
87 |
Feature feature = features.next(); |
|
88 |
featureStore.insert(feature.getEditable()); |
|
89 |
} |
|
90 |
} |
|
91 |
|
|
92 |
public void cutFeatures() throws DataException { |
|
93 |
cutting = true; |
|
94 |
copy(); |
|
95 |
} |
|
96 |
|
|
97 |
private void copy() throws DataException { |
|
98 |
DisposableIterator features = null; |
|
99 |
try { |
|
100 |
features = |
|
101 |
((FeatureSelection) featureStore.getSelection()).fastIterator(); |
|
102 |
selectedFeatures.clear(); |
|
103 |
while (features.hasNext()) { |
|
104 |
Feature feature = (Feature) features.next(); |
|
105 |
selectedFeatures.add(feature); |
|
106 |
} |
|
107 |
} finally { |
|
108 |
if (features != null) { |
|
109 |
features.dispose(); |
|
110 |
} |
|
111 |
} |
|
112 |
} |
|
113 |
|
|
114 |
private void delete() throws DataException { |
|
115 |
Iterator<Feature> features = selectedFeatures.iterator(); |
|
116 |
while (features.hasNext()) { |
|
117 |
Feature feature = features.next(); |
|
118 |
featureStore.delete(feature); |
|
119 |
} |
|
120 |
} |
|
121 |
|
|
122 |
public void deleteFeatures() throws DataException { |
|
123 |
DisposableIterator features = null; |
|
124 |
try { |
|
125 |
features = |
|
126 |
((FeatureSelection) featureStore.getSelection()).fastIterator(); |
|
127 |
while (features.hasNext()) { |
|
128 |
Feature feature = (Feature) features.next(); |
|
129 |
featureStore.delete(feature); |
|
130 |
} |
|
131 |
} finally { |
|
132 |
if (features != null) { |
|
133 |
features.dispose(); |
|
134 |
} |
|
135 |
} |
|
136 |
} |
|
137 |
|
|
138 |
public void insertNewFeature() throws DataException { |
|
139 |
// if (getModel().getAssociatedTable()!=null){ |
|
140 |
// JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),"No se puede a?adir una fila a una tabla asociada a una capa."); |
|
141 |
// return; |
|
142 |
// } |
|
143 |
EditableFeature feature = featureStore.createNewFeature(); |
|
144 |
featureStore.insert(feature); |
|
145 |
} |
|
146 |
|
|
147 |
public void deleteAttributes(FeatureTable table) throws DataException { |
|
148 |
EditableFeatureType eft = |
|
149 |
featureStore.getDefaultFeatureType().getEditable(); |
|
150 |
FeatureAttributeDescriptor[] selecteds = |
|
151 |
table.getSelectedColumnsAttributeDescriptor(); |
|
152 |
for (int i = 0; i < selecteds.length; i++) { |
|
153 |
eft.remove(selecteds[i].getName()); |
|
154 |
} |
|
155 |
featureStore.update(eft); |
|
156 |
} |
|
157 |
|
|
158 |
public void insertAttributes(FeatureTable table) throws DataException { |
|
159 |
EditableFeatureType eft = |
|
160 |
featureStore.getDefaultFeatureType().getEditable(); |
|
161 |
|
|
162 |
try { |
|
163 |
CreateNewAttributePanel panelNewField = |
|
164 |
new CreateNewAttributePanel(); |
|
165 |
|
|
166 |
EditableFeatureAttributeDescriptor ead = |
|
167 |
panelNewField.loadFieldDescription(eft); |
|
168 |
if (ead == null) { |
|
169 |
return; |
|
170 |
} |
|
171 |
if (ead.getType() == DataTypes.STRING |
|
172 |
&& ead.getSize() > MAX_FIELD_LENGTH) { |
|
173 |
NotificationManager.showMessageInfo( |
|
174 |
PluginServices.getText(this, "max_length_is") + ":" |
|
175 |
+ MAX_FIELD_LENGTH, null); |
|
176 |
ead.setSize(MAX_FIELD_LENGTH); |
|
177 |
} |
|
178 |
PluginServices.getMDIManager().closeWindow(panelNewField); |
|
179 |
} catch (ParseException e2) { |
|
180 |
NotificationManager.addError(e2); |
|
181 |
} |
|
182 |
featureStore.update(eft); |
|
183 |
|
|
184 |
} |
|
185 |
|
|
186 |
public void renameAttributes(FeatureTable table) throws DataException { |
|
187 |
EditableFeatureType eft = |
|
188 |
featureStore.getDefaultFeatureType().getEditable(); |
|
189 |
FeatureAttributeDescriptor[] selecteds = |
|
190 |
table.getSelectedColumnsAttributeDescriptor(); |
|
191 |
|
|
192 |
for (int i = selecteds.length - 1; i >= 0; i--) { |
|
193 |
String newName = |
|
194 |
JOptionPane.showInputDialog((Component) PluginServices |
|
195 |
.getMDIManager().getActiveWindow(), PluginServices.getText( |
|
196 |
this, "please_insert_new_field_name"), selecteds[i] |
|
197 |
.getName()); |
|
198 |
if (newName == null) { |
|
199 |
return; |
|
200 |
} |
|
201 |
if (eft.getIndex(newName) != -1) { |
|
202 |
NotificationManager.showMessageInfo( |
|
203 |
PluginServices.getText(this, "field_already_exists"), null); |
|
204 |
return; |
|
205 |
} |
|
206 |
FeatureAttributeDescriptor ad = |
|
207 |
(FeatureAttributeDescriptor) eft.get(selecteds[i].getName()); |
|
208 |
eft.remove(ad.getName()); |
|
209 |
EditableFeatureAttributeDescriptor ead = |
|
210 |
eft.add(newName, ad.getType(), ad.getSize()); |
|
211 |
ead.setPrecision(ad.getPrecision()); |
|
212 |
} |
|
213 |
|
|
214 |
featureStore.update(eft); |
|
215 |
} |
|
216 |
|
|
217 |
} |
tags/v2_0_0_Build_2038/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/ExportStatisticsFile.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 |
package org.gvsig.app.project.documents.table; |
|
23 |
|
|
24 |
import java.awt.Component; |
|
25 |
import java.io.File; |
|
26 |
import java.io.FileWriter; |
|
27 |
import java.io.IOException; |
|
28 |
import java.util.Hashtable; |
|
29 |
import java.util.Iterator; |
|
30 |
import java.util.List; |
|
31 |
|
|
32 |
import javax.swing.JFileChooser; |
|
33 |
import javax.swing.JOptionPane; |
|
34 |
import javax.swing.filechooser.FileFilter; |
|
35 |
|
|
36 |
import org.slf4j.Logger; |
|
37 |
import org.slf4j.LoggerFactory; |
|
38 |
|
|
39 |
import org.gvsig.andami.PluginServices; |
|
40 |
import org.gvsig.andami.messages.NotificationManager; |
|
41 |
import org.gvsig.app.project.documents.table.gui.CSVSeparatorOptionsPanel; |
|
42 |
import org.gvsig.app.project.documents.table.gui.Statistics.MyObjectStatistics; |
|
43 |
import org.gvsig.fmap.dal.DALLocator; |
|
44 |
import org.gvsig.fmap.dal.DataManager; |
|
45 |
import org.gvsig.fmap.dal.DataTypes; |
|
46 |
import org.gvsig.fmap.dal.exception.DataException; |
|
47 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
48 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
49 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
50 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
51 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
52 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
|
53 |
|
|
54 |
/** |
|
55 |
* Class to create dbf and csv files at disk with the statistics group generated |
|
56 |
* from a table. |
|
57 |
* |
|
58 |
* dbf -> Data Base File |
|
59 |
* csv -> Comma Separated Value |
|
60 |
* |
|
61 |
* @author ?ngel Fraile Gri??n e-mail: angel.fraile@iver.es |
|
62 |
* |
|
63 |
*/ |
|
64 |
|
|
65 |
public class ExportStatisticsFile { |
|
66 |
|
|
67 |
private static final Logger logger = LoggerFactory |
|
68 |
.getLogger(ExportStatisticsFile.class); |
|
69 |
|
|
70 |
private String lastPath = null; |
|
71 |
private Hashtable<String, MyFileFilter> dbfExtensionsSupported; // Supported |
|
72 |
// extensions. |
|
73 |
private Hashtable<String, MyFileFilter> csvExtensionsSupported; |
|
74 |
|
|
75 |
public ExportStatisticsFile(List<MyObjectStatistics> valores) { |
|
76 |
|
|
77 |
JFileChooser jfc = new JFileChooser(lastPath); |
|
78 |
jfc.removeChoosableFileFilter(jfc.getAcceptAllFileFilter()); |
|
79 |
|
|
80 |
// Adding required extensions (dbf, csv) |
|
81 |
dbfExtensionsSupported = new Hashtable<String, MyFileFilter>(); |
|
82 |
csvExtensionsSupported = new Hashtable<String, MyFileFilter>(); |
|
83 |
dbfExtensionsSupported.put("dbf", new MyFileFilter("dbf", |
|
84 |
PluginServices.getText(this, "Ficheros_dbf"), "dbf")); |
|
85 |
csvExtensionsSupported.put("csv", new MyFileFilter("csv", |
|
86 |
PluginServices.getText(this, "Ficheros_csv"), "csv")); |
|
87 |
|
|
88 |
Iterator<MyFileFilter> iter = |
|
89 |
csvExtensionsSupported.values().iterator(); |
|
90 |
while (iter.hasNext()) { |
|
91 |
jfc.addChoosableFileFilter(iter.next()); |
|
92 |
} |
|
93 |
|
|
94 |
iter = dbfExtensionsSupported.values().iterator(); |
|
95 |
while (iter.hasNext()) { |
|
96 |
jfc.addChoosableFileFilter(iter.next()); |
|
97 |
} |
|
98 |
|
|
99 |
// Opening a JFileCooser |
|
100 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
|
101 |
File endFile = jfc.getSelectedFile(); |
|
102 |
if (endFile.exists()) {// File exists in the directory. |
|
103 |
int resp = |
|
104 |
JOptionPane.showConfirmDialog( |
|
105 |
(Component) PluginServices.getMainFrame(), |
|
106 |
PluginServices.getText(this, |
|
107 |
"fichero_ya_existe_seguro_desea_guardarlo") |
|
108 |
+ "\n" |
|
109 |
+ endFile.getAbsolutePath(), PluginServices |
|
110 |
.getText(this, "guardar"), |
|
111 |
JOptionPane.YES_NO_OPTION);// Informing the user |
|
112 |
if (resp != JOptionPane.YES_OPTION) {// cancel pressed. |
|
113 |
return; |
|
114 |
} |
|
115 |
}// end if exits. |
|
116 |
MyFileFilter filter = (MyFileFilter) jfc.getFileFilter();// dbf, csv |
|
117 |
endFile = filter.normalizeExtension(endFile);// "name" + "." + |
|
118 |
// "dbf", "name" + "." |
|
119 |
// + "csv" |
|
120 |
|
|
121 |
if (filter.getExtensionOfAFile(endFile).toLowerCase() |
|
122 |
.compareTo("csv") == 0) { // csv file |
|
123 |
exportToCSVFile(valores, endFile); // export to csv format |
|
124 |
} else |
|
125 |
if (filter.getExtensionOfAFile(endFile).toLowerCase() |
|
126 |
.compareTo("dbf") == 0) {// dbf file |
|
127 |
try { |
|
128 |
exportToDBFFile(valores, endFile); |
|
129 |
} catch (Exception e) { |
|
130 |
NotificationManager.addError(e); |
|
131 |
} // export to dbf format |
|
132 |
} |
|
133 |
}// end if aprove option. |
|
134 |
} |
|
135 |
|
|
136 |
/** |
|
137 |
* Creating cvs format file with the statistics. |
Also available in: Unified diff