Revision 42590
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/CheckSOAndArquitectureExtension.java | ||
---|---|---|
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2007-2013 gvSIG Association. |
5 | 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.
|
|
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 | 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.
|
|
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 | 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. |
|
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. |
|
20 | 19 |
* |
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
23 | 22 |
*/ |
24 | 23 |
package org.gvsig.app.extension; |
25 | 24 |
|
... | ... | |
58 | 57 |
|
59 | 58 |
public class CheckSOAndArquitectureExtension extends Extension implements Runnable { |
60 | 59 |
|
61 |
private static Logger logger = LoggerFactory.getLogger(CheckSOAndArquitectureExtension.class); |
|
62 |
public void initialize() { |
|
63 |
// Do nothing |
|
64 |
} |
|
60 |
private static final Logger logger = LoggerFactory.getLogger(CheckSOAndArquitectureExtension.class); |
|
65 | 61 |
|
66 |
public void execute(String actionCommand) { |
|
67 |
// Do nothing |
|
62 |
@Override |
|
63 |
public void initialize() { |
|
64 |
// Do nothing |
|
65 |
} |
|
68 | 66 |
|
69 |
} |
|
67 |
@Override |
|
68 |
public void execute(String actionCommand) { |
|
69 |
// Do nothing |
|
70 | 70 |
|
71 |
public boolean isEnabled() { |
|
72 |
return false; |
|
73 |
} |
|
71 |
} |
|
74 | 72 |
|
75 |
public boolean isVisible() { |
|
76 |
return false; |
|
77 |
} |
|
73 |
@Override |
|
74 |
public boolean isEnabled() { |
|
75 |
return false; |
|
76 |
} |
|
78 | 77 |
|
79 |
public void postInitialize() { |
|
80 |
PluginsManager pluginManager = PluginsLocator.getManager(); |
|
81 |
pluginManager.addStartupTask("CheckOsAndArquitectre", this, true, 100); |
|
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 |
try { |
|
97 |
PackageInfo[] pkgs = installmgr.getInstalledPackages(); |
|
98 |
for (PackageInfo pkg : pkgs) { |
|
99 |
if (!InstallerManager.ARCH.ALL.equalsIgnoreCase(pkg.getArchitecture()) && !installmgr.getArchitecture().equalsIgnoreCase( |
|
100 |
pkg.getArchitecture())) { |
|
101 |
mismatchs.add(pkg); |
|
102 |
} |
|
103 |
if (!InstallerManager.OS.ALL.equalsIgnoreCase(pkg.getOperatingSystem()) && !installmgr.getOperatingSystem().equalsIgnoreCase( |
|
104 |
pkg.getOperatingSystem())) { |
|
105 |
mismatchs.add(pkg); |
|
106 |
} |
|
107 |
} |
|
108 |
} catch (Throwable e) { |
|
109 |
logger.info("Can't get installed packages.", e); |
|
82 | 110 |
} |
83 |
|
|
84 |
public void run() { |
|
85 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
86 |
InstallerManager installmgr = InstallerLocator.getInstallerManager(); |
|
87 |
PluginsManager pluginmgr = PluginsLocator.getManager(); |
|
111 |
if (mismatchs.isEmpty()) { |
|
112 |
return; |
|
113 |
} |
|
88 | 114 |
|
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(); |
|
115 |
StringBuilder buffer = new StringBuilder(); |
|
116 |
Iterator<PackageInfo> it = mismatchs.iterator(); |
|
117 |
while (it.hasNext()) { |
|
118 |
PackageInfo pkg = it.next(); |
|
114 | 119 |
buffer.append(pkg.getName()); |
115 | 120 |
buffer.append(" ("); |
116 | 121 |
buffer.append(pkg.getOperatingSystem()); |
117 | 122 |
buffer.append("/"); |
118 | 123 |
buffer.append(pkg.getArchitecture()); |
119 | 124 |
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";
|
|
125 |
buffer.append("<br>\n");
|
|
126 |
}
|
|
127 |
String template = "<html>"
|
|
128 |
+ "<p>Packages are installed that are not compatible with your system.</p>\n"
|
|
129 |
+ "<br>\n"
|
|
130 |
+ "$(PACKAGES)"
|
|
131 |
+ "<br>\n"
|
|
132 |
+ "<p>Some are not specific to your system or architecture.</p>\n"
|
|
133 |
+ "<br>\n"
|
|
134 |
+ "<p>You may need to configure a 32-bit Java environment\n"
|
|
135 |
+ "for the proper functioning of gvSIG.</p>\n"
|
|
136 |
+ "</html>\n";
|
|
132 | 137 |
|
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 |
} |
|
138 |
try { |
|
139 |
String fname = "i18n/" + application.translate("_filename_warning_architecture_or_os_mismatch"); |
|
140 |
URL res = this.getClass().getClassLoader().getResource(fname); |
|
141 |
template = FileUtils.readFileToString(new File(res.getFile())); |
|
142 |
} catch (Throwable e) { |
|
143 |
logger.info("Can't get template, use default.", e); |
|
144 |
} |
|
147 | 145 |
|
148 |
public class ShowMessageControler extends ShowMessageView { |
|
149 |
/** |
|
150 |
* |
|
151 |
*/ |
|
152 |
private static final long serialVersionUID = 2641062720310466029L; |
|
146 |
String msg = template.replaceAll("[$][(]PACKAGES[)]", buffer.toString()); |
|
147 |
msg = msg.replaceAll("[%]PACKAGES[%]", buffer.toString()); |
|
148 |
msg = msg.replaceAll("[$]PACKAGES", buffer.toString()); |
|
153 | 149 |
|
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(); |
|
150 |
application.showDialog(new ShowMessageControler(msg), "_Warning"); |
|
151 |
} |
|
177 | 152 |
|
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); |
|
153 |
public class ShowMessageControler extends ShowMessageView { |
|
199 | 154 |
|
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 |
} |
|
155 |
/** |
|
156 |
* |
|
157 |
*/ |
|
158 |
private static final long serialVersionUID = 2641062720310466029L; |
|
209 | 159 |
|
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 |
} |
|
160 |
public ShowMessageControler(String message) { |
|
161 |
super(); |
|
162 |
this.messaje.setContentType("text/html"); |
|
163 |
this.messaje.setText(message); |
|
164 |
this.closeButton.addActionListener(new ActionListener() { |
|
165 |
@Override |
|
166 |
public void actionPerformed(ActionEvent arg0) { |
|
167 |
close(); |
|
168 |
} |
|
169 |
}); |
|
170 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
171 |
this.closeButton.setText(application.translate("Close")); |
|
172 |
} |
|
216 | 173 |
|
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 |
} |
|
174 |
public void close() { |
|
175 |
this.setVisible(false); |
|
176 |
} |
|
223 | 177 |
|
224 |
}
|
|
178 |
}
|
|
225 | 179 |
|
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) { |
|
180 |
public class ShowMessageView extends JPanel { |
|
181 |
|
|
182 |
private static final long serialVersionUID = 8291970039773969840L; |
|
183 |
JTextPane messaje = new JTextPane(); |
|
184 |
JButton closeButton = new JButton(); |
|
185 |
|
|
186 |
/** |
|
187 |
* Default constructor |
|
188 |
*/ |
|
189 |
public ShowMessageView() { |
|
190 |
initializePanel(); |
|
191 |
} |
|
192 |
|
|
193 |
/** |
|
194 |
* Adds fill components to empty cells in the first row and first column |
|
195 |
* of the grid. This ensures that the grid spacing will be the same as |
|
196 |
* shown in the designer. |
|
197 |
* |
|
198 |
* @param cols an array of column indices in the first row where fill |
|
199 |
* components should be added. |
|
200 |
* @param rows an array of row indices in the first column where fill |
|
201 |
* components should be added. |
|
202 |
*/ |
|
203 |
private void addFillComponents(Container panel, int[] cols, int[] rows) { |
|
204 |
Dimension filler = new Dimension(10, 10); |
|
205 |
|
|
206 |
boolean filled_cell_11 = false; |
|
207 |
CellConstraints cc = new CellConstraints(); |
|
208 |
if (cols.length > 0 && rows.length > 0) { |
|
209 |
if (cols[0] == 1 && rows[0] == 1) { |
|
210 |
/** |
|
211 |
* add a rigid area |
|
212 |
*/ |
|
213 |
panel.add(Box.createRigidArea(filler), cc.xy(1, 1)); |
|
214 |
filled_cell_11 = true; |
|
215 |
} |
|
216 |
} |
|
217 |
|
|
218 |
for (int index = 0; index < cols.length; index++) { |
|
219 |
if (cols[index] == 1 && filled_cell_11) { |
|
220 |
continue; |
|
221 |
} |
|
222 |
panel.add(Box.createRigidArea(filler), cc.xy(cols[index], 1)); |
|
223 |
} |
|
224 |
|
|
225 |
for (int index = 0; index < rows.length; index++) { |
|
226 |
if (rows[index] == 1 && filled_cell_11) { |
|
227 |
continue; |
|
228 |
} |
|
229 |
panel.add(Box.createRigidArea(filler), cc.xy(1, rows[index])); |
|
230 |
} |
|
231 |
|
|
232 |
} |
|
233 |
|
|
234 |
/** |
|
235 |
* Method for recalculating the component orientation for right-to-left |
|
236 |
* Locales. |
|
237 |
* |
|
238 |
* @param orientation the component orientation to be applied |
|
239 |
*/ |
|
240 |
@Override |
|
241 |
public void applyComponentOrientation(ComponentOrientation orientation) { |
|
234 | 242 |
// Not yet implemented... |
235 |
// I18NUtils.applyComponentOrientation(this, orientation);
|
|
236 |
super.applyComponentOrientation(orientation);
|
|
237 |
}
|
|
243 |
// I18NUtils.applyComponentOrientation(this, orientation);
|
|
244 |
super.applyComponentOrientation(orientation);
|
|
245 |
}
|
|
238 | 246 |
|
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);
|
|
247 |
public JPanel createPanel() {
|
|
248 |
JPanel jpanel1 = new JPanel();
|
|
249 |
FormLayout formlayout1 = new FormLayout(
|
|
250 |
"FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE",
|
|
251 |
"CENTER:DEFAULT:NONE,CENTER:DEFAULT:GROW(1.0),CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE");
|
|
252 |
CellConstraints cc = new CellConstraints();
|
|
253 |
jpanel1.setLayout(formlayout1);
|
|
246 | 254 |
|
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 |
JScrollPane jscrollpane1 = new JScrollPane();
|
|
256 |
jscrollpane1.setViewportView(messaje);
|
|
257 |
jscrollpane1
|
|
258 |
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
|
259 |
jscrollpane1
|
|
260 |
.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
|
261 |
jpanel1.add(jscrollpane1, new CellConstraints(2, 2, 3, 1,
|
|
262 |
CellConstraints.DEFAULT, CellConstraints.FILL));
|
|
255 | 263 |
|
256 |
closeButton.setActionCommand("JButton");
|
|
257 |
closeButton.setText("JButton");
|
|
258 |
jpanel1.add(closeButton, cc.xy(3, 4));
|
|
264 |
closeButton.setActionCommand("JButton");
|
|
265 |
closeButton.setText("JButton");
|
|
266 |
jpanel1.add(closeButton, cc.xy(3, 4));
|
|
259 | 267 |
|
260 |
addFillComponents(jpanel1, new int[] { 1, 2, 3, 4, 5 }, new int[] {
|
|
261 |
1, 2, 3, 4, 5 });
|
|
262 |
return jpanel1;
|
|
263 |
}
|
|
268 |
addFillComponents(jpanel1, new int[]{1, 2, 3, 4, 5}, new int[]{
|
|
269 |
1, 2, 3, 4, 5});
|
|
270 |
return jpanel1;
|
|
271 |
}
|
|
264 | 272 |
|
265 |
/**
|
|
266 |
* Initializer
|
|
267 |
*/
|
|
268 |
protected void initializePanel() {
|
|
269 |
setLayout(new BorderLayout());
|
|
270 |
add(createPanel(), BorderLayout.CENTER);
|
|
271 |
}
|
|
273 |
/**
|
|
274 |
* Initializer
|
|
275 |
*/
|
|
276 |
protected void initializePanel() {
|
|
277 |
setLayout(new BorderLayout());
|
|
278 |
add(createPanel(), BorderLayout.CENTER);
|
|
279 |
}
|
|
272 | 280 |
|
273 |
}
|
|
281 |
}
|
|
274 | 282 |
|
275 | 283 |
} |
Also available in: Unified diff