Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / org.gvsig.newlayer / org.gvsig.newlayer.lib / org.gvsig.newlayer.lib.impl / src / main / java / org / gvsig / newlayer / impl / TypeSelectorPanel.java @ 38549

History | View | Annotate | Download (2.49 KB)

1
package org.gvsig.newlayer.impl;
2

    
3
import java.awt.BorderLayout;
4

    
5
import javax.swing.DefaultListSelectionModel;
6
import javax.swing.JList;
7
import javax.swing.JPanel;
8
import javax.swing.JScrollPane;
9
import javax.swing.ListModel;
10
import javax.swing.event.ListSelectionEvent;
11
import javax.swing.event.ListSelectionListener;
12

    
13
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException;
14
import org.gvsig.gui.beans.wizard.panel.OptionPanel;
15
import org.gvsig.newlayer.NewLayerProviderFactory;
16
import org.gvsig.newlayer.NewLayerService;
17
import org.gvsig.newlayer.NewLayerWizard;
18

    
19
public class TypeSelectorPanel extends JPanel implements OptionPanel{
20
        
21
        /**
22
         * 
23
         */
24
        private static final long serialVersionUID = 419873365484240927L;
25
        private NewLayerWizard wizard;
26
    private NewLayerProviderFactory currentType;
27

    
28
        public TypeSelectorPanel(NewLayerWizard wizard){
29
                this.wizard = wizard;
30
                initializeComponents();
31
        }
32

    
33
        public String getPanelTitle() {
34
                return "Type selector panel";
35
        }
36

    
37
        public void nextPanel() throws NotContinueWizardException {
38
                if (currentType!=null){
39
                        this.wizard.setType(currentType);
40
                        return;
41
                }
42
                throw new NotContinueWizardException("", null, false);
43
        }
44

    
45
        public void lastPanel() {
46
                // do nothing
47
                
48
        }
49

    
50
        public void updatePanel() {
51
                initializeComponents();
52
        }
53

    
54
        public JPanel getJPanel() {
55
                return this;
56
        }
57

    
58
    private void initializeComponents() {
59
        this.setLayout(new BorderLayout());
60

    
61
        JList types = new JList();     
62
        ListModel model =
63
            new org.gvsig.utils.DefaultListModel(this.getService()
64
                .getProviderFactories());
65
       
66
        types.setModel(model);
67
        types.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
68
        
69
        types.addListSelectionListener(new ListSelectionListener() {
70
                        public void valueChanged(ListSelectionEvent e) {
71
                                if (e.getValueIsAdjusting() == false) {
72
                                        JList list = (JList) e.getSource();
73
                                        
74
                                if (list.getSelectedIndex() > -1) {
75
                        currentType =
76
                            (NewLayerProviderFactory) list.getSelectedValue();
77
                        
78
                        wizard.setNextButtonEnabled(true);
79
                                } else {
80
                                    wizard.setNextButtonEnabled(false);
81
                                }
82
                            }
83
                        }
84
                });
85
        
86
        JScrollPane scrollPane = new JScrollPane();
87
        scrollPane.setViewportView(types);
88
        this.add(scrollPane, BorderLayout.CENTER);        
89
    }
90

    
91
        private NewLayerService getService() {
92
                return this.wizard.getService();
93
        } 
94
}