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

History | View | Annotate | Download (6.86 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.api.execution.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
    private JButton typesButton;
73

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

    
81
        private void initComponents() {
82

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

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

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

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

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

    
101
                java.awt.GridBagConstraints gridBagConstraints;
102

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

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

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

    
131
        }
132

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

    
141
        public void actionPerformed(ActionEvent e) {
142

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

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

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

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

    
169
        void setEnabledTypeFilter(boolean enabled) {
170
            this.typesButton.setEnabled(enabled);
171
        }
172

    
173
        private class MyMouseListener implements MouseListener {
174

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

    
192
                        }
193
                }
194

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

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

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

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

    
207
        }
208
        
209
        private void loadCategories() {
210
               
211
            InstallPackageService service = packagesTablePanel
212
               .getSelectPackagesPanel().getModel().getInstallPackageService();
213
        model.removeAllElements();
214

    
215
        List<String> categories = service.getCategories();
216

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

    
231
}