Ticket #13010: patch-plugins-import-list.patch
File patch-plugins-import-list.patch, 8.6 KB (added by , 9 years ago) |
---|
-
src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java
diff --git a/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java b/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java index 41f0494..fda427c 100644
a b import javax.swing.AbstractAction; 27 27 import javax.swing.BorderFactory; 28 28 import javax.swing.DefaultListModel; 29 29 import javax.swing.JButton; 30 import javax.swing.JCheckBox; 30 31 import javax.swing.JLabel; 31 32 import javax.swing.JList; 32 33 import javax.swing.JOptionPane; 33 34 import javax.swing.JPanel; 34 35 import javax.swing.JScrollPane; 35 36 import javax.swing.JTabbedPane; 37 import javax.swing.JTextArea; 36 38 import javax.swing.SwingUtilities; 37 39 import javax.swing.UIManager; 38 40 import javax.swing.event.DocumentEvent; … … import org.openstreetmap.josm.plugins.ReadLocalPluginInformationTask; 57 59 import org.openstreetmap.josm.plugins.ReadRemotePluginInformationTask; 58 60 import org.openstreetmap.josm.tools.GBC; 59 61 import org.openstreetmap.josm.tools.ImageProvider; 62 import org.openstreetmap.josm.tools.Utils; 60 63 61 64 /** 62 65 * Preference settings for plugins. … … public final class PluginPreference extends DefaultTabPreferenceSetting { 107 110 downloaded.size() 108 111 )); 109 112 sb.append("<ul>"); 110 for (PluginInformation pi : downloaded) {113 for (PluginInformation pi : downloaded) { 111 114 sb.append("<li>").append(pi.name).append(" (").append(pi.version).append(")</li>"); 112 115 } 113 116 sb.append("</ul>"); … … public final class PluginPreference extends DefaultTabPreferenceSetting { 120 123 failed.size() 121 124 )); 122 125 sb.append("<ul>"); 123 for (PluginInformation pi : failed) {126 for (PluginInformation pi : failed) { 124 127 sb.append("<li>").append(pi.name).append("</li>"); 125 128 } 126 129 sb.append("</ul>"); … … public final class PluginPreference extends DefaultTabPreferenceSetting { 142 145 public static void notifyDownloadResults(final Component parent, PluginDownloadTask task, boolean restartRequired) { 143 146 final Collection<PluginInformation> failed = task.getFailedPlugins(); 144 147 final StringBuilder sb = new StringBuilder(); 145 sb.append("<html>") 146 148 sb.append("<html>"); 149 sb.append(buildDownloadSummary(task)); 147 150 if (restartRequired) { 148 151 sb.append(tr("Please restart JOSM to activate the downloaded plugins.")); 149 152 } … … public final class PluginPreference extends DefaultTabPreferenceSetting { 157 160 sb.toString(), 158 161 tr("Update plugins"), 159 162 !failed.isEmpty() ? JOptionPane.WARNING_MESSAGE : JOptionPane.INFORMATION_MESSAGE, 160 163 HelpUtil.ht("/Preferences/Plugins") 161 164 ); 162 165 } 163 166 }); … … public final class PluginPreference extends DefaultTabPreferenceSetting { 191 194 pnl.add(new JButton(new DownloadAvailablePluginsAction())); 192 195 pnl.add(new JButton(new UpdateSelectedPluginsAction())); 193 196 pnl.add(new JButton(new ConfigureSitesAction())); 197 pnl.add(new JButton(new SelectByListAction())); 194 198 return pnl; 195 199 } 196 200 … … public final class PluginPreference extends DefaultTabPreferenceSetting { 211 215 public void componentHidden(ComponentEvent e) { 212 216 spPluginPreferences.setBorder(null); 213 217 } 214 } 215 ); 218 }); 216 219 217 220 pnl.add(spPluginPreferences, BorderLayout.CENTER); 218 221 pnl.add(buildActionPanel(), BorderLayout.SOUTH); … … public final class PluginPreference extends DefaultTabPreferenceSetting { 248 251 tr("Accept the new plugin sites and close the dialog"), 249 252 null /* no special help topic */ 250 253 ), 251 252 253 254 255 256 254 new ButtonSpec( 255 tr("Cancel"), 256 ImageProvider.get("cancel"), 257 tr("Close the dialog"), 258 null /* no special help topic */ 259 ) 257 260 }; 258 261 PluginConfigurationSitesPanel pnl = new PluginConfigurationSitesPanel(); 259 262 … … public final class PluginPreference extends DefaultTabPreferenceSetting { 476 479 } 477 480 } 478 481 479 480 482 /** 481 483 * The action for configuring the plugin download sites 482 484 * … … public final class PluginPreference extends DefaultTabPreferenceSetting { 495 497 } 496 498 497 499 /** 500 * The action for selecting the plugins given by a text file compatible to JOSM bug report. 501 */ 502 class SelectByListAction extends AbstractAction { 503 SelectByListAction() { 504 putValue(NAME, tr("Load from list...")); 505 putValue(SHORT_DESCRIPTION, tr("Load plugins from a list of plugins")); 506 //TODO: Icon putValue(SMALL_ICON, ImageProvider.get("dialogs", "")); 507 } 508 509 @Override 510 public void actionPerformed(ActionEvent e) { 511 JTextArea textField = new JTextArea(10, 0); 512 JCheckBox deleteNotInList = new JCheckBox(tr("Disable all other plugins")); 513 514 JLabel helpLabel = new JLabel(tr("<html>Enter a list of plugins you want to download." 515 + "<br/>You should add one plugin id per line, version information is ignored." 516 + "<br/>You can copy+paste the list of a status report here.</html>")); 517 int result = JOptionPane.showConfirmDialog( 518 GuiHelper.getFrameForComponent(getTabPane()), 519 new Object[] { helpLabel, new JScrollPane(textField), deleteNotInList }, 520 tr("Load plugins from list"), 521 JOptionPane.OK_CANCEL_OPTION, 522 JOptionPane.PLAIN_MESSAGE); 523 524 if (result == JOptionPane.OK_OPTION) { 525 activatePlugins(textField, deleteNotInList.isSelected()); 526 } 527 } 528 529 private void activatePlugins(JTextArea textField, boolean deleteNotInList) { 530 String[] lines = textField.getText().split("\n"); 531 ArrayList<String> toActivate = new ArrayList<>(); 532 ArrayList<String> notFound = new ArrayList<>(); 533 for (String line : lines) { 534 String name = line.replaceAll("^[-\\s]*|\\s[\\(\\)\\d\\s]*", ""); 535 if (name.isEmpty()) { 536 continue; 537 } 538 PluginInformation plugin = model.getPluginInformation(name); 539 if (plugin == null) { 540 notFound.add(name); 541 } else { 542 toActivate.add(name); 543 } 544 } 545 546 if (notFound.isEmpty() || confirmIgnoreNotFound(notFound)) { 547 activatePlugins(toActivate, deleteNotInList); 548 } 549 } 550 551 private void activatePlugins(ArrayList<String> toActivate, boolean deleteNotInList) { 552 if (deleteNotInList) { 553 for (String name : model.getSelectedPluginNames()) { 554 if (!toActivate.contains(name)) { 555 model.setPluginSelected(name, false); 556 } 557 } 558 } 559 for (String name : toActivate) { 560 model.setPluginSelected(name, true); 561 } 562 pnlPluginPreferences.refreshView(); 563 } 564 565 private boolean confirmIgnoreNotFound(ArrayList<String> notFound) { 566 String list = "<ul><li>" + Utils.join("</li><li>", notFound) + "</li></ul>"; 567 String message = "<html>" + tr("The following plugins were not found. Continue anyway?") + list + "</html>"; 568 return JOptionPane.showConfirmDialog(GuiHelper.getFrameForComponent(getTabPane()), message) == JOptionPane.OK_OPTION; 569 } 570 } 571 572 /** 498 573 * Applies the current filter condition in the filter text field to the model. 499 574 */ 500 575 class SearchFieldAdapter implements DocumentListener {