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 / CategoriesFilterPanel.java @ 37575

History | View | Annotate | Download (6.09 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
package org.gvsig.installer.swing.impl.execution.panel;
23

    
24
import java.awt.GridBagConstraints;
25
import java.awt.GridBagLayout;
26
import java.awt.Insets;
27
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
29
import java.awt.event.MouseEvent;
30
import java.awt.event.MouseListener;
31
import java.util.List;
32

    
33
import javax.swing.DefaultListModel;
34
import javax.swing.JButton;
35
import javax.swing.JList;
36
import javax.swing.JPanel;
37
import javax.swing.JScrollPane;
38

    
39
import org.gvsig.installer.lib.api.execution.InstallPackageService;
40
import org.gvsig.installer.swing.api.SwingInstallerLocator;
41
import org.gvsig.installer.swing.impl.DefaultSwingInstallerManager;
42

    
43
/**
44
 * @author gvSIG Team
45
 * @version $Id$
46
 * 
47
 */
48
public class CategoriesFilterPanel extends JPanel implements ActionListener {
49

    
50
    private static final long serialVersionUID = 3767011079359743742L;
51

    
52
    private enum FilterType {
53
        CATEGORIES, TYPES
54
    }
55

    
56
    private PackagesTablePanel packagesTablePanel;
57

    
58
    private JScrollPane filterScrollPane;
59
    private JList jList;
60
    private FilterType filterType = null;
61
    private DefaultListModel model = null;
62

    
63
    private DefaultSwingInstallerManager manager;
64

    
65
    public CategoriesFilterPanel(PackagesTablePanel packagesTablePanel) {
66
        this.packagesTablePanel = packagesTablePanel;
67
        manager =
68
            (DefaultSwingInstallerManager) SwingInstallerLocator
69
                .getSwingInstallerManager();
70
        initComponents();
71
    }
72

    
73
    private void initComponents() {
74

    
75
        model = new DefaultListModel();
76
        jList = new JList(model);
77

    
78
        filterScrollPane = new JScrollPane(jList);
79

    
80
        JButton categoriesButton = new JButton(manager.getText("_Categories"));
81
        categoriesButton.setActionCommand("categories");
82
        categoriesButton.addActionListener(this);
83

    
84
        JButton typesButton = new JButton(manager.getText("_Types"));
85
        typesButton.setActionCommand("types");
86
        typesButton.addActionListener(this);
87

    
88
        this.setLayout(new GridBagLayout());
89

    
90
        java.awt.GridBagConstraints gridBagConstraints;
91

    
92
        gridBagConstraints = new GridBagConstraints();
93
        gridBagConstraints.fill = GridBagConstraints.BOTH;
94
        gridBagConstraints.gridx = 0;
95
        gridBagConstraints.gridy = 0;
96
        gridBagConstraints.weightx = 1;
97
        gridBagConstraints.weighty = 1;
98
        // gridBagConstraints.gridheight = 3;
99
        gridBagConstraints.insets = new Insets(2, 2, 2, 2);
100
        this.add(filterScrollPane, gridBagConstraints);
101

    
102
        gridBagConstraints = new GridBagConstraints();
103
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
104
        gridBagConstraints.gridx = 0;
105
        gridBagConstraints.gridy = 1;
106
        gridBagConstraints.weightx = 1;
107
        gridBagConstraints.weighty = 0;
108
        gridBagConstraints.insets = new Insets(2, 2, 2, 2);
109
        this.add(categoriesButton, gridBagConstraints);
110

    
111
        gridBagConstraints = new GridBagConstraints();
112
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
113
        gridBagConstraints.gridx = 0;
114
        gridBagConstraints.gridy = 2;
115
        gridBagConstraints.weightx = 1;
116
        gridBagConstraints.weighty = 0;
117
        gridBagConstraints.insets = new Insets(2, 2, 2, 2);
118
        this.add(typesButton, gridBagConstraints);
119

    
120
    }
121

    
122
    public void resetPanel() {
123
        model.removeAllElements();
124
    }
125
    
126
    /*
127
     * Sets the filter type, or null to set no filter
128
     */
129
    public void setFilterType(FilterType filter) {
130
        this.filterType = filter;
131
    }
132

    
133
    public FilterType getFilterType() {
134
        return this.filterType;
135
    }
136

    
137
    public void actionPerformed(ActionEvent e) {
138

    
139
        InstallPackageService service =
140
            packagesTablePanel.getSelectPackagesPanel().getModel()
141
                .getInstallPackageService();
142

    
143
        if ("categories".equals(e.getActionCommand())) {
144
            this.filterType = FilterType.CATEGORIES;
145
            model.removeAllElements();
146

    
147
            List<String> categories = service.getCategories();
148

    
149
            if (categories != null) {
150
                String[] items = categories.toArray((new String[0]));
151
                for (int i = 0; i < items.length; i++) {
152
                    model.add(i, items[i]);
153
                }
154
            }
155

    
156
        } else {
157
            if ("types".equals(e.getActionCommand())) {
158
                this.filterType = FilterType.TYPES;
159
                model.removeAllElements();
160

    
161
                List<String> types = service.getTypes();
162

    
163
                if (types != null) {
164
                    String[] items = types.toArray((new String[0]));
165
                    for (int i = 0; i < items.length; i++) {
166
                        model.add(i, items[i]);
167
                    }
168
                }
169
            }
170
        }
171
    }
172
    
173
    private class MyKeyListener implements MouseListener {
174

    
175
                public void mouseClicked(MouseEvent e) {
176
                        // TODO Auto-generated method stub
177
                        
178
                }
179

    
180
                public void mouseEntered(MouseEvent e) {
181
                        // TODO Auto-generated method stub
182
                        
183
                }
184

    
185
                public void mouseExited(MouseEvent e) {
186
                        // TODO Auto-generated method stub
187
                        
188
                }
189

    
190
                public void mousePressed(MouseEvent e) {
191
                        // TODO Auto-generated method stub
192
                        
193
                }
194

    
195
                public void mouseReleased(MouseEvent e) {
196
                        // TODO Auto-generated method stub
197
                        
198
                }
199

    
200

    
201
    }
202

    
203
}