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 / selectPackages2 / PackagesTablePanel.java @ 37538
History | View | Annotate | Download (10.3 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.selectPackages2; |
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.selectPackages2.Renderers.InstallStatusCellEditor; |
53 |
import org.gvsig.installer.swing.impl.execution.panel.selectPackages2.Renderers.InstallStatusCellRenderer; |
54 |
import org.gvsig.installer.swing.impl.execution.panel.selectPackages2.Renderers.InstalledPackageCellRenderer; |
55 |
import org.gvsig.installer.swing.impl.execution.panel.selectPackages2.Renderers.OfficialRecommendedCellRenderer; |
56 |
import org.gvsig.installer.swing.impl.execution.panel.selectPackages2.Renderers.OsAndArchitectureCellRenderer; |
57 |
import org.gvsig.installer.swing.impl.execution.panel.selectPackages2.model.PackagesTableModel; |
58 |
import org.gvsig.installer.swing.impl.execution.panel.selectPackages2.model.PackagesTableModel.PackageOfficialRecommended; |
59 |
import org.gvsig.installer.swing.impl.execution.panel.selectPackages2.model.PackagesTableModel.PackageOsAndArchitecture; |
60 |
import org.gvsig.installer.swing.impl.execution.panel.selectPackages2.model.PackagesTableModel.PackageStatus; |
61 |
|
62 |
/**
|
63 |
* @author gvSIG Team
|
64 |
* @version $Id$
|
65 |
*/
|
66 |
public class PackagesTablePanel extends JPanel implements ListSelectionListener { |
67 |
|
68 |
private static final long serialVersionUID = 8156088357208685689L; |
69 |
protected SwingInstallerManager swingInstallerManager = null; |
70 |
|
71 |
private JScrollPane descriptionScrollPane; |
72 |
private JTextArea descriptionTextArea; |
73 |
private JTextPane descriptionTextPane; |
74 |
private JScrollPane pluginsScrollPane; |
75 |
private JTable pluginsTable; |
76 |
private JPanel filterPanel; |
77 |
private FastFilterButtonsPanel fastFilterPanel;
|
78 |
private SelectPackagesPanel selectPackagesPanel;
|
79 |
|
80 |
private MouseListener mouseListener = new MouseListener() { |
81 |
|
82 |
public void mouseClicked(MouseEvent e) { |
83 |
selectPackagesPanel.checkIfPluginSelected(); |
84 |
} |
85 |
|
86 |
public void mouseEntered(MouseEvent e) { |
87 |
} |
88 |
|
89 |
public void mouseExited(MouseEvent e) { |
90 |
} |
91 |
|
92 |
public void mousePressed(MouseEvent e) { |
93 |
} |
94 |
|
95 |
public void mouseReleased(MouseEvent e) { |
96 |
} |
97 |
|
98 |
}; |
99 |
|
100 |
public PackagesTablePanel(SelectPackagesPanel selectPackagesPanel) {
|
101 |
super();
|
102 |
swingInstallerManager = |
103 |
SwingInstallerLocator.getSwingInstallerManager(); |
104 |
this.selectPackagesPanel = selectPackagesPanel;
|
105 |
initComponents(); |
106 |
pluginsTable.getSelectionModel().addListSelectionListener(this);
|
107 |
pluginsTable.setDefaultRenderer(PackageOfficialRecommended.class, |
108 |
new OfficialRecommendedCellRenderer());
|
109 |
pluginsTable.setDefaultRenderer(PackageStatus.class, |
110 |
new InstallStatusCellRenderer());
|
111 |
pluginsTable.setDefaultEditor(PackageStatus.class, |
112 |
new InstallStatusCellEditor(this.selectPackagesPanel)); |
113 |
AbstractTablePackageInfoCellRenderer ipcr = |
114 |
new InstalledPackageCellRenderer();
|
115 |
pluginsTable.setDefaultRenderer(PackageOsAndArchitecture.class, |
116 |
new OsAndArchitectureCellRenderer());
|
117 |
pluginsTable.setDefaultRenderer(String.class, ipcr);
|
118 |
pluginsTable.setDefaultRenderer(Number.class, ipcr);
|
119 |
pluginsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
120 |
} |
121 |
|
122 |
private void initComponents() { |
123 |
java.awt.GridBagConstraints gridBagConstraints; |
124 |
|
125 |
pluginsTable = new JTable(); |
126 |
|
127 |
pluginsTable.addMouseListener(mouseListener); |
128 |
|
129 |
pluginsScrollPane = new JScrollPane(pluginsTable); |
130 |
|
131 |
descriptionTextArea = new JTextArea(); |
132 |
descriptionTextArea.setEditable(false);
|
133 |
descriptionTextArea.setBackground(Color.WHITE);
|
134 |
descriptionTextArea.setColumns(20);
|
135 |
descriptionTextArea.setRows(5);
|
136 |
|
137 |
descriptionTextPane = new JTextPane(); |
138 |
descriptionTextPane.setEditable(false);
|
139 |
|
140 |
descriptionScrollPane = new JScrollPane(descriptionTextArea); |
141 |
|
142 |
filterPanel = new CategoriesFilterPanel(this); |
143 |
filterPanel.setVisible(true);
|
144 |
|
145 |
fastFilterPanel = new FastFilterButtonsPanel(this); |
146 |
|
147 |
setLayout(new GridBagLayout()); |
148 |
|
149 |
// panel filter
|
150 |
gridBagConstraints = new GridBagConstraints(); |
151 |
gridBagConstraints.fill = GridBagConstraints.BOTH;
|
152 |
gridBagConstraints.gridx = 0;
|
153 |
gridBagConstraints.gridy = 0;
|
154 |
gridBagConstraints.weightx = 0.13;
|
155 |
gridBagConstraints.weighty = 1;
|
156 |
gridBagConstraints.gridheight = 3;
|
157 |
gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
158 |
add(filterPanel, gridBagConstraints); |
159 |
|
160 |
// filters buttons panel
|
161 |
gridBagConstraints = new GridBagConstraints(); |
162 |
gridBagConstraints.fill = GridBagConstraints.BOTH;
|
163 |
gridBagConstraints.gridx = 1;
|
164 |
gridBagConstraints.gridy = 0;
|
165 |
gridBagConstraints.weightx = 0.75;
|
166 |
gridBagConstraints.weighty = 0;
|
167 |
gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
168 |
add(fastFilterPanel, gridBagConstraints); |
169 |
|
170 |
// plugins scroll panel
|
171 |
gridBagConstraints = new GridBagConstraints(); |
172 |
gridBagConstraints.fill = GridBagConstraints.BOTH;
|
173 |
gridBagConstraints.gridx = 1;
|
174 |
gridBagConstraints.gridy = 1;
|
175 |
gridBagConstraints.weightx = 0.75;
|
176 |
gridBagConstraints.weighty = 0.7;
|
177 |
gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
178 |
add(pluginsScrollPane, gridBagConstraints); |
179 |
|
180 |
// description panel
|
181 |
gridBagConstraints = new GridBagConstraints(); |
182 |
gridBagConstraints.gridx = 1;
|
183 |
gridBagConstraints.gridy = 2;
|
184 |
gridBagConstraints.fill = GridBagConstraints.BOTH;
|
185 |
gridBagConstraints.weightx = 0.75;
|
186 |
gridBagConstraints.weighty = 0.3;
|
187 |
gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
188 |
add(descriptionScrollPane, gridBagConstraints); |
189 |
} |
190 |
|
191 |
public void selectPackages() { |
192 |
PackagesTableModel pluginsTableModel = |
193 |
(PackagesTableModel) pluginsTable.getModel(); |
194 |
pluginsTableModel.selectDefaultPackages(); |
195 |
} |
196 |
|
197 |
public void setTableModel(PackagesTableModel pluginsTableModel) { |
198 |
pluginsTable.setModel(pluginsTableModel); |
199 |
pluginsTableModel.fireTableDataChanged(); |
200 |
TableColumnModel tableColumnModel = pluginsTable.getColumnModel();
|
201 |
tableColumnModel.getColumn(0).setPreferredWidth(20); |
202 |
tableColumnModel.getColumn(1).setPreferredWidth(20); |
203 |
tableColumnModel.getColumn(2).setPreferredWidth(20); |
204 |
tableColumnModel.getColumn(3).setPreferredWidth(225); |
205 |
tableColumnModel.getColumn(4).setPreferredWidth(130); |
206 |
tableColumnModel.getColumn(5).setPreferredWidth(53); |
207 |
|
208 |
} |
209 |
|
210 |
public List<PackageInfo> getPackagesToInstall() { |
211 |
return ((PackagesTableModel) pluginsTable.getModel())
|
212 |
.getPackagesToInstall(); |
213 |
} |
214 |
|
215 |
public boolean isPackageSelected() { |
216 |
return ((PackagesTableModel) pluginsTable.getModel())
|
217 |
.hasAnyPackageSelected(); |
218 |
} |
219 |
|
220 |
public void valueChanged(ListSelectionEvent e) { |
221 |
int row = pluginsTable.getSelectedRow();
|
222 |
if (row != -1) { |
223 |
|
224 |
String owner;
|
225 |
|
226 |
if (((PackagesTableModel) pluginsTable.getModel()).getOwnerAt(row)
|
227 |
.trim().equals("")) {
|
228 |
owner = "";
|
229 |
} else {
|
230 |
owner = |
231 |
"Owner: "
|
232 |
+ ((PackagesTableModel) pluginsTable.getModel()) |
233 |
.getOwnerAt(row) + "\n";
|
234 |
} |
235 |
|
236 |
String sources;
|
237 |
URL sourcesURL =
|
238 |
((PackagesTableModel) pluginsTable.getModel()) |
239 |
.getSourcesAt(row); |
240 |
if (sourcesURL == null) { |
241 |
sources = "";
|
242 |
} else {
|
243 |
sources = "Sources: " + sourcesURL.toString() + "\n\n"; |
244 |
} |
245 |
|
246 |
String description =
|
247 |
((PackagesTableModel) pluginsTable.getModel()) |
248 |
.getDescriptionAt(row); |
249 |
if (description == null) { |
250 |
description = "";
|
251 |
} |
252 |
|
253 |
String depends = ""; |
254 |
Dependencies dependencies = |
255 |
((PackagesTableModel) pluginsTable.getModel()) |
256 |
.getPackageInfoAt(row).getDependencies(); |
257 |
if (dependencies != null && !dependencies.isEmpty()) { |
258 |
depends = |
259 |
"\n\nDependencies: " + dependencies.toString() + "\n\n"; |
260 |
} |
261 |
|
262 |
String descriptionText = owner + sources + description + depends;
|
263 |
|
264 |
descriptionTextArea.setText(descriptionText); |
265 |
|
266 |
} |
267 |
} |
268 |
|
269 |
public void setFilter(PackageFilter filter) { |
270 |
PackagesTableModel pluginsTableModel = |
271 |
(PackagesTableModel) pluginsTable.getModel(); |
272 |
pluginsTableModel.setFilter(filter); |
273 |
selectPackagesPanel.updatePanel(); |
274 |
} |
275 |
|
276 |
} |