svn-gvsig-desktop / trunk / frameworks / _fwAndami / src / com / iver / andami / PluginServices.java @ 38211
History | View | Annotate | Download (19.8 KB)
1 | 1104 | fjp | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | 11910 | cesar | * Copyright (C) 2004-2007 IVER T.I. and Generalitat Valenciana.
|
4 | 1104 | fjp | *
|
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | 598 | fernando | package com.iver.andami; |
42 | |||
43 | import java.awt.Component; |
||
44 | 4419 | azabala | import java.awt.Frame; |
45 | 5828 | fjp | import java.awt.KeyEventDispatcher; |
46 | 7741 | jmvivo | import java.awt.Toolkit; |
47 | import java.awt.datatransfer.DataFlavor; |
||
48 | import java.awt.datatransfer.StringSelection; |
||
49 | import java.awt.datatransfer.UnsupportedFlavorException; |
||
50 | 598 | fernando | import java.awt.event.ActionListener; |
51 | 1141 | fernando | import java.io.File; |
52 | 7741 | jmvivo | import java.io.IOException; |
53 | 1141 | fernando | import java.lang.reflect.InvocationTargetException; |
54 | 9634 | caballero | import java.util.ArrayList; |
55 | 8508 | jaume | import java.util.HashMap; |
56 | 735 | vcaballero | import java.util.Iterator; |
57 | 16251 | jmvivo | import java.util.Properties; |
58 | 598 | fernando | |
59 | 5817 | fjp | import javax.swing.KeyStroke; |
60 | 1141 | fernando | import javax.swing.SwingUtilities; |
61 | 4338 | azabala | import javax.swing.Timer; |
62 | 598 | fernando | |
63 | 1153 | fernando | import org.apache.log4j.Logger; |
64 | 598 | fernando | |
65 | 4358 | ldiaz | import com.iver.andami.authentication.IAuthentication; |
66 | 15944 | jmvivo | import com.iver.andami.iconthemes.IIconTheme; |
67 | 15919 | jmvivo | import com.iver.andami.iconthemes.IconThemeManager; |
68 | 1153 | fernando | import com.iver.andami.messages.Messages; |
69 | import com.iver.andami.messages.NotificationManager; |
||
70 | 11910 | cesar | import com.iver.andami.plugins.ExclusiveUIExtension; |
71 | 5275 | jaume | import com.iver.andami.plugins.ExtensionDecorator; |
72 | 5005 | jorpiell | import com.iver.andami.plugins.IExtension; |
73 | 1153 | fernando | import com.iver.andami.plugins.PluginClassLoader; |
74 | 5800 | caballero | import com.iver.andami.preferences.DlgPreferences; |
75 | 1153 | fernando | import com.iver.andami.ui.mdiFrame.MDIFrame; |
76 | import com.iver.andami.ui.mdiFrame.MainFrame; |
||
77 | import com.iver.andami.ui.mdiManager.MDIManager; |
||
78 | import com.iver.utiles.XMLEntity; |
||
79 | 4419 | azabala | import com.iver.utiles.swing.threads.IMonitorableTask; |
80 | import com.iver.utiles.swing.threads.IProgressMonitorIF; |
||
81 | 4338 | azabala | import com.iver.utiles.swing.threads.TaskMonitorTimerListener; |
82 | 4419 | azabala | import com.iver.utiles.swing.threads.UndefinedProgressMonitor; |
83 | 1153 | fernando | |
84 | 598 | fernando | /**
|
85 | 11910 | cesar | * Provides services to Plugins. Each plugin has an associated PluginServices
|
86 | * object, which provides specific services. Main of them: translations,
|
||
87 | * logging, access to plugin's resources, background tasks, clipboard access
|
||
88 | * and data persistence.
|
||
89 | 5800 | caballero | *
|
90 | 1141 | fernando | * @author Fernando Gonz?lez Cort?s
|
91 | 598 | fernando | */
|
92 | public class PluginServices { |
||
93 | 4419 | azabala | private static Logger logger = Logger.getLogger(PluginServices.class |
94 | .getName()); |
||
95 | |||
96 | 3654 | fjp | private static String[] arguments; |
97 | 4419 | azabala | |
98 | 4361 | ldiaz | private static IAuthentication authentication; |
99 | 9634 | caballero | |
100 | 11910 | cesar | private static ExclusiveUIExtension exclusiveUIExtension = null; |
101 | 4419 | azabala | |
102 | 1141 | fernando | private PluginClassLoader loader;
|
103 | 4419 | azabala | |
104 | 1141 | fernando | private XMLEntity persistentXML;
|
105 | 598 | fernando | |
106 | 13793 | cesar | |
107 | 1141 | fernando | /**
|
108 | 11910 | cesar | * Creates a new PluginServices objetct.
|
109 | 5800 | caballero | *
|
110 | 4419 | azabala | * @param loader
|
111 | 11910 | cesar | * The Plugin's ClassLoader.
|
112 | 1141 | fernando | */
|
113 | public PluginServices(PluginClassLoader loader) {
|
||
114 | this.loader = loader;
|
||
115 | } |
||
116 | 598 | fernando | |
117 | 1141 | fernando | /**
|
118 | 15944 | jmvivo | * Returns the message in the current's locale language
|
119 | 11910 | cesar | * corresponding to the provided translation key.
|
120 | * The key-message pairs are obtained from the plugin's
|
||
121 | * translation files (text_xx.properties files).
|
||
122 | 5800 | caballero | *
|
123 | 4419 | azabala | * @param key
|
124 | 11910 | cesar | * Translation key whose associated message is to be obtained
|
125 | 5800 | caballero | *
|
126 | 11910 | cesar | * @return The message associated with the provided key, in one of the
|
127 | * current locale languages, or the key if the translation is not found.
|
||
128 | 1141 | fernando | */
|
129 | public String getText(String key) { |
||
130 | 4517 | cesar | if (key == null) return null; |
131 | 4732 | cesar | String translation = org.gvsig.i18n.Messages.getText(key, false); |
132 | 6367 | caballero | if (translation != null) |
133 | 4517 | cesar | return translation;
|
134 | else
|
||
135 | { |
||
136 | 8010 | cesar | logger.warn("Plugin "+getPluginName()+" -- "+org.gvsig.i18n.Messages.getText("No_se_encontro_la_traduccion_para", false)+ " " + key); |
137 | 1141 | fernando | return key;
|
138 | } |
||
139 | } |
||
140 | 598 | fernando | |
141 | 1141 | fernando | /**
|
142 | 11910 | cesar | * Gets the plugin's classloader.
|
143 | 5800 | caballero | *
|
144 | 1141 | fernando | * @return Returns the loader.
|
145 | */
|
||
146 | public PluginClassLoader getClassLoader() {
|
||
147 | return loader;
|
||
148 | } |
||
149 | |||
150 | /**
|
||
151 | 11910 | cesar | * Gets the plugin's name
|
152 | 5800 | caballero | *
|
153 | 11910 | cesar | * @return The plugin's name
|
154 | 1141 | fernando | */
|
155 | String getPluginName() {
|
||
156 | return loader.getPluginName();
|
||
157 | } |
||
158 | |||
159 | /**
|
||
160 | 11910 | cesar | * Gets a reference to the PluginServices object associated with the
|
161 | * plugin containing the provided class.
|
||
162 | 15944 | jmvivo | *
|
163 | 1141 | fernando | * Obtienen una referencia al PluginServices del plugin cuyo nombre se pasa
|
164 | * como par?metro
|
||
165 | 5800 | caballero | *
|
166 | 4419 | azabala | * @param pluginClassInstance
|
167 | 11910 | cesar | * An instance of a class. This class is contained in a plugin, whose
|
168 | * services are to be obtained
|
||
169 | 5800 | caballero | *
|
170 | 11910 | cesar | * @return The PluginServices object associated to the containing plugin
|
171 | 5800 | caballero | *
|
172 | 4419 | azabala | * @throws RuntimeException
|
173 | 11910 | cesar | * If the parameter was not loaded from a plugin
|
174 | 1141 | fernando | */
|
175 | public static PluginServices getPluginServices(Object pluginClassInstance) { |
||
176 | try {
|
||
177 | 4419 | azabala | PluginClassLoader loader = (PluginClassLoader) pluginClassInstance |
178 | .getClass().getClassLoader(); |
||
179 | 1141 | fernando | |
180 | return Launcher.getPluginServices(loader.getPluginName());
|
||
181 | } catch (ClassCastException e) { |
||
182 | 4419 | azabala | /*
|
183 | * throw new RuntimeException( "Parameter is not a plugin class
|
||
184 | * instance");
|
||
185 | */
|
||
186 | return null; |
||
187 | 598 | fernando | } |
188 | 1141 | fernando | } |
189 | 598 | fernando | |
190 | 1141 | fernando | /**
|
191 | 11910 | cesar | * Gets a reference to the PluginServices object associated with the
|
192 | * provided plugin.
|
||
193 | 5800 | caballero | *
|
194 | 4419 | azabala | * @param pluginName
|
195 | 11910 | cesar | * Plugin's name whose services are going to be used
|
196 | 5800 | caballero | *
|
197 | 11910 | cesar | * @return The PluginServices object associated with the provided plugin.
|
198 | 1141 | fernando | */
|
199 | public static PluginServices getPluginServices(String pluginName) { |
||
200 | return Launcher.getPluginServices(pluginName);
|
||
201 | } |
||
202 | 598 | fernando | |
203 | 1141 | fernando | /**
|
204 | 11910 | cesar | * Gets the window manager (MDIManager).
|
205 | 5800 | caballero | *
|
206 | 11910 | cesar | * @return A reference to the window manager (MDIManager).
|
207 | 1141 | fernando | */
|
208 | public static MDIManager getMDIManager() { |
||
209 | return Launcher.getFrame().getMDIManager();
|
||
210 | } |
||
211 | 598 | fernando | |
212 | 1141 | fernando | /**
|
213 | 11910 | cesar | * Gets the application's main frame.
|
214 | 5800 | caballero | *
|
215 | 11910 | cesar | * @return A reference to the application's main window
|
216 | 1141 | fernando | */
|
217 | public static MainFrame getMainFrame() { |
||
218 | return Launcher.getFrame();
|
||
219 | } |
||
220 | 6367 | caballero | |
221 | 5828 | fjp | public static void registerKeyStroke(KeyStroke key, KeyEventDispatcher a) |
222 | 5817 | fjp | { |
223 | GlobalKeyEventDispatcher.getInstance().registerKeyStroke(key, a); |
||
224 | } |
||
225 | 1141 | fernando | |
226 | 5817 | fjp | public static void unRegisterKeyStroke(KeyStroke key) |
227 | { |
||
228 | GlobalKeyEventDispatcher.getInstance().removeKeyStrokeBinding(key); |
||
229 | } |
||
230 | |||
231 | 1141 | fernando | /**
|
232 | 15944 | jmvivo | * Gets the instance of the extension whose class is provided.
|
233 | 5800 | caballero | *
|
234 | 4419 | azabala | * @param extensionClass
|
235 | 11910 | cesar | * Class of the extension whose instance is to be returned
|
236 | 5800 | caballero | *
|
237 | 11910 | cesar | * @return The instance of the extension, or null if the instance does
|
238 | * not exist.Instancia de la extensi?n o null en caso de que no haya una
|
||
239 | 1141 | fernando | */
|
240 | 5005 | jorpiell | public static IExtension getExtension(Class extensionClass) { |
241 | 4419 | azabala | ExtensionDecorator extAux = (ExtensionDecorator) Launcher |
242 | .getClassesExtensions().get(extensionClass); |
||
243 | 11910 | cesar | try {
|
244 | return extAux.getExtension();
|
||
245 | } |
||
246 | catch (NullPointerException ex) { |
||
247 | return null; |
||
248 | } |
||
249 | 1141 | fernando | } |
250 | |||
251 | /**
|
||
252 | 11910 | cesar | * Gets a reference to the Extension Decorator which adds some extra options
|
253 | * to the basic extension interface.
|
||
254 | 5800 | caballero | *
|
255 | 11910 | cesar | * @param extensionClass The class of the extension whose decorator is to be returned
|
256 | * @return The ExtensionDecorator associated with the provided extension,
|
||
257 | * or null if the extension does not exist.
|
||
258 | 2862 | jaume | */
|
259 | public static ExtensionDecorator getDecoratedExtension(Class extensionClass) { |
||
260 | 4419 | azabala | return (ExtensionDecorator) Launcher.getClassesExtensions().get(
|
261 | extensionClass); |
||
262 | 2862 | jaume | } |
263 | 4419 | azabala | |
264 | 2862 | jaume | /**
|
265 | 8508 | jaume | * Returns an array containing references to all the loaded extensions.
|
266 | 15944 | jmvivo | *
|
267 | 11910 | cesar | * @return ExtensionDecorator[] An array of ExtensionDecorators (each
|
268 | * Decorator contains one extension).
|
||
269 | 8508 | jaume | */
|
270 | public static ExtensionDecorator[] getDecoratedExtensions() { |
||
271 | HashMap map = Launcher.getClassesExtensions();
|
||
272 | ExtensionDecorator[] extensions = (ExtensionDecorator[]) map. |
||
273 | values().toArray(new ExtensionDecorator[0]); |
||
274 | return extensions;
|
||
275 | } |
||
276 | |||
277 | /**
|
||
278 | 11910 | cesar | * Gets an iterator with all the loaded Extensions.
|
279 | 5800 | caballero | *
|
280 | 11910 | cesar | * @return Iterator over the decorated extensions (each member of
|
281 | * the iterator is an ExtensionDecorator, which in turn contains
|
||
282 | * one IExtension object).
|
||
283 | 1141 | fernando | */
|
284 | public static Iterator getExtensions() { |
||
285 | return Launcher.getClassesExtensions().values().iterator();
|
||
286 | } |
||
287 | |||
288 | /**
|
||
289 | 15944 | jmvivo | * Returns the message in the current's locale language
|
290 | 11910 | cesar | * corresponding to the provided translation key.
|
291 | * The key-message pairs are obtained from the plugin's
|
||
292 | * translation files (text_xx.properties files).
|
||
293 | 15944 | jmvivo | *
|
294 | 11910 | cesar | * @param pluginObject Any object which was loaded from a plugin
|
295 | 5800 | caballero | *
|
296 | 4419 | azabala | * @param key
|
297 | 11910 | cesar | * Translation key whose associated message is to be obtained
|
298 | 5800 | caballero | *
|
299 | 11910 | cesar | * @return The message associated with the provided key, in one of the
|
300 | * current locale languages, or the key if the translation is not found.
|
||
301 | 1141 | fernando | */
|
302 | public static String getText(Object pluginObject, String key) { |
||
303 | 4517 | cesar | if (key == null) return null; |
304 | 4732 | cesar | String translation = org.gvsig.i18n.Messages.getText(key, false); |
305 | 6367 | caballero | if (translation != null) |
306 | 4517 | cesar | return translation;
|
307 | else
|
||
308 | { |
||
309 | 8010 | cesar | logger.warn(org.gvsig.i18n.Messages.getText("No_se_encontro_la_traduccion_para",false) + " "+ key); |
310 | 1141 | fernando | return key;
|
311 | 608 | fjp | } |
312 | 1141 | fernando | } |
313 | |||
314 | /**
|
||
315 | 11910 | cesar | * Sets the XML data which should be saved on disk for this plugin. This
|
316 | * data can be retrieved on following sessions.
|
||
317 | 15944 | jmvivo | *
|
318 | 11910 | cesar | * @param The XMLEntity object containing the data to be persisted.
|
319 | 15944 | jmvivo | *
|
320 | 11910 | cesar | * @see PluginServices.getPersistentXML()
|
321 | 15944 | jmvivo | * @see XMLEntity
|
322 | 1141 | fernando | */
|
323 | 1217 | fernando | public void setPersistentXML(XMLEntity entity) { |
324 | 1141 | fernando | persistentXML = entity; |
325 | } |
||
326 | |||
327 | /**
|
||
328 | 11910 | cesar | * Gets the XML data which was saved on previous sessions for this
|
329 | * plugins.
|
||
330 | 5800 | caballero | *
|
331 | 13831 | cesar | * @return An XMLEntity object containing the persisted data
|
332 | 1141 | fernando | */
|
333 | public XMLEntity getPersistentXML() {
|
||
334 | 4419 | azabala | if (persistentXML == null) { |
335 | 1363 | fernando | persistentXML = new XMLEntity();
|
336 | } |
||
337 | 1141 | fernando | return persistentXML;
|
338 | } |
||
339 | |||
340 | /**
|
||
341 | 4419 | azabala | * A?ade un listener a un popup menu registrado en el config.xml de alg?n
|
342 | * plugin
|
||
343 | 5800 | caballero | *
|
344 | 4419 | azabala | * @param name
|
345 | * Nombre del men? contextual
|
||
346 | * @param c
|
||
347 | * Componente que desplegar? el men? cuando se haga click con el
|
||
348 | * bot?n derecho
|
||
349 | * @param listener
|
||
350 | * Listener que se ejecutar? cuando se seleccione cualquier
|
||
351 | * entrada del men?
|
||
352 | 5800 | caballero | *
|
353 | 4419 | azabala | * @throws RuntimeException
|
354 | * Si la interfaz no est? preparada todav?a. S?lo puede darse
|
||
355 | * durante el arranque
|
||
356 | 1141 | fernando | */
|
357 | public void addPopupMenuListener(String name, Component c, |
||
358 | 4419 | azabala | ActionListener listener) {
|
359 | 1141 | fernando | MDIFrame frame = Launcher.getFrame(); |
360 | |||
361 | if (frame == null) { |
||
362 | throw new RuntimeException("MDIFrame not loaded yet"); |
||
363 | 608 | fjp | } |
364 | 598 | fernando | |
365 | 1141 | fernando | frame.addPopupMenuListener(name, c, listener, loader); |
366 | } |
||
367 | 598 | fernando | |
368 | 1141 | fernando | /**
|
369 | 11910 | cesar | * Gets the plugin's root directory.
|
370 | 5800 | caballero | *
|
371 | 11910 | cesar | * @return A File pointing to the plugin's root directory.
|
372 | 1141 | fernando | */
|
373 | public File getPluginDirectory() { |
||
374 | 4419 | azabala | return new File(Launcher.getPluginsDir() + File.separator |
375 | + getPluginName()); |
||
376 | 1141 | fernando | } |
377 | 598 | fernando | |
378 | 1141 | fernando | /**
|
379 | 11910 | cesar | * Runs a background task. The events produced on the main frame will
|
380 | * be inhibited.
|
||
381 | 5800 | caballero | *
|
382 | 4419 | azabala | * @param r
|
383 | 11910 | cesar | * The task to run.
|
384 | 5800 | caballero | *
|
385 | 11910 | cesar | * @return The Thread on which the task is executed.
|
386 | 1141 | fernando | */
|
387 | public static Thread backgroundExecution(Runnable r) { |
||
388 | Thread t = new Thread(new RunnableDecorator(r)); |
||
389 | t.start(); |
||
390 | 598 | fernando | |
391 | 1141 | fernando | return t;
|
392 | } |
||
393 | 4419 | azabala | |
394 | /**
|
||
395 | 11910 | cesar | * Runs a backbround task. This task may be monitored and canceled, and
|
396 | * does not inhibit any event.
|
||
397 | 5800 | caballero | *
|
398 | 4419 | azabala | * @param task
|
399 | 11910 | cesar | * The task to run.
|
400 | 4419 | azabala | */
|
401 | public static void cancelableBackgroundExecution(final IMonitorableTask task) { |
||
402 | 4338 | azabala | final com.iver.utiles.swing.threads.SwingWorker worker = new com.iver.utiles.swing.threads.SwingWorker() { |
403 | 4419 | azabala | public Object construct() { |
404 | try {
|
||
405 | task.run(); |
||
406 | return task;
|
||
407 | } catch (Exception e) { |
||
408 | NotificationManager.addError(null, e);
|
||
409 | } |
||
410 | return null; |
||
411 | } |
||
412 | 11632 | cesar | /**
|
413 | * Called on the event dispatching thread (not on the worker thread)
|
||
414 | * after the <code>construct</code> method has returned.
|
||
415 | */
|
||
416 | public void finished() { |
||
417 | task.finished(); |
||
418 | } |
||
419 | 4419 | azabala | }; |
420 | |||
421 | Component mainFrame = (Component) PluginServices.getMainFrame(); |
||
422 | |||
423 | IProgressMonitorIF progressMonitor = null;
|
||
424 | 4816 | azabala | String title = getText(null, "PluginServices.Procesando"); |
425 | progressMonitor = new UndefinedProgressMonitor((Frame) mainFrame, title); |
||
426 | 4419 | azabala | progressMonitor.setIndeterminated(!task.isDefined()); |
427 | progressMonitor.setInitialStep(task.getInitialStep()); |
||
428 | progressMonitor.setLastStep(task.getFinishStep()); |
||
429 | progressMonitor.setCurrentStep(task.getCurrentStep()); |
||
430 | progressMonitor.setMainTitleLabel(task.getStatusMessage()); |
||
431 | progressMonitor.setNote(task.getNote()); |
||
432 | progressMonitor.open(); |
||
433 | int delay = 500; |
||
434 | TaskMonitorTimerListener timerListener = new TaskMonitorTimerListener(
|
||
435 | progressMonitor, task); |
||
436 | Timer timer = new Timer(delay, timerListener); |
||
437 | timerListener.setTimer(timer); |
||
438 | timer.start(); |
||
439 | |||
440 | worker.start(); |
||
441 | |||
442 | 4338 | azabala | } |
443 | 1141 | fernando | |
444 | 11910 | cesar | /**
|
445 | * Closes the application. Cleanly exits from the application:
|
||
446 | * terminates all the extensions, then exits.
|
||
447 | *
|
||
448 | */
|
||
449 | 4419 | azabala | public static void closeApplication() { |
450 | Launcher.closeApplication(); |
||
451 | 2142 | fernando | } |
452 | 4419 | azabala | |
453 | 1141 | fernando | /**
|
454 | * DOCUMENT ME!
|
||
455 | 5800 | caballero | *
|
456 | 1141 | fernando | * @author Fernando Gonz?lez Cort?s
|
457 | */
|
||
458 | private static class RunnableDecorator implements Runnable { |
||
459 | private Runnable r; |
||
460 | |||
461 | /**
|
||
462 | * Crea un nuevo RunnableDecorator.
|
||
463 | 5800 | caballero | *
|
464 | 4419 | azabala | * @param r
|
465 | * DOCUMENT ME!
|
||
466 | 1141 | fernando | */
|
467 | public RunnableDecorator(Runnable r) { |
||
468 | this.r = r;
|
||
469 | } |
||
470 | |||
471 | /**
|
||
472 | * @see java.lang.Runnable#run()
|
||
473 | */
|
||
474 | public void run() { |
||
475 | 4419 | azabala | try {
|
476 | 1141 | fernando | SwingUtilities.invokeAndWait(new Runnable() { |
477 | 4419 | azabala | public void run() { |
478 | try {
|
||
479 | r.run(); |
||
480 | } catch (RuntimeException e) { |
||
481 | NotificationManager |
||
482 | .addError( |
||
483 | Messages |
||
484 | .getString("PluginServices.Bug_en_el_codigo"),
|
||
485 | e); |
||
486 | } catch (Error e) { |
||
487 | NotificationManager |
||
488 | .addError( |
||
489 | Messages |
||
490 | .getString("PluginServices.Error_grave_de_la_aplicaci?n"),
|
||
491 | e); |
||
492 | 1141 | fernando | } |
493 | 4419 | azabala | } |
494 | }); |
||
495 | 1141 | fernando | } catch (InterruptedException e) { |
496 | 4419 | azabala | NotificationManager |
497 | .addWarning( |
||
498 | Messages |
||
499 | .getString("PluginServices.No_se_pudo_poner_el_reloj_de_arena"),
|
||
500 | e); |
||
501 | 1141 | fernando | } catch (InvocationTargetException e) { |
502 | 4419 | azabala | NotificationManager |
503 | .addWarning( |
||
504 | Messages |
||
505 | .getString("PluginServices.No_se_pudo_poner_el_reloj_de_arena"),
|
||
506 | e); |
||
507 | 1153 | fernando | } |
508 | 1141 | fernando | } |
509 | } |
||
510 | 3654 | fjp | |
511 | /**
|
||
512 | 11910 | cesar | * Gets an array containing the application's startup arguments.
|
513 | * <br><br>
|
||
514 | * Usually: <code>appName plugins-directory [locale] [other args]</code>
|
||
515 | 5800 | caballero | *
|
516 | 4419 | azabala | * @return the original arguments that Andami received. (app-name
|
517 | * plugins-directory, locale, etc)
|
||
518 | 3654 | fjp | */
|
519 | public static String[] getArguments() { |
||
520 | return arguments;
|
||
521 | 9634 | caballero | } |
522 | 3654 | fjp | |
523 | 11910 | cesar | /**
|
524 | * Replaces the original Andami arguments with the provided arguments.
|
||
525 | 15944 | jmvivo | *
|
526 | 11910 | cesar | * @param arguments An array of String, each element of the array
|
527 | * represents one
|
||
528 | * argument.
|
||
529 | */
|
||
530 | 3654 | fjp | public static void setArguments(String[] arguments) { |
531 | PluginServices.arguments = arguments; |
||
532 | } |
||
533 | 9634 | caballero | |
534 | 8992 | jmvivo | /**
|
535 | 11910 | cesar | * Returns the value of a command line named argument.
|
536 | 8992 | jmvivo | *<br>
|
537 | *<br>
|
||
538 | * The argument format is:
|
||
539 | *<br>
|
||
540 | * -{argumentName}={argumentValue}
|
||
541 | *<br>
|
||
542 | *<br>
|
||
543 | *example:
|
||
544 | * <br>
|
||
545 | * ' -language=en '
|
||
546 | 11910 | cesar | * @return String The value of the argument
|
547 | 15944 | jmvivo | */
|
548 | 9634 | caballero | public static String getArgumentByName(String name) { |
549 | 8990 | jmvivo | for (int i=2; i < PluginServices.arguments.length; i++) |
550 | { |
||
551 | int index = PluginServices.arguments[i].indexOf(name +"="); |
||
552 | if (index != -1) |
||
553 | return PluginServices.arguments[i].substring(index+name.length()+1); |
||
554 | } |
||
555 | return null; |
||
556 | } |
||
557 | 3668 | fjp | |
558 | 11910 | cesar | /**
|
559 | * Gets the logger. The logger is used to register important
|
||
560 | * events (errors, etc), which are stored on a file which
|
||
561 | * can be checked later.
|
||
562 | 15944 | jmvivo | *
|
563 | 11910 | cesar | * @return A Logger object.
|
564 | * @see Logger object from the Log4j library.
|
||
565 | *
|
||
566 | */
|
||
567 | 3668 | fjp | public static Logger getLogger() { |
568 | return logger;
|
||
569 | } |
||
570 | 4419 | azabala | |
571 | public static IAuthentication getAuthentication() { |
||
572 | 4358 | ldiaz | return authentication;
|
573 | } |
||
574 | 4419 | azabala | |
575 | public static void setAuthentication(IAuthentication authen) { |
||
576 | 4358 | ldiaz | authentication = authen; |
577 | } |
||
578 | 5800 | caballero | public static DlgPreferences getDlgPreferences() { |
579 | return DlgPreferences.getInstance();
|
||
580 | } |
||
581 | 8508 | jaume | |
582 | 11910 | cesar | /**
|
583 | 15944 | jmvivo | * Stores the provided text data on the clipboard.
|
584 | *
|
||
585 | 11910 | cesar | * @param data An String containing the data to be stored
|
586 | * on the clipboard.
|
||
587 | */
|
||
588 | 7741 | jmvivo | public static void putInClipboard(String data) { |
589 | StringSelection ss = new StringSelection(data); |
||
590 | |||
591 | Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,ss);
|
||
592 | } |
||
593 | |||
594 | 11910 | cesar | /**
|
595 | * Gets text data from the Clipboard, if available.
|
||
596 | 15944 | jmvivo | *
|
597 | 11910 | cesar | * @return An String containing the clipboard's data, or
|
598 | * <code>null</code>
|
||
599 | * if the data was not available.
|
||
600 | */
|
||
601 | 7741 | jmvivo | public static String getFromClipboard() { |
602 | |||
603 | try {
|
||
604 | return (String)Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null).getTransferData(DataFlavor.stringFlavor); |
||
605 | } catch (UnsupportedFlavorException e) { |
||
606 | return null; |
||
607 | } catch (IOException e) { |
||
608 | // TODO Auto-generated catch block
|
||
609 | return null; |
||
610 | } |
||
611 | } |
||
612 | 9634 | caballero | |
613 | |||
614 | 8990 | jmvivo | /**
|
615 | 11910 | cesar | * Gets the ExclusiveUIExtension, an special extension which
|
616 | * will take
|
||
617 | * control over the UI and will decide which extensions may be
|
||
618 | * enable/disabled or visible/hidden.
|
||
619 | *
|
||
620 | * @return If an ExclusiveUIExtension was set, return this extension.
|
||
621 | * Otherwise, return <code>null</code>.
|
||
622 | 15944 | jmvivo | *
|
623 | 8990 | jmvivo | * @see com.iver.andami.Launcher#initializeExclusiveUIExtension()
|
624 | * @see com.iver.andami.plugins.IExtension#isEnabled(IExtension extension)
|
||
625 | * @see com.iver.andami.plugins.IExtension#isVisible(IExtension extension)
|
||
626 | */
|
||
627 | 11910 | cesar | public static ExclusiveUIExtension getExclusiveUIExtension() { |
628 | 8990 | jmvivo | return PluginServices.exclusiveUIExtension;
|
629 | } |
||
630 | 9634 | caballero | |
631 | 11910 | cesar | /**
|
632 | * Sets the ExclusiveUIExtension, an special extension which
|
||
633 | * will take
|
||
634 | * control over the UI and will decide which extensions may be
|
||
635 | * enable/disabled or visible/hidden.
|
||
636 | * <br><br>
|
||
637 | * The ExclusiveUIExtension is normally set by the following
|
||
638 | * Andami startup argument:
|
||
639 | * <br><br>
|
||
640 | * <code>ExclusiveUIExtension=ExtensionName</code>
|
||
641 | 15944 | jmvivo | *
|
642 | 11910 | cesar | * @see com.iver.andami.Launcher#initializeExclusiveUIExtension()
|
643 | * @see com.iver.andami.plugins.IExtension#isEnabled(IExtension extension)
|
||
644 | * @see com.iver.andami.plugins.IExtension#isVisible(IExtension extension)
|
||
645 | */
|
||
646 | 23987 | vcaballero | public static void setExclusiveUIExtension(ExclusiveUIExtension extension) { |
647 | 8990 | jmvivo | PluginServices.exclusiveUIExtension = extension; |
648 | } |
||
649 | 7741 | jmvivo | |
650 | 9634 | caballero | public static void addLoaders(ArrayList classLoaders) { |
651 | PluginClassLoader.addLoaders(classLoaders); |
||
652 | } |
||
653 | 15944 | jmvivo | |
654 | 13901 | cesar | public static IconThemeManager getIconThemeManager() { |
655 | 15944 | jmvivo | return IconThemeManager.getIconThemeManager();
|
656 | 13793 | cesar | } |
657 | 15944 | jmvivo | |
658 | public static IIconTheme getIconTheme() { |
||
659 | return IconThemeManager.getIconThemeManager().getCurrent();
|
||
660 | 13800 | cesar | } |
661 | 16251 | jmvivo | |
662 | /** Try to detect if the application is running in a development
|
||
663 | * environment.
|
||
664 | * <br>
|
||
665 | * This look for <b>.project</b> and <b>.classpath</b> files in the starts path of the application.
|
||
666 | *
|
||
667 | * @return true if <b>.project</b> and <b>.classpath</b> are in the development path
|
||
668 | */
|
||
669 | public static boolean runningInDevelopment(){ |
||
670 | String andamiPath;
|
||
671 | Properties props = System.getProperties(); |
||
672 | |||
673 | try {
|
||
674 | try {
|
||
675 | andamiPath = (new File(Launcher.class.getResource(".").getFile() + File.separator + ".." + File.separator + ".." + File.separator +".." + File.separator+ "..")).getCanonicalPath(); |
||
676 | } catch (IOException e) { |
||
677 | andamiPath = (new File(Launcher.class.getResource(".").getFile() + File.separator + ".." + File.separator + ".." + File.separator +".."+ File.separator+ "..")).getAbsolutePath(); |
||
678 | } |
||
679 | } catch (Exception e1) { |
||
680 | andamiPath = (String)props.get("user.dir"); |
||
681 | } |
||
682 | |||
683 | File andamiJar = new File(andamiPath + File.separator +"andami.jar"); |
||
684 | if (!andamiJar.exists())
|
||
685 | return false; |
||
686 | File projectFile = new File(andamiPath + File.separator +".project"); |
||
687 | File classpathFile = new File(andamiPath + File.separator +".classpath"); |
||
688 | return projectFile.exists() && classpathFile.exists();
|
||
689 | |||
690 | } |
||
691 | 598 | fernando | } |