Revision 38447

View differences:

trunk/extensions/org.gvsig.installer.app.extension/src/main/java/org/gvsig/installer/app/extension/GvSIGFolders.java
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
package org.gvsig.installer.app.extension;
23

  
24
import java.io.File;
25

  
26
import com.iver.andami.Launcher;
27

  
28

  
29

  
30
/**
31
 * Gets the main gvSIG application folders.
32
 * 
33
 * @author gvSIG Team
34
 * @version $Id$
35
 */
36
public class GvSIGFolders {
37

  
38
    /**
39
     * Returns the gvSIG main application folder.
40
     * 
41
     * @return the gvSIG main application folder
42
     */
43
    public File getApplicationFolder() {
44
        // TODO: check if there is a better way to handle this
45
        return new File(System.getProperty("user.dir"));
46
    }
47

  
48
    /**
49
     * Returns the gvSIG plugins folder.
50
     * 
51
     * @return the gvSIG plugins folder
52
     */
53
    public File getPluginsFolder() {
54
        return new File(Launcher.getAndamiConfig().getPluginsDirectory())
55
            .getAbsoluteFile();
56
    }
57

  
58
    /**
59
     * Returns the default gvSIG folder with the installable package bundles.
60
     * 
61
     * @return the default gvSIG folder with the installable package bundles
62
     */
63
    public File getInstallFolder() {
64
        return new File(getApplicationFolder(), "install");
65
    }
66

  
67
}
trunk/extensions/org.gvsig.installer.app.extension/src/main/java/org/gvsig/installer/app/extension/execution/InstallPackageExtension.java
27 27

  
28 28
package org.gvsig.installer.app.extension.execution;
29 29

  
30
import java.io.BufferedReader;
31
import java.io.InputStream;
32
import java.io.InputStreamReader;
30 33
import java.net.MalformedURLException;
31 34
import java.net.URL;
32 35

  
33
import javax.swing.JOptionPane;
34

  
35
import org.gvsig.i18n.Messages;
36
import org.gvsig.installer.app.extension.GvSIGFolders;
36
import org.gvsig.installer.app.extension.BackportrHelper.ApplicationLocator;
37
import org.gvsig.installer.app.extension.BackportrHelper.PluginsLocator;
38
import org.gvsig.installer.app.extension.BackportrHelper.PluginsManager;
37 39
import org.gvsig.installer.swing.api.SwingInstallerLocator;
38
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
40
import org.gvsig.installer.swing.api.SwingInstallerManager;
39 41
import org.slf4j.Logger;
40 42
import org.slf4j.LoggerFactory;
41 43

  
......
48 50
 */
