Revision 45175
tags/org.gvsig.desktop-2.0.288/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.288</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.288/org.gvsig.desktop.framework/org.gvsig.andami/src/test/java/org/gvsig/andami/AllTests.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; |
|
25 |
|
|
26 |
import junit.framework.Test; |
|
27 |
import junit.framework.TestSuite; |
|
28 |
|
|
29 |
public class AllTests { |
|
30 |
|
|
31 |
public static Test suite() { |
|
32 |
TestSuite suite = new TestSuite("Test for com.iver.andami"); |
|
33 |
//$JUnit-BEGIN$ |
|
34 |
|
|
35 |
//$JUnit-END$ |
|
36 |
return suite; |
|
37 |
} |
|
38 |
|
|
39 |
} |
|
0 | 40 |
tags/org.gvsig.desktop-2.0.288/org.gvsig.desktop.framework/org.gvsig.andami/src/main/assembly/gvsig-andami-package.xml | ||
---|---|---|
1 |
<!-- |
|
2 |
|
|
3 |
gvSIG. Desktop Geographic Information System. |
|
4 |
|
|
5 |
Copyright (C) 2007-2013 gvSIG Association. |
|
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
|
8 |
modify it under the terms of the GNU General Public License |
|
9 |
as published by the Free Software Foundation; either version 3 |
|
10 |
of the License, or (at your option) any later version. |
|
11 |
|
|
12 |
This program is distributed in the hope that it will be useful, |
|
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 |
GNU General Public License for more details. |
|
16 |
|
|
17 |
You should have received a copy of the GNU General Public License |
|
18 |
along with this program; if not, write to the Free Software |
|
19 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
20 |
MA 02110-1301, USA. |
|
21 |
|
|
22 |
For any additional information, do not hesitate to contact us |
|
23 |
at info AT gvsig.com, or visit our website www.gvsig.com. |
|
24 |
|
|
25 |
--> |
|
26 |
<assembly> |
|
27 |
<id>gvsig-andami-package</id> |
|
28 |
<formats> |
|
29 |
<format>zip</format> |
|
30 |
</formats> |
|
31 |
<baseDirectory>.</baseDirectory> |
|
32 |
<!-- |
|
33 |
<includeBaseDirectory>true</includeBaseDirectory> |
|
34 |
--> |
|
35 |
<files> |
|
36 |
<file> |
|
37 |
<source>target/${project.artifactId}-${project.version}.jar</source> |
|
38 |
<outputDirectory>lib</outputDirectory> |
|
39 |
</file> |
|
40 |
<file> |
|
41 |
<source>src/main/resources/default-log4j/log4j.properties</source> |
|
42 |
<outputDirectory>.</outputDirectory> |
|
43 |
</file> |
|
44 |
</files> |
|
45 |
<fileSets> |
|
46 |
<fileSet> |
|
47 |
<directory>src/main/resources-application</directory> |
|
48 |
<outputDirectory>.</outputDirectory> |
|
49 |
</fileSet> |
|
50 |
<fileSet> |
|
51 |
<directory>src/main/resources/org/gvsig/andami</directory> |
|
52 |
<outputDirectory>i18n/andami</outputDirectory> |
|
53 |
</fileSet> |
|
54 |
</fileSets> |
|
55 |
|
|
56 |
<dependencySets> |
|
57 |
<dependencySet> |
|
58 |
<useProjectArtifact>false</useProjectArtifact> |
|
59 |
<useTransitiveDependencies>true</useTransitiveDependencies> |
|
60 |
<outputDirectory>lib</outputDirectory> |
|
61 |
</dependencySet> |
|
62 |
</dependencySets> |
|
63 |
|
|
64 |
</assembly> |
|
65 |
|
|
0 | 66 |
tags/org.gvsig.desktop-2.0.288/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/Arguments.java | ||
---|---|---|
1 |
package org.gvsig.andami; |
|
2 |
|
|
3 |
import java.util.Iterator; |
|
4 |
import java.util.List; |
|
5 |
import java.util.Map; |
|
6 |
|
|
7 |
public interface Arguments extends Iterable<String> { |
|
8 |
|
|
9 |
public String get(String name); |
|
10 |
|
|
11 |
public Object get(String name, Object defaultValue); |
|
12 |
|
|
13 |
public boolean contains(String name); |
|
14 |
|
|
15 |
public boolean contains(String name, String value); |
|
16 |
|
|
17 |
public Map<String,String> flags(); |
|
18 |
|
|
19 |
public List<String> parameters(); |
|
20 |
|
|
21 |
public int size(); |
|
22 |
|
|
23 |
public String get(int n); |
|
24 |
|
|
25 |
public Iterator<String> iterator(); |
|
26 |
} |
tags/org.gvsig.desktop-2.0.288/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/PluginsLocator.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; |
|
25 |
|
|
26 |
import org.apache.commons.lang3.StringUtils; |
|
27 |
import org.gvsig.andami.actioninfo.ActionInfoManager; |
|
28 |
import org.gvsig.andami.ui.mdiFrame.MainFrame; |
|
29 |
import org.gvsig.tools.locator.AbstractLocator; |
|
30 |
import org.gvsig.tools.locator.Locator; |
|
31 |
import org.gvsig.tools.locator.LocatorException; |
|
32 |
|
|
33 |
|
|
34 |
public class PluginsLocator extends AbstractLocator { |
|
35 |
|
|
36 |
private static final String LOCATOR_NAME = "PluginsLocator"; |
|
37 |
|
|
38 |
/** |
|
39 |
* PluginsManager name used by the locator to access the instance |
|
40 |
*/ |
|
41 |
public static final String PLUGINS_MANAGER_NAME = "PluginsManager"; |
|
42 |
public static final String PLUGINS_ACTIONINFO_MANAGER_NAME = "PluginsActionInfoManager"; |
|
43 |
public static final String PLUGINS_LOCALE_MANAGER_NAME = "LocaleManager"; |
|
44 |
|
|
45 |
private static final String PLUGINS_MANAGER_DESCRIPTION = "PluginsManager of Andami framework"; |
|
46 |
private static final String PLUGINS_ACTIONINFO_MANAGER_DESCRIPTION = "PluginsActionInfoManager"; |
|
47 |
private static final String PLUGINS_LOCALE_MANAGER_DESCRIPTION = "LocaleManager"; |
|
48 |
|
|
49 |
/** |
|
50 |
* Unique instance. |
|
51 |
*/ |
|
52 |
private static final PluginsLocator INSTANCE = new PluginsLocator(); |
|
53 |
|
|
54 |
/** |
|
55 |
* Return the singleton instance. |
|
56 |
* |
|
57 |
* @return the singleton instance |
|
58 |
*/ |
|
59 |
public static PluginsLocator getInstance() { |
|
60 |
return INSTANCE; |
|
61 |
} |
|
62 |
|
|
63 |
/** |
|
64 |
* Returns the Locator name. |
|
65 |
* |
|
66 |
* @return String containing the locator name. |
|
67 |
*/ |
|
68 |
@Override |
|
69 |
public String getLocatorName() { |
|
70 |
return LOCATOR_NAME; |
|
71 |
} |
|
72 |
|
|
73 |
/** |
|
74 |
* Return a reference to PluginsManager. |
|
75 |
* |
|
76 |
* @return a reference to PluginsManager |
|
77 |
* @throws LocatorException |
|
78 |
* if there is no access to the class or the class cannot be |
|
79 |
* instantiated |
|
80 |
* @see Locator#get(String) |
|
81 |
*/ |
|
82 |
public static PluginsManager getManager() throws LocatorException { |
|
83 |
return (PluginsManager) getInstance().get(PLUGINS_MANAGER_NAME); |
|
84 |
} |
|
85 |
|
|
86 |
public static PluginsManager getPluginsManager() throws LocatorException { |
|
87 |
return (PluginsManager) getInstance().get(PLUGINS_MANAGER_NAME); |
|
88 |
} |
|
89 |
|
|
90 |
/** |
|
91 |
* Registers the Class implementing the PluginsManager interface. |
|
92 |
* |
|
93 |
* @param clazz |
|
94 |
* implementing the PluginsManager interface |
|
95 |
*/ |
|
96 |
public static void registerManager(Class clazz) { |
|
97 |
getInstance().register(PLUGINS_MANAGER_NAME, PLUGINS_MANAGER_DESCRIPTION, |
|
98 |
clazz); |
|
99 |
} |
|
100 |
|
|
101 |
/** |
|
102 |
* Registers a class as the default PluginsManager. |
|
103 |
* |
|
104 |
* @param clazz |
|
105 |
* implementing the DataManager interface |
|
106 |
*/ |
|
107 |
public static void registerDefaultManager(Class clazz) { |
|
108 |
getInstance().registerDefault(PLUGINS_MANAGER_NAME, PLUGINS_MANAGER_DESCRIPTION, |
|
109 |
clazz); |
|
110 |
} |
|
111 |
|
|
112 |
|
|
113 |
public static ActionInfoManager getActionInfoManager() throws LocatorException { |
|
114 |
return (ActionInfoManager) getInstance().get(PLUGINS_ACTIONINFO_MANAGER_NAME); |
|
115 |
} |
|
116 |
|
|
117 |
public static void registerActionInfoManager(Class clazz) { |
|
118 |
getInstance().register(PLUGINS_ACTIONINFO_MANAGER_NAME, PLUGINS_ACTIONINFO_MANAGER_DESCRIPTION, |
|
119 |
clazz); |
|
120 |
} |
|
121 |
|
|
122 |
public static MainFrame getMainFrame() { |
|
123 |
return Launcher.getFrame(); |
|
124 |
} |
|
125 |
|
|
126 |
public static LocaleManager getLocaleManager() throws LocatorException { |
|
127 |
return (LocaleManager) getInstance().get(PLUGINS_LOCALE_MANAGER_NAME); |
|
128 |
} |
|
129 |
|
|
130 |
public static void registerLocaleManager(Class clazz) { |
|
131 |
getInstance().register(PLUGINS_LOCALE_MANAGER_NAME, PLUGINS_LOCALE_MANAGER_DESCRIPTION, |
|
132 |
clazz); |
|
133 |
} |
|
134 |
} |
|
0 | 135 |
tags/org.gvsig.desktop-2.0.288/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/PluginsLibrary.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; |
|
25 |
|
|
26 |
import org.gvsig.andami.actioninfo.impl.DefaultActionInfoManager; |
|
27 |
import org.gvsig.andami.firewall.DefaultFirewallConfiguration; |
|
28 |
import org.gvsig.andami.impl.DefaultLocaleManager; |
|
29 |
import org.gvsig.andami.impl.DefaultPluginsManager; |
|
30 |
import org.gvsig.andami.installer.icontheme.IconThemeInstallerFactory.RegisterIconThemeInstaller; |
|
31 |
import org.gvsig.andami.installer.translations.TranslationsInstallerFactory.RegisterTranslationsInstaller; |
|
32 |
import org.gvsig.andami.ui.mdiFrame.DefaultThreadSafeDialogs; |
|
33 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
|
34 |
import org.gvsig.installer.lib.api.InstallerLibrary; |
|
35 |
import org.gvsig.tools.ToolsLocator; |
|
36 |
import org.gvsig.tools.library.AbstractLibrary; |
|
37 |
import org.gvsig.tools.library.LibraryException; |
|
38 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
39 |
import org.gvsig.tools.util.Caller; |
|
40 |
import org.gvsig.tools.util.impl.DefaultCaller; |
|
41 |
|
|
42 |
|
|
43 |
public class PluginsLibrary extends AbstractLibrary { |
|
44 |
|
|
45 |
@Override |
|
46 |
public void doRegistration() { |
|
47 |
registerAsAPI(PluginsLibrary.class); |
|
48 |
require(InstallerLibrary.class); |
|
49 |
} |
|
50 |
|
|
51 |
protected void doInitialize() throws LibraryException { |
|
52 |
PluginsLocator.registerDefaultManager(DefaultPluginsManager.class); |
|
53 |
PluginsLocator.registerActionInfoManager(DefaultActionInfoManager.class); |
|
54 |
PluginsLocator.registerLocaleManager(DefaultLocaleManager.class); |
|
55 |
|
|
56 |
ToolsLocator.registerDefaultFirewallManager(DefaultFirewallConfiguration.class); |
|
57 |
ToolsSwingLocator.registerThreadSafeDialogsManager(DefaultThreadSafeDialogs.class); |
|
58 |
|
|
59 |
// Force initialize of the LocaleManager |
|
60 |
PluginsLocator.getLocaleManager(); |
|
61 |
} |
|
62 |
|
|
63 |
protected void doPostInitialize() throws LibraryException { |
|
64 |
Caller caller = new DefaultCaller(); |
|
65 |
|
|
66 |
caller.add(new WindowInfo.RegisterPersistence() ); |
|
67 |
caller.add(new RegisterTranslationsInstaller() ); |
|
68 |
caller.add(new RegisterIconThemeInstaller() ); |
|
69 |
if( !caller.call() ) { |
|
70 |
throw new LibraryException(PluginsLibrary.class, caller.getExceptions()); |
|
71 |
} |
|
72 |
|
|
73 |
|
|
74 |
} |
|
75 |
|
|
76 |
} |
|
0 | 77 |
tags/org.gvsig.desktop-2.0.288/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.288/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.288/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.288/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.288/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.288/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.288/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); |
Also available in: Unified diff