Revision 41312

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/resources-application/theme/andami-theme.xml
24 24

  
25 25
-->
26 26
<AndamiProperties>
27
	<ApplicationImages>
28
		<SplashImages>
29
			<Splash
30
				path="splash.png"
31
				timer="10000"
32
				x="225" y="50"
33
				fontsize="16" color="80,170,240"
34
				version="${gvsig.package.info.gvSIGVersion}.${buildNumber} ${gvsig.package.info.state}"/>
35
		</SplashImages>		
36
		<!-- 
37
		<BackgroundImage path="gvsig-icon16x16.png"/>
38
		 -->
39
		<WallpaperType value="CENTERED"/>
40
		<Icon path="gvsig-icon16x16.png"/>
41
	</ApplicationImages>
42
	<ApplicationName value="gvSIG ${gvsig.package.info.gvSIGVersion}.${buildNumber} ${gvsig.package.info.state}"/>
27
    <ApplicationImages>
28
        <SplashImages>
29
            <Splash
30
                path="splash.png"
31
                timer="10000"
32
                x="225" y="50"
33
                fontsize="16" color="80,170,240"
34
                version="${version}.${buildNumber} ${state}"/>
35
        </SplashImages>	
36
        <!--	
37
        <BackgroundImage path="gvsig-proj-black-wallpaper.png"/>
38
        -->
39
        <WallpaperType value="CENTERED"/>
40
        <Icon path="gvsig-icon16x16.png"/>
41
    </ApplicationImages>
42
    <ApplicationName value="gvSIG ${version}.${buildNumber} ${state}"/>
43
    <priority value="0"/>
43 44
</AndamiProperties>
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/ui/theme/Theme.java
68 68
    private static final String TIMER = "timer";
69 69
    private static final String ICON = "Icon";
70 70
    private static final String APPLICATION_NAME = "ApplicationName";
71
    private static final String PRIORITY = "priority";
71 72
    private static final String VALUE = "value";
72 73
    private static final String BACKGROUND_IMAGE = "BackgroundImage";
73 74
    private static final String WALLPAPER_TYPE = "WallpaperType";
......
91 92
    private String name = null;
92 93
    private String backgroundimage;
93 94
    private String wallpaperType = CENTERED;
95
    private int priority = 0;
94 96

  
95 97
    /**
96 98
     * Spurce file of the theme *
......
185 187
                            name = expand(parser.getAttributeValue("", VALUE));
186 188
                            tag = parser.next();
187 189
                        }
190
                        if ( parser.getName().compareTo(PRIORITY) == 0 ) {
191
                            String s = parser.getAttributeValue("", VALUE);
192
                            try {
193
                                this.priority = Integer.parseInt(s);
194
                            } catch(Exception ex) {
195
                                this.priority = 0;
196
                            }
197
                            tag = parser.next();
198
                        }
188 199
                        break;
189 200

  
190 201
                    case XmlPullParser.END_TAG:
......
372 383
        }
373 384
        return strSubstitutor.replace(value);
374 385
    }
386
    
387
    public int getPriority() {
388
        return this.priority;
389
    }
375 390
}
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/Launcher.java
32 32
import java.awt.KeyboardFocusManager;
33 33
import java.awt.Point;
34 34
import java.awt.Toolkit;
35
import java.awt.Window;
36 35
import java.awt.event.ActionEvent;
37 36
import java.awt.event.ActionListener;
38 37
import java.io.BufferedOutputStream;
......
49 48
import java.io.OutputStreamWriter;
50 49
import java.io.Reader;
51 50
import java.io.StringWriter;
52
import java.lang.reflect.InvocationTargetException;
53 51
import java.net.Authenticator;
54 52
import java.net.MalformedURLException;
55 53
import java.net.PasswordAuthentication;
......
64 62
import java.text.MessageFormat;
65 63
import java.util.ArrayList;
66 64
import java.util.Arrays;
65
import java.util.Collections;
67 66
import java.util.Comparator;
68 67
import java.util.Enumeration;
69 68
import java.util.HashMap;
......
76 75
import java.util.Properties;
77 76
import java.util.Set;
78 77
import java.util.TreeSet;
79
import java.util.logging.Level;
80 78
import java.util.prefs.Preferences;
81 79

  
82 80
import javax.swing.ImageIcon;
......
96 94
import org.apache.commons.cli.ParseException;
97 95
import org.apache.commons.cli.PosixParser;
98 96
import org.apache.commons.io.FileUtils;
97
import org.apache.commons.lang3.JavaVersion;
98
import org.apache.commons.lang3.SystemUtils;
99 99
import org.apache.log4j.AppenderSkeleton;
100 100
import org.apache.log4j.PatternLayout;
101 101
import org.apache.log4j.PropertyConfigurator;
......
376 376
				install = true;
377 377
			}
378 378
		}
379

  
379 380
		try {
380 381
			if (install) {
381 382
				launcher.doInstall(args);
......
697 698
		/*
698 699
		 * Executes additional tasks required by plugins
699 700
		 */
700
		PluginsLocator.getManager().executeOnStartupTasks();
701
		PluginsLocator.getManager().executeStartupTasks();
701 702

  
702 703
	}
703 704
	
......
775 776
	 * @throws IOException
776 777
	 * @throws ConfigurationException
777 778
	 */
778
	private void initializeApp(String[] args) throws IOException,