49 51
public class InstallPackageExtension extends Extension {
50 52

  
51
    private static final Logger LOG = LoggerFactory
52
        .getLogger(InstallPackageExtension.class);
53
	private static final Logger LOG = LoggerFactory
54
			.getLogger(InstallPackageExtension.class);
53 55

  
54
    public void execute(String actionCommand) {
55
    	int resp = JOptionPane.showConfirmDialog(
56
    			null,
57
    			Messages.getText("install_package_extension_warning"),
58
    			Messages.getText("select_an_option"),
59
    			JOptionPane.YES_NO_OPTION);
60
    	if (resp!=JOptionPane.OK_OPTION){
61
    		return;
62
    	}
56
	public void execute(String actionCommand) {
57
		if ("tools-addonsmanager".equalsIgnoreCase(actionCommand)) {
58
			PluginsManager manager = PluginsLocator.getManager();
59
			try {
60
				PluginServices.getMDIManager().addCentredWindow(
61
						new InstallPackageWindow(
62
								manager.getApplicationFolder(), manager
63
										.getInstallFolder()));
64
			} catch (Error e) {
65
				LOG.error("Error creating the wizard to install a package ", e);
66
			} catch (Exception e) {
67
				LOG.error("Error creating the wizard to install a package ", e);
68
			}
69
		}
70
	}
63 71

  
64
        GvSIGFolders folders = new GvSIGFolders();
65
        try {
66
            PluginServices.getMDIManager().addCentredWindow(
67
                new InstallPackageWindow(folders.getApplicationFolder(),
68
                    folders.getPluginsFolder(), folders.getInstallFolder()));
69
        } catch (Exception e) {
70
            LOG.error("Error creating the wizard to install a package ", e);
71
        }
72
    }
72
	public void initialize() {
73
		Version version = ApplicationLocator.getManager().getVersion();
73 74

  
74
    public void initialize() {
75
		try {
76
	    	PluginsLocator.getIconThemeManager().getCurrent().registerDefault(
77
					"tools-addonsmanager",
78
					this.getClass().getClassLoader().getResource("images/action/tools-addonsmanager.png")
79
				);
80
	    	
81
			SwingInstallerManager manager = SwingInstallerLocator
82
					.getSwingInstallerManager();
83
			InputStream is = this.getClass().getResourceAsStream(
84
					"/defaultDownloadsURLs");
85
			BufferedReader in = new BufferedReader(new InputStreamReader(is));
86
			String line = null;
87
			for (line = in.readLine(); line != null; line = in.readLine()) {
88
				line = line.replace("$version", version.getFormat());
89
				line = line.replace("<%Version%>", version.getFormat());
90
				try {
91
					manager.addDefaultDownloadURL(new URL(line));
92
				} catch (MalformedURLException e) {
93
					LOG.error(
94
							"Error creating the default packages download URL pointing to "
95
									+ line, e);
96
				}
97
			}
98
			manager.getInstallerManager().setVersion(version.getFormat());
99
		} catch (Throwable e) {
100
			LOG.error("Error reading the default packages download URL file "
101
					+ "/defaultDownloadsURLs", e);
102
		}
103
	}
75 104

  
76
        // TODO: move to user preferences or an external configuration file
77
        String packageDownloadURL =
78
        	"http://downloads.gvsig.org/download/gvsig-desktop/dists/"+(new Version()).getFormat()+"/packages.gvspki";
105
	public boolean isEnabled() {
106
		return true;
107
	}
79 108

  
80
        try {
81
        	
82
//        	InitializeLibraries.initialize();
83
    		new DefaultLibrariesInitializer(this.getClass().getClassLoader()).fullInitialize();
109
	public boolean isVisible() {
110
		return true;
111
	}
84 112

  
85
        	
86
        	SwingInstallerLocator.getSwingInstallerManager()
87
                .setDefaultDownloadURL(new URL(packageDownloadURL));
88
        } catch (MalformedURLException e) {
89
            LOG.error(
90
                "Error creating the default packages download URL pointing to"
91
                    + packageDownloadURL, e);
92
        }
93
    }
94

  
95
    public boolean isEnabled() {
96
        return true;
97
    }
98

  
99
    public boolean isVisible() {
100
        return true;
101
    }
102

  
113
    
114
 
115
    
103 116
}
trunk/extensions/org.gvsig.installer.app.extension/src/main/java/org/gvsig/installer/app/extension/execution/InstallPackageWindow.java
48 48
 */
49 49
public class InstallPackageWindow extends JPanel implements IWindow {
50 50

  
51
    private static final long serialVersionUID = 4719868181091291809L;
52
    WindowInfo windowInfo = null;
53 51

  
54
    public InstallPackageWindow(File applicationFolder, File pluginsFolder,
55
        File installFolder) throws LocatorException,
56
        InstallPackageWizardException {
57
        super();
58
        AbstractInstallPackageWizard installPackageWizard =
59
            SwingInstallerLocator.getSwingInstallerManager()
60
                .createInstallPackageWizard(applicationFolder, pluginsFolder,
61
                    installFolder);
62
        installPackageWizard
63
            .setWizardActionListener(new WindowInstallerListener(this));
64
        this.setLayout(new BorderLayout());
65
        add(installPackageWizard, BorderLayout.CENTER);
66
    }
52
	private static final long serialVersionUID = 4719868181091291809L;
53
	WindowInfo windowInfo = null;
67 54

  
68
    public WindowInfo getWindowInfo() {
69
        if (windowInfo == null) {
70
            windowInfo =
71
                new WindowInfo(WindowInfo.MODELESSDIALOG
72
                    | WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE);
73
            Dimension dim = getPreferredSize();
74
            windowInfo.setWidth((int) dim.getWidth());
75
            windowInfo.setHeight((int) dim.getHeight());
76
            windowInfo.setTitle(Messages.getText("install_package"));
77
        }
78
        return windowInfo;
79
    }
55
	public InstallPackageWindow(File applicationFolder, File installFolder)
56
			throws LocatorException, InstallPackageWizardException {
57
		super();
58
		AbstractInstallPackageWizard installPackageWizard = SwingInstallerLocator
59
				.getSwingInstallerManager().createInstallPackageWizard(
60
						applicationFolder, installFolder);
61
		installPackageWizard
62
				.setWizardActionListener(new WindowInstallerListener(this));
63
		this.setLayout(new BorderLayout());
64
		add(installPackageWizard, BorderLayout.CENTER);
65
	}
80 66

  
81
    public Object getWindowProfile() {
82
        return WindowInfo.DIALOG_PROFILE;
83
    }
67
	public WindowInfo getWindowInfo() {
68
		if (windowInfo == null) {
69
			windowInfo = new WindowInfo(WindowInfo.MODELESSDIALOG
70
					| WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE);
71
			Dimension dim = getPreferredSize();
72
			windowInfo.setWidth((int) dim.getWidth());
73
			windowInfo.setHeight((int) dim.getHeight());
74
			windowInfo.setTitle(Messages.getText("install_package"));
75
		}
76
		return windowInfo;
77
	}
84 78

  
79
	public Object getWindowProfile() {
80
		return WindowInfo.DIALOG_PROFILE;
81
	}
85 82
}
trunk/extensions/org.gvsig.installer.app.extension/src/main/java/org/gvsig/installer/app/extension/creation/MakePluginPackageWindow.java
48 48
 */
