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 | 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 | 37541 | nfrancisco | 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 | 37538 | nfrancisco | |
64 | /**
|
||
65 | * @author gvSIG Team
|
||
66 | * @version $Id$
|
||
67 | */
|
||
68 | public class PackagesTablePanel extends JPanel implements ListSelectionListener { |
||
69 | |||
70 | 37575 | nfrancisco | private static final long serialVersionUID = 8156088357208685689L; |
71 | protected SwingInstallerManager swingInstallerManager = null; |
||
72 | 37538 | nfrancisco | |
73 | 37575 | nfrancisco | 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 | 37538 | nfrancisco | |
82 | 37575 | nfrancisco | 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 | 37538 | nfrancisco | |
103 | 37575 | nfrancisco | private void initComponents() { |
104 | java.awt.GridBagConstraints gridBagConstraints; |
||
105 | 37538 | nfrancisco | |
106 | 37575 | nfrancisco | pluginsTable = new JTable(); |
107 | 37538 | nfrancisco | |
108 | 37575 | nfrancisco | MouseListener mouseListener = new MyMouseListener(); |
109 | pluginsTable.addMouseListener(mouseListener); |
||
110 | 37538 | nfrancisco | |
111 | 37575 | nfrancisco | pluginsScrollPane = new JScrollPane(pluginsTable); |
112 | 37538 | nfrancisco | |
113 | 37575 | nfrancisco | descriptionTextArea = new JTextArea(); |
114 | descriptionTextArea.setEditable(false);
|
||
115 | descriptionTextArea.setBackground(Color.WHITE);
|
||
116 | descriptionTextArea.setColumns(20);
|
||
117 | descriptionTextArea.setRows(5);
|
||
118 | 37538 | nfrancisco | |
119 | 37575 | nfrancisco | descriptionTextPane = new JTextPane(); |
120 | descriptionTextPane.setEditable(false);
|
||
121 | 37538 | nfrancisco | |
122 | 37575 | nfrancisco | descriptionScrollPane = new JScrollPane(descriptionTextArea); |
123 | 37538 | nfrancisco | |
124 | 37575 | nfrancisco | filterPanel = new CategoriesFilterPanel(this); |
125 | filterPanel.setVisible(false);
|
||
126 | 37538 | nfrancisco | |
127 | 37575 | nfrancisco | fastFilterPanel = new FastFilterButtonsPanel(this); |
128 | 37538 | nfrancisco | |
129 | 37575 | nfrancisco | setLayout(new GridBagLayout()); |
130 | 37538 | nfrancisco | |
131 | 37575 | nfrancisco | // 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 | 37538 | nfrancisco | |
142 | 37575 | nfrancisco | // 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 | 37538 | nfrancisco | |
152 | 37575 | nfrancisco | // 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 | 37538 | nfrancisco | |
162 | 37575 | nfrancisco | // 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 | 37538 | nfrancisco | |
173 | 37575 | nfrancisco | public void selectPackages() { |
174 | PackagesTableModel pluginsTableModel = (PackagesTableModel) pluginsTable |
||
175 | .getModel(); |
||
176 | 37550 | nfrancisco | |
177 | 37575 | nfrancisco | // 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 | 37538 | nfrancisco | |
185 | 37575 | nfrancisco | 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 | 37538 | nfrancisco | |
202 | 37575 | nfrancisco | } |
203 | 37538 | nfrancisco | |
204 | 37575 | nfrancisco | public List<PackageInfo> getPackagesToInstall() { |
205 | return ((PackagesTableModel) pluginsTable.getModel())
|
||
206 | .getPackagesToInstall(); |
||
207 | } |
||
208 | 37538 | nfrancisco | |
209 | 37575 | nfrancisco | public boolean isPackageSelected() { |
210 | return ((PackagesTableModel) pluginsTable.getModel())
|
||
211 | .hasAnyPackageSelected(); |
||
212 | } |
||
213 | 37538 | nfrancisco | |
214 | 37575 | nfrancisco | public void valueChanged(ListSelectionEvent e) { |
215 | int row = pluginsTable.getSelectedRow();
|
||
216 | if (row != -1) { |
||
217 | 37538 | nfrancisco | |
218 | 37575 | nfrancisco | 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 | 37538 | nfrancisco | |
226 | 37575 | nfrancisco | 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 | 37550 | nfrancisco | |
234 | 37575 | nfrancisco | 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 | 37538 | nfrancisco | |
242 | 37575 | nfrancisco | 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 | 37538 | nfrancisco | |
251 | 37575 | nfrancisco | String description = ((PackagesTableModel) pluginsTable.getModel())
|
252 | .getDescriptionAt(row); |
||
253 | if (description == null) { |
||
254 | description = "";
|
||
255 | } else {
|
||
256 | description = description + "\n";
|
||
257 | } |
||
258 | 37538 | nfrancisco | |
259 | 37575 | nfrancisco | 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 | 37538 | nfrancisco | |
266 | 37575 | nfrancisco | 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 | 37538 | nfrancisco | |
274 | 37575 | nfrancisco | String descriptionText = name + "\n" + description + "\n" + code |
275 | + owner + sources + depends + categories; |
||
276 | 37538 | nfrancisco | |
277 | 37575 | nfrancisco | descriptionTextArea.setText(descriptionText.trim()); |
278 | 37550 | nfrancisco | |
279 | 37575 | nfrancisco | // get the view area to the top-left corner
|
280 | descriptionTextArea.setCaretPosition(0);
|
||
281 | 37550 | nfrancisco | |
282 | 37575 | nfrancisco | } |
283 | } |
||
284 | 37538 | nfrancisco | |
285 | 37575 | nfrancisco | public void setFilter(PackageFilter filter) { |
286 | PackagesTableModel pluginsTableModel = (PackagesTableModel) pluginsTable |
||
287 | .getModel(); |
||
288 | pluginsTableModel.setFilter(filter); |
||
289 | selectPackagesPanel.updatePanel(); |
||
290 | } |
||
291 | 37538 | nfrancisco | |
292 | 37575 | nfrancisco | private class MyMouseListener implements MouseListener { |
293 | 37550 | nfrancisco | |
294 | 37575 | nfrancisco | public void mouseClicked(MouseEvent e) { |
295 | selectPackagesPanel.checkIfPluginSelected(); |
||
296 | } |
||
297 | 37550 | nfrancisco | |
298 | 37575 | nfrancisco | public void mouseEntered(MouseEvent e) { |
299 | } |
||
300 | 37550 | nfrancisco | |
301 | 37575 | nfrancisco | public void mouseExited(MouseEvent e) { |
302 | } |
||
303 | 37550 | nfrancisco | |
304 | 37575 | nfrancisco | public void mousePressed(MouseEvent e) { |
305 | } |
||
306 | 37550 | nfrancisco | |
307 | 37575 | nfrancisco | public void mouseReleased(MouseEvent e) { |
308 | } |
||
309 | } |
||
310 | 37550 | nfrancisco | |
311 | 37575 | nfrancisco | public SelectPackagesPanel getSelectPackagesPanel() {
|
312 | return this.selectPackagesPanel; |
||
313 | } |
||
314 | 37550 | nfrancisco | |
315 | 37575 | nfrancisco | public void clearAllPanels() { |
316 | filterPanel.resetPanel(); |
||
317 | descriptionTextArea.setText("");
|
||
318 | fastFilterPanel.resetPanel(); |
||
319 | } |
||
320 | 37550 | nfrancisco | |
321 | 37575 | nfrancisco | public void resetPanel() { |
322 | filterPanel.resetPanel(); |
||
323 | descriptionTextArea.setText("");
|
||
324 | } |
||
325 | 37550 | nfrancisco | |
326 | 37538 | nfrancisco | } |