Revision 2125 org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/DefaultEditingContext.java
DefaultEditingContext.java | ||
---|---|---|
327 | 327 |
|
328 | 328 |
setActiveService(service); |
329 | 329 |
|
330 |
getNextParameter();
|
|
330 |
nextParameter();
|
|
331 | 331 |
} |
332 | 332 |
} |
333 | 333 |
} |
... | ... | |
775 | 775 |
return; |
776 | 776 |
} |
777 | 777 |
|
778 |
getNextParameter();
|
|
778 |
nextParameter();
|
|
779 | 779 |
} |
780 | 780 |
|
781 |
protected EditingService getActiveService() {
|
|
781 |
public EditingService getActiveService() {
|
|
782 | 782 |
if (!serviceStack.isEmpty()) { |
783 | 783 |
return serviceStack.peek(); |
784 | 784 |
} |
... | ... | |
848 | 848 |
return mapControlReference.get(); |
849 | 849 |
} |
850 | 850 |
|
851 |
protected void getNextParameter() { |
|
851 |
|
|
852 |
/*friend*/ void nextParameter() { |
|
852 | 853 |
if ((getMapControl().getCurrentTool() != null) |
853 | 854 |
&& !getMapControl().getCurrentTool().equals("VectorEditing")) { |
854 | 855 |
getMapControl().setTool("VectorEditing"); |
... | ... | |
1139 | 1140 |
refreshMenusAndToolBars(); |
1140 | 1141 |
activeService = getActiveService(); |
1141 | 1142 |
if (activeService != null) { |
1142 |
getNextParameter();
|
|
1143 |
nextParameter();
|
|
1143 | 1144 |
} else { |
1144 | 1145 |
cleanEditingContext(); |
1145 | 1146 |
} |
... | ... | |
1154 | 1155 |
} |
1155 | 1156 |
} else { |
1156 | 1157 |
|
1158 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
1157 | 1159 |
if (getCurrentParam() != null) { |
1158 |
Set<TYPE> types = getCurrentParam().getTypes(); |
|
1159 |
Point point = null; |
|
1160 |
Double value = null; |
|
1161 |
Point defaultPoint = null; |
|
1162 |
Object defaultValue = getCurrentParam().getDefaultValue(); |
|
1163 |
// int dimension = 2; |
|
1164 |
// if(defaultValue != null && defaultValue instanceof Point){ |
|
1165 |
// dimension = defaultPoint.getDimension(); |
|
1166 |
// } |
|
1160 |
try { |
|
1161 |
Object coercedValue = coerceInputParameter(getCurrentParam(), response); |
|
1162 |
activeService.setValue(coercedValue); |
|
1163 |
} catch (InvalidEntryException ex) { |
|
1164 |
showConsoleMessage("\n" |
|
1165 |
+ i18nManager.getTranslation("invalid_option")); |
|
1166 |
} |
|
1167 |
} |
|
1167 | 1168 |
|
1168 |
boolean insertedValue = false; |
|
1169 |
if ((!insertedValue && types.contains(TYPE.POSITION)) |
|
1169 |
nextParameter(); |
|
1170 |
} |
|
1171 |
} |
|
1172 |
|
|
1173 |
private Object coerceInputParameter(EditingServiceParameter parameter, String input) throws InvalidEntryException { |
|
1174 |
if (parameter != null) { |
|
1175 |
FeatureStore featureStore = getCurrentLayer().getFeatureStore(); |
|
1176 |
Set<TYPE> types = parameter.getTypes(); |
|
1177 |
Point point = null; |
|
1178 |
Double value = null; |
|
1179 |
Point defaultPoint = null; |
|
1180 |
Object defaultValue = parameter.getDefaultValue(); |
|
1181 |
|
|
1182 |
boolean insertedValue = false; |
|
1183 |
if ((!insertedValue && types.contains(TYPE.POSITION)) |
|
1170 | 1184 |
|| types.contains(TYPE.LIST_POSITIONS)) { |
1171 | 1185 |
|
1172 |
defaultPoint = (Point)defaultValue; |
|
1173 |
try { |
|
1174 |
if(StringUtils.isEmpty(response.replace("\n", ""))){ |
|
1175 |
point = defaultPoint; |
|
1176 |
} else { |
|
1177 |
point = parsePoint(response); |
|
1178 |
} |
|
1179 |
|
|
1180 |
if (point != null) { |
|
1181 |
activeService.setValue(point); |
|
1182 |
insertedValue = true; |
|
1183 |
} |
|
1184 |
|
|
1185 |
} catch (VectorEditingException e) { |
|
1186 |
// Do nothing to try other types |
|
1186 |
defaultPoint = (Point) defaultValue; |
|
1187 |
try { |
|
1188 |
if (StringUtils.isEmpty(input.replace("\n", ""))) { |
|
1189 |
point = defaultPoint; |
|
1190 |
} else { |
|
1191 |
point = parsePoint(input); |
|
1187 | 1192 |
} |
1188 |
} |
|
1189 |
if (!insertedValue && types.contains(TYPE.VALUE)) { |
|
1190 | 1193 |
|
1191 |
try { |
|
1192 |
|
|
1193 |
value = parseValue(response); |
|
1194 |
if (value != null) { |
|
1195 |
activeService.setValue(value); |
|
1196 |
insertedValue = true; |
|
1197 |
} |
|
1198 |
|
|
1199 |
} catch (VectorEditingException e) { |
|
1200 |
// Do nothing to try other types |
|
1194 |
if (point != null) { |
|
1195 |
return point; |
|
1201 | 1196 |
} |
1202 | 1197 |
|
1198 |
} catch (ParsePointException e) { |
|
1199 |
// Do nothing to try other types |
|
1203 | 1200 |
} |
1204 |
if (!insertedValue && types.contains(TYPE.OPTION)) { |
|
1201 |
} |
|
1202 |
if (types.contains(TYPE.VALUE)) { |
|
1205 | 1203 |
|
1206 |
try { |
|
1204 |
try { |
|
1205 |
value = parseValue(input); |
|
1206 |
if (value != null) { |
|
1207 |
return value; |
|
1208 |
} |
|
1207 | 1209 |
|
1208 |
response = response.replace("\n", ""); |
|
1209 |
if (response != null) { |
|
1210 |
activeService.setValue(response); |
|
1211 |
insertedValue = true; |
|
1212 |
} |
|
1213 |
|
|
1214 |
} catch (VectorEditingException e) { |
|
1215 |
// Do nothing to try other types |
|
1216 |
} |
|
1210 |
} catch (ParseValueException e) { |
|
1211 |
// Do nothing to try other types |
|
1217 | 1212 |
} |
1218 |
if (!insertedValue && types.contains(TYPE.SELECTION)) { |
|
1219 |
if (response.equalsIgnoreCase("\n")) { |
|
1220 |
enableSelection(false); |
|
1221 |
insertedValue = true; |
|
1222 | 1213 |
|
1223 |
try { |
|
1214 |
} |
|
1215 |
if (types.contains(TYPE.OPTION)) { |
|
1216 |
input = input.replace("\n", ""); |
|
1217 |
return input; |
|
1218 |
} |
|
1219 |
if (!insertedValue && types.contains(TYPE.SELECTION)) { |
|
1220 |
if (input.equalsIgnoreCase("\n")) { |
|
1221 |
enableSelection(false); |
|
1222 |
insertedValue = true; |
|
1224 | 1223 |
|
1225 |
FeatureSelection clonedSelection = (FeatureSelection)featureStore |
|
1224 |
FeatureSelection clonedSelection; |
|
1225 |
try { |
|
1226 |
clonedSelection = (FeatureSelection) featureStore |
|
1226 | 1227 |
.getFeatureSelection().clone(); |
1227 |
if(clonedSelection.isEmpty()){ |
|
1228 |
throw new InvalidEntryException(null); |
|
1229 |
} |
|
1230 |
activeService.setValue( |
|
1231 |
clonedSelection); |
|
1232 |
|
|
1233 |
} catch (InvalidEntryException e) { |
|
1234 |
I18nManager i18nManager = |
|
1235 |
ToolsLocator.getI18nManager(); |
|
1236 |
showConsoleMessage("\n" |
|
1237 |
+ i18nManager.getTranslation("invalid_option")); |
|
1238 |
} catch (Exception e) { |
|
1239 |
logger.info("Can't access to selection.", e); |
|
1240 |
cleanEditingContext(); |
|
1241 |
return; |
|
1228 |
if (clonedSelection.isEmpty()) { |
|
1229 |
throw new InvalidEntryException(null); |
|
1242 | 1230 |
} |
1231 |
} catch (InvalidEntryException e) { |
|
1232 |
throw e; |
|
1233 |
} catch (Exception e) { |
|
1234 |
logger.warn("Can't access to selection.", e); |
|
1235 |
throw new InvalidEntryException(e); |
|
1236 |
// cleanEditingContext(); |
|
1237 |
// return null; |
|
1243 | 1238 |
} |
1239 |
|
|
1240 |
return clonedSelection; |
|
1244 | 1241 |
} |
1245 |
if (!insertedValue) { |
|
1246 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
1247 |
showConsoleMessage("\n" |
|
1248 |
+ i18nManager.getTranslation("invalid_option")); |
|
1249 |
} |
|
1250 |
getNextParameter(); |
|
1251 | 1242 |
} |
1252 | 1243 |
} |
1244 |
return null; |
|
1253 | 1245 |
} |
1254 | 1246 |
|
1255 | 1247 |
@Override |
... | ... | |
1267 | 1259 |
public Behavior[] getDefaultBehaviors() { |
1268 | 1260 |
return this.defaultBehaviors; |
1269 | 1261 |
} |
1262 |
|
|
1263 |
@Override |
|
1264 |
public void setValue(EditingServiceParameter parameter, String value) throws InvalidEntryException { |
|
1265 |
Object obj = coerceInputParameter(parameter, value); |
|
1266 |
getActiveService().setValue(parameter, obj); |
|
1267 |
nextParameter(); |
|
1268 |
} |
|
1269 |
|
|
1270 |
|
|
1270 | 1271 |
} |
Also available in: Unified diff