49 49
public class MakePluginPackageWindow extends JPanel implements IWindow {
50 50

  
51
    private static final long serialVersionUID = 3423389124323013058L;
52
    WindowInfo windowInfo = null;
51
	private static final long serialVersionUID = 3423389124323013058L;
52
	WindowInfo windowInfo = null;
53 53

  
54
    public MakePluginPackageWindow(File applicationFolder, File pluginsFolder,
55
        File installFolder) throws LocatorException,
56
        MakePluginPackageWizardException {
57
        super();
58
        MakePluginPackageWizard makePluginPackageWizard =
59
            SwingInstallerLocator.getSwingInstallerManager()
60
                .createMakePluginPackageWizard(applicationFolder,
61
                    pluginsFolder, installFolder);
62
        makePluginPackageWizard
63
            .setWizardActionListener(new WindowInstallerListener(this));
64
        this.setLayout(new BorderLayout());
65
        add(makePluginPackageWizard, BorderLayout.CENTER);
66
    }
54
	public MakePluginPackageWindow(File applicationFolder, File installFolder)
55
			throws LocatorException, MakePluginPackageWizardException {
56
		super();
57
		MakePluginPackageWizard makePluginPackageWizard = SwingInstallerLocator
58
				.getSwingInstallerManager().createMakePluginPackageWizard(
59
						applicationFolder, installFolder);
60
		makePluginPackageWizard
61
				.setWizardActionListener(new WindowInstallerListener(this));
62
		this.setLayout(new BorderLayout());
63
		add(makePluginPackageWizard, BorderLayout.CENTER);
64
	}
67 65

  
68
    public WindowInfo getWindowInfo() {
69
        if (windowInfo == null) {
70
            windowInfo =
71
                new WindowInfo(WindowInfo.MODELESSDIALOG
72
                    | WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE);
73
            Dimension dim = getPreferredSize();
74
            windowInfo.setWidth((int) dim.getWidth());
75
            windowInfo.setHeight((int) dim.getHeight());
76
            windowInfo.setTitle(Messages.getText("make_plugin_package"));
77
        }
78
        return windowInfo;
79
    }
66
	public WindowInfo getWindowInfo() {
67
		if (windowInfo == null) {
68
			windowInfo = new WindowInfo(WindowInfo.MODELESSDIALOG
69
					| WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE);
70
			Dimension dim = getPreferredSize();
71
			windowInfo.setWidth((int) dim.getWidth());
72
			windowInfo.setHeight((int) dim.getHeight());
73
			windowInfo.setTitle(Messages.getText("make_plugin_package"));
74
		}
75
		return windowInfo;
76
	}
80 77

  
81
    public Object getWindowProfile() {
82
        return WindowInfo.DIALOG_PROFILE;
83
    }
78
	public Object getWindowProfile() {
79
		return WindowInfo.DIALOG_PROFILE;
80
	}
81
	
84 82
}
trunk/extensions/org.gvsig.installer.app.extension/src/main/java/org/gvsig/installer/app/extension/creation/MakePluginPackageExtension.java
27 27

  
28 28
package org.gvsig.installer.app.extension.creation;
29 29

  
30
import org.gvsig.installer.app.extension.GvSIGFolders;
30
import org.gvsig.installer.app.extension.BackportrHelper.ApplicationLocator;
31
import org.gvsig.installer.app.extension.BackportrHelper.PluginsLocator;
32
import org.gvsig.installer.app.extension.BackportrHelper.PluginsManager;
31 33
import org.gvsig.installer.swing.api.SwingInstallerLocator;
32 34
import org.slf4j.Logger;
33 35
import org.slf4j.LoggerFactory;
......
41 43
 */
