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

History | View | Annotate | Download (6.35 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
//                optionFilter = null;
133
                PackageFilter filter = null;
134
                packagesTablePanel.setFilter(filter);
135
        }
136

    
137
        public void actionPerformed(ActionEvent e) {
138

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

    
142
                if ("categories".equals(e.getActionCommand())) {
143
//                        this.optionFilter = PropertiesFilter.CATEGORIES;
144
                        model.removeAllElements();
145
                        packagesTablePanel.resetPanel();
146

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

    
149
                        model.add(0,new AllFilter());
150
                        if (categories != null) {
151
                                for (int i = 0; i < categories.size(); i++) {
152
                                        model.add(i+1, new CategoryFilter(categories.get(i)));
153
                                }
154
                        }
155
                        
156
                } else {
157
                        if ("types".equals(e.getActionCommand())) {
158
//                                this.optionFilter = PropertiesFilter.TYPES;
159
                                model.removeAllElements();
160
                                packagesTablePanel.resetPanel();
161

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

    
164
                                model.add(0,new AllFilter());
165
                                if (types != null) {
166
                                        for (int i = 0; i < types.size(); i++) {
167
                                                model.add(i+1, new TypeFilter(types.get(i)));
168
                                        }
169
                                }
170
                        }
171
                }
172
        }
173

    
174
        private class MyMouseListener implements MouseListener {
175

    
176
                public void mouseClicked(MouseEvent e) {
177
                        int i = jList.getSelectedIndex();
178
                        if (i >= 0) {
179
                                ListModel listModel = jList.getModel();
180
                                PackageFilter filter = (PackageFilter) listModel.getElementAt(i);
181
                                packagesTablePanel.setFilter(filter);
182
                                
183
//                                
184
//                                // update packets list to filter
185
//                                if (optionFilter == PropertiesFilter.TYPES) {
186
//                                        TypeFilter typeFilter = new TypeFilter(element);
187
//                                        packagesTablePanel.setFilter(typeFilter);
188
//                                } else if (optionFilter == PropertiesFilter.CATEGORIES) {
189
//                                        CategoryFilter categoryFilter = new CategoryFilter(element);
190
//                                        packagesTablePanel.setFilter(categoryFilter);
191
//                                }
192

    
193
                        }
194
                }
195

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

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

    
202
                public void mousePressed(MouseEvent e) {
203
                }
204

    
205
                public void mouseReleased(MouseEvent e) {
206
                }
207

    
208
        }
209

    
210
}