svn-gvsig-desktop / tags / v2_0_0_Build_2061 / applications / appgvSIG / src / org / gvsig / app / extension / CheckSOAndArquitectureExtension.java @ 39431
History | View | Annotate | Download (7.42 KB)
1 |
package org.gvsig.app.extension; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.ComponentOrientation; |
5 |
import java.awt.Container; |
6 |
import java.awt.Dimension; |
7 |
import java.awt.event.ActionEvent; |
8 |
import java.awt.event.ActionListener; |
9 |
import java.io.File; |
10 |
import java.net.URL; |
11 |
import java.util.HashSet; |
12 |
import java.util.Iterator; |
13 |
import java.util.Set; |
14 |
|
15 |
import javax.swing.Box; |
16 |
import javax.swing.JButton; |
17 |
import javax.swing.JPanel; |
18 |
import javax.swing.JScrollPane; |
19 |
import javax.swing.JTextPane; |
20 |
|
21 |
import org.apache.commons.io.FileUtils; |
22 |
import org.gvsig.andami.PluginsLocator; |
23 |
import org.gvsig.andami.PluginsManager; |
24 |
import org.gvsig.andami.plugins.Extension; |
25 |
import org.gvsig.app.ApplicationLocator; |
26 |
import org.gvsig.app.ApplicationManager; |
27 |
import org.gvsig.installer.lib.api.InstallerLocator; |
28 |
import org.gvsig.installer.lib.api.InstallerManager; |
29 |
import org.gvsig.installer.lib.api.PackageInfo; |
30 |
import org.slf4j.Logger; |
31 |
import org.slf4j.LoggerFactory; |
32 |
|
33 |
import com.jgoodies.forms.layout.CellConstraints; |
34 |
import com.jgoodies.forms.layout.FormLayout; |
35 |
|
36 |
public class CheckSOAndArquitectureExtension extends Extension { |
37 |
|
38 |
private static Logger logger = LoggerFactory.getLogger(CheckSOAndArquitectureExtension.class); |
39 |
public void initialize() { |
40 |
// Do nothing
|
41 |
} |
42 |
|
43 |
public void execute(String actionCommand) { |
44 |
// Do nothing
|
45 |
|
46 |
} |
47 |
|
48 |
public boolean isEnabled() { |
49 |
return false; |
50 |
} |
51 |
|
52 |
public boolean isVisible() { |
53 |
return false; |
54 |
} |
55 |
|
56 |
public void postInitialize() { |
57 |
ApplicationManager application = ApplicationLocator.getManager(); |
58 |
InstallerManager installmgr = InstallerLocator.getInstallerManager(); |
59 |
PluginsManager pluginmgr = PluginsLocator.getManager(); |
60 |
|
61 |
Set<PackageInfo> mismatchs = new HashSet<PackageInfo>(); |
62 |
try {
|
63 |
PackageInfo[] pkgs = installmgr
|
64 |
.getInstalledPackages(pluginmgr.getPluginsFolder()); |
65 |
for (int i = 0; i < pkgs.length; i++) { |
66 |
PackageInfo pkg = pkgs[i]; |
67 |
if ( !InstallerManager.ARCH.ALL.equalsIgnoreCase(pkg.getArchitecture()) && !installmgr.getArchitecture().equalsIgnoreCase(
|
68 |
pkg.getArchitecture())) { |
69 |
mismatchs.add(pkg); |
70 |
} |
71 |
if (!InstallerManager.OS.ALL.equalsIgnoreCase(pkg.getOperatingSystem()) && !installmgr.getOperatingSystem().equalsIgnoreCase(
|
72 |
pkg.getOperatingSystem())) { |
73 |
mismatchs.add(pkg); |
74 |
} |
75 |
} |
76 |
} catch (Throwable e) { |
77 |
logger.info("Can't get installed packages.",e);
|
78 |
} |
79 |
if( mismatchs.size() == 0 ) { |
80 |
return;
|
81 |
} |
82 |
|
83 |
StringBuffer buffer = new StringBuffer(); |
84 |
Iterator<PackageInfo> it = mismatchs.iterator();
|
85 |
while( it.hasNext() ) {
|
86 |
PackageInfo pkg = it.next(); |
87 |
buffer.append(pkg.getName()); |
88 |
buffer.append(" (");
|
89 |
buffer.append(pkg.getOperatingSystem()); |
90 |
buffer.append("/");
|
91 |
buffer.append(pkg.getArchitecture()); |
92 |
buffer.append(")");
|
93 |
buffer.append("<br>\n");
|
94 |
} |
95 |
String template = "<html>" |
96 |
+ "<p>Packages are installed that are not compatible with your system.</p>\n"
|
97 |
+ "<br>\n"
|
98 |
+ "$(PACKAGES)"
|
99 |
+ "<br>\n"
|
100 |
+ "<p>Some are not specific to your system or architecture.</p>\n"
|
101 |
+ "<br>\n"
|
102 |
+ "<p>You may need to configure a 32-bit Java environment\n"
|
103 |
+ "for the proper functioning of gvSIG.</p>\n"
|
104 |
+ "</html>\n";
|
105 |
|
106 |
try {
|
107 |
String fname = application.translate("filename_warning_architecture_or_os_mismatch"); |
108 |
URL res = this.getClass().getClassLoader().getResource(fname); |
109 |
template = FileUtils.readFileToString(new File(res.getFile())); |
110 |
} catch (Throwable e) { |
111 |
logger.info("Can't get template, use default.",e);
|
112 |
} |
113 |
|
114 |
String msg = template.replaceAll("[$][(]PACKAGES[)]", buffer.toString()); |
115 |
msg = msg.replaceAll("[%]PACKAGES[%]", buffer.toString());
|
116 |
msg = msg.replaceAll("[$]PACKAGES", buffer.toString());
|
117 |
|
118 |
application.showDialog(new ShowMessageControler(msg), "_Warning"); |
119 |
} |
120 |
|
121 |
public class ShowMessageControler extends ShowMessageView { |
122 |
/**
|
123 |
*
|
124 |
*/
|
125 |
private static final long serialVersionUID = 2641062720310466029L; |
126 |
|
127 |
public ShowMessageControler(String message) { |
128 |
super();
|
129 |
this.messaje.setContentType("text/html"); |
130 |
this.messaje.setText(message);
|
131 |
this.closeButton.addActionListener(new ActionListener() { |
132 |
public void actionPerformed(ActionEvent arg0) { |
133 |
close(); |
134 |
} |
135 |
}); |
136 |
ApplicationManager application = ApplicationLocator.getManager(); |
137 |
this.closeButton.setText(application.translate("Close")); |
138 |
} |
139 |
|
140 |
public void close() { |
141 |
this.setVisible(false); |
142 |
} |
143 |
|
144 |
} |
145 |
|
146 |
public class ShowMessageView extends JPanel { |
147 |
private static final long serialVersionUID = 8291970039773969840L; |
148 |
JTextPane messaje = new JTextPane(); |
149 |
JButton closeButton = new JButton(); |
150 |
|
151 |
/**
|
152 |
* Default constructor
|
153 |
*/
|
154 |
public ShowMessageView() {
|
155 |
initializePanel(); |
156 |
} |
157 |
|
158 |
/**
|
159 |
* Adds fill components to empty cells in the first row and first column
|
160 |
* of the grid. This ensures that the grid spacing will be the same as
|
161 |
* shown in the designer.
|
162 |
*
|
163 |
* @param cols
|
164 |
* an array of column indices in the first row where fill
|
165 |
* components should be added.
|
166 |
* @param rows
|
167 |
* an array of row indices in the first column where fill
|
168 |
* components should be added.
|
169 |
*/
|
170 |
private void addFillComponents(Container panel, int[] cols, int[] rows) { |
171 |
Dimension filler = new Dimension(10, 10); |
172 |
|
173 |
boolean filled_cell_11 = false; |
174 |
CellConstraints cc = new CellConstraints();
|
175 |
if (cols.length > 0 && rows.length > 0) { |
176 |
if (cols[0] == 1 && rows[0] == 1) { |
177 |
/** add a rigid area */
|
178 |
panel.add(Box.createRigidArea(filler), cc.xy(1, 1)); |
179 |
filled_cell_11 = true;
|
180 |
} |
181 |
} |
182 |
|
183 |
for (int index = 0; index < cols.length; index++) { |
184 |
if (cols[index] == 1 && filled_cell_11) { |
185 |
continue;
|
186 |
} |
187 |
panel.add(Box.createRigidArea(filler), cc.xy(cols[index], 1)); |
188 |
} |
189 |
|
190 |
for (int index = 0; index < rows.length; index++) { |
191 |
if (rows[index] == 1 && filled_cell_11) { |
192 |
continue;
|
193 |
} |
194 |
panel.add(Box.createRigidArea(filler), cc.xy(1, rows[index])); |
195 |
} |
196 |
|
197 |
} |
198 |
|
199 |
/**
|
200 |
* Method for recalculating the component orientation for right-to-left
|
201 |
* Locales.
|
202 |
*
|
203 |
* @param orientation
|
204 |
* the component orientation to be applied
|
205 |
*/
|
206 |
public void applyComponentOrientation(ComponentOrientation orientation) { |
207 |
// Not yet implemented...
|
208 |
// I18NUtils.applyComponentOrientation(this, orientation);
|
209 |
super.applyComponentOrientation(orientation);
|
210 |
} |
211 |
|
212 |
public JPanel createPanel() { |
213 |
JPanel jpanel1 = new JPanel(); |
214 |
FormLayout formlayout1 = new FormLayout(
|
215 |
"FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE",
|
216 |
"CENTER:DEFAULT:NONE,CENTER:DEFAULT:GROW(1.0),CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE");
|
217 |
CellConstraints cc = new CellConstraints();
|
218 |
jpanel1.setLayout(formlayout1); |
219 |
|
220 |
JScrollPane jscrollpane1 = new JScrollPane(); |
221 |
jscrollpane1.setViewportView(messaje); |
222 |
jscrollpane1 |
223 |
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
224 |
jscrollpane1 |
225 |
.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
226 |
jpanel1.add(jscrollpane1, new CellConstraints(2, 2, 3, 1, |
227 |
CellConstraints.DEFAULT, CellConstraints.FILL)); |
228 |
|
229 |
closeButton.setActionCommand("JButton");
|
230 |
closeButton.setText("JButton");
|
231 |
jpanel1.add(closeButton, cc.xy(3, 4)); |
232 |
|
233 |
addFillComponents(jpanel1, new int[] { 1, 2, 3, 4, 5 }, new int[] { |
234 |
1, 2, 3, 4, 5 }); |
235 |
return jpanel1;
|
236 |
} |
237 |
|
238 |
/**
|
239 |
* Initializer
|
240 |
*/
|
241 |
protected void initializePanel() { |
242 |
setLayout(new BorderLayout()); |
243 |
add(createPanel(), BorderLayout.CENTER);
|
244 |
} |
245 |
|
246 |
} |
247 |
|
248 |
} |