42 44
public class MakePluginPackageExtension extends Extension {
43 45

  
44
    private static final Logger LOG = LoggerFactory
45
        .getLogger(MakePluginPackageExtension.class);
46
	private static final Logger LOG = LoggerFactory
47
			.getLogger(MakePluginPackageExtension.class);
46 48

  
47
    public void execute(String actionCommand) {
48
        GvSIGFolders folders = new GvSIGFolders();
49
	public void execute(String actionCommand) {
50
		if ("tools-devel-pack-plugin".equalsIgnoreCase(actionCommand)) {
51
			PluginsManager manager = PluginsLocator.getManager();
49 52

  
50
        try {
51
            PluginServices.getMDIManager().addCentredWindow(
52
                new MakePluginPackageWindow(folders.getApplicationFolder(),
53
                    folders.getPluginsFolder(), folders.getInstallFolder()));
54
        } catch (Exception e) {
55
            LOG.error("Error creating teh wizard to create an installer ", e);
56
        }
57
    }
53
			try {
54
				PluginServices.getMDIManager().addCentredWindow(
55
						new MakePluginPackageWindow(manager
56
								.getApplicationFolder(), manager
57
								.getInstallFolder()));
58
			} catch (Exception e) {
59
				LOG.error("Error creating teh wizard to create an installer ",
60
						e);
61
			}
62
		}
63
	}
58 64

  
59
    public void initialize() {
60
    }
65
	public void initialize() {
61 66

  
62
    @Override
63
    public void postInitialize() {
64
        super.postInitialize();
65
        //Version version = ApplicationLocator.getManager().getVersion();
66
        SwingInstallerLocator.getSwingInstallerManager().setApplicationVersion(
67
            Version.format());
68
    }
67
	}
69 68

  
70
    public boolean isEnabled() {
71
        return true;
72
    }
69
	@Override
70
	public void postInitialize() {
71
		super.postInitialize();
72
		Version version = ApplicationLocator.getManager().getVersion();
73
		SwingInstallerLocator.getSwingInstallerManager().setApplicationVersion(
74
				version.getFormat());
75
	}
73 76

  
74
    public boolean isVisible() {
75
        return true;
76
    }
77
	public boolean isEnabled() {
78
		return true;
79
	}
77 80

  
81
	public boolean isVisible() {
82
		return true;
83
	}
84

  
78 85
}
trunk/extensions/org.gvsig.installer.app.extension/src/main/java/org/gvsig/installer/app/extension/BackportrHelper.java
1
package org.gvsig.installer.app.extension;
2

  
3
import java.io.File;
4

  
5
import org.gvsig.installer.app.extension.creation.MakePluginPackageExtension;
6
import org.gvsig.installer.lib.api.InstallerLocator;
7
import org.gvsig.installer.lib.api.InstallerManager;
8
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
9
import org.slf4j.Logger;
10
import org.slf4j.LoggerFactory;
11

  
12
import com.iver.andami.Launcher;
13
import com.iver.andami.iconthemes.IconThemeManager;
14
import com.iver.cit.gvsig.Version;
15

  
16
/**
17
 * backport parcial de algunas clases e interfaces de la 2 que son usadas en
18
 * el codifgo de este plugin.
19
 * 
20
 * @author jjdelcerro
21
 *
22
 */
