Revision 41768
tags/org.gvsig.desktop-2.0.62/org.gvsig.desktop.framework/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<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"> |
|
3 |
|
|
4 |
<modelVersion>4.0.0</modelVersion> |
|
5 |
<artifactId>org.gvsig.desktop.framework</artifactId> |
|
6 |
<packaging>pom</packaging> |
|
7 |
<name>${project.artifactId}</name> |
|
8 |
<parent> |
|
9 |
<groupId>org.gvsig</groupId> |
|
10 |
<artifactId>org.gvsig.desktop</artifactId> |
|
11 |
<version>2.0.62</version> |
|
12 |
</parent> |
|
13 |
|
|
14 |
<modules> |
|
15 |
<module>org.gvsig.andami</module> |
|
16 |
<module>org.gvsig.andami.updater</module> |
|
17 |
</modules> |
|
18 |
|
|
19 |
<description>Contains the launcher and plugin framework used in gvSIG.</description> |
|
20 |
</project> |
|
21 |
|
|
0 | 22 |
tags/org.gvsig.desktop-2.0.62/org.gvsig.desktop.framework/org.gvsig.andami/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
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 |
<artifactId>org.gvsig.andami</artifactId> |
|
6 |
<packaging>jar</packaging> |
|
7 |
<name>${project.artifactId}</name> |
|
8 |
<description>Plugins management framework</description> |
|
9 |
<parent> |
|
10 |
<groupId>org.gvsig</groupId> |
|
11 |
<artifactId>org.gvsig.desktop.framework</artifactId> |
|
12 |
<version>2.0.62</version> |
|
13 |
</parent> |
|
14 |
|
|
15 |
<dependencies> |
|
16 |
|
|
17 |
<!-- This dependency is a patch to resolve a problem with jcrs --> |
|
18 |
<!-- This can be removed in the near future --> |
|
19 |
<!-- <dependency> --> |
|
20 |
<!-- <groupId>org.gvsig</groupId> --> |
|
21 |
<!-- <artifactId>org.gvsig.projection.api</artifactId> --> |
|
22 |
<!-- <scope>compile</scope> --> |
|
23 |
<!-- </dependency> --> |
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
<dependency> |
|
28 |
<groupId>org.slf4j</groupId> |
|
29 |
<artifactId>slf4j-api</artifactId> |
|
30 |
<scope>compile</scope> |
|
31 |
</dependency> |
|
32 |
<dependency> |
|
33 |
<groupId>commons-configuration</groupId> |
|
34 |
<artifactId>commons-configuration</artifactId> |
|
35 |
<scope>compile</scope> |
|
36 |
</dependency> |
|
37 |
<dependency> |
|
38 |
<groupId>commons-io</groupId> |
|
39 |
<artifactId>commons-io</artifactId> |
|
40 |
<scope>compile</scope> |
|
41 |
</dependency> |
|
42 |
<dependency> |
|
43 |
<groupId>org.gvsig</groupId> |
|
44 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
45 |
<scope>compile</scope> |
|
46 |
</dependency> |
|
47 |
<dependency> |
|
48 |
<groupId>org.gvsig</groupId> |
|
49 |
<artifactId>org.gvsig.tools.dynform.api</artifactId> |
|
50 |
<scope>compile</scope> |
|
51 |
</dependency> |
|
52 |
<dependency> |
|
53 |
<groupId>org.gvsig</groupId> |
|
54 |
<artifactId>org.gvsig.tools.dynform.spi</artifactId> |
|
55 |
<scope>compile</scope> |
|
56 |
</dependency> |
|
57 |
<dependency> |
|
58 |
<groupId>org.gvsig</groupId> |
|
59 |
<artifactId>org.gvsig.tools.dynform.services</artifactId> |
|
60 |
<scope>compile</scope> |
|
61 |
</dependency> |
|
62 |
<dependency> |
|
63 |
<groupId>org.gvsig</groupId> |
|
64 |
<artifactId>org.gvsig.tools.dynform.impl</artifactId> |
|
65 |
<scope>compile</scope> |
|
66 |
</dependency> |
|
67 |
<dependency> |
|
68 |
<groupId>org.gvsig</groupId> |
|
69 |
<artifactId>org.gvsig.i18n</artifactId> |
|
70 |
<scope>compile</scope> |
|
71 |
</dependency> |
|
72 |
<dependency> |
|
73 |
<groupId>org.gvsig</groupId> |
|
74 |
<artifactId>org.gvsig.tools.swing.api</artifactId> |
|
75 |
<scope>compile</scope> |
|
76 |
</dependency> |
|
77 |
<dependency> |
|
78 |
<groupId>org.gvsig</groupId> |
|
79 |
<artifactId>org.gvsig.utils</artifactId> |
|
80 |
<scope>compile</scope> |
|
81 |
</dependency> |
|
82 |
<dependency> |
|
83 |
<groupId>org.gvsig</groupId> |
|
84 |
<artifactId>org.gvsig.ui</artifactId> |
|
85 |
<scope>compile</scope> |
|
86 |
</dependency> |
|
87 |
<dependency> |
|
88 |
<groupId>org.gvsig</groupId> |
|
89 |
<artifactId>org.gvsig.installer.lib.api</artifactId> |
|
90 |
<scope>compile</scope> |
|
91 |
</dependency> |
|
92 |
<dependency> |
|
93 |
<groupId>org.gvsig</groupId> |
|
94 |
<artifactId>org.gvsig.installer.swing.api</artifactId> |
|
95 |
<scope>compile</scope> |
|
96 |
</dependency> |
|
97 |
<dependency> |
|
98 |
<groupId>javax.help</groupId> |
|
99 |
<artifactId>javahelp</artifactId> |
|
100 |
<scope>compile</scope> |
|
101 |
</dependency> |
|
102 |
<dependency> |
|
103 |
<groupId>com.jgoodies</groupId> |
|
104 |
<artifactId>looks</artifactId> |
|
105 |
</dependency> |
|
106 |
<dependency> |
|
107 |
<groupId>castor</groupId> |
|
108 |
<artifactId>castor</artifactId> |
|
109 |
<scope>compile</scope> |
|
110 |
</dependency> |
|
111 |
<dependency> |
|
112 |
<groupId>log4j</groupId> |
|
113 |
<artifactId>log4j</artifactId> |
|
114 |
<scope>compile</scope> |
|
115 |
</dependency> |
|
116 |
<dependency> |
|
117 |
<groupId>commons-cli</groupId> |
|
118 |
<artifactId>commons-cli</artifactId> |
|
119 |
<scope>compile</scope> |
|
120 |
</dependency> |
|
121 |
<dependency> |
|
122 |
<groupId>jwizardcomponent</groupId> |
|
123 |
<artifactId>jwizardcomponent</artifactId> |
|
124 |
<scope>compile</scope> |
|
125 |
</dependency> |
|
126 |
<dependency> |
|
127 |
<groupId>jwizardcomponent</groupId> |
|
128 |
<artifactId>jwizardcomponent-0i18n</artifactId> |
|
129 |
<scope>compile</scope> |
|
130 |
</dependency> |
|
131 |
<dependency> |
|
132 |
<groupId>net.sf.kxml</groupId> |
|
133 |
<artifactId>kxml2</artifactId> |
|
134 |
<scope>compile</scope> |
|
135 |
</dependency> |
|
136 |
|
|
137 |
<dependency> |
|
138 |
<groupId>org.gvsig</groupId> |
|
139 |
<artifactId>org.gvsig.about.api</artifactId> |
|
140 |
<scope>runtime</scope> |
|
141 |
</dependency> |
|
142 |
<dependency> |
|
143 |
<groupId>org.gvsig</groupId> |
|
144 |
<artifactId>org.gvsig.about.impl</artifactId> |
|
145 |
<scope>runtime</scope> |
|
146 |
</dependency> |
|
147 |
<dependency> |
|
148 |
<groupId>org.gvsig</groupId> |
|
149 |
<artifactId>org.gvsig.jdk.v1_6</artifactId> |
|
150 |
<scope>runtime</scope> |
|
151 |
</dependency> |
|
152 |
<dependency> |
|
153 |
<groupId>org.gvsig</groupId> |
|
154 |
<artifactId>org.gvsig.compat.api</artifactId> |
|
155 |
<scope>runtime</scope> |
|
156 |
</dependency> |
|
157 |
<dependency> |
|
158 |
<groupId>org.gvsig</groupId> |
|
159 |
<artifactId>org.gvsig.compat.se</artifactId> |
|
160 |
<scope>runtime</scope> |
|
161 |
</dependency> |
|
162 |
<dependency> |
|
163 |
<groupId>xerces</groupId> |
|
164 |
<artifactId>xercesImpl</artifactId> |
|
165 |
<scope>runtime</scope> |
|
166 |
</dependency> |
|
167 |
<dependency> |
|
168 |
<groupId>org.slf4j</groupId> |
|
169 |
<artifactId>slf4j-log4j12</artifactId> |
|
170 |
<scope>runtime</scope> |
|
171 |
</dependency> |
|
172 |
<dependency> |
|
173 |
<groupId>org.gvsig</groupId> |
|
174 |
<artifactId>org.gvsig.tools.swing.impl</artifactId> |
|
175 |
<scope>runtime</scope> |
|
176 |
</dependency> |
|
177 |
<dependency> |
|
178 |
<groupId>org.gvsig</groupId> |
|
179 |
<artifactId>org.gvsig.installer.lib.impl</artifactId> |
|
180 |
<scope>runtime</scope> |
|
181 |
</dependency> |
|
182 |
<dependency> |
|
183 |
<groupId>org.gvsig</groupId> |
|
184 |
<artifactId>org.gvsig.installer.lib.spi</artifactId> |
|
185 |
<scope>compile</scope> |
|
186 |
</dependency> |
|
187 |
<dependency> |
|
188 |
<groupId>org.gvsig</groupId> |
|
189 |
<artifactId>org.gvsig.installer.prov.plugin</artifactId> |
|
190 |
<scope>runtime</scope> |
|
191 |
</dependency> |
|
192 |
<dependency> |
|
193 |
<groupId>org.gvsig</groupId> |
|
194 |
<artifactId>org.gvsig.installer.swing.impl</artifactId> |
|
195 |
<scope>runtime</scope> |
|
196 |
</dependency> |
|
197 |
<dependency> |
|
198 |
<groupId>com.sardak</groupId> |
|
199 |
<artifactId>antform</artifactId> |
|
200 |
<scope>runtime</scope> |
|
201 |
</dependency> |
|
202 |
<dependency> |
|
203 |
<groupId>ant-contrib</groupId> |
|
204 |
<artifactId>ant-contrib</artifactId> |
|
205 |
<scope>runtime</scope> |
|
206 |
</dependency> |
|
207 |
<dependency> |
|
208 |
<groupId>org.apache.commons</groupId> |
|
209 |
<artifactId>commons-lang3</artifactId> |
|
210 |
<scope>compile</scope> |
|
211 |
</dependency> |
|
212 |
<dependency> |
|
213 |
<groupId>org.swinglabs</groupId> |
|
214 |
<artifactId>swing-layout</artifactId> |
|
215 |
<version>1.0.3</version> |
|
216 |
</dependency> |
|
217 |
</dependencies> |
|
218 |
|
|
219 |
|
|
220 |
<build> |
|
221 |
<plugins> |
|
222 |
|
|
223 |
<plugin> |
|
224 |
<groupId>org.codehaus.mojo</groupId> |
|
225 |
<artifactId>exec-maven-plugin</artifactId> |
|
226 |
<executions> |
|
227 |
<execution> |
|
228 |
<goals> |
|
229 |
<goal>exec</goal> |
|
230 |
</goals> |
|
231 |
</execution> |
|
232 |
</executions> |
|
233 |
<configuration> |
|
234 |
<executable>java</executable> |
|
235 |
<arguments> |
|
236 |
<argument>-classpath</argument> |
|
237 |
<!-- automatically creates the classpath using all project |
|
238 |
dependencies, also adding the project build directory --> |
|
239 |
<classpath /> |
|
240 |
<argument>org.gvsig.andami.Launcher</argument> |
|
241 |
<argument>gvSIG</argument> |
|
242 |
<argument>${gvsig.install.dir}/gvSIG/extensiones</argument> |
|
243 |
</arguments> |
|
244 |
<environmentVariables> |
|
245 |
<GDAL_DATA>${user.home}/.depman/data/gdal</GDAL_DATA> |
|
246 |
<PROJ_LIB>gvSIG/extensiones/org.gvsig.crs.extension/data</PROJ_LIB> |
|
247 |
<LD_LIBRARY_PATH>${user.home}/.depman/lib</LD_LIBRARY_PATH> |
|
248 |
<PATH>${user.home}/.depman/bin</PATH> |
|
249 |
</environmentVariables> |
|
250 |
</configuration> |
|
251 |
</plugin> |
|
252 |
|
|
253 |
<plugin> |
|
254 |
<artifactId>maven-assembly-plugin</artifactId> |
|
255 |
<configuration> |
|
256 |
<ignoreDirFormatExtensions>true</ignoreDirFormatExtensions> |
|
257 |
<appendAssemblyId>false</appendAssemblyId> |
|
258 |
</configuration> |
|
259 |
<executions> |
|
260 |
<execution> |
|
261 |
<id>gvsig-plugin-package</id> |
|
262 |
<phase>package</phase> |
|
263 |
<goals> |
|
264 |
<goal>single</goal> |
|
265 |
</goals> |
|
266 |
<configuration> |
|
267 |
<finalName>${project.artifactId}-${project.version}-root-folder</finalName> |
|
268 |
<descriptors> |
|
269 |
<descriptor>src/main/assembly/gvsig-andami-package.xml</descriptor> |
|
270 |
</descriptors> |
|
271 |
</configuration> |
|
272 |
</execution> |
|
273 |
</executions> |
|
274 |
</plugin> |
|
275 |
|
|
276 |
<plugin> |
|
277 |
<groupId>org.codehaus.gmaven</groupId> |
|
278 |
<artifactId>gmaven-plugin</artifactId> |
|
279 |
<executions> |
|
280 |
<execution> |
|
281 |
<id>install-plugin</id> |
|
282 |
<phase>install</phase> |
|
283 |
<goals> |
|
284 |
<goal>execute</goal> |
|
285 |
</goals> |
|
286 |
<configuration> |
|
287 |
<source><![CDATA[ |
|
288 |
ant = new AntBuilder() |
|
289 |
source = project.basedir.getAbsolutePath() + |
|
290 |
"/target/" + |
|
291 |
project.artifactId + "-" + |
|
292 |
project.version + "-" + |
|
293 |
"root-folder.zip" |
|
294 |
target = project.properties["gvsig.product.folder.path"] |
|
295 |
ant.unzip(src: source, dest: target) |
|
296 |
ant.chmod(file:target+"/gvSIG.sh", perm:"a+rx") |
|
297 |
]]></source> |
|
298 |
</configuration> |
|
299 |
</execution> |
|
300 |
</executions> |
|
301 |
</plugin> |
|
302 |
|
|
303 |
<plugin> |
|
304 |
<artifactId>maven-clean-plugin</artifactId> |
|
305 |
<configuration> |
|
306 |
<skip>false</skip> |
|
307 |
<failOnError>true</failOnError> |
|
308 |
<filesets> |
|
309 |
<fileset> |
|
310 |
<directory>${gvsig.product.folder.path}/lib</directory> |
|
311 |
</fileset> |
|
312 |
</filesets> |
|
313 |
</configuration> |
|
314 |
<executions> |
|
315 |
<execution> |
|
316 |
<id>default-clean</id> |
|
317 |
<phase>clean</phase> |
|
318 |
</execution> |
|
319 |
</executions> |
|
320 |
</plugin> |
|
321 |
</plugins> |
|
322 |
</build> |
|
323 |
|
|
324 |
</project> |
|
0 | 325 |
tags/org.gvsig.desktop-2.0.62/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/help/AndamiHelpPanel.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.andami.help; |
|
25 |
|
|
26 |
import javax.help.HelpSet; |
|
27 |
|
|
28 |
import org.gvsig.andami.PluginServices; |
|
29 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
30 |
import org.gvsig.andami.ui.mdiManager.MDIManager; |
|
31 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
public class AndamiHelpPanel extends HelpPanel implements IWindow { |
|
36 |
|
|
37 |
private static final long serialVersionUID = 2683827167020046672L; |
|
38 |
|
|
39 |
private WindowInfo info = null ; |
|
40 |
|
|
41 |
public AndamiHelpPanel(HelpSet hs){ |
|
42 |
super(hs); |
|
43 |
} |
|
44 |
|
|
45 |
public AndamiHelpPanel(HelpSet hs, String id){ |
|
46 |
super(hs,id); |
|
47 |
} |
|
48 |
|
|
49 |
public void showWindow() { |
|
50 |
MDIManager mdim = PluginServices.getMDIManager(); |
|
51 |
mdim.addWindow((IWindow) this); |
|
52 |
} |
|
53 |
|
|
54 |
public WindowInfo getWindowInfo() { |
|
55 |
if( info == null ) { |
|
56 |
info = new WindowInfo( WindowInfo.RESIZABLE | |
|
57 |
WindowInfo.MAXIMIZABLE | WindowInfo.MODELESSDIALOG); |
|
58 |
info.setHeight(HEIGHT); |
|
59 |
info.setWidth(WIDTH); |
|
60 |
info.setTitle(getTitle()); |
|
61 |
} |
|
62 |
return info; |
|
63 |
} |
|
64 |
|
|
65 |
public Object getWindowProfile() { |
|
66 |
return WindowInfo.TOOL_PROFILE; |
|
67 |
} |
|
68 |
|
|
69 |
} |
|
0 | 70 |
tags/org.gvsig.desktop-2.0.62/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/help/Help.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.andami.help; |
|
25 |
|
|
26 |
import java.awt.event.ActionEvent; |
|
27 |
import java.awt.event.ActionListener; |
|
28 |
import java.awt.event.KeyEvent; |
|
29 |
import java.io.File; |
|
30 |
import java.net.MalformedURLException; |
|
31 |
import java.net.URL; |
|
32 |
import java.net.URLClassLoader; |
|
33 |
import java.text.MessageFormat; |
|
34 |
import java.util.ArrayList; |
|
35 |
import java.util.Iterator; |
|
36 |
import java.util.Locale; |
|
37 |
|
|
38 |
import javax.help.HelpSet; |
|
39 |
import javax.swing.JComponent; |
|
40 |
import javax.swing.KeyStroke; |
|
41 |
|
|
42 |
import org.slf4j.Logger; |
|
43 |
import org.slf4j.LoggerFactory; |
|
44 |
|
|
45 |
|
|
46 |
public class Help { |
|
47 |
|
|
48 |
private static Help help = null; |
|
49 |
|
|
50 |
private HelpSet mainHS = null; |
|
51 |
private ArrayList resources = new ArrayList(); |
|
52 |
private ArrayList helps = new ArrayList(); |
|
53 |
|
|
54 |
private HelpPanel window=null; |
|
55 |
|
|
56 |
public static Help getHelp() { |
|
57 |
if( help == null ) { |
|
58 |
help = new Help(); |
|
59 |
} |
|
60 |
return help; |
|
61 |
} |
|
62 |
|
|
63 |
private Logger log() { |
|
64 |
return LoggerFactory.getLogger("org.gvsig"); |
|
65 |
} |
|
66 |
|
|
67 |
public void show() { |
|
68 |
log().info("show()"); |
|
69 |
show(null); |
|
70 |
} |
|
71 |
|
|
72 |
public void show(String id) { |
|
73 |
try { |
|
74 |
log().info("show(id) id="+id); |
|
75 |
initHelp(); |
|
76 |
try { |
|
77 |
window.showWindow(id); |
|
78 |
}catch(NullPointerException e) { |
|
79 |
window = new AndamiHelpPanel(mainHS, id); |
|
80 |
window.showWindow(); |
|
81 |
} |
|
82 |
} catch (Exception ex) { |
|
83 |
log().error("Se ha producido un error mostrando la ventana de ayuda.",ex); |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
public void enableHelp(JComponent comp, String id) |
|
88 |
{ |
|
89 |
try{ |
|
90 |
initHelp(); |
|
91 |
comp.registerKeyboardAction(new DisplayHelpFromFocus(id), KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); |
|
92 |
} |
|
93 |
catch(Exception except){ |
|
94 |
log().error("ID: "+id+" erronea"); |
|
95 |
} |
|
96 |
} |
|
97 |
|
|
98 |
public boolean addResource(String path) { |
|
99 |
URL url = null; |
|
100 |
try { |
|
101 |
url = (new File(path)).toURL(); |
|
102 |
} catch (MalformedURLException e) { |
|
103 |
return false; |
|
104 |
} |
|
105 |
resources.add(url); |
|
106 |
return true; |
|
107 |
} |
|
108 |
|
|
109 |
|
|
110 |
public boolean addHelp(String helpName) { |
|
111 |
helps.add(helpName); |
|
112 |
return true; |
|
113 |
} |
|
114 |
|
|
115 |
private void initHelp() |
|
116 |
{ |
|
117 |
if ( mainHS != null ) { |
|
118 |
return; |
|
119 |
} |
|
120 |
|
|
121 |
// |
|
122 |
// Obtenemos un array de URLs de array list de URLs |
|
123 |
// |
|
124 |
URL urls[] = new URL[resources.size()]; |
|
125 |
int i=0; |
|
126 |
for( Iterator it=resources.iterator(); it.hasNext() ;) { |
|
127 |
urls[i++] = (URL) it.next(); |
|
128 |
} |
|
129 |
|
|
130 |
// |
|
131 |
// Creamos la lista de helpsets que han de componer |
|
132 |
// la ayuda |
|
133 |
// |
|
134 |
ArrayList helpSets = new ArrayList(); |
|
135 |
|
|
136 |
for( Iterator it=helps.iterator(); it.hasNext() ;) { |
|
137 |
String name = (String) it.next(); |
|
138 |
String lang = Locale.getDefault().getLanguage(); |
|
139 |
HelpSet hs = createHelpSet(urls, name + "/" + lang + "/help.hs"); |
|
140 |
if( hs == null ) { |
|
141 |
lang = "en"; |
|
142 |
hs = createHelpSet(urls, name + "/" + lang + "/help.hs"); |
|
143 |
} |
|
144 |
if( hs != null ) { |
|
145 |
helpSets.add(hs); |
|
146 |
} |
|
147 |
} |
|
148 |
|
|
149 |
// |
|
150 |
// Fijamos el primer helpset de la lista como master y |
|
151 |
// le a?adimos (merge) a este los demas helpsets |
|
152 |
// |
|
153 |
Iterator it=helpSets.iterator(); |
|
154 |
if( ! it.hasNext() ) { |
|
155 |
return; |
|
156 |
} |
|
157 |
mainHS = (HelpSet) it.next(); |
|
158 |
while( it.hasNext() ) { |
|
159 |
try { |
|
160 |
mainHS.add( (HelpSet) it.next() ); |
|
161 |
} catch (Exception ex) { |
|
162 |
log().error(ex.toString()); |
|
163 |
} |
|
164 |
} |
|
165 |
} |
|
166 |
|
|
167 |
private HelpSet createHelpSet(URL resources[], String hsName) { |
|
168 |
HelpSet hs = null; |
|
169 |
|
|
170 |
ClassLoader loader = ClassLoader.getSystemClassLoader(); |
|
171 |
loader = new URLClassLoader(resources, loader); |
|
172 |
URL url = HelpSet.findHelpSet(loader, hsName); |
|
173 |
if (url == null) { |
|
174 |
log().error( |
|
175 |
MessageFormat.format( |
|
176 |
"No se ha encontrado el helpset ''{0}''.", |
|
177 |
new Object[] { hsName } |
|
178 |
) |
|
179 |
); |
|
180 |
return null; |
|
181 |
} |
|
182 |
log().info("createHelpSet: url="+url); |
|
183 |
|
|
184 |
try { |
|
185 |
hs = new HelpSet(null, url); |
|
186 |
} catch (Exception ex) { |
|
187 |
log().error( |
|
188 |
MessageFormat.format( |
|
189 |
"No se ha podido cargar el helpset desde ''{0}''.", |
|
190 |
new Object[] { url } |
|
191 |
), |
|
192 |
ex |
|
193 |
); |
|
194 |
return null; |
|
195 |
} |
|
196 |
return hs; |
|
197 |
} |
|
198 |
|
|
199 |
|
|
200 |
public class DisplayHelpFromFocus implements ActionListener { |
|
201 |
|
|
202 |
private String id = null; |
|
203 |
|
|
204 |
public DisplayHelpFromFocus(String id) { |
|
205 |
log().info("DisplayHelpFromFocus(id) id="+id); |
|
206 |
this.id=id; |
|
207 |
} |
|
208 |
|
|
209 |
public void actionPerformed(ActionEvent e) { |
|
210 |
Help.getHelp().show(this.id); |
|
211 |
} |
|
212 |
} |
|
213 |
} |
|
214 |
|
|
0 | 215 |
tags/org.gvsig.desktop-2.0.62/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/help/HelpPanel.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.andami.help; |
|
25 |
|
|
26 |
import java.awt.BorderLayout; |
|
27 |
import java.awt.Frame; |
|
28 |
import java.awt.event.ComponentEvent; |
|
29 |
import java.awt.event.ComponentListener; |
|
30 |
|
|
31 |
import javax.help.BadIDException; |
|
32 |
import javax.help.HelpSet; |
|
33 |
import javax.help.JHelp; |
|
34 |
import javax.swing.JPanel; |
|
35 |
|
|
36 |
import org.slf4j.Logger; |
|
37 |
import org.slf4j.LoggerFactory; |
|
38 |
|
|
39 |
public class HelpPanel extends JPanel { |
|
40 |
|
|
41 |
private static final long serialVersionUID = 4164482247505362337L; |
|
42 |
|
|
43 |
public static int WIDTH = 645; |
|
44 |
public static int HEIGHT = 495; |
|
45 |
private String title = null; |
|
46 |
private JHelp jh; |
|
47 |
|
|
48 |
private Logger log() { |
|
49 |
return LoggerFactory.getLogger("org.gvsig"); |
|
50 |
} |
|
51 |
|
|
52 |
public HelpPanel(HelpSet hs){ |
|
53 |
log().info("HelpPanel(hs)"); |
|
54 |
init(hs,null); |
|
55 |
} |
|
56 |
|
|
57 |
public HelpPanel(HelpSet hs, String id){ |
|
58 |
log().info("HelpPanel(hs,id) id="+id); |
|
59 |
init(hs,id); |
|
60 |
} |
|
61 |
|
|
62 |
private void init(HelpSet hs, String id){ |
|
63 |
jh = new JHelp(hs); |
|
64 |
log().info("init() ID "+ id); |
|
65 |
if (id != null) { |
|
66 |
try { |
|
67 |
log().info("init() setCurrentID "+ id); |
|
68 |
jh.setCurrentID(id); |
|
69 |
} catch (BadIDException ex) { |
|
70 |
log().error(ex.toString()); |
|
71 |
|
|
72 |
} catch (NullPointerException ex) { |
|
73 |
log().error(ex.toString()); |
|
74 |
} |
|
75 |
} |
|
76 |
String hsTitle = hs.getTitle(); |
|
77 |
if (hsTitle == null || hsTitle.equals("")) { |
|
78 |
hsTitle = "gvSIG Help"; |
|
79 |
} |
|
80 |
title = hsTitle; |
|
81 |
setLayout(new BorderLayout()); |
|
82 |
add(jh,BorderLayout.CENTER); |
|
83 |
} |
|
84 |
|
|
85 |
public void showWindow() { |
|
86 |
|
|
87 |
log().info("showWindow()"); |
|
88 |
Frame frame = new Frame(); |
|
89 |
frame.add(this); |
|
90 |
frame.setSize(WIDTH, HEIGHT + 30); |
|
91 |
frame.setTitle(getTitle()); |
|
92 |
frame.setResizable(true); |
|
93 |
this.setVisible(true); |
|
94 |
frame.show(); |
|
95 |
} |
|
96 |
|
|
97 |
public void showWindow(String id) { |
|
98 |
if (id != null) { |
|
99 |
try { |
|
100 |
log().info("showWindow(id) -> setCurrentID "+ id); |
|
101 |
jh.setCurrentID(id); |
|
102 |
} catch (BadIDException ex) { |
|
103 |
log().error(ex.toString()); |
|
104 |
} |
|
105 |
} |
|
106 |
String hsTitle = jh.getHelpSetPresentation().getTitle(); |
|
107 |
if (hsTitle == null || hsTitle.equals("")) { |
|
108 |
hsTitle = "gvSIG Help"; |
|
109 |
} |
|
110 |
title = hsTitle; |
|
111 |
showWindow(); |
|
112 |
} |
|
113 |
|
|
114 |
public String getTitle() { |
|
115 |
return this.title; |
|
116 |
} |
|
117 |
|
|
118 |
} |
|
0 | 119 |
tags/org.gvsig.desktop-2.0.62/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/actioninfo/ActionInfoStatusCache.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.andami.actioninfo; |
|
25 |
|
|
26 |
public interface ActionInfoStatusCache { |
|
27 |
public void clear(); |
|
28 |
|
|
29 |
public boolean isEnabled(ActionInfo action); |
|
30 |
|
|
31 |
public boolean isVisible(ActionInfo action); |
|
32 |
} |
|
0 | 33 |
tags/org.gvsig.desktop-2.0.62/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/actioninfo/impl/DefaultActionInfoStatusCache.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.andami.actioninfo.impl; |
|
25 |
|
|
26 |
import java.util.HashMap; |
|
27 |
import java.util.Map; |
|
28 |
|
|
29 |
import org.gvsig.andami.actioninfo.ActionInfo; |
|
30 |
import org.gvsig.andami.actioninfo.ActionInfoStatusCache; |
|
31 |
import org.gvsig.andami.plugins.ExtensionHelper; |
|
32 |
import org.gvsig.andami.plugins.IExtension; |
|
33 |
import org.gvsig.tools.ToolsLocator; |
|
34 |
import org.gvsig.tools.identitymanagement.SimpleIdentity; |
|
35 |
import org.gvsig.tools.identitymanagement.SimpleIdentityManager; |
|
36 |
|
|
37 |
public class DefaultActionInfoStatusCache implements ActionInfoStatusCache { |
|
38 |
|
|
39 |
private SimpleIdentityManager identityManager; |
|
40 |
|
|
41 |
private class Status { |
|
42 |
Boolean isEnabled = null; |
|
43 |
Boolean isVisible = null; |
|
44 |
} |
|
45 |
|
|
46 |
private Map<IExtension,Status> extensions = null; |
|
47 |
private Map<ActionInfo,Status> actions = null; |
|
48 |
|
|
49 |
public DefaultActionInfoStatusCache() { |
|
50 |
this.clear(); |
|
51 |
} |
|
52 |
|
|
53 |
public void clear() { |
|
54 |
extensions = new HashMap<IExtension, Status>(); |
|
55 |
actions = new HashMap<ActionInfo, Status>(); |
|
56 |
} |
|
57 |
|
|
58 |
private SimpleIdentityManager getIdentityManager() { |
|
59 |
if( this.identityManager == null ) { |
|
60 |
this.identityManager = ToolsLocator.getIdentityManager(); |
|
61 |
} |
|
62 |
return this.identityManager; |
|
63 |
} |
|
64 |
|
|
65 |
private SimpleIdentity getCurrentUser() { |
|
66 |
return this.getIdentityManager().getCurrentIdentity(); |
|
67 |
} |
|
68 |
|
|
69 |
public boolean isEnabled(ActionInfo action) { |
|
70 |
if( !this.getCurrentUser().isAuthorized(action.getName()) ) { |
|
71 |
return false; |
|
72 |
} |
|
73 |
Status status; |
|
74 |
IExtension extension = action.getExtension(); |
|
75 |
if( extension == null ) { |
|
76 |
return false; |
|
77 |
} |
|
78 |
if( ExtensionHelper.canQueryByAction(extension) ) { |
|
79 |
status = actions.get(action); |
|
80 |
if( status == null ) { |
|
81 |
status = new Status(); |
|
82 |
actions.put(action, status); |
|
83 |
} |
|
84 |
if( status.isEnabled == null ) { |
|
85 |
status.isEnabled = new Boolean( action.isEnabled() ); |
|
86 |
} |
|
87 |
} else { |
|
88 |
status = extensions.get(extension); |
|
89 |
if( status == null ) { |
|
90 |
status = new Status(); |
|
91 |
extensions.put(extension, status); |
|
92 |
} |
|
93 |
if( status.isEnabled == null ) { |
|
94 |
status.isEnabled = new Boolean( extension.isEnabled() ); |
|
95 |
} |
|
96 |
} |
|
97 |
return status.isEnabled.booleanValue(); |
|
98 |
} |
|
99 |
|
|
100 |
public boolean isVisible(ActionInfo action) { |
|
101 |
if( !this.getCurrentUser().isAuthorized(action.getName()) ) { |
|
102 |
return false; |
|
103 |
} |
|
104 |
Status status; |
|
105 |
IExtension extension = action.getExtension(); |
|
106 |
if( extension == null ) { |
|
107 |
return false; |
|
108 |
} |
|
109 |
if( ExtensionHelper.canQueryByAction(extension) ) { |
|
110 |
status = actions.get(action); |
|
111 |
if( status == null ) { |
|
112 |
status = new Status(); |
|
113 |
actions.put(action, status); |
|
114 |
} |
|
115 |
if( status.isVisible == null ) { |
|
116 |
status.isVisible = new Boolean( action.isVisible() ); |
|
117 |
} |
|
118 |
} else { |
|
119 |
status = extensions.get(extension); |
|
120 |
if( status == null ) { |
|
121 |
status = new Status(); |
|
122 |
extensions.put(extension, status); |
|
123 |
} |
|
124 |
if( status.isVisible == null ) { |
|
125 |
status.isVisible = new Boolean( extension.isVisible() ); |
|
126 |
} |
|
127 |
} |
|
128 |
return status.isVisible.booleanValue(); |
|
129 |
} |
|
130 |
|
|
131 |
} |
|
0 | 132 |
tags/org.gvsig.desktop-2.0.62/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/actioninfo/impl/DefaultActionInfoManager.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.andami.actioninfo.impl; |
|
25 |
|
|
26 |
import java.util.ArrayList; |
|
27 |
import java.util.Collections; |
|
28 |
import java.util.Comparator; |
|
29 |
import java.util.HashMap; |
|
30 |
import java.util.Iterator; |
|
31 |
import java.util.List; |
|
32 |
import java.util.Map; |
|
33 |
|
|
34 |
import org.gvsig.andami.actioninfo.ActionInfo; |
|
35 |
import org.gvsig.andami.actioninfo.ActionInfoManager; |
|
36 |
import org.gvsig.andami.actioninfo.ActionInfoStatusCache; |
|
37 |
import org.gvsig.andami.plugins.IExtension; |
|
38 |
import org.slf4j.Logger; |
|
39 |
import org.slf4j.LoggerFactory; |
|
40 |
|
|
41 |
public class DefaultActionInfoManager implements ActionInfoManager { |
|
42 |
private static Logger logger = LoggerFactory.getLogger(DefaultActionInfoManager.class); |
|
43 |
|
|
44 |
private Map<String, ActionInfo>actions = new HashMap<String, ActionInfo>(); |
|
45 |
private int anonymousCounter = 1; |
|
46 |
|
|
47 |
public ActionInfo createAction(Class<? extends IExtension> extension, String name, String text, String command, String icon, String accelerator, long position, String tip) { |
|
48 |
name = emptyToNull(name); |
|
49 |
String actionName = name; |
|
50 |
if( actionName==null ){ |
|
51 |
actionName = String.format("anonymous__%04d",this.anonymousCounter++); |
|
52 |
} |
|
53 |
ActionInfo action = new DefaultActionInfo(extension, actionName, text, command, icon, accelerator, position, tip); |
|
54 |
ActionInfo previous = this.getAction(action.getName()); |
|
55 |
if( previous != null ) { |
|
56 |
((DefaultActionInfo)action).merge(previous); |
|
57 |
} |
|
58 |
if( name == null ){ |
|
59 |
logger.info("createAction: name of action is null/empty, rename to '"+actionName+"' ("+action.toString()+")."); |
|
60 |
} |
|
61 |
if( action.getLabel()==null && action.getIconName()==null ) { |
|
62 |
logger.info("createAction(name='"+name+"'): text and icon of action is null"); |
|
63 |
} |
|
64 |
return action; |
|
65 |
} |
|
66 |
|
|
67 |
private String emptyToNull(String s) { |
|
68 |
if( s==null ) { |
|
69 |
return null; |
|
70 |
} |
|
71 |
return "".equals(s.trim())? null:s; |
|
72 |
} |
|
73 |
|
|
74 |
public ActionInfo registerAction(ActionInfo action) { |
|
75 |
if( action == null ) { |
|
76 |
// Avisamos en el log de que se intenta registrar una accion null, intentado |
|
77 |
// sacar el stack para que se pueda ver quien lo esta haciendo, pero no |
|
78 |
// provocamos un error, solo retornamos null. |
|
79 |
try { |
|
80 |
throw new IllegalArgumentException(); |
|
81 |
} catch (IllegalArgumentException e) { |
|
82 |
logger.info("registerAction(null).", e); |
|
83 |
} |
|
84 |
return null; |
|
85 |
} |
|
86 |
ActionInfo previous = this.getAction(action.getName()); |
|
87 |
if( previous != null ) { |
|
88 |
((DefaultActionInfo)previous).merge(action); |
|
89 |
return previous; |
|
90 |
} else { |
|
91 |
this.actions.put(action.getName(), action); |
|
92 |
return action; |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
public ActionInfo getAction(String name) { |
|
97 |
if( name == null || "".equals(name) ) { |
|
98 |
try { |
|
99 |
throw new IllegalArgumentException(); |
|
100 |
} catch (IllegalArgumentException e) { |
|
101 |
logger.info("getAction(null/empty) return null.", e); |
|
102 |
return null; |
|
103 |
} |
|
104 |
} |
|
105 |
return this.actions.get(name); |
|
106 |
} |
|
107 |
|
|
108 |
public Iterator<ActionInfo> getActions() { |
|
109 |
List<ActionInfo> actions = new ArrayList<ActionInfo>(); |
|
110 |
actions.addAll(this.actions.values()); |
|
111 |
Collections.sort(actions, new Comparator<ActionInfo>() { |
|
112 |
public int compare(ActionInfo arg0, ActionInfo arg1) { |
|
113 |
String s0 = String.format("%s/%012d", arg0.getPluginName(), arg0.getPosition()); |
|
114 |
String s1 = String.format("%s/%012d", arg1.getPluginName(), arg1.getPosition()); |
|
115 |
return s0.compareTo(s1); |
|
116 |
}; |
|
117 |
}); |
|
118 |
return actions.iterator(); |
|
119 |
} |
|
120 |
|
|
121 |
public ActionInfoStatusCache createActionStatusCache() { |
|
122 |
return new DefaultActionInfoStatusCache(); |
|
123 |
} |
|
124 |
|
|
125 |
public void redirect(String sourceName, String targetName) { |
|
126 |
ActionInfo source = this.getAction(sourceName); |
|
127 |
if( source == null ) { |
|
128 |
throw new IllegalArgumentException("Can't locate source action '"+sourceName+"'."); |
|
129 |
} |
|
130 |
ActionInfo target = this.getAction(targetName); |
|
131 |
if( target == null ) { |
|
132 |
throw new IllegalArgumentException("Can't locate target action '"+targetName+"'."); |
|
133 |
} |
|
134 |
source.getRedirections().add(target); |
|
135 |
} |
|
136 |
|
|
137 |
public void execute(String actionName, Object[] parameters) { |
|
138 |
ActionInfo action = this.actions.get(actionName); |
|
139 |
if( action == null ) { |
|
140 |
return; |
|
141 |
} |
|
142 |
action.execute(parameters); |
|
143 |
} |
|
144 |
|
|
145 |
|
|
146 |
} |
|
0 | 147 |
tags/org.gvsig.desktop-2.0.62/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/actioninfo/impl/DefaultActionInfo.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.andami.actioninfo.impl; |
|
24 |
|
|
25 |
import java.awt.event.ActionEvent; |
|
26 |
import java.net.URL; |
|
27 |
import java.util.ArrayList; |
|
28 |
import java.util.Collection; |
|
29 |
import java.util.List; |
|
30 |
import java.util.Map; |
|
31 |
|
|
32 |
import javax.swing.AbstractAction; |
|
33 |
import javax.swing.Action; |
|
34 |
import javax.swing.ImageIcon; |
|
35 |
import javax.swing.KeyStroke; |
|
36 |
|
|
37 |
import org.apache.commons.io.FilenameUtils; |
|
38 |
import org.gvsig.andami.PluginServices; |
|
39 |
import org.gvsig.andami.PluginsLocator; |
|
40 |
import org.gvsig.andami.actioninfo.ActionInfo; |
|
41 |
import org.gvsig.andami.plugins.ExclusiveUIExtension; |
|
42 |
import org.gvsig.andami.plugins.ExtensionHelper; |
|
43 |
import org.gvsig.andami.plugins.IExtension; |
|
44 |
import org.gvsig.andami.ui.mdiFrame.KeyMapping; |
|
45 |
import org.gvsig.tools.ToolsLocator; |
|
46 |
import org.gvsig.tools.identitymanagement.SimpleIdentity; |
|
47 |
import org.gvsig.tools.identitymanagement.SimpleIdentityManager; |
|
48 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
49 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
|
50 |
import org.slf4j.Logger; |
|
51 |
import org.slf4j.LoggerFactory; |
|
52 |
|
|
53 |
public class DefaultActionInfo extends AbstractAction implements ActionInfo { |
|
54 |
|
|
55 |
/** |
|
56 |
* |
|
57 |
*/ |
|
58 |
private static final long serialVersionUID = 1620939552263334110L; |
|
59 |
|
|
60 |
private static Logger logger = LoggerFactory |
|
61 |
.getLogger(DefaultActionInfo.class); |
|
62 |
|
|
63 |
private Class<? extends IExtension> extensionClass; |
|
64 |
private IExtension extension; |
|
65 |
private String name; |
|
66 |
private String text; |
|
67 |
private String command; |
|
68 |
private String iconName; |
|
69 |
private String accelerator; |
|
70 |
private long position; |
|
71 |
private String tip; |
|
72 |
private List<ActionInfo> redirections; |
|
73 |
private boolean active; |
|
74 |
|
|
75 |
private Boolean previousEnabled = null; |
|
76 |
private SimpleIdentityManager identityManager; |
|
77 |
|
|
78 |
DefaultActionInfo(Class<? extends IExtension> extension, String name, |
|
79 |
String text, String command, String icon, String accelerator, |
|
80 |
long position, String tip) { |
|
81 |
this.extensionClass = extension; |
|
82 |
this.name = name; |
|
83 |
this.text = emptyToNull(text); |
|
84 |
this.command = emptyToNull(command); |
|
85 |
this.iconName = emptyToNull(icon); |
|
86 |
this.accelerator = emptyToNull(accelerator); |
|
87 |
this.position = position; |
|
88 |
this.tip = emptyToNull(tip); |
|
89 |
this.redirections = null; |
|
90 |
this.active = true; |
|
91 |
|
|
92 |
fixIcon(); |
|
93 |
} |
|
94 |
|
|
95 |
public Object clone() throws CloneNotSupportedException { |
|
96 |
DefaultActionInfo other = (DefaultActionInfo) super.clone(); |
|
97 |
if (other.redirections != null) { |
|
98 |
other.redirections = new ArrayList<ActionInfo>(); |
|
99 |
other.redirections.addAll(this.redirections); |
|
100 |
} |
|
101 |
return other; |
|
102 |
} |
|
103 |
|
|
104 |
private void fixIcon() { |
|
105 |
if (iconName != null && (iconName.contains("/") || iconName.contains("."))) { |
|
106 |
// it's a file path |
|
107 |
String name = FilenameUtils.getBaseName(iconName); |
|
108 |
IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getDefault(); |
|
109 |
URL resource = null; |
|
110 |
try { |
|
111 |
resource = this.extensionClass.getClassLoader().getResource(iconName); |
|
112 |
} catch (Exception e) { |
|
113 |
return; |
|
114 |
} |
|
115 |
if (resource == null) { |
|
116 |
return; |
|
117 |
} |
|
118 |
iconTheme.registerDefault(this.getPluginName(), "broken", name, null, resource); |
|
119 |
logger.info("Plugin " + this.getPluginName() + " contains icons out of icon theme (" + iconName + ")"); |
|
120 |
iconName = name; |
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
private String emptyToNull(String s) { |
|
125 |
if (s == null) { |
|
126 |
return null; |
|
127 |
} |
|
128 |
return s.trim().length() < 0 ? null : s; |
|
129 |
} |
|
130 |
|
|
131 |
public Collection<ActionInfo> getRedirections() { |
|
132 |
if (this.redirections == null) { |
|
133 |
this.redirections = new ArrayList<ActionInfo>(); |
|
134 |
} |
|
135 |
return this.redirections; |
|
136 |
} |
|
137 |
|
|
138 |
public void merge(ActionInfo other) { |
|
139 |
if (this.extensionClass == null) { |
|
140 |
this.extensionClass = other.getExtension().getClass(); |
|
141 |
this.extension = other.getExtension(); |
|
142 |
} |
|
143 |
if (this.text == null) { |
|
144 |
this.text = other.getLabel(); |
|
145 |
} |
|
146 |
if (this.command == null) { |
|
147 |
this.command = other.getCommand(); |
|
148 |
} |
|
149 |
if (this.iconName == null) { |
|
150 |
this.iconName = other.getIconName(); |
|
151 |
} |
|
152 |
if (this.accelerator == null) { |
|
153 |
this.accelerator = other.getAccelerator(); |
|
154 |
} |
|
155 |
if (this.position < 1) { |
|
156 |
this.position = other.getPosition(); |
|
157 |
} |
|
158 |
if (this.tip == null) { |
|
159 |
this.tip = other.getTooltip(); |
|
160 |
} |
|
161 |
|
|
162 |
} |
|
163 |
|
|
164 |
public PluginServices getPlugin() { |
|
165 |
PluginServices plugin = PluginsLocator.getManager().getPlugin( |
|
166 |
this.extensionClass); |
|
167 |
return plugin; |
|
168 |
} |
|
169 |
|
|
170 |
public String getPluginName() { |
|
171 |
if (this.getPlugin() == null) { |
|
172 |
return null; |
|
173 |
} |
|
174 |
return this.getPlugin().getPluginName(); |
|
175 |
} |
|
176 |
|
|
177 |
public IExtension getExtension() { |
|
178 |
if (this.extension == null) { |
|
179 |
this.extension = PluginsLocator.getManager().getExtension( |
|
180 |
this.extensionClass); |
|
181 |
} |
|
182 |
return this.extension; |
|
183 |
} |
|
184 |
|
|
185 |
public String getExtensionName() { |
|
186 |
if (this.extensionClass == null) { |
|
187 |
return null; |
|
188 |
} |
|
189 |
return this.extensionClass.getName(); |
|
190 |
} |
|
191 |
|
|
192 |
private SimpleIdentityManager getIdentityManager() { |
|
193 |
if( this.identityManager == null ) { |
|
194 |
this.identityManager = ToolsLocator.getIdentityManager(); |
|
195 |
} |
|
196 |
return this.identityManager; |
|
197 |
} |
|
198 |
|
|
199 |
private SimpleIdentity getCurrentUser() { |
|
200 |
return this.getIdentityManager().getCurrentIdentity(); |
|
201 |
} |
|
202 |
|
|
203 |
public boolean isVisible() { |
|
204 |
if( !this.getCurrentUser().isAuthorized(this.getName()) ) { |
|
205 |
return false; |
|
206 |
} |
|
207 |
if (!this.isActive()) { |
|
208 |
logger.info("isVisible(), action {} not active", this.getName()); |
|
209 |
return false; |
|
210 |
} |
|
211 |
ActionInfo redirection = this.getRedirection(); |
|
212 |
if (redirection != null) { |
|
213 |
return redirection.isVisible(); |
|
214 |
} |
|
215 |
|
|
216 |
ExclusiveUIExtension eui = PluginsLocator.getManager() |
|
217 |
.getExclusiveUIExtension(); |
|
218 |
if (eui == null) { |
|
219 |
return ExtensionHelper.isVisible(this.getExtension(), this.command); |
|
220 |
} |
|
221 |
return eui.isVisible(this.getExtension()); |
|
222 |
} |
|
223 |
|
|
224 |
public boolean isEnabled() { |
|
225 |
boolean value; |
|
226 |
if( !this.getCurrentUser().isAuthorized(this.getName()) ) { |
|
227 |
return false; |
|
228 |
} |
|
229 |
if (!this.isActive()) { |
|
230 |
logger.info("isEnabled(), action {} not active", this.getName()); |
|
231 |
value = false; |
|
232 |
} else { |
|
233 |
ActionInfo redirection = this.getRedirection(); |
|
234 |
if (redirection != null) { |
|
235 |
value = true; |
|
236 |
} else { |
|
237 |
ExclusiveUIExtension eui = PluginsLocator.getManager() |
|
238 |
.getExclusiveUIExtension(); |
|
239 |
if (eui == null) { |
|
240 |
value = ExtensionHelper.isEnabled(this.getExtension(), this.command); |
|
241 |
} else { |
|
242 |
value = eui.isEnabled(this.getExtension()); |
|
243 |
} |
|
244 |
} |
|
245 |
} |
|
246 |
if (this.previousEnabled == null || this.previousEnabled.booleanValue() != value) { |
|
247 |
this.setEnabled(value); // force call listeners |
|
248 |
} |
|
249 |
return value; |
|
250 |
} |
|
251 |
|
|
252 |
private ActionInfo getRedirection() { |
|
253 |
if (this.redirections == null) { |
|
254 |
return null; |
|
255 |
} |
|
256 |
for (int n = this.redirections.size() - 1; n >= 0; n--) { |
|
257 |
ActionInfo redirection = this.redirections.get(n); |
|
258 |
if (redirection.isEnabled()) { |
|
259 |
return redirection; |
|
260 |
} |
|
261 |
} |
|
262 |
return null; |
|
263 |
} |
|
264 |
|
|
265 |
public void execute() { |
|
266 |
// if (!this.isActive()) { |
|
267 |
// logger.info("execute(), action {} not active", this.getName()); |
|
268 |
// return; |
|
269 |
// } |
|
270 |
if( !this.getCurrentUser().isAuthorized(this.getName()) ) { |
|
271 |
logger.warn("Current user '"+this.getCurrentUser().getID()+"' not authorized to execute this action '"+this.getName()+"'."); |
|
272 |
return ; |
|
273 |
} |
|
274 |
ActionInfo redirection = this.getRedirection(); |
|
275 |
if (redirection != null) { |
|
276 |
logger.info("{}.execute('{}') redirected", this.getPluginName() |
|
277 |
+ ":" + this.getExtensionName(), this.getCommand()); |
|
278 |
redirection.execute(); |
|
279 |
return; |
|
280 |
} |
|
281 |
logger.info("{}.execute('{}')", |
|
282 |
this.getPluginName() + ":" + this.getExtensionName(), |
|
283 |
this.getCommand()); |
|
284 |
this.getExtension().execute(this.command); |
|
285 |
} |
|
286 |
|
|
287 |
public void execute(Object[] args) { |
|
288 |
// if (!this.isActive()) { |
|
289 |
// logger.info("execute(args), action {} not active", this.getName()); |
|
290 |
// return; |
|
291 |
// } |
|
292 |
if( !this.getCurrentUser().isAuthorized(this.getName()) ) { |
|
293 |
logger.warn("Current user '"+this.getCurrentUser().getID()+"' not authorized to execute this action '"+this.getName()+"'."); |
|
294 |
return ; |
|
295 |
} |
|
296 |
ActionInfo redirection = this.getRedirection(); |
|
297 |
if (redirection != null) { |
|
298 |
logger.info("{}.execute('{}', args) redirected", this.getPluginName() |
|
299 |
+ ":" + this.getExtensionName(), this.getCommand()); |
|
300 |
redirection.execute(args); |
|
301 |
return; |
|
302 |
} |
|
303 |
logger.info("{}.execute('{}', Object[] args)", |
|
304 |
this.getPluginName() + ":" + this.getExtensionName(), |
|
305 |
this.getCommand()); |
|
306 |
ExtensionHelper.execute(this.getExtension(), this.command, args); |
|
307 |
} |
|
308 |
|
|
309 |
public void execute(Object arg) { |
|
310 |
if (arg instanceof Object[]) { |
|
311 |
execute((Object[]) arg); |
|
312 |
return; |
|
313 |
} |
|
314 |
execute(new Object[]{arg}); |
|
315 |
} |
|
316 |
|
|
317 |
public void execute(Map args) { |
|
318 |
if( !this.getCurrentUser().isAuthorized(this.getName()) ) { |
|
319 |
logger.warn("Current user '"+this.getCurrentUser().getID()+"' not authorized to execute this action '"+this.getName()+"'."); |
|
320 |
return ; |
|
321 |
} |
|
322 |
logger.info("{}.execute('{}', Map args)", |
|
323 |
this.getPluginName() + ":" + this.getExtensionName(), |
|
324 |
this.getCommand()); |
|
325 |
ExtensionHelper.execute(this.getExtension(), this.command, new Object[]{args}); |
|
326 |
} |
|
327 |
|
|
328 |
public void actionPerformed(ActionEvent arg0) { |
|
329 |
this.execute(); |
|
330 |
} |
|
331 |
|
|
332 |
public String getName() { |
|
333 |
return this.name; |
|
334 |
} |
|
335 |
|
|
336 |
public String getLabel() { |
|
337 |
return this.text; |
|
338 |
} |
|
339 |
|
|
340 |
public String getCommand() { |
|
341 |
return this.command; |
|
342 |
} |
|
343 |
|
|
344 |
public String getIconName() { |
|
345 |
return this.iconName; |
|
346 |
} |
|
347 |
|
|
348 |
public ImageIcon getIcon() { |
|
349 |
IconTheme iconTheme = PluginServices.getIconTheme(); |
|
350 |
return iconTheme.get(this.iconName); |
Also available in: Unified diff