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 |
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 |
|
54 |
public NewLayerService getService() {
|
55 |
return this.service; |
56 |
} |
57 |
|
58 |
private void createTypeSelector() { |
59 |
|
60 |
TypeSelectorPanel panel = new TypeSelectorPanel(this); |
61 |
this.addOptionPanel(panel);
|
62 |
|
63 |
} |
64 |
|
65 |
private void createFeatureTypePanel() { |
66 |
|
67 |
FeatureTypePanel panel = new FeatureTypePanel(service);
|
68 |
this.addOptionPanel(panel);
|
69 |
} |
70 |
|
71 |
private void createProviderPanels() { |
72 |
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 |
} |
85 |
|
86 |
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 |
@Override
|
102 |
public void setType(NewLayerProviderFactory currentType) { |
103 |
this.service.setProviderFactory(currentType);
|
104 |
createProviderPanels(); |
105 |
} |
106 |
|
107 |
private class OptionPanelWrapper implements OptionPanel { |
108 |
|
109 |
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 |
|
121 |
try {
|
122 |
if (!this.panel.isValidPanel()) { |
123 |
throw new NotContinueWizardException("Error validating the form", panel, false); |
124 |
} |
125 |
} catch (NewLayerException e) {
|
126 |
LOG.info("Error validating the form", e);
|
127 |
throw new NotContinueWizardException("Error validating the form", |
128 |
e, panel); |
129 |
} |
130 |
} |
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 |
|
143 |
} |
144 |
|
145 |
private class MyFinishAction extends FinishAction { |
146 |
|
147 |
public MyFinishAction(JWizardComponents arg0) {
|
148 |
super(arg0);
|
149 |
} |
150 |
|
151 |
public void performAction() { |
152 |
|
153 |
if (getService().getStoreName() == null) { |
154 |
JOptionPane
|
155 |
.showMessageDialog( |
156 |
null,
|
157 |
Messages.getText("new_layer_not_store_name"),
|
158 |
Messages.getText("new_layer"),
|
159 |
JOptionPane.WARNING_MESSAGE);
|
160 |
return;
|
161 |
} |
162 |
if (getService().getNewStoreParameters() == null) { |
163 |
JOptionPane
|
164 |
.showMessageDialog( |
165 |
null,
|
166 |
Messages.getText("new_layer_parameters_missing"),
|
167 |
Messages.getText("new_layer"),
|
168 |
JOptionPane.WARNING_MESSAGE);
|
169 |
return;
|
170 |
} |
171 |
getService().addLayerToView(getAddLayerToView()); |
172 |
try {
|
173 |
getService().createLayer(); |
174 |
} catch (NewLayerServiceException e) {
|
175 |
LOG.info("Cannot create the new layer", e);
|
176 |
JOptionPane
|
177 |
.showMessageDialog( |
178 |
null,
|
179 |
Messages.getText("cant_create_new_layer") + "\n" + e.getMessageStack(), |
180 |
Messages.getText("new_layer"),
|
181 |
JOptionPane.ERROR_MESSAGE);
|
182 |
return;
|
183 |
} |
184 |
|
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 |
} |
198 |
|
199 |
} |
200 |
|
201 |
private class MyCancelAction extends CancelAction { |
202 |
|
203 |
public MyCancelAction(DefaultJWizardComponents wizardComponents) {
|
204 |
super(wizardComponents);
|
205 |
} |
206 |
|
207 |
public void performAction() { |
208 |
setVisible(false);
|
209 |
} |
210 |
|
211 |
} |
212 |
} |