Revision 43215 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/layers/FLyrDefault.java
FLyrDefault.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import java.awt.Image; |
27 | 27 |
import java.awt.geom.Point2D; |
28 |
import java.io.File; |
|
28 | 29 |
import java.net.URI; |
29 | 30 |
import java.util.HashSet; |
30 | 31 |
import java.util.List; |
31 | 32 |
import java.util.Map; |
32 | 33 |
import java.util.Set; |
34 |
import org.apache.commons.lang3.StringUtils; |
|
33 | 35 |
|
34 | 36 |
import org.cresques.cts.ICoordTrans; |
35 | 37 |
import org.cresques.cts.IProjection; |
38 |
import org.gvsig.fmap.dal.DataStore; |
|
36 | 39 |
import org.gvsig.fmap.dal.DataTypes; |
37 | 40 |
import org.gvsig.fmap.dal.exception.ReadException; |
41 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
|
38 | 42 |
import org.gvsig.fmap.geom.primitive.Envelope; |
39 | 43 |
import org.gvsig.fmap.mapcontext.MapContext; |
40 | 44 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
... | ... | |
43 | 47 |
import org.gvsig.fmap.mapcontext.exceptions.StartEditionLayerException; |
44 | 48 |
import org.gvsig.fmap.mapcontext.impl.DefaultMapContextManager; |
45 | 49 |
import org.gvsig.fmap.mapcontext.layers.operations.ComposedLayer; |
50 |
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
|
46 | 51 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendChangedEvent; |
47 | 52 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.listeners.LegendListener; |
48 | 53 |
import org.gvsig.metadata.MetadataContainer; |
... | ... | |
751 | 756 |
return status.getNumErrors(); |
752 | 757 |
} |
753 | 758 |
|
754 |
/* |
|
755 |
* (non-Javadoc) |
|
756 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getError(int) |
|
757 |
*/ |
|
758 |
public BaseException getError(int i){ |
|
759 |
|
|
760 |
@Override |
|
761 |
public Throwable getError(int i){ |
|
759 | 762 |
return status.getError(i); |
760 | 763 |
} |
761 |
/* |
|
762 |
* (non-Javadoc) |
|
763 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getErrors() |
|
764 |
*/ |
|
765 |
public List getErrors(){ |
|
764 |
|
|
765 |
@Override |
|
766 |
public List<Throwable> getErrors(){ |
|
766 | 767 |
return status.getErrors(); |
767 | 768 |
} |
768 | 769 |
|
769 |
/* |
|
770 |
* (non-Javadoc) |
|
771 |
* |
|
772 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#addError(BaseException) |
|
773 |
*/ |
|
774 |
@Override |
|
775 |
public void addError(BaseException exception){ |
|
770 |
@Override |
|
771 |
public void addError(Throwable exception){ |
|
776 | 772 |
status.addLayerError(exception); |
777 | 773 |
} |
778 | 774 |
|
779 |
@Override
|
|
780 |
public void setError(Exception ex) {
|
|
781 |
this.status.setLayerError(ex);
|
|
782 |
}
|
|
775 |
@Override
|
|
776 |
public void setError(Throwable ex) {
|
|
777 |
this.status.setLayerError(ex);
|
|
778 |
}
|
|
783 | 779 |
|
784 |
/* |
|
785 |
* (non-Javadoc) |
|
786 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#visibleRequired() |
|
787 |
*/ |
|
780 |
@Override |
|
788 | 781 |
public boolean visibleRequired() { |
789 | 782 |
return status.visible; |
790 | 783 |
} |
791 |
/* |
|
792 |
* (non-Javadoc) |
|
793 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getInfoString() |
|
794 |
*/ |
|
795 |
@Override |
|
784 |
|
|
785 |
@Override |
|
796 | 786 |
public String getInfoString() { |
797 | 787 |
Envelope env = null; |
788 |
DataStore store = null; |
|
798 | 789 |
try { |
799 | 790 |
env = this.getFullEnvelope(); |
800 | 791 |
} catch (ReadException ex) { |
801 | 792 |
} |
793 |
|
|
794 |
try { |
|
795 |
store = ((SingleLayer)this).getDataStore(); |
|
796 |
} catch(Throwable th) { |
|
797 |
|
|
798 |
} |
|
802 | 799 |
|
803 | 800 |
LayerInformationBuilder builder = MapContextLocator.getMapContextManager().createLayerInformationBuilder(); |
804 |
|
|
801 |
|
|
802 |
if( store!=null ) { |
|
803 |
builder.title().labelkey("Data_source"); |
|
804 |
builder.property().labelkey("Source_type").value(store.getProviderName()); |
|
805 |
builder.property().labelkey("origen").value(store.getFullName()); |
|
806 |
if( store.getParameters() instanceof FilesystemStoreParameters ) { |
|
807 |
File f = ((FilesystemStoreParameters) (store.getParameters())).getFile(); |
|
808 |
if( f != null && f.exists() ) { |
|
809 |
builder.property().labelkey("_Size").value("%d bytes", f.length()); |
|
810 |
} |
|
811 |
} |
|
812 |
} |
|
813 |
|
|
805 | 814 |
builder.title().labelkey("_Coordenadas_geograficas"); |
806 |
builder.envelope().value(env); |
|
815 |
if( this.isAvailable() ) { |
|
816 |
builder.envelope().value(env); |
|
817 |
} |
|
807 | 818 |
|
808 | 819 |
builder.title().labelkey("_Projection"); |
809 |
builder.property().value(this.getProjection()); |
|
810 |
builder.text().asWKT(this.getProjection()); |
|
811 |
|
|
820 |
if( this.isAvailable() ) { |
|
821 |
builder.property().value(this.getProjection()); |
|
822 |
builder.text().asWKT(this.getProjection()); |
|
823 |
} |
|
824 |
|
|
812 | 825 |
return builder.toString(); |
813 | 826 |
} |
814 | 827 |
|
815 |
/* |
|
816 |
* (non-Javadoc) |
|
817 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#isWritable() |
|
818 |
*/ |
|
828 |
@Override |
|
819 | 829 |
public boolean isWritable() { |
820 | 830 |
return status.writable; |
821 | 831 |
} |
822 | 832 |
|
823 |
/* |
|
824 |
* (non-Javadoc) |
|
825 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#cloneLayer() |
|
826 |
*/ |
|
833 |
@Override |
|
827 | 834 |
public FLayer cloneLayer() throws Exception { |
835 |
logger.warn("Use of cloneLayer and this is not implemented."); |
|
828 | 836 |
return this; |
829 | 837 |
} |
830 |
/* |
|
831 |
* (non-Javadoc) |
|
832 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getTocStatusImage() |
|
833 |
*/ |
|
838 |
|
|
839 |
@Override |
|
834 | 840 |
public Image getTocStatusImage() { |
835 | 841 |
return tocStatusImage; |
836 | 842 |
} |
... | ... | |
985 | 991 |
} |
986 | 992 |
} |
987 | 993 |
|
994 |
@Override |
|
988 | 995 |
public void loadFromState(PersistentState state) throws PersistenceException { |
989 |
try { |
|
990 |
this.setDynValue(METADATA_NAME, state.getString("name")); |
|
991 |
this.setDynValue(METADATA_CRS, state.get("crs")); |
|
996 |
try { |
|
997 |
String name = state.getString("name"); |
|
998 |
if( StringUtils.isEmpty(name) ) { |
|
999 |
name = "Unknown"; |
|
1000 |
} |
|
1001 |
this.setDynValue(METADATA_NAME, name); |
|
1002 |
this.setDynValue(METADATA_CRS, state.get("crs")); |
|
992 | 1003 |
|
993 |
this.parentLayer = (FLayers) state.get("parentLayer"); |
|
994 |
this.status = (FLayerStatus) state.get("status"); |
|
995 |
this.minScale = state.getDouble("minScale"); |
|
996 |
this.maxScale = state.getDouble("maxScale"); |
|
997 |
this.transparency = state.getInt("transparency"); |
|
998 |
this.ct = (ICoordTrans) state.get("coordTrans"); |
|
1004 |
this.parentLayer = (FLayers) state.get("parentLayer"); |
|
1005 |
this.status = (FLayerStatus) state.get("status"); |
|
1006 |
if( this.status == null ) { |
|
1007 |
this.status = new FLayerStatus(); |
|
1008 |
this.setAvailable(false); |
|
1009 |
this.addError(new RuntimeException("Can't retreieve the status of the layer.")); |
|
1010 |
} |
|
1011 |
this.minScale = state.getDouble("minScale", -1); |
|
1012 |
this.maxScale = state.getDouble("maxScale", -1); |
|
1013 |
this.transparency = state.getInt("transparency", 255); |
|
1014 |
this.ct = (ICoordTrans) state.get("coordTrans"); |
|
999 | 1015 |
|
1000 |
this.properties.setExtendedProperties((Map)state.get("properties")); |
|
1001 |
} catch(PersistenceException ex) { |
|
1002 |
logger.warn("Can't load from persietent state the layer '"+this.getName()+"'."); |
|
1003 |
throw ex; |
|
1004 |
} catch(RuntimeException ex) { |
|
1005 |
logger.warn("Can't load from persietent state the layer '"+this.getName()+"'."); |
|
1006 |
throw ex; |
|
1007 |
} |
|
1016 |
this.properties.setExtendedProperties((Map) state.get("properties")); |
|
1017 |
} catch (Exception ex) { |
|
1018 |
logger.warn("Can't load from persietent state the layer '" + this.getName() + "'."); |
|
1019 |
throw ex; |
|
1020 |
} |
|
1008 | 1021 |
|
1009 | 1022 |
} |
1010 | 1023 |
public static class RegisterPersistence implements Callable { |
1011 | 1024 |
|
1012 |
public Object call() { |
|
1013 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
1014 |
DynStruct definition = manager.addDefinition( |
|
1025 |
@Override |
|
1026 |
public Object call() { |
|
1027 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
1028 |
DynStruct definition = manager.addDefinition( |
|
1015 | 1029 |
FLyrDefault.class, |
1016 | 1030 |
"FLyrDefault", |
1017 | 1031 |
"FLyrDefault Persistence definition", |
1018 | 1032 |
null, |
1019 | 1033 |
null |
1020 |
); |
|
1021 |
definition.addDynFieldString("name").setMandatory(false); |
|
1022 |
definition.addDynFieldInt("transparency").setMandatory(true); |
|
1023 |
definition.addDynFieldDouble("minScale").setMandatory(true); |
|
1024 |
definition.addDynFieldDouble("maxScale").setMandatory(true); |
|
1025 |
definition.addDynFieldObject("crs").setClassOfValue(IProjection.class).setMandatory(false); |
|
1026 |
definition.addDynFieldObject("parentLayer").setClassOfValue(FLayers.class).setMandatory(false); |
|
1027 |
definition.addDynFieldObject("coordTrans").setClassOfValue(ICoordTrans.class).setMandatory(false); |
|
1028 |
definition.addDynFieldObject("status").setClassOfValue(FLayerStatus.class).setMandatory(true); |
|
1029 |
definition.addDynFieldMap("properties").setClassOfItems(Object.class) |
|
1034 |
); |
|
1035 |
definition.addDynFieldString("name").setMandatory(false); |
|
1036 |
definition.addDynFieldInt("transparency").setMandatory(true); |
|
1037 |
definition.addDynFieldDouble("minScale").setMandatory(true); |
|
1038 |
definition.addDynFieldDouble("maxScale").setMandatory(true); |
|
1039 |
definition.addDynFieldObject("crs").setClassOfValue( |
|
1040 |
IProjection.class).setMandatory(false); |
|
1041 |
definition.addDynFieldObject("parentLayer").setClassOfValue( |
|
1042 |
FLayers.class).setMandatory(false); |
|
1043 |
definition.addDynFieldObject("coordTrans").setClassOfValue( |
|
1044 |
ICoordTrans.class).setMandatory(false); |
|
1045 |
definition.addDynFieldObject("status").setClassOfValue( |
|
1046 |
FLayerStatus.class).setMandatory(true); |
|
1047 |
// "properties" deberia estar declarada como un "ExtendedPropertiesHelper" |
|
1048 |
// pero por compatibilidad con proyectos viejos lo mantenemos como un |
|
1049 |
// Map. |
|
1050 |
// definition.addDynFieldObject("properties").setClassOfValue( |
|
1051 |
// ExtendedPropertiesHelper.class) |
|
1052 |
// .setMandatory(false); |
|
1053 |
definition.addDynFieldMap("properties").setClassOfItems(Object.class) |
|
1030 | 1054 |
.setMandatory(true); |
1031 | 1055 |
|
1032 |
return Boolean.TRUE;
|
|
1033 |
}
|
|
1056 |
return Boolean.TRUE;
|
|
1057 |
}
|
|
1034 | 1058 |
} |
1035 | 1059 |
|
1036 | 1060 |
|
Also available in: Unified diff