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