gvsig-scripting / org.gvsig.scripting.app / trunk / org.gvsig.scripting.app / org.gvsig.scripting.app.extension / src / main / java / org / gvsig / scripting / app / extension / ScriptingExtension.java @ 458
History | View | Annotate | Download (5.8 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
package org.gvsig.scripting.app.extension; |
24 |
|
25 |
|
26 |
import java.io.File; |
27 |
import java.util.Arrays; |
28 |
import java.util.List; |
29 |
|
30 |
import javax.swing.JOptionPane; |
31 |
|
32 |
import org.gvsig.andami.IconThemeHelper; |
33 |
import org.gvsig.andami.PluginsLocator; |
34 |
import org.gvsig.andami.PluginsManager; |
35 |
import org.gvsig.andami.plugins.Extension; |
36 |
import org.gvsig.app.ApplicationLocator; |
37 |
import org.gvsig.app.ApplicationManager; |
38 |
import org.gvsig.scripting.ScriptingBaseScript; |
39 |
import org.gvsig.scripting.ScriptingLocator; |
40 |
import org.gvsig.scripting.ScriptingManager; |
41 |
import org.gvsig.scripting.swing.api.JScriptingComposer; |
42 |
import org.gvsig.scripting.swing.api.ScriptingSwingLocator; |
43 |
import org.gvsig.scripting.swing.api.ScriptingUIManager; |
44 |
import org.gvsig.tools.dynobject.DynObject; |
45 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
46 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
47 |
import org.gvsig.tools.swing.impl.windowmanager.DefaultWindowManager; |
48 |
import org.slf4j.Logger; |
49 |
import org.slf4j.LoggerFactory; |
50 |
|
51 |
public class ScriptingExtension extends Extension { |
52 |
|
53 |
private static Logger logger = LoggerFactory.getLogger(ScriptingExtension.class); |
54 |
|
55 |
public void execute(String actionCommand) { |
56 |
this.execute(actionCommand,null); |
57 |
} |
58 |
|
59 |
public void execute(String command, Object[] args) { |
60 |
ScriptingUIManager uimanager = ScriptingSwingLocator.getUIManager(); |
61 |
WindowManager winmanager = ToolsSwingLocator.getWindowManager(); |
62 |
|
63 |
if( "tools-scripting-launcher".equalsIgnoreCase(command) ) { |
64 |
winmanager.showWindow(uimanager.createLauncher(), uimanager.getTranslation("Scripting_Launcher"), WindowManager.MODE.TOOL);
|
65 |
|
66 |
} else if( "tools-scripting-composer".equalsIgnoreCase(command) ) { |
67 |
DynObject preferences = this.getPlugin().getPluginProperties();
|
68 |
Boolean composerUseHisWindowManager = (Boolean) preferences.getDynValue("ComposerUseHisWindowManager"); |
69 |
JScriptingComposer composer = uimanager.createComposer(); |
70 |
if( composerUseHisWindowManager.booleanValue() ) {
|
71 |
winmanager = new DefaultWindowManager();
|
72 |
composer.setWindowManager(winmanager); |
73 |
winmanager.showWindow(composer, uimanager.getTranslation("Scripting_Composer"), WindowManager.MODE.WINDOW);
|
74 |
} else {
|
75 |
winmanager.showWindow(composer, uimanager.getTranslation("Scripting_Composer"), WindowManager.MODE.WINDOW);
|
76 |
} |
77 |
|
78 |
} else {
|
79 |
ScriptingBaseScript script = uimanager.getManager().getScript(command); |
80 |
if( script != null ) { |
81 |
script.run(args); |
82 |
} else {
|
83 |
ApplicationManager application = ApplicationLocator.getManager(); |
84 |
application.messageDialog("Can't locate script '"+command+"'.", "ScriptLaunch", JOptionPane.OK_OPTION); |
85 |
} |
86 |
} |
87 |
} |
88 |
|
89 |
public void initialize() { |
90 |
IconThemeHelper.registerIcon("action", "tools-scripting-launcher", this); |
91 |
IconThemeHelper.registerIcon("action", "tools-scripting-composer", this); |
92 |
IconThemeHelper.registerIcon("action", "tools-scripting-console-jython", this); |
93 |
} |
94 |
|
95 |
public void postInitialize() { |
96 |
super.postInitialize();
|
97 |
ScriptingManager manager = ScriptingLocator.getManager(); |
98 |
PluginsManager pluginManager = PluginsLocator.getManager(); |
99 |
|
100 |
File home = this.getPlugin().getPluginHomeFolder(); |
101 |
manager.setHomeFolder(home); |
102 |
|
103 |
List<File> pluginsFolders = Arrays.asList(pluginManager.getPluginsFolder().listFiles()); |
104 |
for( File pluginsFolder : pluginsFolders ) { |
105 |
File[] folders = pluginsFolder.listFiles(); |
106 |
for (File folder : folders) { |
107 |
File scriptsFolder = new File(folder,"scripting/scripts"); |
108 |
if( scriptsFolder.exists() ) {
|
109 |
manager.registerSystemFolder(folder.getName(), scriptsFolder); |
110 |
} |
111 |
File libFolder = new File(folder,"scripting/lib"); |
112 |
if( libFolder.exists() ) {
|
113 |
manager.addLibFolder(libFolder); |
114 |
} |
115 |
} |
116 |
} |
117 |
File autorun_file = null; |
118 |
ScriptingBaseScript autorun = null;
|
119 |
for( File pluginsFolder : pluginsFolders ) { |
120 |
File[] folders = pluginsFolder.listFiles(); |
121 |
for (File folder : folders) { |
122 |
autorun_file = new File(folder,"scripting/scripts/autorun.inf"); |
123 |
if( autorun_file.exists() ) {
|
124 |
autorun = manager.getScript(autorun_file); |
125 |
try {
|
126 |
autorun.run(); |
127 |
} catch(Exception ex) { |
128 |
logger.warn("Can't execute autorun from '"+autorun_file.getAbsolutePath()+"'.",ex); |
129 |
} |
130 |
} |
131 |
} |
132 |
} |
133 |
try {
|
134 |
autorun_file = new File( manager.getRootUserFolder(),"autorun.inf" ); |
135 |
if( autorun_file.exists() ) {
|
136 |
autorun = (ScriptingBaseScript) manager.getUserFolder().getUnit(new File("autorun.inf")); |
137 |
if( autorun!=null) { |
138 |
autorun.run(); |
139 |
} |
140 |
} |
141 |
} catch(Exception ex) { |
142 |
logger.warn("Can't execute autorun in home.",ex);
|
143 |
} |
144 |
|
145 |
/*
|
146 |
*
|
147 |
ProviderManager providerManager = InstallerProviderLocator.getProviderManager();
|
148 |
providerManager.addProviderFactory(new ScriptingInstallerProviderFactory());
|
149 |
*/
|
150 |
} |
151 |
|
152 |
public boolean isEnabled() { |
153 |
return true; |
154 |
} |
155 |
|
156 |
public boolean isVisible() { |
157 |
return true; |
158 |
} |
159 |
|
160 |
} |