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 / DefaultNewLayerWizard.java @ 36022

History | View | Annotate | Download (3.15 KB)

1
package org.gvsig.newlayer.impl;
2

    
3
import java.awt.Dimension;
4
import java.util.Iterator;
5
import java.util.List;
6

    
7
import javax.swing.ImageIcon;
8
import javax.swing.JPanel;
9

    
10
import jwizardcomponent.DefaultJWizardComponents;
11
import jwizardcomponent.FinishAction;
12
import jwizardcomponent.JWizardComponents;
13

    
14
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException;
15
import org.gvsig.gui.beans.wizard.panel.OptionPanel;
16
import org.gvsig.newlayer.NewLayerProviderPanel;
17
import org.gvsig.newlayer.NewLayerService;
18
import org.gvsig.newlayer.NewLayerServiceException;
19
import org.gvsig.newlayer.NewLayerWizard;
20
import org.gvsig.newlayer.spi.AbstractNewLayerProvider;
21

    
22
public class DefaultNewLayerWizard extends NewLayerWizard {
23

    
24
        /**
25
         * 
26
         */
27
        private static final long serialVersionUID = -5827106636136663823L;
28
        private NewLayerService service;
29

    
30
        public DefaultNewLayerWizard(ImageIcon logo, NewLayerService service) {
31
                super(logo);
32
                setPreferredSize(new Dimension(600,400));
33
                this.service = service;
34
                this.getWizardComponents().setFinishAction(new MyFinishAction(this.getWizardComponents()));
35
                this.createTypeSelector();
36
        }
37

    
38
        public NewLayerService getService(){
39
                return this.service;
40
        }
41
        
42
        private void createTypeSelector() {
43
                
44
                TypeSelectorPanel panel = new TypeSelectorPanel(this);
45
                this.addOptionPanel(panel);
46
                
47
        }
48
        
49
        private void createFeatureTypePanel() {
50
                
51
                FeatureTypePanel panel = new FeatureTypePanel(this);
52
                this.addOptionPanel(panel);
53

    
54
        }
55

    
56
        private void createProviderPanels() {
57
               DefaultJWizardComponents wizardComponents = this.getWizardComponents();              
58
                for (int i=wizardComponents.getWizardPanelList().size()-1 ; i>=1 ; i--){
59
                    wizardComponents.removeWizardPanel(i);
60
                }
61
                List<NewLayerProviderPanel> panels = service.getProvider().getPanels();
62
                Iterator<NewLayerProviderPanel> it = panels.iterator();
63
                while (it.hasNext()) {
64
                        NewLayerProviderPanel panel = it.next();
65
                                this.addOptionPanel(new OptionPanelWrapper(panel));
66
                        }
67
                this.createFeatureTypePanel();
68
        }
69

    
70
        @Override
71
        public void setType(String currentType) {
72
                this.service.setType(currentType);
73
                createProviderPanels();
74
        }
75
        
76
        private class OptionPanelWrapper implements OptionPanel {
77
                
78
                private NewLayerProviderPanel panel;
79

    
80
                public OptionPanelWrapper(NewLayerProviderPanel panel) {
81
                        this.panel = panel;
82
                }
83

    
84
                public String getPanelTitle() {
85
                        return this.panel.getTitle();
86
                }
87

    
88
                public void nextPanel() throws NotContinueWizardException {
89
                        
90
                        if(!this.panel.isValidPanel()){
91
                                throw new NotContinueWizardException("", null, false);
92
                        }
93
                        
94
                }
95

    
96
                public void lastPanel() {
97
                }
98

    
99
                public void updatePanel() {
100
                        this.panel.updatePanel();
101
                }
102

    
103
                public JPanel getJPanel() {
104
                        return this.panel;
105
                }
106
                
107
        }
108
        
109
        private class MyFinishAction extends FinishAction {
110

    
111
                public MyFinishAction(JWizardComponents arg0) {
112
                        super(arg0);
113
                        // TODO Auto-generated constructor stub
114
                }
115

    
116
                public void performAction() {
117
                        //Comprobar storeName y storeParameters y pedirlos si no est?n 
118
                        try {
119
                                getService().createLayer();
120
                        } catch (NewLayerServiceException e) {
121
                                // TODO Auto-generated catch block
122
                                e.printStackTrace();
123
                        }
124
                }
125

    
126
        }
127
}