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 @ 37585
History | View | Annotate | Download (11.2 KB)
1 | 37538 | nfrancisco | /* 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 | 37541 | nfrancisco | package org.gvsig.installer.swing.impl.execution.panel; |
29 | 37538 | nfrancisco | |
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 | 37585 | nfrancisco | import org.gvsig.installer.swing.impl.execution.panel.filters.NameDescriptionOrCodeFilter; |
53 | 37541 | nfrancisco | 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 | 37538 | nfrancisco | |
65 | /**
|
||
66 | * @author gvSIG Team
|
||
67 | * @version $Id$
|
||
68 | */
|
||
69 | public class PackagesTablePanel extends JPanel implements ListSelectionListener { |
||
70 | |||
71 | 37575 | nfrancisco | private static final long serialVersionUID = 8156088357208685689L; |
72 | protected SwingInstallerManager swingInstallerManager = null; |
||
73 | 37538 | nfrancisco | |
74 | 37575 | nfrancisco | private JScrollPane descriptionScrollPane; |
75 | private JTextArea descriptionTextArea; |
||
76 | private JTextPane descriptionTextPane; |
||
77 | private JScrollPane pluginsScrollPane; |
||
78 | private JTable pluginsTable; |
||
79 | 37584 | nfrancisco | private PackagePropertiesFilterPanel filterPanel;
|
80 | 37575 | nfrancisco | private FastFilterButtonsPanel fastFilterPanel;
|
81 | private SelectPackagesPanel selectPackagesPanel;
|
||
82 | 37538 | nfrancisco | |
83 | 37575 | nfrancisco | 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 | 37538 | nfrancisco | |
104 | 37575 | nfrancisco | private void initComponents() { |
105 | java.awt.GridBagConstraints gridBagConstraints; |
||
106 | 37538 | nfrancisco | |
107 | 37575 | nfrancisco | pluginsTable = new JTable(); |
108 | 37538 | nfrancisco | |
109 | 37575 | nfrancisco | MouseListener mouseListener = new MyMouseListener(); |
110 | pluginsTable.addMouseListener(mouseListener); |
||
111 | 37538 | nfrancisco | |
112 | 37575 | nfrancisco | pluginsScrollPane = new JScrollPane(pluginsTable); |
113 | 37538 | nfrancisco | |
114 | 37575 | nfrancisco | descriptionTextArea = new JTextArea(); |
115 | descriptionTextArea.setEditable(false);
|
||
116 | descriptionTextArea.setBackground(Color.WHITE);
|
||
117 | descriptionTextArea.setColumns(20);
|
||
118 | descriptionTextArea.setRows(5);
|
||
119 | 37538 | nfrancisco | |
120 | 37575 | nfrancisco | descriptionTextPane = new JTextPane(); |
121 | descriptionTextPane.setEditable(false);
|
||
122 | 37538 | nfrancisco | |
123 | 37575 | nfrancisco | descriptionScrollPane = new JScrollPane(descriptionTextArea); |
124 | 37538 | nfrancisco | |
125 | 37584 | nfrancisco | filterPanel = new PackagePropertiesFilterPanel(this); |
126 | filterPanel.setVisible(true);
|
||
127 | 37538 | nfrancisco | |
128 | 37575 | nfrancisco | fastFilterPanel = new FastFilterButtonsPanel(this); |
129 | 37538 | nfrancisco | |
130 | 37575 | nfrancisco | setLayout(new GridBagLayout()); |
131 | 37538 | nfrancisco | |
132 | 37584 | nfrancisco | // left panel filter
|
133 | 37575 | nfrancisco | gridBagConstraints = new GridBagConstraints(); |
134 | gridBagConstraints.fill = GridBagConstraints.BOTH;
|
||
135 | gridBagConstraints.gridx = 0;
|
||
136 | 37584 | nfrancisco | gridBagConstraints.gridy = 1;
|
137 | 37575 | nfrancisco | gridBagConstraints.weightx = 0.13;
|
138 | gridBagConstraints.weighty = 1;
|
||
139 | 37584 | nfrancisco | gridBagConstraints.gridheight = 2;
|
140 | gridBagConstraints.insets = new Insets(0, 2, 2, 2); |
||
141 | 37575 | nfrancisco | add(filterPanel, gridBagConstraints); |
142 | 37538 | nfrancisco | |
143 | 37584 | nfrancisco | // fast filters buttons panel
|
144 | 37575 | nfrancisco | 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 | 37538 | nfrancisco | |
153 | 37575 | nfrancisco | // 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 | 37538 | nfrancisco | |
163 | 37575 | nfrancisco | // 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 | 37538 | nfrancisco | |
174 | 37575 | nfrancisco | public void selectPackages() { |
175 | PackagesTableModel pluginsTableModel = (PackagesTableModel) pluginsTable |
||
176 | .getModel(); |
||
177 | 37550 | nfrancisco | |
178 | 37575 | nfrancisco | // 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 | 37538 | nfrancisco | |
186 | 37575 | nfrancisco | public void setTableModel(PackagesTableModel pluginsTableModel) { |
187 | pluginsTable.setModel(pluginsTableModel); |
||
188 | pluginsTableModel.fireTableDataChanged(); |
||
189 | TableColumnModel tableColumnModel = pluginsTable.getColumnModel();
|
||
190 | 37584 | nfrancisco | // 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 | 37575 | nfrancisco | tableColumnModel.getColumn(0).setPreferredWidth(20); |
197 | tableColumnModel.getColumn(1).setPreferredWidth(20); |
||
198 | tableColumnModel.getColumn(2).setPreferredWidth(20); |
||
199 | 37584 | nfrancisco | tableColumnModel.getColumn(3).setPreferredWidth(225); |
200 | tableColumnModel.getColumn(4).setPreferredWidth(130); |
||
201 | tableColumnModel.getColumn(5).setPreferredWidth(53); |
||
202 | 37538 | nfrancisco | |
203 | 37575 | nfrancisco | } |
204 | 37538 | nfrancisco | |
205 | 37575 | nfrancisco | public List<PackageInfo> getPackagesToInstall() { |
206 | return ((PackagesTableModel) pluginsTable.getModel())
|
||
207 | .getPackagesToInstall(); |
||
208 | } |
||
209 | 37538 | nfrancisco | |
210 | 37575 | nfrancisco | public boolean isPackageSelected() { |
211 | return ((PackagesTableModel) pluginsTable.getModel())
|
||
212 | .hasAnyPackageSelected(); |
||
213 | } |
||
214 | 37538 | nfrancisco | |
215 | 37575 | nfrancisco | public void valueChanged(ListSelectionEvent e) { |
216 | int row = pluginsTable.getSelectedRow();
|
||
217 | if (row != -1) { |
||
218 | 37538 | nfrancisco | |
219 | 37575 | nfrancisco | 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 | 37538 | nfrancisco | |
227 | 37575 | nfrancisco | 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 | 37550 | nfrancisco | |
235 | 37575 | nfrancisco | 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 | 37538 | nfrancisco | |
243 | 37575 | nfrancisco | 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 | 37538 | nfrancisco | |
252 | 37575 | nfrancisco | String description = ((PackagesTableModel) pluginsTable.getModel())
|
253 | .getDescriptionAt(row); |
||
254 | if (description == null) { |
||
255 | description = "";
|
||
256 | } else {
|
||
257 | description = description + "\n";
|
||
258 | } |
||
259 | 37538 | nfrancisco | |
260 | 37575 | nfrancisco | 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 | 37538 | nfrancisco | |
267 | 37575 | nfrancisco | 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 | 37538 | nfrancisco | |
275 | 37575 | nfrancisco | String descriptionText = name + "\n" + description + "\n" + code |
276 | + owner + sources + depends + categories; |
||
277 | 37538 | nfrancisco | |
278 | 37575 | nfrancisco | descriptionTextArea.setText(descriptionText.trim()); |
279 | 37550 | nfrancisco | |
280 | 37575 | nfrancisco | // get the view area to the top-left corner
|
281 | descriptionTextArea.setCaretPosition(0);
|
||
282 | 37550 | nfrancisco | |
283 | 37575 | nfrancisco | } |
284 | } |
||
285 | 37538 | nfrancisco | |
286 | 37575 | nfrancisco | public void setFilter(PackageFilter filter) { |
287 | PackagesTableModel pluginsTableModel = (PackagesTableModel) pluginsTable |
||
288 | .getModel(); |
||
289 | pluginsTableModel.setFilter(filter); |
||
290 | selectPackagesPanel.updatePanel(); |
||
291 | } |
||
292 | 37538 | nfrancisco | |
293 | 37585 | nfrancisco | public void setFilter(NameDescriptionOrCodeFilter filter) { |
294 | 37584 | nfrancisco | PackagesTableModel pluginsTableModel = (PackagesTableModel) pluginsTable |
295 | .getModel(); |
||
296 | pluginsTableModel.setFilter(filter); |
||
297 | selectPackagesPanel.updatePanel(); |
||
298 | } |
||
299 | |||
300 | 37575 | nfrancisco | private class MyMouseListener implements MouseListener { |
301 | 37550 | nfrancisco | |
302 | 37575 | nfrancisco | public void mouseClicked(MouseEvent e) { |
303 | selectPackagesPanel.checkIfPluginSelected(); |
||
304 | } |
||
305 | 37550 | nfrancisco | |
306 | 37575 | nfrancisco | public void mouseEntered(MouseEvent e) { |
307 | } |
||
308 | 37550 | nfrancisco | |
309 | 37575 | nfrancisco | public void mouseExited(MouseEvent e) { |
310 | } |
||
311 | 37550 | nfrancisco | |
312 | 37575 | nfrancisco | public void mousePressed(MouseEvent e) { |
313 | } |
||
314 | 37550 | nfrancisco | |
315 | 37575 | nfrancisco | public void mouseReleased(MouseEvent e) { |
316 | } |
||
317 | } |
||
318 | 37550 | nfrancisco | |
319 | 37575 | nfrancisco | public SelectPackagesPanel getSelectPackagesPanel() {
|
320 | return this.selectPackagesPanel; |
||
321 | } |
||
322 | 37550 | nfrancisco | |
323 | 37575 | nfrancisco | public void clearAllPanels() { |
324 | filterPanel.resetPanel(); |
||
325 | descriptionTextArea.setText("");
|
||
326 | fastFilterPanel.resetPanel(); |
||
327 | } |
||
328 | 37550 | nfrancisco | |
329 | 37575 | nfrancisco | public void resetPanel() { |
330 | filterPanel.resetPanel(); |
||
331 | descriptionTextArea.setText("");
|
||
332 | } |
||
333 | 37550 | nfrancisco | |
334 | 37538 | nfrancisco | } |