Add dialog for when someone tries to add too many objects

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head v0.1.10
Taylor Smock 2019-10-31 16:09:22 -06:00
rodzic f0898f5a5d
commit d62089662c
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
1 zmienionych plików z 35 dodań i 15 usunięć

Wyświetl plik

@ -8,12 +8,15 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.swing.JOptionPane;
import org.openstreetmap.josm.actions.JosmAction; import org.openstreetmap.josm.actions.JosmAction;
import org.openstreetmap.josm.data.UndoRedoHandler; import org.openstreetmap.josm.data.UndoRedoHandler;
import org.openstreetmap.josm.data.osm.DataSet; import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.data.osm.Node; import org.openstreetmap.josm.data.osm.Node;
import org.openstreetmap.josm.data.osm.OsmPrimitive; import org.openstreetmap.josm.data.osm.OsmPrimitive;
import org.openstreetmap.josm.gui.MainApplication; import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.Notification;
import org.openstreetmap.josm.gui.layer.Layer; import org.openstreetmap.josm.gui.layer.Layer;
import org.openstreetmap.josm.gui.layer.OsmDataLayer; import org.openstreetmap.josm.gui.layer.OsmDataLayer;
import org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin; import org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin;
@ -44,26 +47,43 @@ public class MapWithAIMoveAction extends JosmAction {
.collect(Collectors.toList()); .collect(Collectors.toList());
ds.clearSelection(nodes); ds.clearSelection(nodes);
nodes.stream().map(Node::getReferrers).forEach(ds::addSelected); nodes.stream().map(Node::getReferrers).forEach(ds::addSelected);
if (ds.getSelected().size() > maxAddition) {
createMaxAddedDialog(maxAddition, ds.getSelected().size());
}
final Collection<OsmPrimitive> selected = maxAddition > 0 final Collection<OsmPrimitive> selected = maxAddition > 0
? ds.getSelected().stream().limit(maxAddition).collect(Collectors.toList()) ? ds.getSelected().stream().limit(maxAddition).collect(Collectors.toList())
: ds.getSelected(); : ds.getSelected();
for (final OsmDataLayer osmLayer : osmLayers) { for (final OsmDataLayer osmLayer : osmLayers) {
if (!osmLayer.isLocked() && osmLayer.isVisible() && osmLayer.isUploadable() if (!osmLayer.isLocked() && osmLayer.isVisible() && osmLayer.isUploadable()
&& osmLayer.getClass().equals(OsmDataLayer.class)) { && osmLayer.getClass().equals(OsmDataLayer.class)) {
editLayer = osmLayer; editLayer = osmLayer;
break; break;
} }
} }
if (editLayer != null) { if (editLayer != null) {
final MapWithAIAddCommand command = new MapWithAIAddCommand(mapWithAI, editLayer, selected); final MapWithAIAddCommand command = new MapWithAIAddCommand(mapWithAI, editLayer, selected);
UndoRedoHandler.getInstance().add(command); UndoRedoHandler.getInstance().add(command);
if (MapWithAIPreferenceHelper.isSwitchLayers()) { if (MapWithAIPreferenceHelper.isSwitchLayers()) {
MainApplication.getLayerManager().setActiveLayer(editLayer); MainApplication.getLayerManager().setActiveLayer(editLayer);
} }
} }
} }
} }
private void createMaxAddedDialog(int maxAddition, int triedToAdd) {
final Notification notification = new Notification();
final StringBuilder message = new StringBuilder();
message.append(MapWithAIPlugin.NAME);
message.append(": ");
message.append(tr("maximum additions per action are ")).append(maxAddition).append(", ");
message.append(tr("tried to add ")).append(triedToAdd).append(".");
notification.setContent(message.toString());
notification.setDuration(Notification.TIME_LONG);
notification.setIcon(JOptionPane.INFORMATION_MESSAGE);
notification.show();
}
@Override @Override
protected void updateEnabledState() { protected void updateEnabledState() {
setEnabled(checkIfActionEnabled()); setEnabled(checkIfActionEnabled());