kopia lustrzana https://github.com/JOSM/MapWithAI
Add a cap on the number of objects can be added with MapWithAI before an upload is required (message is shown)
Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
e24709a279
commit
f96693e05a
|
@ -79,7 +79,7 @@ public class DataAvailability {
|
|||
false, entry.getValue().asJsonObject().getJsonArray("parameters").toString());
|
||||
MapWithAIPreferenceHelper.setMapWithAIUrl(url, false, true);
|
||||
}
|
||||
Logging.error("{0}: {1}", entry.getKey(), entry.getValue());
|
||||
Logging.debug("{0}: {1}", entry.getKey(), entry.getValue());
|
||||
if (JsonValue.ValueType.OBJECT.equals(entry.getValue().getValueType())
|
||||
&& entry.getValue().asJsonObject().containsKey("countries")) {
|
||||
JsonValue countries = entry.getValue().asJsonObject().get("countries");
|
||||
|
|
|
@ -32,6 +32,9 @@ public class MapWithAIMoveAction extends JosmAction {
|
|||
private static final long serialVersionUID = 319374598;
|
||||
private transient Notification lastNotification;
|
||||
|
||||
/** The maximum number of objects is this times the maximum add */
|
||||
public static final int MAX_ADD_MULTIPLIER = 10;
|
||||
|
||||
public MapWithAIMoveAction() {
|
||||
super(tr("{0}: Add selected data", MapWithAIPlugin.NAME), "mapwithai",
|
||||
tr("Add data from {0}", MapWithAIPlugin.NAME), obtainShortcut(), true);
|
||||
|
@ -71,16 +74,29 @@ public class MapWithAIMoveAction extends JosmAction {
|
|||
}
|
||||
final Collection<OsmPrimitive> selected = limitCollection(ds, maxAddition);
|
||||
final OsmDataLayer editLayer = getOsmDataLayer();
|
||||
if (editLayer != null && !selected.isEmpty()) {
|
||||
if (editLayer != null && !selected.isEmpty()
|
||||
&& MapWithAIDataUtils.getAddedObjects() < maxAddition * MAX_ADD_MULTIPLIER) {
|
||||
final MapWithAIAddCommand command = new MapWithAIAddCommand(mapWithAI, editLayer, selected);
|
||||
UndoRedoHandler.getInstance().add(command);
|
||||
if (MapWithAIPreferenceHelper.isSwitchLayers()) {
|
||||
MainApplication.getLayerManager().setActiveLayer(editLayer);
|
||||
}
|
||||
} else if (MapWithAIDataUtils.getAddedObjects() >= maxAddition * MAX_ADD_MULTIPLIER) {
|
||||
createTooManyAdditionsNotification(maxAddition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createTooManyAdditionsNotification(int maxAddition) {
|
||||
Notification tooMany = new Notification();
|
||||
tooMany.setIcon(JOptionPane.WARNING_MESSAGE);
|
||||
tooMany.setDuration(Notification.TIME_DEFAULT);
|
||||
tooMany.setContent(
|
||||
tr("There is a soft cap of {0} objects before uploading. Please verify everything before uploading.",
|
||||
maxAddition * MAX_ADD_MULTIPLIER));
|
||||
tooMany.show();
|
||||
}
|
||||
|
||||
private static Collection<OsmPrimitive> limitCollection(DataSet ds, int maxSize) {
|
||||
return (maxSize > 0 || !ExpertToggleAction.isExpert())
|
||||
? ds.getSelected().stream().limit(maxSize).collect(Collectors.toList())
|
||||
|
|
Ładowanie…
Reference in New Issue