root / tags / v2_0_0_Build_2050 / libraries / org.gvsig.newlayer / org.gvsig.newlayer.lib / org.gvsig.newlayer.lib.impl / src / main / java / org / gvsig / newlayer / impl / DefaultNewLayerWizard.java @ 38695
History | View | Annotate | Download (5.79 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.JOptionPane; |
9 |
import javax.swing.JPanel; |
10 |
|
11 |
import jwizardcomponent.CancelAction; |
12 |
import jwizardcomponent.DefaultJWizardComponents; |
13 |
import jwizardcomponent.FinishAction; |
14 |
import jwizardcomponent.JWizardComponents; |
15 |
|
16 |
import org.slf4j.Logger; |
17 |
import org.slf4j.LoggerFactory; |
18 |
|
19 |
import org.gvsig.fmap.dal.DALLocator; |
20 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
21 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
22 |
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException; |
23 |
import org.gvsig.gui.beans.wizard.panel.OptionPanel; |
24 |
import org.gvsig.i18n.Messages; |
25 |
import org.gvsig.newlayer.NewLayerException; |
26 |
import org.gvsig.newlayer.NewLayerProviderFactory; |
27 |
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 |
private AddNewLayerQuestionPanel addNewLayerQuestionPanel;
|
40 |
private static final Logger LOG = |
41 |
LoggerFactory.getLogger(DefaultNewLayerWizard.class); |
42 |
|
43 |
public DefaultNewLayerWizard(ImageIcon logo, NewLayerService service) { |
44 |
super(logo);
|
45 |
setPreferredSize(new Dimension(800, 400)); |
46 |
this.service = service;
|
47 |
this.getWizardComponents().setFinishAction(
|
48 |
new MyFinishAction(this.getWizardComponents())); |
49 |
this.getWizardComponents().setCancelAction(
|
50 |
new MyCancelAction(this.getWizardComponents())); |
51 |
this.createTypeSelector();
|
52 |
|
53 |
// ================ disable at the start
|
54 |
this.setFinishButtonEnabled(false); |
55 |
this.setBackButtonEnabled(false); |
56 |
this.setNextButtonEnabled(false); |
57 |
} |
58 |
|
59 |
public NewLayerService getService() {
|
60 |
return this.service; |
61 |
} |
62 |
|
63 |
private void createTypeSelector() { |
64 |
|
65 |
TypeSelectorPanel panel = new TypeSelectorPanel(this); |
66 |
this.addOptionPanel(panel);
|
67 |
|
68 |
} |
69 |
|
70 |
private void createFeatureTypePanel() { |
71 |
|
72 |
FeatureTypePanel panel = new FeatureTypePanel(service);
|
73 |
this.addOptionPanel(panel);
|
74 |
} |
75 |
|
76 |
private void createProviderPanels() { |
77 |
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 |
} |
90 |
|
91 |
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 |
@Override
|
107 |
public void setType(NewLayerProviderFactory currentType) { |
108 |
this.service.setProviderFactory(currentType);
|
109 |
createProviderPanels(); |
110 |
} |
111 |
|
112 |
private class OptionPanelWrapper implements OptionPanel { |
113 |
|
114 |
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 |
|
126 |
try {
|
127 |
if (!this.panel.isValidPanel()) { |
128 |
throw new NotContinueWizardException("Error validating the form", panel, false); |
129 |
} |
130 |
} catch (NewLayerException e) {
|
131 |
LOG.info("Error validating the form", e);
|
132 |
throw new NotContinueWizardException("Error validating the form", |
133 |
e, panel); |
134 |
} |
135 |
} |
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 |
|
148 |
} |
149 |
|
150 |
private class MyFinishAction extends FinishAction { |
151 |
|
152 |
public MyFinishAction(JWizardComponents arg0) {
|
153 |
super(arg0);
|
154 |
} |
155 |
|
156 |
public void performAction() { |
157 |
|
158 |
if (getService().getStoreName() == null) { |
159 |
JOptionPane
|
160 |
.showMessageDialog( |
161 |
null,
|
162 |
Messages.getText("new_layer_not_store_name"),
|
163 |
Messages.getText("new_layer"),
|
164 |
JOptionPane.WARNING_MESSAGE);
|
165 |
return;
|
166 |
} |
167 |
if (getService().getNewStoreParameters() == null) { |
168 |
JOptionPane
|
169 |
.showMessageDialog( |
170 |
null,
|
171 |
Messages.getText("new_layer_parameters_missing"),
|
172 |
Messages.getText("new_layer"),
|
173 |
JOptionPane.WARNING_MESSAGE);
|
174 |
return;
|
175 |
} |
176 |
getService().addLayerToView(getAddLayerToView()); |
177 |
try {
|
178 |
getService().createLayer(); |
179 |
} catch (NewLayerServiceException e) {
|
180 |
LOG.info("Cannot create the new layer", e);
|
181 |
JOptionPane
|
182 |
.showMessageDialog( |
183 |
null,
|
184 |
Messages.getText("cant_create_new_layer") + "\n" + e.getMessageStack(), |
185 |
Messages.getText("new_layer"),
|
186 |
JOptionPane.ERROR_MESSAGE);
|
187 |
return;
|
188 |
} |
189 |
|
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 |
} |
203 |
|
204 |
} |
205 |
|
206 |
private class MyCancelAction extends CancelAction { |
207 |
|
208 |
public MyCancelAction(DefaultJWizardComponents wizardComponents) {
|
209 |
super(wizardComponents);
|
210 |
} |
211 |
|
212 |
public void performAction() { |
213 |
setVisible(false);
|
214 |
} |
215 |
|
216 |
} |
217 |
} |