Revision 38298
tags/v2_0_0_Build_2047/extensions/org.gvsig.app.document.table.app/distribution/distribution.xml | ||
---|---|---|
1 |
<assembly> |
|
2 |
</assembly> |
tags/v2_0_0_Build_2047/extensions/org.gvsig.app.document.table.app/buildNumber.properties | ||
---|---|---|
1 |
#maven.buildNumber.plugin properties file |
|
2 |
#Tue May 29 16:38:15 CEST 2012 |
|
3 |
buildNumber=13 |
tags/v2_0_0_Build_2047/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_2047/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/buildNumber.properties | ||
---|---|---|
1 |
#maven.buildNumber.plugin properties file |
|
2 |
#Tue May 29 16:38:16 CEST 2012 |
|
3 |
buildNumber=13 |
tags/v2_0_0_Build_2047/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_2047/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_2047/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_2047/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_2047/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. |
|
138 |
* Option to select the two columns separator. |
|
139 |
* |
|
140 |
* Example with semicolon: Name;data\n |
|
141 |
* Name2;data2\n |
|
142 |
* |
|
143 |
* @param valores |
|
144 |
* - Pairs: String name (key) + Double value ( |
|
145 |
* @param endFile |
|
146 |
* - File to write the information |
|
147 |
*/ |
|
148 |
|
|
149 |
private void exportToCSVFile(List<MyObjectStatistics> valores, File endFile) { |
|
150 |
|
|
151 |
try { |
|
152 |
CSVSeparatorOptionsPanel csvSeparatorOptions = |
|
153 |
new CSVSeparatorOptionsPanel(); |
|
154 |
PluginServices.getMDIManager().addWindow(csvSeparatorOptions); |
|
155 |
|
|
156 |
String separator = csvSeparatorOptions.getSeparator(); |
|
157 |
|
|
158 |
if (separator != null) { |
|
159 |
|
|
160 |
FileWriter fileCSV = new FileWriter(endFile); |
|
161 |
|
|
162 |
fileCSV.write(PluginServices.getText(this, "Nombre") |
|
163 |
+ separator + PluginServices.getText(this, "Valor") + "\n"); |
|
164 |
|
|
165 |
Iterator<MyObjectStatistics> iterador = valores.listIterator(); |
|
166 |
|
|
167 |
while (iterador.hasNext()) {// Writing value,value\n |
|
168 |
MyObjectStatistics data = iterador.next(); |
|
169 |
fileCSV.write(data.getKey() + separator + (data.getValue()) |
|
170 |
+ "\n"); |
|
171 |
} |
|
172 |
fileCSV.close(); |
|
173 |
JOptionPane.showMessageDialog( |
|
174 |
null, |
|
175 |
PluginServices.getText(this, "fichero_creado_en") + " " |
|
176 |
+ endFile.getAbsolutePath(), |
|
177 |
PluginServices.getText(this, "fichero_creado_en_formato") |
|
178 |
+ " csv " |
|
179 |
+ PluginServices.getText(this, "mediante_el_separador") |
|
180 |
+ " \"" + separator + "\"", |
|
181 |
JOptionPane.INFORMATION_MESSAGE);// Informing the user |
|
182 |
} else { |
|
183 |
return; |
|
184 |
} |
|
185 |
|
|
186 |
} catch (IOException e) {// Informing the user |
|
187 |
logger.error("Error exportando a formato csv"); |
|
188 |
JOptionPane.showMessageDialog( |
|
189 |
null, |
|
190 |
PluginServices.getText(this, |
|
191 |
"Error_exportando_las_estadisticas") |
|
192 |
+ " " |
|
193 |
+ endFile.getAbsolutePath(), PluginServices.getText(this, |
|
194 |
"Error"), JOptionPane.ERROR_MESSAGE); |
|
195 |
} |
|
196 |
|
|
197 |
} |
|
198 |
|
|
199 |
public void exportToDBFFile(List<MyObjectStatistics> valores, File endFile) |
|
200 |
throws DataException, ValidateDataParametersException { |
|
201 |
DataManager datamanager = DALLocator.getDataManager(); |
|
202 |
|
|
203 |
// |
|
204 |
// Averigua el proveedor en funcion del fichero |
|
205 |
// preguntandoselo al FilesystemServerExplorer. |
|
206 |
FilesystemServerExplorer explorer = |
|
207 |
(FilesystemServerExplorer) datamanager.openServerExplorer( |
|
208 |
FilesystemServerExplorer.NAME, null // |
|
209 |
); |
|
210 |
String providerName = explorer.getProviderName(endFile); |
|
211 |
|
|
212 |
try { |
|
213 |
NewFeatureStoreParameters parameters = |
|
214 |
(NewFeatureStoreParameters) datamanager |
|
215 |
.createNewStoreParameters(FilesystemServerExplorer.NAME, |
|
216 |
providerName); |
|
217 |
EditableFeatureType type = |
|
218 |
parameters.getDefaultFeatureType().getEditable(); |
|
219 |
type.add(PluginServices.getText(this, "Nombre"), DataTypes.STRING, |
|
220 |
50); |
|
221 |
type.add(PluginServices.getText(this, "Valor"), DataTypes.DOUBLE, |
|
222 |
100).setPrecision(25); |
|
223 |
|
|
224 |
parameters.setDefaultFeatureType(type); |
|
225 |
datamanager.newStore(FilesystemServerExplorer.NAME, providerName, |
|
226 |
parameters, true); |
|
227 |
|
|
228 |
FeatureStore target = |
|
229 |
(FeatureStore) datamanager.openStore(providerName, parameters); |
|
230 |
target.edit(FeatureStore.MODE_APPEND); |
|
231 |
Iterator<MyObjectStatistics> iterador = valores.listIterator(); |
|
232 |
while (iterador.hasNext()) { |
|
233 |
MyObjectStatistics data = iterador.next(); |
|
234 |
EditableFeature ef = target.createNewFeature().getEditable(); |
|
235 |
ef.set(PluginServices.getText(this, "Nombre"), data.getKey()); |
|
236 |
ef.set(PluginServices.getText(this, "Valor"), data.getValue()); |
|
237 |
target.insert(ef); |
|
238 |
} |
|
239 |
target.finishEditing(); |
|
240 |
target.dispose(); |
|
241 |
JOptionPane.showMessageDialog( |
|
242 |
(Component) PluginServices.getMainFrame(), |
|
243 |
PluginServices.getText(this, "fichero_creado_en") + " " |
|
244 |
+ endFile.getAbsolutePath(), |
|
245 |
PluginServices.getText(this, "fichero_creado_en_formato") |
|
246 |
+ " dbf", JOptionPane.INFORMATION_MESSAGE);// Informing the |
|
247 |
// user |
|
248 |
} catch (Exception e) { |
|
249 |
e.printStackTrace(); |
|
250 |
} |
|
251 |
} |
|
252 |
} |
|
253 |
|
|
254 |
/** |
|
255 |
* @author ?ngel Fraile Gri??n e-mail: angel.fraile@iver.es |
|
256 |
* |
|
257 |
* Class to work with the file extensions. |
|
258 |
*/ |
|
259 |
class MyFileFilter extends FileFilter { |
|
260 |
|
|
261 |
private String[] extensiones = new String[1]; |
|
262 |
private String description; |
|
263 |
private boolean dirs = true; |
|
264 |
private String info = null; |
|
265 |
|
|
266 |
public MyFileFilter(String[] ext, String desc) { |
|
267 |
extensiones = ext; |
|
268 |
description = desc; |
|
269 |
} |
|
270 |
|
|
271 |
public MyFileFilter(String[] ext, String desc, String info) { |
|
272 |
extensiones = ext; |
|
273 |
description = desc; |
|
274 |
this.info = info; |
|
275 |
} |
|
276 |
|
|
277 |
public MyFileFilter(String ext, String desc) { |
|
278 |
extensiones[0] = ext; |
|
279 |
description = desc; |
|
280 |
} |
|
281 |
|
|
282 |
public MyFileFilter(String ext, String desc, String info) { |
|
283 |
extensiones[0] = ext; |
|
284 |
description = desc; |
|
285 |
this.info = info; |
|
286 |
} |
|
287 |
|
|
288 |
public MyFileFilter(String ext, String desc, boolean dirs) { |
|
289 |
extensiones[0] = ext; |
|
290 |
description = desc; |
|
291 |
this.dirs = dirs; |
|
292 |
} |
|
293 |
|
|
294 |
public MyFileFilter(String ext, String desc, boolean dirs, String info) { |
|
295 |
extensiones[0] = ext; |
|
296 |
description = desc; |
|
297 |
this.dirs = dirs; |
|
298 |
this.info = info; |
|
299 |
} |
|
300 |
|
|
301 |
public boolean accept(File f) { |
|
302 |
if (f.isDirectory()) { |
|
303 |
if (dirs) { |
|
304 |
return true; |
|
305 |
} else { |
|
306 |
return false; |
|
307 |
} |
|
308 |
} |
|
309 |
for (int i = 0; i < extensiones.length; i++) { |
|
310 |
if (extensiones[i].equals("")) { |
|
311 |
continue; |
|
312 |
} |
|
313 |
if (getExtensionOfAFile(f).equalsIgnoreCase(extensiones[i])) { |
|
314 |
return true; |
|
315 |
} |
|
316 |
} |
|
317 |
return false; |
|
318 |
} |
|
319 |
|
|
320 |
public String getDescription() { |
|
321 |
return description; |
|
322 |
} |
|
323 |
|
|
324 |
public String[] getExtensions() { |
|
325 |
return extensiones; |
|
326 |
} |
|
327 |
|
|
328 |
public boolean isDirectory() { |
|
329 |
return dirs; |
|
330 |
} |
|
331 |
|
|
332 |
public String getExtensionOfAFile(File file) { |
|
333 |
String name; |
|
334 |
int dotPos; |
|
335 |
name = file.getName(); |
|
336 |
dotPos = name.lastIndexOf("."); |
|
337 |
if (dotPos < 1) { |
|
338 |
return ""; |
|
339 |
} |
|
340 |
return name.substring(dotPos + 1); |
|
341 |
} |
|
342 |
|
|
343 |
public File normalizeExtension(File file) { |
|
344 |
String ext = getExtensionOfAFile(file); |
|
345 |
if (ext.equals("") || !(this.accept(file))) { |
|
346 |
return new File(file.getAbsolutePath() + "." + extensiones[0]); |
|
347 |
} |
|
348 |
return file; |
|
349 |
} |
|
350 |
|
|
351 |
public String getInfo() { |
|
352 |
return this.info; |
|
353 |
} |
|
354 |
|
|
355 |
public void setInfo(String info) { |
|
356 |
this.info = info; |
|
357 |
} |
|
358 |
} |
tags/v2_0_0_Build_2047/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/TableSelectionModel.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 org.gvsig.utils.swing.objectSelection.ObjectSelectionModel; |
|
25 |
|
|
26 |
/** |
|
27 |
* @author Fernando Gonz?lez Cort?s |
|
28 |
*/ |
|
29 |
public class TableSelectionModel implements ObjectSelectionModel { |
|
30 |
|
|
31 |
private TableDocument[] tables; |
|
32 |
private String msg; |
|
33 |
|
|
34 |
public TableSelectionModel(TableDocument[] tables, String msg) { |
|
35 |
this.tables = tables; |
|
36 |
this.msg = msg; |
|
37 |
} |
|
38 |
|
|
39 |
/** |
|
40 |
* @see org.gvsig.app.project.documents.table.TableSelectionModel#getTables() |
|
41 |
*/ |
|
42 |
public Object[] getObjects() { |
|
43 |
return tables; |
|
44 |
} |
|
45 |
|
|
46 |
/** |
|
47 |
* @see org.gvsig.utils.swing.objectSelection.ObjectSelectionModel#getMsg() |
|
48 |
*/ |
|
49 |
public String getMsg() { |
|
50 |
return msg; |
|
51 |
} |
|
52 |
|
|
53 |
} |
tags/v2_0_0_Build_2047/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/package.html | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8" ?> |
|
2 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
3 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
|
4 |
<head> |
|
5 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
|
6 |
<title>org.gvsig.landregistryviewer package documentation</title> |
|
7 |
</head> |
|
8 |
<body> |
|
9 |
|
|
10 |
<p>Table document support</p> |
|
11 |
|
|
12 |
</body> |
|
13 |
</html> |
tags/v2_0_0_Build_2047/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/exceptions/package.html | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8" ?> |
|
2 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
3 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
|
4 |
<head> |
|
5 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
|
6 |
<title>org.gvsig.landregistryviewer package documentation</title> |
|
7 |
</head> |
|
8 |
<body> |
|
9 |
|
|
10 |
<p>Table document exceptions</p> |
|
11 |
|
|
12 |
</body> |
|
13 |
</html> |
tags/v2_0_0_Build_2047/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/exceptions/CancelEditingTableException.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.exceptions; |
|
23 |
|
|
24 |
/** |
|
25 |
* @author Vicente Caballero Navarro |
|
26 |
*/ |
|
27 |
public class CancelEditingTableException extends TableEditingException { |
|
28 |
|
|
29 |
/** |
|
30 |
* |
|
31 |
*/ |
|
32 |
private static final long serialVersionUID = 5231674331725098637L; |
|
33 |
|
|
34 |
public CancelEditingTableException(String table, Throwable exception) { |
|
35 |
super(table, exception); |
|
36 |
init(); |
|
37 |
initCause(exception); |
|
38 |
} |
|
39 |
|
|
40 |
private void init() { |
|
41 |
messageKey = "error_cancel_editing_table"; |
|
42 |
formatString = "Can�t cancel editing the table: %(table) "; |
|
43 |
} |
|
44 |
|
|
45 |
} |
tags/v2_0_0_Build_2047/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/exceptions/StopEditingTableException.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.exceptions; |
|
23 |
|
|
24 |
/** |
|
25 |
* @author Vicente Caballero Navarro |
|
26 |
*/ |
|
27 |
public class StopEditingTableException extends TableEditingException { |
|
28 |
|
|
29 |
/** |
|
30 |
* |
|
31 |
*/ |
|
32 |
private static final long serialVersionUID = 1663393663065092896L; |
|
33 |
|
|
34 |
public StopEditingTableException(String table, Throwable exception) { |
|
35 |
super(table, exception); |
|
36 |
init(); |
|
37 |
initCause(exception); |
|
38 |
} |
|
39 |
|
|
40 |
private void init() { |
|
41 |
messageKey = "error_stop_editing_table"; |
|
42 |
formatString = "Can�t stop editing the table: %(table) "; |
|
43 |
} |
|
44 |
|
|
45 |
} |
tags/v2_0_0_Build_2047/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/exceptions/StartEditingTableException.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.exceptions; |
|
23 |
|
|
24 |
/** |
|
25 |
* @author Vicente Caballero Navarro |
|
26 |
*/ |
|
27 |
public class StartEditingTableException extends TableEditingException { |
|
28 |
|
|
29 |
/** |
|
30 |
* |
|
31 |
*/ |
|
32 |
private static final long serialVersionUID = 8031152738000164873L; |
|
33 |
|
|
34 |
public StartEditingTableException(String table, Throwable exception) { |
|
35 |
super(table, exception); |
|
36 |
init(); |
|
37 |
initCause(exception); |
|
38 |
} |
|
39 |
|
|
40 |
private void init() { |
|
41 |
messageKey = "error_start_editing_table"; |
|
42 |
formatString = "Can�t start editing the table: %(table) "; |
|
43 |
} |
|
44 |
|
|
45 |
} |
tags/v2_0_0_Build_2047/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/exceptions/TableEditingException.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.exceptions; |
|
23 |
|
|
24 |
import org.gvsig.tools.exception.BaseException; |
|
25 |
|
|
26 |
/** |
|
27 |
* @author gvSIG Team |
|
28 |
* @version $Id$ |
|
29 |
*/ |
|
30 |
public class TableEditingException extends BaseException { |
|
31 |
|
|
32 |
private static final long serialVersionUID = -3672330283934624242L; |
|
33 |
private static final String KEY = "error_editing_table"; |
|
34 |
private static final String FORMAT = "Can't edit the table: %(table) "; |
|
35 |
|
|
36 |
public TableEditingException(String table, Throwable exception) { |
|
37 |
super(FORMAT, exception, KEY, serialVersionUID); |
|
38 |
setValue("table", table); |
|
39 |
} |
|
40 |
} |
tags/v2_0_0_Build_2047/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/TableManager.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 |
* 2004-2009 IVER TI |
|
26 |
* |
|
27 |
*/ |
|
28 |
|
|
29 |
package org.gvsig.app.project.documents.table; |
|
30 |
|
|
31 |
import java.util.Iterator; |
|
32 |
import java.util.List; |
|
33 |
|
|
34 |
import javax.swing.ImageIcon; |
|
35 |
|
|
36 |
import org.gvsig.andami.PluginServices; |
|
37 |
import org.gvsig.andami.messages.NotificationManager; |
|
38 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
39 |
import org.gvsig.app.ApplicationLocator; |
|
40 |
import org.gvsig.app.addlayer.AddLayerDialog; |
|
41 |
import org.gvsig.app.extension.AddLayer; |
|
42 |
import org.gvsig.app.gui.WizardPanel; |
|
43 |
import org.gvsig.app.project.Project; |
|
44 |
import org.gvsig.app.project.ProjectManager; |
|
45 |
import org.gvsig.app.project.documents.AbstractDocument; |
|
46 |
import org.gvsig.app.project.documents.AbstractDocumentManager; |
|
47 |
import org.gvsig.app.project.documents.Document; |
|
48 |
import org.gvsig.app.project.documents.gui.IDocumentWindow; |
|
49 |
import org.gvsig.app.project.documents.gui.WindowLayout; |
|
50 |
import org.gvsig.app.project.documents.table.TableDocument.TableLink; |
|
51 |
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel; |
|
52 |
import org.gvsig.app.project.documents.table.gui.TableProperties; |
|
53 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
54 |
import org.gvsig.fmap.dal.feature.FeatureQueryOrder; |
|
55 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
56 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.swing.FilesystemExplorerWizardPanel; |
|
57 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
58 |
import org.gvsig.tools.ToolsLocator; |
|
59 |
import org.gvsig.tools.dynobject.DynObjectManager; |
|
60 |
import org.gvsig.tools.dynobject.DynStruct; |
|
61 |
import org.gvsig.tools.evaluator.Evaluator; |
|
62 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
63 |
|
|
64 |
/** |
|
65 |
* Factory of Table. |
|
66 |
* |
|
67 |
* @author 2005- Vicente Caballero |
|
68 |
* @author 2009- Joaquin del Cerro |
|
69 |
* |
|
70 |
*/ |
|
71 |
public class TableManager extends AbstractDocumentManager { |
|
72 |
|
|
73 |
public static final String PERSISTENCE_TABLE_DOCUMENT_DEFINITION_NAME = |
|
74 |
"TableDocument"; |
|
75 |
public static final String PERSISTENCE_TABLELINK_DEFINITION_NAME = |
|
76 |
"TableLink"; |
|
77 |
|
|
78 |
public static String TYPENAME = "project.document.table"; |
|
79 |
|
|
80 |
private DynStruct persistenceDefinition = null; |
|
81 |
|
|
82 |
public ImageIcon getIcon() { |
|
83 |
return PluginServices.getIconTheme().get("document-table-icon"); |
|
84 |
} |
|
85 |
|
|
86 |
public ImageIcon getIconSelected() { |
|
87 |
return PluginServices.getIconTheme().get("document-table-icon-sel"); |
|
88 |
} |
|
89 |
|
|
90 |
public String getTitle() { |
|
91 |
return PluginServices.getText(this, "Tabla"); |
|
92 |
} |
|
93 |
|
|
94 |
public String getTypeName() { |
|
95 |
return TYPENAME; |
|
96 |
} |
|
97 |
|
|
98 |
public int getPriority() { |
|
99 |
return 1; |
|
100 |
} |
|
101 |
|
|
102 |
public Iterator<? extends Document> createDocumentsByUser() { |
|
103 |
AddLayerDialog fopen = null; |
|
104 |
try { |
|
105 |
fopen = |
|
106 |
new AddLayerDialog(PluginServices.getText(this, "Nueva_tabla")); |
|
107 |
List<WizardPanel> wizards = |
|
108 |
ApplicationLocator.getManager().getWizardPanels(); |
|
109 |
WizardPanel panel; |
|
110 |
Iterator<WizardPanel> iter = wizards.iterator(); |
|
111 |
while (iter.hasNext()) { |
|
112 |
panel = iter.next(); |
|
113 |
fopen.addWizardTab(panel.getTabName(), panel); |
|
114 |
panel.initWizard(); |
|
115 |
} |
|
116 |
PluginServices.getMDIManager().addWindow(fopen); |
|
117 |
if (fopen.isAccepted()) { |
|
118 |
panel = (WizardPanel) fopen.getSelectedTab(); |
|
119 |
@SuppressWarnings("unchecked") |
|
120 |
List<TableDocument> docs = |
|
121 |
(List<TableDocument>) panel.executeWizard(); |
|
122 |
return docs.iterator(); |
|
123 |
} |
|
124 |
} catch (Exception e) { |
|
125 |
NotificationManager.addError(e); |
|
126 |
} finally { |
|
127 |
if (fopen != null) { |
|
128 |
fopen.dispose(); |
|
129 |
fopen = null; |
|
130 |
} |
|
131 |
} |
|
132 |
return null; |
|
133 |
} |
|
134 |
|
|
135 |
public AbstractDocument createDocumentByUser() { |
|
136 |
return (AbstractDocument) createDocumentsByUser().next(); |
|
137 |
} |
|
138 |
|
|
139 |
/** |
|
140 |
* Registers in the points of extension the Factory with alias. |
|
141 |
* |
|
142 |
*/ |
|
143 |
public static void register() { |
|
144 |
|
|
145 |
TableManager factory = new TableManager(); |
|
146 |
// A?adimos nuestra extension para el tratamiento de la apertura de |
|
147 |
// ficheros |
|
148 |
// dentro de gvSIG |
|
149 |
ToolsLocator.getExtensionPointManager().add("FileTableOpenDialog", "") |
|
150 |
.append("FileOpenTable", "", FilesystemExplorerWizardPanel.class); |
|
151 |
|
|
152 |
ProjectManager.getInstance().registerDocumentFactory(factory); |
|
153 |
|
|
154 |
// ProjectFactory.getInstance().registerDocumentAction(TYPENAME,"copy",new |
|
155 |
// CopyDocumentContextMenuAction()); |
|
156 |
// ProjectFactory.getInstance().registerDocumentAction(TYPENAME,"cut",new |
|
157 |
// CutDocumentContextMenuAction()); |
|
158 |
// ProjectFactory.getInstance().registerDocumentAction(TYPENAME,"paste",new |
|
159 |
// PasteDocumentContextMenuAction()); |
|
160 |
|
|
161 |
PluginServices.getIconTheme().registerDefault("document-table-icon", |
|
162 |
AddLayer.class.getClassLoader().getResource("images/tablas.png"));// |
|
163 |
|
|
164 |
PluginServices.getIconTheme().registerDefault( |
|
165 |
"document-table-icon-sel", |
|
166 |
AddLayer.class.getClassLoader() |
|
167 |
.getResource("images/tablas_sel.png")); |
|
168 |
|
|
169 |
PluginServices.getIconTheme().registerDefault("edit-copy", |
|
170 |
AddLayer.class.getClassLoader().getResource("images/editcopy.png"));// |
|
171 |
PluginServices.getIconTheme().registerDefault("edit-cut", |
|
172 |
AddLayer.class.getClassLoader().getResource("images/editcut.png")); |
|
173 |
PluginServices.getIconTheme() |
|
174 |
.registerDefault( |
|
175 |
"edit-paste", |
|
176 |
AddLayer.class.getClassLoader().getResource( |
|
177 |
"images/editpaste.png")); |
|
178 |
PluginServices.getIconTheme().registerDefault( |
|
179 |
"edit-delete", |
|
180 |
AddLayer.class.getClassLoader() |
|
181 |
.getResource("images/editdelete.png")); |
|
182 |
|
|
183 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
184 |
manager.registerFactory(factory); |
|
185 |
|
|
186 |
if (factory.persistenceDefinition == null) { |
|
187 |
DynObjectManager dynman = ToolsLocator.getDynObjectManager(); |
|
188 |
factory.persistenceDefinition = |
|
189 |
dynman.createDynClass(PersistenceManager.PERSISTENCE_NAMESPACE, |
|
190 |
PERSISTENCE_TABLE_DOCUMENT_DEFINITION_NAME, |
|
191 |
"Table document Persistence definition"); |
|
192 |
factory.persistenceDefinition.extend(manager |
|
193 |
.getDefinition(AbstractDocument.PERSISTENCE_DEFINITION_NAME)); |
|
194 |
|
|
195 |
factory.persistenceDefinition.addDynFieldObject("store") |
|
196 |
.setClassOfValue(FeatureStore.class).setMandatory(true); |
|
197 |
factory.persistenceDefinition.addDynFieldString("featureTypeId") |
|
198 |
.setMandatory(false); |
|
199 |
factory.persistenceDefinition.addDynFieldArray("attributeNames") |
|
200 |
.setClassOfItems(String.class).setMandatory(false); |
|
201 |
factory.persistenceDefinition.addDynFieldObject("associatedLayer") |
|
202 |
.setClassOfValue(FLyrVect.class).setMandatory(false); |
|
203 |
factory.persistenceDefinition.addDynFieldObject("query") |
|
204 |
.setClassOfValue(FeatureQuery.class).setMandatory(false); |
|
205 |
factory.persistenceDefinition.addDynFieldObject("baseFilter") |
|
206 |
.setClassOfValue(Evaluator.class).setMandatory(false); |
|
207 |
factory.persistenceDefinition.addDynFieldObject("baseOrder") |
|
208 |
.setClassOfValue(FeatureQueryOrder.class).setMandatory(false); |
|
209 |
factory.persistenceDefinition.addDynFieldList("linkTable") |
|
210 |
.setClassOfItems(TableLink.class).setMandatory(false); |
|
211 |
} |
|
212 |
|
|
213 |
|
|
214 |
//Register also the TableLink |
|
215 |
if (manager.getDefinition(PERSISTENCE_TABLELINK_DEFINITION_NAME) == null){ |
|
216 |
DynStruct tableLinkDefinition = |
|
217 |
manager.addDefinition(TableLink.class, |
|
218 |
PERSISTENCE_TABLELINK_DEFINITION_NAME, |
|
219 |
"TableLink Persistence definition", null, null); |
|
220 |
|
|
221 |
tableLinkDefinition.addDynFieldObject("source") |
|
222 |
.setClassOfValue(TableDocument.class).setMandatory(true); |
|
223 |
tableLinkDefinition.addDynFieldObject("target") |
|
224 |
.setClassOfValue(TableDocument.class).setMandatory(true); |
|
225 |
tableLinkDefinition.addDynFieldString("fieldSource").setMandatory(true); |
|
226 |
tableLinkDefinition.addDynFieldString("fieldTarget").setMandatory(true); |
|
227 |
tableLinkDefinition.addDynFieldBoolean("enabled").setMandatory(true); |
|
228 |
} |
|
229 |
} |
|
230 |
|
|
231 |
/** |
|
232 |
* Create a new table document. |
|
233 |
* |
|
234 |
* @return TableDocument. |
|
235 |
*/ |
|
236 |
public AbstractDocument createDocument() { |
|
237 |
return new TableDocument(this); |
|
238 |
} |
|
239 |
|
|
240 |
public Class<? extends IDocumentWindow> getMainWindowClass() { |
|
241 |
return FeatureTableDocumentPanel.class; |
|
242 |
} |
|
243 |
|
|
244 |
public IWindow getMainWindow(Document doc, WindowLayout layout) { |
|
245 |
IDocumentWindow tablePanel; |
|
246 |
tablePanel = |
|
247 |
(IDocumentWindow) PluginServices.getMDIManager() |
|
248 |
.getSingletonWindow(getMainWindowClass(), doc); |
|
249 |
if (tablePanel != null) { |
|
250 |
// The table window document is already created, return it. |
|
251 |
return tablePanel; |
|
252 |
} |
|
253 |
|
|
254 |
tablePanel = (IDocumentWindow) this.createDocumentWindow(doc); |
|
255 |
if (layout != null && tablePanel != null) { |
|
256 |
tablePanel.setWindowLayout(layout); |
|
257 |
} |
|
258 |
return tablePanel; |
|
259 |
} |
|
260 |
|
|
261 |
public IWindow getPropertiesWindow(Document doc) { |
|
262 |
|
|
263 |
// IWindow mainwin = |
|
264 |
// PluginServices.getMDIManager().getSingletonWindow(FeatureTableDocumentPanel.class, |
|
265 |
// doc); |
|
266 |
return new TableProperties((TableDocument) doc); |
|
267 |
} |
|
268 |
|
|
269 |
protected Class<? extends Document> getDocumentClass() { |
|
270 |
return TableDocument.class; |
|
271 |
} |
|
272 |
|
|
273 |
public DynStruct getDefinition(String className) { |
|
274 |
|
|
275 |
if (this.persistenceDefinition.getName().equalsIgnoreCase(className)) { |
|
276 |
return this.persistenceDefinition; |
|
277 |
} |
|
278 |
if (this.persistenceDefinition.getFullName() |
|
279 |
.equalsIgnoreCase(className)) { |
|
280 |
return this.persistenceDefinition; |
|
281 |
} |
|
282 |
if (this.getDocumentClass().getName().equals(className)) { |
|
283 |
return this.persistenceDefinition; |
|
284 |
} |
|
285 |
return null; |
|
286 |
} |
|
287 |
|
|
288 |
public boolean manages(Object object) { |
|
289 |
return object instanceof TableDocument; |
|
290 |
} |
|
291 |
|
|
292 |
public TableDocument getTableDocument(FLyrVect layer) { |
|
293 |
if (layer == null) { |
|
294 |
return null; |
|
295 |
} |
|
296 |
List<Document> tableDocs = |
|
297 |
getProject().getDocuments(TableManager.TYPENAME); |
|
298 |
for (Document document : tableDocs) { |
|
299 |
if (layer == ((TableDocument) document).getAssociatedLayer()) { |
|
300 |
return (TableDocument) document; |
|
301 |
} |
|
302 |
} |
|
303 |
return null; |
|
304 |
} |
|
305 |
|
|
306 |
public void removeTableDocument(FLyrVect layer) { |
|
307 |
TableDocument doc = getTableDocument(layer); |
|
308 |
// Only remove it if it exists |
|
309 |
if (doc != null) { |
|
310 |
PluginServices.getMDIManager().closeSingletonWindow(doc); |
|
311 |
getProject().remove(doc); |
|
312 |
} |
|
313 |
} |
|
314 |
|
|
315 |
private Project getProject() { |
|
316 |
return ProjectManager.getInstance().getCurrentProject(); |
|
317 |
} |
|
318 |
} |
tags/v2_0_0_Build_2047/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/gui/TableProperties.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.gui; |
|
23 |
|
|
24 |
import java.awt.GridLayout; |
|
25 |
|
|
26 |
import javax.swing.JComponent; |
|
27 |
import javax.swing.JPanel; |
|
28 |
|
|
29 |
import org.gvsig.andami.PluginServices; |
|
30 |
import org.gvsig.andami.ui.mdiManager.SingletonWindow; |
|
31 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
|
32 |
import org.gvsig.app.project.documents.table.TableDocument; |
|
33 |
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.FeatureTableConfigurationPanel; |
|
34 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
|
35 |
|
|
36 |
/** |
|
37 |
* Table properties dialog. |
|
38 |
* |
|
39 |
* @author 2004-2005 Fernando Gonz?lez Cort?s |
|
40 |
* @author 2005- Vicente Caballero |
|
41 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team |
|
42 |
*/ |
|
43 |
public class TableProperties extends JPanel implements SingletonWindow { |
|
44 |
|
|
45 |
/** |
|
46 |
* |
|
47 |
*/ |
|
48 |
private static final long serialVersionUID = -3280622997496976100L; |
|
49 |
|
|
50 |
private javax.swing.JLabel jLabel = null; |
|
51 |
private javax.swing.JTextField txtName = null; |
|
52 |
private javax.swing.JLabel jLabel1 = null; |
|
53 |
private javax.swing.JTextField txtDate = null; |
|
54 |
private javax.swing.JTextField txtOwner = null; |
|
55 |
private javax.swing.JLabel jLabel2 = null; |
|
56 |
private javax.swing.JLabel jLabel3 = null; |
|
57 |
private javax.swing.JScrollPane jScrollPane = null; |
|
58 |
private javax.swing.JTextArea txtComments = null; |
|
59 |
private TableDocument tableDocument; |
|
60 |
private AcceptCancelPanel okCancelPanel = null; |
|
61 |
private javax.swing.JPanel jPanel = null; |
|
62 |
private javax.swing.JPanel jPanel1 = null; |
|
63 |
|
|
64 |
private JPanel configPanel; |
|
65 |
|
|
66 |
/** |
|
67 |
* This is the default constructor |
|
68 |
* |
|
69 |
* @param f |
|
70 |
* Frame padre del di?logo |
|
71 |
* @param t |
|
72 |
* Tabla que se representa en el di?logo |
|
73 |
*/ |
|
74 |
public TableProperties(TableDocument t) { |
|
75 |
tableDocument = t; |
|
76 |
initialize(); |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* This method initializes this |
|
81 |
*/ |
|
82 |
private void initialize() { |
|
83 |
|
Also available in: Unified diff