svn-gvsig-desktop / 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 @ 40560
History | View | Annotate | Download (6.73 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.newlayer.impl; |
25 |
|
26 |
import java.awt.Dimension; |
27 |
import java.util.Iterator; |
28 |
import java.util.List; |
29 |
|
30 |
import javax.swing.ImageIcon; |
31 |
import javax.swing.JOptionPane; |
32 |
import javax.swing.JPanel; |
33 |
|
34 |
import jwizardcomponent.CancelAction; |
35 |
import jwizardcomponent.DefaultJWizardComponents; |
36 |
import jwizardcomponent.FinishAction; |
37 |
import jwizardcomponent.JWizardComponents; |
38 |
|
39 |
import org.slf4j.Logger; |
40 |
import org.slf4j.LoggerFactory; |
41 |
|
42 |
import org.gvsig.fmap.dal.DALLocator; |
43 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
44 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
45 |
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException; |
46 |
import org.gvsig.gui.beans.wizard.panel.OptionPanel; |
47 |
import org.gvsig.i18n.Messages; |
48 |
import org.gvsig.newlayer.NewLayerException; |
49 |
import org.gvsig.newlayer.NewLayerProviderFactory; |
50 |
import org.gvsig.newlayer.NewLayerProviderPanel; |
51 |
import org.gvsig.newlayer.NewLayerService; |
52 |
import org.gvsig.newlayer.NewLayerServiceException; |
53 |
import org.gvsig.newlayer.NewLayerWizard; |
54 |
|
55 |
public class DefaultNewLayerWizard extends NewLayerWizard { |
56 |
|
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); |
65 |
|
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
|
77 |
this.setFinishButtonEnabled(false); |
78 |
this.setBackButtonEnabled(false); |
79 |
this.setNextButtonEnabled(false); |
80 |
} |
81 |
|
82 |
public NewLayerService getService() {
|
83 |
return this.service; |
84 |
} |
85 |
|
86 |
private void createTypeSelector() { |
87 |
|
88 |
TypeSelectorPanel panel = new TypeSelectorPanel(this); |
89 |
this.addOptionPanel(panel);
|
90 |
|
91 |
} |
92 |
|
93 |
private void createFeatureTypePanel() { |
94 |
|
95 |
FeatureTypePanel panel = new FeatureTypePanel(service);
|
96 |
this.addOptionPanel(panel);
|
97 |
} |
98 |
|
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 |
} |
113 |
|
114 |
private AddNewLayerQuestionPanel getAddNewLayerQuestionPanel() {
|
115 |
if (this.addNewLayerQuestionPanel == null) { |
116 |
this.addNewLayerQuestionPanel = new AddNewLayerQuestionPanel(this); |
117 |
} |
118 |
return this.addNewLayerQuestionPanel; |
119 |
} |
120 |
|
121 |
private void createAddNewLayerQuestionPanel() { |
122 |
this.addOptionPanel(getAddNewLayerQuestionPanel());
|
123 |
} |
124 |
|
125 |
private boolean getAddLayerToView() { |
126 |
return getAddNewLayerQuestionPanel().getAddLayerToView();
|
127 |
} |
128 |
|
129 |
@Override
|
130 |
public void setType(NewLayerProviderFactory currentType) { |
131 |
this.service.setProviderFactory(currentType);
|
132 |
createProviderPanels(); |
133 |
} |
134 |
|
135 |
private class OptionPanelWrapper implements OptionPanel { |
136 |
|
137 |
private NewLayerProviderPanel panel;
|
138 |
|
139 |
public OptionPanelWrapper(NewLayerProviderPanel panel) {
|
140 |
this.panel = panel;
|
141 |
} |
142 |
|
143 |
public String getPanelTitle() { |
144 |
return this.panel.getTitle(); |
145 |
} |
146 |
|
147 |
public void nextPanel() throws NotContinueWizardException { |
148 |
|
149 |
try {
|
150 |
if (!this.panel.isValidPanel()) { |
151 |
throw new NotContinueWizardException("Error validating the form", panel, false); |
152 |
} |
153 |
} catch (NewLayerException e) {
|
154 |
LOG.info("Error validating the form", e);
|
155 |
throw new NotContinueWizardException("Error validating the form", |
156 |
e, panel); |
157 |
} |
158 |
} |
159 |
|
160 |
public void lastPanel() { |
161 |
} |
162 |
|
163 |
public void updatePanel() { |
164 |
this.panel.updatePanel();
|
165 |
} |
166 |
|
167 |
public JPanel getJPanel() { |
168 |
return this.panel; |
169 |
} |
170 |
|
171 |
} |
172 |
|
173 |
private class MyFinishAction extends FinishAction { |
174 |
|
175 |
public MyFinishAction(JWizardComponents arg0) {
|
176 |
super(arg0);
|
177 |
} |
178 |
|
179 |
public void performAction() { |
180 |
|
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 |
} |
226 |
|
227 |
} |
228 |
|
229 |
private class MyCancelAction extends CancelAction { |
230 |
|
231 |
public MyCancelAction(DefaultJWizardComponents wizardComponents) {
|
232 |
super(wizardComponents);
|
233 |
} |
234 |
|
235 |
public void performAction() { |
236 |
setVisible(false);
|
237 |
} |
238 |
|
239 |
} |
240 |
} |