svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.installer / org.gvsig.installer.swing / org.gvsig.installer.swing.impl / src / main / java / org / gvsig / installer / swing / impl / execution / panel / PackagesTablePanel.java @ 37822
History | View | Annotate | Download (11.1 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2010 {Prodevelop} {Task}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.installer.swing.impl.execution.panel; |
29 |
|
30 |
import java.awt.Color; |
31 |
import java.awt.GridBagConstraints; |
32 |
import java.awt.GridBagLayout; |
33 |
import java.awt.Insets; |
34 |
import java.awt.event.MouseEvent; |
35 |
import java.awt.event.MouseListener; |
36 |
import java.net.URL; |
37 |
import java.util.List; |
38 |
|
39 |
import javax.swing.JEditorPane; |
40 |
import javax.swing.JPanel; |
41 |
import javax.swing.JScrollPane; |
42 |
import javax.swing.JTable; |
43 |
import javax.swing.event.ListSelectionEvent; |
44 |
import javax.swing.event.ListSelectionListener; |
45 |
import javax.swing.table.TableColumnModel; |
46 |
|
47 |
import org.gvsig.installer.lib.api.Dependencies; |
48 |
import org.gvsig.installer.lib.api.PackageInfo; |
49 |
import org.gvsig.installer.swing.api.SwingInstallerLocator; |
50 |
import org.gvsig.installer.swing.api.SwingInstallerManager; |
51 |
import org.gvsig.installer.swing.impl.execution.panel.filters.NameDescriptionOrCodeFilter; |
52 |
import org.gvsig.installer.swing.impl.execution.panel.filters.PackageFilter; |
53 |
import org.gvsig.installer.swing.impl.execution.panel.model.PackagesTableModel; |
54 |
import org.gvsig.installer.swing.impl.execution.panel.model.PackagesTableModel.PackageOfficialRecommended; |
55 |
import org.gvsig.installer.swing.impl.execution.panel.model.PackagesTableModel.PackageOsAndArchitecture; |
56 |
import org.gvsig.installer.swing.impl.execution.panel.model.PackagesTableModel.PackageStatus; |
57 |
import org.gvsig.installer.swing.impl.execution.panel.renderers.AbstractTablePackageInfoCellRenderer; |
58 |
import org.gvsig.installer.swing.impl.execution.panel.renderers.InstallStatusCellEditor; |
59 |
import org.gvsig.installer.swing.impl.execution.panel.renderers.InstallStatusCellRenderer; |
60 |
import org.gvsig.installer.swing.impl.execution.panel.renderers.InstalledPackageCellRenderer; |
61 |
import org.gvsig.installer.swing.impl.execution.panel.renderers.OfficialRecommendedCellRenderer; |
62 |
import org.gvsig.installer.swing.impl.execution.panel.renderers.OsAndArchitectureCellRenderer; |
63 |
|
64 |
/**
|
65 |
* @author gvSIG Team
|
66 |
* @version $Id$
|
67 |
*/
|
68 |
public class PackagesTablePanel extends JPanel implements ListSelectionListener { |
69 |
|
70 |
private static final long serialVersionUID = 8156088357208685689L; |
71 |
protected SwingInstallerManager swingInstallerManager = null; |
72 |
|
73 |
private JScrollPane descriptionScrollPane; |
74 |
private JEditorPane descriptionTextEditor; |
75 |
private JScrollPane pluginsScrollPane; |
76 |
private JTable pluginsTable; |
77 |
private PackagePropertiesFilterPanel filterPanel;
|
78 |
private FastFilterButtonsPanel fastFilterPanel;
|
79 |
private SelectPackagesPanel selectPackagesPanel;
|
80 |
|
81 |
public PackagesTablePanel(SelectPackagesPanel selectPackagesPanel) {
|
82 |
super();
|
83 |
swingInstallerManager = SwingInstallerLocator |
84 |
.getSwingInstallerManager(); |
85 |
this.selectPackagesPanel = selectPackagesPanel;
|
86 |
initComponents(); |
87 |
pluginsTable.getSelectionModel().addListSelectionListener(this);
|
88 |
pluginsTable.setDefaultRenderer(PackageOfficialRecommended.class, |
89 |
new OfficialRecommendedCellRenderer());
|
90 |
pluginsTable.setDefaultRenderer(PackageStatus.class, |
91 |
new InstallStatusCellRenderer());
|
92 |
pluginsTable.setDefaultEditor(PackageStatus.class, |
93 |
new InstallStatusCellEditor(this.selectPackagesPanel)); |
94 |
AbstractTablePackageInfoCellRenderer ipcr = new InstalledPackageCellRenderer();
|
95 |
pluginsTable.setDefaultRenderer(PackageOsAndArchitecture.class, |
96 |
new OsAndArchitectureCellRenderer());
|
97 |
pluginsTable.setDefaultRenderer(String.class, ipcr);
|
98 |
pluginsTable.setDefaultRenderer(Number.class, ipcr);
|
99 |
pluginsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
100 |
} |
101 |
|
102 |
private void initComponents() { |
103 |
java.awt.GridBagConstraints gridBagConstraints; |
104 |
|
105 |
pluginsTable = new JTable(); |
106 |
|
107 |
MouseListener mouseListener = new MyMouseListener(); |
108 |
pluginsTable.addMouseListener(mouseListener); |
109 |
|
110 |
pluginsScrollPane = new JScrollPane(pluginsTable); |
111 |
|
112 |
descriptionTextEditor = new JEditorPane(); |
113 |
descriptionTextEditor.setBackground(Color.WHITE);
|
114 |
descriptionTextEditor.setEditable(false);
|
115 |
descriptionTextEditor.setContentType("text/html");
|
116 |
|
117 |
descriptionScrollPane = new JScrollPane(descriptionTextEditor); |
118 |
|
119 |
filterPanel = new PackagePropertiesFilterPanel(this); |
120 |
filterPanel.setVisible(true);
|
121 |
|
122 |
fastFilterPanel = new FastFilterButtonsPanel(this); |
123 |
|
124 |
setLayout(new GridBagLayout()); |
125 |
|
126 |
// left panel filter
|
127 |
gridBagConstraints = new GridBagConstraints(); |
128 |
gridBagConstraints.fill = GridBagConstraints.BOTH;
|
129 |
gridBagConstraints.gridx = 0;
|
130 |
gridBagConstraints.gridy = 1;
|
131 |
gridBagConstraints.weightx = 0.13;
|
132 |
gridBagConstraints.weighty = 1;
|
133 |
gridBagConstraints.gridheight = 2;
|
134 |
gridBagConstraints.insets = new Insets(0, 2, 2, 2); |
135 |
add(filterPanel, gridBagConstraints); |
136 |
|
137 |
// fast filters buttons panel
|
138 |
gridBagConstraints = new GridBagConstraints(); |
139 |
gridBagConstraints.fill = GridBagConstraints.BOTH;
|
140 |
gridBagConstraints.gridx = 1;
|
141 |
gridBagConstraints.gridy = 0;
|
142 |
gridBagConstraints.weightx = 0.75;
|
143 |
gridBagConstraints.weighty = 0;
|
144 |
gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
145 |
add(fastFilterPanel, gridBagConstraints); |
146 |
|
147 |
// plugins scroll panel
|
148 |
gridBagConstraints = new GridBagConstraints(); |
149 |
gridBagConstraints.fill = GridBagConstraints.BOTH;
|
150 |
gridBagConstraints.gridx = 1;
|
151 |
gridBagConstraints.gridy = 1;
|
152 |
gridBagConstraints.weightx = 0.75;
|
153 |
gridBagConstraints.weighty = 0.7;
|
154 |
gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
155 |
add(pluginsScrollPane, gridBagConstraints); |
156 |
|
157 |
// description panel
|
158 |
gridBagConstraints = new GridBagConstraints(); |
159 |
gridBagConstraints.gridx = 1;
|
160 |
gridBagConstraints.gridy = 2;
|
161 |
gridBagConstraints.fill = GridBagConstraints.BOTH;
|
162 |
gridBagConstraints.weightx = 0.75;
|
163 |
gridBagConstraints.weighty = 0.3;
|
164 |
gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
165 |
add(descriptionScrollPane, gridBagConstraints); |
166 |
} |
167 |
|
168 |
public void selectPackages() { |
169 |
PackagesTableModel pluginsTableModel = (PackagesTableModel) pluginsTable |
170 |
.getModel(); |
171 |
pluginsTableModel.selectDefaultPackages(); |
172 |
} |
173 |
|
174 |
public void setTableModel(PackagesTableModel pluginsTableModel) { |
175 |
pluginsTable.setModel(pluginsTableModel); |
176 |
pluginsTableModel.fireTableDataChanged(); |
177 |
TableColumnModel tableColumnModel = pluginsTable.getColumnModel();
|
178 |
tableColumnModel.getColumn(0).setPreferredWidth(20); |
179 |
tableColumnModel.getColumn(1).setPreferredWidth(20); |
180 |
tableColumnModel.getColumn(2).setPreferredWidth(20); |
181 |
tableColumnModel.getColumn(3).setPreferredWidth(225); |
182 |
tableColumnModel.getColumn(4).setPreferredWidth(130); |
183 |
tableColumnModel.getColumn(5).setPreferredWidth(53); |
184 |
|
185 |
} |
186 |
|
187 |
public List<PackageInfo> getPackagesToInstall() { |
188 |
return ((PackagesTableModel) pluginsTable.getModel())
|
189 |
.getPackagesToInstall(); |
190 |
} |
191 |
|
192 |
public boolean isPackageSelected() { |
193 |
return ((PackagesTableModel) pluginsTable.getModel())
|
194 |
.hasAnyPackageSelected(); |
195 |
} |
196 |
|
197 |
// shows the package info in the wizard
|
198 |
public void valueChanged(ListSelectionEvent e) { |
199 |
int row = pluginsTable.getSelectedRow();
|
200 |
if (row != -1) { |
201 |
|
202 |
String code = ((PackagesTableModel) pluginsTable.getModel())
|
203 |
.getPackageInfoAt(row).getCode(); |
204 |
if (code == null || code.equals("")) { |
205 |
code = "";
|
206 |
} else {
|
207 |
code = "<li type='circle'>Code: " + code + "</li>"; |
208 |
} |
209 |
|
210 |
String name = ((PackagesTableModel) pluginsTable.getModel())
|
211 |
.getPackageInfoAt(row).getName(); |
212 |
if (name == null || name.equals("")) { |
213 |
name = "";
|
214 |
} else {
|
215 |
name = name + "<br>";
|
216 |
} |
217 |
|
218 |
String owner = ((PackagesTableModel) pluginsTable.getModel())
|
219 |
.getOwnerAt(row).trim(); |
220 |
if (owner == null || owner.equals("")) { |
221 |
owner = "";
|
222 |
} else {
|
223 |
owner = "<li type='circle'>Owner: " + owner + "</li>"; |
224 |
} |
225 |
|
226 |
String ownerUrlStr;
|
227 |
URL ownerURL = ((PackagesTableModel) pluginsTable.getModel())
|
228 |
.getOwnerUrlAt(row); |
229 |
if (ownerURL == null) { |
230 |
ownerUrlStr = "";
|
231 |
} else {
|
232 |
ownerUrlStr = "<li type='circle'>Owner URL:"
|
233 |
+ ownerURL.toString() + "</li>";
|
234 |
} |
235 |
|
236 |
String sources;
|
237 |
URL sourcesURL = ((PackagesTableModel) pluginsTable.getModel())
|
238 |
.getSourcesAt(row); |
239 |
if (sourcesURL == null) { |
240 |
sources = "";
|
241 |
} else {
|
242 |
String sourcesb = "Sources:" + sourcesURL.toString(); |
243 |
sources = "<li type='circle'>" + sourcesb + "</li>"; |
244 |
} |
245 |
|
246 |
String description = ((PackagesTableModel) pluginsTable.getModel())
|
247 |
.getDescriptionAt(row); |
248 |
if (description == null) { |
249 |
description = "";
|
250 |
} else {
|
251 |
description = description + "<br>";
|
252 |
} |
253 |
|
254 |
String depends = ""; |
255 |
Dependencies dependencies = ((PackagesTableModel) pluginsTable |
256 |
.getModel()).getPackageInfoAt(row).getDependencies(); |
257 |
if (dependencies != null && !dependencies.isEmpty()) { |
258 |
depends = "<li type='circle'>Dependencies: "
|
259 |
+ dependencies.toString() + "</li>";
|
260 |
} |
261 |
|
262 |
String categories = ((PackagesTableModel) pluginsTable.getModel())
|
263 |
.getPackageInfoAt(row).getCategoriesAsString(); |
264 |
if (categories == null || categories.equals("")) { |
265 |
categories = "";
|
266 |
} else {
|
267 |
categories = "<li type='circle'>Categories: " + categories
|
268 |
+ "</li>";
|
269 |
} |
270 |
|
271 |
// sets the html format
|
272 |
String descriptionTextHtml = "<b>" + name + "</b>" |
273 |
+ "<br><font size='-1'>" + description
|
274 |
+ "<br></font><hr /><font size='-1'>" + code + owner
|
275 |
+ ownerUrlStr + sources + depends + categories + "</font>";
|
276 |
|
277 |
descriptionTextEditor.setText(descriptionTextHtml); |
278 |
|
279 |
// get the view area to the top-left corner
|
280 |
descriptionTextEditor.setCaretPosition(0);
|
281 |
|
282 |
} |
283 |
} |
284 |
|
285 |
public void setFilter(PackageFilter filter) { |
286 |
PackagesTableModel pluginsTableModel = (PackagesTableModel) pluginsTable |
287 |
.getModel(); |
288 |
pluginsTableModel.setFilter(filter); |
289 |
selectPackagesPanel.updatePanel(); |
290 |
} |
291 |
|
292 |
public void setFilter(NameDescriptionOrCodeFilter filter) { |
293 |
PackagesTableModel pluginsTableModel = (PackagesTableModel) pluginsTable |
294 |
.getModel(); |
295 |
pluginsTableModel.setFilter(filter); |
296 |
selectPackagesPanel.updatePanel(); |
297 |
} |
298 |
|
299 |
private class MyMouseListener implements MouseListener { |
300 |
|
301 |
public void mouseClicked(MouseEvent e) { |
302 |
selectPackagesPanel.checkIfPluginSelected(); |
303 |
} |
304 |
|
305 |
public void mouseEntered(MouseEvent e) { |
306 |
} |
307 |
|
308 |
public void mouseExited(MouseEvent e) { |
309 |
} |
310 |
|
311 |
public void mousePressed(MouseEvent e) { |
312 |
} |
313 |
|
314 |
public void mouseReleased(MouseEvent e) { |
315 |
} |
316 |
} |
317 |
|
318 |
public SelectPackagesPanel getSelectPackagesPanel() {
|
319 |
return this.selectPackagesPanel; |
320 |
} |
321 |
|
322 |
public void clearAllPanels() { |
323 |
filterPanel.resetPanel(); |
324 |
descriptionTextEditor.setText("");
|
325 |
fastFilterPanel.resetPanel(); |
326 |
} |
327 |
|
328 |
public void resetPanel() { |
329 |
filterPanel.resetPanel(); |
330 |
descriptionTextEditor.setText("");
|
331 |
} |
332 |
|
333 |
} |