Revision 4211
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.254/org.gvsig.vectorediting.app/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
|
|
3 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
4 |
<modelVersion>4.0.0</modelVersion> |
|
5 |
<groupId>org.gvsig</groupId> |
|
6 |
<artifactId>org.gvsig.vectorediting.app</artifactId> |
|
7 |
<packaging>pom</packaging> |
|
8 |
<version>1.0.254</version> |
|
9 |
<name>${project.artifactId}</name> |
|
10 |
<description>This plugin add to gvSIG a tool to show Vectorediting messages</description> |
|
11 |
<parent> |
|
12 |
<groupId>org.gvsig</groupId> |
|
13 |
<artifactId>org.gvsig.vectorediting</artifactId> |
|
14 |
<version>1.0.254</version> |
|
15 |
</parent> |
|
16 |
<dependencyManagement> |
|
17 |
<dependencies> |
|
18 |
|
|
19 |
</dependencies> |
|
20 |
</dependencyManagement> |
|
21 |
|
|
22 |
<modules> |
|
23 |
<module>org.gvsig.vectorediting.app.mainplugin</module> |
|
24 |
</modules> |
|
25 |
|
|
26 |
</project> |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.254/org.gvsig.vectorediting.app/maven-howto.rst | ||
---|---|---|
1 |
|
|
2 |
================================== |
|
3 |
Usefull maven "howtos" and FAQs |
|
4 |
================================== |
|
5 |
|
|
6 |
.. contents:: |
|
7 |
|
|
8 |
How to reduce the process of "install" to run as fast as possible. |
|
9 |
------------------------------------------------------------------- |
|
10 |
|
|
11 |
Can reduce install execution skiping test execution and compilation, |
|
12 |
javadoc generation, test signature checking, license checking, and |
|
13 |
attach sources in jar. |
|
14 |
|
|
15 |
mvn -Danimal.sniffer.skip=true -Dmaven.test.skip=true -Dsource.skip=true -DskipTests -Dmaven.javadoc.skip=true install |
|
16 |
|
|
17 |
How to increment the build number of gvSIG plugins |
|
18 |
---------------------------------------------------- |
|
19 |
|
|
20 |
To increase the build number of gvSIG plugins, yo can do: |
|
21 |
|
|
22 |
mvn -Dincrease-build-number process-sources |
|
23 |
|
|
24 |
How to deploy a package of a gvSIG plugin |
|
25 |
-------------------------------------------- |
|
26 |
|
|
27 |
Yo can deploy the package of a gvSIG plugin with: |
|
28 |
|
|
29 |
mvn -Ddeploy-package -Duser=USER -Dpassword=PASSWORD install |
|
30 |
|
|
31 |
Notes: |
|
32 |
- Require that the gvsig.package.info.poolURL property that this set to the correct value. |
|
33 |
- The process uses WEBDAV to upload the packages, gvspkg and gvspki, and require |
|
34 |
access to write in the location specified by gvsig.package.info.poolURL |
|
35 |
- If "user" or "password" is not present, the process ask its each time it need. |
|
36 |
- If folder specified in gvsig.package.info.poolURL does not exist, the process try to create it. |
|
37 |
- The process create a file "addon-request.txt" in the target with the information to |
|
38 |
add to the ticket to request the update of the package in the main repository of |
|
39 |
packages of gvSIG. |
|
40 |
|
|
41 |
How to skip attach sources in jar from command line |
|
42 |
------------------------------------------------------ |
|
43 |
|
|
44 |
If in the project is enabled by default the generation of jar whith |
|
45 |
the sources of the project, you can disable this setting the property |
|
46 |
"source.skip" to true in the command line:: |
|
47 |
|
|
48 |
mvn -Dsource.skip=true install |
|
49 |
|
|
50 |
How to skip test compile from command line |
|
51 |
-------------------------------------------- |
|
52 |
|
|
53 |
You can skip the compilation of test setting the propety "maven.test.skip" |
|
54 |
to true in the command line:: |
|
55 |
|
|
56 |
mvn -Dmaven.test.skip=true install |
|
57 |
|
|
58 |
|
|
59 |
How to skip test execution from command line |
|
60 |
---------------------------------------------- |
|
61 |
|
|
62 |
You can skip the tests execution setting the propety "skipTests" to true |
|
63 |
in the command line:: |
|
64 |
|
|
65 |
mvn -DskipTests install |
|
66 |
|
|
67 |
How to skip javadoc generation from command line |
|
68 |
-------------------------------------------------- |
|
69 |
|
|
70 |
You can skip the javadoc generation setting the property |
|
71 |
"maven.javadoc.skip" to true in the command line:: |
|
72 |
|
|
73 |
mvn -Dmaven.javadoc.skip=true install |
|
74 |
|
|
75 |
How to skip test signature cheks from command line |
|
76 |
--------------------------------------------------- |
|
77 |
|
|
78 |
You can skip the signature check setting the property |
|
79 |
"animal.sniffer.skip" to true in the command line:: |
|
80 |
|
|
81 |
mvn -Danimal.sniffer.skip=true install |
|
82 |
|
|
83 |
How to install a project without install submodules |
|
84 |
---------------------------------------------------------- |
|
85 |
|
|
86 |
To install a project with submodules and only install the |
|
87 |
parent project without submodules use the option "--non-recursive" :: |
|
88 |
|
|
89 |
mvn --non-recursive install |
|
90 |
|
|
91 |
|
|
92 |
How to skip test compilation |
|
93 |
-------------------------------- |
|
94 |
|
|
95 |
To configure a project to don't run the compilation |
|
96 |
of test you can add to this pom the next configuration of |
|
97 |
the plugin "maven-compiler-plugin":: |
|
98 |
|
|
99 |
<build> |
|
100 |
<plugins> |
|
101 |
... |
|
102 |
<plugin> |
|
103 |
<!-- Skip compilation tests --> |
|
104 |
<groupId>org.apache.maven.plugins</groupId> |
|
105 |
<artifactId>maven-compiler-plugin</artifactId> |
|
106 |
<executions> |
|
107 |
<execution> |
|
108 |
<id>default-testCompile</id> |
|
109 |
<phase>process-test-sources</phase> |
|
110 |
<goals> |
|
111 |
<goal>testCompile</goal> |
|
112 |
</goals> |
|
113 |
<configuration> |
|
114 |
<skip>true</skip> |
|
115 |
</configuration> |
|
116 |
</execution> |
|
117 |
</executions> |
|
118 |
</plugin> |
|
119 |
... |
|
120 |
</plugins> |
|
121 |
</build> |
|
122 |
|
|
123 |
Skip test execution |
|
124 |
---------------------- |
|
125 |
|
|
126 |
To configure a project to don't run the execution |
|
127 |
of test you can add to this pom the next configuration of |
|
128 |
the plugin "maven-surefire-plugin":: |
|
129 |
|
|
130 |
|
|
131 |
<build> |
|
132 |
<plugins> |
|
133 |
... |
|
134 |
<plugin> |
|
135 |
<!-- Skip test execution --> |
|
136 |
<groupId>org.apache.maven.plugins</groupId> |
|
137 |
<artifactId>maven-surefire-plugin</artifactId> |
|
138 |
<configuration> |
|
139 |
<skipTests>true</skipTests> |
|
140 |
</configuration> |
|
141 |
</plugin> |
|
142 |
... |
|
143 |
</plugins> |
|
144 |
</build> |
|
145 |
|
|
146 |
Continue on test failure |
|
147 |
----------------------------- |
|
148 |
|
|
149 |
You can configure a project to continue on test execution |
|
150 |
failure. To do this add to the pom of the project the next |
|
151 |
configuration of plugin "maven-surefire-plugin" :: |
|
152 |
|
|
153 |
<build> |
|
154 |
<plugins> |
|
155 |
... |
|
156 |
<plugin> |
|
157 |
<!-- Continue on test failure --> |
|
158 |
<groupId>org.apache.maven.plugins</groupId> |
|
159 |
<artifactId>maven-surefire-plugin</artifactId> |
|
160 |
<configuration> |
|
161 |
<testFailureIgnore>true</testFailureIgnore> |
|
162 |
</configuration> |
|
163 |
</plugin> |
|
164 |
... |
|
165 |
</plugins> |
|
166 |
</build> |
|
167 |
|
|
168 |
|
|
169 |
Set java compatibility |
|
170 |
-------------------------- |
|
171 |
|
|
172 |
To set the compatibility with a java version add to the |
|
173 |
pom of the project the next configuration of plugin |
|
174 |
"maven-compiler-plugin" :: |
|
175 |
|
|
176 |
<build> |
|
177 |
<plugins> |
|
178 |
... |
|
179 |
<plugin> |
|
180 |
<!-- Set java compatibility --> |
|
181 |
<groupId>org.apache.maven.plugins</groupId> |
|
182 |
<artifactId>maven-compiler-plugin</artifactId> |
|
183 |
<configuration> |
|
184 |
<source>1.5</source> |
|
185 |
<target>1.5</target> |
|
186 |
<encoding>ISO-8859-1</encoding> |
|
187 |
</configuration> |
|
188 |
</plugin> |
|
189 |
... |
|
190 |
</plugins> |
|
191 |
</build> |
|
192 |
|
|
193 |
Packaging tests in jar |
|
194 |
------------------------ |
|
195 |
|
|
196 |
Test classes do not packaging in jar by default. |
|
197 |
To packing add to pom:: |
|
198 |
|
|
199 |
<build> |
|
200 |
<plugins> |
|
201 |
... |
|
202 |
<plugin> |
|
203 |
<!-- Packaging tests in jar --> |
|
204 |
<groupId>org.apache.maven.plugins</groupId> |
|
205 |
<artifactId>maven-jar-plugin</artifactId> |
|
206 |
<executions> |
|
207 |
<!-- Generates a jar file only with the test classes --> |
|
208 |
<execution> |
|
209 |
<goals> |
|
210 |
<goal>test-jar</goal> |
|
211 |
</goals> |
|
212 |
<configuration> |
|
213 |
<includes> |
|
214 |
<include>**/**</include> |
|
215 |
</includes> |
|
216 |
</configuration> |
|
217 |
</execution> |
|
218 |
</executions> |
|
219 |
</plugin> |
|
220 |
... |
|
221 |
</plugins> |
|
222 |
</build> |
|
223 |
|
|
224 |
How to set a dependency with tests jar |
|
225 |
----------------------------------------- |
|
226 |
|
|
227 |
You can set a dependency with a test jar adding to |
|
228 |
the declaration of the dependency the scope of |
|
229 |
test and the type of "test-jar":: |
|
230 |
|
|
231 |
<dependency> |
|
232 |
<groupId>...</groupId> |
|
233 |
<artifactId>...</artifactId> |
|
234 |
<type>test-jar</type> |
|
235 |
<scope>test</scope> |
|
236 |
</dependency> |
|
237 |
|
|
238 |
How use ant in maven |
|
239 |
------------------------- |
|
240 |
|
|
241 |
You can use ant embed in the pom of you project. |
|
242 |
To do this use:: |
|
243 |
|
|
244 |
<plugin> |
|
245 |
<artifactId>maven-antrun-plugin</artifactId> |
|
246 |
<version>1.7</version> |
|
247 |
<executions> |
|
248 |
<execution> |
|
249 |
<phase>generate-sources</phase> |
|
250 |
<configuration> |
|
251 |
<target> |
|
252 |
<echo>Hello world!</echo> |
|
253 |
</target> |
|
254 |
</configuration> |
|
255 |
<goals> |
|
256 |
<goal>run</goal> |
|
257 |
</goals> |
|
258 |
</execution> |
|
259 |
</executions> |
|
260 |
</plugin> |
|
261 |
|
|
262 |
Fail when execute "mvn deploy" with "No connector available" |
|
263 |
------------------------------------------------------------- |
|
264 |
|
|
265 |
When execute a "mvn deploy" fail with the error:: |
|
266 |
|
|
267 |
[INFO] ------------------------------------------------------------------------ |
|
268 |
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy |
|
269 |
(default-deploy) on project org.gvsig.desktop: Failed to deploy artifacts/metadata: |
|
270 |
No connector available to access repository gvsig-repository (dav:https://devel.gvsig.org/m2repo/j2se) |
|
271 |
of type default using the available factories WagonRepositoryConnectorFactory -> [Help 1] |
|
272 |
[ERROR] |
|
273 |
|
|
274 |
This happens to be configured the webdav wagon as an extension in the section "build":: |
|
275 |
|
|
276 |
... |
|
277 |
<build> |
|
278 |
<extensions> |
|
279 |
<extension> |
|
280 |
<groupId>org.apache.maven.wagon</groupId> |
|
281 |
<artifactId>wagon-webdav-jackrabbit</artifactId> |
|
282 |
<version>1.0-beta-7</version> |
|
283 |
</extension> |
|
284 |
</extensions> |
|
285 |
... |
|
286 |
|
|
287 |
Fail when execute "mvn release: prepare" with "svn command failed... Could not authenticate" |
|
288 |
------------------------------------------------------------------------------------------------ |
|
289 |
|
|
290 |
When running "mvn release: prepare" updates poms, compiles, and then |
|
291 |
fails with the following error :: |
|
292 |
|
|
293 |
[INFO] ------------------------------------------------------------------------ |
|
294 |
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.1:prepare |
|
295 |
(default-cli) on project org.gvsig.desktop: Unable to commit files |
|
296 |
[ERROR] Provider message: |
|
297 |
[ERROR] The svn command failed. |
|
298 |
[ERROR] Command output: |
|
299 |
[ERROR] svn: Commit failed (details follow): |
|
300 |
[ERROR] svn: MKACTIVITY of '/svn/gvsig-desktop/!svn/act/931a27bc-57e8-45d9-adcd-5a2cf54a7045': |
|
301 |
authorization failed: Could not authenticate to server: rejected Basic challenge (https://devel.gvsig.org) |
|
302 |
[ERROR] -> [Help 1] |
|
303 |
[ERROR] |
|
304 |
[ERROR] |
|
305 |
|
|
306 |
Apparently maven in linux system use the svn of system and if you're not |
|
307 |
authenticated when trying to access to the repository, svn fails. |
|
308 |
|
|
309 |
This is solved by executing a commit from the command line on |
|
310 |
some file of the project (only if you have not enabled the option |
|
311 |
"store-passwords = no" in $ HOME / .subversion / config). For example, you |
|
312 |
can add or remove at the end of "pom.xml" a blank line and then run |
|
313 |
from the command line :: |
|
314 |
|
|
315 |
svn ci -m "" pom.xml |
|
316 |
|
|
317 |
Another option that works on Windows in declaring the user and password in the command: |
|
318 |
|
|
319 |
mvn release:prepare -Dusername=[username] -Dpassword=[password] |
|
320 |
|
|
321 |
|
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.254/org.gvsig.vectorediting.app/org.gvsig.vectorediting.app.mainplugin/buildNumber.properties | ||
---|---|---|
1 |
#Thu Oct 19 16:15:18 CEST 2023 |
|
2 |
buildNumber=265 |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.254/org.gvsig.vectorediting.app/org.gvsig.vectorediting.app.mainplugin/src/main/java/org/gvsig/app/project/documents/view/toc/actions/StartEditingTocMenuEntry.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
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 3 |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.app.project.documents.view.toc.actions; |
|
25 |
|
|
26 |
import org.slf4j.Logger; |
|
27 |
import org.slf4j.LoggerFactory; |
|
28 |
|
|
29 |
import org.gvsig.andami.PluginServices; |
|
30 |
import org.gvsig.andami.plugins.IExtension; |
|
31 |
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction; |
|
32 |
import org.gvsig.app.project.documents.view.toc.ITocItem; |
|
33 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
34 |
import org.gvsig.vectorediting.app.mainplugin.EditingExtension; |
|
35 |
|
|
36 |
|
|
37 |
public class StartEditingTocMenuEntry extends AbstractTocContextMenuAction { |
|
38 |
|
|
39 |
public static final String EXTENSION_POINT_NAME = "StartEditing"; |
|
40 |
|
|
41 |
private IExtension ext = null; |
|
42 |
|
|
43 |
private static Logger logger = |
|
44 |
LoggerFactory.getLogger(StartEditingTocMenuEntry.class); |
|
45 |
|
|
46 |
public String getGroup() { |
|
47 |
return "vectorEditing"; |
|
48 |
} |
|
49 |
|
|
50 |
public int getGroupOrder() { |
|
51 |
return 0; |
|
52 |
} |
|
53 |
|
|
54 |
public int getOrder() { |
|
55 |
return 0; |
|
56 |
} |
|
57 |
|
|
58 |
public String getText() { |
|
59 |
return PluginServices.getText(this, "start_editing"); |
|
60 |
} |
|
61 |
|
|
62 |
public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
|
63 |
return ((EditingExtension)getExtension()).isEnabled("start-editing"); |
|
64 |
} |
|
65 |
|
|
66 |
public boolean isVisible(ITocItem item, FLayer[] selectedItems) { |
|
67 |
return ((EditingExtension)getExtension()).isVisible("start-editing"); |
|
68 |
} |
|
69 |
|
|
70 |
|
|
71 |
public void execute(ITocItem item, FLayer[] selItems) { |
|
72 |
getExtension().execute("start-editing"); |
|
73 |
} |
|
74 |
|
|
75 |
private IExtension getExtension() { |
|
76 |
|
|
77 |
if (ext == null) { |
|
78 |
ext = PluginServices.getExtension(EditingExtension.class); |
|
79 |
} |
|
80 |
return ext; |
|
81 |
} |
|
82 |
|
|
83 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.254/org.gvsig.vectorediting.app/org.gvsig.vectorediting.app.mainplugin/src/main/java/org/gvsig/app/project/documents/view/toc/actions/EndEditingTocMenuEntry.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
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 3 |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.app.project.documents.view.toc.actions; |
|
25 |
|
|
26 |
import org.slf4j.Logger; |
|
27 |
import org.slf4j.LoggerFactory; |
|
28 |
|
|
29 |
import org.gvsig.andami.PluginServices; |
|
30 |
import org.gvsig.andami.plugins.IExtension; |
|
31 |
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction; |
|
32 |
import org.gvsig.app.project.documents.view.toc.ITocItem; |
|
33 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
34 |
import org.gvsig.vectorediting.app.mainplugin.EditingExtension; |
|
35 |
|
|
36 |
|
|
37 |
public class EndEditingTocMenuEntry extends AbstractTocContextMenuAction { |
|
38 |
|
|
39 |
public static final String EXTENSION_POINT_NAME = "EndEditing"; |
|
40 |
|
|
41 |
private IExtension ext = null; |
|
42 |
|
|
43 |
private static Logger logger = |
|
44 |
LoggerFactory.getLogger(EndEditingTocMenuEntry.class); |
|
45 |
|
|
46 |
public String getGroup() { |
|
47 |
return "vectorEditing"; |
|
48 |
} |
|
49 |
|
|
50 |
public int getGroupOrder() { |
|
51 |
return 0; |
|
52 |
} |
|
53 |
|
|
54 |
public int getOrder() { |
|
55 |
return 1; |
|
56 |
} |
|
57 |
|
|
58 |
public String getText() { |
|
59 |
return PluginServices.getText(this, "end_editing"); |
|
60 |
} |
|
61 |
|
|
62 |
public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
|
63 |
return ((EditingExtension)getExtension()).isEnabled("end-editing"); |
|
64 |
} |
|
65 |
|
|
66 |
public boolean isVisible(ITocItem item, FLayer[] selectedItems) { |
|
67 |
return ((EditingExtension)getExtension()).isVisible("end-editing"); |
|
68 |
} |
|
69 |
|
|
70 |
|
|
71 |
public void execute(ITocItem item, FLayer[] selItems) { |
|
72 |
getExtension().execute("end-editing"); |
|
73 |
} |
|
74 |
|
|
75 |
private IExtension getExtension() { |
|
76 |
|
|
77 |
if (ext == null) { |
|
78 |
ext = PluginServices.getExtension(EditingExtension.class); |
|
79 |
} |
|
80 |
return ext; |
|
81 |
} |
|
82 |
|
|
83 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.254/org.gvsig.vectorediting.app/org.gvsig.vectorediting.app.mainplugin/src/main/java/org/gvsig/vectorediting/app/mainplugin/EditingExtension.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2014 gvSIG Association |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.vectorediting.app.mainplugin; |
|
25 |
|
|
26 |
import java.awt.Component; |
|
27 |
import java.awt.event.ActionEvent; |
|
28 |
import java.io.File; |
|
29 |
import java.util.ArrayList; |
|
30 |
import java.util.Collections; |
|
31 |
import java.util.List; |
|
32 |
import java.util.function.Predicate; |
|
33 |
import javax.swing.AbstractAction; |
|
34 |
import javax.swing.Action; |
|
35 |
import javax.swing.JMenuItem; |
|
36 |
import javax.swing.JOptionPane; |
|
37 |
import javax.swing.JPopupMenu; |
|
38 |
import org.apache.commons.collections4.CollectionUtils; |
|
39 |
import org.apache.commons.io.FileUtils; |
|
40 |
import org.apache.commons.lang.StringUtils; |
|
41 |
|
|
42 |
import org.slf4j.Logger; |
|
43 |
import org.slf4j.LoggerFactory; |
|
44 |
|
|
45 |
import org.gvsig.andami.IconThemeHelper; |
|
46 |
import org.gvsig.andami.PluginServices; |
|
47 |
import org.gvsig.andami.PluginsLocator; |
|
48 |
import org.gvsig.andami.actioninfo.ActionInfo; |
|
49 |
import org.gvsig.andami.plugins.Extension; |
|
50 |
import org.gvsig.andami.plugins.IExtension; |
|
51 |
import org.gvsig.andami.plugins.status.IExtensionStatus; |
|
52 |
import org.gvsig.andami.plugins.status.IUnsavedData; |
|
53 |
import org.gvsig.andami.plugins.status.UnsavedData; |
|
54 |
import org.gvsig.app.ApplicationLocator; |
|
55 |
import org.gvsig.app.ApplicationManager; |
|
56 |
import org.gvsig.app.project.Project; |
|
57 |
import org.gvsig.app.project.documents.Document; |
|
58 |
import org.gvsig.app.project.documents.view.ViewDocument; |
|
59 |
import org.gvsig.app.project.documents.view.ViewManager; |
|
60 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
|
61 |
import org.gvsig.app.project.documents.view.gui.IView; |
|
62 |
import org.gvsig.app.project.documents.view.toc.actions.EndEditingTocMenuEntry; |
|
63 |
import org.gvsig.app.project.documents.view.toc.actions.StartEditingTocMenuEntry; |
|
64 |
import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener; |
|
65 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
|
66 |
import org.gvsig.expressionevaluator.swing.JExpressionBuilder; |
|
67 |
import org.gvsig.fmap.dal.exception.DataException; |
|
68 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
69 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
70 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
71 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
72 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
73 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
74 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
75 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolException; |
|
76 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
|
77 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
78 |
import org.gvsig.fmap.mapcontrol.MapControlCreationListener; |
|
79 |
import org.gvsig.fmap.mapcontrol.MapControlLocator; |
|
80 |
import org.gvsig.fmap.mapcontrol.MapControlManager; |
|
81 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
|
82 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior; |
|
83 |
import org.gvsig.tools.ToolsLocator; |
|
84 |
import org.gvsig.tools.dynform.spi.DynFormSPILocator; |
|
85 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
|
86 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
|
87 |
import org.gvsig.tools.i18n.I18nManager; |
|
88 |
import org.gvsig.tools.observer.Notification; |
|
89 |
import org.gvsig.tools.observer.Observable; |
|
90 |
import org.gvsig.tools.observer.Observer; |
|
91 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
92 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
|
93 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
|
94 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager.MODE; |
|
95 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
|
96 |
import org.gvsig.utils.swing.threads.IMonitorableTask; |
|
97 |
import org.gvsig.vectorediting.app.mainplugin.dynformfield.point.JDynFormFieldPointFactory; |
|
98 |
import org.gvsig.vectorediting.lib.api.EditingService; |
|
99 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
|
100 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
|
101 |
import org.gvsig.vectorediting.swing.api.EditingContext; |
|
102 |
import org.gvsig.vectorediting.swing.api.EditingSwingLocator; |
|
103 |
import org.gvsig.vectorediting.swing.api.EditingSwingManager; |
|
104 |
import org.gvsig.vectorediting.swing.api.console.EditingConsole; |
|
105 |
|
|
106 |
@SuppressWarnings("UseSpecificCatch") |
|
107 |
public class EditingExtension extends Extension implements Observer { |
|
108 |
|
|
109 |
private static final Logger LOGGER = LoggerFactory.getLogger(EditingExtension.class); |
|
110 |
|
|
111 |
@Override |
|
112 |
public void execute(String actionCommand) { |
|
113 |
IView view = getActiveView(); |
|
114 |
EditingSwingManager swingManager = EditingSwingLocator.getSwingManager(); |
|
115 |
|
|
116 |
if (view != null) { |
|
117 |
EditingContext editingContext = swingManager.getEditingContext(view.getMapControl()); |
|
118 |
|
|
119 |
if ("start-editing".equals(actionCommand)) { |
|
120 |
doStartEditing(view, editingContext); |
|
121 |
|
|
122 |
} else if ("end-editing".equals(actionCommand)) { |
|
123 |
doEndEditing(view, editingContext); |
|
124 |
|
|
125 |
} else if ("vector-editing-tooloptions".equalsIgnoreCase(actionCommand)) { |
|
126 |
doToolOptions(editingContext); |
|
127 |
} else if ("vector-editing-ortomode-enable".equalsIgnoreCase(actionCommand)) { |
|
128 |
editingContext.setDrawMode(EditingContext.DRAWMODE_ORTO); |
|
129 |
} else if ("vector-editing-ortomode-disable".equalsIgnoreCase(actionCommand)) { |
|
130 |
editingContext.setDrawMode(EditingContext.DRAWMODE_NORMAL); |
|
131 |
} |
|
132 |
} |
|
133 |
} |
|
134 |
|
|
135 |
private void doStartEditing(IView view, EditingContext editingContext) { |
|
136 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
137 |
MapControl mapControl = view.getMapControl(); |
|
138 |
List<FLyrVect> reprojectedLayers = getActiveLayers( |
|
139 |
view, |
|
140 |
(FLyrVect layer) -> canBeEdited(layer) |
|
141 |
&& !mapControl.getProjection().equals(layer.getProjection()) |
|
142 |
); |
|
143 |
if (!reprojectedLayers.isEmpty()) { |
|
144 |
String msg = "_The_layer_is_reproyected_on_the_fly" |
|
145 |
+ "_Not_all_editing_tools_work_properly" |
|
146 |
+ "_When_you_finish_editing" |
|
147 |
+ "_will_only_export_the_changes_to_another_layer"; |
|
148 |
application.messageDialog(msg, "_Warning", JOptionPane.WARNING_MESSAGE); |
|
149 |
} else { |
|
150 |
List<FLyrVect> nonWritableLayers = getActiveLayers( |
|
151 |
view, |
|
152 |
(FLyrVect layer) -> canBeEdited(layer) && !isWritable(layer) |
|
153 |
); |
|
154 |
if (!nonWritableLayers.isEmpty()) { |
|
155 |
String msg = "_The_layer_can_not_be_written" |
|
156 |
+ "_When_you_finish_editing" |
|
157 |
+ "_will_only_export_the_changes_to_another_layer"; |
|
158 |
application.messageDialog(msg, "_Warning", JOptionPane.WARNING_MESSAGE); |
|
159 |
} |
|
160 |
} |
|
161 |
List<FLyrVect> activeLayers = getActiveLayers( |
|
162 |
view, |
|
163 |
(FLyrVect layer) -> canBeEdited(layer) |
|
164 |
); |
|
165 |
for (FLyrVect layer : activeLayers) { |
|
166 |
editingContext.beginEdition(layer); |
|
167 |
editingContext.addObserver(this); |
|
168 |
} |
|
169 |
|
|
170 |
EditingConsole console = editingContext.getConsolePanel(); |
|
171 |
JPopupMenu popup = console.getComponentPopupMenu(); |
|
172 |
boolean needadd = true; |
|
173 |
for (int i = 0; i < popup.getComponentCount(); i++) { |
|
174 |
Component comp = popup.getComponent(i); |
|
175 |
if( StringUtils.equals("ExpressionBuilder",comp.getName()) ) { |
|
176 |
needadd = false; |
|
177 |
break; |
|
178 |
} |
|
179 |
} |
|
180 |
if( needadd ) { |
|
181 |
JMenuItem entry = new JMenuItem(new ExpressionBuilderAction(editingContext, console)); |
|
182 |
entry.setName("ExpressionBuilder"); |
|
183 |
popup.add(entry); |
|
184 |
} |
|
185 |
ApplicationLocator.getManager().refreshMenusAndToolBars(); |
|
186 |
} |
|
187 |
|
|
188 |
private void doEndEditing(IView view, EditingContext editingContext) { |
|
189 |
List<FLyrVect> activeLayers = getActiveLayers( |
|
190 |
view, |
|
191 |
(FLyrVect layer) -> layer.isEditing() |
|
192 |
); |
|
193 |
// for (FLyrVect layer : activeLayers) { |
|
194 |
// editingContext.endEdition(layer); |
|
195 |
// } |
|
196 |
if (CollectionUtils.isEmpty(activeLayers)) { |
|
197 |
return; |
|
198 |
} |
|
199 |
if (activeLayers.size() == 1) { |
|
200 |
editingContext.endEdition(activeLayers.get(0)); |
|
201 |
ApplicationLocator.getManager().refreshMenusAndToolBars(); |
|
202 |
} else { |
|
203 |
showMultilaterFinishEditingPanel(view.getMapControl().getMapContext()); |
|
204 |
} |
|
205 |
} |
|
206 |
|
|
207 |
private void doToolOptions(EditingContext editingContext) { |
|
208 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
209 |
// EditingSwingManager editingSwingManager = EditingSwingLocator.getSwingManager(); |
|
210 |
if (editingContext == null) { |
|
211 |
return; |
|
212 |
} |
|
213 |
WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
|
214 |
EditingToolOptionsPanel panel = new EditingToolOptionsPanel(editingContext); |
|
215 |
windowManager.showWindow( |
|
216 |
panel, |
|
217 |
i18n.getTranslation("_Vector_editing_tool_options"), |
|
218 |
WindowManager.MODE.TOOL |
|
219 |
); |
|
220 |
} |
|
221 |
|
|
222 |
@Override |
|
223 |
public void initialize() { |
|
224 |
registerIcons(); |
|
225 |
|
|
226 |
// Disable default view panel console. Uses editing context console. |
|
227 |
DefaultViewPanel.setDisableConsole(true); |
|
228 |
|
|
229 |
// Adding TOC menu entry |
|
230 |
ExtensionPoint exPoint = ToolsLocator.getExtensionPointManager().add( |
|
231 |
"View_TocActions", ""); |
|
232 |
exPoint.append( |
|
233 |
StartEditingTocMenuEntry.EXTENSION_POINT_NAME, |
|
234 |
"TOC popup menu to start vector layer's editing", |
|
235 |
new StartEditingTocMenuEntry()); |
|
236 |
exPoint.append( |
|
237 |
EndEditingTocMenuEntry.EXTENSION_POINT_NAME, |
|
238 |
"TOC popup menu to end vector layer's editing", |
|
239 |
new EndEditingTocMenuEntry()); |
|
240 |
EditingToolOptionsPanel.registerPersistence(); |
|
241 |
} |
|
242 |
|
|
243 |
private void registerIcons() { |
|
244 |
IconThemeHelper.registerIcon("vectorediting-tools", "vector-editing", this); |
|
245 |
IconThemeHelper.registerIcon("vectorediting-tools", "vector-editing-tooloptions", this); |
|
246 |
// IconThemeHelper.registerIcon("vectorediting-tools", "vector-editing-tooloptions-confirm", this); |
|
247 |
IconThemeHelper.registerIcon("vectorediting-tools", "vector-editing-ortomode-enable", this); |
|
248 |
IconThemeHelper.registerIcon("vectorediting-tools", "vector-editing-ortomode-disable", this); |
|
249 |
} |
|
250 |
|
|
251 |
@Override |
|
252 |
@SuppressWarnings("Convert2Lambda") |
|
253 |
public void postInitialize() { |
|
254 |
super.postInitialize(); |
|
255 |
registerSymbols(); |
|
256 |
|
|
257 |
MapControlManager mapControlManager = MapControlLocator.getMapControlManager(); |
|
258 |
mapControlManager.addMapControlCreationListener(new MapControlCreationListener() { |
|
259 |
@Override |
|
260 |
public MapControl mapControlCreated(MapControl mapControl) { |
|
261 |
EditingContext editingContext = EditingSwingLocator.getSwingManager().getEditingContext(mapControl); |
|
262 |
StatusBarListener sbl = new StatusBarListener(mapControl); |
|
263 |
editingContext.setDefaultBehaviors(new Behavior[]{new MouseMovementBehavior(sbl)}); |
|
264 |
editingContext.addObserver(EditingExtension.this); |
|
265 |
ApplicationLocator.getManager().refreshMenusAndToolBars(); |
|
266 |
return mapControl; |
|
267 |
} |
|
268 |
}); |
|
269 |
|
|
270 |
DynFormSPIManager dynFormManager = DynFormSPILocator.getDynFormSPIManager(); |
|
271 |
dynFormManager.registerDynFieldFactory(new JDynFormFieldPointFactory()); |
|
272 |
|
|
273 |
} |
|
274 |
|
|
275 |
/** |
|
276 |
* Register all symbols in the plugin symbols folder in the providerManager. |
|
277 |
* The description of the symbols must be unique because the key used for |
|
278 |
* registration is the proper description of the symbol. |
|
279 |
* |
|
280 |
*/ |
|
281 |
private void registerSymbols() { |
|
282 |
|
|
283 |
EditingProviderManager providerManager = EditingProviderLocator.getProviderManager(); |
|
284 |
|
|
285 |
SymbolManager symbolManager = MapContextLocator.getSymbolManager(); |
|
286 |
File symbolsFolder = FileUtils.getFile(getPlugin().getPluginDirectory(), "symbols", "editing"); |
|
287 |
ISymbol[] symbols = null; |
|
288 |
try { |
|
289 |
symbols = symbolManager.loadSymbols(symbolsFolder); |
|
290 |
} catch (SymbolException e) { |
|
291 |
LOGGER.warn("No symbols loaded from " + symbolsFolder.getAbsolutePath(), e); |
|
292 |
} |
|
293 |
|
|
294 |
if (symbols != null) { |
|
295 |
for (ISymbol symbol : symbols) { |
|
296 |
String description = symbol.getDescription(); |
|
297 |
providerManager.registerSymbol(description, symbol); |
|
298 |
} |
|
299 |
} |
|
300 |
} |
|
301 |
|
|
302 |
@Override |
|
303 |
public boolean isEnabled() { |
|
304 |
return true; |
|
305 |
} |
|
306 |
|
|
307 |
@Override |
|
308 |
public boolean isVisible() { |
|
309 |
return true; |
|
310 |
} |
|
311 |
|
|
312 |
@Override |
|
313 |
public boolean isVisible(String action) { |
|
314 |
IView view = getActiveView(); |
|
315 |
if (view == null) { |
|
316 |
return false; |
|
317 |
} |
|
318 |
EditingSwingManager swingManager = EditingSwingLocator.getSwingManager(); |
|
319 |
EditingContext editingContext = swingManager.getEditingContext(view.getMapControl()); |
|
320 |
if ("start-editing".equals(action)) { |
|
321 |
List<FLyrVect> activeLayers = getActiveLayers(view, (FLyrVect layer) -> !layer.isEditing()); |
|
322 |
return !activeLayers.isEmpty(); |
|
323 |
} else if ("vector-editing-ortomode-enable".equals(action)) { |
|
324 |
List<FLyrVect> activeLayers = getActiveLayers(view, (FLyrVect layer) -> layer.isEditing()); |
|
325 |
return editingContext.getDrawMode()==EditingContext.DRAWMODE_NORMAL && !activeLayers.isEmpty(); |
|
326 |
} else if ("vector-editing-ortomode-disable".equals(action)) { |
|
327 |
List<FLyrVect> activeLayers = getActiveLayers(view, (FLyrVect layer) -> layer.isEditing()); |
|
328 |
return editingContext.getDrawMode()==EditingContext.DRAWMODE_ORTO && !activeLayers.isEmpty(); |
|
329 |
} else { |
|
330 |
List<FLyrVect> activeLayers = getActiveLayers(view, (FLyrVect layer) -> layer.isEditing()); |
|
331 |
return !activeLayers.isEmpty(); |
|
332 |
} |
|
333 |
} |
|
334 |
|
|
335 |
@Override |
|
336 |
@SuppressWarnings("ConvertToStringSwitch") |
|
337 |
public boolean isEnabled(String action) { |
|
338 |
IView view = getActiveView(); |
|
339 |
if (view == null) { |
|
340 |
return false; |
|
341 |
} |
|
342 |
EditingSwingManager swingManager = EditingSwingLocator.getSwingManager(); |
|
343 |
EditingContext editingContext = swingManager.getEditingContext(view.getMapControl()); |
|
344 |
if( editingContext.isProcessing() ) { |
|
345 |
return false; |
|
346 |
} |
|
347 |
|
|
348 |
if ("start-editing".equals(action)) { |
|
349 |
List<FLyrVect> activeLayers = getActiveLayers(view, (FLyrVect layer) -> canBeEdited(layer)); |
|
350 |
return !activeLayers.isEmpty(); |
|
351 |
|
|
352 |
} else if ("end-editing".equals(action)) { |
|
353 |
List<FLyrVect> activeLayers = getActiveLayers(view, (FLyrVect layer) -> layer.isEditing()); |
|
354 |
return !activeLayers.isEmpty(); |
|
355 |
|
|
356 |
} else if ("vector-editing-tooloptions".equals(action)) { |
|
357 |
List<FLyrVect> activeLayers = getActiveLayers(view, (FLyrVect layer) -> layer.isEditing()); |
|
358 |
return !activeLayers.isEmpty(); |
|
359 |
} else if ("vector-editing-ortomode-enable".equals(action)) { |
|
360 |
return editingContext.getDrawMode()==EditingContext.DRAWMODE_NORMAL; |
|
361 |
} else if ("vector-editing-ortomode-disable".equals(action)) { |
|
362 |
return editingContext.getDrawMode()==EditingContext.DRAWMODE_ORTO; |
|
363 |
} |
|
364 |
|
|
365 |
return false; |
|
366 |
|
|
367 |
} |
|
368 |
|
|
369 |
@Override |
|
370 |
public boolean canQueryByAction() { |
|
371 |
return true; |
|
372 |
} |
|
373 |
|
|
374 |
private IView getActiveView() { |
|
375 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
376 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
|
377 |
return view; |
|
378 |
} |
|
379 |
|
|
380 |
private boolean isWritable(FLyrVect layer) { |
|
381 |
if (layer != null && layer.isAvailable() && layer.isVisible()) { |
|
382 |
return layer.getFeatureStore().allowWrite(); |
|
383 |
} |
|
384 |
return false; |
|
385 |
} |
|
386 |
|
|
387 |
private boolean canBeEdited(FLyrVect layer) { |
|
388 |
if (layer != null && layer.isAvailable() && layer.isVisible()) { |
|
389 |
FeatureStore store = layer.getFeatureStore(); |
|
390 |
boolean storeCanBeEdited= false; |
|
391 |
if(store != null){ |
|
392 |
storeCanBeEdited = store.canBeEdited(); |
|
393 |
} |
|
394 |
return storeCanBeEdited && !layer.isEditing(); |
|
395 |
} |
|
396 |
|
|
397 |
return false; |
|
398 |
} |
|
399 |
|
|
400 |
// private FLyrVect getActiveLayer(IView vista) { |
|
401 |
// if (vista != null) { |
|
402 |
// ViewDocument viewDocument = vista.getViewDocument(); |
|
403 |
// FLayer[] actives |
|
404 |
// = viewDocument.getMapContext().getLayers().getActives(); |
|
405 |
// |
|
406 |
// if ((actives.length == 1) && (actives[0] instanceof FLyrVect)) { |
|
407 |
// return (FLyrVect) actives[0]; |
|
408 |
// } |
|
409 |
// } |
|
410 |
// return null; |
|
411 |
// } |
|
412 |
private List<FLyrVect> getActiveLayers(IView view, Predicate<FLyrVect> valid) { |
|
413 |
if (view == null) { |
|
414 |
return Collections.EMPTY_LIST; |
|
415 |
} |
|
416 |
List<FLyrVect> layers = new ArrayList<>(); |
|
417 |
ViewDocument viewDocument = view.getViewDocument(); |
|
418 |
FLayer[] actives = viewDocument.getMapContext().getLayers().getActives(); |
|
419 |
for (FLayer layer : actives) { |
|
420 |
if (layer instanceof FLyrVect && valid.test((FLyrVect) layer)) { |
|
421 |
layers.add((FLyrVect) layer); |
|
422 |
} |
|
423 |
} |
|
424 |
return layers; |
|
425 |
} |
|
426 |
|
|
427 |
@Override |
|
428 |
public void update(Observable observable, Object notification) { |
|
429 |
|
|
430 |
if (notification instanceof Notification) { |
|
431 |
ApplicationManager appManager = ApplicationLocator.getManager(); |
|
432 |
Notification n = (Notification) notification; |
|
433 |
if (n.isOfType(EditingContext.CHANGE_SELECTED_TOOL_NOTIFICATION)) { |
|
434 |
String name = (String) n.getValue(); |
|
435 |
if( name!=null ) { |
|
436 |
LOGGER.trace("Changed selected tool to '{}'", name); |
|
437 |
appManager.getMainFrame().setSelectedTool(name); |
|
438 |
appManager.refreshMenusAndToolBars(); |
|
439 |
} |
|
440 |
|
|
441 |
} else if (n.isOfType(EditingContext.EXPORT_LAYER_NOTIFICATION)) { |
|
442 |
exportLayer((FLyrVect) (n.getValue())); |
|
443 |
|
|
444 |
} else if (n.isOfType(EditingContext.REFRESH_TOOLS_NOTIFICATION)) { |
|
445 |
EditingService activeService = ((EditingContext)observable).getActiveService(); |
|
446 |
if(activeService != null){ |
|
447 |
appManager.getMainFrame().setSelectedTool(activeService.getName()); |
|
448 |
} |
|
449 |
appManager.refreshMenusAndToolBars(); |
|
450 |
} |
|
451 |
} |
|
452 |
} |
|
453 |
|
|
454 |
private void exportLayer(FLyrVect layer) { |
|
455 |
ApplicationManager appManager = ApplicationLocator.getManager(); |
|
456 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
457 |
ActionInfo action = PluginsLocator.getActionInfoManager().getAction("layer-exportto"); |
|
458 |
action.execute(new Object[]{layer, MODE.toInteger(MODE.DIALOG)}); |
|
459 |
String msg = "_Do_you_want_to_finish_editing_If_not_exported_the_data_the_changes_will_be_lost"; |
|
460 |
if (appManager.confirmDialog( |
|
461 |
i18nManager.getTranslation(msg), |
|
462 |
i18nManager.getTranslation("end_editing"), |
|
463 |
JOptionPane.YES_NO_OPTION, |
|
464 |
JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { |
|
465 |
try { |
|
466 |
layer.getFeatureStore().cancelEditing(); |
|
467 |
} catch (Exception e) { |
|
468 |
LOGGER.warn("Can't abort editing of layer '" + layer.getName() + "'.", e); |
|
469 |
msg = "_Cant_finish_editing_See_the_error_log_for_more_information"; |
|
470 |
appManager.messageDialog(msg, "_Warning", JOptionPane.WARNING_MESSAGE); |
|
471 |
} |
|
472 |
} |
|
473 |
} |
|
474 |
|
|
475 |
private List<FLyrVect> getEditedLayers() { |
|
476 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
477 |
List<FLyrVect> editedLayers = new ArrayList<>(); |
|
478 |
|
|
479 |
Project project = application.getCurrentProject(); |
|
480 |
for (Document document : project.getDocuments(ViewManager.TYPENAME)) { |
|
481 |
ViewDocument view = (ViewDocument) document; |
|
482 |
MapContext mapContext = view.getMapContext(); |
|
483 |
if (mapContext != null) { |
|
484 |
FLayers layers = mapContext.getLayers(); |
|
485 |
for (int j = 0; j < layers.getLayersCount(); j++) { |
|
486 |
FLayer lyr = layers.getLayer(j); |
|
487 |
if (lyr instanceof FLyrVect) { |
|
488 |
FLyrVect layerVect = (FLyrVect) lyr; |
|
489 |
if (layerVect.isEditing()) { |
|
490 |
editedLayers.add(layerVect); |
|
491 |
} |
|
492 |
} |
|
493 |
} |
|
494 |
} |
|
495 |
} |
|
496 |
return editedLayers; |
|
497 |
} |
|
498 |
|
|
499 |
private List<IUnsavedData> getUnsavedData(List<FLyrVect> editedLayers) { |
|
500 |
List<IUnsavedData> unsavedData = new ArrayList<>(); |
|
501 |
for (FLyrVect editedLayer : editedLayers) { |
|
502 |
IUnsavedData unsavedDataLayer = new UnsavedLayer(this, editedLayer); |
|
503 |
unsavedData.add(unsavedDataLayer); |
|
504 |
} |
|
505 |
return unsavedData; |
|
506 |
|
|
507 |
} |
|
508 |
|
|
509 |
private static class UnsavedLayer extends UnsavedData { |
|
510 |
|
|
511 |
private final FLyrVect layer; |
|
512 |
|
|
513 |
public UnsavedLayer(IExtension extension, FLyrVect layer) { |
|
514 |
super(extension); |
|
515 |
this.layer = layer; |
|
516 |
} |
|
517 |
|
|
518 |
@Override |
|
519 |
public String getDescription() { |
|
520 |
return layer.getName(); |
|
521 |
} |
|
522 |
|
|
523 |
@Override |
|
524 |
public String getResourceName() { |
|
525 |
return layer.getFeatureStore().getFullName(); |
|
526 |
} |
|
527 |
|
|
528 |
@Override |
|
529 |
public boolean saveData() { |
|
530 |
FeatureStore featureStore = layer.getFeatureStore(); |
|
531 |
if (featureStore.isEditing()) { |
|
532 |
try { |
|
533 |
featureStore.finishEditing(); |
|
534 |
return true; |
|
535 |
} catch (DataException e) { |
|
536 |
throw new RuntimeException(e); |
|
537 |
} |
|
538 |
} |
|
539 |
return true; |
|
540 |
} |
|
541 |
} |
|
542 |
|
|
543 |
@Override |
|
544 |
public IExtensionStatus getStatus() { |
|
545 |
List<FLyrVect> editedLayers = getEditedLayers(); |
|
546 |
final List<IUnsavedData> unsavedData = getUnsavedData(editedLayers); |
|
547 |
|
|
548 |
return new IExtensionStatus() { |
|
549 |
|
|
550 |
@Override |
|
551 |
public boolean hasUnsavedData() { |
|
552 |
if (unsavedData == null) { |
|
553 |
return false; |
|
554 |
} |
|
555 |
return !unsavedData.isEmpty(); |
|
556 |
} |
|
557 |
|
|
558 |
@Override |
|
559 |
public boolean hasRunningProcesses() { |
|
560 |
return false; |
|
561 |
} |
|
562 |
|
|
563 |
@Override |
|
564 |
public IUnsavedData[] getUnsavedData() { |
|
565 |
if (unsavedData == null) { |
|
566 |
return null; |
|
567 |
} |
|
568 |
return unsavedData.toArray(new IUnsavedData[0]); |
|
569 |
} |
|
570 |
|
|
571 |
@Override |
|
572 |
public IMonitorableTask[] getRunningProcesses() { |
|
573 |
return null; |
|
574 |
} |
|
575 |
}; |
|
576 |
} |
|
577 |
|
|
578 |
private void showMultilaterFinishEditingPanel(MapContext mapContext) { |
|
579 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
580 |
WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
|
581 |
MultilayerFinishEditingPanel finishEditingPanel = new MultilayerFinishEditingPanel(mapContext); |
|
582 |
Dialog dialog = windowManager.createDialog( |
|
583 |
finishEditingPanel.asJComponent(), |
|
584 |
i18n.getTranslation("end_editing"), |
|
585 |
i18n.getTranslation("_List_of_layers_to_finish_editing"), |
|
586 |
WindowManager_v2.BUTTONS_OK_CANCEL |
|
587 |
); |
|
588 |
finishEditingPanel.setDialog(dialog); |
|
589 |
dialog.addActionListener((ActionEvent e) -> { |
|
590 |
if (dialog.getAction() == WindowManager_v2.BUTTON_OK) { |
|
591 |
finishEditingPanel.apply(); |
|
592 |
} |
|
593 |
}); |
|
594 |
dialog.show(WindowManager.MODE.WINDOW); |
|
595 |
} |
|
596 |
|
|
597 |
private static class ExpressionBuilderAction extends AbstractAction { |
|
598 |
|
|
599 |
private final EditingConsole console; |
|
600 |
private final EditingContext editingContext; |
|
601 |
|
|
602 |
|
|
603 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
|
604 |
public ExpressionBuilderAction(EditingContext editingContext, EditingConsole console) { |
|
605 |
this.editingContext = editingContext; |
|
606 |
this.console = console; |
|
607 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
608 |
this.putValue( |
|
609 |
Action.ACTION_COMMAND_KEY, |
|
610 |
"CreateJExpressionBuilderAction" |
|
611 |
); |
|
612 |
this.putValue( |
|
613 |
Action.NAME, |
|
614 |
i18n.getTranslation("_Show_expression_builder") |
|
615 |
); |
|
616 |
this.putValue( |
|
617 |
Action.SMALL_ICON, |
|
618 |
ToolsSwingLocator.getIconThemeManager().getCurrent().get("picker-expression") |
|
619 |
); |
|
620 |
} |
|
621 |
|
|
622 |
@Override |
|
623 |
public void actionPerformed(ActionEvent e) { |
|
624 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
625 |
WindowManager_v2 winmgr = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
|
626 |
final JExpressionBuilder panel = ExpressionEvaluatorSwingLocator.getManager().createJExpressionBuilder(); |
|
627 |
panel.getConfig().addSymbolTable(this.editingContext.getContextSymbolTable()); |
|
628 |
panel.getConfig().setPreviewSymbolTable(this.editingContext.getContextSymbolTable()); |
|
629 |
final Dialog dialog = winmgr.createDialog( |
|
630 |
panel.asJComponent(), |
|
631 |
i18n.getTranslation("_Expression_builder"), |
|
632 |
null, |
|
633 |
WindowManager_v2.BUTTONS_OK_CANCEL |
|
634 |
); |
|
635 |
dialog.addActionListener((ActionEvent e2) -> { |
|
636 |
if( dialog.getAction()==WindowManager_v2.BUTTON_OK ) { |
|
637 |
console.addResponseText(panel.getExpression().getPhrase()); |
|
638 |
} |
|
639 |
}); |
|
640 |
dialog.show(WindowManager.MODE.DIALOG); |
|
641 |
} |
|
642 |
|
|
643 |
} |
|
644 |
|
|
645 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.254/org.gvsig.vectorediting.app/org.gvsig.vectorediting.app.mainplugin/src/main/java/org/gvsig/vectorediting/app/mainplugin/dynformfield/point/JDynFormFieldPointFactory.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
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 3 |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.vectorediting.app.mainplugin.dynformfield.point; |
|
25 |
|
|
26 |
import org.gvsig.fmap.geom.DataTypes; |
|
27 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
|
28 |
import org.gvsig.tools.dynform.JDynFormField; |
|
29 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
|
30 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormFieldFactory; |
|
31 |
|
|
32 |
public class JDynFormFieldPointFactory extends AbstractJDynFormFieldFactory { |
|
33 |
|
|
34 |
public static final String NAME = "EditingPoint"; |
|
35 |
|
|
36 |
public JDynFormFieldPointFactory() { |
|
37 |
super("POINT", DataTypes.GEOMETRY, "EditingPoint"); |
|
38 |
} |
|
39 |
|
|
40 |
@Override |
|
41 |
public JDynFormField create( |
|
42 |
DynFormSPIManager serviceManager, |
|
43 |
DynFormSPIManager.ComponentsFactory componentsFactory, |
|
44 |
DynFormFieldDefinition fieldDefinition, |
|
45 |
Object value |
|
46 |
) { |
|
47 |
return new JDynFormFieldPoint(serviceManager, componentsFactory, this, fieldDefinition, value); |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
public int getPriority() { |
|
52 |
return 300; |
|
53 |
} |
|
54 |
} |
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.254/org.gvsig.vectorediting.app/org.gvsig.vectorediting.app.mainplugin/src/main/java/org/gvsig/vectorediting/app/mainplugin/dynformfield/point/JDynFormFieldPoint.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or modify it under |
|
7 |
* the terms of the GNU General Public License as published by the Free Software |
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later |
|
9 |
* version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
14 |
* details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us at info AT |
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.vectorediting.app.mainplugin.dynformfield.point; |
|
24 |
|
|
25 |
import java.awt.BorderLayout; |
|
26 |
import java.awt.event.ActionEvent; |
|
27 |
import java.awt.event.FocusEvent; |
|
28 |
import java.awt.event.FocusListener; |
|
29 |
import javax.swing.JButton; |
|
30 |
import javax.swing.JPanel; |
|
31 |
import javax.swing.event.DocumentEvent; |
|
32 |
import javax.swing.event.DocumentListener; |
|
33 |
import javax.swing.text.JTextComponent; |
|
34 |
import org.apache.commons.lang3.StringUtils; |
|
35 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
|
36 |
import org.gvsig.fmap.geom.primitive.Point; |
|
37 |
import org.gvsig.tools.ToolsLocator; |
|
38 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
|
39 |
import org.gvsig.tools.dynform.JDynFormField; |
|
40 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
|
41 |
import org.gvsig.tools.dynform.spi.dynformfield.JDynFormFieldFactory; |
|
42 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField; |
|
43 |
import org.gvsig.tools.dynobject.Tags; |
|
44 |
import org.gvsig.tools.i18n.I18nManager; |
|
45 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
46 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
|
47 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
|
48 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
|
49 |
import org.gvsig.vectorediting.swing.api.EditingContext; |
|
50 |
import org.gvsig.vectorediting.swing.api.EditingSwingLocator; |
|
51 |
import org.gvsig.vectorediting.swing.api.JPointPanel; |
|
52 |
|
|
53 |
public class JDynFormFieldPoint extends AbstractJDynFormField implements JDynFormField, FocusListener { |
|
54 |
|
|
55 |
protected Point assignedValue = null; |
|
56 |
protected Point currentValue = null; |
|
57 |
protected JTextComponent jtext = null; |
|
58 |
protected JButton jbutton = null; |
|
59 |
protected boolean readonly = false; |
|
60 |
|
|
61 |
public JDynFormFieldPoint( |
|
62 |
DynFormSPIManager serviceManager, |
|
63 |
DynFormSPIManager.ComponentsFactory componentsFactory, |
|
64 |
JDynFormFieldFactory factory, |
|
65 |
DynFormFieldDefinition definition, |
|
66 |
Object value |
|
67 |
) { |
|
68 |
super(serviceManager, componentsFactory, factory, definition, value); |
|
69 |
this.assignedValue = (Point) value; |
|
70 |
} |
|
71 |
|
|
72 |
@Override |
|
73 |
public void setReadOnly(boolean readonly) { |
|
74 |
super.setReadOnly(readonly); |
|
75 |
if (this.contents != null) { |
|
76 |
if (readonly) { |
|
77 |
this.jtext.setEditable(false); |
|
78 |
this.jbutton.setEnabled(false); |
|
79 |
} else { |
|
80 |
this.jtext.setEditable(true); |
|
81 |
this.jbutton.setEnabled(true); |
|
82 |
} |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
@Override |
|
87 |
public Object getAssignedValue() { |
|
88 |
return this.assignedValue; |
|
89 |
} |
|
90 |
|
|
91 |
@Override |
|
92 |
public void initComponent() { |
|
93 |
this.contents = new JPanel(); |
|
94 |
this.contents.setLayout(new BorderLayout()); |
|
95 |
|
|
96 |
JTextComponent text = this.getComponentsFactory().getJTextField(this.getDefinition(), null); |
|
97 |
this.jtext = text; |
|
98 |
this.fixPreferredWidth(text); |
|
99 |
text.addFocusListener(this); |
|
100 |
//this.jtext.setEditable(false); |
|
101 |
text.getDocument().addDocumentListener(new DocumentListener() { |
|
102 |
@Override |
|
103 |
public void insertUpdate(DocumentEvent e) { |
|
104 |
fireFieldChangedEvent(); |
|
105 |
} |
|
106 |
|
|
107 |
@Override |
|
108 |
public void removeUpdate(DocumentEvent e) { |
|
109 |
fireFieldChangedEvent(); |
|
110 |
} |
|
111 |
|
|
112 |
@Override |
|
113 |
public void changedUpdate(DocumentEvent e) { |
|
114 |
fireFieldChangedEvent(); |
|
115 |
} |
|
116 |
}); |
|
117 |
|
|
118 |
this.jbutton = this.getComponentsFactory().getJButton(this.getDefinition(), null); |
|
119 |
this.jbutton.setIcon(this.getIcon("insert-point")); |
|
120 |
if( StringUtils.equals("...", this.jbutton.getText()) ) { |
|
121 |
this.jbutton.setText(""); |
|
122 |
} |
|
123 |
this.jbutton.addActionListener((ActionEvent e) -> { |
|
124 |
onClickPointPanel(); |
|
125 |
}); |
|
126 |
|
|
127 |
this.contents.add(jtext, BorderLayout.CENTER); |
|
128 |
this.contents.add(jbutton, BorderLayout.LINE_END); |
|
129 |
this.contents.setVisible(true); |
|
130 |
|
|
131 |
if (this.readonly) { |
|
132 |
this.jtext.setEditable(false); |
|
133 |
this.jbutton.setEnabled(false); |
|
134 |
} else { |
|
135 |
this.jtext.setEditable(true); |
|
136 |
this.jbutton.setEnabled(true); |
|
137 |
} |
|
138 |
this.setValue(this.assignedValue); |
|
139 |
} |
|
140 |
|
|
141 |
public void onClickPointPanel() { |
|
142 |
fireFieldEnterEvent(); |
|
143 |
Point previous = this.currentValue; |
|
144 |
|
|
145 |
this.problemIndicator().restore(); |
|
146 |
Point x = showOpenPointDialog(this.getLabel(),this.currentValue); |
|
147 |
if (x == null) { |
|
148 |
return; |
|
149 |
} |
|
150 |
this.currentValue = x; |
|
151 |
this.jtext.setText(pointToText(x)); |
|
152 |
this.fireFieldChangedEventIfChanged(previous); |
|
153 |
} |
|
154 |
|
|
155 |
private void fireFieldChangedEventIfChanged(Point previous) { |
|
156 |
if (previous == null) { |
|
157 |
if (this.currentValue == null) { |
|
158 |
return; |
|
159 |
} |
|
160 |
this.fireFieldChangedEvent(); |
|
161 |
return; |
|
162 |
} |
|
163 |
if (this.currentValue == null) { |
|
164 |
this.fireFieldChangedEvent(); |
|
165 |
return; |
|
166 |
} |
|
167 |
if (!previous.toString().equals(this.currentValue.toString())) { |
|
168 |
this.fireFieldChangedEvent(); |
|
169 |
} |
|
170 |
} |
|
171 |
|
|
172 |
@Override |
|
173 |
public void setValue(Object value) { |
|
174 |
Point previous = this.currentValue; |
|
175 |
if (value == null) { |
|
176 |
this.jtext.setText(""); |
|
177 |
} else { |
|
178 |
if (!(value instanceof Point)) { |
|
179 |
LOGGER.info("setValue invoked with non Point value (" + value.toString() + ")."); |
|
180 |
return; |
|
181 |
} |
|
182 |
this.jtext.setText(pointToText((Point) value)); |
|
183 |
this.fixPreferredWidth(this.jtext); |
|
184 |
} |
|
185 |
this.assignedValue = (Point) value; |
|
186 |
this.currentValue = this.assignedValue; |
|
187 |
this.fireFieldChangedEventIfChanged(previous); |
|
188 |
} |
|
189 |
|
|
190 |
@Override |
|
191 |
public Object getValue() { |
|
192 |
Point value; |
|
193 |
String s = this.jtext.getText(); |
|
194 |
if (StringUtils.isBlank(s)){ |
|
195 |
return null; |
|
196 |
} |
|
197 |
value = textToPoint(s); |
|
198 |
return value; |
|
199 |
} |
|
200 |
|
|
201 |
@Override |
|
202 |
public boolean hasValidValue() { |
|
203 |
return true; |
|
204 |
} |
|
205 |
|
|
206 |
|
|
207 |
@Override |
|
208 |
public void focusGained(FocusEvent arg0) { |
|
209 |
fireFieldEnterEvent(); |
|
210 |
this.problemIndicator().restore(); |
|
211 |
} |
|
212 |
|
|
213 |
@Override |
|
214 |
public void focusLost(FocusEvent arg0) { |
|
215 |
fireFieldExitEvent(); |
|
216 |
} |
|
217 |
|
|
218 |
@Override |
|
219 |
public void clear() { |
|
220 |
Object value = this.getDefinition().getDefaultValue(); |
|
221 |
if (value != null) { |
|
222 |
value = pointToText((Point) value); |
|
223 |
} else { |
|
224 |
value = ""; |
|
225 |
} |
|
226 |
this.jtext.setText((String) value); |
|
227 |
} |
|
228 |
|
|
229 |
private String pointToText(Point p) { |
|
230 |
StringBuilder buffer = new StringBuilder(); |
|
231 |
for (int i = 0; i < p.getDimension(); i++) { |
|
232 |
double n = p.getCoordinateAt(i); |
|
233 |
if( buffer.length()>0 ) { |
|
234 |
buffer.append(", "); |
|
235 |
} |
|
236 |
buffer.append(n); |
|
237 |
} |
|
238 |
return buffer.toString(); |
|
239 |
} |
|
240 |
|
|
241 |
private Point textToPoint(String text) { |
|
242 |
try { |
|
243 |
return (Point) ExpressionUtils.evaluate("ST_MakePoint("+text+")"); |
|
244 |
} catch(Exception ex) { |
|
245 |
return null; |
|
246 |
} |
|
247 |
} |
Also available in: Unified diff