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