Revision 41434
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/AddLayer.java | ||
---|---|---|
40 | 40 |
import org.gvsig.app.project.documents.view.ViewDocument; |
41 | 41 |
import org.gvsig.app.project.documents.view.gui.IView; |
42 | 42 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.swing.FilesystemExplorerAddLayerWizardPanel; |
43 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
43 | 44 |
import org.gvsig.fmap.mapcontext.ViewPort; |
44 | 45 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
45 | 46 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
... | ... | |
154 | 155 |
* |
155 | 156 |
* @return FOpenDialog |
156 | 157 |
*/ |
157 |
private AddLayerDialog createFOpenDialog(MapControl mapControl) { |
|
158 |
private AddLayerDialog createFOpenDialog(MapControl mapControl, MapContext mapContext) {
|
|
158 | 159 |
AddLayerDialog fopen = new AddLayerDialog(); |
159 | 160 |
for (int i = 0; i < wizardStack.size(); i++) { |
160 | 161 |
WizardPanel wp; |
161 | 162 |
try { |
162 |
wp = AddLayer.getInstance(i, mapControl); |
|
163 |
Class<? extends WizardPanel> wpClass = AddLayer.wizardStack.get(i); |
|
164 |
Object[] params = {}; |
|
165 |
wp = wpClass.getConstructor() |
|
166 |
.newInstance(params); |
|
167 |
wp.setMapCtrl(mapControl); |
|
168 |
wp.setMapContext(mapContext); |
|
169 |
wp.initWizard(); |
|
163 | 170 |
|
164 | 171 |
fopen.addWizardTab(wp.getTabName(), wp); |
165 | 172 |
} catch (Exception e) { |
... | ... | |
178 | 185 |
* @param wizardPanel WizardPanel where user selected the layers to load |
179 | 186 |
* @return |
180 | 187 |
*/ |
181 |
private boolean loadGenericWizardPanelLayers(MapControl mapControl, WizardPanel wp) {
|
|
182 |
wp.setMapCtrl(mapControl);
|
|
183 |
wp.execute(); |
|
188 |
private boolean loadGenericWizardPanelLayers(MapContext mapContext, WizardPanel wp, boolean mapControlAvailable) {
|
|
189 |
wp.setMapContext(mapContext);
|
|
190 |
wp.executeWizard();
|
|
184 | 191 |
return true; |
185 | 192 |
} |
186 | 193 |
|
187 | 194 |
/** |
188 |
* Abre dialogo para a�adir capas y las a�ade en mapControl |
|
195 |
* Opens the AddLayer dialog, and adds the selected layers to the provided |
|
196 |
* MapContext. |
|
189 | 197 |
* |
190 |
* Devuelve true si se han a�adido capas. |
|
191 |
* @param mapControl |
|
192 |
* @return |
|
198 |
* This method is useful when we want to add a layer but we don't have an |
|
199 |
* associated View. If a View or a MapControl is available, you will |
|
200 |
* usually prefer the {@link #addLayers(MapControl)} method. |
|
201 |
* |
|
202 |
* @param mapContext The MapContext to add the layers to |
|
203 |
* @return <code>true</code> if any layer has been added. |
|
193 | 204 |
*/ |
205 |
public boolean addLayers(MapContext mapContext) { |
|
206 |
return doAddLayers(null, mapContext); |
|
207 |
} |
|
208 |
|
|
209 |
/** |
|
210 |
* Opens the AddLayer dialog, and adds the selected layers to the provided |
|
211 |
* mapControl. |
|
212 |
* |
|
213 |
* @param mapControl The MapControl to add the layers to |
|
214 |
* |
|
215 |
* @return <code>true</code> if any layer has been added. |
|
216 |
*/ |
|
194 | 217 |
public boolean addLayers(MapControl mapControl) { |
195 |
// create and show the modal fopen dialog |
|
218 |
return doAddLayers(mapControl, mapControl.getMapContext()); |
|
219 |
} |
|
220 |
|
|
221 |
private boolean doAddLayers(MapControl mapControl, MapContext mapContext) { |
|
196 | 222 |
AddLayerDialog fopen = null; |
197 | 223 |
try { |
198 |
fopen = createFOpenDialog(mapControl); |
|
224 |
fopen = createFOpenDialog(mapControl, mapContext);
|
|
199 | 225 |
PluginServices.getMDIManager().addWindow(fopen); |
200 | 226 |
|
201 | 227 |
if (fopen.isAccepted()) { |
202 | 228 |
if (fopen.getSelectedTab() instanceof WizardPanel) { |
203 | 229 |
WizardPanel wp = (WizardPanel) fopen.getSelectedTab(); |
204 |
return loadGenericWizardPanelLayers(mapControl, wp); |
|
230 |
wp.execute(); |
|
231 |
return true; |
|
205 | 232 |
} else { |
206 | 233 |
JOptionPane.showMessageDialog((Component) PluginServices |
207 | 234 |
.getMainFrame(), PluginServices.getText(this, "ninguna_capa_seleccionada")); |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/prepareAction/PrepareContextView.java | ||
---|---|---|
27 | 27 |
import org.gvsig.fmap.mapcontrol.MapControl; |
28 | 28 |
|
29 | 29 |
/** |
30 |
* Object containing the context to prepare the loading process |
|
31 |
* of a layer. |
|
32 |
* |
|
30 | 33 |
* @author jmvivo |
31 |
* |
|
34 |
* @see PrepareContextView_1
|
|
32 | 35 |
*/ |
33 | 36 |
public interface PrepareContextView extends PrepareContext { |
34 | 37 |
|
35 |
/** |
|
36 |
* |
|
37 |
* |
|
38 |
* @return |
|
39 |
*/ |
|
40 |
|
|
38 |
/** |
|
39 |
* You can use it to interact with the MapControl component that will |
|
40 |
* receive the new layer, in order to get user feedback |
|
41 |
* (for instance a bounding box). Check the |
|
42 |
* {@link PrepareContextView_v1#isMapControlAvailable()} method before |
|
43 |
* accessing the MapControl |
|
44 |
* because it may not be available (for instance when adding layers |
|
45 |
* to a MapContext not associated with a View). |
|
46 |
* |
|
47 |
* For the moment, this method will return a non-null MapControl for |
|
48 |
* compatibility reasons, but you should still check |
|
49 |
* {@link PrepareContextView_v1#isMapControlAvailable()} to be sure it |
|
50 |
* is a valid one, as it could only be a fake MapControl. |
|
51 |
* |
|
52 |
* It is recommended to use {@link PrepareContextView_v1#getMapContext()} |
|
53 |
* method when no interaction is needed with the map user interface |
|
54 |
* (for instance to get the active projection, visible extent, etc) |
|
55 |
* |
|
56 |
* @return Returns the mapCtrl. |
|
57 |
*/ |
|
41 | 58 |
MapControl getMapControl(); |
42 | 59 |
|
43 | 60 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/gui/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 |
* |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/addlayer/AddLayerDialog.java | ||
---|---|---|
230 | 230 |
} |
231 | 231 |
|
232 | 232 |
private void closeWindow() { |
233 |
// JTabbedPane tabbed = getJTabbedPane(); |
|
234 |
// for (int i = 0; i < tabbed.getTabCount(); i++) { |
|
235 |
// Component component = tabbed.getComponentAt(i); |
|
236 |
// if (component instanceof WizardPanel) { |
|
237 |
// ((WizardPanel) component).close(); |
|
238 |
// } |
|
239 |
// } |
|
240 | 233 |
if (PluginServices.getMainFrame() == null) { |
241 | 234 |
((JDialog) (getParent().getParent().getParent().getParent())).dispose(); |
242 | 235 |
} else { |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.geodb.app/org.gvsig.geodb.app.mainplugin/src/main/java/org/gvsig/geodb/vectorialdb/wizard/WizardDB.java | ||
---|---|---|
702 | 702 |
*/ |
703 | 703 |
|
704 | 704 |
protected void processErrorsOfLayer(FLayer lyr, MapControl mapControl) { |
705 |
// List errors = lyr.getErrors(); |
|
706 |
// wp.callError(null); |
|
707 |
mapControl.getMapContext().callNewErrorEvent(null); |
|
705 |
this.getMapContext().callNewErrorEvent(null); |
|
708 | 706 |
} |
709 | 707 |
|
710 | 708 |
private void removeSettingsPanels() { |
... | ... | |
723 | 721 |
} |
724 | 722 |
|
725 | 723 |
public IProjection getViewProjection() { |
726 |
return null;
|
|
724 |
return WizardDB.this.getMapContext().getProjection();
|
|
727 | 725 |
} |
728 | 726 |
|
729 | 727 |
}; |
Also available in: Unified diff