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