Revision 42515 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.prov/org.gvsig.newlayer.prov.file/src/main/java/org/gvsig/newlayer/prov/file/AbstractNewLayerFileProvider.java
AbstractNewLayerFileProvider.java | ||
---|---|---|
47 | 47 |
|
48 | 48 |
/** |
49 | 49 |
* NewLayer provider to create a shape file. |
50 |
*
|
|
50 |
* |
|
51 | 51 |
* @author gvSIG Team |
52 | 52 |
* @version $Id$ |
53 | 53 |
*/ |
54 | 54 |
public abstract class AbstractNewLayerFileProvider extends AbstractNewLayerProvider { |
55 | 55 |
protected static final Logger LOG = |
56 | 56 |
LoggerFactory.getLogger(AbstractNewLayerFileProvider.class); |
57 |
|
|
57 |
|
|
58 | 58 |
protected List<NewLayerProviderPanel> panels = new ArrayList(); |
59 | 59 |
protected NewLayerFileProviderPanel fileProviderPanel = null; |
60 | 60 |
protected NewFeatureStoreParameters storeParameters = null; |
61 |
|
|
61 |
|
|
62 | 62 |
protected AbstractNewLayerFileProvider(NewLayerService service) { |
63 | 63 |
super(service); |
64 | 64 |
fileProviderPanel = new NewLayerFileProviderPanel(this); |
65 | 65 |
panels.add(fileProviderPanel); |
66 |
}
|
|
67 |
|
|
68 |
public List<NewLayerProviderPanel> getPanels() {
|
|
66 |
} |
|
67 |
|
|
68 |
public List<NewLayerProviderPanel> getPanels() { |
|
69 | 69 |
return panels; |
70 |
}
|
|
71 |
|
|
70 |
} |
|
71 |
|
|
72 | 72 |
public EditableFeatureType getFeatureType() { |
73 | 73 |
return this.getNewStoreParameters().getDefaultFeatureType(); |
74 | 74 |
} |
75 |
|
|
75 |
|
|
76 | 76 |
protected abstract String getFileParameterName(); |
77 |
|
|
77 |
|
|
78 | 78 |
protected abstract String getFileExtension(); |
79 | 79 |
|
80 | 80 |
public NewFeatureStoreParameters getNewStoreParameters() { |
81 | 81 |
DataManager dataManager = DALLocator.getDataManager(); |
82 |
|
|
82 |
|
|
83 | 83 |
try { |
84 | 84 |
if (this.explorer == null){ |
85 | 85 |
DataServerExplorerParameters explorerParameters = |
... | ... | |
87 | 87 |
this.explorer = |
88 | 88 |
dataManager.openServerExplorer("FilesystemExplorer", explorerParameters); |
89 | 89 |
} |
90 |
|
|
90 |
|
|
91 | 91 |
File selectedFile = fileProviderPanel.getSelectedFile(); |
92 | 92 |
String fileName = selectedFile.getName(); |
93 | 93 |
if (fileName.indexOf(".") < 0){ |
94 | 94 |
fileName = fileName + "." + this.getFileExtension(); |
95 |
} |
|
96 |
if (selectedFile.getParent()!=null){ |
|
95 | 97 |
selectedFile = new File(selectedFile.getParent() + File.separator + fileName); |
96 |
} |
|
97 |
|
|
98 |
}else{ |
|
99 |
selectedFile = new File(fileName); |
|
100 |
} |
|
101 |
if (!selectedFile.isAbsolute()){ |
|
102 |
String home=System.getProperty("user.home"); |
|
103 |
selectedFile=new File(home+ File.separator + fileName); |
|
104 |
} |
|
105 |
|
|
98 | 106 |
//If the file has not been updated, returns the same parameters |
99 | 107 |
if (this.storeParameters != null){ |
100 | 108 |
File previousFile = (File)storeParameters.getDynValue(getFileParameterName()); |
101 | 109 |
if (previousFile.equals(selectedFile)){ |
102 | 110 |
return storeParameters; |
103 | 111 |
} |
104 |
}
|
|
105 |
|
|
106 |
storeParameters =
|
|
107 |
(NewFeatureStoreParameters) explorer.getAddParameters(this.getStoreName());
|
|
112 |
} |
|
113 |
|
|
114 |
storeParameters = |
|
115 |
(NewFeatureStoreParameters) explorer.getAddParameters(this.getStoreName()); |
|
108 | 116 |
storeParameters.setDynValue( |
109 | 117 |
getFileParameterName(), selectedFile); |
110 | 118 |
return storeParameters; |
... | ... | |
122 | 130 |
throw new CantCreateExplorerException(e); |
123 | 131 |
} |
124 | 132 |
} |
125 |
|
|
133 |
|
|
126 | 134 |
public DataStoreParameters getOpenStoreParameters() { |
127 | 135 |
DataManager dataManager = DALLocator.getDataManager(); |
128 | 136 |
|
... | ... | |
131 | 139 |
String fileName = selectedFile.getName(); |
132 | 140 |
if (fileName.indexOf(".") < 0) { |
133 | 141 |
fileName = fileName + "." + this.getFileExtension(); |
134 |
selectedFile = new File(selectedFile.getParent() |
|
135 |
+ File.separator + fileName); |
|
136 | 142 |
} |
143 |
if (selectedFile.getParent()!=null){ |
|
144 |
selectedFile = new File(selectedFile.getParent() + File.separator + fileName); |
|
145 |
}else{ |
|
146 |
selectedFile = new File(fileName); |
|
147 |
} |
|
148 |
if (!selectedFile.isAbsolute()){ |
|
149 |
String home=System.getProperty("user.home"); |
|
150 |
selectedFile=new File(home+ File.separator + fileName); |
|
151 |
} |
|
137 | 152 |
|
138 | 153 |
DataStoreParameters storeParameters = (DataStoreParameters) dataManager |
139 | 154 |
.createStoreParameters(this.getStoreName()); |
... | ... | |
145 | 160 |
throw new CantCreateStoreParametersException(e); |
146 | 161 |
} |
147 | 162 |
} |
148 |
|
|
163 |
|
|
149 | 164 |
class CantCreateExplorerException extends BaseRuntimeException { |
150 | 165 |
private static final long serialVersionUID = -3487961532247258393L; |
151 | 166 |
private final static String MESSAGE_FORMAT = "Can't create explorer."; |
... | ... | |
155 | 170 |
super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID); |
156 | 171 |
} |
157 | 172 |
} |
158 |
|
|
173 |
|
|
159 | 174 |
class CantCreateStoreParametersException extends BaseRuntimeException { |
160 | 175 |
private static final long serialVersionUID = -3487961532247258393L; |
161 | 176 |
private final static String MESSAGE_FORMAT = "Can't create store parameters, provider not registered."; |
... | ... | |
165 | 180 |
super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID); |
166 | 181 |
} |
167 | 182 |
} |
168 |
|
|
183 |
|
|
169 | 184 |
class CantInitializeStoreParametersException extends BaseRuntimeException { |
170 | 185 |
private static final long serialVersionUID = -5263149018209261288L; |
171 | 186 |
private final static String MESSAGE_FORMAT = "Can't initialize store parameters."; |
Also available in: Unified diff