Statistics
| Revision:

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 @ 33743

History | View | Annotate | Download (5.26 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.GridBagConstraints;
31
import java.awt.GridBagLayout;
32
import java.awt.Insets;
33
import java.util.List;
34

    
35
import javax.swing.JPanel;
36
import javax.swing.JScrollPane;
37
import javax.swing.JTable;
38
import javax.swing.JTextArea;
39
import javax.swing.event.ListSelectionEvent;
40
import javax.swing.event.ListSelectionListener;
41
import javax.swing.table.TableColumnModel;
42

    
43
import org.gvsig.installer.lib.api.PackageInfo;
44
import org.gvsig.installer.swing.api.SwingInstallerLocator;
45
import org.gvsig.installer.swing.api.SwingInstallerManager;
46
import org.gvsig.installer.swing.impl.execution.model.PackagesTableModel;
47

    
48
/**
49
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
50
 */
51
public class PackagesTablePanel extends JPanel implements ListSelectionListener {
52

    
53
    private static final long serialVersionUID = 1202119227054423264L;
54
    protected SwingInstallerManager swingInstallerManager = null;
55
    private JScrollPane descriptionScrollPane;
56
    private JTextArea descriptionTextArea;
57
    private JScrollPane pluginsScrollPane;
58
    private JTable pluginsTable;
59

    
60
    public PackagesTablePanel(SelectPackagesPanel selectPluginsPanel) {
61
        super();
62
        swingInstallerManager =
63
            SwingInstallerLocator.getSwingInstallerManager();
64
        initComponents();
65
        pluginsTable.getSelectionModel().addListSelectionListener(this);
66
        pluginsTable.setDefaultRenderer(Boolean.class,
67
            new PackageToInstallCellRenderer(selectPluginsPanel));
68
        AbstractTablePackageInfoCellRenderer ipcr = new InstalledPackageCellRenderer();
69
        pluginsTable.setDefaultRenderer(String.class, ipcr);
70
        pluginsTable.setDefaultRenderer(Number.class, ipcr);
71
        pluginsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
72
    }
73

    
74
    public void setTableModel(PackagesTableModel pluginsTableModel) {
75
        pluginsTable.setModel(pluginsTableModel);
76
        TableColumnModel tableColumnModel = pluginsTable.getColumnModel();
77
        tableColumnModel.getColumn(0).setPreferredWidth(25);
78
        tableColumnModel.getColumn(1).setPreferredWidth(150);
79
        tableColumnModel.getColumn(2).setPreferredWidth(70);
80
        tableColumnModel.getColumn(3).setPreferredWidth(75);
81
        tableColumnModel.getColumn(4).setPreferredWidth(150);
82
        tableColumnModel.getColumn(5).setPreferredWidth(50);
83
        tableColumnModel.getColumn(6).setPreferredWidth(50);
84
        tableColumnModel.getColumn(7).setPreferredWidth(50);
85
        tableColumnModel.getColumn(8).setPreferredWidth(50);
86
    }
87

    
88
    public void addPackageInfosToInstall(List<PackageInfo> packageInfosToInstall) {
89
        ((PackagesTableModel) pluginsTable.getModel())
90
            .addPackageInfosToInstall(packageInfosToInstall);
91
    }
92

    
93
    public boolean isPackageSelected() {
94
        return ((PackagesTableModel) pluginsTable.getModel())
95
            .hasAnyPackageSelected();
96
    }
97

    
98
    private void initComponents() {
99
        java.awt.GridBagConstraints gridBagConstraints;
100

    
101
        pluginsTable = new JTable();
102
        pluginsScrollPane = new JScrollPane(pluginsTable);
103

    
104
        descriptionTextArea = new JTextArea();
105
        descriptionTextArea.setEditable(false);
106
        descriptionTextArea.setColumns(20);
107
        descriptionTextArea.setRows(5);
108

    
109
        descriptionScrollPane = new JScrollPane(descriptionTextArea);
110

    
111
        setLayout(new GridBagLayout());
112

    
113
        gridBagConstraints = new GridBagConstraints();
114
        gridBagConstraints.fill = GridBagConstraints.BOTH;
115
        gridBagConstraints.weightx = 1.0;
116
        gridBagConstraints.weighty = 0.75;
117
        gridBagConstraints.insets = new Insets(2, 2, 2, 2);
118
        add(pluginsScrollPane, gridBagConstraints);
119

    
120
        gridBagConstraints = new GridBagConstraints();
121
        gridBagConstraints.gridx = 0;
122
        gridBagConstraints.gridy = 1;
123
        gridBagConstraints.fill = GridBagConstraints.BOTH;
124
        gridBagConstraints.weightx = 1.0;
125
        gridBagConstraints.weighty = 0.25;
126
        gridBagConstraints.insets = new Insets(2, 2, 2, 2);
127
        add(descriptionScrollPane, gridBagConstraints);
128
    }
129

    
130
    public void valueChanged(ListSelectionEvent e) {
131
        int row = pluginsTable.getSelectedRow();
132
        if (row != -1) {
133
            descriptionTextArea.setText(((PackagesTableModel) pluginsTable
134
                .getModel()).getDescriptionAt(row));
135
        }
136
    }
137
}