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 @ 40560
History | View | Annotate | Download (11 KB)
1 | 40560 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40560 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | *
|
||
6 | 40435 | jjdelcerro | * This program is free software; you can redistribute it and/or
|
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40560 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | 40560 | jjdelcerro | *
|
11 | 40435 | jjdelcerro | * 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 | 40560 | jjdelcerro | *
|
16 | 40435 | jjdelcerro | * 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 | 40560 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 40435 | jjdelcerro | * MA 02110-1301, USA.
|
20 | 40560 | jjdelcerro | *
|
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 | 40435 | jjdelcerro | */
|
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.net.URL; |
||
38 | import java.util.List; |
||
39 | |||
40 | import javax.swing.JEditorPane; |
||
41 | import javax.swing.JPanel; |
||
42 | import javax.swing.JScrollPane; |
||
43 | import javax.swing.JTable; |
||
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.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_LAST_COLUMN);
|
||
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 | // filterPanel.setInitialFilter();
|
||
168 | } |
||
169 | |||
170 | public void resetFilter() { |
||
171 | filterPanel.resetPanel(); |
||
172 | valueChanged(); |
||
173 | } |
||
174 | |||
175 | public void selectPackages() { |
||
176 | PackagesTableModel pluginsTableModel = (PackagesTableModel) pluginsTable |
||
177 | .getModel(); |
||
178 | pluginsTableModel.selectDefaultPackages(); |
||
179 | } |
||
180 | |||
181 | public void setTableModel(PackagesTableModel pluginsTableModel) { |
||
182 | pluginsTable.setModel(pluginsTableModel); |
||
183 | pluginsTableModel.fireTableDataChanged(); |
||
184 | TableColumnModel tableColumnModel = pluginsTable.getColumnModel();
|
||
185 | tableColumnModel.getColumn(0).setPreferredWidth(20); |
||
186 | tableColumnModel.getColumn(1).setPreferredWidth(20); |
||
187 | tableColumnModel.getColumn(2).setPreferredWidth(20); |
||
188 | tableColumnModel.getColumn(3).setPreferredWidth(225); |
||
189 | tableColumnModel.getColumn(4).setPreferredWidth(130); |
||
190 | tableColumnModel.getColumn(5).setPreferredWidth(53); |
||
191 | |||
192 | } |
||
193 | |||
194 | public List<PackageInfo> getPackagesToInstall() { |
||
195 | return ((PackagesTableModel) pluginsTable.getModel())
|
||
196 | .getPackagesToInstall(); |
||
197 | } |
||
198 | |||
199 | public boolean isPackageSelected() { |
||
200 | return ((PackagesTableModel) pluginsTable.getModel())
|
||
201 | .hasAnyPackageSelected(); |
||
202 | } |
||
203 | |||
204 | private class HTMLCoder { |
||
205 | private StringBuffer buffer = new StringBuffer(); |
||
206 | |||
207 | public String toString() { |
||
208 | return buffer.toString();
|
||
209 | } |
||
210 | |||
211 | public void addTitle(String title) { |
||
212 | if( title == null ) { |
||
213 | return;
|
||
214 | } |
||
215 | buffer.append("<h1>");
|
||
216 | buffer.append(title); |
||
217 | buffer.append("</h1>");
|
||
218 | } |
||
219 | |||
220 | public void addParagraph(Object text) { |
||
221 | if( text == null ) { |
||
222 | return;
|
||
223 | } |
||
224 | String t = text.toString().replaceAll("\\n", "<br>\n"); |
||
225 | buffer.append("<p>");
|
||
226 | buffer.append(t); |
||
227 | buffer.append("</p>");
|
||
228 | } |
||
229 | |||
230 | public void addBeginList() { |
||
231 | buffer.append("<ul>");
|
||
232 | } |
||
233 | |||
234 | public void addEndList() { |
||
235 | buffer.append("</ul>");
|
||
236 | } |
||
237 | |||
238 | public void addListItem(String label, Object value) { |
||
239 | if( value == null ) { |
||
240 | return;
|
||
241 | } |
||
242 | buffer.append("<li>");
|
||
243 | buffer.append(label); |
||
244 | buffer.append(": <i>");
|
||
245 | buffer.append(value.toString()); |
||
246 | buffer.append("</i></li>");
|
||
247 | } |
||
248 | |||
249 | public void addListItem(String label, URL value) { |
||
250 | if( value == null ) { |
||
251 | return;
|
||
252 | } |
||
253 | buffer.append("<li>");
|
||
254 | buffer.append(label); |
||
255 | buffer.append(": <a href=\"");
|
||
256 | buffer.append(value.toString()); |
||
257 | buffer.append("\">");
|
||
258 | buffer.append(value.toString()); |
||
259 | buffer.append("</a></li>");
|
||
260 | } |
||
261 | |||
262 | } |
||
263 | public void valueChanged(ListSelectionEvent e) { |
||
264 | valueChanged(); |
||
265 | } |
||
266 | |||
267 | public void valueChanged() { |
||
268 | int row = pluginsTable.getSelectedRow();
|
||
269 | if (row < 0) { |
||
270 | descriptionTextEditor.setText("<p></p>");
|
||
271 | return;
|
||
272 | } |
||
273 | |||
274 | PackageInfo pkginfo = ((PackagesTableModel) pluginsTable.getModel()) |
||
275 | .getPackageInfoAt(row); |
||
276 | |||
277 | HTMLCoder html = new HTMLCoder();
|
||
278 | html.addTitle(pkginfo.getName()); |
||
279 | html.addParagraph(pkginfo.getDescription()); |
||
280 | html.addBeginList(); |
||
281 | html.addListItem("code", pkginfo.getCode());
|
||
282 | html.addListItem("Organization", pkginfo.getOwner());
|
||
283 | html.addListItem("Organization URL", pkginfo.getOwnerURL());
|
||
284 | html.addListItem("Sources", pkginfo.getSourcesURL());
|
||
285 | html.addListItem("Dependencies", pkginfo.getDependencies());
|
||
286 | html.addListItem("Categories", pkginfo.getCategoriesAsString());
|
||
287 | html.addListItem("Official", pkginfo.isOfficial());
|
||
288 | html.addListItem("Signed", pkginfo.isSigned());
|
||
289 | html.addEndList(); |
||
290 | |||
291 | descriptionTextEditor.setText(html.toString()); |
||
292 | |||
293 | // get the view area to the top-left corner
|
||
294 | descriptionTextEditor.setCaretPosition(0);
|
||
295 | |||
296 | } |
||
297 | |||
298 | public void setFilter(PackageFilter filter) { |
||
299 | PackagesTableModel pluginsTableModel = (PackagesTableModel) pluginsTable |
||
300 | .getModel(); |
||
301 | pluginsTableModel.setFilter(filter); |
||
302 | selectPackagesPanel.updatePanel(); |
||
303 | } |
||
304 | |||
305 | public void setFilter(NameDescriptionOrCodeFilter filter) { |
||
306 | PackagesTableModel pluginsTableModel = (PackagesTableModel) pluginsTable |
||
307 | .getModel(); |
||
308 | pluginsTableModel.setFilter(filter); |
||
309 | selectPackagesPanel.updatePanel(); |
||
310 | } |
||
311 | |||
312 | private class MyMouseListener implements MouseListener { |
||
313 | |||
314 | public void mouseClicked(MouseEvent e) { |
||
315 | selectPackagesPanel.checkIfPluginSelected(); |
||
316 | } |
||
317 | |||
318 | public void mouseEntered(MouseEvent e) { |
||
319 | } |
||
320 | |||
321 | public void mouseExited(MouseEvent e) { |
||
322 | } |
||
323 | |||
324 | public void mousePressed(MouseEvent e) { |
||
325 | } |
||
326 | |||
327 | public void mouseReleased(MouseEvent e) { |
||
328 | } |
||
329 | } |
||
330 | |||
331 | public SelectPackagesPanel getSelectPackagesPanel() {
|
||
332 | return this.selectPackagesPanel; |
||
333 | } |
||
334 | |||
335 | public void clearAllPanels() { |
||
336 | filterPanel.resetPanel(); |
||
337 | descriptionTextEditor.setText("");
|
||
338 | fastFilterPanel.resetPanel(); |
||
339 | } |
||
340 | |||
341 | public void resetPanel() { |
||
342 | filterPanel.resetPanel(); |
||
343 | descriptionTextEditor.setText("");
|
||
344 | } |
||
345 | |||
346 | /**
|
||
347 | *
|
||
348 | */
|
||
349 | public void setInitialFilter() { |
||
350 | filterPanel.setInitialFilter(); |
||
351 | } |
||
352 | |||
353 | } |