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 @ 42619
History | View | Annotate | Download (10.7 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 modify it under
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
9 |
* version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
14 |
* details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License along with
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.app.extension; |
24 |
|
25 |
import java.awt.BorderLayout; |
26 |
import java.awt.ComponentOrientation; |
27 |
import java.awt.Container; |
28 |
import java.awt.Dimension; |
29 |
import java.awt.event.ActionEvent; |
30 |
import java.awt.event.ActionListener; |
31 |
import java.io.File; |
32 |
import java.net.URL; |
33 |
import java.util.HashSet; |
34 |
import java.util.Iterator; |
35 |
import java.util.Set; |
36 |
|
37 |
import javax.swing.Box; |
38 |
import javax.swing.JButton; |
39 |
import javax.swing.JPanel; |
40 |
import javax.swing.JScrollPane; |
41 |
import javax.swing.JTextPane; |
42 |
|
43 |
import org.apache.commons.io.FileUtils; |
44 |
import org.gvsig.andami.PluginsLocator; |
45 |
import org.gvsig.andami.PluginsManager; |
46 |
import org.gvsig.andami.plugins.Extension; |
47 |
import org.gvsig.app.ApplicationLocator; |
48 |
import org.gvsig.app.ApplicationManager; |
49 |
import org.gvsig.installer.lib.api.InstallerLocator; |
50 |
import org.gvsig.installer.lib.api.InstallerManager; |
51 |
import org.gvsig.installer.lib.api.PackageInfo; |
52 |
import org.slf4j.Logger; |
53 |
import org.slf4j.LoggerFactory; |
54 |
|
55 |
import com.jgoodies.forms.layout.CellConstraints; |
56 |
import com.jgoodies.forms.layout.FormLayout; |
57 |
|
58 |
public class CheckSOAndArquitectureExtension extends Extension implements Runnable { |
59 |
|
60 |
private static final Logger logger = LoggerFactory.getLogger(CheckSOAndArquitectureExtension.class); |
61 |
|
62 |
@Override
|
63 |
public void initialize() { |
64 |
// Do nothing
|
65 |
} |
66 |
|
67 |
@Override
|
68 |
public void execute(String actionCommand) { |
69 |
// Do nothing
|
70 |
|
71 |
} |
72 |
|
73 |
@Override
|
74 |
public boolean isEnabled() { |
75 |
return false; |
76 |
} |
77 |
|
78 |
@Override
|
79 |
public boolean isVisible() { |
80 |
return false; |
81 |
} |
82 |
|
83 |
@Override
|
84 |
public void postInitialize() { |
85 |
PluginsManager pluginManager = PluginsLocator.getManager(); |
86 |
pluginManager.addStartupTask("CheckOsAndArquitectre", this, true, 100); |
87 |
} |
88 |
|
89 |
@Override
|
90 |
public void run() { |
91 |
ApplicationManager application = ApplicationLocator.getManager(); |
92 |
InstallerManager installmgr = InstallerLocator.getInstallerManager(); |
93 |
PluginsManager pluginmgr = PluginsLocator.getManager(); |
94 |
|
95 |
Set<PackageInfo> mismatchs = new HashSet<>(); |
96 |
String recommendedArchitecture = null; |
97 |
try {
|
98 |
PackageInfo[] pkgs = installmgr.getInstalledPackages();
|
99 |
for (PackageInfo pkg : pkgs) {
|
100 |
if( !InstallerManager.ARCH.ALL.equalsIgnoreCase(pkg.getArchitecture())
|
101 |
&& !installmgr.getArchitecture().equalsIgnoreCase(pkg.getArchitecture())) { |
102 |
recommendedArchitecture = pkg.getArchitecture(); |
103 |
mismatchs.add(pkg); |
104 |
} |
105 |
if (!InstallerManager.OS.ALL.equalsIgnoreCase(pkg.getOperatingSystem()) && !installmgr.getOperatingSystem().equalsIgnoreCase(
|
106 |
pkg.getOperatingSystem())) { |
107 |
mismatchs.add(pkg); |
108 |
} |
109 |
} |
110 |
} catch (Throwable e) { |
111 |
logger.info("Can't get installed packages.", e);
|
112 |
} |
113 |
if (mismatchs.isEmpty()) {
|
114 |
return;
|
115 |
} |
116 |
|
117 |
StringBuilder buffer = new StringBuilder(); |
118 |
Iterator<PackageInfo> it = mismatchs.iterator();
|
119 |
while (it.hasNext()) {
|
120 |
PackageInfo pkg = it.next(); |
121 |
buffer.append(pkg.getName()); |
122 |
buffer.append(" (");
|
123 |
buffer.append(pkg.getOperatingSystem()); |
124 |
buffer.append("/");
|
125 |
buffer.append(pkg.getArchitecture()); |
126 |
buffer.append(")");
|
127 |
buffer.append("<br>\n");
|
128 |
} |
129 |
String template = "<html>" |
130 |
+ "<p>gvSIG is running on a platform $(CURRENT_ARCHITECTURE)</p>\n"
|
131 |
+ "<br>\n"
|
132 |
+ "<p>Packages are installed that are not compatible with your system.</p>\n"
|
133 |
+ "<br>\n"
|
134 |
+ "$(PACKAGES)"
|
135 |
+ "<br>\n"
|
136 |
+ "<p>Some are not specific to your system or architecture.</p>\n"
|
137 |
+ "<br>\n"
|
138 |
+ "<p>You probably need to configure a $(RECOMMENDED_ARCHITECTURE) Java environment\n"
|
139 |
+ "for the proper functioning of gvSIG.</p>\n"
|
140 |
+ "</html>\n";
|
141 |
|
142 |
try {
|
143 |
String fname = "i18n/" + application.translate("_filename_warning_architecture_or_os_mismatch"); |
144 |
URL res = this.getClass().getClassLoader().getResource(fname); |
145 |
template = FileUtils.readFileToString(new File(res.getFile())); |
146 |
} catch (Throwable e) { |
147 |
logger.info("Can't get template, use default.", e);
|
148 |
} |
149 |
|
150 |
String msg = template.replaceAll("[$][(]PACKAGES[)]", buffer.toString()); |
151 |
msg = msg.replaceAll("[%]PACKAGES[%]", buffer.toString());
|
152 |
msg = msg.replaceAll("[$]PACKAGES", buffer.toString());
|
153 |
|
154 |
msg = msg.replaceAll("[$][(]RECOMMENDED_ARCHITECTURE[)]", recommendedArchitecture);
|
155 |
msg = msg.replaceAll("[%]RECOMMENDED_ARCHITECTURE[%]", recommendedArchitecture);
|
156 |
msg = msg.replaceAll("[$]RECOMMENDED_ARCHITECTURE", recommendedArchitecture);
|
157 |
|
158 |
msg = msg.replaceAll("[$][(]CURRENT_ARCHITECTURE[)]", installmgr.getArchitecture());
|
159 |
msg = msg.replaceAll("[%]CURRENT_ARCHITECTURE[%]", installmgr.getArchitecture());
|
160 |
msg = msg.replaceAll("[$]CURRENT_ARCHITECTURE", installmgr.getArchitecture());
|
161 |
|
162 |
application.showDialog(new ShowMessageControler(msg), "_Warning"); |
163 |
} |
164 |
|
165 |
public class ShowMessageControler extends ShowMessageView { |
166 |
|
167 |
/**
|
168 |
*
|
169 |
*/
|
170 |
private static final long serialVersionUID = 2641062720310466029L; |
171 |
|
172 |
public ShowMessageControler(String message) { |
173 |
super();
|
174 |
this.messaje.setContentType("text/html"); |
175 |
this.messaje.setText(message);
|
176 |
this.closeButton.addActionListener(new ActionListener() { |
177 |
@Override
|
178 |
public void actionPerformed(ActionEvent arg0) { |
179 |
close(); |
180 |
} |
181 |
}); |
182 |
ApplicationManager application = ApplicationLocator.getManager(); |
183 |
this.closeButton.setText(application.translate("Close")); |
184 |
} |
185 |
|
186 |
public void close() { |
187 |
this.setVisible(false); |
188 |
} |
189 |
|
190 |
} |
191 |
|
192 |
public class ShowMessageView extends JPanel { |
193 |
|
194 |
private static final long serialVersionUID = 8291970039773969840L; |
195 |
JTextPane messaje = new JTextPane(); |
196 |
JButton closeButton = new JButton(); |
197 |
|
198 |
/**
|
199 |
* Default constructor
|
200 |
*/
|
201 |
public ShowMessageView() {
|
202 |
initializePanel(); |
203 |
} |
204 |
|
205 |
/**
|
206 |
* Adds fill components to empty cells in the first row and first column
|
207 |
* of the grid. This ensures that the grid spacing will be the same as
|
208 |
* shown in the designer.
|
209 |
*
|
210 |
* @param cols an array of column indices in the first row where fill
|
211 |
* components should be added.
|
212 |
* @param rows an array of row indices in the first column where fill
|
213 |
* components should be added.
|
214 |
*/
|
215 |
private void addFillComponents(Container panel, int[] cols, int[] rows) { |
216 |
Dimension filler = new Dimension(10, 10); |
217 |
|
218 |
boolean filled_cell_11 = false; |
219 |
CellConstraints cc = new CellConstraints();
|
220 |
if (cols.length > 0 && rows.length > 0) { |
221 |
if (cols[0] == 1 && rows[0] == 1) { |
222 |
/**
|
223 |
* add a rigid area
|
224 |
*/
|
225 |
panel.add(Box.createRigidArea(filler), cc.xy(1, 1)); |
226 |
filled_cell_11 = true;
|
227 |
} |
228 |
} |
229 |
|
230 |
for (int index = 0; index < cols.length; index++) { |
231 |
if (cols[index] == 1 && filled_cell_11) { |
232 |
continue;
|
233 |
} |
234 |
panel.add(Box.createRigidArea(filler), cc.xy(cols[index], 1)); |
235 |
} |
236 |
|
237 |
for (int index = 0; index < rows.length; index++) { |
238 |
if (rows[index] == 1 && filled_cell_11) { |
239 |
continue;
|
240 |
} |
241 |
panel.add(Box.createRigidArea(filler), cc.xy(1, rows[index])); |
242 |
} |
243 |
|
244 |
} |
245 |
|
246 |
/**
|
247 |
* Method for recalculating the component orientation for right-to-left
|
248 |
* Locales.
|
249 |
*
|
250 |
* @param orientation the component orientation to be applied
|
251 |
*/
|
252 |
@Override
|
253 |
public void applyComponentOrientation(ComponentOrientation orientation) { |
254 |
// Not yet implemented...
|
255 |
// I18NUtils.applyComponentOrientation(this, orientation);
|
256 |
super.applyComponentOrientation(orientation);
|
257 |
} |
258 |
|
259 |
public JPanel createPanel() { |
260 |
JPanel jpanel1 = new JPanel(); |
261 |
FormLayout formlayout1 = new FormLayout(
|
262 |
"FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE",
|
263 |
"CENTER:DEFAULT:NONE,CENTER:DEFAULT:GROW(1.0),CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE");
|
264 |
CellConstraints cc = new CellConstraints();
|
265 |
jpanel1.setLayout(formlayout1); |
266 |
|
267 |
JScrollPane jscrollpane1 = new JScrollPane(); |
268 |
jscrollpane1.setViewportView(messaje); |
269 |
jscrollpane1 |
270 |
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
271 |
jscrollpane1 |
272 |
.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
273 |
jpanel1.add(jscrollpane1, new CellConstraints(2, 2, 3, 1, |
274 |
CellConstraints.DEFAULT, CellConstraints.FILL)); |
275 |
|
276 |
closeButton.setActionCommand("JButton");
|
277 |
closeButton.setText("JButton");
|
278 |
jpanel1.add(closeButton, cc.xy(3, 4)); |
279 |
|
280 |
addFillComponents(jpanel1, new int[]{1, 2, 3, 4, 5}, new int[]{ |
281 |
1, 2, 3, 4, 5}); |
282 |
return jpanel1;
|
283 |
} |
284 |
|
285 |
/**
|
286 |
* Initializer
|
287 |
*/
|
288 |
protected void initializePanel() { |
289 |
setLayout(new BorderLayout()); |
290 |
add(createPanel(), BorderLayout.CENTER);
|
291 |
} |
292 |
|
293 |
} |
294 |
|
295 |
} |