svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.installer / org.gvsig.installer.swing / org.gvsig.installer.swing.impl / src / main / java / org / gvsig / installer / swing / impl / execution / panel / PackagesTablePanel.java @ 43088
History | View | Annotate | Download (13.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
|
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 |
/*
|
25 |
* AUTHORS (In addition to CIT):
|
26 |
* 2010 {Prodevelop} {Task}
|
27 |
*/
|
28 |
|
29 |
package org.gvsig.installer.swing.impl.execution.panel; |
30 |
|
31 |
import java.awt.Color; |
32 |
import java.awt.GridBagConstraints; |
33 |
import java.awt.GridBagLayout; |
34 |
import java.awt.Insets; |
35 |
import java.awt.event.MouseEvent; |
36 |
import java.awt.event.MouseListener; |
37 |
import java.io.IOException; |
38 |
import java.io.InputStream; |
39 |
import java.net.URL; |
40 |
import java.util.List; |
41 |
import java.util.Locale; |
42 |
import java.util.logging.Level; |
43 |
import java.util.logging.Logger; |
44 |
|
45 |
import javax.swing.JEditorPane; |
46 |
import javax.swing.JPanel; |
47 |
import javax.swing.JScrollPane; |
48 |
import javax.swing.JTable; |
49 |
import javax.swing.event.ListSelectionEvent; |
50 |
import javax.swing.event.ListSelectionListener; |
51 |
import javax.swing.table.TableColumnModel; |
52 |
import org.apache.commons.io.FileUtils; |
53 |
import org.apache.commons.io.IOUtils; |
54 |
import org.apache.commons.lang3.StringUtils; |
55 |
|
56 |
import org.gvsig.installer.lib.api.PackageInfo; |
57 |
import org.gvsig.installer.swing.api.SwingInstallerLocator; |
58 |
import org.gvsig.installer.swing.api.SwingInstallerManager; |
59 |
import org.gvsig.installer.swing.impl.execution.panel.filters.NameDescriptionOrCodeFilter; |
60 |
import org.gvsig.installer.swing.impl.execution.panel.filters.PackageFilter; |
61 |
import org.gvsig.installer.swing.impl.execution.panel.model.PackagesTableModel; |
62 |
import org.gvsig.installer.swing.impl.execution.panel.model.PackagesTableModel.PackageOfficialRecommended; |
63 |
import org.gvsig.installer.swing.impl.execution.panel.model.PackagesTableModel.PackageOsAndArchitecture; |
64 |
import org.gvsig.installer.swing.impl.execution.panel.model.PackagesTableModel.PackageStatus; |
65 |
import org.gvsig.installer.swing.impl.execution.panel.renderers.AbstractTablePackageInfoCellRenderer; |
66 |
import org.gvsig.installer.swing.impl.execution.panel.renderers.InstallStatusCellEditor; |
67 |
import org.gvsig.installer.swing.impl.execution.panel.renderers.InstallStatusCellRenderer; |
68 |
import org.gvsig.installer.swing.impl.execution.panel.renderers.InstalledPackageCellRenderer; |
69 |
import org.gvsig.installer.swing.impl.execution.panel.renderers.OfficialRecommendedCellRenderer; |
70 |
import org.gvsig.installer.swing.impl.execution.panel.renderers.OsAndArchitectureCellRenderer; |
71 |
|
72 |
/**
|
73 |
* @author gvSIG Team
|
74 |
* @version $Id$
|
75 |
*/
|
76 |
public class PackagesTablePanel extends JPanel implements ListSelectionListener { |
77 |
|
78 |
private static final long serialVersionUID = 8156088357208685689L; |
79 |
protected SwingInstallerManager swingInstallerManager = null; |
80 |
|
81 |
private JScrollPane descriptionScrollPane; |
82 |
private JEditorPane descriptionTextEditor; |
83 |
private JScrollPane pluginsScrollPane; |
84 |
private JTable pluginsTable; |
85 |
private PackagePropertiesFilterPanel filterPanel;
|
86 |
private FastFilterButtonsPanel fastFilterPanel;
|
87 |
private SelectPackagesPanel selectPackagesPanel;
|
88 |
|
89 |
public PackagesTablePanel(SelectPackagesPanel selectPackagesPanel) {
|
90 |
super();
|
91 |
swingInstallerManager = SwingInstallerLocator |
92 |
.getSwingInstallerManager(); |
93 |
this.selectPackagesPanel = selectPackagesPanel;
|
94 |
initComponents(); |
95 |
pluginsTable.getSelectionModel().addListSelectionListener(this);
|
96 |
pluginsTable.setDefaultRenderer(PackageOfficialRecommended.class, |
97 |
new OfficialRecommendedCellRenderer());
|
98 |
pluginsTable.setDefaultRenderer(PackageStatus.class, |
99 |
new InstallStatusCellRenderer());
|
100 |
pluginsTable.setDefaultEditor(PackageStatus.class, |
101 |
new InstallStatusCellEditor(this.selectPackagesPanel)); |
102 |
AbstractTablePackageInfoCellRenderer ipcr = new InstalledPackageCellRenderer();
|
103 |
pluginsTable.setDefaultRenderer(PackageOsAndArchitecture.class, |
104 |
new OsAndArchitectureCellRenderer());
|
105 |
pluginsTable.setDefaultRenderer(String.class, ipcr);
|
106 |
pluginsTable.setDefaultRenderer(Number.class, ipcr);
|
107 |
pluginsTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
|
108 |
} |
109 |
|
110 |
private void initComponents() { |
111 |
java.awt.GridBagConstraints gridBagConstraints; |
112 |
|
113 |
pluginsTable = new JTable(); |
114 |
|
115 |
MouseListener mouseListener = new MyMouseListener(); |
116 |
pluginsTable.addMouseListener(mouseListener); |
117 |
|
118 |
pluginsScrollPane = new JScrollPane(pluginsTable); |
119 |
|
120 |
descriptionTextEditor = new JEditorPane(); |
121 |
descriptionTextEditor.setBackground(Color.WHITE);
|
122 |
descriptionTextEditor.setEditable(false);
|
123 |
descriptionTextEditor.setContentType("text/html");
|
124 |
|
125 |
descriptionScrollPane = new JScrollPane(descriptionTextEditor); |
126 |
|
127 |
filterPanel = new PackagePropertiesFilterPanel(this); |
128 |
filterPanel.setVisible(true);
|
129 |
|
130 |
fastFilterPanel = new FastFilterButtonsPanel(this); |
131 |
|
132 |
setLayout(new GridBagLayout()); |
133 |
|
134 |
// left panel filter
|
135 |
gridBagConstraints = new GridBagConstraints(); |
136 |
gridBagConstraints.fill = GridBagConstraints.BOTH;
|
137 |
gridBagConstraints.gridx = 0;
|
138 |
gridBagConstraints.gridy = 1;
|
139 |
gridBagConstraints.weightx = 0.13;
|
140 |
gridBagConstraints.weighty = 1;
|
141 |
gridBagConstraints.gridheight = 2;
|
142 |
gridBagConstraints.insets = new Insets(0, 2, 2, 2); |
143 |
add(filterPanel, gridBagConstraints); |
144 |
|
145 |
// fast filters buttons panel
|
146 |
gridBagConstraints = new GridBagConstraints(); |
147 |
gridBagConstraints.fill = GridBagConstraints.BOTH;
|
148 |
gridBagConstraints.gridx = 1;
|
149 |
gridBagConstraints.gridy = 0;
|
150 |
gridBagConstraints.weightx = 0.75;
|
151 |
gridBagConstraints.weighty = 0;
|
152 |
gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
153 |
add(fastFilterPanel, gridBagConstraints); |
154 |
|
155 |
// plugins scroll panel
|
156 |
gridBagConstraints = new GridBagConstraints(); |
157 |
gridBagConstraints.fill = GridBagConstraints.BOTH;
|
158 |
gridBagConstraints.gridx = 1;
|
159 |
gridBagConstraints.gridy = 1;
|
160 |
gridBagConstraints.weightx = 0.75;
|
161 |
gridBagConstraints.weighty = 0.7;
|
162 |
gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
163 |
add(pluginsScrollPane, gridBagConstraints); |
164 |
|
165 |
// description panel
|
166 |
gridBagConstraints = new GridBagConstraints(); |
167 |
gridBagConstraints.gridx = 1;
|
168 |
gridBagConstraints.gridy = 2;
|
169 |
gridBagConstraints.fill = GridBagConstraints.BOTH;
|
170 |
gridBagConstraints.weightx = 0.75;
|
171 |
gridBagConstraints.weighty = 0.3;
|
172 |
gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
173 |
add(descriptionScrollPane, gridBagConstraints); |
174 |
|
175 |
// filterPanel.setInitialFilter();
|
176 |
} |
177 |
|
178 |
public void resetFilter() { |
179 |
filterPanel.resetPanel(); |
180 |
valueChanged(); |
181 |
} |
182 |
|
183 |
public void selectPackages() { |
184 |
PackagesTableModel pluginsTableModel = (PackagesTableModel) pluginsTable |
185 |
.getModel(); |
186 |
pluginsTableModel.selectDefaultPackages(); |
187 |
} |
188 |
|
189 |
public void setTableModel(PackagesTableModel pluginsTableModel) { |
190 |
pluginsTable.setModel(pluginsTableModel); |
191 |
pluginsTableModel.fireTableDataChanged(); |
192 |
TableColumnModel tableColumnModel = pluginsTable.getColumnModel();
|
193 |
tableColumnModel.getColumn(0).setPreferredWidth(20); |
194 |
tableColumnModel.getColumn(1).setPreferredWidth(20); |
195 |
tableColumnModel.getColumn(2).setPreferredWidth(20); |
196 |
tableColumnModel.getColumn(3).setPreferredWidth(225); |
197 |
tableColumnModel.getColumn(4).setPreferredWidth(130); |
198 |
tableColumnModel.getColumn(5).setPreferredWidth(53); |
199 |
|
200 |
} |
201 |
|
202 |
public List<PackageInfo> getPackagesToInstall() { |
203 |
return ((PackagesTableModel) pluginsTable.getModel())
|
204 |
.getPackagesToInstall(); |
205 |
} |
206 |
|
207 |
public boolean isPackageSelected() { |
208 |
return ((PackagesTableModel) pluginsTable.getModel())
|
209 |
.hasAnyPackageSelected(); |
210 |
} |
211 |
|
212 |
private class HTMLCoder { |
213 |
private StringBuffer buffer = new StringBuffer(); |
214 |
|
215 |
public String toString() { |
216 |
return buffer.toString();
|
217 |
} |
218 |
|
219 |
public void addTitle(String title) { |
220 |
if( title == null ) { |
221 |
return;
|
222 |
} |
223 |
buffer.append("<h1>");
|
224 |
buffer.append(title); |
225 |
buffer.append("</h1>");
|
226 |
} |
227 |
|
228 |
public void addParagraph(Object text) { |
229 |
if( text == null ) { |
230 |
return;
|
231 |
} |
232 |
String t = text.toString().replaceAll("\\n", "<br>\n"); |
233 |
buffer.append("<p>");
|
234 |
buffer.append(t); |
235 |
buffer.append("</p>");
|
236 |
} |
237 |
|
238 |
public void addBeginList() { |
239 |
buffer.append("<ul>");
|
240 |
} |
241 |
|
242 |
public void addEndList() { |
243 |
buffer.append("</ul>");
|
244 |
} |
245 |
|
246 |
public void addListItem(String label, Object value) { |
247 |
if( value == null ) { |
248 |
return;
|
249 |
} |
250 |
buffer.append("<li>");
|
251 |
buffer.append(label); |
252 |
buffer.append(": <i>");
|
253 |
buffer.append(value.toString()); |
254 |
buffer.append("</i></li>");
|
255 |
} |
256 |
|
257 |
public void addListItem(String label, URL value) { |
258 |
if( value == null ) { |
259 |
return;
|
260 |
} |
261 |
buffer.append("<li>");
|
262 |
buffer.append(label); |
263 |
buffer.append(": <a href=\"");
|
264 |
buffer.append(value.toString()); |
265 |
buffer.append("\">");
|
266 |
buffer.append(value.toString()); |
267 |
buffer.append("</a></li>");
|
268 |
} |
269 |
|
270 |
} |
271 |
public void valueChanged(ListSelectionEvent e) { |
272 |
valueChanged(); |
273 |
} |
274 |
|
275 |
public void valueChanged() { |
276 |
int row = pluginsTable.getSelectedRow();
|
277 |
if (row < 0) { |
278 |
descriptionTextEditor.setText("<p></p>");
|
279 |
return;
|
280 |
} |
281 |
|
282 |
PackageInfo pkginfo = ((PackagesTableModel) pluginsTable.getModel()).getPackageInfoAt(row); |
283 |
descriptionTextEditor.setText(getFullDescriptionAsHTML(pkginfo)); |
284 |
|
285 |
// get the view area to the top-left corner
|
286 |
descriptionTextEditor.setCaretPosition(0);
|
287 |
|
288 |
} |
289 |
|
290 |
public String getFullDescriptionAsHTML(PackageInfo pkginfo) { |
291 |
String html = null; |
292 |
String lang = Locale.getDefault().getLanguage(); |
293 |
InputStream res = this.getClass().getClassLoader().getResourceAsStream("org/gvsig/installer/swing/impl/pkg_description_"+lang+".html"); |
294 |
if( res == null ) { |
295 |
res = this.getClass().getClassLoader().getResourceAsStream("org/gvsig/installer/swing/impl/pkg_description_en.html"); |
296 |
} |
297 |
if( res != null ) { |
298 |
try {
|
299 |
List<String> lines = IOUtils.readLines(res); |
300 |
html = StringUtils.join(lines,null);
|
301 |
res.close(); |
302 |
} catch (Exception ex) { |
303 |
// Do nothing
|
304 |
} |
305 |
} |
306 |
if( html == null ) { |
307 |
HTMLCoder coder = new HTMLCoder();
|
308 |
coder.addTitle(pkginfo.getName()); |
309 |
coder.addParagraph(pkginfo.getDescription()); |
310 |
coder.addBeginList(); |
311 |
coder.addListItem("code", pkginfo.getCode());
|
312 |
coder.addListItem("Organization", pkginfo.getOwner());
|
313 |
coder.addListItem("Organization URL", pkginfo.getOwnerURL());
|
314 |
coder.addListItem("Sources", pkginfo.getSourcesURL());
|
315 |
coder.addListItem("Dependencies", pkginfo.getDependencies());
|
316 |
coder.addListItem("Categories", pkginfo.getCategoriesAsString());
|
317 |
coder.addListItem("Official", pkginfo.isOfficial());
|
318 |
coder.addEndList(); |
319 |
return coder.toString();
|
320 |
} |
321 |
|
322 |
html = html.replace("${gvsig.package.info.name}",pkginfo.getName());
|
323 |
html = html.replace("${gvsig.package.info.description}",pkginfo.getDescription());
|
324 |
html = html.replace("${gvsig.package.info.official}",pkginfo.isOfficial()?"true":"false"); |
325 |
html = html.replace("${gvsig.package.info.official.label}",pkginfo.isOfficial()?"official":"community"); |
326 |
html = html.replace("${gvsig.package.info.owner}",pkginfo.getOwner());
|
327 |
html = html.replace("${gvsig.package.info.webURL}",pkginfo.getWebURL()==null? "":pkginfo.getWebURL().toString()); |
328 |
html = html.replace("${gvsig.package.info.categories}",pkginfo.getCategoriesAsString());
|
329 |
html = html.replace("${gvsig.package.info.sourcesURL}",pkginfo.getSourcesURL()==null?"":pkginfo.getSourcesURL().toString()); |
330 |
html = html.replace("${gvsig.package.info.code}",pkginfo.getCode());
|
331 |
html = html.replace("${gvsig.package.info.dependencies}",pkginfo.getDependencies()==null?"":pkginfo.getDependencies().toString()); |
332 |
html = html.replace("${gvsig.package.info.version}",pkginfo.getVersion()==null?"":pkginfo.getVersion().toString()); |
333 |
html = html.replace("${gvsig.package.info.state}",pkginfo.getState());
|
334 |
html = html.replace("${gvsig.package.info.operatingSystem}",pkginfo.getOperatingSystem());
|
335 |
html = html.replace("${gvsig.package.info.architecture}",pkginfo.getArchitecture());
|
336 |
html = html.replace("${gvsig.package.info.javaVM}",pkginfo.getJavaVM());
|
337 |
return html;
|
338 |
} |
339 |
|
340 |
public void setFilter(PackageFilter filter) { |
341 |
PackagesTableModel pluginsTableModel = (PackagesTableModel) pluginsTable |
342 |
.getModel(); |
343 |
pluginsTableModel.setFilter(filter); |
344 |
selectPackagesPanel.updatePanel(); |
345 |
} |
346 |
|
347 |
public void setFilter(NameDescriptionOrCodeFilter filter) { |
348 |
PackagesTableModel pluginsTableModel = (PackagesTableModel) pluginsTable |
349 |
.getModel(); |
350 |
pluginsTableModel.setFilter(filter); |
351 |
selectPackagesPanel.updatePanel(); |
352 |
} |
353 |
|
354 |
private class MyMouseListener implements MouseListener { |
355 |
|
356 |
public void mouseClicked(MouseEvent e) { |
357 |
selectPackagesPanel.checkIfPluginSelected(); |
358 |
} |
359 |
|
360 |
public void mouseEntered(MouseEvent e) { |
361 |
} |
362 |
|
363 |
public void mouseExited(MouseEvent e) { |
364 |
} |
365 |
|
366 |
public void mousePressed(MouseEvent e) { |
367 |
} |
368 |
|
369 |
public void mouseReleased(MouseEvent e) { |
370 |
} |
371 |
} |
372 |
|
373 |
public SelectPackagesPanel getSelectPackagesPanel() {
|
374 |
return this.selectPackagesPanel; |
375 |
} |
376 |
|
377 |
public void clearAllPanels() { |
378 |
filterPanel.resetPanel(); |
379 |
descriptionTextEditor.setText("");
|
380 |
fastFilterPanel.resetPanel(); |
381 |
} |
382 |
|
383 |
public void resetPanel() { |
384 |
filterPanel.resetPanel(); |
385 |
descriptionTextEditor.setText("");
|
386 |
} |
387 |
|
388 |
/**
|
389 |
*
|
390 |
*/
|
391 |
public void setInitialFilter() { |
392 |
filterPanel.setInitialFilter(); |
393 |
} |
394 |
|
395 |
} |