Revision 46130
tags/org.gvsig.desktop-2.0.346/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.346</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.346/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.346/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.346/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.346/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/actioninfo/ActionInfo.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 |
import java.awt.event.ActionListener; |
|
27 |
import java.util.Collection; |
|
28 |
import java.util.Map; |
|
29 |
|
|
30 |
import javax.swing.Action; |
|
31 |
import javax.swing.ImageIcon; |
|
32 |
import javax.swing.KeyStroke; |
|
33 |
|
|
34 |
import org.gvsig.tools.lang.Cloneable; |
|
35 |
|
|
36 |
import org.gvsig.andami.PluginServices; |
|
37 |
import org.gvsig.andami.plugins.IExtension; |
|
38 |
|
|
39 |
/** |
|
40 |
* Esta entidad representa a una accion dentro de gvSIG, que podra ser usada |
|
41 |
* por menus, botones de la toolbar, menus contextuales, o desde cualquier |
|
42 |
* otro elemento de gvSIG que precise invocar a una accion. |
|
43 |
* |
|
44 |
* La accion esta compuesta por una definicion de cual es su etiqueta, su |
|
45 |
* icono, teclas aceleradoras, su tip, o su posicion respecto a otras acciones, |
|
46 |
* junto con una extension (IExtension) que aporta el codigo de la accion. |
|
47 |
* |
|
48 |
* Una accion responde principalmente a cuatro operaciones: |
|
49 |
* |
|
50 |
* - isActive, que nos indica si la accion esta activa, es decir, si |
|
51 |
* debera presentarse al usuario o no. Si una extension no esta activa, |
|
52 |
* los metodos isVisible y isEnabled retornaran siempre false, sin invocar |
|
53 |
* al codigo de la extension asociada a la accion. |
|
54 |
* |
|
55 |
* - isVisible, que nos indica si la accion debera presentarse o no en el |
|
56 |
* interface de usuario. De forma general podemos asumir que cuando se |
|
57 |
* invoque a este metodo se delegara en el metodo isVisible de la extension |
|
58 |
* asociada a la accion. |
|
59 |
* |
|
60 |
* - isEnabled, que nos indica si la accion debera estar habilitada o no en |
|
61 |
* el interface de usuario. De forma general podemos asumir que cuando se |
|
62 |
* invoque a este metodo se delegara en el metodo isEnabled de la extension |
|
63 |
* asociada a la accion. |
|
64 |
* |
|
65 |
* - execute, que provocara que se ejecute el codigo asociado a la accion. |
|
66 |
* De forma general podemos asumir que cuando se invoque a estos metodo se |
|
67 |
* delegara en el metodo execute de la extension asociada a esta accion, pasandole |
|
68 |
* el "command" de la accion como parametro. |
|
69 |
* |
|
70 |
* Ademas de la definicion de la accion, esta tambien puede disponer de una coleccion |
|
71 |
* de acciones hacia las que puede ser redirigida. Esto es, en un momento dado |
|
72 |
* nos puede interesar que cuando sea invocada la accion "A", en lugar de ejecutarse |
|
73 |
* las operaciones de esta, se ejecuten las operaciones de otra accion "B". Esto nos |
|
74 |
* permite atrapar la ejecucion de una accion independientemente de desde donde se este |
|
75 |
* invocando. Cuando una accion tenga asignadas otras acciones a las que redirigir |
|
76 |
* su ejecucion, solo se redigira a una de ellas, la primera en la coleccion de acciones a |
|
77 |
* redirigir que responda "true" a su metodo isEnabled, y en caso de que no responda true |
|
78 |
* ninguna se ejecutara el codigo de la accion original. El orden de la coleccion de |
|
79 |
* acciones a las que redirigir de una accion sera el orden inverso en el que se han |
|
80 |
* ido registrandose las redirecciones. Asi primero se intentara con la ultima redireccion |
|
81 |
* asignada, luego con la anterior, y asi sucesivamente se recorreran todas las redireccion |
|
82 |
* hasta que una responda "true" a su isEnabled, ejecutandose entonces el codigo de esta. |
|
83 |
* |
|
84 |
* |
|
85 |
* @author jjdelcerro |
|
86 |
* |
|
87 |
*/ |
|
88 |
public interface ActionInfo extends Action, ActionListener, Cloneable { |
|
89 |
|
|
90 |
public static final String ACCELERATOR = "ACCELERATOR"; |
|
91 |
public static final String ACTIVE = "ACTIVE"; |
|
92 |
public static final String VISIBLE = "VISIBLE"; |
|
93 |
public static final String PLUGIN_NAME = "PLUGIN_NAME"; |
|
94 |
public static final String PLUGIN = "PLUGIN"; |
|
95 |
public static final String EXTENSION_NAME = "EXTENSION_NAME"; |
|
96 |
public static final String EXTENSION = "EXTENSION"; |
|
97 |
public static final String REDIRECTIONS = "REDIRECTIONS"; |
|
98 |
public static final String REDIRECTION = "REDIRECTION"; |
|
99 |
public static final String POSITION = "POSITION"; |
|
100 |
public static final String TOOLTIP = "TOOLTIP"; |
|
101 |
public static final String ICON_NAME = "ICON_NAME"; |
|
102 |
|
|
103 |
/** |
|
104 |
* returns the plugin of the extension asociated to the action. |
|
105 |
* |
|
106 |
* @return pluginServices asiciated to the action. |
|
107 |
*/ |
|
108 |
public PluginServices getPlugin(); |
|
109 |
|
|
110 |
/** |
|
111 |
* returns the extension asociated to the action. The action |
|
112 |
* delegates the methods isEnabled, isVisible and execute in this |
|
113 |
* extension when these are invoked. |
|
114 |
* |
|
115 |
* @return IExtension asociated to the action |
|
116 |
*/ |
|
117 |
public IExtension getExtension(); |
|
118 |
|
|
119 |
/** |
|
120 |
* Return the plugin name of the plugin asociated to the action. |
|
121 |
* This is a utility method checkins null values. is equivalent to: |
|
122 |
* |
|
123 |
* action.getPlugin().getPluginName() |
|
124 |
* |
|
125 |
* |
|
126 |
* @return plugin name |
|
127 |
* @see #getPlugin() |
|
128 |
*/ |
|
129 |
public String getPluginName(); |
|
130 |
|
|
131 |
/** |
|
132 |
* Returns the extension name of the extension asociated to this action. |
|
133 |
* This a utility method that check null values. Is equivalent to: |
|
134 |
* |
|
135 |
* action.getExtension().getClass().getName() |
|
136 |
* |
|
137 |
* @return extension name. |
|
138 |
* @see #getExtension() |
|
139 |
*/ |
|
140 |
public String getExtensionName(); |
|
141 |
|
|
142 |
/** |
|
143 |
* Returns the name of the action. This name is usaed to retrieve the |
|
144 |
* action thwros the manager. |
|
145 |
* |
|
146 |
* @return action name |
|
147 |
*/ |
|
148 |
public String getName(); |
|
149 |
|
|
150 |
/** |
|
151 |
* Return a label asociated to the action. This label can be used |
|
152 |
* in buttons, o menus. |
|
153 |
* |
|
154 |
* @return label of action |
|
155 |
*/ |
|
156 |
public String getLabel(); |
|
157 |
|
|
158 |
/** |
|
159 |
* Returns the command used for invoking the execute method of |
|
160 |
* the extension asociated to this action. |
|
161 |
* |
|
162 |
* @return command of action |
|
163 |
*/ |
|
164 |
public String getCommand(); |
|
165 |
|
|
166 |
/** |
|
167 |
* Return an icon asociated to the action. This icon can be used |
|
168 |
* in buttons, o menus. |
|
169 |
* |
|
170 |
* @return ImageIcon asociated tho the action |
|
171 |
*/ |
|
172 |
public ImageIcon getIcon(); |
|
173 |
|
|
174 |
/** |
|
175 |
* Returns the name of icon asociated to the action. This name is |
|
176 |
* used to retrive the icon from the current icon theme of the application. |
|
177 |
* |
|
178 |
* @return icon name. |
|
179 |
*/ |
|
180 |
public String getIconName(); |
|
181 |
|
|
182 |
/** |
|
183 |
* returns a representation human readable of the accelerator to be used |
|
184 |
* associated to the action. |
|
185 |
* |
|
186 |
* @return String representing the accelerator |
|
187 |
*/ |
|
188 |
public String getAccelerator(); |
|
189 |
|
|
190 |
/** |
|
191 |
* returns the KeyStroke which represents the accelerator of this |
|
192 |
* action. |
|
193 |
* |
|
194 |
* @return keystroke asociated to this action |
|
195 |
* @see #getAccelerator() |
|
196 |
*/ |
|
197 |
public KeyStroke getKeyStroke(); |
|
198 |
|
|
199 |
/** |
|
200 |
* Return a string that represents a tip asociated whit the action, |
|
201 |
* usually used as tooltip in buttons or menus. |
|
202 |
* |
|
203 |
* @return the tip of the action |
|
204 |
*/ |
|
205 |
public String getTooltip(); |
|
206 |
|
|
207 |
/** |
|
208 |
* Return the position absolute of the action referred to all actions. |
|
209 |
* |
|
210 |
* @return the position of the action |
|
211 |
*/ |
|
212 |
public long getPosition(); |
|
213 |
|
|
214 |
/** |
|
215 |
* retrurn if the action can be visible in the user interface or not. |
|
216 |
* This method call the isVisible of the extension asociated to the action, |
|
217 |
* unless the action is inactive. |
|
218 |
* If has a ExclusiveUIExtension set, then this is invoqued instead of the |
|
219 |
* the isVisible of the extension. |
|
220 |
* |
|
221 |
* @return if the action if visible for the user. |
|
222 |
*/ |
|
223 |
public boolean isVisible(); |
|
224 |
|
|
225 |
/** |
|
226 |
* retrurn if the action is enables. |
|
227 |
* This method call the isEnabled of the extension asociated to the action, |
|
228 |
* unless the action is inactive. |
|
229 |
* This method is used to determine whether it is possible to redirect |
|
230 |
* to this action or not. |
|
231 |
* If has a ExclusiveUIExtension set, then this is invoqued instead of the |
|
232 |
* the isEnabled of the extension. |
|
233 |
* |
|
234 |
* @return if the action if visible for the user. |
|
235 |
*/ |
|
236 |
public boolean isEnabled(); |
|
237 |
|
|
238 |
/** |
|
239 |
* Execute the code asociated to the action. |
|
240 |
* This method call the execute method of the asociated exetnsion using the |
|
241 |
* command of action as argument. |
|
242 |
* If the action is redirected try to call to the redirected actions. |
|
243 |
* |
|
244 |
*/ |
|
245 |
public void execute(); |
|
246 |
|
|
247 |
/** |
|
248 |
* Execute the code asociated to the action. |
|
249 |
* Pass the args to the execute of the asociated extension. |
|
250 |
* |
|
251 |
* @see #execute() |
|
252 |
*/ |
|
253 |
public void execute(Object[] args); |
|
254 |
public void execute(Map args); |
|
255 |
|
|
256 |
/** |
|
257 |
* Execute the code asociated to the action. |
|
258 |
* Pass the args to the execute of the asociated extension. |
|
259 |
* |
|
260 |
* @see #execute() |
|
261 |
*/ |
|
262 |
public void execute(Object arg); |
|
263 |
|
|
264 |
/** |
|
265 |
* Return true is the action is active. When an action is active the methods |
|
266 |
* isEnable and isVisible call the methods of the extension asociated to this. |
|
267 |
* When is inactive always return false. |
|
268 |
* |
|
269 |
* @return if the action is active |
|
270 |
*/ |
|
271 |
public boolean isActive(); |
|
272 |
/** |
|
273 |
* Set the active state of an ActionInfo. |
|
274 |
* When the active state is set to false, isEnabled, and isVisible |
|
275 |
* returns false. |
|
276 |
* |
|
277 |
* @param active |
|
278 |
*/ |
|
279 |
public void setActive(boolean active); |
|
280 |
|
|
281 |
/** |
|
282 |
* |
|
283 |
* An action can redirect the execution of the execute, isVisible and isEnabled methods |
|
284 |
* to other action. Using this method is can be query and set this redirections. |
|
285 |
* The redirect will be established only if the method isEnabled of target action |
|
286 |
* returns true. Otherwise execute methods of initial action. |
|
287 |
* |
|
288 |
* @return the redirections established for this action |
|
289 |
*/ |
|
290 |
public Collection<ActionInfo> getRedirections(); |
|
291 |
|
|
292 |
} |
|
0 | 293 |
tags/org.gvsig.desktop-2.0.346/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.346/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 |
@Override |
|
54 |
public void clear() { |
|
55 |
extensions = new HashMap<>(); |
|
56 |
actions = new HashMap<>(); |
|
57 |
} |
|
58 |
|
|
59 |
private SimpleIdentityManager getIdentityManager() { |
|
60 |
if( this.identityManager == null ) { |
|
61 |
this.identityManager = ToolsLocator.getIdentityManager(); |
|
62 |
} |
|
63 |
return this.identityManager; |
|
64 |
} |
|
65 |
|
|
66 |
private SimpleIdentity getCurrentUser() { |
|
67 |
return this.getIdentityManager().getCurrentIdentity(); |
|
68 |
} |
|
69 |
|
|
70 |
@Override |
|
71 |
public boolean isEnabled(ActionInfo action) { |
|
72 |
if( !this.getCurrentUser().isAuthorized(action.getName()) ) { |
|
73 |
return false; |
|
74 |
} |
|
75 |
if (!action.isActive()) { |
|
76 |
//logger.info("isEnabled(), action {} not active", action.getName()); |
|
77 |
return false; |
|
78 |
} Status status; |
|
79 |
IExtension extension = action.getExtension(); |
|
80 |
if( extension == null ) { |
|
81 |
return false; |
|
82 |
} |
|
83 |
if( ExtensionHelper.canQueryByAction(extension) ) { |
|
84 |
status = actions.get(action); |
|
85 |
if( status == null ) { |
|
86 |
status = new Status(); |
|
87 |
actions.put(action, status); |
|
88 |
} |
|
89 |
if( status.isEnabled == null ) { |
|
90 |
status.isEnabled = action.isEnabled(); |
|
91 |
} |
|
92 |
} else { |
|
93 |
status = extensions.get(extension); |
|
94 |
if( status == null ) { |
|
95 |
status = new Status(); |
|
96 |
extensions.put(extension, status); |
|
97 |
} |
|
98 |
if( status.isEnabled == null ) { |
|
99 |
status.isEnabled = extension.isEnabled(); |
|
100 |
} |
|
101 |
} |
|
102 |
return status.isEnabled; |
|
103 |
} |
|
104 |
|
|
105 |
@Override |
|
106 |
public boolean isVisible(ActionInfo action) { |
|
107 |
if( !this.getCurrentUser().isAuthorized(action.getName()) ) { |
|
108 |
return false; |
|
109 |
} |
|
110 |
if (!action.isActive()) { |
|
111 |
//logger.info("isVisible(), action {} not active", action.getName()); |
|
112 |
return false; |
|
113 |
} |
|
114 |
Status status; |
|
115 |
IExtension extension = action.getExtension(); |
|
116 |
if( extension == null ) { |
|
117 |
return false; |
|
118 |
} |
|
119 |
if( ExtensionHelper.canQueryByAction(extension) ) { |
|
120 |
status = actions.get(action); |
|
121 |
if( status == null ) { |
|
122 |
status = new Status(); |
|
123 |
actions.put(action, status); |
|
124 |
} |
|
125 |
if( status.isVisible == null ) { |
|
126 |
status.isVisible = action.isVisible(); |
|
127 |
} |
|
128 |
} else { |
|
129 |
status = extensions.get(extension); |
|
130 |
if( status == null ) { |
|
131 |
status = new Status(); |
|
132 |
extensions.put(extension, status); |
|
133 |
} |
|
134 |
if( status.isVisible == null ) { |
|
135 |
status.isVisible = extension.isVisible(); |
|
136 |
} |
|
137 |
} |
|
138 |
return status.isVisible; |
|
139 |
} |
|
140 |
|
|
141 |
} |
|
0 | 142 |
tags/org.gvsig.desktop-2.0.346/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-2020 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.io.File; |
|
26 |
import java.io.FileInputStream; |
|
27 |
import java.util.ArrayList; |
|
28 |
import java.util.Collections; |
|
29 |
import java.util.HashMap; |
|
30 |
import java.util.Iterator; |
|
31 |
import java.util.List; |
|
32 |
import java.util.Map; |
|
33 |
import java.util.Properties; |
|
34 |
import org.apache.commons.io.IOUtils; |
|
35 |
import org.apache.commons.lang3.BooleanUtils; |
|
36 |
import org.apache.commons.lang3.StringUtils; |
|
37 |
import org.gvsig.andami.PluginsLocator; |
|
38 |
import org.gvsig.andami.actioninfo.ActionInfo; |
|
39 |
import org.gvsig.andami.actioninfo.ActionInfoManager; |
|
40 |
import org.gvsig.andami.actioninfo.ActionInfoStatusCache; |
|
41 |
import org.gvsig.andami.plugins.IExtension; |
|
42 |
import org.gvsig.tools.ToolsLocator; |
|
43 |
import org.gvsig.tools.identitymanagement.SimpleIdentityManager; |
|
44 |
import org.slf4j.Logger; |
|
45 |
import org.slf4j.LoggerFactory; |
|
46 |
|
|
47 |
@SuppressWarnings("UseSpecificCatch") |
|
48 |
public class DefaultActionInfoManager implements ActionInfoManager { |
|
49 |
|
|
50 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultActionInfoManager.class); |
|
51 |
|
|
52 |
private final Map<String, ActionInfo> actions = new HashMap<>(); |
|
53 |
private int anonymousCounter = 1; |
|
54 |
private Properties activeStates = null; |
|
55 |
|
|
56 |
@Override |
|
57 |
public ActionInfo createAction(Class<? extends IExtension> extension, String name, String text, String command, String icon, String accelerator, long position, String tip) { |
|
58 |
String actionName = name; |
|
59 |
if ( StringUtils.isBlank(actionName) ) { |
|
60 |
actionName = String.format("anonymous__%04d", this.anonymousCounter++); |
|
61 |
} |
|
62 |
ActionInfo action = new DefaultActionInfo(extension, actionName, text, command, icon, accelerator, position, tip); |
|
63 |
ActionInfo previous = this.getAction(action.getName()); |
|
64 |
if (previous != null) { |
|
65 |
((DefaultActionInfo) action).merge(previous); |
|
66 |
} |
|
67 |
if (name == null) { |
|
68 |
LOGGER.info("createAction: name of action is null/empty, rename to '" + actionName + "' (" + action.toString() + ")."); |
|
69 |
} |
|
70 |
if (action.getLabel() == null && action.getIconName() == null) { |
|
71 |
LOGGER.info("createAction(name='" + name + "'): text and icon of action is null"); |
|
72 |
} |
|
73 |
return action; |
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
public ActionInfo createAction(IExtension extension, String name, String text, String command, String icon, String accelerator, long position, String tip) { |
|
78 |
String actionName = name; |
|
79 |
if ( StringUtils.isBlank(actionName) ) { |
|
80 |
actionName = String.format("anonymous__%04d", this.anonymousCounter++); |
|
81 |
} |
|
82 |
ActionInfo action = new DefaultActionInfo(extension, actionName, text, command, icon, accelerator, position, tip); |
|
83 |
ActionInfo previous = this.getAction(action.getName()); |
|
84 |
if (previous != null) { |
|
85 |
((DefaultActionInfo) action).merge(previous); |
|
86 |
} |
|
87 |
if (name == null) { |
|
88 |
LOGGER.info("createAction: name of action is null/empty, rename to '" + actionName + "' (" + action.toString() + ")."); |
|
89 |
} |
|
90 |
if (action.getLabel() == null && action.getIconName() == null) { |
|
91 |
LOGGER.info("createAction(name='" + name + "'): text and icon of action is null"); |
|
92 |
} |
|
93 |
return action; |
|
94 |
} |
|
95 |
|
|
96 |
@Override |
|
97 |
public ActionInfo registerAction(ActionInfo action) { |
|
98 |
return this.registerAction(action, false); |
|
99 |
} |
|
100 |
|
|
101 |
@Override |
|
102 |
public ActionInfo registerAction(ActionInfo action, boolean override) { |
|
103 |
if (action == null) { |
|
104 |
// Avisamos en el log de que se intenta registrar una accion null, intentado |
|
105 |
// sacar el stack para que se pueda ver quien lo esta haciendo, pero no |
|
106 |
// provocamos un error, solo retornamos null. |
|
107 |
try { |
|
108 |
throw new IllegalArgumentException(); |
|
109 |
} catch (IllegalArgumentException e) { |
|
110 |
LOGGER.info("registerAction(null).", e); |
|
111 |
} |
|
112 |
return null; |
|
113 |
} |
|
114 |
ActionInfo previous = this.getAction(action.getName()); |
|
115 |
if (previous != null) { |
|
116 |
if( override ) { |
|
117 |
this.actions.put(action.getName(), action); |
|
118 |
} else { |
|
119 |
((DefaultActionInfo) previous).merge(action); |
|
120 |
action = previous; |
|
121 |
} |
|
122 |
} else { |
|
123 |
this.actions.put(action.getName(), action); |
|
124 |
SimpleIdentityManager identityManager = ToolsLocator.getIdentityManager(); |
|
125 |
identityManager.registerAction(action.getName()); |
|
126 |
} |
|
127 |
this.updateActiveState(action); |
|
128 |
return action; |
|
129 |
} |
|
130 |
|
|
131 |
private void updateActiveState(ActionInfo action) { |
|
132 |
if( activeStates==null ) { |
|
133 |
this.activeStates = new Properties(); |
|
134 |
File home = PluginsLocator.getManager().getApplicationHomeFolder(); |
|
135 |
File states = new File(home,"actions-states.properties"); |
|
136 |
if( states.exists() ) { |
|
137 |
FileInputStream fis = null; |
|
138 |
try { |
|
139 |
fis = new FileInputStream(states); |
|
140 |
this.activeStates.load(fis); |
|
141 |
} catch (Exception ex) { |
|
142 |
LOGGER.warn("Can't load actions states from '"+states.getAbsolutePath()+"'.",ex); |
|
143 |
} finally { |
|
144 |
IOUtils.closeQuietly(fis); |
|
145 |
} |
|
146 |
} |
|
147 |
} |
|
148 |
Boolean active = BooleanUtils.toBooleanObject((String) this.activeStates.getProperty(action.getName(),"true")); |
|
149 |
action.setActive(active); |
|
150 |
} |
|
151 |
|
|
152 |
@Override |
|
153 |
public ActionInfo getAction(String name) { |
|
154 |
if ( StringUtils.isEmpty(name) ) { |
|
155 |
try { |
|
156 |
throw new IllegalArgumentException(); |
|
157 |
} catch (IllegalArgumentException e) { |
|
158 |
LOGGER.info("getAction(null/empty) return null.", e); |
|
159 |
return null; |
|
160 |
} |
|
161 |
} |
|
162 |
return this.actions.get(name); |
|
163 |
} |
|
164 |
|
|
165 |
@Override |
|
166 |
public Iterator<ActionInfo> getActions() { |
|
167 |
List<ActionInfo> theActions = new ArrayList<>(); |
|
168 |
theActions.addAll(this.actions.values()); |
|
169 |
Collections.sort(theActions, (ActionInfo arg0, ActionInfo arg1) -> { |
|
170 |
String s0 = String.format("%s/%012d", arg0.getPluginName(), arg0.getPosition()); |
|
171 |
String s1 = String.format("%s/%012d", arg1.getPluginName(), arg1.getPosition()); |
|
172 |
return s0.compareTo(s1); |
|
173 |
}); |
|
174 |
return theActions.iterator(); |
|
175 |
} |
|
176 |
|
|
177 |
@Override |
|
178 |
public ActionInfoStatusCache createActionStatusCache() { |
|
179 |
return new DefaultActionInfoStatusCache(); |
|
180 |
} |
|
181 |
|
|
182 |
@Override |
|
183 |
public void redirect(String sourceName, String targetName) { |
|
184 |
ActionInfo source = this.getAction(sourceName); |
|
185 |
if (source == null) { |
|
186 |
throw new IllegalArgumentException("Can't locate source action '" + sourceName + "'."); |
|
187 |
} |
|
188 |
ActionInfo target = this.getAction(targetName); |
|
189 |
if (target == null) { |
|
190 |
throw new IllegalArgumentException("Can't locate target action '" + targetName + "'."); |
|
191 |
} |
|
192 |
source.getRedirections().add(target); |
|
193 |
} |
|
194 |
|
|
195 |
@Override |
|
196 |
public void execute(String actionName, Object[] parameters) { |
|
197 |
ActionInfo action = this.actions.get(actionName); |
|
198 |
if (action == null) { |
|
199 |
return; |
|
200 |
} |
|
201 |
action.execute(parameters); |
|
202 |
} |
|
203 |
|
|
204 |
@Override |
|
205 |
public ActionInfo getTranslated(ActionInfo actionInfo) { |
|
206 |
return new TranslatedActionInfo(actionInfo); |
|
207 |
} |
|
208 |
|
|
209 |
} |
|
0 | 210 |
tags/org.gvsig.desktop-2.0.346/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/actioninfo/impl/TranslatedActionInfo.java | ||
---|---|---|
1 |
package org.gvsig.andami.actioninfo.impl; |
|
2 |
|
|
3 |
import java.awt.event.ActionEvent; |
|
4 |
import java.beans.PropertyChangeListener; |
|
5 |
import java.util.Collection; |
|
6 |
import java.util.Map; |
|
7 |
|
|
8 |
import javax.swing.Action; |
|
9 |
import javax.swing.ImageIcon; |
|
10 |
import javax.swing.KeyStroke; |
|
11 |
|
|
12 |
import org.gvsig.andami.PluginServices; |
|
13 |
import org.gvsig.andami.actioninfo.ActionInfo; |
|
14 |
import org.gvsig.andami.plugins.IExtension; |
|
15 |
import org.gvsig.tools.ToolsLocator; |
|
16 |
|
|
17 |
|
|
18 |
public class TranslatedActionInfo implements ActionInfo { |
|
19 |
|
|
20 |
private ActionInfo actionInfo; |
|
21 |
|
|
22 |
TranslatedActionInfo(ActionInfo actionInfo) { |
|
23 |
this.actionInfo = actionInfo; |
|
24 |
} |
|
25 |
|
|
26 |
public Object getValue(String key) { |
|
27 |
if (Action.SHORT_DESCRIPTION.equalsIgnoreCase(key)) { |
|
28 |
return this.getLabel(); |
|
29 |
} |
|
30 |
if (ActionInfo.TOOLTIP.equalsIgnoreCase(key)) { |
|
31 |
return this.getTooltip(); |
|
32 |
} |
|
33 |
|
|
34 |
return this.actionInfo.getValue(key); |
|
35 |
} |
|
36 |
|
|
37 |
public void putValue(String key, Object value) { |
|
38 |
this.actionInfo.putValue(key, value); |
|
39 |
|
|
40 |
} |
|
41 |
|
|
42 |
public void setEnabled(boolean b) { |
|
43 |
this.actionInfo.setEnabled(b); |
|
44 |
|
|
45 |
} |
|
46 |
|
|
47 |
public void addPropertyChangeListener(PropertyChangeListener listener) { |
|
48 |
this.actionInfo.addPropertyChangeListener(listener); |
|
49 |
} |
|
50 |
|
|
51 |
public void removePropertyChangeListener(PropertyChangeListener listener) { |
|
52 |
this.actionInfo.removePropertyChangeListener(listener); |
|
53 |
} |
|
54 |
|
|
55 |
public void actionPerformed(ActionEvent e) { |
|
56 |
this.actionInfo.actionPerformed(e); |
|
57 |
} |
|
58 |
|
|
59 |
public PluginServices getPlugin() { |
|
60 |
return this.actionInfo.getPlugin(); |
|
61 |
} |
|
62 |
|
|
63 |
public IExtension getExtension() { |
|
64 |
return this.actionInfo.getExtension(); |
|
65 |
} |
|
66 |
|
|
67 |
public String getPluginName() { |
|
68 |
return this.actionInfo.getPluginName(); |
|
69 |
} |
|
70 |
|
|
71 |
public String getExtensionName() { |
|
72 |
return this.actionInfo.getExtensionName(); |
|
73 |
} |
|
74 |
|
|
75 |
public String getName() { |
|
76 |
return this.actionInfo.getName(); |
|
77 |
} |
|
78 |
|
|
79 |
public String getLabel() { |
|
80 |
return ToolsLocator.getI18nManager().getTranslation(this.actionInfo.getLabel()); |
|
81 |
} |
|
82 |
|
|
83 |
public String getCommand() { |
|
84 |
return this.actionInfo.getCommand(); |
|
85 |
} |
|
86 |
|
|
87 |
public ImageIcon getIcon() { |
|
88 |
return this.actionInfo.getIcon(); |
|
89 |
} |
|
90 |
|
|
91 |
public String getIconName() { |
|
92 |
return this.actionInfo.getIconName(); |
|
93 |
} |
|
94 |
|
|
95 |
public String getAccelerator() { |
|
96 |
return this.actionInfo.getAccelerator(); |
|
97 |
} |
|
98 |
|
|
99 |
public KeyStroke getKeyStroke() { |
|
100 |
return this.actionInfo.getKeyStroke(); |
|
101 |
} |
|
102 |
|
|
103 |
public String getTooltip() { |
|
104 |
return ToolsLocator.getI18nManager().getTranslation(this.actionInfo.getTooltip()); |
|
105 |
} |
|
106 |
|
|
107 |
public long getPosition() { |
|
108 |
return this.actionInfo.getPosition(); |
|
109 |
} |
|
110 |
|
|
111 |
public boolean isVisible() { |
|
112 |
return this.actionInfo.isVisible(); |
|
113 |
} |
|
114 |
|
|
115 |
public boolean isEnabled() { |
|
116 |
return this.actionInfo.isEnabled(); |
|
117 |
} |
|
118 |
|
|
119 |
public void execute() { |
|
120 |
this.actionInfo.execute(); |
|
121 |
|
|
122 |
} |
|
123 |
|
|
124 |
public void execute(Object[] args) { |
|
125 |
this.actionInfo.execute(args); |
|
126 |
|
|
127 |
} |
|
128 |
|
|
129 |
public void execute(Map args) { |
|
130 |
this.actionInfo.execute(args); |
|
131 |
} |
|
132 |
|
|
133 |
public void execute(Object arg) { |
|
134 |
this.actionInfo.execute(arg); |
|
135 |
|
|
136 |
} |
|
137 |
|
|
138 |
public boolean isActive() { |
|
139 |
return this.actionInfo.isActive(); |
|
140 |
} |
|
141 |
|
|
142 |
public void setActive(boolean active) { |
|
143 |
this.actionInfo.setActive(active); |
|
144 |
|
|
145 |
} |
|
146 |
|
|
147 |
public Collection<ActionInfo> getRedirections() { |
|
148 |
return this.actionInfo.getRedirections(); |
|
149 |
} |
|
150 |
|
|
151 |
public Object clone() throws CloneNotSupportedException { |
|
152 |
TranslatedActionInfo other = (TranslatedActionInfo) super.clone(); |
|
153 |
other.actionInfo = (ActionInfo) this.actionInfo.clone(); |
|
154 |
return other; |
|
155 |
} |
|
156 |
} |
tags/org.gvsig.desktop-2.0.346/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.Extension; |
|
43 |
import org.gvsig.andami.plugins.ExtensionHelper; |
|
44 |
import org.gvsig.andami.plugins.IExtension; |
|
45 |
import org.gvsig.andami.ui.mdiFrame.KeyMapping; |
|
46 |
import org.gvsig.tools.ToolsLocator; |
|
47 |
import org.gvsig.tools.identitymanagement.SimpleIdentity; |
|
48 |
import org.gvsig.tools.identitymanagement.SimpleIdentityManager; |
|
49 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
50 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
|
51 |
import org.slf4j.Logger; |
|
52 |
import org.slf4j.LoggerFactory; |
|
53 |
|
|
54 |
public class DefaultActionInfo extends AbstractAction implements ActionInfo { |
|
55 |
|
|
56 |
/** |
|
57 |
* |
|
58 |
*/ |
|
59 |
private static final long serialVersionUID = 1620939552263334110L; |
|
60 |
|
|
61 |
private static Logger logger = LoggerFactory |
|
62 |
.getLogger(DefaultActionInfo.class); |
|
63 |
|
|
64 |
private Class<? extends IExtension> extensionClass; |
|
65 |
private IExtension extension; |
|
66 |
private String name; |
|
67 |
private String text; |
|
68 |
private String command; |
|
69 |
private String iconName; |
|
70 |
private String accelerator; |
|
71 |
private long position; |
|
72 |
private String tip; |
|
73 |
private List<ActionInfo> redirections; |
|
74 |
private boolean active; |
|
75 |
|
|
76 |
private Boolean previousEnabled = null; |
|
77 |
private SimpleIdentityManager identityManager; |
|
78 |
|
|
79 |
|
|
80 |
DefaultActionInfo(IExtension extension, String name, |
|
81 |
String text, String command, String icon, String accelerator, |
|
82 |
long position, String tip) { |
|
83 |
this.extensionClass = extension.getClass(); |
|
84 |
this.extension = extension; |
|
85 |
this.name = name; |
|
86 |
this.text = emptyToNull(text); |
|
87 |
this.command = emptyToNull(command); |
|
88 |
this.iconName = emptyToNull(icon); |
|
89 |
this.accelerator = emptyToNull(accelerator); |
|
90 |
this.position = position; |
|
91 |
this.tip = emptyToNull(tip); |
|
92 |
this.redirections = null; |
|
93 |
this.active = true; |
|
94 |
|
|
95 |
fixIcon(); |
|
96 |
} |
|
97 |
|
|
98 |
DefaultActionInfo(Class<? extends IExtension> extensionClass, String name, |
|
99 |
String text, String command, String icon, String accelerator, |
|
100 |
long position, String tip) { |
|
101 |
this.extensionClass = extensionClass; |
|
102 |
this.name = name; |
|
103 |
this.text = emptyToNull(text); |
|
104 |
this.command = emptyToNull(command); |
|
105 |
this.iconName = emptyToNull(icon); |
|
106 |
this.accelerator = emptyToNull(accelerator); |
|
107 |
this.position = position; |
|
108 |
this.tip = emptyToNull(tip); |
|
109 |
this.redirections = null; |
|
110 |
this.active = true; |
|
111 |
|
|
112 |
fixIcon(); |
|
113 |
} |
|
114 |
|
|
115 |
public Object clone() throws CloneNotSupportedException { |
|
116 |
DefaultActionInfo other = (DefaultActionInfo) super.clone(); |
|
117 |
if (other.redirections != null) { |
|
118 |
other.redirections = new ArrayList<ActionInfo>(); |
|
119 |
other.redirections.addAll(this.redirections); |
|
120 |
} |
|
121 |
return other; |
|
122 |
} |
|
123 |
|
|
124 |
private void fixIcon() { |
|
125 |
if (iconName != null && (iconName.contains("/") || iconName.contains("."))) { |
|
126 |
// it's a file path |
|
127 |
String name = FilenameUtils.getBaseName(iconName); |
|
128 |
IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getDefault(); |
|
129 |
URL resource = null; |
|
130 |
try { |
|
131 |
resource = this.extensionClass.getClassLoader().getResource(iconName); |
|
132 |
} catch (Exception e) { |
|
133 |
return; |
|
134 |
} |
|
135 |
if (resource == null) { |
|
136 |
return; |
|
137 |
} |
|
138 |
iconTheme.registerDefault(this.getPluginName(), "broken", name, null, resource); |
|
139 |
logger.info("Plugin " + this.getPluginName() + " contains icons out of icon theme (" + iconName + ")"); |
|
140 |
iconName = name; |
|
141 |
} |
|
142 |
} |
|
143 |
|
|
144 |
private String emptyToNull(String s) { |
|
145 |
if (s == null) { |
|
146 |
return null; |
|
147 |
} |
|
148 |
return s.trim().length() < 0 ? null : s; |
Also available in: Unified diff