Revision 39413

View differences:

branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/app/extension/CheckSOAndArquitectureExtension.java
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("<br>\n");
89
		}
90
		String template = "<html>"
91
				+ "<p>Packages are installed that are not compatible with your system.</p>\n"
92
				+ "<br>\n"
93
				+ "$(PACKAGES)"
94
				+ "<br>\n"
95
				+ "<p>Some are not specific to your system or architecture.</p>\n"
96
				+ "<br>\n" 
97
				+ "<p>You may need to configure a 32-bit Java environment\n"
98
				+ "for the proper functioning of gvSIG.</p>\n" 
99
				+ "</html>\n";
100

  
101
		try {
102
			String fname = application.translate("filename_warning_architecture_or_os_mismatch");
103
			URL res = this.getClass().getClassLoader().getResource(fname);
104
			template = FileUtils.readFileToString(new File(res.getFile()));
105
		} catch (Throwable e) {
106
			logger.info("Can't get template, use default.",e);
107
		}
108
		
109
		String msg = template.replaceAll("[$][(]PACKAGES[)]", buffer.toString());
110
		msg = msg.replaceAll("[%]PACKAGES[%]", buffer.toString());
111
		msg = msg.replaceAll("[$]PACKAGES", buffer.toString());
112
		
113
		application.showDialog(new ShowMessageControler(msg), "_Warning");
114
	}
115

  
116
	public class ShowMessageControler extends ShowMessageView {
117
		/**
118
		 * 
119
		 */
120
		private static final long serialVersionUID = 2641062720310466029L;
121

  
122
		public ShowMessageControler(String message) {
123
			super();
124
			this.messaje.setContentType("text/html");
125
			this.messaje.setText(message);
126
			this.closeButton.addActionListener(new ActionListener() {
127
				public void actionPerformed(ActionEvent arg0) {
128
					close();
129
				}
130
			});
131
			ApplicationManager application = ApplicationLocator.getManager();
132
			this.closeButton.setText(application.translate("Close"));
133
		}
134
		
135
		public void close() {
136
			this.setVisible(false);
137
		}
138
		
139
	}
140
	
141
	public class ShowMessageView extends JPanel {
142
		private static final long serialVersionUID = 8291970039773969840L;
143
		JTextPane messaje = new JTextPane();
144
		JButton closeButton = new JButton();
145

  
146
		/**
147
		 * Default constructor
148
		 */
149
		public ShowMessageView() {
150
			initializePanel();
151
		}
152
		
153
		/**
154
		 * Adds fill components to empty cells in the first row and first column
155
		 * of the grid. This ensures that the grid spacing will be the same as
156
		 * shown in the designer.
157
		 * 
158
		 * @param cols
159
		 *            an array of column indices in the first row where fill
160
		 *            components should be added.
161
		 * @param rows
162
		 *            an array of row indices in the first column where fill
163
		 *            components should be added.
164
		 */
165
		private void addFillComponents(Container panel, int[] cols, int[] rows) {
166
			Dimension filler = new Dimension(10, 10);
167

  
168
			boolean filled_cell_11 = false;
169
			CellConstraints cc = new CellConstraints();
170
			if (cols.length > 0 && rows.length > 0) {
171
				if (cols[0] == 1 && rows[0] == 1) {
172
					/** add a rigid area */
173
					panel.add(Box.createRigidArea(filler), cc.xy(1, 1));
174
					filled_cell_11 = true;
175
				}
176
			}
177

  
178
			for (int index = 0; index < cols.length; index++) {
179
				if (cols[index] == 1 && filled_cell_11) {
180
					continue;
181
				}
182
				panel.add(Box.createRigidArea(filler), cc.xy(cols[index], 1));
183
			}
184

  
185
			for (int index = 0; index < rows.length; index++) {
186
				if (rows[index] == 1 && filled_cell_11) {
187
					continue;
188
				}
189
				panel.add(Box.createRigidArea(filler), cc.xy(1, rows[index]));
190
			}
191

  
192
		}
193

  
194
		/**
195
		 * Method for recalculating the component orientation for right-to-left
196
		 * Locales.
197
		 * 
198
		 * @param orientation
199
		 *            the component orientation to be applied
200
		 */
201
		public void applyComponentOrientation(ComponentOrientation orientation) {
202
			// Not yet implemented...
203
			// I18NUtils.applyComponentOrientation(this, orientation);
204
			super.applyComponentOrientation(orientation);
205
		}
206

  
207
		public JPanel createPanel() {
208
			JPanel jpanel1 = new JPanel();
209
			FormLayout formlayout1 = new FormLayout(
210
					"FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE",
211
					"CENTER:DEFAULT:NONE,CENTER:DEFAULT:GROW(1.0),CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE");
212
			CellConstraints cc = new CellConstraints();
213
			jpanel1.setLayout(formlayout1);
214

  
215
			JScrollPane jscrollpane1 = new JScrollPane();
216
			jscrollpane1.setViewportView(messaje);
217
			jscrollpane1
218
					.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
219
			jscrollpane1
220
					.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
221
			jpanel1.add(jscrollpane1, new CellConstraints(2, 2, 3, 1,
222
					CellConstraints.DEFAULT, CellConstraints.FILL));
223

  
224
			closeButton.setActionCommand("JButton");
225
			closeButton.setText("JButton");
226
			jpanel1.add(closeButton, cc.xy(3, 4));
227

  
228
			addFillComponents(jpanel1, new int[] { 1, 2, 3, 4, 5 }, new int[] {
229
					1, 2, 3, 4, 5 });
230
			return jpanel1;
231
		}
232

  
233
		/**
234
		 * Initializer
235
		 */
236
		protected void initializePanel() {
237
			setLayout(new BorderLayout());
238
			add(createPanel(), BorderLayout.CENTER);
239
		}
240

  
241
	}
242

  
243
}
0 244

  

Also available in: Unified diff