Revision 45564 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.impl/src/main/java/org/gvsig/newlayer/impl/DefaultNewLayerWizard.java
DefaultNewLayerWizard.java | ||
---|---|---|
28 | 28 |
import java.util.List; |
29 | 29 |
|
30 | 30 |
import javax.swing.ImageIcon; |
31 |
import javax.swing.JButton; |
|
31 | 32 |
import javax.swing.JOptionPane; |
32 | 33 |
import javax.swing.JPanel; |
33 | 34 |
|
... | ... | |
39 | 40 |
import org.slf4j.Logger; |
40 | 41 |
import org.slf4j.LoggerFactory; |
41 | 42 |
|
42 |
import org.gvsig.fmap.dal.DALLocator; |
|
43 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
|
44 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
|
45 | 43 |
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException; |
46 | 44 |
import org.gvsig.gui.beans.wizard.panel.OptionPanel; |
47 | 45 |
import org.gvsig.i18n.Messages; |
... | ... | |
51 | 49 |
import org.gvsig.newlayer.NewLayerService; |
52 | 50 |
import org.gvsig.newlayer.NewLayerServiceException; |
53 | 51 |
import org.gvsig.newlayer.NewLayerWizard; |
52 |
import org.gvsig.newlayer.impl.panels.FeatureTypePanel; |
|
54 | 53 |
|
55 | 54 |
public class DefaultNewLayerWizard extends NewLayerWizard { |
56 | 55 |
|
57 |
/**
|
|
58 |
*
|
|
59 |
*/
|
|
60 |
private static final long serialVersionUID = -5827106636136663823L;
|
|
61 |
private NewLayerService service;
|
|
62 |
private AddNewLayerQuestionPanel addNewLayerQuestionPanel;
|
|
63 |
private static final Logger LOG =
|
|
64 |
LoggerFactory.getLogger(DefaultNewLayerWizard.class); |
|
56 |
/**
|
|
57 |
*
|
|
58 |
*/
|
|
59 |
private static final long serialVersionUID = -5827106636136663823L;
|
|
60 |
private final NewLayerService service;
|
|
61 |
private AddNewLayerQuestionPanel addNewLayerQuestionPanel;
|
|
62 |
private static final Logger LOG
|
|
63 |
= LoggerFactory.getLogger(DefaultNewLayerWizard.class);
|
|
65 | 64 |
|
66 |
public DefaultNewLayerWizard(ImageIcon logo, NewLayerService service) {
|
|
67 |
super(logo);
|
|
68 |
setPreferredSize(new Dimension(800, 400));
|
|
69 |
this.service = service;
|
|
70 |
this.getWizardComponents().setFinishAction(
|
|
71 |
new MyFinishAction(this.getWizardComponents()));
|
|
72 |
this.getWizardComponents().setCancelAction(
|
|
73 |
new MyCancelAction(this.getWizardComponents()));
|
|
74 |
this.createTypeSelector();
|
|
75 |
|
|
76 |
// ================ disable at the start
|
|
65 |
public DefaultNewLayerWizard(ImageIcon logo, NewLayerService service) {
|
|
66 |
super(logo);
|
|
67 |
setPreferredSize(new Dimension(800, 400));
|
|
68 |
this.service = service;
|
|
69 |
this.getWizardComponents().setFinishAction(
|
|
70 |
new MyFinishAction(this.getWizardComponents()));
|
|
71 |
this.getWizardComponents().setCancelAction(
|
|
72 |
new MyCancelAction(this.getWizardComponents()));
|
|
73 |
this.createTypeSelector();
|
|
74 |
|
|
75 |
// ================ disable at the start
|
|
77 | 76 |
this.setFinishButtonEnabled(false); |
78 | 77 |
this.setBackButtonEnabled(false); |
79 | 78 |
this.setNextButtonEnabled(false); |
80 |
} |
|
79 |
this.setPreferredSize(new Dimension(850, 550)); |
|
80 |
} |
|
81 | 81 |
|
82 |
public NewLayerService getService() { |
|
83 |
return this.service; |
|
84 |
} |
|
82 |
@Override |
|
83 |
public NewLayerService getService() { |
|
84 |
return this.service; |
|
85 |
} |
|
85 | 86 |
|
86 |
private void createTypeSelector() {
|
|
87 |
private void createTypeSelector() {
|
|
87 | 88 |
|
88 |
TypeSelectorPanel panel = new TypeSelectorPanel(this);
|
|
89 |
this.addOptionPanel(panel);
|
|
89 |
TypeSelectorPanel panel = new TypeSelectorPanel(this);
|
|
90 |
this.addOptionPanel(panel);
|
|
90 | 91 |
|
91 |
}
|
|
92 |
}
|
|
92 | 93 |
|
93 |
private void createFeatureTypePanel() {
|
|
94 |
|
|
95 |
FeatureTypePanel panel = new FeatureTypePanel(service);
|
|
96 |
this.addOptionPanel(panel);
|
|
97 |
}
|
|
94 |
@Override
|
|
95 |
public NewLayerProviderPanel createFeatureTypePanel() { |
|
96 |
FeatureTypePanel panel = new FeatureTypePanel(this, service.getProvider());
|
|
97 |
return panel;
|
|
98 |
}
|
|
98 | 99 |
|
99 |
private void createProviderPanels() { |
|
100 |
DefaultJWizardComponents wizardComponents = this.getWizardComponents(); |
|
101 |
for (int i = wizardComponents.getWizardPanelList().size() - 1; i >= 1; i--) { |
|
102 |
wizardComponents.removeWizardPanel(i); |
|
103 |
} |
|
104 |
List<NewLayerProviderPanel> panels = service.getProvider().getPanels(); |
|
105 |
Iterator<NewLayerProviderPanel> it = panels.iterator(); |
|
106 |
while (it.hasNext()) { |
|
107 |
NewLayerProviderPanel panel = it.next(); |
|
108 |
this.addOptionPanel(new OptionPanelWrapper(panel)); |
|
109 |
} |
|
110 |
this.createFeatureTypePanel(); |
|
111 |
this.createAddNewLayerQuestionPanel(); |
|
112 |
} |
|
100 |
private void createProviderPanels() { |
|
101 |
DefaultJWizardComponents wizardComponents = this.getWizardComponents(); |
|
102 |
for (int i = wizardComponents.getWizardPanelList().size() - 1; i >= 1; i--) { |
|
103 |
wizardComponents.removeWizardPanel(i); |
|
104 |
} |
|
105 |
List<NewLayerProviderPanel> panels = service.getProvider().createPanels(this); |
|
106 |
Iterator<NewLayerProviderPanel> it = panels.iterator(); |
|
107 |
while (it.hasNext()) { |
|
108 |
NewLayerProviderPanel panel = it.next(); |
|
109 |
this.addOptionPanel(new OptionPanelWrapper(panel)); |
|
110 |
} |
|
111 |
this.createAddNewLayerQuestionPanel(); |
|
112 |
} |
|
113 | 113 |
|
114 |
private AddNewLayerQuestionPanel getAddNewLayerQuestionPanel() {
|
|
115 |
if (this.addNewLayerQuestionPanel == null) {
|
|
116 |
this.addNewLayerQuestionPanel = new AddNewLayerQuestionPanel(this);
|
|
117 |
}
|
|
118 |
return this.addNewLayerQuestionPanel;
|
|
119 |
}
|
|
114 |
private AddNewLayerQuestionPanel getAddNewLayerQuestionPanel() {
|
|
115 |
if (this.addNewLayerQuestionPanel == null) {
|
|
116 |
this.addNewLayerQuestionPanel = new AddNewLayerQuestionPanel(this);
|
|
117 |
}
|
|
118 |
return this.addNewLayerQuestionPanel;
|
|
119 |
}
|
|
120 | 120 |
|
121 |
private void createAddNewLayerQuestionPanel() {
|
|
122 |
this.addOptionPanel(getAddNewLayerQuestionPanel());
|
|
123 |
}
|
|
121 |
private void createAddNewLayerQuestionPanel() {
|
|
122 |
this.addOptionPanel(getAddNewLayerQuestionPanel());
|
|
123 |
}
|
|
124 | 124 |
|
125 |
private boolean getAddLayerToView() {
|
|
126 |
return getAddNewLayerQuestionPanel().getAddLayerToView();
|
|
127 |
}
|
|
125 |
private boolean getAddLayerToView() {
|
|
126 |
return getAddNewLayerQuestionPanel().getAddLayerToView();
|
|
127 |
}
|
|
128 | 128 |
|
129 |
@Override
|
|
129 |
@Override
|
|
130 | 130 |
public void setType(NewLayerProviderFactory currentType) { |
131 | 131 |
this.service.setProviderFactory(currentType); |
132 |
createProviderPanels();
|
|
133 |
}
|
|
132 |
createProviderPanels();
|
|
133 |
}
|
|
134 | 134 |
|
135 |
private class OptionPanelWrapper implements OptionPanel {
|
|
135 |
private class OptionPanelWrapper implements OptionPanel {
|
|
136 | 136 |
|
137 |
private NewLayerProviderPanel panel;
|
|
137 |
private final NewLayerProviderPanel panel;
|
|
138 | 138 |
|
139 |
public OptionPanelWrapper(NewLayerProviderPanel panel) {
|
|
140 |
this.panel = panel;
|
|
141 |
}
|
|
139 |
public OptionPanelWrapper(NewLayerProviderPanel panel) {
|
|
140 |
this.panel = panel;
|
|
141 |
}
|
|
142 | 142 |
|
143 |
public String getPanelTitle() { |
|
144 |
return this.panel.getTitle(); |
|
145 |
} |
|
143 |
@Override |
|
144 |
public String getPanelTitle() { |
|
145 |
return this.panel.getTitlePanel(); |
|
146 |
} |
|
146 | 147 |
|
147 |
public void nextPanel() throws NotContinueWizardException { |
|
148 |
@Override |
|
149 |
public void nextPanel() throws NotContinueWizardException { |
|
148 | 150 |
|
149 |
try {
|
|
150 |
if (!this.panel.isValidPanel()) {
|
|
151 |
throw new NotContinueWizardException("Error validating the form", panel, false);
|
|
152 |
}
|
|
153 |
} catch (NewLayerException e) {
|
|
151 |
try {
|
|
152 |
if (!this.panel.validatePanel()) {
|
|
153 |
throw new NotContinueWizardException("Error validating the form", panel.asJComponent(), false);
|
|
154 |
}
|
|
155 |
} catch (NewLayerException e) {
|
|
154 | 156 |
LOG.info("Error validating the form", e); |
155 |
throw new NotContinueWizardException("Error validating the form", |
|
156 |
e, panel); |
|
157 |
throw new NotContinueWizardException("Error validating the form", e, panel.asJComponent()); |
|
157 | 158 |
} |
158 |
}
|
|
159 |
}
|
|
159 | 160 |
|
160 |
public void lastPanel() { |
|
161 |
} |
|
161 |
@Override |
|
162 |
public void lastPanel() { |
|
163 |
} |
|
162 | 164 |
|
163 |
public void updatePanel() { |
|
164 |
this.panel.updatePanel(); |
|
165 |
} |
|
165 |
@Override |
|
166 |
public void updatePanel() { |
|
167 |
this.panel.enterPanel(); |
|
168 |
} |
|
166 | 169 |
|
167 |
public JPanel getJPanel() { |
|
168 |
return this.panel; |
|
169 |
} |
|
170 |
@Override |
|
171 |
public JPanel getJPanel() { |
|
172 |
return (JPanel) this.panel.asJComponent(); |
|
173 |
} |
|
170 | 174 |
|
171 |
}
|
|
175 |
}
|
|
172 | 176 |
|
173 |
private class MyFinishAction extends FinishAction {
|
|
177 |
private class MyFinishAction extends FinishAction {
|
|
174 | 178 |
|
175 |
public MyFinishAction(JWizardComponents arg0) {
|
|
176 |
super(arg0);
|
|
177 |
}
|
|
179 |
public MyFinishAction(JWizardComponents arg0) {
|
|
180 |
super(arg0);
|
|
181 |
}
|
|
178 | 182 |
|
179 |
public void performAction() { |
|
183 |
@Override |
|
184 |
public void performAction() { |
|
185 |
if (getService().getStoreName() == null) { |
|
186 |
JOptionPane.showMessageDialog( |
|
187 |
null, |
|
188 |
Messages.getText("new_layer_not_store_name"), |
|
189 |
Messages.getText("new_layer"), |
|
190 |
JOptionPane.WARNING_MESSAGE |
|
191 |
); |
|
192 |
return; |
|
193 |
} |
|
194 |
|
|
195 |
if (getService().getNewStoreParametersQuietly()== null) { |
|
196 |
JOptionPane.showMessageDialog( |
|
197 |
null, |
|
198 |
Messages.getText("new_layer_parameters_missing"), |
|
199 |
Messages.getText("new_layer"), |
|
200 |
JOptionPane.WARNING_MESSAGE |
|
201 |
); |
|
202 |
return; |
|
203 |
} |
|
204 |
getService().addLayerToView(getAddLayerToView()); |
|
205 |
try { |
|
206 |
getService().createTable(); |
|
207 |
} catch (NewLayerServiceException e) { |
|
208 |
LOG.info("Cannot create the new layer", e); |
|
209 |
JOptionPane.showMessageDialog( |
|
210 |
null, |
|
211 |
Messages.getText("cant_create_new_layer") + "\n" + e.getMessageStack(), |
|
212 |
Messages.getText("new_layer"), |
|
213 |
JOptionPane.ERROR_MESSAGE |
|
214 |
); |
|
215 |
return; |
|
216 |
} |
|
180 | 217 |
|
181 |
if (getService().getStoreName() == null) { |
|
182 |
JOptionPane |
|
183 |
.showMessageDialog( |
|
184 |
null, |
|
185 |
Messages.getText("new_layer_not_store_name"), |
|
186 |
Messages.getText("new_layer"), |
|
187 |
JOptionPane.WARNING_MESSAGE); |
|
188 |
return; |
|
189 |
} |
|
190 |
if (getService().getNewStoreParameters() == null) { |
|
191 |
JOptionPane |
|
192 |
.showMessageDialog( |
|
193 |
null, |
|
194 |
Messages.getText("new_layer_parameters_missing"), |
|
195 |
Messages.getText("new_layer"), |
|
196 |
JOptionPane.WARNING_MESSAGE); |
|
197 |
return; |
|
198 |
} |
|
199 |
getService().addLayerToView(getAddLayerToView()); |
|
200 |
try { |
|
201 |
getService().createLayer(); |
|
202 |
} catch (NewLayerServiceException e) { |
|
203 |
LOG.info("Cannot create the new layer", e); |
|
204 |
JOptionPane |
|
205 |
.showMessageDialog( |
|
206 |
null, |
|
207 |
Messages.getText("cant_create_new_layer") + "\n" + e.getMessageStack(), |
|
208 |
Messages.getText("new_layer"), |
|
209 |
JOptionPane.ERROR_MESSAGE); |
|
210 |
return; |
|
211 |
} |
|
212 |
|
|
213 |
try { |
|
214 |
getService().loadLayer(); |
|
215 |
} catch (NewLayerServiceException e) { |
|
216 |
JOptionPane |
|
217 |
.showMessageDialog( |
|
218 |
null, |
|
219 |
"The new layer has been succesfully created but can't load the new layer.\n Try load it yourshelf, please.", |
|
220 |
"Can't create a new layer", |
|
221 |
JOptionPane.WARNING_MESSAGE); |
|
222 |
} |
|
223 |
setVisible(false); |
|
224 |
return; |
|
225 |
} |
|
218 |
try { |
|
219 |
getService().loadTable(); |
|
220 |
} catch (NewLayerServiceException e) { |
|
221 |
JOptionPane.showMessageDialog( |
|
222 |
null, |
|
223 |
"The new layer has been succesfully created but can't load the new layer.\n Try load it yourshelf, please.", |
|
224 |
"Can't create a new layer", |
|
225 |
JOptionPane.WARNING_MESSAGE |
|
226 |
); |
|
227 |
} |
|
228 |
setVisible(false); |
|
229 |
} |
|
226 | 230 |
|
227 |
}
|
|
231 |
}
|
|
228 | 232 |
|
229 |
private class MyCancelAction extends CancelAction {
|
|
233 |
private class MyCancelAction extends CancelAction {
|
|
230 | 234 |
|
231 |
public MyCancelAction(DefaultJWizardComponents wizardComponents) {
|
|
232 |
super(wizardComponents);
|
|
233 |
}
|
|
235 |
public MyCancelAction(DefaultJWizardComponents wizardComponents) {
|
|
236 |
super(wizardComponents);
|
|
237 |
}
|
|
234 | 238 |
|
235 |
public void performAction() { |
|
236 |
setVisible(false); |
|
237 |
} |
|
239 |
@Override |
|
240 |
public void performAction() { |
|
241 |
setVisible(false); |
|
242 |
} |
|
238 | 243 |
|
239 |
} |
|
244 |
} |
|
245 |
|
|
246 |
private JButton getButton(int button) { |
|
247 |
switch (button) { |
|
248 |
case BUTTON_BACK: |
|
249 |
return this.getWizardComponents().getBackButton(); |
|
250 |
case BUTTON_NEXT: |
|
251 |
return this.getWizardComponents().getNextButton(); |
|
252 |
case BUTTON_FINISH: |
|
253 |
return this.getWizardComponents().getFinishButton(); |
|
254 |
case BUTTON_CANCEL: |
|
255 |
return this.getWizardComponents().getCancelButton(); |
|
256 |
} |
|
257 |
throw new IllegalArgumentException("Illegal button value (" + button + ")."); |
|
258 |
} |
|
259 |
|
|
260 |
@Override |
|
261 |
public void setButtonEnabled(int button, boolean enabled) { |
|
262 |
this.getButton(button).setEnabled(enabled); |
|
263 |
} |
|
264 |
|
|
265 |
@Override |
|
266 |
public void setButtonText(int button, String text) { |
|
267 |
this.getButton(button).setText(text); |
|
268 |
} |
|
269 |
|
|
270 |
@Override |
|
271 |
public boolean isButtonEnabled(int button) { |
|
272 |
return this.getButton(button).isEnabled(); |
|
273 |
} |
|
274 |
|
|
275 |
@Override |
|
276 |
public String getButtonText(int button) { |
|
277 |
return this.getButton(button).getText(); |
|
278 |
} |
|
279 |
|
|
240 | 280 |
} |
Also available in: Unified diff