Hi Juan Lucas,<br>with your suggestion I managed correctly my custom Flayers. The problem was on reopening projects and I discovered that also topology extension is affected by this error.<br>However, in order to extend Flayers the trick is to override the setParentLayer(), the getXMLEntity() and the setXMLEntity() methods..<br>
obviously this could be avoided if the check in the Flayers was <span><span title="Fai clic per visualizzare le traduzioni alternative"><br></span></span> if (layer instanceof FLayers) <br>instead of <br> if (clase.isAssignableFrom(FLayers.class)) <br>
<br>This is my code, I hope it could help someone else:<br><br>@Override<br> public void setParentLayer(FLayers lyr) {<br> super.setParentLayer(lyr);<br> <br> if (lyr == null) {<br> return;<br>
}<br> <br> setMapContext(lyr.getMapContext());<br> lyr.addLayerCollectionListener(this);<br> }<br> <br> @Override<br> public XMLEntity getXMLEntity() throws XMLException {<br> XMLEntity xml = new XMLEntity();<br>
xml.putProperty("className", this.getClass().getName());<br> xml.putProperty("active", isActive());<br> xml.putProperty("name", getName());<br> xml.putProperty("minScale", getMinScale());<br>
xml.putProperty("maxScale", getMaxScale());<br> xml.putProperty("visible", isVisible());<br><br> if (getProjection() != null) {<br> xml.putProperty("proj", getProjection().getAbrev());<br>
}<br><br> xml.putProperty("transparency", getTransparency());<br><br> // --------------------<br> xml.putProperty("numLayers", getLayersCount());<br><br> String[] s = new String[getLayersCount()];<br>
<br> for (int i = 0; i < getLayersCount(); i++) {<br> s[i] = getLayer(i).getName();<br> }<br><br> xml.putProperty("LayerNames", s);<br><br> for (int i = 0; i < getLayersCount(); i++) {<br>
xml.addChild(getLayer(i).getXMLEntity());<br> }<br> xml.putProperty("myCustomProperty", "test");<br> return xml;<br> }<br> <br> public void setXMLEntity(XMLEntity xml) throws XMLException {<br>
setActive(xml.getBooleanProperty("active"));<br> setName(xml.getStringProperty("name"));<br> setMinScale(xml.getDoubleProperty("minScale"));<br> setMaxScale(xml.getDoubleProperty("maxScale"));<br>
setVisible(xml.getBooleanProperty("visible"));<br><br> if (xml.contains("proj")) {<br> setProjection(CRSFactory.getCRS(xml.getStringProperty("proj")));<br> }<br>
<br> if (xml.contains("transparency")) {<br> setTransparency(xml.getIntProperty("transparency"));<br> }<br><br> // ------------<br> int numLayers = xml.getIntProperty("numLayers");<br>
String[] s = xml.getStringArrayProperty("LayerNames");<br><br> for (int i = 0; i < numLayers; i++) {<br> FLayer layer = null;<br><br> try {<br> String className = xml.getChild(i).getStringProperty("className");<br>
Class<?> clase = Class.forName(className);<br> layer = (FLayer) clase.newInstance();<br> layer.setName(s[i]);<br> layer.setXMLEntity(xml.getChild(i));<br>
layer.load();<br> logger.debug("Layer: " + layer.getName() + " has been loaded.");<br> }<br> catch (Exception e) {<br> logger.error("While loading layer: " + s[i] + " (visible = false)", e);<br>
//layer.setVisible(false);<br> }<br><br> addLayer(layer);<br> }<br> String myCustomProp= xml.getStringProperty("myCustomProperty");<br> }<br> <br>Best regards,<br>
Flavio<br><br><div class="gmail_quote">2011/5/11 Flavio Pompermaier <span dir="ltr"><<a href="mailto:fla83tn@gmail.com">fla83tn@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I'll keep you up to date after my tests! Thanks for all<br><br><div class="gmail_quote"><div><div></div><div class="h5">2011/5/11 Juan Lucas Dominguez Rubio <span dir="ltr"><<a href="mailto:jldominguez@prodevelop.es" target="_blank">jldominguez@prodevelop.es</a>></span><br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div class="h5">
<div>
<div>
<div><font size="3" color="#000000" face="Times New Roman">Hello, yes that's it. </font><font size="3" color="#000000" face="Times New Roman">It keeps its own reference to Mapcontext. Does that work for you?</font></div>
<div> </div>
<div>If I had to do it again, I would probably promote a change in libFMap though.</div>
<div><font size="3" color="#000000" face="Times New Roman"></font> </div>
<div>Regards,</div></div><div>
<div>
<div><font size="2" face="Courier New"><font size="3" face="Times New Roman">Juan Lucas Domínguez Rubio<br></font>---</font></div>
<div><font size="2" face="Courier New"><font size="2" face="Courier New"><font size="2" face="Courier New">Prodevelop SL, Valencia (España)</font></font></font></div>
<div>
<div><font size="2" face="Courier New">Tlf.: 96.351.06.12 -- Fax: 96.351.09.68<br></font><a href="http://www.prodevelop.es/" target="_blank"><font size="2" face="Courier New">http://www.prodevelop.es</font></a><br><font size="2" face="Courier New">---</font></div>
</div></div>
</div><div><br>
<hr>
<font size="2" face="Tahoma"><div><b>De:</b> <a href="mailto:gvsig-desktop-devel-bounces@lists.forge.osor.eu" target="_blank">gvsig-desktop-devel-bounces@lists.forge.osor.eu</a> en nombre de Flavio Pompermaier<br>
</div><b>Enviado el:</b> mar 10/05/2011 18:26<div><br><b>Para:</b> gvSIG developers mailing list<br></div><b>CC:</b> Users and Developers mailing list<br><b>Asunto:</b> Re: [gvSIG-devel] Herencia de Flayers<br>
</font><br></div><div><div></div><div>
<div>The problem is actually in the opening of the gvSIG project (gvp). <br>If a class extends FLayers, then it will not have its MapContext during the set setXMLEntity(XMLEntity xml)!<br>There's no way to retrieve it..I wasn't able to test the class you suggested me and I don't know if it solves the problem..maybe it goes around the problem overriding the setParentLayer() method (pasted below)??<br>
<br> public void setParentLayer(FLayers lyr) {<br> super.setParentLayer(lyr);<br><br> if (lyr == null) {<br> return;<br> }<br><br> myFMap = lyr.getMapContext();<br><br> if (lyr instanceof LayerCollection) {<br>
LayerCollection lyrcol = (LayerCollection) lyr;<br> lyrcol.addLayerCollectionListener(this);<br> }<br> }<br><br>Thanks for the reply,<br>Flavio<br><br>
<div class="gmail_quote">2011/5/10 Juan Lucas Dominguez Rubio <span><<a href="mailto:jldominguez@prodevelop.es" target="_blank">jldominguez@prodevelop.es</a>></span><br>
<blockquote class="gmail_quote" style="padding-left:1ex;margin:0px 0px 0px 0.8ex;border-left:#ccc 1px solid">
<div>
<div>
<div><font size="3" color="#000000" face="Times New Roman">Hola, Flavio:</font></div>
<div> </div>
<div>Creo que yo encontré este problema cuando hice la capa para servidores ArcIMS vectorial porque es posible tener varias capas ArcIMS vectorial en una petición y el resultado era una colección (FLayers). Después de investigar un poco pude resolverlo pero no recuerdo los detalles. La clase es esta:</div>
<div> </div>
<div><a href="https://svn.forge.osor.eu/svn/gvsig-desktop/branches/gvSIG_1.11.0_Mejoras_gvSIG-EIEL/extensions/extArcims/src/es/prodevelop/cit/gvsig/arcims/fmap/layers/FFeatureLyrArcIMSCollection.java" target="_blank">https://svn.forge.osor.eu/svn/gvsig-desktop/branches/gvSIG_1.11.0_Mejoras_gvSIG-EIEL/extensions/extArcims/src/es/prodevelop/cit/gvsig/arcims/fmap/layers/FFeatureLyrArcIMSCollection.java</a></div>
<div> </div>
<div>
<div>¿Quizá es un ejemplo para ti? </div>
<div>¿En qué momento encuentras el problema concretamente?</div>
<div>¿Es cuando has salvado el proyecto y quieres abrirlo de nuevo?</div></div>
<div> </div>
<div>En este momento existen pocos servidores ArcIMS y ninguno tiene capas vectoriales (solo raster) por lo tanto no puedo ejecutar un ejemplo con mi código.</div>
<div> </div>
<div>Saludos,</div>
<div><font size="2" face="Courier New"><font size="3" face="Times New Roman">Juan Lucas Domínguez Rubio<br></font>---</font></div></div>
<div>
<div><font size="2" face="Courier New"><font size="2" face="Courier New"><font size="2" face="Courier New">Prodevelop SL, Valencia (España)</font></font></font></div>
<div>
<div><font size="2" face="Courier New">Tlf.: 96.351.06.12 -- Fax: 96.351.09.68<br></font><a href="http://www.prodevelop.es/" target="_blank"><font size="2" face="Courier New">http://www.prodevelop.es</font></a><br><font size="2" face="Courier New">---</font></div>
</div></div>
<div><br>
<hr>
<font size="2" face="Tahoma"><b>De:</b> <a href="mailto:gvsig-desktop-devel-bounces@lists.forge.osor.eu" target="_blank">gvsig-desktop-devel-bounces@lists.forge.osor.eu</a> en nombre de Flavio Pompermaier<br><b>Enviado el:</b> mar 10/05/2011 17:04<br>
<b>Para:</b> gvSIG developers mailing list; Users and Developers mailing list<br><b>Asunto:</b> [gvSIG-devel] Herencia de Flayers<br></font><br></div>
<div>
<div></div>
<div>
<div><span><span title="Fai clic per visualizzare le traduzioni alternative">Hola</span> <span title="Fai clic per visualizzare le traduzioni alternative">a todos,<br></span></span><span><span title="Fai clic per visualizzare le traduzioni alternative">salutimi</span> <span title="Fai clic per visualizzare le traduzioni alternative">disculpas por</span> <span title="Fai clic per visualizzare le traduzioni alternative">mi</span> <span title="Fai clic per visualizzare le traduzioni alternative">español...</span></span><br>
<span><span title="Fai clic per visualizzare le traduzioni alternative"></span><span title="Fai clic per visualizzare le traduzioni alternative">Quería</span> <span title="Fai clic per visualizzare le traduzioni alternative">saber</span> <span title="Fai clic per visualizzare le traduzioni alternative">si</span> <span title="Fai clic per visualizzare le traduzioni alternative">hay</span> <span title="Fai clic per visualizzare le traduzioni alternative">una manera de</span> <span title="Fai clic per visualizzare le traduzioni alternative">extender</span> la clase FLayer <span title="Fai clic per visualizzare le traduzioni alternative">(para</span> <span title="Fai clic per visualizzare le traduzioni alternative">crear</span> <span title="Fai clic per visualizzare le traduzioni alternative">grupo de</span> <span title="Fai clic per visualizzare le traduzioni alternative">capas</span> <span title="Fai clic per visualizzare le traduzioni alternative">a medida</span><span title="Fai clic per visualizzare le traduzioni alternative">)</span><span title="Fai clic per visualizzare le traduzioni alternative">.</span> <span title="Fai clic per visualizzare le traduzioni alternative"><br>
Creo</span> <span title="Fai clic per visualizzare le traduzioni alternative">que</span> <span title="Fai clic per visualizzare le traduzioni alternative">es</span> <span title="Fai clic per visualizzare le traduzioni alternative">'</span><span title="Fai clic per visualizzare le traduzioni alternative">un error</span> <span title="Fai clic per visualizzare le traduzioni alternative">en</span> <span title="Fai clic per visualizzare le traduzioni alternative">el siguiente control</span></span>: clase.isAssignableFrom(FLayers.class). <br>
<span><span title="Fai clic per visualizzare le traduzioni alternative">Específicamente, en FLayers </span></span><span><span title="Fai clic per visualizzare le traduzioni alternative">está</span> <span title="Fai clic per visualizzare le traduzioni alternative">escrito:</span></span><span><span title="Fai clic per visualizzare le traduzioni alternative"> </span></span><br>
<br> Class clase = LayerFactory.getLayerClassForLayerClassName(className);<br> layer = (FLayer) clase.newInstance();<br> if (clase.isAssignableFrom(FLayers.class)) {<br> ((FLayers)layer).setMapContext(getMapContext());<br>
((FLayers)layer).setParentLayer(this);<br> // layer = new FLayers(getMapContext(),this);<br> layer.setXMLEntity(xml);<br> } else {<br> // Capas Nuevas (externas)<br> layer.setName(name);<br>
layer.setXMLEntity(xml);<br> layer.load();<br> }<br><br>En el caso de Capas Nuevas (externas), <span><span title="Fai clic per visualizzare le traduzioni alternative">no</span> <span title="Fai clic per visualizzare le traduzioni alternative">hay</span> <span title="Fai clic per visualizzare le traduzioni alternative">manera</span> <span title="Fai clic per visualizzare le traduzioni alternative">de</span> <span title="Fai clic per visualizzare le traduzioni alternative">establecer el</span> <span title="Fai clic per visualizzare le traduzioni alternative">MapContext</span><span title="Fai clic per visualizzare le traduzioni alternative"> en el mi custom FLayers, a menos</span> <span title="Fai clic per visualizzare le traduzioni alternative">que</span> <span title="Fai clic per visualizzare le traduzioni alternative">corregir el</span> <span title="Fai clic per visualizzare le traduzioni alternative">código</span> <span title="Fai clic per visualizzare le traduzioni alternative">de la siguiente manera</span><span title="Fai clic per visualizzare le traduzioni alternative">:<br>
<br></span></span> if (layer instanceof FLayers) {<br> .....<br> }<br><br><span><span title="Fai clic per visualizzare le traduzioni alternative">Algo</span> <span title="Fai clic per visualizzare le traduzioni alternative">mal</span><span title="Fai clic per visualizzare le traduzioni alternative">?</span></span><br>
<br>Saludos,<br>Flavio<br></div></div></div></div><br>_______________________________________________<br>gvSIG-desktop-devel mailing list<br><a href="mailto:gvSIG-desktop-devel@lists.forge.osor.eu" target="_blank">gvSIG-desktop-devel@lists.forge.osor.eu</a><br>
<a href="https://lists.forge.osor.eu/listinfo/gvsig-desktop-devel" target="_blank">https://lists.forge.osor.eu/listinfo/gvsig-desktop-devel</a><br><br></blockquote></div><br></div></div></div></div><br></div></div>_______________________________________________<br>
Gvsig_internacional mailing list<br>
<a href="mailto:Gvsig_internacional@listserv.gva.es" target="_blank">Gvsig_internacional@listserv.gva.es</a><br>
<a href="http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional" target="_blank">http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional</a><br>
<br></blockquote></div><br>
</blockquote></div><br>