Revision 950 org.gvsig.raster.postgis/trunk/org.gvsig.raster.postgis/org.gvsig.raster.postgis.app/org.gvsig.raster.postgis.app.postgisrasterclient/src/main/java/org/gvsig/raster/postgis/app/postgisrasterclient/gui/AddPostGISRasterLayerWizard.java

View differences:

AddPostGISRasterLayerWizard.java
36 36
import org.gvsig.andami.PluginServices;
37 37
import org.gvsig.andami.PluginsLocator;
38 38
import org.gvsig.andami.PluginsManager;
39
import org.gvsig.andami.messages.NotificationManager;
40 39
import org.gvsig.andami.ui.mdiManager.IWindow;
41 40
import org.gvsig.app.gui.WizardPanel;
42 41
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
42
import org.gvsig.compat.net.ICancellable;
43 43
import org.gvsig.fmap.dal.DALLocator;
44 44
import org.gvsig.fmap.dal.DataManager;
45 45
import org.gvsig.fmap.dal.DataStore;
......
48 48
import org.gvsig.fmap.dal.exception.DataException;
49 49
import org.gvsig.fmap.dal.exception.InitializeException;
50 50
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
51
import org.gvsig.fmap.dal.exception.ReadException;
51 52
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
52 53
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
53 54
import org.gvsig.fmap.dal.feature.FeatureStore;
......
68 69
import org.gvsig.raster.postgis.io.PostGISRasterServerExplorerParameters;
69 70
import org.gvsig.raster.postgis.swing.AddLayerUI;
70 71
import org.gvsig.raster.postgis.swing.PostGISRasterSwingLocator;
72
import org.gvsig.raster.util.CancelTaskImpl;
71 73
import org.gvsig.raster.util.RasterNotLoadException;
72 74
import org.gvsig.tools.dynobject.DynObject;
73 75
import org.slf4j.Logger;
......
84 86
	private AbstractViewPanel           view                  = null;
85 87
	private AddLayerUI                  apiUI                 = null;
86 88
	private DBServerExplorerParameters  dbExplorerParameters  = null;
89
	private ICancellable                cancel                = null;
87 90
	
91
	/**
92
	 * Thread to connect to a PostGIS raster server
93
	 * @author Nacho Brodin (nachobrodin@gmail.com)
94
	 */
95
	public class ConnectThread extends Thread {
96
		private ICancellable              cancel      = null;
97
		
98
		public ConnectThread(ICancellable cancel) {
99
			this.cancel = cancel;
100
		}
101
		
102
	    public void run() {
103
	    	try {
104
	    		loadLayer();
105
			} finally {
106
				((CancelTaskImpl)cancel).setCanceled(false);
107
			}
108
	    }
109
	}
110
	
