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/DefaultNewLayerService.java
DefaultNewLayerService.java | ||
---|---|---|
28 | 28 |
import org.gvsig.fmap.dal.DALLocator; |
29 | 29 |
import org.gvsig.fmap.dal.DataManager; |
30 | 30 |
import org.gvsig.fmap.dal.DataServerExplorer; |
31 |
import org.gvsig.fmap.dal.NewDataStoreParameters;
|
|
31 |
import org.gvsig.fmap.dal.DataStore;
|
|
32 | 32 |
import org.gvsig.fmap.dal.exception.DataException; |
33 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
33 | 34 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
34 | 35 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
35 |
import org.gvsig.newlayer.NewLayerException; |
|
36 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
37 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
38 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
|
39 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
|
40 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
36 | 41 |
import org.gvsig.newlayer.NewLayerManager; |
37 | 42 |
import org.gvsig.newlayer.NewLayerProvider; |
38 | 43 |
import org.gvsig.newlayer.NewLayerProviderFactory; |
... | ... | |
50 | 55 |
private NewLayerManager newLayerManager; |
51 | 56 |
private NewLayerProviderFactory type; |
52 | 57 |
private NewLayerProvider provider; |
58 |
private boolean addLayerToView = true; |
|
59 |
private MapContext mapContext; |
|
53 | 60 |
|
54 | 61 |
/** |
55 | 62 |
* {@link DefaultNewLayerService} constructor |
56 | 63 |
|
57 | 64 |
*/ |
58 |
public DefaultNewLayerService(NewLayerManager manager) { |
|
65 |
public DefaultNewLayerService(NewLayerManager manager , MapContext mapContext) {
|
|
59 | 66 |
this.newLayerManager = manager; |
67 |
this.mapContext = mapContext; |
|
60 | 68 |
} |
61 | 69 |
|
62 | 70 |
public NewLayerProvider getProvider(){ |
... | ... | |
70 | 78 |
} catch (DataException e) { |
71 | 79 |
throw new CantCreateNewLayerException(e); |
72 | 80 |
} |
73 |
|
|
74 | 81 |
} |
75 | 82 |
|
83 |
public void loadLayer() throws NewLayerServiceException { |
|
84 |
try { |
|
85 |
String storeName = this.getStoreName(); |
|
86 |
NewFeatureStoreParameters storeParameters = this.getNewStoreParameters(); |
|
87 |
DataManager dataManager=DALLocator.getDataManager(); |
|
88 |
DataStore store = dataManager.openStore(storeName, storeParameters); |
|
89 |
String layerName = store.getName(); |
|
90 |
|
|
91 |
MapContextManager mapContextManager = MapContextLocator.getMapContextManager(); |
|
92 |
FLayer lyr = mapContextManager.createLayer(layerName, store); |
|
93 |
lyr.setActive(true); |
|
94 |
lyr.setVisible(true); |
|
95 |
mapContext.getLayers().addLayer(lyr); |
|
96 |
|
|
97 |
lyr.dispose(); |
|
98 |
} catch (DataException e) { |
|
99 |
throw new CantOpenStoreException(e); |
|
100 |
} catch (ValidateDataParametersException e) { |
|
101 |
throw new CantOpenStoreException(e); |
|
102 |
} catch (LoadLayerException e) { |
|
103 |
throw new CantLoadNewLayerException(e); |
|
104 |
} |
|
105 |
|
|
106 |
} |
|
107 |
|
|
108 |
|
|
76 | 109 |
public class CantCreateNewLayerException extends NewLayerServiceException { |
77 | 110 |
/** |
78 | 111 |
* |
... | ... | |
84 | 117 |
} |
85 | 118 |
} |
86 | 119 |
|
120 |
public class CantOpenStoreException extends NewLayerServiceException { |
|
121 |
|
|
122 |
/** |
|
123 |
* |
|
124 |
*/ |
|
125 |
private static final long serialVersionUID = -2245228621032918630L; |
|
126 |
|
|
127 |
public CantOpenStoreException(Throwable cause) { |
|
128 |
super("Can't open store", cause, "_cant_open_store", serialVersionUID); |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
public class CantLoadNewLayerException extends NewLayerServiceException { |
|
133 |
|
|
134 |
/** |
|
135 |
* |
|
136 |
*/ |
|
137 |
private static final long serialVersionUID = -1711950651766745963L; |
|
138 |
|
|
139 |
public CantLoadNewLayerException(Throwable cause) { |
|
140 |
super("Can't load the new layer", cause, "_cant_load_the_new_layer", serialVersionUID); |
|
141 |
} |
|
142 |
} |
|
143 |
|
|
87 | 144 |
public void setType(String type) { |
88 | 145 |
List<NewLayerProviderFactory> providers = this.newLayerManager.getProviders(NewLayerManager.STORETYPE.ANY); |
89 | 146 |
Iterator<NewLayerProviderFactory> it = providers.iterator(); |
... | ... | |
129 | 186 |
return this.type.getName(); |
130 | 187 |
} |
131 | 188 |
|
189 |
public void addLayerToView(boolean b) { |
|
190 |
this.addLayerToView = b; |
|
191 |
} |
|
192 |
|
|
132 | 193 |
} |
Also available in: Unified diff