Statistics
| Revision:

root / tags / v2_0_0_Build_2050 / 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 @ 38692

History | View | Annotate | Download (6.67 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.AllFilter;
44
import org.gvsig.installer.swing.impl.execution.panel.filters.CategoryFilter;
45
import org.gvsig.installer.swing.impl.execution.panel.filters.PackageFilter;
46
import org.gvsig.installer.swing.impl.execution.panel.filters.TypeFilter;
47

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

    
56
        private static final long serialVersionUID = 3767011079359743742L;
57

    
58
        public enum PropertiesFilter {
59
                CATEGORIES, TYPES
60
        }
61

    
62
        private PackagesTablePanel packagesTablePanel;
63

    
64
        private JScrollPane filterScrollPane;
65
        private JList jList;
66
//        private PropertiesFilter optionFilter = null;
67
        private DefaultListModel model = null;
68

    
69
        private DefaultSwingInstallerManager manager;
70

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

    
78
        private void initComponents() {
79

    
80
                model = new DefaultListModel();
81
                jList = new JList(model);
82

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

    
88
                JButton categoriesButton = new JButton(manager.getText("_categories"));
89
                categoriesButton.setActionCommand("categories");
90
                categoriesButton.addActionListener(this);
91

    
92
                JButton typesButton = new JButton(manager.getText("_types"));
93
                typesButton.setActionCommand("types");
94
                typesButton.addActionListener(this);
95

    
96
                this.setLayout(new GridBagLayout());
97

    
98
                java.awt.GridBagConstraints gridBagConstraints;
99

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

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

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

    
128
        }
129

    
130
        public void resetPanel() {
131
                model.removeAllElements();
132
                
133
                // optionFilter = null;
134
                PackageFilter filter = null;
135
                packagesTablePanel.setFilter(filter);
136
        }
137

    
138
        public void actionPerformed(ActionEvent e) {
139

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

    
143
                if ("categories".equals(e.getActionCommand())) {
144
                    
145
                    packagesTablePanel.resetPanel();
146
                    loadCategories();
147
                        
148
                } else {
149
                        if ("types".equals(e.getActionCommand())) {
150
//                                this.optionFilter = PropertiesFilter.TYPES;
151
                                model.removeAllElements();
152
                                packagesTablePanel.resetPanel();
153

    
154
                                List<String> types = service.getTypes();
155

    
156
                                model.add(0,new AllFilter());
157
                                if (types != null) {
158
                                        for (int i = 0; i < types.size(); i++) {
159
                                                model.add(i+1, new TypeFilter(types.get(i)));
160
                                        }
161
                                }
162
                        }
163
                }
164
        }
165

    
166
        private class MyMouseListener implements MouseListener {
167

    
168
                public void mouseClicked(MouseEvent e) {
169
                        int i = jList.getSelectedIndex();
170
                        if (i >= 0) {
171
                                ListModel listModel = jList.getModel();
172
                                PackageFilter filter = (PackageFilter) listModel.getElementAt(i);
173
                                packagesTablePanel.setFilter(filter);
174
                                
175
//                                
176
//                                // update packets list to filter
177
//                                if (optionFilter == PropertiesFilter.TYPES) {
178
//                                        TypeFilter typeFilter = new TypeFilter(element);
179
//                                        packagesTablePanel.setFilter(typeFilter);
180
//                                } else if (optionFilter == PropertiesFilter.CATEGORIES) {
181
//                                        CategoryFilter categoryFilter = new CategoryFilter(element);
182
//                                        packagesTablePanel.setFilter(categoryFilter);
183
//                                }
184

    
185
                        }
186
                }
187

    
188
                public void mouseEntered(MouseEvent e) {
189
                }
190

    
191
                public void mouseExited(MouseEvent e) {
192
                }
193

    
194
                public void mousePressed(MouseEvent e) {
195
                }
196

    
197
                public void mouseReleased(MouseEvent e) {
198
                }
199

    
200
        }
201
        
202
        private void loadCategories() {
203
               
204
            InstallPackageService service = packagesTablePanel
205
               .getSelectPackagesPanel().getModel().getInstallPackageService();
206
        model.removeAllElements();
207

    
208
        List<String> categories = service.getCategories();
209

    
210
        model.add(0,new AllFilter());
211
        if (categories != null) {
212
            for (int i = 0; i < categories.size(); i++) {
213
                model.add(i+1, new CategoryFilter(categories.get(i)));
214
            }
215
        }
216
        jList.setSelectedIndex(0);
217
            
218
        }
219
        
220
        public void setInitialFilter() {
221
            loadCategories();
222
        }
223

    
224
}