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