Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / extension / CheckSOAndArquitectureExtension.java @ 41706

History | View | Annotate | Download (8.55 KB)

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.awt.BorderLayout;
27
import java.awt.ComponentOrientation;
28
import java.awt.Container;
29
import java.awt.Dimension;
30
import java.awt.event.ActionEvent;
31
import java.awt.event.ActionListener;
32
import java.io.File;
33
import java.net.URL;
34
import java.util.HashSet;
35
import java.util.Iterator;
36
import java.util.Set;
37

    
38
import javax.swing.Box;
39
import javax.swing.JButton;
40
import javax.swing.JPanel;
41
import javax.swing.JScrollPane;
42
import javax.swing.JTextPane;
43

    
44
import org.apache.commons.io.FileUtils;
45
import org.gvsig.andami.PluginsLocator;
46
import org.gvsig.andami.PluginsManager;
47
import org.gvsig.andami.plugins.Extension;
48
import org.gvsig.app.ApplicationLocator;
49
import org.gvsig.app.ApplicationManager;
50
import org.gvsig.installer.lib.api.InstallerLocator;
51
import org.gvsig.installer.lib.api.InstallerManager;
52
import org.gvsig.installer.lib.api.PackageInfo;
53
import org.slf4j.Logger;
54
import org.slf4j.LoggerFactory;
55

    
56
import com.jgoodies.forms.layout.CellConstraints;
57
import com.jgoodies.forms.layout.FormLayout;
58

    
59
public class CheckSOAndArquitectureExtension extends Extension implements Runnable {
60

    
61
        private static Logger logger = LoggerFactory.getLogger(CheckSOAndArquitectureExtension.class);
62
        public void initialize() {
63
                // Do nothing
64
        }
65

    
66
        public void execute(String actionCommand) {
67
                // Do nothing
68

    
69
        }
70

    
71
        public boolean isEnabled() {
72
                return false;
73
        }
74

    
75
        public boolean isVisible() {
76
                return false;
77
        }
78

    
79
        public void postInitialize() {
80
            PluginsManager pluginManager = PluginsLocator.getManager();
81
            pluginManager.addStartupTask("CheckOsAndArquitectre", this, true, 100);
82
        }
83
        
84
        public void run() {
85
                ApplicationManager application = ApplicationLocator.getManager();
86
                InstallerManager installmgr = InstallerLocator.getInstallerManager();
87
                PluginsManager pluginmgr = PluginsLocator.getManager();
88

    
89
                Set<PackageInfo>  mismatchs = new HashSet<PackageInfo>();
90
                try {
91
                        PackageInfo[] pkgs = installmgr.getInstalledPackages();
92
                        for (int i = 0; i < pkgs.length; i++) {
93
                                PackageInfo pkg = pkgs[i];
94
                                if ( !InstallerManager.ARCH.ALL.equalsIgnoreCase(pkg.getArchitecture()) && !installmgr.getArchitecture().equalsIgnoreCase(
95
                                                pkg.getArchitecture())) {
96
                                        mismatchs.add(pkg);
97
                                }
98
                                if (!InstallerManager.OS.ALL.equalsIgnoreCase(pkg.getOperatingSystem()) &&  !installmgr.getOperatingSystem().equalsIgnoreCase(
99
                                                pkg.getOperatingSystem())) {
100
                                        mismatchs.add(pkg);
101
                                }
102
                        }
103
                } catch (Throwable e) {
104
                        logger.info("Can't get installed packages.",e);
105
                }
106
                if( mismatchs.size() == 0  ) {
107
                        return;
108
                }
109

    
110
                StringBuffer buffer = new StringBuffer();
111
                Iterator<PackageInfo> it = mismatchs.iterator();
112
                while( it.hasNext() ) {
113
                        PackageInfo pkg = it.next();
114
            buffer.append(pkg.getName());
115
            buffer.append(" (");
116
            buffer.append(pkg.getOperatingSystem());
117
            buffer.append("/");
118
            buffer.append(pkg.getArchitecture());
119
            buffer.append(")");
120
                        buffer.append("<br>\n");
121
                }
122
                String template = "<html>"
123
                                + "<p>Packages are installed that are not compatible with your system.</p>\n"
124
                                + "<br>\n"
125
                                + "$(PACKAGES)"
126
                                + "<br>\n"
127
                                + "<p>Some are not specific to your system or architecture.</p>\n"
128
                                + "<br>\n" 
129
                                + "<p>You may need to configure a 32-bit Java environment\n"
130
                                + "for the proper functioning of gvSIG.</p>\n" 
131
                                + "</html>\n";
132

    
133
                try {
134
                        String fname = "i18n/" + application.translate("_filename_warning_architecture_or_os_mismatch");
135
                        URL res = this.getClass().getClassLoader().getResource(fname);
136
                        template = FileUtils.readFileToString(new File(res.getFile()));
137
                } catch (Throwable e) {
138
                        logger.info("Can't get template, use default.",e);
139
                }
140
                
141
                String msg = template.replaceAll("[$][(]PACKAGES[)]", buffer.toString());
142
                msg = msg.replaceAll("[%]PACKAGES[%]", buffer.toString());
143
                msg = msg.replaceAll("[$]PACKAGES", buffer.toString());
144
                
145
                application.showDialog(new ShowMessageControler(msg), "_Warning");
146
        }
147

    
148
        public class ShowMessageControler extends ShowMessageView {
149
                /**
150
                 * 
151
                 */
152
                private static final long serialVersionUID = 2641062720310466029L;
153

    
154
                public ShowMessageControler(String message) {
155
                        super();
156
                        this.messaje.setContentType("text/html");
157
                        this.messaje.setText(message);
158
                        this.closeButton.addActionListener(new ActionListener() {
159
                                public void actionPerformed(ActionEvent arg0) {
160
                                        close();
161
                                }
162
                        });
163
                        ApplicationManager application = ApplicationLocator.getManager();
164
                        this.closeButton.setText(application.translate("Close"));
165
                }
166
                
167
                public void close() {
168
                        this.setVisible(false);
169
                }
170
                
171
        }
172
        
173
        public class ShowMessageView extends JPanel {
174
                private static final long serialVersionUID = 8291970039773969840L;
175
                JTextPane messaje = new JTextPane();
176
                JButton closeButton = new JButton();
177

    
178
                /**
179
                 * Default constructor
180
                 */
181
                public ShowMessageView() {
182
                        initializePanel();
183
                }
184
                
185
                /**
186
                 * Adds fill components to empty cells in the first row and first column
187
                 * of the grid. This ensures that the grid spacing will be the same as
188
                 * shown in the designer.
189
                 * 
190
                 * @param cols
191
                 *            an array of column indices in the first row where fill
192
                 *            components should be added.
193
                 * @param rows
194
                 *            an array of row indices in the first column where fill
195
                 *            components should be added.
196
                 */
197
                private void addFillComponents(Container panel, int[] cols, int[] rows) {
198
                        Dimension filler = new Dimension(10, 10);
199

    
200
                        boolean filled_cell_11 = false;
201
                        CellConstraints cc = new CellConstraints();
202
                        if (cols.length > 0 && rows.length > 0) {
203
                                if (cols[0] == 1 && rows[0] == 1) {
204
                                        /** add a rigid area */
205
                                        panel.add(Box.createRigidArea(filler), cc.xy(1, 1));
206
                                        filled_cell_11 = true;
207
                                }
208
                        }
209

    
210
                        for (int index = 0; index < cols.length; index++) {
211
                                if (cols[index] == 1 && filled_cell_11) {
212
                                        continue;
213
                                }
214
                                panel.add(Box.createRigidArea(filler), cc.xy(cols[index], 1));
215
                        }
216

    
217
                        for (int index = 0; index < rows.length; index++) {
218
                                if (rows[index] == 1 && filled_cell_11) {
219
                                        continue;
220
                                }
221
                                panel.add(Box.createRigidArea(filler), cc.xy(1, rows[index]));
222
                        }
223

    
224
                }
225

    
226
                /**
227
                 * Method for recalculating the component orientation for right-to-left
228
                 * Locales.
229
                 * 
230
                 * @param orientation
231
                 *            the component orientation to be applied
232
                 */
233
                public void applyComponentOrientation(ComponentOrientation orientation) {
234
                        // Not yet implemented...
235
                        // I18NUtils.applyComponentOrientation(this, orientation);
236
                        super.applyComponentOrientation(orientation);
237
                }
238

    
239
                public JPanel createPanel() {
240
                        JPanel jpanel1 = new JPanel();
241
                        FormLayout formlayout1 = new FormLayout(
242
                                        "FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE",
243
                                        "CENTER:DEFAULT:NONE,CENTER:DEFAULT:GROW(1.0),CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE");
244
                        CellConstraints cc = new CellConstraints();
245
                        jpanel1.setLayout(formlayout1);
246

    
247
                        JScrollPane jscrollpane1 = new JScrollPane();
248
                        jscrollpane1.setViewportView(messaje);
249
                        jscrollpane1
250
                                        .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
251
                        jscrollpane1
252
                                        .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
253
                        jpanel1.add(jscrollpane1, new CellConstraints(2, 2, 3, 1,
254
                                        CellConstraints.DEFAULT, CellConstraints.FILL));
255

    
256
                        closeButton.setActionCommand("JButton");
257
                        closeButton.setText("JButton");
258
                        jpanel1.add(closeButton, cc.xy(3, 4));
259

    
260
                        addFillComponents(jpanel1, new int[] { 1, 2, 3, 4, 5 }, new int[] {
261
                                        1, 2, 3, 4, 5 });
262
                        return jpanel1;
263
                }
264

    
265
                /**
266
                 * Initializer
267
                 */
268
                protected void initializePanel() {
269
                        setLayout(new BorderLayout());
270
                        add(createPanel(), BorderLayout.CENTER);
271
                }
272

    
273
        }
274

    
275
}