Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.installer / org.gvsig.installer.swing / org.gvsig.installer.swing.impl / src / main / java / org / gvsig / installer / swing / impl / execution / panel / PackagePropertiesFilterPanel.java @ 40560

History | View | Annotate | Download (6.72 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.installer.swing.impl.execution.panel;
25

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

    
35
import javax.swing.DefaultListModel;
36
import javax.swing.JButton;
37
import javax.swing.JList;
38
import javax.swing.JPanel;
39
import javax.swing.JScrollPane;
40
import javax.swing.ListModel;
41

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

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

    
58
        private static final long serialVersionUID = 3767011079359743742L;
59

    
60
        public enum PropertiesFilter {
61
                CATEGORIES, TYPES
62
        }
63

    
64
        private PackagesTablePanel packagesTablePanel;
65

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

    
71
        private DefaultSwingInstallerManager manager;
72

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

    
80
        private void initComponents() {
81

    
82
                model = new DefaultListModel();
83
                jList = new JList(model);
84

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

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

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

    
98
                this.setLayout(new GridBagLayout());
99

    
100
                java.awt.GridBagConstraints gridBagConstraints;
101

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

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

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

    
130
        }
131

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

    
140
        public void actionPerformed(ActionEvent e) {
141

    
142
                InstallPackageService service = packagesTablePanel
143
                                .getSelectPackagesPanel().getModel().getInstallPackageService();
144

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

    
156
                                List<String> types = service.getTypes();
157

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

    
168
        private class MyMouseListener implements MouseListener {
169

    
170
                public void mouseClicked(MouseEvent e) {
171
                        int i = jList.getSelectedIndex();
172
                        if (i >= 0) {
173
                                ListModel listModel = jList.getModel();
174
                                PackageFilter filter = (PackageFilter) listModel.getElementAt(i);
175
                                packagesTablePanel.setFilter(filter);
176
                                
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
        private void loadCategories() {
205
               
206
            InstallPackageService service = packagesTablePanel
207
               .getSelectPackagesPanel().getModel().getInstallPackageService();
208
        model.removeAllElements();
209

    
210
        List<String> categories = service.getCategories();
211

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

    
226
}