23
public class BackportrHelper {
24
	private static final Logger logger = LoggerFactory.getLogger(BackportrHelper.class);
25

  
26

  
27
	private static boolean alreadyInitialized = false;
28
	
29
	private static void initialize() {
30
	    if( alreadyInitialized ) {
31
	      return;
32
	    }
33
	    alreadyInitialized = true;
34
	    
35
	    Version version = new Version();
36
	    logger.info("BackportHelper inicialinig... (gvsig ver "+version.getMajor()+"."+version.getMinor()+").");
37

  
38
	    if( version.getMajor()==1 && version.getMinor()==11 ) {
39
	      logger.info("Initializing libraries.");
40
	      new DefaultLibrariesInitializer(BackportrHelper.class.getClassLoader()).fullInitialize();
41
	    }
42
	    
43
	    File defaultAddonsRepository = PluginsLocator.getManager().getPluginsFolder();
44
	    InstallerManager installerManager = InstallerLocator.getInstallerManager();
45
	    installerManager.addLocalAddonRepository(defaultAddonsRepository);
46
	    installerManager.setDefaultLocalAddonRepository(defaultAddonsRepository);
47

  
48
	    logger.info("BackportHelper inicialzed.");
49
	    logger.info("defaultAddonsRepository = '"+defaultAddonsRepository.toString()+"'.");
50
	  }
51
	
52
	
53
	public interface PluginsManager {
54
		public File getPluginsFolder();
55
		public File getApplicationFolder();
56
		public File getInstallFolder();
57
    }
58
	public static class PluginsLocator {
59
		public static PluginsManager getManager() {
60
			initialize();
61
			return new DefaultPluginsManager();
62
		}
63
	    public static IconThemeManager getIconThemeManager() {
64
			initialize();
65
	    	return IconThemeManager.getIconThemeManager();
66
	    }
67
	}
68
	public static class DefaultPluginsManager implements PluginsManager {
69
		private File pluginsFolder = null;
70
		
71
		public File getPluginsFolder() {
72
			if (this.pluginsFolder != null) {
73
				return this.pluginsFolder;
74
			}
75
			String folder = "gvSIG/extensiones";
76
			if (!(Launcher.getAndamiConfig() == null || Launcher
77
					.getAndamiConfig().getPluginsDirectory() == null)) {
78
				folder = Launcher.getAndamiConfig().getPluginsDirectory();
79
			}
80
			this.pluginsFolder = new File(getApplicationFolder(), folder);
81
			return this.pluginsFolder;
82
		}
83

  
84
		public File getApplicationFolder() {
85
			// TODO: check if there is a better way to handle this
86
			return new File(System.getProperty("user.dir"));
87
		}
88
		
89
	    public File getInstallFolder() {
90
	        return new File(getApplicationFolder(), "install");
91
	    }
92
	}
93

  
94
	public interface ApplicationManager {
95
		public Version getVersion();
96
	}
97
	public static class ApplicationLocator {
98
		public static ApplicationManager getManager() {
99
			initialize();
100
			return new DefaultApplicationManager();
101
		}
102
	}
103
	public static class DefaultApplicationManager implements ApplicationManager {
104
		public Version getVersion() {
105
			return new Version();
106
		}
107
	}
108

  
109
}
trunk/extensions/org.gvsig.installer.app.extension/src/main/resources/config/config.xml
9 9
			active="false">
10 10
			<menu text="tools/Development/make_plugin_package"
11 11
				  tooltip="make_plugin_package_description"
12
				  action-command=""
12
				  action-command="tools-devel-pack-plugin"
13 13
				  position="4998" />			
14 14
		</extension>
15 15
			<extension class-name="org.gvsig.installer.app.extension.execution.InstallPackageExtension"
......
17 17
			active="true">
18 18
			<menu text="tools/install_package"
19 19
				  tooltip="install_package_description"
20
				  action-command=""
20
				  action-command="tools-addonsmanager"
21 21
				  position="4999" />			
22 22
		</extension>
23 23
	</extensions>
trunk/extensions/org.gvsig.installer.app.extension/src/main/resources/config/defaultDownloadsURLs
1
http://downloads.gvsig.org/download/gvsig-desktop
2
http://gvsig.freegis.ru/download/gvsig-desktop
trunk/frameworks/_fwAndami/src/com/iver/andami/Launcher.java
276 276
		AbstractInstallPackageWizard installPackageWizard = SwingInstallerLocator
277 277
				.getSwingInstallerManager().createInstallPackageWizard(
278 278
						appFolder,
279
						new File(Launcher.getAndamiConfig()
280
								.getPluginsDirectory()).getAbsoluteFile(),
281 279
						new File(appFolder, "install"));
280
		
282 281
		installPackageWizard
283 282
				.setWizardActionListener(new InstallerWizardActionListener() {
284 283

  

Also available in: Unified diff