Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / org.gvsig.installer.app / org.gvsig.installer.app.extension / src / main / java / org / gvsig / installer / app / extension / execution / InstallPackageExtension.java @ 38564

History | View | Annotate | Download (3.55 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2010 {Prodevelop}   {Task}
26
 */
27

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

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

    
36
import org.gvsig.andami.IconThemeHelper;
37
import org.gvsig.andami.PluginServices;
38
import org.gvsig.andami.PluginsLocator;
39
import org.gvsig.andami.PluginsManager;
40
import org.gvsig.andami.plugins.Extension;
41
import org.gvsig.app.ApplicationLocator;
42
import org.gvsig.app.extension.Version;
43
import org.gvsig.installer.lib.api.InstallerLocator;
44
import org.gvsig.installer.swing.api.SwingInstallerLocator;
45
import org.gvsig.installer.swing.api.SwingInstallerManager;
46
import org.slf4j.Logger;
47
import org.slf4j.LoggerFactory;
48

    
49
/**
50
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
51
 */
52
public class InstallPackageExtension extends Extension {
53

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

    
57
        public void execute(String actionCommand) {
58
                if ("tools-addonsmanager".equalsIgnoreCase(actionCommand)) {
59
                        PluginsManager manager = PluginsLocator.getManager();
60
                        try {
61
                                PluginServices.getMDIManager().addCentredWindow(
62
                                                new InstallPackageWindow(
63
                                                                manager.getApplicationFolder(), manager
64
                                                                                .getInstallFolder()));
65
                        } catch (Error e) {
66
                                LOG.error("Error creating the wizard to install a package ", e);
67
                        } catch (Exception e) {
68
                                LOG.error("Error creating the wizard to install a package ", e);
69
                        }
70
                }
71
        }
72

    
73
        public void initialize() {
74
                Version version = ApplicationLocator.getManager().getVersion();
75
                InstallerLocator.getInstallerManager().setVersion(
76
                                version.getFormat() + "-" + version.getBuildId());
77
                try {
78
                        IconThemeHelper.registerIcon("action", "tools-addonsmanager", this);
79
                    
80
                        SwingInstallerManager manager = SwingInstallerLocator
81
                                        .getSwingInstallerManager();
82
                        
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
                                try {
89
                                        manager.addDefaultDownloadURL(line);
90
                                } catch (MalformedURLException e) {
91
                                        LOG.error(
92
                                                        "Error creating the default packages download URL pointing to "
93
                                                                        + line, e);
94
                                }
95
                        }
96
                        manager.getInstallerManager().setVersion(version.getFormat());
97
                } catch (Throwable e) {
98
                        LOG.error("Error reading the default packages download URL file "
99
                                        + "/defaultDownloadsURLs", e);
100
                }
101
        }
102

    
103
        public boolean isEnabled() {
104
                return true;
105
        }
106

    
107
        public boolean isVisible() {
108
                return true;
109
        }
110

    
111
}