Revision 36220 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

View differences:

DefaultNewLayerWizard.java
5 5
import java.util.List;
6 6

  
7 7
import javax.swing.ImageIcon;
8
import javax.swing.JOptionPane;
8 9
import javax.swing.JPanel;
9 10

  
10 11
import jwizardcomponent.CancelAction;
......
18 19
import org.gvsig.newlayer.NewLayerService;
19 20
import org.gvsig.newlayer.NewLayerServiceException;
20 21
import org.gvsig.newlayer.NewLayerWizard;
22
import org.slf4j.Logger;
23
import org.slf4j.LoggerFactory;
21 24

  
22 25
public class DefaultNewLayerWizard extends NewLayerWizard {
23 26

  
......
26 29
	 */
27 30
	private static final long serialVersionUID = -5827106636136663823L;
28 31
	private NewLayerService service;
32
	private AddNewLayerQuestionPanel addNewLayerQuestionPanel;
33
	private static final Logger LOG =
34
        LoggerFactory.getLogger(DefaultNewLayerWizard.class);
29 35

  
30 36
	public DefaultNewLayerWizard(ImageIcon logo, NewLayerService service) {
31 37
		super(logo);
32
		setPreferredSize(new Dimension(600,400));
38
		setPreferredSize(new Dimension(600, 400));
33 39
		this.service = service;
34
		this.getWizardComponents().setFinishAction(new MyFinishAction(this.getWizardComponents()));
35
		this.getWizardComponents().setCancelAction(new MyCancelAction(this.getWizardComponents()));
40
		this.getWizardComponents().setFinishAction(
41
				new MyFinishAction(this.getWizardComponents()));
42
		this.getWizardComponents().setCancelAction(
43
				new MyCancelAction(this.getWizardComponents()));
36 44
		this.createTypeSelector();
37 45
	}
38 46

  
39
	public NewLayerService getService(){
47
	public NewLayerService getService() {
40 48
		return this.service;
41 49
	}
42
	
50

  
43 51
	private void createTypeSelector() {
44
		
52

  
45 53
		TypeSelectorPanel panel = new TypeSelectorPanel(this);
46 54
		this.addOptionPanel(panel);
47
		
55

  
48 56
	}
49
	
57

  
50 58
	private void createFeatureTypePanel() {
51
		
59

  
52 60
		FeatureTypePanel panel = new FeatureTypePanel(this);
53 61
		this.addOptionPanel(panel);
54 62

  
55 63
	}
56 64

  
57 65
	private void createProviderPanels() {
58
	       DefaultJWizardComponents wizardComponents = this.getWizardComponents();              
59
	        for (int i=wizardComponents.getWizardPanelList().size()-1 ; i>=1 ; i--){
60
	            wizardComponents.removeWizardPanel(i);
61
	        }
62
	        List<NewLayerProviderPanel> panels = service.getProvider().getPanels();
63
	        Iterator<NewLayerProviderPanel> it = panels.iterator();
64
	        while (it.hasNext()) {
65
	        	NewLayerProviderPanel panel = it.next();
66
				this.addOptionPanel(new OptionPanelWrapper(panel));
67
			}
68
	        this.createFeatureTypePanel();
66
		DefaultJWizardComponents wizardComponents = this.getWizardComponents();
67
		for (int i = wizardComponents.getWizardPanelList().size() - 1; i >= 1; i--) {
68
			wizardComponents.removeWizardPanel(i);
69
		}
70
		List<NewLayerProviderPanel> panels = service.getProvider().getPanels();
71
		Iterator<NewLayerProviderPanel> it = panels.iterator();
72
		while (it.hasNext()) {
73
			NewLayerProviderPanel panel = it.next();
74
			this.addOptionPanel(new OptionPanelWrapper(panel));
75
		}
76
		this.createFeatureTypePanel();
77
		this.createAddNewLayerQuestionPanel();
69 78
	}
70 79

  
80
	private AddNewLayerQuestionPanel getAddNewLayerQuestionPanel() {
81
		if (this.addNewLayerQuestionPanel == null) {
82
			this.addNewLayerQuestionPanel = new AddNewLayerQuestionPanel(this);
83
		}
84
		return this.addNewLayerQuestionPanel;
85
	}
86

  
87
	private void createAddNewLayerQuestionPanel() {
88
		this.addOptionPanel(getAddNewLayerQuestionPanel());
89
	}
90

  
91
	private boolean getAddLayerToView() {
92
		return getAddNewLayerQuestionPanel().getAddLayerToView();
93
	}
94

  
71 95
	@Override
72 96
	public void setType(String currentType) {
73 97
		this.service.setType(currentType);
74 98
		createProviderPanels();
75 99
	}
76
	
100

  
77 101
	private class OptionPanelWrapper implements OptionPanel {
78
		
102

  
79 103
		private NewLayerProviderPanel panel;
80 104

  
81 105
		public OptionPanelWrapper(NewLayerProviderPanel panel) {
......
87 111
		}
88 112

  
89 113
		public void nextPanel() throws NotContinueWizardException {
90
			
91
			if(!this.panel.isValidPanel()){
114

  
115
			if (!this.panel.isValidPanel()) {
92 116
				throw new NotContinueWizardException("", null, false);
93 117
			}
94
			
118

  
95 119
		}
96 120

  
97 121
		public void lastPanel() {
......
104 128
		public JPanel getJPanel() {
105 129
			return this.panel;
106 130
		}
107
		
131

  
108 132
	}
109
	
133

  
110 134
	private class MyFinishAction extends FinishAction {
111 135

  
112 136
		public MyFinishAction(JWizardComponents arg0) {
......
114 138
		}
115 139

  
116 140
		public void performAction() {
117
			if (getService().getStoreName()==null){
118
				//TODO pedirlo
141

  
142
			if (getService().getStoreName() == null) {
143
				JOptionPane
144
				.showMessageDialog(
145
						null,
146
						"Can't create a new layer.\n The store name is missing.\n Go back and enter it, please.",
147
						"Can't create a new layer",
148
						JOptionPane.WARNING_MESSAGE);
149
				return;
119 150
			}
120
			if (getService().getNewStoreParameters()==null){
121
				//TODO pedirlo
151
			if (getService().getNewStoreParameters() == null) {
152
				JOptionPane
153
				.showMessageDialog(
154
						null,
155
						"Can't create a new layer.\n The store paremeters are missing.\n Go back and enter it, please.",
156
						"Can't create a new layer",
157
						JOptionPane.WARNING_MESSAGE);
158
				return;
122 159
			}
160
			getService().addLayerToView(getAddLayerToView());
123 161
			try {
124 162
				getService().createLayer();
125 163
			} catch (NewLayerServiceException e) {
126
				// TODO Auto-generated catch block
127
				e.printStackTrace();
164
				LOG.error("Can't create the new layer", e);
165
				JOptionPane
166
				.showMessageDialog(
167
						null,
168
						"Can't create the new layer.",
169
						"Can't create the new layer.",
170
						JOptionPane.ERROR_MESSAGE);
171
				return;
128 172
			}
173
			
174
			try {
175
				getService().loadLayer();
176
			} catch (NewLayerServiceException e) {
177
				JOptionPane
178
				.showMessageDialog(
179
						null,
180
						"The new layer has been succesfully created but can't load the new layer.\n Try load it yourshelf, please.",
181
						"Can't create a new layer",
182
						JOptionPane.WARNING_MESSAGE);
183
			}
184
			setVisible(false);
185
			return;
129 186
		}
130 187

  
131 188
	}
132
	
189

  
133 190
	private class MyCancelAction extends CancelAction {
134
		
191

  
135 192
		public MyCancelAction(DefaultJWizardComponents wizardComponents) {
136 193
			super(wizardComponents);
137 194
		}
138 195

  
139 196
		public void performAction() {
140
			
197
			setVisible(false);
141 198
		}
142
		
199

  
143 200
	}
144 201
}

Also available in: Unified diff