Statistics
| Revision:

root / 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 / PackagePropertiesFilterPanel.java @ 37584

History | View | Annotate | Download (6.11 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
import javax.swing.ListModel;
39

    
40
import org.gvsig.installer.lib.api.execution.InstallPackageService;
41
import org.gvsig.installer.swing.api.SwingInstallerLocator;
42
import org.gvsig.installer.swing.impl.DefaultSwingInstallerManager;
43
import org.gvsig.installer.swing.impl.execution.panel.filters.CategoryFilter;
44
import org.gvsig.installer.swing.impl.execution.panel.filters.PackageFilter;
45
import org.gvsig.installer.swing.impl.execution.panel.filters.TypeFilter;
46

    
47
/**
48
 * @author gvSIG Team
49
 * @version $Id$
50
 * 
51
 */
52
public class PackagePropertiesFilterPanel extends JPanel implements ActionListener {
53

    
54
        private static final long serialVersionUID = 3767011079359743742L;
55

    
56
        public enum PropertiesFilter {
57
                CATEGORIES, TYPES
58
        }
59

    
60
        private PackagesTablePanel packagesTablePanel;
61

    
62
        private JScrollPane filterScrollPane;
63
        private JList jList;
64
        private PropertiesFilter optionFilter = null;
65
        private DefaultListModel model = null;
66

    
67
        private DefaultSwingInstallerManager manager;
68

    
69
        public PackagePropertiesFilterPanel(PackagesTablePanel packagesTablePanel) {
70
                this.packagesTablePanel = packagesTablePanel;
71
                manager = (DefaultSwingInstallerManager) SwingInstallerLocator
72
                                .getSwingInstallerManager();
73
                initComponents();
74
        }
75

    
76
        private void initComponents() {
77

    
78
                model = new DefaultListModel();
79
                jList = new JList(model);
80

    
81
                filterScrollPane = new JScrollPane(jList);
82
                MyMouseListener mouseListener = new MyMouseListener();
83
                // filterScrollPane.addMouseListener(mouseListener);
84
                jList.addMouseListener(mouseListener);
85

    
86
                JButton categoriesButton = new JButton(manager.getText("_Categories"));
87
                categoriesButton.setActionCommand("categories");
88
                categoriesButton.addActionListener(this);
89

    
90
                JButton typesButton = new JButton(manager.getText("_Types"));
91
                typesButton.setActionCommand("types");
92
                typesButton.addActionListener(this);
93

    
94
                this.setLayout(new GridBagLayout());
95

    
96
                java.awt.GridBagConstraints gridBagConstraints;
97

    
98
                gridBagConstraints = new GridBagConstraints();
99
                gridBagConstraints.fill = GridBagConstraints.BOTH;
100
                gridBagConstraints.gridx = 0;
101
                gridBagConstraints.gridy = 0;
102
                gridBagConstraints.weightx = 1;
103
                gridBagConstraints.weighty = 1;
104
                // gridBagConstraints.gridheight = 3;
105
                gridBagConstraints.insets = new Insets(2, 2, 2, 2);
106
                this.add(filterScrollPane, gridBagConstraints);
107

    
108
                gridBagConstraints = new GridBagConstraints();
109
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
110
                gridBagConstraints.gridx = 0;
111
                gridBagConstraints.gridy = 1;
112
                gridBagConstraints.weightx = 1;
113
                gridBagConstraints.weighty = 0;
114
                gridBagConstraints.insets = new Insets(2, 2, 2, 2);
115
                this.add(categoriesButton, gridBagConstraints);
116

    
117
                gridBagConstraints = new GridBagConstraints();
118
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
119
                gridBagConstraints.gridx = 0;
120
                gridBagConstraints.gridy = 2;
121
                gridBagConstraints.weightx = 1;
122
                gridBagConstraints.weighty = 0;
123
                gridBagConstraints.insets = new Insets(2, 2, 2, 2);
124
                this.add(typesButton, gridBagConstraints);
125

    
126
        }
127

    
128
        public void resetPanel() {
129
                model.removeAllElements();
130
                optionFilter = null;
131
                PackageFilter filter = null;
132
                packagesTablePanel.setFilter(filter);
133
        }
134

    
135
        public void actionPerformed(ActionEvent e) {
136

    
137
                InstallPackageService service = packagesTablePanel
138
                                .getSelectPackagesPanel().getModel().getInstallPackageService();
139

    
140
                if ("categories".equals(e.getActionCommand())) {
141
                        this.optionFilter = PropertiesFilter.CATEGORIES;
142
                        model.removeAllElements();
143

    
144
                        List<String> categories = service.getCategories();
145

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

    
153
                } else {
154
                        if ("types".equals(e.getActionCommand())) {
155
                                this.optionFilter = PropertiesFilter.TYPES;
156
                                model.removeAllElements();
157

    
158
                                List<String> types = service.getTypes();
159

    
160
                                if (types != null) {
161
                                        String[] items = types.toArray((new String[0]));
162
                                        for (int i = 0; i < items.length; i++) {
163
                                                model.add(i, items[i]);
164
                                        }
165
                                }
166
                        }
167
                }
168
        }
169

    
170
        private class MyMouseListener implements MouseListener {
171

    
172
                public void mouseClicked(MouseEvent e) {
173
                        int i = jList.getSelectedIndex();
174
                        if (i >= 0) {
175
                                ListModel listModel = jList.getModel();
176
                                String element = listModel.getElementAt(i).toString();
177

    
178
                                // update packets list to filter
179
                                if (optionFilter == PropertiesFilter.TYPES) {
180
                                        TypeFilter typeFilter = new TypeFilter(element);
181
                                        packagesTablePanel.setFilter(typeFilter);
182
                                } else if (optionFilter == PropertiesFilter.CATEGORIES) {
183
                                        CategoryFilter categoryFilter = new CategoryFilter(element);
184
                                        packagesTablePanel.setFilter(categoryFilter);
185
                                }
186

    
187
                        }
188
                }
189

    
190
                public void mouseEntered(MouseEvent e) {
191
                }
192

    
193
                public void mouseExited(MouseEvent e) {
194
                }
195

    
196
                public void mousePressed(MouseEvent e) {
197
                }
198

    
199
                public void mouseReleased(MouseEvent e) {
200
                }
201

    
202
        }
203

    
204
}