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

History | View | Annotate | Download (5.12 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.impl.DefaultSwingInstallerManager;
46
import org.gvsig.installer.swing.impl.execution.model.PackagesTableCellRenderer;
47
import org.gvsig.installer.swing.impl.execution.model.PackagesTableModel;
48

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

    
54
    /**
55
     * 
56
     */
57
    private static final long serialVersionUID = 1202119227054423264L;
58
    protected DefaultSwingInstallerManager swingInstallerManager = null;
59
    private JScrollPane descriptionScrollPane;
60
    private JTextArea descriptionTextArea;
61
    private JScrollPane pluginsScrollPane;
62
    private JTable pluginsTable;
63

    
64
    public PackagesTablePanel(SelectPackagesPanel selectPluginsPanel) {
65
        super();
66
        swingInstallerManager =
67
            (DefaultSwingInstallerManager) SwingInstallerLocator
68
                .getSwingInstallerManager();
69
        initComponents();
70
        pluginsTable.getSelectionModel().addListSelectionListener(this);
71
        pluginsTable.setDefaultRenderer(Boolean.class,
72
            new PackagesTableCellRenderer(selectPluginsPanel));
73
        pluginsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
74
    }
75

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

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

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

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

    
100
        pluginsScrollPane = new JScrollPane();
101
        pluginsTable = new JTable();
102
        descriptionScrollPane = new JScrollPane();
103
        descriptionTextArea = new JTextArea();
104

    
105
        setLayout(new GridBagLayout());
106

    
107
        pluginsScrollPane.setViewportView(pluginsTable);
108

    
109
        gridBagConstraints = new GridBagConstraints();
110
        gridBagConstraints.fill = GridBagConstraints.BOTH;
111
        gridBagConstraints.weightx = 1.0;
112
        gridBagConstraints.weighty = 0.75;
113
        gridBagConstraints.insets = new Insets(2, 2, 2, 2);
114
        add(pluginsScrollPane, gridBagConstraints);
115

    
116
        descriptionTextArea.setEditable(false);
117
        descriptionTextArea.setColumns(20);
118
        descriptionTextArea.setRows(5);
119
        descriptionScrollPane.setViewportView(descriptionTextArea);
120

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

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