779
			ConfigurationException {
780
		if (!validJVM()) {
781
			System.exit(-1);
782
		}
783

  
784
		// Clean temporal files
785
		Utilities.cleanUpTempFiles();
786

  
779
	private void initializeApp(String[] args) throws IOException, ConfigurationException {
787 780
		if( args.length<1 ) {
788 781
			appName = "gvSIG"; // Nombre de aplicacion por defecto es "gvSIG"
789 782
		} else {
790 783
			appName = args[0];
791 784
		}
792

  
793 785
		getOrCreateConfigFolder();
794

  
795 786
		configureLogging(appName);
787
		if (!validJVM()) {
788
                    logger.error("Not a valid JRE. Exit application.");
789
                    System.exit(-1);
790
		}
791
		// Clean temporal files
792
		Utilities.cleanUpTempFiles();
796 793

  
797 794
		if( args.length<2 ) {
798 795
			loadAndamiConfig("gvSIG/extensiones"); // Valor por defecto 
......
971 968
	 * 
972 969
	 * @return Theme
973 970
	 */
974
	private Theme getTheme(String pluginsDirectory) {
975
            File infoFile = new File(Launcher.getApplicationFolder(),"package.info");
976
            File themeFile = null;
977
            Theme theme = new Theme(loadProperties(infoFile));
971
    private Theme getTheme(String pluginsDirectory) {
972
        File infoFile = new File(Launcher.getApplicationFolder(), "package.info");
973
        File themeFile = null;
974
        List<Theme> themes = new ArrayList<Theme>();
978 975

  
979
		// Try to get theme from args
980
		String name = PluginServices.getArgumentByName("andamiTheme");
981
		if (name != null) {
982
			themeFile = new File(name);
983
			logger.info("search andami-theme in {}", themeFile
984
					.getAbsolutePath());
985
			if (themeFile.exists()) {
986
				theme.readTheme(themeFile);
987
				logger.info("andami-theme found in {}", themeFile
988
						.getAbsolutePath());
989
				return theme;
990
			}
991
		}
976
        // Try to get theme from args
977
        String name = PluginServices.getArgumentByName("andamiTheme");
978
        if ( name != null ) {
979
            themeFile = new File(name);
980
            logger.info("search andami-theme in {}", themeFile.getAbsolutePath());
981
            if ( themeFile.exists() ) {
982
                Theme theme = new Theme(loadProperties(infoFile));
983
                theme.readTheme(themeFile);
984
                logger.info("andami-theme found in {}", themeFile.getAbsolutePath());
985
                return theme;
986
            }
987
        }
992 988

  
993
		// Try to get theme from a plugin
994
		File pluginsDir = new File(pluginsDirectory);
995
		if (!pluginsDir.isAbsolute()) {
996
                    pluginsDir = new File(getApplicationFolder(), pluginsDirectory);
997
		}
998
		if (pluginsDir.exists()) {
999
			logger.info("search andami-theme in plugins folder.");
1000
			File[] pluginDirs = pluginsDir.listFiles();
1001
			if (pluginDirs.length > 0) {
1002
				for (int i = 0; i < pluginDirs.length; i++) {
1003
					File pluginThemeFile = new File(pluginDirs[i], "theme"
1004
							+ File.separator + "andami-theme.xml");
1005
					if (pluginThemeFile.exists()) {
1006
						themeFile = pluginThemeFile;
1007
						// This if is a hack to allow more themes than the
1008
						// one available in org.gvsig.app. Remove this
1009
						// when a the theme format is changed to allow for
1010
						// priorities
1011
						if (!"org.gvsig.app".equals(pluginDirs[i].getName())) {
1012
							break;
1013
						}
1014
					}
1015
				}
1016
			}
1017
		}
989
        // Try to get theme from a plugin
990
        File pluginsDir = new File(pluginsDirectory);
991
        if ( !pluginsDir.isAbsolute() ) {
992
            pluginsDir = new File(getApplicationFolder(), pluginsDirectory);
993
        }
994
        if ( pluginsDir.exists() ) {
995
            logger.info("search andami-theme in plugins folder '"+pluginsDir.getAbsolutePath()+"'.");
996
            File[] pluginDirs = pluginsDir.listFiles();
997
            if ( pluginDirs.length > 0 ) {
998
                for ( int i = 0; i < pluginDirs.length; i++ ) {
999
                    File pluginThemeFile = new File(pluginDirs[i], 
1000
                            "theme" + File.separator + "andami-theme.xml");
1001
                    if ( pluginThemeFile.exists() ) {
1002
                        Theme theme = new Theme(loadProperties(infoFile));
1003
                        theme.readTheme(pluginThemeFile);
1004
                        themes.add(theme);
1005
                    }
1006
                }
1007
            }
1008
        }
1018 1009

  
1019
		// The theme file will be the one into a plugin or by default the one
1020
		// in the org.gvsig.app plugin
1021
		if (themeFile != null && themeFile.exists()) {
1022
			theme.readTheme(themeFile);
1023
			logger.info("andami-theme found in plugin {}", themeFile
1024
					.getAbsolutePath());
1025
			return theme;
1026
		}
1010
        // Try to get theme from dir gvSIG in user home
1011
        themeFile = new File(getAppHomeDir(), "theme" + File.separator
1012
                + "andami-theme.xml");
1013
        logger.info("search andami-theme in user's home {}", themeFile
1014
                .getAbsolutePath());
1015
        if ( themeFile.exists() ) {
1016
            Theme theme = new Theme(loadProperties(infoFile));
1017
            theme.readTheme(themeFile);
1018
            themes.add(theme);
1019
        }
1027 1020

  
1028
		// Try to get theme from dir gvSIG in user home
1029
		themeFile = new File(getAppHomeDir(), "theme" + File.separator
1030
				+ "andami-theme.xml");
1031
		logger.info("search andami-theme in user's home {}", themeFile
1032
				.getAbsolutePath());
1033
		if (themeFile.exists()) {
1034
			theme.readTheme(themeFile);
1035
			logger.info("andami-theme found in user's home {}", themeFile
1036
					.getAbsolutePath());
1037
			return theme;
1038
		}
1021
        // Try to get theme from the instalation dir of gvSIG.
1022
        themeFile = new File(getApplicationDirectory(), "theme"
1023
                + File.separator + "andami-theme.xml");
1024
        logger.info("search andami-theme in installation folder {}", themeFile
1025
                .getAbsolutePath());
1026
        if ( themeFile.exists() ) {
1027
            Theme theme = new Theme(loadProperties(infoFile));
1028
            theme.readTheme(themeFile);
1029
            themes.add(theme);
1030
        }
1039 1031

  
1040
		// Try to get theme from the instalation dir of gvSIG.
1041
		themeFile = new File(getApplicationDirectory(), "theme"
1042
				+ File.separator + "andami-theme.xml");
1043
		logger.info("search andami-theme in installation folder {}", themeFile
1044
				.getAbsolutePath());
1045
		if (themeFile.exists()) {
1046
			theme.readTheme(themeFile);
1047
			logger.info("andami-theme found in instalation folder {}",
1048
					themeFile.getAbsolutePath());
1049
			return theme;
1050
		}
1051
		logger.info("Apply default andami-theme.");
1052
		return theme;
1053
	}
1032
        Collections.sort(themes, new Comparator<Theme>() {
1033
           public int compare(Theme t1, Theme t2) {
1034
                return t2.getPriority()-t1.getPriority();
1035
            }
1036
        });
1037
        if( logger.isInfoEnabled() ) {
1038
            logger.info("Found andami-themes in:");
1039
            for( Theme theme : themes) {
1040
                logger.info(" - "+theme.getPriority()+", "+ theme.getSource().getAbsolutePath());
1041
            }
1042
        }
1043
        Theme theme = themes.get(0);
1044
        logger.info("Using theme '"+theme.getSource()+"'.");
1045
        return theme;
1046
    }
1054 1047

  
1055 1048
	/**
1056
	 * Establece los datos que ten�amos guardados respecto de la configuraci�n
1049
	 * Establece los datos que tengamos guardados respecto de la configuracion
1057 1050
	 * del proxy.
1058 1051
	 */
1059 1052
	private void configureProxy() {
......
1135 1128
	}
1136 1129

  
1137 1130
	private boolean validJVM() {
1138
		char thirdCharacter = System.getProperty("java.version").charAt(2);
1139
		if (thirdCharacter < '4') {
1140
			return false;
1141
		} else {
1142
			return true;
1143
		}
1131
                if( !SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_4)) {
1132
                    logger.warn("gvSIG requires Java version 1.4 or higher.");
1133
                    logger.warn("The Java HOME is '"+SystemUtils.getJavaHome().getAbsolutePath()+"'.");
1134
                    return false;
1135
                }
1136
                if( SystemUtils.isJavaAwtHeadless() ) {
1137
                    logger.warn("The java used by gvSIG does not contain the libraries for access to the graphical interface (AWT-headless)");
1138
                    logger.warn("The Java HOME is '"+SystemUtils.getJavaHome().getAbsolutePath()+"'.");
1139
                    return false;
1140
                }
1141
                return true;
1144 1142
	}
1145 1143

  
1146 1144
	private void loadPluginsPersistence() throws ConfigurationException {
......
3238 3236
		 */
3239 3237
            public void closeAndami() {
3240 3238
                PluginsManager pluginsManager = PluginsLocator.getManager();
3241
                pluginsManager.executeOnShutdownTasks();
3239
                pluginsManager.executeShutdownTasks();
3242 3240

  
3243 3241
                try {
3244 3242
                    saveAndamiConfig();
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/PluginsManager.java
189 189
     * This method allows plugins register task to do before initializacion of
190 190
     * all gvSIG plugins.
191 191
     *
192
     * @param task
193
     * @param in_event_thread
194
     * @param priority
192
     * Task with higher priority value are executed after.
193
     * 
194
     * @param name of the task
195
     * @param task runnable with the code of the task
196
     * @param in_event_thread, true if the task shoul run in the AWT event thread.
197
     * @param priority of the task.
195 198
     */
196
    public void addOnStartupTask(String name, Runnable task, boolean in_event_thread, int priority);
199
    public void addStartupTask(String name, Runnable task, boolean in_event_thread, int priority);
197 200

  
198
    public void addOnShutdownTask(String name, Runnable task, boolean in_event_thread, int priority);
201
    /**
202
     * This method allows plugins register task to do after close the application.
203
     *
204
     * Task with higher priority value are executed after.
205
     * 
206
     * @param name of the task
207
     * @param task runnable with the code of the task
208
     * @param in_event_thread, true if the task shoul run in the AWT event thread.
209
     * @param priority of the task.
210
     */
211
    public void addShutdownTask(String name, Runnable task, boolean in_event_thread, int priority);
199 212

  
200 213
    /**
201
     * This method executes registered to run before the initialization of
214
     * This method executes registered task to run before the initialization of
202 215
     * all plugins.
203 216
     * The tasks are sorted according to the priority and executed in a separated
204 217
     * thread.
205 218
     *
206 219
     */
207
    public void executeOnStartupTasks();
220
    public void executeStartupTasks();
208 221

  
209
    public void executeOnShutdownTasks();
222
    /**
223
     * This method executes registered task to run after the close of the application.
224
     * The tasks are sorted according to the priority and executed in a separated
225
     * thread.
226
     *
227
     */
228
    public void executeShutdownTasks();
210 229

  
211 230
}
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/impl/DefaultPluginsManager.java
75 75
        public void run() {
76 76
            if ( this.in_event_thread ) {
77 77
                if ( !SwingUtilities.isEventDispatchThread() ) {
78
                    SwingUtilities.invokeLater(new Runnable() {
79
                        public void run() {
80
                            try {
81
                                task.run();
82
                            } catch(Exception ex) {
83
                                logger.warn("Errors in execution of "+type+" task '"+name+"'.",ex);
78
                    try {
79
                        SwingUtilities.invokeAndWait(new Runnable() {
80
                            public void run() {
81
                                Task.this.run();
84 82
                            }
85
                        }
86
                    });
83
                        });
84
                    } catch (InterruptedException ex) {
85
                        // Do nothing
86
                    } catch (Exception ex) {
87
                       logger.warn("Errors in execution of "+type+" task '"+name+"'.",ex);
88

  
89
                    }
87 90
                    return;
88 91
                }
89 92
            }
93
            logger.info("Running "+type+" task '"+name+"' (priority "+priority+").");
90 94
            try {
91 95
                task.run();
92 96
            } catch(Exception ex) {
......
121 125
	 *  
122 126
	 */
123 127
	public PluginServices getPlugin(Class<? extends IExtension> extension) {
124
	    String pluginName = ((PluginClassLoader)extension.getClassLoader()).getPluginName();
125
		return  this.getPlugin(pluginName);
128
            String pluginName = ((PluginClassLoader)extension.getClassLoader()).getPluginName();
129
            return  this.getPlugin(pluginName);
126 130
	}
127 131

  
128 132
	public PluginServices getPlugin(Object obj) {
129 133
            if( obj instanceof IExtension ) {
130
                return this.getPlugin(obj.getClass());
134
                Class<? extends IExtension> klass = (Class<? extends IExtension>) obj.getClass();
135
                return this.getPlugin(klass);
131 136
            }
132 137
            PluginClassLoader loader = (PluginClassLoader) obj.getClass().getClassLoader();
133 138
            String pluginName = loader.getPluginName();
......
249 254
        return Launcher.getApplicationHomeFolder();
250 255
    }
251 256

  
252
    public void addOnStartupTask(String name, Runnable task, boolean in_event_thread, int priority) {
257
    public void addStartupTask(String name, Runnable task, boolean in_event_thread, int priority) {
253 258
        this.onStartupTasks.add( new Task("startup", name, task, in_event_thread, priority));
254 259
    }
255 260

  
256
    public void addOnShutdownTask(String name, Runnable task, boolean in_event_thread, int priority) {
261
    public void addShutdownTask(String name, Runnable task, boolean in_event_thread, int priority) {
257 262
        this.onShutdownTasks.add( new Task("shutdown",name, task, in_event_thread, priority));
258 263
    }
259 264

  
260
    public void executeOnStartupTasks() {
265
    public void executeStartupTasks() {
261 266
        logger.info("Executing startup tasks.");
262 267
        Thread th = new Thread(new Runnable() {
263 268
            public void run() {
......
267 272
                    // Ignore error
268 273
                }
269 274
                Collections.sort(onStartupTasks);
270
                for ( Task task : onStartupTasks ) {
275
                for( int i=onStartupTasks.size()-1; i>=0; i--) {
276
                    Task task = onStartupTasks.get(i);
271 277
                    task.run();
272 278
                }
273 279
            }
......
275 281
        th.start();
276 282
    }
277 283
    
278
    public void executeOnShutdownTasks() {
284
    public void executeShutdownTasks() {
279 285
        logger.info("Executing shutdown tasks.");
280 286
        Collections.sort(onShutdownTasks);
281
        for ( Task task : onShutdownTasks ) {
287
        for( int i=onShutdownTasks.size()-1; i>=0; i--) {
288
            Task task = onShutdownTasks.get(i);
282 289
            task.run();
283 290
        }
284 291
    }
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/resources-plugin/theme/andami-theme.xml
24 24

  
25 25
-->
26 26
<AndamiProperties>
27
	<ApplicationImages>
28
		<SplashImages>
29
			<Splash
30
				path="splash.png"
31
				timer="10000"
32
				x="225" y="50"
33
				fontsize="16" color="80,170,240"
34
				version="${version}.${buildNumber} ${state}"/>
35
		</SplashImages>		
36
		<!-- 
37
		<BackgroundImage path="gvsig-icon16x16.png"/>
38
		 -->
39
		<WallpaperType value="CENTERED"/>
40
		<Icon path="gvsig-icon16x16.png"/>
41
	</ApplicationImages>
42
	<ApplicationName value="gvSIG ${version}.${buildNumber} ${state}"/>
27
    <ApplicationImages>
28
        <SplashImages>
29
            <Splash
30
                path="splash.png"
31
                timer="10000"
32
                x="225" y="50"
33
                fontsize="16" color="80,170,240"
34
                version="${version}.${buildNumber} ${state}"/>
35
        </SplashImages>		
36
        <!-- 
37
        <BackgroundImage path="gvsig-proj-black-wallpaper.png"/>
38
        -->
39
        <WallpaperType value="CENTERED"/>
40
        <Icon path="gvsig-icon16x16.png"/>
41
    </ApplicationImages>
42
    <ApplicationName value="gvSIG ${version}.${buildNumber} ${state}"/>
43
    <priority value="100"/>
43 44
</AndamiProperties>
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/resources-plugin/config.xml
70 70
      priority="99999">
71 71
    </extension>
72 72

  
73
    <extension class-name="org.gvsig.app.extension.OpenInitialProjectExtension"
74
      description="Open initial project"
75
      active="true"
76
      priority="1">
77
    </extension>
78

  
79 73
    <extension class-name="org.gvsig.app.extension.ProjectExtension"
80 74
      description="Extensi?n encargada de gestionar los proyectos."
81 75
      active="true"
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1 1
org.gvsig.app.ApplicationLibrary
2
org.gvsig.app.imp.AppgvSIGDefaultImplLibrary
2
org.gvsig.app.imp.ApplicationLibraryImpl
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/OpenInitialProjectExtension.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.app.extension;
25

  
26
import java.io.File;
27

  
28
import org.slf4j.Logger;
29
import org.slf4j.LoggerFactory;
30

  
31
import org.gvsig.andami.PluginServices;
32
import org.gvsig.andami.PluginsLocator;
33
import org.gvsig.andami.plugins.Extension;
34
import org.gvsig.app.project.Project;
35

  
36
/**
37
 * This class simply adds a task to the list of additional
38
 * tasks to be executed by the plugins manager. The task consists
39
 * in opening the project found in the parameters list.
40
 * 
41
 * The Launcher will call the correct method to start the tasks
42
 * after all plugins have been loaded
43
 * 
44
 * @author jldominguez
45
 *
46
 */
47
public class OpenInitialProjectExtension extends Extension {
48

  
49
    private static final Logger LOG = LoggerFactory
50
        .getLogger(OpenInitialProjectExtension.class);
51
            
52
    public void initialize() {
53
        PluginsLocator.getManager().addOnStartupTask(
54
            "Open project",
55
            new OpenInitialProjectTask(), true, 0);
56
    }
57

  
58
    public void execute(String actionCommand) {
59
    }
60

  
61
    public boolean isEnabled() {
62
        return false;
63
    }
64

  
65
    public boolean isVisible() {
66
        return false;
67
    }
68
    
69
    
70
    
71
    
72
    private class OpenInitialProjectTask implements Runnable {
73

  
74
        public void run() {
75
            
76
            File pf = getInitialProjectFile();
77
            if (pf != null) {
78
                
79
                ProjectExtension pext = null;
80
                pext = (ProjectExtension)
81
                    PluginsLocator.getManager().getExtension(ProjectExtension.class);
82
                
83
                Object[] args = new Object[1];
84
                args[0] = pf;
85
                pext.execute("application-project-open", args);
86
            } else {
87
                LOG.info("No initial file opened.");
88
            }            
89
        }
90
        
91
        
92
        /**
93
         * Returns file to be opened or null if no parameter
94
         * or file does not exist
95
         * 
96
         * @return
97
         */
98
        private File getInitialProjectFile() {
99
            String[] theArgs = PluginServices.getArguments();
100
            String lastArg = theArgs[theArgs.length - 1];
101
            if (lastArg != null) {
102
                if (lastArg.toLowerCase().endsWith(
103
                        Project.FILE_EXTENSION.toLowerCase())) {
104

  
105
                    File projectFile = new File(lastArg);
106
                    if (projectFile.exists()) {
107
                        return projectFile;
108
                    } else {
109
                        LOG.info("initial file des not exist: " + lastArg);
110
                        return null;
111
                    }
112
                } else {
113
                    LOG.info("Parameter (initial project file) does " +
114
                    		"not have expected extension (*" + Project.FILE_EXTENSION +
115
                    		"): " + lastArg);
116
                }
117
            }
118
            return null;
119
            
120
        }   
121
        
122
    }
123

  
124
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/ProjectExtension.java
25 25

  
26 26
import java.awt.Component;
27 27
import java.io.File;
28
import java.lang.reflect.InvocationTargetException;
29 28
import java.text.MessageFormat;
30 29
import java.util.ArrayList;
31 30
import java.util.Iterator;
......
37 36

  
38 37
import org.slf4j.Logger;
39 38
import org.slf4j.LoggerFactory;
40
import org.apache.commons.io.FilenameUtils;
39
import org.gvsig.tools.util.ArrayUtils;
40
import org.apache.commons.lang.StringUtils;
41 41
import org.gvsig.andami.IconThemeHelper;
42 42
import org.gvsig.andami.Launcher;
43 43
import org.gvsig.andami.Launcher.TerminationProcess;
44 44
import org.gvsig.andami.PluginServices;
45
import org.gvsig.andami.PluginsLocator;
46
import org.gvsig.andami.actioninfo.ActionInfo;
47
import org.gvsig.andami.actioninfo.ActionInfoManager;
45 48
import org.gvsig.andami.messages.NotificationManager;
46 49
import org.gvsig.andami.plugins.Extension;
47 50
import org.gvsig.andami.plugins.IExtension;
......
51 54
import org.gvsig.andami.ui.mdiManager.IWindow;
52 55
import org.gvsig.andami.ui.mdiManager.WindowInfo;
53 56
import org.gvsig.andami.ui.wizard.UnsavedDataPanel;
54
import org.gvsig.app.ApplicationLocator;
55
import org.gvsig.app.ApplicationManager;
56 57
import org.gvsig.app.project.Project;
57 58
import org.gvsig.app.project.ProjectManager;
58 59
import org.gvsig.app.project.documents.gui.ProjectWindow;
59 60
import org.gvsig.app.project.documents.view.ViewManager;
60 61
import org.gvsig.gui.beans.swing.JFileChooser;
61 62
import org.gvsig.tools.ToolsLocator;
63
import org.gvsig.tools.dataTypes.DataTypes;
62 64
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
63 65
import org.gvsig.tools.persistence.exception.PersistenceException;
64 66
import org.gvsig.utils.GenericFileFilter;
......
66 68
import org.gvsig.utils.save.BeforeSavingListener;
67 69
import org.gvsig.utils.save.SaveEvent;
68 70
import org.gvsig.utils.swing.threads.IMonitorableTask;
71
import sun.misc.Launcher;
69 72

  
70 73
/**
71 74
 * Extension que proporciona controles para crear proyectos nuevos, abrirlos y
......
99 102

  
100 103
	private List<AfterSavingListener> afterSavingListeners = new ArrayList<AfterSavingListener>();
101 104

  
102
	/**
103
	 * @see com.iver.mdiApp.plugins.IExtension#initialize()
104
	 */
105
	public void initialize() {
106
		// try {
107
		// Class.forName("javax.media.jai.EnumeratedParameter");
108
		// } catch (ClassNotFoundException e) {
109
		// NotificationManager
110
		// .addError(
111
		// "La m?quina virtual con la que se ejecuta gvSIG no tiene JAI instalado",
112
		// e);
113
		// }
105
        public void initialize() {
106
            initializeDocumentActionsExtensionPoint();
107
            registerDocuments();
108
            registerIcons();
109
            PluginsLocator.getManager().addStartupTask(
110
                    "Open project",
111
                    new OpenInitialProjectTask(), true, 1000);
112
        }
114 113

  
115
		initializeDocumentActionsExtensionPoint();
116
		registerDocuments();
117
		registerIcons();
118
	}
119

  
120 114
	private void registerIcons() {
121 115
		IconThemeHelper.registerIcon("action", "application-project-new", this);
122 116
		IconThemeHelper
......
129 123
		IconThemeHelper.registerIcon("project", "project-icon", this);
130 124
	}
131 125

  
126
        private class OpenInitialProjectTask implements Runnable {
127
            public void run() {
128
                File pf = getInitialProjectFile();
129
                if (pf == null) {
130
                    LOG.info("No initial file opened.");
131
                    return;
132
                }
133
                ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
134
                ActionInfo action = actionManager.getAction("application-project-open");
135
                action.execute(pf);
136
            }
137
            /**
138
             * Returns the file to be opened or null if no parameter
139
             * or file does not exist
140
             * 
141
             * @return
142
             */
143
            private File getInitialProjectFile() {
144
                String[] theArgs = PluginServices.getArguments();
145
                String lastArg = theArgs[theArgs.length - 1];
146
                if ( StringUtils.isEmpty(lastArg) ) {
147
                    return null;
148
                }
149
                if( lastArg.startsWith("-") ) {
150
                    return null;
151
                }
152
                if (!lastArg.toLowerCase().endsWith(Project.FILE_EXTENSION.toLowerCase())) {
153
                    LOG.info("Do not open project file, does not have the expected extension '" + 
154
                            Project.FILE_EXTENSION +"' ("+lastArg+").");
155
                    return null;
156
                }
157
                File projectFile = new File(lastArg);
158
                if ( !projectFile.exists()) {
159
                    LOG.info("Do not open project file, '" +projectFile.getAbsolutePath() + "' do not exist.");
160
                    return null;
161
                }
162
                return projectFile;
163
            }   
164
        }
132 165

  
133

  
134

  
135

  
136 166
	public ProjectWindow getProjectFrame() {
137 167
		if (projectFrame == null) {
138 168
			projectFrame = new ProjectWindow();
......
262 292
	public void execute(String command) {
263 293
		this.execute(command, null);
264 294
	}
265

  
295
        
266 296
	public void execute(String actionCommand, Object[] args) {
267 297
		if (actionCommand.equals("application-project-new")) {
268 298
			if (!askSave()) {
......
270 300
			}
271 301

  
272 302
			projectPath = null;
273
			// ProjectDocument.initializeNUMS();
274 303
			PluginServices.getMDIManager().closeAllWindows();
275 304
			setProject(ProjectManager.getInstance().createProject());
276 305
			getProjectFrame().setProject(p);
277 306
			showProjectWindow();
278 307
			PluginServices.getMainFrame().setTitle(
279 308
					PluginServices.getText(this, "sin_titulo"));
280
		} else if (actionCommand.equals("application-project-open")) {
309

  
310
                } else if (actionCommand.equals("application-project-open")) {
281 311
			if (!askSave()) {
282 312
				return;
283 313
			}
284
			File projectFile = null;
314
                        File projectFile = (File) ArrayUtils.get(args, 0, DataTypes.FILE);
315
                        if ( projectFile != null && !projectFile.exists() ) {
316
                            LOG.warn("Can't load project '"
317
                                    + projectFile.getAbsolutePath()
318
                                    + "', file not exist.");
319
                            projectFile = null;
320
                        }
285 321

  
286
			if (args != null && args.length > 0 && args[0] != null) {
287
				if (args[0] instanceof File) {
288
					projectFile = (File) args[0];
289
				} else if (args[0] instanceof String) {
290
					projectFile = new File((String) args[0]);
291
					if (!projectFile.exists()) {
292
						LOG.warn("Can't load project '"
293
								+ projectFile.getAbsolutePath()
294
								+ "', file not exist.");
295
						projectFile = null;
296
					}
297
				}
298
			}
299

  
300 322
			if (projectFile == null) {
301 323
				Preferences prefs = Preferences.userRoot().node(
302 324
						"gvsig.foldering");
......
334 356
		} else if (actionCommand.equals("application-project-save")) {
335 357
			saveProject();
336 358
		} else if (actionCommand.equals("application-project-save-as")) {
337
			File file = null;
338
			if (args != null && args.length > 0 && args[0] != null) {
339
				if (args[0] instanceof File) {
340
					file = (File) args[0];
341
				} else if (args[0] instanceof String) {
342
					file = new File((String) args[0]);
343
				}
344
			}
359
			File file = (File) ArrayUtils.get(args, 0, DataTypes.FILE);
345 360
			saveAsProject(file);
346 361
		}
347 362

  
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/imp/AppgvSIGDefaultImplLibrary.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
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2009 {DiSiD Technologies}  {{Task}}
27
 */
28
package org.gvsig.app.imp;
29

  
30
import org.gvsig.app.ApplicationLibrary;
31
import org.gvsig.app.ApplicationLocator;
32
import org.gvsig.installer.lib.api.InstallerLibrary;
33
import org.gvsig.tools.library.AbstractLibrary;
34
import org.gvsig.tools.library.LibraryException;
35

  
36
/**
37
 * Registers the default implementation for the AppGvSigManager.
38
 * @author <a href="mailto:cordinyana@gvsig.org">C?sar Ordi?ana</a>
39
 */
40
public class AppgvSIGDefaultImplLibrary extends AbstractLibrary {
41

  
42
    @Override
43
    public void doRegistration() {
44
        registerAsImplementationOf(ApplicationLibrary.class);
45
        require(InstallerLibrary.class);
46
    }
47

  
48
	@Override
49
	protected void doInitialize() throws LibraryException {
50
		ApplicationLocator
51
				.registerDefaultAppgvSIGManager(DefaultAppgvSIGManager.class);
52
	}
53

  
54
	@Override
55
	protected void doPostInitialize() throws LibraryException {
56
		// do nothing
57
	}
58

  
59
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/imp/DefaultAppgvSIGManager.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

  
25
package org.gvsig.app.imp;
26

  
27
import java.awt.Component;
28
import java.io.File;
29
import java.util.ArrayList;
30
import java.util.Iterator;
31
import java.util.List;
32
import javax.swing.JComponent;
33

  
34
import javax.swing.JFileChooser;
35
import javax.swing.filechooser.FileFilter;
36

  
37
import org.cresques.cts.IProjection;
38
import org.gvsig.about.AboutLocator;
39
import org.gvsig.about.AboutManager;
40
import org.gvsig.andami.Launcher;
41
import org.gvsig.andami.PluginServices;
42
import org.gvsig.andami.actioninfo.ActionInfo;
43
import org.gvsig.andami.ui.mdiFrame.MainFrame;
44
import org.gvsig.andami.ui.mdiManager.IWindow;
45
import org.gvsig.andami.ui.mdiManager.MDIManager;
46
import org.gvsig.app.ApplicationManager;
47
import org.gvsig.app.PreferencesNode;
48
import org.gvsig.app.extension.Version;
49
import org.gvsig.app.gui.WizardPanel;
50
import org.gvsig.app.prepareAction.PrepareContext;
51
import org.gvsig.app.prepareAction.PrepareContextView;
52
import org.gvsig.app.prepareAction.PrepareDataStore;
53
import org.gvsig.app.prepareAction.PrepareDataStoreParameters;
54
import org.gvsig.app.prepareAction.PrepareLayer;
55
import org.gvsig.app.project.DefaultProject;
56
import org.gvsig.app.project.Project;
57
import org.gvsig.app.project.ProjectManager;
58
import org.gvsig.app.project.documents.Document;
59
import org.gvsig.app.project.documents.gui.IDocumentWindow;
60
import org.gvsig.app.project.documents.view.ViewDocument;
61
import org.gvsig.fmap.crs.CRSFactory;
62
import org.gvsig.fmap.dal.DALLocator;
63
import org.gvsig.fmap.dal.DataManager;
64
import org.gvsig.fmap.dal.DataStore;
65
import org.gvsig.fmap.dal.DataStoreParameters;
66
import org.gvsig.fmap.geom.GeometryLocator;
67
import org.gvsig.fmap.geom.GeometryManager;
68
import org.gvsig.fmap.mapcontext.MapContextLocator;
69
import org.gvsig.fmap.mapcontext.MapContextManager;
70
import org.gvsig.fmap.mapcontext.layers.FLayer;
71
import org.gvsig.gui.ColorTablesFactory;
72
import org.gvsig.symbology.swing.SymbologySwingLocator;
73
import org.gvsig.tools.ToolsLocator;
74
import org.gvsig.tools.dataTypes.DataTypesManager;
75
import org.gvsig.tools.dispose.DisposableManager;
76
import org.gvsig.tools.dynobject.DynObjectManager;
77
import org.gvsig.tools.extensionpoint.ExtensionPoint;
78
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension;
79
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
80
import org.gvsig.tools.persistence.PersistenceManager;
81
import org.gvsig.tools.swing.api.ToolsSwingLocator;
82
import org.gvsig.tools.swing.icontheme.IconThemeManager;
83
import org.slf4j.Logger;
84
import org.slf4j.LoggerFactory;
85

  
86

  
87

  
88

  
89
/**
90
 * @author jmvivo
91
 *
92
 */
93
public class DefaultAppgvSIGManager implements ApplicationManager {
94

  
95
    @SuppressWarnings("unused")
96
	private static Logger logger = LoggerFactory.getLogger(DefaultAppgvSIGManager.class);
97
    
98
	private static final String EPNAME_PREPARE_OPEN_DATASTORE = "org.gvsig.datastore.open.prepare"; //"PrepareOpenDataStore";
99
	private static final String EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS = "org.gvsig.datastoreparameters.open.prepare"; //"PrepareOpenDataStoreParameters";
100
	private static final String EPNAME_PREPARE_OPEN_LAYER = "org.gvsig.layer.open.prepare"; // "PrepareOpenLayer";
101

  
102
	private static final String EPNAME_ADD_TABLE_WIZARD = "AddLayerWizard";
103

  
104
	private ExtensionPointManager epManager;
105

  
106
    private Version version;
107

  
108
	public DefaultAppgvSIGManager() {
109
		epManager = ToolsLocator.getExtensionPointManager();
110
		epManager.add(EPNAME_PREPARE_OPEN_DATASTORE,
111
				"Actions to do when open a DataStore");
112
		epManager.add(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS,
113
				"Actions to do before open a DataStore with parameters");
114
		epManager.add(EPNAME_PREPARE_OPEN_LAYER,
115
			"Actions to do after create a Layer");
116
		epManager.add(EPNAME_ADD_TABLE_WIZARD,
117
				"Wizards to add new document table");
118

  
119
        version = new Version();
120
	}
121

  
122
	/* (non-Javadoc)
123
	 * @see org.gvsig.appGvSigManager#pepareOpenDataSource(org.gvsig.fmap.dal.DataStore)
124
	 */
125
	@SuppressWarnings("unchecked")
126
	public DataStore pepareOpenDataSource(DataStore store,
127
			PrepareContext context) throws Exception {
128
		ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_DATASTORE);
129
		if (ep.getCount() == 0) {
130
			return store;
131
		}
132
		DataStore result = store;
133
		Iterator<ExtensionPoint.Extension> iter = ep.iterator();
134
		PrepareDataStore prepare;
135
		while (iter.hasNext()) {
136
			prepare = (PrepareDataStore) iter.next().create();
137
			result = prepare.prepare(store, context);
138
		}
139
		return result;
140
	}
141

  
142
	/* (non-Javadoc)
143
	 * @see org.gvsig.appGvSigManager#prepareOpenDataStoreParameters(org.gvsig.fmap.dal.DataStoreParameters)
144
	 */
145
	@SuppressWarnings("unchecked")
146
	public DataStoreParameters prepareOpenDataStoreParameters(
147
			DataStoreParameters storeParameters, PrepareContext context)
148
			throws Exception {
149

  
150
		ExtensionPoint ep = epManager
151
				.get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS);
152
		if (ep.getCount() == 0) {
153
			return storeParameters;
154
		}
155
		DataStoreParameters result = storeParameters;
156
		Iterator<ExtensionPoint.Extension> iter = ep.iterator();
157
		PrepareDataStoreParameters prepare;
158
		while (iter.hasNext()) {
159
			prepare = (PrepareDataStoreParameters) iter.next().create();
160
			result = prepare.prepare(storeParameters, context);
161
		}
162

  
163
		return result;
164
	}
165
	
166
	/*
167
	 * (non-Javadoc)
168
	 * @see org.gvsig.app.ApplicationManager#prepareOpenDataStoreParameters(java.util.List, org.gvsig.app.prepareAction.PrepareContext)
169
	 */
170
	@SuppressWarnings("unchecked")
171
	public List<DataStoreParameters> prepareOpenDataStoreParameters(
172
			List<DataStoreParameters> storeParameters, PrepareContext context)
173
			throws Exception {
174

  
175
		ExtensionPoint ep = epManager
176
				.get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS);
177
		if (ep.getCount() == 0) {
178
			return storeParameters;
179
		}
180
		
181
		List<DataStoreParameters> result = new ArrayList<DataStoreParameters>();
182
		
183
		Iterator<ExtensionPoint.Extension> iter = ep.iterator();
184
		List<PrepareDataStoreParameters> prepareList = new ArrayList<PrepareDataStoreParameters>();
185
		while (iter.hasNext()) {
186
			prepareList.add((PrepareDataStoreParameters) iter.next().create());
187
		}
188
		
189
		for (int i = 0; i < storeParameters.size(); i++) {
190
			DataStoreParameters param = storeParameters.get(i);
191
			for (int j = 0; j < prepareList.size(); j++) {
192
				prepareList.get(j).pre(param, context);
193
			}
194
		}
195
		
196
		for (int i = 0; i < storeParameters.size(); i++) {
197
			DataStoreParameters param = storeParameters.get(i);
198
			if(param != null) {
199
				for (int j = 0; j < prepareList.size(); j++) {
200
					param = prepareList.get(j).prepare(param, context);
201
					if(param == null)
202
						break;
203
				}
204
				if(param != null)
205
					result.add(param);
206
			}
207
		}
208
		
209
		for (int i = 0; i < storeParameters.size(); i++) {
210
			DataStoreParameters param = storeParameters.get(i);
211
			for (int j = 0; j < prepareList.size(); j++) {
212
				prepareList.get(j).post(param, context);
213
			}
214
		}
215

  
216
		return result;
217
	}
218

  
219
	public void registerPrepareOpenDataStore(PrepareDataStore action) {
220
		ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_DATASTORE);
221
		ep.append(action.getName(), action.getDescription(), action);
222
	}
223

  
224
	public void registerPrepareOpenDataStoreParameters(
225
			PrepareDataStoreParameters action) {
226
		ExtensionPoint ep = epManager
227
				.get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS);
228
		ep.append(action.getName(), action.getDescription(), action);
229

  
230

  
231
	}
232

  
233
	@SuppressWarnings("unchecked")
234
	public FLayer prepareOpenLayer(FLayer layer,
235
			PrepareContextView context)
236
			throws Exception {
237

  
238
		ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_LAYER);
239

  
240
		if (ep.getCount() == 0) {
241
			return layer;
242
		}
243
		FLayer result = layer;
244
		Iterator<ExtensionPoint.Extension> iter = ep.iterator();
245
		PrepareLayer prepare;
246
		while (iter.hasNext()) {
247
			prepare = (PrepareLayer) iter.next().create();
248
			result = prepare.prepare(result, context);
249
		}
250

  
251
		return result;
252

  
253
	}
254

  
255
	public void registerPrepareOpenLayer(PrepareLayer action) {
256
		ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_LAYER);
257
		ep.append(action.getName(), action.getDescription(), action);
258
	}
259

  
260
	public void registerAddTableWizard(String name, String description,
261
			Class<? extends WizardPanel> wpClass) {
262
		ExtensionPoint ep = epManager.get(EPNAME_ADD_TABLE_WIZARD);
263
		ep.append(name, description, wpClass);
264
	}
265

  
266
	@SuppressWarnings("unchecked")
267
	public List<WizardPanel> getWizardPanels() throws Exception {
268
		ExtensionPoint ep = epManager.get(EPNAME_ADD_TABLE_WIZARD);
269
		List<WizardPanel> result = new ArrayList<WizardPanel>();
270
		Iterator<Extension> iter = ep.iterator();
271
		while (iter.hasNext()) {
272
			result.add((WizardPanel) iter.next().create());
273
		}
274
		return result;
275
	}
276

  
277
	public DataManager getDataManager() {
278
		return DALLocator.getDataManager();
279
	}
280

  
281
	public GeometryManager getGeometryManager() {
282
		return GeometryLocator.getGeometryManager();
283
	}
284

  
285
	public PersistenceManager getPersistenceManager() {
286
		return ToolsLocator.getPersistenceManager();
287
	}
288

  
289
	public DisposableManager getDisposableManager() {
290
		return ToolsLocator.getDisposableManager();
291
	}
292

  
293
	public DynObjectManager getDynObjectManager() {
294
		return ToolsLocator.getDynObjectManager();
295
	}
296

  
297
	public ExtensionPointManager getExtensionPointManager() {
298
		return ToolsLocator.getExtensionPointManager();
299
	}
300

  
301
	public ProjectManager getProjectManager() {
302
		return ProjectManager.getInstance();
303
	}
304

  
305
	public MDIManager getUIManager() {
306
		return PluginServices.getMDIManager();
307
	}
308

  
309
	public MapContextManager getMapContextManager() {
310
		return MapContextLocator.getMapContextManager();
311
	}
312

  
313
	public DataTypesManager getDataTypesManager() {
314
		return ToolsLocator.getDataTypesManager();
315
	}
316
	
317
	public IProjection getCRS(String code) {
318
		return CRSFactory.getCRS(code);
319
	}
320

  
321
	public IconThemeManager getIconThemeManager() {
322
		return ToolsSwingLocator.getIconThemeManager();
323
	}
324

  
325
	public String getArgument(String name) {
326
		return PluginServices.getArgumentByName(name);
327
	}
328

  
329
	public String[] getArguments() {
330
		return PluginServices.getArguments();
331
	}
332

  
333
	public String getFromClipboard() {
334
		return PluginServices.getFromClipboard();
335
	}
336

  
337
	public void putInClipboard(String data) {
338
		PluginServices.putInClipboard(data);
339
	}
340

  
341
	public Project getCurrentProject() {
342
		return ProjectManager.getInstance().getCurrentProject();
343
	}
344

  
345
	public PreferencesNode getPreferences(String node) {
346
		if( node.equalsIgnoreCase("project")) {
347
			return DefaultProject.getPreferences();
348
		}
349
		return new DefaultPreferencesNode(node);
350
	}
351

  
352
	public PreferencesNode getPreferences() {
353
		return new DefaultPreferencesNode();
354
	}
355

  
356
	public Version getVersion() {
357
        return version;
358
	}
359
	
360
	public AboutManager getAbout() {
361
		AboutManager manager = AboutLocator.getManager();
362
		return manager;
363
	}
364

  
365
	public ColorTablesFactory getColorTablesFactory() {
366
		return SymbologySwingLocator.getSwingManager().getColorTablesFactory();
367
	}
368

  
369
	public void registerColorTablesFactory(ColorTablesFactory factory) {
370
		SymbologySwingLocator.getSwingManager().setColorTablesFactory(factory);
371
		
372
	}
373

  
374
    public IWindow getActiveWindow() {
375
        try {
376
            IWindow window = PluginServices.getMDIManager().getActiveWindow();
377
            return window;
378
        } catch (Exception ex) {
379
            return null;
380
        }
381
    }
382

  
383
    public Document getActiveDocument() {
384
    	return this.getActiveDocument((Class<? extends Document>)null);
385
    }
386
    
387
    public Document getActiveDocument(String documentTypeName) {
388
        Document document = this.getActiveDocument();
389
        if( document!= null && document.getTypeName().equalsIgnoreCase(documentTypeName) ) {
390
            return document;
391
        }
392
        return null;
393
    }
394
    
395
    public Document getActiveDocument(Class<? extends Document> documentClass) {
396
        Project project = this.getCurrentProject();
397
        if( project == null ) {
398
            return null;
399
        }
400
        return project.getActiveDocument(documentClass);
401
    }
402

  
403
    public JComponent getActiveComponent(Class<? extends Document> documentClass) {
404
        Document document = this.getActiveDocument(documentClass);
405
        if (document == null) {
406
            return null;
407
        }
408
        return document.getMainComponent();
409
    }
410
    
411
   
412
    public IDocumentWindow getDocumentWindow(Document document) {
413
        Class<? extends IDocumentWindow> defaultDocumentClass =
414
            document.getFactory().getMainWindowClass();
415
        return (IDocumentWindow) this.getUIManager().getSingletonWindow(defaultDocumentClass, document);
416
    }
417

  
418
	public String getLocaleLanguage() {
419
		return Launcher.getAndamiConfig().getLocaleLanguage();
420
	}
421

  
422
	public void message(String message, int message_type) {
423
		MainFrame main = PluginServices.getMainFrame();
424
		main.message(message, message_type);
425
	}
426

  
427
	public void messageDialog(String message, String title, int messageType) {
428
		MainFrame main = PluginServices.getMainFrame();
429
		main.messageDialog(message, title, messageType);
430
	}
431

  
432
	public void messageDialog(String message, String[] messageArgs,
433
			String title, int messageType) {
434
		MainFrame main = PluginServices.getMainFrame();
435
		main.messageDialog(message, messageArgs, title, messageType);
436
	}
437

  
438
	public int confirmDialog(String message, String title, int optionType,
439
			int messageType) {
440
		MainFrame main = PluginServices.getMainFrame();
441
		return main.confirmDialog(message, title, optionType, messageType);
442
	}
443

  
444
	public String inputDialog(String message, String title, int messageType,
445
			String initialValue) {
446
		MainFrame main = PluginServices.getMainFrame();
447
		return main.inputDialog(message, title, messageType, initialValue);
448
	}
449

  
450
	public String inputDialog(String message, String title) {
451
		MainFrame main = PluginServices.getMainFrame();
452
		return main.inputDialog(message, title);
453
	}
454

  
455
	public void showDialog(Component contents, String title) {
456
		MainFrame main = PluginServices.getMainFrame();
457
		main.showDialog(contents, title);
458
	}
459

  
460
	public Component createComponent(Class<? extends Component> theClass,
461
			Object... parameters) {
462
		MainFrame main = PluginServices.getMainFrame();
463
		return main.createComponentWithParams(theClass, parameters);
464
	}
465

  
466
	public Component createComponentWithParams(
467
			Class<? extends Component> theClass, Object[] parameters) {
468
		MainFrame main = PluginServices.getMainFrame();
469
		return main.createComponentWithParams(theClass, parameters);
470
	}
471

  
472

  
473
	public File[] showChooserDialog(
474
			final String title,
475
			final int type, // SAVE_DIALOG / OPEN_DIALOG
476
			final int selectionMode, //    JFileChooser.FILES_ONLY, JFileChooser.DIRECTORIES_ONLY, JFileChooser.FILES_AND_DIRECTORIES
477
			final boolean multiselection, 
478
			final File initialPath,
479
			final FileFilter filter,
480
			final boolean fileHidingEnabled
481
			) {
482
		MainFrame main = PluginServices.getMainFrame();
483
		return main.showChooserDialog(title, type, selectionMode, multiselection, initialPath, filter, fileHidingEnabled);
484
	}
485
	
486
	public File[] showOpenDirectoryDialog(String title, File initialPath) {
487
		return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.DIRECTORIES_ONLY, false, initialPath, null, false);
488
	}
489

  
490
	
491
	public File[] showOpenFileDialog(String title, File initialPath) {
492
		return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false);
493
	}
494

  
495
	
496
	public File[] showSaveFileDialog(String title, File initialPath) {
497
		return showChooserDialog(title, JFileChooser.SAVE_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false);
498
	}
499
	
500
	public String translate(String message, String... args) {
501
		return org.gvsig.i18n.Messages.translate(message, args);
502
	}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff