Revision 38497
tags/v2_0_0_Build_2049/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
3 |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
4 |
<modelVersion>4.0.0</modelVersion> |
|
5 |
<packaging>jar</packaging> |
|
6 |
<artifactId>org.gvsig.app.document.table.app.mainplugin</artifactId> |
|
7 |
<name>Document: Table</name> |
|
8 |
<description>Adds a table document type which shows information data sources with Features or from an already open View document. Also allows editing on data sources that allow so.</description> |
|
9 |
<parent> |
|
10 |
<groupId>org.gvsig</groupId> |
|
11 |
<artifactId>org.gvsig.app.document.table.app</artifactId> |
|
12 |
<version>2.0.0-SNAPSHOT</version> |
|
13 |
</parent> |
|
14 |
<dependencies> |
|
15 |
<dependency> |
|
16 |
<groupId>org.gvsig</groupId> |
|
17 |
<artifactId>org.gvsig.core.maven.dependencies</artifactId> |
|
18 |
<version>2.0.1-SNAPSHOT</version> |
|
19 |
<type>pom</type> |
|
20 |
<scope>test</scope> |
|
21 |
</dependency> |
|
22 |
<dependency> |
|
23 |
<groupId>org.gvsig</groupId> |
|
24 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
25 |
<scope>compile</scope> |
|
26 |
</dependency> |
|
27 |
<dependency> |
|
28 |
<groupId>org.gvsig</groupId> |
|
29 |
<artifactId>org.gvsig.tools.swing.api</artifactId> |
|
30 |
<scope>compile</scope> |
|
31 |
</dependency> |
|
32 |
<dependency> |
|
33 |
<groupId>org.gvsig</groupId> |
|
34 |
<artifactId>org.gvsig.app</artifactId> |
|
35 |
<scope>compile</scope> |
|
36 |
</dependency> |
|
37 |
<dependency> |
|
38 |
<groupId>org.gvsig</groupId> |
|
39 |
<artifactId>org.gvsig.andami</artifactId> |
|
40 |
<scope>compile</scope> |
|
41 |
</dependency> |
|
42 |
<dependency> |
|
43 |
<groupId>org.gvsig</groupId> |
|
44 |
<artifactId>org.gvsig.fmap.dal</artifactId> |
|
45 |
<scope>compile</scope> |
|
46 |
</dependency> |
|
47 |
<dependency> |
|
48 |
<groupId>org.gvsig</groupId> |
|
49 |
<artifactId>org.gvsig.fmap.dal.file</artifactId> |
|
50 |
<scope>compile</scope> |
|
51 |
</dependency> |
|
52 |
<dependency> |
|
53 |
<groupId>org.gvsig</groupId> |
|
54 |
<artifactId>org.gvsig.fmap.control</artifactId> |
|
55 |
<scope>compile</scope> |
|
56 |
</dependency> |
|
57 |
<dependency> |
|
58 |
<groupId>org.gvsig</groupId> |
|
59 |
<artifactId>org.gvsig.fmap.mapcontext</artifactId> |
|
60 |
<scope>compile</scope> |
|
61 |
</dependency> |
|
62 |
<dependency> |
|
63 |
<groupId>org.gvsig</groupId> |
|
64 |
<artifactId>org.gvsig.utils</artifactId> |
|
65 |
<scope>compile</scope> |
|
66 |
</dependency> |
|
67 |
<dependency> |
|
68 |
<groupId>org.gvsig</groupId> |
|
69 |
<artifactId>org.gvsig.ui</artifactId> |
|
70 |
<scope>compile</scope> |
|
71 |
</dependency> |
|
72 |
<dependency> |
|
73 |
<groupId>org.gvsig</groupId> |
|
74 |
<artifactId>org.gvsig.projection</artifactId> |
|
75 |
<scope>compile</scope> |
|
76 |
</dependency> |
|
77 |
<dependency> |
|
78 |
<groupId>org.gvsig</groupId> |
|
79 |
<artifactId>org.gvsig.fmap.geometry</artifactId> |
|
80 |
<scope>compile</scope> |
|
81 |
</dependency> |
|
82 |
<dependency> |
|
83 |
<groupId>org.gvsig</groupId> |
|
84 |
<artifactId>org.gvsig.metadata.lib.basic.api</artifactId> |
|
85 |
<scope>compile</scope> |
|
86 |
</dependency> |
|
87 |
<dependency> |
|
88 |
<groupId>org.gvsig</groupId> |
|
89 |
<artifactId>org.gvsig.timesupport.lib.api</artifactId> |
|
90 |
<scope>compile</scope> |
|
91 |
</dependency> |
|
92 |
</dependencies> |
|
93 |
<profiles> |
|
94 |
<profile> |
|
95 |
<id>gvsig-install</id> |
|
96 |
<activation> |
|
97 |
<activeByDefault>true</activeByDefault> |
|
98 |
</activation> |
|
99 |
<properties> |
|
100 |
<!-- |
|
101 |
Default gvSIG installation folder relative to the current workspace |
|
102 |
--> |
|
103 |
<gvsig.install.dir>${basedir}/../../build/product</gvsig.install.dir> |
|
104 |
</properties> |
|
105 |
</profile> |
|
106 |
</profiles> |
|
107 |
<properties> |
|
108 |
<package.info.dependencies>required: org.gvsig.app -ge 2.0-2036</package.info.dependencies> |
|
109 |
<package.info.categories>Table</package.info.categories> |
|
110 |
</properties> |
|
111 |
</project> |
tags/v2_0_0_Build_2049/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_2049/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/buildNumber.properties | ||
---|---|---|
1 |
#maven.buildNumber.plugin properties file |
|
2 |
#Mon Jun 25 11:21:40 CEST 2012 |
|
3 |
buildNumber=15 |
tags/v2_0_0_Build_2049/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_2049/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_2049/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/fmap/dal/serverexplorer/filesystem/swing/FilesystemExplorerTableWizardPanel.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 IVER T.I. S.A. {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.fmap.dal.serverexplorer.filesystem.swing; |
|
29 |
|
|
30 |
import java.awt.Window; |
|
31 |
import java.util.ArrayList; |
|
32 |
import java.util.List; |
|
33 |
|
|
34 |
import org.cresques.cts.IProjection; |
|
35 |
import org.gvsig.andami.PluginServices; |
|
36 |
import org.gvsig.andami.messages.NotificationManager; |
|
37 |
import org.gvsig.app.ApplicationLocator; |
|
38 |
import org.gvsig.app.ApplicationManager; |
|
39 |
import org.gvsig.app.prepareAction.PrepareContext; |
|
40 |
import org.gvsig.app.project.Project; |
|
41 |
import org.gvsig.app.project.ProjectManager; |
|
42 |
import org.gvsig.app.project.documents.table.TableDocument; |
|
43 |
import org.gvsig.app.project.documents.table.TableManager; |
|
44 |
import org.gvsig.fmap.dal.DALLocator; |
|
45 |
import org.gvsig.fmap.dal.DataManager; |
|
46 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
47 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
48 |
|
|
49 |
public class FilesystemExplorerTableWizardPanel extends |
|
50 |
FilesystemExplorerWizardPanel { |
|
51 |
|
|
52 |
private static final long serialVersionUID = 8469934188826417698L; |
|
53 |
|
|
54 |
private PrepareContext prepareDSContext = null; |
|
55 |
|
|
56 |
|
|
57 |
@Override |
|
58 |
public void execute() { |
|
59 |
executeWizard(); |
|
60 |
} |
|
61 |
|
|
62 |
public Object executeWizard() { |
|
63 |
FeatureStore store; |
|
64 |
TableDocument table; |
|
65 |
|
|
66 |
ApplicationManager manager = ApplicationLocator.getManager(); |
|
67 |
Project project = manager.getCurrentProject(); |
|
68 |
|
|
69 |
PrepareContext context = this.getPrepareDataStoreContext(); |
|
70 |
DataStoreParameters[] parameters = this.getParameters(); |
|
71 |
List<TableDocument> tabledocs = |
|
72 |
new ArrayList<TableDocument>(parameters.length); |
|
73 |
for (DataStoreParameters params : parameters) { |
|
74 |
store = null; |
|
75 |
try { |
|
76 |
DataManager dataManager = DALLocator.getDataManager(); |
|
77 |
store = |
|
78 |
(FeatureStore) dataManager.openStore( |
|
79 |
params.getDataStoreName(), params); |
|
80 |
manager.pepareOpenDataSource(store, context); |
|
81 |
|
|
82 |
table = |
|
83 |
(TableDocument) ProjectManager.getInstance() |
|
84 |
.createDocument(TableManager.TYPENAME); |
|
85 |
table.setName(store.getName()); |
|
86 |
table.setStore(store); |
|
87 |
|
|
88 |
// project.add(table); |
|
89 |
tabledocs.add(table); |
|
90 |
} catch (Exception e) { |
|
91 |
if (store != null) { |
|
92 |
store.dispose(); |
|
93 |
} |
|
94 |
NotificationManager.addError(e); |
|
95 |
} |
|
96 |
|
|
97 |
} |
|
98 |
return tabledocs; |
|
99 |
} |
|
100 |
|
|
101 |
@Override |
|
102 |
protected PrepareContext getPrepareDataStoreContext() { |
|
103 |
if (this.prepareDSContext == null) { |
|
104 |
this.prepareDSContext = new PrepareContext() { |
|
105 |
|
|
106 |
public Window getOwnerWindow() { |
|
107 |
return null; |
|
108 |
} |
|
109 |
|
|
110 |
public IProjection getViewProjection() { |
|
111 |
return null; |
|
112 |
} |
|
113 |
|
|
114 |
}; |
|
115 |
} |
|
116 |
return this.prepareDSContext; |
|
117 |
} |
|
118 |
|
|
119 |
public String getTabName() { |
|
120 |
return PluginServices.getText(this, "File"); |
|
121 |
} |
|
122 |
|
|
123 |
} |
tags/v2_0_0_Build_2049/extensions/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/fmap/dal/serverexplorer/filesystem/swing/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>Open table document from file support</p> |
|
11 |
|
|
12 |
</body> |
|
13 |
</html> |
tags/v2_0_0_Build_2049/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.mapcontext.layers.vectorial.VectorLayer; |
|
53 |
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.FeatureStoreModel; |
|
54 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
55 |
import org.gvsig.tools.evaluator.Evaluator; |
|
56 |
import org.gvsig.tools.exception.BaseException; |
|
57 |
import org.gvsig.tools.observer.Observable; |
|
58 |
import org.gvsig.tools.observer.Observer; |
|
59 |
import org.gvsig.tools.persistence.Persistent; |
|
60 |
import org.gvsig.tools.persistence.PersistentState; |
|
61 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
62 |
|
|
63 |
/** |
|
64 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
|
65 |
*/ |
|
66 |
public class TableDocument extends AbstractDocument implements Observer { |
|
67 |
|
|
68 |
private static final long serialVersionUID = -1842181135614158881L; |
|
69 |
|
|
70 |
final static private Logger logger = LoggerFactory |
|
71 |
.getLogger(TableDocument.class); |
|
72 |
|
|
73 |
private FeatureStore store; |
|
74 |
|
|
75 |
private String featureTypeId; |
|
76 |
|
|
77 |
private String[] attributeNames; |
|
78 |
|
|
79 |
private List<TableLink> linkTable; |
|
80 |
|
|
81 |
private VectorLayer associatedLayer; |
|
82 |
|
|
83 |
private FeatureQuery query; |
|
84 |
|
|
85 |
private Evaluator baseFilter; |
|
86 |
|
|
87 |
private FeatureQueryOrder baseOrder; |
|
88 |
|
|
89 |
private FeatureStoreModel featureStoreModel; |
|
90 |
|
|
91 |
private Object lock = new Object(); |
|
92 |
|
|
93 |
public TableDocument(DocumentManager factory) { |
|
94 |
super(factory); |
|
95 |
this.store = null; |
|
96 |
this.query = null; |
|
97 |
this.featureTypeId = null; |
|
98 |
this.baseFilter = null; |
|
99 |
this.baseOrder = null; |
|
100 |
} |
|
101 |
|
|
102 |
public TableDocument() { |
|
103 |
this(null); |
|
104 |
} |
|
105 |
|
|
106 |
public TableDocument(DocumentManager factory, FeatureStore store) { |
|
107 |
this(factory); |
|
108 |
setStore(store); |
|
109 |
} |
|
110 |
|
|
111 |
public FeatureStoreModel getFeatureStoreModel() { |
|
112 |
synchronized (lock) { |
|
113 |
if (this.featureStoreModel == null) { |
|
114 |
try { |
|
115 |
this.featureStoreModel = |
|
116 |
new FeatureStoreModel(getStore(), getQuery()); |
|
117 |
} catch (BaseException e) { |
|
118 |
NotificationManager.addError(e); |
|
119 |
} |
|
120 |
} |
|
121 |
} |
|
122 |
return this.featureStoreModel; |
|
123 |
} |
|
124 |
|
|
125 |
public void setStore(FeatureStore store) { |
|
126 |
if (this.store != null) { |
|
127 |
throw new UnsupportedOperationException( |
|
128 |
"can't set store. store already set."); |
|
129 |
} |
|
130 |
this.store = store; |
|
131 |
this.store.addObserver(this); |
|
132 |
this.query = null; // setQuery(store.createFeatureQuery()); |
|
133 |
} |
|
134 |
|
|
135 |
@SuppressWarnings("unchecked") |
|
136 |
public FeatureQuery getQuery() { |
|
137 |
if (this.query == null) { |
|
138 |
try { |
|
139 |
FeatureType fType = null; |
|
140 |
this.query = this.store.createFeatureQuery(); |
|
141 |
if (this.featureTypeId != null) { |
|
142 |
Iterator<FeatureType> iter; |
|
143 |
iter = this.store.getFeatureTypes().iterator(); |
|
144 |
while (iter.hasNext()) { |
|
145 |
fType = iter.next(); |
|
146 |
if (this.featureTypeId.equals(fType.getId())) { |
|
147 |
this.query.setFeatureType(fType); |
|
148 |
break; |
|
149 |
} |
|
150 |
} |
|
151 |
if (fType == null) { |
|
152 |
throw new RuntimeException(MessageFormat.format( |
|
153 |
"frature type {1} not found.", this.featureTypeId)); |
|
154 |
} |
|
155 |
|
|
156 |
} else { |
|
157 |
fType = store.getDefaultFeatureType(); |
|
158 |
} |
|
159 |
|
|
160 |
if (this.attributeNames != null) { |
|
161 |
ArrayList<String> newNames = new ArrayList<String>(); |
|
162 |
for (String name : this.attributeNames) { |
|
163 |
if (fType.getIndex(name) > -1) { |
|
164 |
newNames.add(name); |
|
165 |
} |
|
166 |
} |
|
167 |
if (newNames.size() > 0) { |
|
168 |
this.query.setAttributeNames(newNames |
|
169 |
.toArray(this.attributeNames)); |
|
170 |
} |
|
171 |
} |
|
172 |
|
|
173 |
this.query.setFilter(this.baseFilter); // TODO check is valid |
|
174 |
this.query.setOrder(this.baseOrder); |
|
175 |
|
|
176 |
} catch (DataException e) { |
|
177 |
NotificationManager.addError(e); |
|
178 |
return null; |
|
179 |
} |
|
180 |
|
|
181 |
} |
|
182 |
return this.query; |
|
183 |
} |
|
184 |
|
|
185 |
/** |
|
186 |
* @return the store |
|
187 |
*/ |
|
188 |
public FeatureStore getStore() { |
|
189 |
return store; |
|
190 |
} |
|
191 |
|
|
192 |
/** |
|
193 |
* Return information about the table links. |
|
194 |
* |
|
195 |
* @return List of TableLink information. |
|
196 |
*/ |
|
197 |
public List<TableLink> getLinks() { |
|
198 |
return this.linkTable; |
|
199 |
} |
|
200 |
|
|
201 |
/** |
|
202 |
* Returns if this table document has links with other tables. |
|
203 |
* |
|
204 |
* @return if this table document has links with other tables |
|
205 |
*/ |
|
206 |
public boolean hasLinks() { |
|
207 |
return this.linkTable != null && this.linkTable.size() > 0; |
|
208 |
} |
|
209 |
|
|
210 |
/** |
|
211 |
* Devuelve el identificador de la tabla que contiene el link. |
|
212 |
* |
|
213 |
* @return identificador ?nico de la tabla. |
|
214 |
* @deprecated see {{@link #getLinks()} |
|
215 |
*/ |
|
216 |
public String getLinkTable() { |
|
217 |
if (linkTable == null || linkTable.isEmpty()) { |
|
218 |
return null; |
|
219 |
} |
|
220 |
return linkTable.get(0).getTargetTable().getName(); |
|
221 |
} |
|
222 |
|
|
223 |
/** |
|
224 |
* Devuelve el nombre del campo de la tabla a enlazar. |
|
225 |
* |
|
226 |
* @return Nombre del campo de la tabla a enlazar. |
|
227 |
* @deprecated see {{@link #getLink()} |
|
228 |
*/ |
|
229 |
public String getField1() { |
|
230 |
if (linkTable.isEmpty()) { |
|
231 |
return null; |
|
232 |
} |
|
233 |
return this.linkTable.get(0).getSourceFieldName(); |
|
234 |
} |
|
235 |
|
|
236 |
/** |
|
237 |
* Devuelve el nombre del campo de la tabla enlazada. |
|
238 |
* |
|
239 |
* @return Nombre del campo de la tabla enlazada. |
|
240 |
* @deprecated see {{@link #getLink()} |
|
241 |
*/ |
|
242 |
public String getField2() { |
|
243 |
if (linkTable.isEmpty()) { |
|
244 |
return null; |
|
245 |
} |
|
246 |
return this.linkTable.get(0).getTargetFieldName(); |
|
247 |
} |
|
248 |
|
|
249 |
/** |
|
250 |
* Enlaza la seleccion de esta tabla con la de la tabla indicada |
|
251 |
* |
|
252 |
* @deprecated see {@link #addLinkTable(String, String, String)} |
|
253 |
*/ |
|
254 |
public void setLinkTable(String targetTable, String fieldSource, |
|
255 |
String fieldTarget) { |
|
256 |
this.addLinkTable(targetTable, fieldSource, fieldTarget); |
|
257 |
} |
|
258 |
|
|
259 |
/** |
|
260 |
* Add a table link to this document. |
|
261 |
* |
|
262 |
* @param targetTable |
|
263 |
* @param fieldSource |
|
264 |
* @param fieldTarget |
|
265 |
*/ |
|
266 |
public void addLinkTable(String targetTable, String fieldSource, |
|
267 |
String fieldTarget) { |
|
268 |
TableDocument target = |
|
269 |
(TableDocument) ProjectManager.getInstance().getCurrentProject() |
|
270 |
.getDocument(targetTable, TableManager.TYPENAME); |
|
271 |
TableLink link = new TableLink(this, target, fieldSource, fieldTarget); |
|
272 |
link.setEnabled(true); |
|
273 |
if (this.linkTable == null) { |
|
274 |
this.linkTable = new ArrayList<TableLink>(); |
|
275 |
} |
|
276 |
this.linkTable.add(link); |
|
277 |
} |
|
278 |
|
|
279 |
/** |
|
280 |
* remove the last link to table added. |
|
281 |
* |
|
282 |
*/ |
|
283 |
public void removeLinkTable() { |
|
284 |
if (linkTable.isEmpty()) { |
|
285 |
return; |
|
286 |
} |
|
287 |
TableLink link = this.linkTable.remove(this.linkTable.size() - 1); |
|
288 |
link.setEnabled(false); |
|
289 |
this.linkTable = null; |
|
290 |
} |
|
291 |
|
|
292 |
/** |
|
293 |
* Remove the link to the table document. |
|
294 |
* |
|
295 |
* @param name |
|
296 |
* of table document to remove. |
|
297 |
*/ |
|
298 |
public void removeLinkTable(String name) { |
|
299 |
for (TableLink link : this.linkTable) { |
|
300 |
if (name.equals(link.target.getName())) { |
|
301 |
link.setEnabled(false); |
|
302 |
this.linkTable.remove(link); |
|
303 |
} |
|
304 |
} |
|
305 |
} |
|
306 |
|
|
307 |
public VectorLayer getAssociatedLayer() { |
|
308 |
return associatedLayer; |
|
309 |
} |
|
310 |
|
|
311 |
public void setAssociatedLayer(VectorLayer associatedLayer) { |
|
312 |
this.associatedLayer = associatedLayer; |
|
313 |
} |
|
314 |
|
|
315 |
public void update(Observable arg0, Object arg1) { |
|
316 |
if (this.store.equals(arg0)) { |
|
317 |
if (arg1 instanceof FeatureStoreNotification) { |
|
318 |
FeatureStoreNotification event = |
|
319 |
(FeatureStoreNotification) arg1; |
|
320 |
if (event.getType() == FeatureStoreNotification.TRANSFORM_CHANGE |
|
321 |
|| event.getType() == FeatureStoreNotification.RESOURCE_CHANGED) { |
|
322 |
this.query = null; |
|
323 |
} |
|
324 |
} |
|
325 |
|
|
326 |
} |
|
327 |
|
|
328 |
} |
|
329 |
|
|
330 |
@SuppressWarnings("unchecked") |
|
331 |
public void loadFromState(PersistentState state) |
|
332 |
throws PersistenceException { |
|
333 |
super.loadFromState(state); |
|
334 |
|
|
335 |
this.store = (FeatureStore) state.get("store"); |
|
336 |
this.featureTypeId = state.getString("featureTypeId"); |
|
337 |
this.attributeNames = |
|
338 |
(String[]) state.getArray("attributeNames", String.class); |
|
339 |
this.linkTable = state.getList("linkTable"); |
|
340 |
this.associatedLayer = (FLyrVect) state.get("associatedLayer"); |
|
341 |
this.query = (FeatureQuery) state.get("query"); |
|
342 |
this.baseFilter = (Evaluator) state.get("baseFilter"); |
|
343 |
this.baseOrder = (FeatureQueryOrder) state.get("baseOrder"); |
|
344 |
} |
|
345 |
|
|
346 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
347 |
super.saveToState(state); |
|
348 |
|
|
349 |
state.set("store", store); |
|
350 |
state.set("featureTypeId", featureTypeId); |
|
351 |
state.set("attributeNames", attributeNames); |
|
352 |
state.set("linkTable", linkTable); |
|
353 |
state.set("associatedLayer", associatedLayer); |
|
354 |
state.set("query", query); |
|
355 |
// state.set("baseFilter", baseFilter); |
|
356 |
state.set("baseOrder", baseOrder); |
|
357 |
} |
|
358 |
|
|
359 |
public static class TableLink implements Observer, Persistent { |
|
360 |
|
|
361 |
private TableDocument source; |
|
362 |
private FeatureStore storeSource; |
|
363 |
private int fieldSource; |
|
364 |
|
|
365 |
private TableDocument target; |
|
366 |
private FeatureStore storeTarget; |
|
367 |
private int fieldTarget; |
|
368 |
|
|
369 |
private boolean enabled; |
|
370 |
|
|
371 |
public TableLink() { |
|
372 |
this.source = null; |
|
373 |
this.target = null; |
|
374 |
this.fieldSource = -1; |
|
375 |
this.fieldTarget = -1; |
|
376 |
this.storeSource = null; |
|
377 |
this.storeTarget = null; |
|
378 |
this.enabled = false; |
|
379 |
} |
|
380 |
|
|
381 |
public TableLink(TableDocument source, TableDocument target, |
|
382 |
String fieldSource, String fieldTarget) { |
|
383 |
this(); |
|
384 |
this.initialize(source, target, fieldSource, fieldTarget); |
|
385 |
} |
|
386 |
|
|
387 |
private void initialize(TableDocument source, TableDocument target, |
|
388 |
String fieldSource, String fieldTarget) { |
|
389 |
this.source = source; |
|
390 |
this.target = target; |
|
391 |
|
|
392 |
this.storeSource = this.source.getStore(); |
|
393 |
this.storeTarget = this.target.getStore(); |
|
394 |
try { |
|
395 |
this.fieldSource = |
|
396 |
storeSource.getDefaultFeatureType().getIndex(fieldSource); |
|
397 |
this.fieldTarget = |
|
398 |
storeTarget.getDefaultFeatureType().getIndex(fieldTarget); |
|
399 |
} catch (DataException ex) { |
|
400 |
logger.error("Can't initialize TableLink", ex); |
|
401 |
throw new RuntimeException("Can't initialize TableLink", ex); |
|
402 |
} |
|
403 |
} |
|
404 |
|
|
405 |
public void setEnabled(boolean enabled) { |
|
406 |
if (enabled) { |
|
407 |
this.storeSource.addObserver(this); |
|
408 |
} else { |
|
409 |
this.storeSource.deleteObserver(this); |
|
410 |
} |
|
411 |
this.enabled = enabled; |
|
412 |
} |
|
413 |
|
|
414 |
public boolean getEnabled() { |
|
415 |
return this.enabled; |
|
416 |
} |
|
417 |
|
|
418 |
public TableDocument getTargetTable() { |
|
419 |
return this.target; |
|
420 |
} |
|
421 |
|
|
422 |
public TableDocument getSourceTable() { |
|
423 |
return this.source; |
|
424 |
} |
|
425 |
|
|
426 |
public String getSourceFieldName() { |
|
427 |
try { |
|
428 |
return ((FeatureAttributeDescriptor) this.storeSource |
|
429 |
.getDefaultFeatureType().get(this.fieldSource)).getName(); |
|
430 |
} catch (DataException e) { |
|
431 |
logger.warn("Can't get source field name.", e); |
|
432 |
return null; |
|
433 |
} |
|
434 |
} |
|
435 |
|
|
436 |
public String getTargetFieldName() { |
|
437 |
try { |
|
438 |
return ((FeatureAttributeDescriptor) this.storeTarget |
|
439 |
.getDefaultFeatureType().get(this.fieldTarget)).getName(); |
|
440 |
} catch (DataException e) { |
|
441 |
logger.warn("Can't get target field name.", e); |
|
442 |
return null; |
|
443 |
} |
|
444 |
} |
|
445 |
|
|
446 |
public void update(Observable arg0, Object arg1) { |
|
447 |
try { |
|
448 |
FeatureSet fCollection1 = |
|
449 |
(FeatureSet) storeSource.getSelection(); |
|
450 |
FeatureSelection fCollection2 = |
|
451 |
(FeatureSelection) storeTarget.createSelection(); |
|
452 |
List<Object> idx = new ArrayList<Object>(); |
|
453 |
|
|
454 |
// Construimos el ?ndice |
|
455 |
DisposableIterator iterator1 = null; |
|
456 |
try { |
|
457 |
iterator1 = fCollection1.fastIterator(); |
|
458 |
while (iterator1.hasNext()) { |
|
459 |
Feature feature = (Feature) iterator1.next(); |
|
460 |
Object obj = feature.get(fieldSource); |
|
461 |
if (!idx.contains(obj)) { |
|
462 |
idx.add(obj); |
|
463 |
} |
|
464 |
} |
|
465 |
} finally { |
|
466 |
if (iterator1 != null) { |
|
467 |
iterator1.dispose(); |
|
468 |
} |
|
469 |
} |
|
470 |
FeatureSet set = null; |
|
471 |
DisposableIterator iterator2 = null; |
|
472 |
|
|
473 |
try { |
|
474 |
set = storeTarget.getFeatureSet(); |
|
475 |
iterator2 = set.fastIterator(); |
|
476 |
while (iterator2.hasNext()) { |
|
477 |
Feature feature = (Feature) iterator2.next(); |
|
478 |
Object obj = feature.get(fieldTarget); |
|
479 |
if (idx.contains(obj)) { |
|
480 |
fCollection2.select(feature); |
|
481 |
} |
|
482 |
} |
|
483 |
} catch (DataException e1) { |
|
484 |
NotificationManager.addError(e1); |
|
485 |
return; |
|
486 |
} finally { |
|
487 |
if (iterator2 != null) { |
|
488 |
iterator2.dispose(); |
|
489 |
} |
|
490 |
if (set != null) { |
|
491 |
set.dispose(); |
|
492 |
} |
|
493 |
} |
|
494 |
|
|
495 |
// this applies the selection to the linked table |
|
496 |
if (storeSource != storeTarget) { |
|
497 |
storeTarget.setSelection(fCollection2); |
|
498 |
} |
|
499 |
} catch (DataException e2) { |
|
500 |
NotificationManager.addError(e2); |
|
501 |
return; |
|
502 |
} |
|
503 |
} |
|
504 |
|
|
505 |
public void loadFromState(PersistentState state) |
|
506 |
throws PersistenceException { |
|
507 |
this.initialize((TableDocument) state.get("source"), |
|
508 |
(TableDocument) state.get("target"), |
|
509 |
state.getString("fieldSource"), state.getString("fieldTarget")); |
|
510 |
this.setEnabled(state.getBoolean("enabled")); |
|
511 |
} |
|
512 |
|
|
513 |
public void saveToState(PersistentState state) |
|
514 |
throws PersistenceException { |
|
515 |
state.set("source", this.source); |
|
516 |
state.set("target", this.target); |
|
517 |
state.set("fieldSource", this.getSourceFieldName()); |
|
518 |
state.set("fieldTarget", this.getTargetFieldName()); |
|
519 |
state.set("enabled", this.getEnabled()); |
|
520 |
} |
|
521 |
|
|
522 |
} |
|
523 |
|
|
524 |
} |
tags/v2_0_0_Build_2049/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_2049/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_2049/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.DataServerExplorerParameters; |
|
46 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
47 |
import org.gvsig.fmap.dal.DataTypes; |
|
48 |
import org.gvsig.fmap.dal.exception.DataException; |
|
49 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
50 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
51 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
52 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
53 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
54 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
|
55 |
|
|
56 |
/** |
|
57 |
* Class to create dbf and csv files at disk with the statistics group generated |
|
58 |
* from a table. |
|
59 |
* |
|
60 |
* dbf -> Data Base File |
|
61 |
* csv -> Comma Separated Value |
|
62 |
* |
|
63 |
* @author ?ngel Fraile Gri??n e-mail: angel.fraile@iver.es |
|
64 |
* |
|
65 |
*/ |
|
66 |
|
|
67 |
public class ExportStatisticsFile { |
|
68 |
|
|
69 |
private static final Logger logger = LoggerFactory |
|
70 |
.getLogger(ExportStatisticsFile.class); |
|
71 |
|
|
72 |
private String lastPath = null; |
|
73 |
private Hashtable<String, MyFileFilter> dbfExtensionsSupported; // Supported |
|
74 |
// extensions. |
|
75 |
private Hashtable<String, MyFileFilter> csvExtensionsSupported; |
|
76 |
|
|
77 |
public ExportStatisticsFile(List<MyObjectStatistics> valores) { |
|
78 |
|
|
79 |
JFileChooser jfc = new JFileChooser(lastPath); |
|
80 |
jfc.removeChoosableFileFilter(jfc.getAcceptAllFileFilter()); |
|
81 |
|
|
82 |
// Adding required extensions (dbf, csv) |
|
83 |
dbfExtensionsSupported = new Hashtable<String, MyFileFilter>(); |
|
84 |
csvExtensionsSupported = new Hashtable<String, MyFileFilter>(); |
|
85 |
dbfExtensionsSupported.put("dbf", new MyFileFilter("dbf", |
|
86 |
PluginServices.getText(this, "Ficheros_dbf"), "dbf")); |
|
87 |
csvExtensionsSupported.put("csv", new MyFileFilter("csv", |
|
88 |
PluginServices.getText(this, "Ficheros_csv"), "csv")); |
|
89 |
|
|
90 |
Iterator<MyFileFilter> iter = |
|
91 |
csvExtensionsSupported.values().iterator(); |
|
92 |
while (iter.hasNext()) { |
|
93 |
jfc.addChoosableFileFilter(iter.next()); |
|
94 |
} |
|
95 |
|
|
96 |
iter = dbfExtensionsSupported.values().iterator(); |
|
97 |
while (iter.hasNext()) { |
|
98 |
jfc.addChoosableFileFilter(iter.next()); |
|
99 |
} |
|
100 |
|
|
101 |
// Opening a JFileCooser |
|
102 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
|
103 |
File endFile = jfc.getSelectedFile(); |
|
104 |
if (endFile.exists()) {// File exists in the directory. |
|
105 |
int resp = |
|
106 |
JOptionPane.showConfirmDialog( |
|
107 |
(Component) PluginServices.getMainFrame(), |
|
108 |
PluginServices.getText(this, |
|
109 |
"fichero_ya_existe_seguro_desea_guardarlo") |
|
110 |
+ "\n" |
|
111 |
+ endFile.getAbsolutePath(), PluginServices |
|
112 |
.getText(this, "guardar"), |
|
113 |
JOptionPane.YES_NO_OPTION);// Informing the user |
|
114 |
if (resp != JOptionPane.YES_OPTION) {// cancel pressed. |
|
115 |
return; |
|
116 |
} |
|
117 |
}// end if exits. |
|
118 |
MyFileFilter filter = (MyFileFilter) jfc.getFileFilter();// dbf, csv |
|
119 |
endFile = filter.normalizeExtension(endFile);// "name" + "." + |
|
120 |
// "dbf", "name" + "." |
|
121 |
// + "csv" |
|
122 |
|
|
123 |
if (filter.getExtensionOfAFile(endFile).toLowerCase() |
|
124 |
.compareTo("csv") == 0) { // csv file |
|
125 |
exportToCSVFile(valores, endFile); // export to csv format |
|
126 |
} else |
|
127 |
if (filter.getExtensionOfAFile(endFile).toLowerCase() |
|
128 |
.compareTo("dbf") == 0) {// dbf file |
|
129 |
try { |
|
130 |
exportToDBFFile(valores, endFile); |
|
131 |
} catch (Exception e) { |
|
132 |
NotificationManager.addError(e); |
|
133 |
} // export to dbf format |
|
134 |
} |
|
135 |
}// end if aprove option. |
|
136 |
} |
|
137 |
|
|
138 |
/** |
|
139 |
* Creating cvs format file with the statistics. |
|
140 |
* Option to select the two columns separator. |
|
141 |
* |
|
142 |
* Example with semicolon: Name;data\n |
|
143 |
* Name2;data2\n |
|
144 |
* |
|
145 |
* @param valores |
|
146 |
* - Pairs: String name (key) + Double value ( |
|
147 |
* @param endFile |
|
148 |
* - File to write the information |
|
149 |
*/ |
|
150 |
|
|
151 |
private void exportToCSVFile(List<MyObjectStatistics> valores, File endFile) { |
|
152 |
|
|
153 |
try { |
|
154 |
CSVSeparatorOptionsPanel csvSeparatorOptions = |
|
155 |
new CSVSeparatorOptionsPanel(); |
|
156 |
PluginServices.getMDIManager().addWindow(csvSeparatorOptions); |
|
157 |
|
|
158 |
String separator = csvSeparatorOptions.getSeparator(); |
|
159 |
|
|
160 |
if (separator != null) { |
|
161 |
|
|
162 |
FileWriter fileCSV = new FileWriter(endFile); |
|
163 |
|
|
164 |
fileCSV.write(PluginServices.getText(this, "Nombre") |
|
165 |
+ separator + PluginServices.getText(this, "Valor") + "\n"); |
|
166 |
|
|
167 |
Iterator<MyObjectStatistics> iterador = valores.listIterator(); |
|
168 |
|
|
169 |
while (iterador.hasNext()) {// Writing value,value\n |
|
170 |
MyObjectStatistics data = iterador.next(); |
|
171 |
fileCSV.write(data.getKey() + separator + (data.getValue()) |
|
172 |
+ "\n"); |
|
173 |
} |
|
174 |
fileCSV.close(); |
|
175 |
JOptionPane.showMessageDialog( |
|
176 |
null, |
|
177 |
PluginServices.getText(this, "fichero_creado_en") + " " |
|
178 |
+ endFile.getAbsolutePath(), |
|
179 |
PluginServices.getText(this, "fichero_creado_en_formato") |
|
180 |
+ " csv " |
|
181 |
+ PluginServices.getText(this, "mediante_el_separador") |
|
182 |
+ " \"" + separator + "\"", |
|
183 |
JOptionPane.INFORMATION_MESSAGE);// Informing the user |
|
184 |
} else { |
|
185 |
return; |
|
186 |
} |
|
187 |
|
|
188 |
} catch (IOException e) {// Informing the user |
|
189 |
logger.error("Error exportando a formato csv"); |
|
190 |
JOptionPane.showMessageDialog( |
|
191 |
null, |
|
192 |
PluginServices.getText(this, |
|
193 |
"Error_exportando_las_estadisticas") |
|
194 |
+ " " |
|
195 |
+ endFile.getAbsolutePath(), PluginServices.getText(this, |
|
196 |
"Error"), JOptionPane.ERROR_MESSAGE); |
|
197 |
} |
|
198 |
|
|
199 |
} |
|
200 |
|
|
201 |
public void exportToDBFFile(List<MyObjectStatistics> valores, File endFile) |
|
202 |
throws DataException, ValidateDataParametersException { |
|
203 |
DataManager datamanager = DALLocator.getDataManager(); |
|
204 |
|
|
205 |
// |
|
206 |
// Averigua el proveedor en funcion del fichero |
|
207 |
// preguntandoselo al FilesystemServerExplorer. |
|
208 |
DataServerExplorerParameters no_params = |
|
209 |
(DataServerExplorerParameters) datamanager |
|
210 |
.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
|
211 |
|
|
212 |
FilesystemServerExplorer explorer = |
|
213 |
(FilesystemServerExplorer) datamanager.openServerExplorer( |
|
214 |
FilesystemServerExplorer.NAME, no_params // empty params |
|
215 |
); |
|
216 |
String providerName = explorer.getProviderName(endFile); |
|
217 |
|
|
218 |
try { |
|
219 |
DataStoreParameters dsp = |
|
220 |
explorer.createStoreParameters(endFile, providerName); |
|
221 |
NewFeatureStoreParameters parameters = |
|
222 |
(NewFeatureStoreParameters) datamanager |
|
223 |
.createNewStoreParameters(FilesystemServerExplorer.NAME, |
|
224 |
providerName); |
|
225 |
|
|
226 |
parameters.delegate(dsp); |
|
227 |
|
|
228 |
EditableFeatureType type = |
|
229 |
parameters.getDefaultFeatureType(); // .getEditable(); |
|
230 |
type.add(PluginServices.getText(this, "Nombre"), DataTypes.STRING, |
|
231 |
50); |
|
232 |
type.add(PluginServices.getText(this, "Valor"), DataTypes.DOUBLE, |
|
233 |
100).setPrecision(25); |
|
234 |
|
|
235 |
parameters.setDefaultFeatureType(type); |
|
236 |
datamanager.newStore(FilesystemServerExplorer.NAME, providerName, |
|
237 |
parameters, true); |
|
238 |
|
|
239 |
FeatureStore target = |
|
240 |
(FeatureStore) datamanager.openStore(providerName, parameters); |
|
241 |
target.edit(FeatureStore.MODE_APPEND); |
|
242 |
Iterator<MyObjectStatistics> iterador = valores.listIterator(); |
|
243 |
while (iterador.hasNext()) { |
|
244 |
MyObjectStatistics data = iterador.next(); |
|
245 |
EditableFeature ef = target.createNewFeature().getEditable(); |
|
246 |
ef.set(PluginServices.getText(this, "Nombre"), data.getKey()); |
|
247 |
ef.set(PluginServices.getText(this, "Valor"), data.getValue()); |
|
248 |
target.insert(ef); |
|
249 |
} |
|
250 |
target.finishEditing(); |
|
251 |
target.dispose(); |
|
252 |
JOptionPane.showMessageDialog( |
|
253 |
(Component) PluginServices.getMainFrame(), |
|
254 |
PluginServices.getText(this, "fichero_creado_en") + " " |
|
255 |
+ endFile.getAbsolutePath(), |
|
256 |
PluginServices.getText(this, "fichero_creado_en_formato") |
|
257 |
+ " dbf", JOptionPane.INFORMATION_MESSAGE);// Informing the |
|
258 |
// user |
|
259 |
} catch (Exception e) { |
|
260 |
e.printStackTrace(); |
|
261 |
} |
|
262 |
} |
|
263 |
} |
|
264 |
|
|
265 |
/** |
|
266 |
* @author ?ngel Fraile Gri??n e-mail: angel.fraile@iver.es |
|
267 |
* |
|
268 |
* Class to work with the file extensions. |
|
269 |
*/ |
|
270 |
class MyFileFilter extends FileFilter { |
|
271 |
|
|
272 |
private String[] extensiones = new String[1]; |
|
273 |
private String description; |
|
274 |
private boolean dirs = true; |
|
275 |
private String info = null; |
|
276 |
|
|
277 |
public MyFileFilter(String[] ext, String desc) { |
|
278 |
extensiones = ext; |
|
279 |
description = desc; |
|
280 |
} |
|
281 |
|
|
282 |
public MyFileFilter(String[] ext, String desc, String info) { |
|
283 |
extensiones = ext; |
Also available in: Unified diff