1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package reverter;
|
---|
3 |
|
---|
4 | import java.util.Map;
|
---|
5 | import java.util.Objects;
|
---|
6 |
|
---|
7 | import org.openstreetmap.josm.actions.upload.UploadHook;
|
---|
8 | import org.openstreetmap.josm.command.Command;
|
---|
9 | import org.openstreetmap.josm.command.SequenceCommand;
|
---|
10 | import org.openstreetmap.josm.data.UndoRedoHandler;
|
---|
11 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
12 | import org.openstreetmap.josm.plugins.PluginInformation;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * Upload hook to add tag to new changeset.
|
---|
16 | *
|
---|
17 | */
|
---|
18 | public class ReverterUploadHook implements UploadHook {
|
---|
19 | final String pluginString;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Create new {@link ReverterUploadHook}
|
---|
23 | * @param info plugin information
|
---|
24 | */
|
---|
25 | public ReverterUploadHook(PluginInformation info) {
|
---|
26 | pluginString = "reverter_plugin/" + info.version;
|
---|
27 | }
|
---|
28 |
|
---|
29 | @Override
|
---|
30 | public void modifyChangesetTags(Map<String, String> tags) {
|
---|
31 | if (ReverterPlugin.reverterUsed.get()) {
|
---|
32 | for (Command cmd : UndoRedoHandler.getInstance().getUndoCommands()) {
|
---|
33 | if (Objects.equals(MainApplication.getLayerManager().getEditDataSet(), cmd.getAffectedDataSet()) && isReverterCmd(cmd)) {
|
---|
34 | tags.put("created_by", pluginString);
|
---|
35 | break;
|
---|
36 | }
|
---|
37 | }
|
---|
38 | }
|
---|
39 | }
|
---|
40 |
|
---|
41 | private static boolean isReverterCmd(Command cmd) {
|
---|
42 | if (cmd instanceof RevertChangesetCommand)
|
---|
43 | return true;
|
---|
44 | if (cmd instanceof SequenceCommand) {
|
---|
45 | return ((SequenceCommand) cmd).getLastCommand() instanceof RevertChangesetCommand;
|
---|
46 | }
|
---|
47 | return false;
|
---|
48 | }
|
---|
49 | }
|
---|