Revision 41434 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/gui/WizardPanel.java
WizardPanel.java | ||
---|---|---|
34 | 34 |
import org.gvsig.app.gui.wizards.WizardListener; |
35 | 35 |
import org.gvsig.app.gui.wizards.WizardListenerSupport; |
36 | 36 |
import org.gvsig.app.prepareAction.PrepareContextView; |
37 |
import org.gvsig.app.prepareAction.PrepareContextView_v1; |
|
37 | 38 |
import org.gvsig.fmap.dal.DataStoreParameters; |
38 | 39 |
import org.gvsig.fmap.mapcontext.MapContext; |
39 | 40 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
... | ... | |
50 | 51 |
private String tabName = "TabName"; |
51 | 52 |
private MapControl mapCtrl = null; |
52 | 53 |
private WizardListenerSupport listenerSupport = new WizardListenerSupport(); |
54 |
private MapContext mapContext; |
|
55 |
private boolean b_isMapControlAvailable = false; |
|
53 | 56 |
|
54 | 57 |
public void addWizardListener(WizardListener listener) { |
55 | 58 |
listenerSupport.addWizardListener(listener); |
... | ... | |
97 | 100 |
abstract public DataStoreParameters[] getParameters(); |
98 | 101 |
|
99 | 102 |
/** |
100 |
* You can use it to extract information from |
|
101 |
* the mapControl that will receive the new layer. |
|
102 |
* For example, projection to use, or visible extent. |
|
103 |
* You can use it to interact with the MapControl component that will |
|
104 |
* receive the new layer, in order to get user feedback |
|
105 |
* (for instance a bounding box). Check the |
|
106 |
* {@link #isMapControlAvailable()} method before accessing the MapControl |
|
107 |
* because it may not be available (for instance when adding layers |
|
108 |
* to a MapContext not associated with a View). |
|
103 | 109 |
* |
110 |
* For the moment, this method will return a non-null MapControl for |
|
111 |
* compatibility reasons, but you should still check |
|
112 |
* {@link #isMapControlAvailable()} to be sure it is a valid one, |
|
113 |
* as it could only be a fake MapControl. |
|
114 |
* |
|
115 |
* It is recommended to use {@link #getMapContext()} method |
|
116 |
* when no interaction is needed with the map user interface |
|
117 |
* (for instance to get the active projection, visible extent, etc) |
|
118 |
* |
|
104 | 119 |
* @return Returns the mapCtrl. |
105 | 120 |
*/ |
106 | 121 |
public MapControl getMapCtrl() { |
107 |
return mapCtrl; |
|
122 |
if (mapCtrl!=null) { |
|
123 |
return mapCtrl; |
|
124 |
} |
|
125 |
else if (mapContext!=null) { |
|
126 |
// if MapContext has been set, create a fake MapControl |
|
127 |
// for compatibility purposes |
|
128 |
MapControl mc = new MapControl(); |
|
129 |
mc.setMapContext(mapContext); |
|
130 |
mapCtrl=mc; |
|
131 |
} |
|
132 |
return mapCtrl; |
|
108 | 133 |
} |
109 | 134 |
|
110 | 135 |
/** |
136 |
* Sets the MapControl that will receive the new layer |
|
111 | 137 |
* @param mapCtrl |
112 | 138 |
* The mapCtrl to set. |
113 | 139 |
*/ |
114 | 140 |
public void setMapCtrl(MapControl mapCtrl) { |
115 | 141 |
this.mapCtrl = mapCtrl; |
142 |
b_isMapControlAvailable = (mapCtrl!=null); |
|
116 | 143 |
} |
144 |
|
|
145 |
/** |
|
146 |
* You can use it to extract information from |
|
147 |
* the MapContext that will receive the new layer. |
|
148 |
* For example, projection to use, or visible extent. |
|
149 |
* |
|
150 |
* @return Returns the MapContext. |
|
151 |
*/ |
|
152 |
public MapContext getMapContext() { |
|
153 |
if (this.mapContext!=null || this.mapCtrl==null) { |
|
154 |
return this.mapContext; |
|
155 |
} |
|
156 |
else { |
|
157 |
return this.mapCtrl.getMapContext(); |
|
158 |
} |
|
159 |
|
|
160 |
} |
|
117 | 161 |
|
118 |
protected void doAddLayer(final MapControl mapControl, |
|
119 |
final String layerName, final DataStoreParameters parameters) { |
|
120 |
final ApplicationManager application = ApplicationLocator.getManager(); |
|
162 |
/** |
|
163 |
* Sets the MapContext that will receive the new layer |
|
164 |
* @param mapContext |
|
165 |
* The mapContext to set. |
|
166 |
*/ |
|
167 |
public void setMapContext(MapContext mapContext) { |
|
168 |
this.mapContext = mapContext; |
|
169 |
} |
|
170 |
|
|
171 |
/** |
|
172 |
* Checks whether the MapControl is available. |
|
173 |
* The MapControl may not be available in some circumstances, for instance |
|
174 |
* when adding layers to a MapContext not associated with a View. |
|
175 |
* |
|
176 |
* A MapContext should always be available on the {@link #getMapContext()} |
|
177 |
* method. |
|
178 |
* |
|
179 |
* @return true if the MapControl is available, false otherwise |
|
180 |
*/ |
|
181 |
public boolean isMapControlAvailable() { |
|
182 |
return b_isMapControlAvailable ; |
|
183 |
} |
|
184 |
|
|
185 |
protected void doAddLayer( |
|
186 |
final String layerName, final DataStoreParameters parameters) { |
|
187 |
final boolean b_isMapControlAvail = this.isMapControlAvailable(); |
|
188 |
final MapControl mapControl = this.getMapCtrl(); |
|
189 |
final MapContext mapContext = this.getMapContext(); |
|
190 |
final ApplicationManager application = ApplicationLocator.getManager(); |
|
121 | 191 |
final MapContextManager manager = |
122 | 192 |
MapContextLocator.getMapContextManager(); |
123 |
final MapContext mapContext = mapControl.getMapContext(); |
|
124 | 193 |
|
125 | 194 |
logger.info("addLayer('{}','{}')", layerName, parameters.toString()); |
126 | 195 |
Thread task = new Thread(new Runnable() { |
... | ... | |
132 | 201 |
layer = manager.createLayer(layerName, parameters); |
133 | 202 |
preparedLayer = |
134 | 203 |
application.prepareOpenLayer(layer, |
135 |
new PrepareContextView() { |
|
204 |
new PrepareContextView_v1() {
|
|
136 | 205 |
|
137 | 206 |
public Window getOwnerWindow() { |
138 | 207 |
return null; |
... | ... | |
143 | 212 |
} |
144 | 213 |
|
145 | 214 |
public IProjection getViewProjection() { |
146 |
return mapControl.getProjection();
|
|
215 |
return mapContext.getProjection();
|
|
147 | 216 |
} |
217 |
|
|
218 |
public MapContext getMapContext() { |
|
219 |
return mapContext; |
|
220 |
} |
|
221 |
|
|
222 |
public boolean isMapControlAvailable() { |
|
223 |
return b_isMapControlAvail; |
|
224 |
} |
|
148 | 225 |
}); |
149 | 226 |
if (preparedLayer != null) { |
150 | 227 |
mapContext.getLayers().addLayer(preparedLayer); |
... | ... | |
165 | 242 |
} |
166 | 243 |
}); |
167 | 244 |
task.start(); |
245 |
|
|
168 | 246 |
} |
169 | 247 |
|
170 | 248 |
/** |
249 |
* |
|
250 |
* @param mapControl |
|
251 |
* @param layerName |
|
252 |
* @param parameters |
|
253 |
* @deprecated Use {@link #doAddLayer(String, DataStoreParameters)} |
|
254 |
* in combination with {@link #setMapCtrl(MapControl)} if you need |
|
255 |
* to set the MapControl. Note that MapControl is automatically initialized |
|
256 |
* when creating the panel from the AddLayer extension. |
|
257 |
*/ |
|
258 |
protected void doAddLayer(final MapControl mapControl, |
|
259 |
final String layerName, final DataStoreParameters parameters) { |
|
260 |
this.setMapCtrl(mapControl); |
|
261 |
doAddLayer(layerName, parameters); |
|
262 |
} |
|
263 |
|
|
264 |
/** |
|
171 | 265 |
* This method is called for example when user changes |
172 | 266 |
* tab in add layer dialog (new tab's settings are valid?) |
173 | 267 |
* |
Also available in: Unified diff