88 111
	public AddPostGISRasterLayerWizard() {
89 112
		super();
90 113
		initialize();
......
155 178
    /**
156 179
	 * Return FLayers if user performs multi selection.
157 180
	 */
158
	public FLayer getLayer() {
181
	public void loadLayer() {
182
		MapContext mapContext = null;
183
		IWindow[] w = PluginServices.getMDIManager().getAllWindows();
184
		for (int i = 0; i < w.length; i++) {
185
			if (w[i] instanceof org.gvsig.app.project.documents.view.gui.AbstractViewPanel) {
186
				mapContext = ((org.gvsig.app.project.documents.view.gui.AbstractViewPanel)w[i]).getMapControl().getMapContext();
187
			}
188
		}
159 189
		
160 190
		String host = dbExplorerParameters.getHost();
161 191
		if(host.compareTo("localhost") == 0)
......
168 198
		String schema = null;
169 199
		
170 200
		List<Object> tables = apiUI.getSelectedTables();
171
		TableListItem item = (TableListItem)tables.get(0);
172
		schema = item.getSchema();
173
		table = item.getTableName();
174
		
175
		String connString = null;
176
		if(schema == null)
177
			connString = "PG:host='" + host + "' port='" + port + "' dbname='" + dbname + "' user='" + user + "' password='" + password + "' table='" + table + "'";
178
		else
179
			connString = "PG:host='" + host + "' port='" + port + "' dbname='" + dbname + "' user='" + user + "' password='" + password + "' schema='" + schema + "' table='" + table + "'";
180
 
181
		//connString += " column='rast' where='rid = 1041'";
182
		try {
183
			return createLayer(getFormatedRasterFileName(connString), connString, item);
184
		} catch (LoadLayerException e) {
185
			logger.error("Error creating layer: " + e.getMessage(), e);
186
			showConnectionErrorMessage(PluginServices.getText(this, "error_creating_layer"));
187
			return null;
201

  
202
		for(int i = 0; i < tables.size(); i++) {
203
			TableListItem item = (TableListItem)tables.get(i);
204
			schema = item.getSchema();
205
			table = item.getTableName();
206

  
207
			String connString = null;
208
			if(schema == null)
209
				connString = "PG:host='" + host + "' port='" + port + "' dbname='" + dbname + "' user='" + user + "' password='" + password + "' table='" + table + "'";
210
			else
211
				connString = "PG:host='" + host + "' port='" + port + "' dbname='" + dbname + "' user='" + user + "' password='" + password + "' schema='" + schema + "' table='" + table + "'";
212

  
213
			//connString += " column='rast' where='rid = 1041'";
214
			try {
215
				FLayer layer = createLayer(getFormatedRasterFileName(connString), connString, item);
216

  
217
				//Adds the layer to the view
218
				mapContext.beginAtomicEvent();
219
				layer.setVisible(true);
220
				mapContext.getLayers().addLayer(layer);
221
				mapContext.callLegendChanged();
222
				mapContext.endAtomicEvent();
223
				mapContext.invalidate();
224
			} catch (LoadLayerException e) {
225
				logger.error("Error creating layer: " + e.getMessage(), e);
226
				showConnectionErrorMessage(PluginServices.getText(this, "error_creating_layer"));
227
			}
188 228
		}
189 229
	}
190 230
	
......
257 297

  
258 298
	@Override
259 299
	public void execute() {
260
		FLayer lyr = getLayer();
261
		MapContext mapContext = null;
262
		IWindow[] w = PluginServices.getMDIManager().getAllWindows();
263
		for (int i = 0; i < w.length; i++) {
264
			if (w[i] instanceof org.gvsig.app.project.documents.view.gui.AbstractViewPanel) {
265
				mapContext = ((org.gvsig.app.project.documents.view.gui.AbstractViewPanel)w[i]).getMapControl().getMapContext();
266
			}
267
		}
268

  
269
		mapContext.beginAtomicEvent();
270
		lyr.setVisible(true);
271
		mapContext.getLayers().addLayer(lyr);
272
		mapContext.callLegendChanged();
273
		mapContext.endAtomicEvent();
274
		mapContext.invalidate();
300
		showConnectionInfoMessage(PluginServices.getText(this, "loading_postgis_raster_layer"));
301
		cancel = new CancelTaskImpl();
302
		new ConnectThread(cancel).start();
275 303
	}
276 304

  
277 305
	@Override
......
301 329
		try {
302 330
			dbExplorer = (DBServerExplorer) dm.openServerExplorer(dbSeverExplorerParameters2.getExplorerName(), dbSeverExplorerParameters2);
303 331

  
332
			if(dbExplorer == null) {
333
				throw new Exception();	
334
			}
335
			
304 336
			List parameters = dbExplorer.list();
305 337

  
306 338
			Iterator iter = parameters.iterator();
......
311 343
				
312 344
				//Criterios para a?adir la tabla a la lista
313 345
				try {
314
					if(!param.getTable().startsWith("o_") && isRasterTable(param)) {
346
					if(/*!param.getTable().startsWith("o_") &&*/ isRasterTable(param)) {
315 347
						apiUI.addElementToTable(new TableListItem(dbExplorer, param));
316 348
					}
317 349
				} catch (PostGISRasterCoreException e) {
318
					logger.error("While getting table names: " + e.getMessage(), e);
350
					logger.info("While getting table names: " + e.getMessage(), e);
319 351
				}
320 352
			}
321 353

  
322
		} catch (Exception e) {
323
			logger.error("While getting table names: " + e.getMessage(), e);
354
		} catch (ReadException e) {
355
			logger.info("While getting table names: " + e.getMessage(), e);
324 356
			showConnectionErrorMessage(PluginServices.getText(this, "error_getting_tables"));
325 357
			return;
358
		}  catch (Exception e) {
359
			logger.info("While getting table names: " + e.getMessage(), e);
360
			showConnectionErrorMessage(PluginServices.getText(this, "error_getting_tables"));
361
			return;
326 362
		}
327 363
	}
328 364
	
......
449 485
		JOptionPane.showMessageDialog(apiUI.getComponent(), title + msg, title,
450 486
				JOptionPane.ERROR_MESSAGE);
451 487
	}
488
	
489
	/**
490
	 * Shows a information window
491
	 * @param _msg
492
	 */
493
	private void showConnectionInfoMessage(String _msg) {
494
		String msg = (_msg.length() > 300) ? "" : (": " + _msg);
495
		String title = PluginServices.getText(this, "warning");
496
		JOptionPane.showMessageDialog(apiUI.getComponent(), title + msg, title,
497
				JOptionPane.WARNING_MESSAGE);
498
	}
452 499

  
453 500
}

Also available in: Unified diff