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

History | View | Annotate | Download (5.62 KB)

1 36022 fdiaz
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 36220 fdiaz
import javax.swing.JOptionPane;
9 36022 fdiaz
import javax.swing.JPanel;
10
11 36113 fdiaz
import jwizardcomponent.CancelAction;
12 36022 fdiaz
import jwizardcomponent.DefaultJWizardComponents;
13
import jwizardcomponent.FinishAction;
14
import jwizardcomponent.JWizardComponents;
15
16 37804 jpiera
import org.slf4j.Logger;
17
import org.slf4j.LoggerFactory;
18
19 38533 jldominguez
import org.gvsig.fmap.dal.DALLocator;
20
import org.gvsig.fmap.dal.DataStoreProviderFactory;
21
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory;
22 36022 fdiaz
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException;
23
import org.gvsig.gui.beans.wizard.panel.OptionPanel;
24 37804 jpiera
import org.gvsig.i18n.Messages;
25
import org.gvsig.newlayer.NewLayerException;
26 37891 cordinyana
import org.gvsig.newlayer.NewLayerProviderFactory;
27 36022 fdiaz
import org.gvsig.newlayer.NewLayerProviderPanel;
28
import org.gvsig.newlayer.NewLayerService;
29
import org.gvsig.newlayer.NewLayerServiceException;
30
import org.gvsig.newlayer.NewLayerWizard;
31
32
public class DefaultNewLayerWizard extends NewLayerWizard {
33
34
        /**
35
         *
36
         */
37
        private static final long serialVersionUID = -5827106636136663823L;
38
        private NewLayerService service;
39 36220 fdiaz
        private AddNewLayerQuestionPanel addNewLayerQuestionPanel;
40
        private static final Logger LOG =
41
        LoggerFactory.getLogger(DefaultNewLayerWizard.class);
42 36022 fdiaz
43
        public DefaultNewLayerWizard(ImageIcon logo, NewLayerService service) {
44
                super(logo);
45 36228 fdiaz
                setPreferredSize(new Dimension(800, 400));
46 36022 fdiaz
                this.service = service;
47 36220 fdiaz
                this.getWizardComponents().setFinishAction(
48
                                new MyFinishAction(this.getWizardComponents()));
49
                this.getWizardComponents().setCancelAction(
50
                                new MyCancelAction(this.getWizardComponents()));
51 36022 fdiaz
                this.createTypeSelector();
52
        }
53
54 36220 fdiaz
        public NewLayerService getService() {
55 36022 fdiaz
                return this.service;
56
        }
57 36220 fdiaz
58 36022 fdiaz
        private void createTypeSelector() {
59 36220 fdiaz
60 36022 fdiaz
                TypeSelectorPanel panel = new TypeSelectorPanel(this);
61
                this.addOptionPanel(panel);
62 36220 fdiaz
63 36022 fdiaz
        }
64 36220 fdiaz
65 36022 fdiaz
        private void createFeatureTypePanel() {
66 38533 jldominguez
67
                FeatureTypePanel panel = new FeatureTypePanel(service);
68 36022 fdiaz
                this.addOptionPanel(panel);
69
        }
70
71
        private void createProviderPanels() {
72 36220 fdiaz
                DefaultJWizardComponents wizardComponents = this.getWizardComponents();
73
                for (int i = wizardComponents.getWizardPanelList().size() - 1; i >= 1; i--) {
74
                        wizardComponents.removeWizardPanel(i);
75
                }
76
                List<NewLayerProviderPanel> panels = service.getProvider().getPanels();
77
                Iterator<NewLayerProviderPanel> it = panels.iterator();
78
                while (it.hasNext()) {
79
                        NewLayerProviderPanel panel = it.next();
80
                        this.addOptionPanel(new OptionPanelWrapper(panel));
81
                }
82
                this.createFeatureTypePanel();
83
                this.createAddNewLayerQuestionPanel();
84 36022 fdiaz
        }
85
86 36220 fdiaz
        private AddNewLayerQuestionPanel getAddNewLayerQuestionPanel() {
87
                if (this.addNewLayerQuestionPanel == null) {
88
                        this.addNewLayerQuestionPanel = new AddNewLayerQuestionPanel(this);
89
                }
90
                return this.addNewLayerQuestionPanel;
91
        }
92
93
        private void createAddNewLayerQuestionPanel() {
94
                this.addOptionPanel(getAddNewLayerQuestionPanel());
95
        }
96
97
        private boolean getAddLayerToView() {
98
                return getAddNewLayerQuestionPanel().getAddLayerToView();
99
        }
100
101 36022 fdiaz
        @Override
102 37891 cordinyana
    public void setType(NewLayerProviderFactory currentType) {
103
        this.service.setProviderFactory(currentType);
104 36022 fdiaz
                createProviderPanels();
105
        }
106 36220 fdiaz
107 36022 fdiaz
        private class OptionPanelWrapper implements OptionPanel {
108 36220 fdiaz
109 36022 fdiaz
                private NewLayerProviderPanel panel;
110
111
                public OptionPanelWrapper(NewLayerProviderPanel panel) {
112
                        this.panel = panel;
113
                }
114
115
                public String getPanelTitle() {
116
                        return this.panel.getTitle();
117
                }
118
119
                public void nextPanel() throws NotContinueWizardException {
120 36220 fdiaz
121 37804 jpiera
                    try {
122
                            if (!this.panel.isValidPanel()) {
123
                                    throw new NotContinueWizardException("Error validating the form", panel, false);
124
                            }
125
                    } catch (NewLayerException e) {
126 38367 jldominguez
                LOG.info("Error validating the form", e);
127 37804 jpiera
                throw new NotContinueWizardException("Error validating the form",
128
                    e, panel);
129
            }
130 36022 fdiaz
                }
131
132
                public void lastPanel() {
133
                }
134
135
                public void updatePanel() {
136
                        this.panel.updatePanel();
137
                }
138
139
                public JPanel getJPanel() {
140
                        return this.panel;
141
                }
142 36220 fdiaz
143 36022 fdiaz
        }
144 36220 fdiaz
145 36022 fdiaz
        private class MyFinishAction extends FinishAction {
146
147
                public MyFinishAction(JWizardComponents arg0) {
148
                        super(arg0);
149
                }
150
151
                public void performAction() {
152 36220 fdiaz
153
                        if (getService().getStoreName() == null) {
154
                                JOptionPane
155
                                .showMessageDialog(
156
                                                null,
157 37804 jpiera
                                                Messages.getText("new_layer_not_store_name"),
158
                                                Messages.getText("new_layer"),
159 36220 fdiaz
                                                JOptionPane.WARNING_MESSAGE);
160
                                return;
161 36113 fdiaz
                        }
162 36220 fdiaz
                        if (getService().getNewStoreParameters() == null) {
163
                                JOptionPane
164
                                .showMessageDialog(
165
                                                null,
166 37804 jpiera
                                                Messages.getText("new_layer_parameters_missing"),
167
                                                Messages.getText("new_layer"),
168 36220 fdiaz
                                                JOptionPane.WARNING_MESSAGE);
169
                                return;
170 36113 fdiaz
                        }
171 36220 fdiaz
                        getService().addLayerToView(getAddLayerToView());
172 36022 fdiaz
                        try {
173
                                getService().createLayer();
174
                        } catch (NewLayerServiceException e) {
175 38367 jldominguez
                                LOG.info("Cannot create the new layer", e);
176 36220 fdiaz
                                JOptionPane
177
                                .showMessageDialog(
178
                                                null,
179 37804 jpiera
                                                Messages.getText("cant_create_new_layer") + "\n" + e.getMessageStack(),
180
                                                Messages.getText("new_layer"),
181 36220 fdiaz
                                                JOptionPane.ERROR_MESSAGE);
182
                                return;
183 36022 fdiaz
                        }
184 36220 fdiaz
185
                        try {
186
                                getService().loadLayer();
187
                        } catch (NewLayerServiceException e) {
188
                                JOptionPane
189
                                .showMessageDialog(
190
                                                null,
191
                                                "The new layer has been succesfully created but can't load the new layer.\n Try load it yourshelf, please.",
192
                                                "Can't create a new layer",
193
                                                JOptionPane.WARNING_MESSAGE);
194
                        }
195
                        setVisible(false);
196
                        return;
197 36022 fdiaz
                }
198
199
        }
200 36220 fdiaz
201 36113 fdiaz
        private class MyCancelAction extends CancelAction {
202 36220 fdiaz
203 36113 fdiaz
                public MyCancelAction(DefaultJWizardComponents wizardComponents) {
204
                        super(wizardComponents);
205
                }
206
207
                public void performAction() {
208 36220 fdiaz
                        setVisible(false);
209 36113 fdiaz
                }
210 36220 fdiaz
211 36113 fdiaz
        }
212 36022 fdiaz
}