svn-gvsig-desktop / tags / v2_0_0_Build_2055 / libraries / org.gvsig.newlayer / org.gvsig.newlayer.lib / org.gvsig.newlayer.lib.impl / src / main / java / org / gvsig / newlayer / impl / DefaultNewLayerWizard.java @ 38983
History | View | Annotate | Download (5.79 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 | 38549 | jldominguez | |
53 | // ================ disable at the start
|
||
54 | this.setFinishButtonEnabled(false); |
||
55 | this.setBackButtonEnabled(false); |
||
56 | this.setNextButtonEnabled(false); |
||
57 | 36022 | fdiaz | } |
58 | |||
59 | 36220 | fdiaz | public NewLayerService getService() {
|
60 | 36022 | fdiaz | return this.service; |
61 | } |
||
62 | 36220 | fdiaz | |
63 | 36022 | fdiaz | private void createTypeSelector() { |
64 | 36220 | fdiaz | |
65 | 36022 | fdiaz | TypeSelectorPanel panel = new TypeSelectorPanel(this); |
66 | this.addOptionPanel(panel);
|
||
67 | 36220 | fdiaz | |
68 | 36022 | fdiaz | } |
69 | 36220 | fdiaz | |
70 | 36022 | fdiaz | private void createFeatureTypePanel() { |
71 | 38533 | jldominguez | |
72 | FeatureTypePanel panel = new FeatureTypePanel(service);
|
||
73 | 36022 | fdiaz | this.addOptionPanel(panel);
|
74 | } |
||
75 | |||
76 | private void createProviderPanels() { |
||
77 | 36220 | fdiaz | DefaultJWizardComponents wizardComponents = this.getWizardComponents();
|
78 | for (int i = wizardComponents.getWizardPanelList().size() - 1; i >= 1; i--) { |
||
79 | wizardComponents.removeWizardPanel(i); |
||
80 | } |
||
81 | List<NewLayerProviderPanel> panels = service.getProvider().getPanels();
|
||
82 | Iterator<NewLayerProviderPanel> it = panels.iterator();
|
||
83 | while (it.hasNext()) {
|
||
84 | NewLayerProviderPanel panel = it.next(); |
||
85 | this.addOptionPanel(new OptionPanelWrapper(panel)); |
||
86 | } |
||
87 | this.createFeatureTypePanel();
|
||
88 | this.createAddNewLayerQuestionPanel();
|
||
89 | 36022 | fdiaz | } |
90 | |||
91 | 36220 | fdiaz | private AddNewLayerQuestionPanel getAddNewLayerQuestionPanel() {
|
92 | if (this.addNewLayerQuestionPanel == null) { |
||
93 | this.addNewLayerQuestionPanel = new AddNewLayerQuestionPanel(this); |
||
94 | } |
||
95 | return this.addNewLayerQuestionPanel; |
||
96 | } |
||
97 | |||
98 | private void createAddNewLayerQuestionPanel() { |
||
99 | this.addOptionPanel(getAddNewLayerQuestionPanel());
|
||
100 | } |
||
101 | |||
102 | private boolean getAddLayerToView() { |
||
103 | return getAddNewLayerQuestionPanel().getAddLayerToView();
|
||
104 | } |
||
105 | |||
106 | 36022 | fdiaz | @Override
|
107 | 37891 | cordinyana | public void setType(NewLayerProviderFactory currentType) { |
108 | this.service.setProviderFactory(currentType);
|
||
109 | 36022 | fdiaz | createProviderPanels(); |
110 | } |
||
111 | 36220 | fdiaz | |
112 | 36022 | fdiaz | private class OptionPanelWrapper implements OptionPanel { |
113 | 36220 | fdiaz | |
114 | 36022 | fdiaz | private NewLayerProviderPanel panel;
|
115 | |||
116 | public OptionPanelWrapper(NewLayerProviderPanel panel) {
|
||
117 | this.panel = panel;
|
||
118 | } |
||
119 | |||
120 | public String getPanelTitle() { |
||
121 | return this.panel.getTitle(); |
||
122 | } |
||
123 | |||
124 | public void nextPanel() throws NotContinueWizardException { |
||
125 | 36220 | fdiaz | |
126 | 37804 | jpiera | try {
|
127 | if (!this.panel.isValidPanel()) { |
||
128 | throw new NotContinueWizardException("Error validating the form", panel, false); |
||
129 | } |
||
130 | } catch (NewLayerException e) {
|
||
131 | 38367 | jldominguez | LOG.info("Error validating the form", e);
|
132 | 37804 | jpiera | throw new NotContinueWizardException("Error validating the form", |
133 | e, panel); |
||
134 | } |
||
135 | 36022 | fdiaz | } |
136 | |||
137 | public void lastPanel() { |
||
138 | } |
||
139 | |||
140 | public void updatePanel() { |
||
141 | this.panel.updatePanel();
|
||
142 | } |
||
143 | |||
144 | public JPanel getJPanel() { |
||
145 | return this.panel; |
||
146 | } |
||
147 | 36220 | fdiaz | |
148 | 36022 | fdiaz | } |
149 | 36220 | fdiaz | |
150 | 36022 | fdiaz | private class MyFinishAction extends FinishAction { |
151 | |||
152 | public MyFinishAction(JWizardComponents arg0) {
|
||
153 | super(arg0);
|
||
154 | } |
||
155 | |||
156 | public void performAction() { |
||
157 | 36220 | fdiaz | |
158 | if (getService().getStoreName() == null) { |
||
159 | JOptionPane
|
||
160 | .showMessageDialog( |
||
161 | null,
|
||
162 | 37804 | jpiera | Messages.getText("new_layer_not_store_name"),
|
163 | Messages.getText("new_layer"),
|
||
164 | 36220 | fdiaz | JOptionPane.WARNING_MESSAGE);
|
165 | return;
|
||
166 | 36113 | fdiaz | } |
167 | 36220 | fdiaz | if (getService().getNewStoreParameters() == null) { |
168 | JOptionPane
|
||
169 | .showMessageDialog( |
||
170 | null,
|
||
171 | 37804 | jpiera | Messages.getText("new_layer_parameters_missing"),
|
172 | Messages.getText("new_layer"),
|
||
173 | 36220 | fdiaz | JOptionPane.WARNING_MESSAGE);
|
174 | return;
|
||
175 | 36113 | fdiaz | } |
176 | 36220 | fdiaz | getService().addLayerToView(getAddLayerToView()); |
177 | 36022 | fdiaz | try {
|
178 | getService().createLayer(); |
||
179 | } catch (NewLayerServiceException e) {
|
||
180 | 38367 | jldominguez | LOG.info("Cannot create the new layer", e);
|
181 | 36220 | fdiaz | JOptionPane
|
182 | .showMessageDialog( |
||
183 | null,
|
||
184 | 37804 | jpiera | Messages.getText("cant_create_new_layer") + "\n" + e.getMessageStack(), |
185 | Messages.getText("new_layer"),
|
||
186 | 36220 | fdiaz | JOptionPane.ERROR_MESSAGE);
|
187 | return;
|
||
188 | 36022 | fdiaz | } |
189 | 36220 | fdiaz | |
190 | try {
|
||
191 | getService().loadLayer(); |
||
192 | } catch (NewLayerServiceException e) {
|
||
193 | JOptionPane
|
||
194 | .showMessageDialog( |
||
195 | null,
|
||
196 | "The new layer has been succesfully created but can't load the new layer.\n Try load it yourshelf, please.",
|
||
197 | "Can't create a new layer",
|
||
198 | JOptionPane.WARNING_MESSAGE);
|
||
199 | } |
||
200 | setVisible(false);
|
||
201 | return;
|
||
202 | 36022 | fdiaz | } |
203 | |||
204 | } |
||
205 | 36220 | fdiaz | |
206 | 36113 | fdiaz | private class MyCancelAction extends CancelAction { |
207 | 36220 | fdiaz | |
208 | 36113 | fdiaz | public MyCancelAction(DefaultJWizardComponents wizardComponents) {
|
209 | super(wizardComponents);
|
||
210 | } |
||
211 | |||
212 | public void performAction() { |
||
213 | 36220 | fdiaz | setVisible(false);
|
214 | 36113 | fdiaz | } |
215 | 36220 | fdiaz | |
216 | 36113 | fdiaz | } |
217 | 36022 | fdiaz | } |