Changeset 31853 in osm for applications/editors/josm/plugins
- Timestamp:
- 2015-12-22T21:46:48+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/FetchWikidataAction.java
r31852 r31853 13 13 import java.util.Set; 14 14 15 import javax.swing.JOptionPane; 16 15 17 import org.openstreetmap.josm.Main; 16 18 import org.openstreetmap.josm.actions.JosmAction; … … 19 21 import org.openstreetmap.josm.command.SequenceCommand; 20 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 23 import org.openstreetmap.josm.gui.Notification; 21 24 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 22 25 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 23 26 import org.openstreetmap.josm.tools.MultiMap; 27 import org.openstreetmap.josm.tools.Utils; 24 28 25 29 public class FetchWikidataAction extends JosmAction { … … 41 45 private final Collection<? extends OsmPrimitive> selection; 42 46 private boolean canceled = false; 43 private List<Command> commands; 47 private final List<Command> commands = new ArrayList<>(); 48 private final Collection<WikipediaApp.WikipediaLangArticle> notFound = new ArrayList<>(); 44 49 45 50 public Fetcher(Collection<? extends OsmPrimitive> selection) { … … 56 61 protected void realRun() { 57 62 final Map<String, PrimitivesWithWikipedia> wikipediaByLanguage = getLanguageToArticlesMap(selection); 58 commands = new ArrayList<>(wikipediaByLanguage.keySet().size());59 63 getProgressMonitor().setTicksCount(wikipediaByLanguage.keySet().size()); 60 64 for (final Map.Entry<String, PrimitivesWithWikipedia> i : wikipediaByLanguage.entrySet()) { … … 62 66 break; 63 67 } 64 final Command command = i.getValue().updateWikidataIds(getProgressMonitor().createSubTaskMonitor(1, false)); 68 final PrimitivesWithWikipedia fetcher = i.getValue(); 69 fetcher.updateWikidataIds(getProgressMonitor().createSubTaskMonitor(1, false)); 70 final Command command = fetcher.getCommand(); 65 71 if (command != null) { 66 72 commands.add(command); 67 73 } 74 notFound.addAll(fetcher.getNotFound()); 68 75 } 69 76 } … … 88 95 Main.main.undoRedo.add(commands.size() == 1 ? commands.get(0) : new SequenceCommand(tr("Add Wikidata"), commands)); 89 96 } 97 if (!canceled && !notFound.isEmpty()) { 98 new Notification(tr("No Wikidata ID found for: {0}", Utils.joinAsHtmlUnorderedList(notFound))) 99 .setIcon(JOptionPane.WARNING_MESSAGE) 100 .setDuration(Notification.TIME_LONG) 101 .show(); 102 } 90 103 } 91 104 } … … 94 107 final String lang; 95 108 final MultiMap<String, OsmPrimitive> byArticle = new MultiMap<>(); 109 final List<Command> commands = new ArrayList<>(); 110 final List<WikipediaApp.WikipediaLangArticle> notFound = new ArrayList<>(); 96 111 97 112 public PrimitivesWithWikipedia(String lang) { … … 103 118 } 104 119 105 protected Command updateWikidataIds(ProgressMonitor monitor) {120 protected void updateWikidataIds(ProgressMonitor monitor) { 106 121 final int size = byArticle.keySet().size(); 107 122 monitor.beginTask(trn( 108 123 "Fetching {0} Wikidata ID for language ''{1}''", 109 124 "Fetching {0} Wikidata IDs for language ''{1}''", size, size, lang)); 110 final List<Command> commands = new ArrayList<>(size);111 125 final Map<String, String> wikidataByWikipedia = WikipediaApp.getWikidataForArticles(lang, byArticle.keySet()); 112 126 for (Map.Entry<String, Set<OsmPrimitive>> i : byArticle.entrySet()) { … … 116 130 commands.add(new ChangePropertyCommand(i.getValue(), "wikidata", wikidata)); 117 131 } else { 118 Main.warn(tr("No Wikidata ID found for {0}", lang + ":" + wikipedia)); 132 final WikipediaApp.WikipediaLangArticle article = new WikipediaApp.WikipediaLangArticle(lang, wikipedia); 133 Main.warn(tr("No Wikidata ID found for: {0}", article)); 134 notFound.add(article); 119 135 } 120 136 } 121 137 monitor.finishTask(); 138 } 139 140 public Command getCommand() { 122 141 return commands.isEmpty() 123 142 ? null 124 143 : new SequenceCommand(tr("Add Wikidata for language ''{0}''", lang), commands); 144 } 145 146 public List<WikipediaApp.WikipediaLangArticle> getNotFound() { 147 return notFound; 125 148 } 126 149 }
Note:
See TracChangeset
for help on using the changeset viewer.