Changeset 1860 in josm for trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
- Timestamp:
- 2009-07-27T18:36:17+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r1837 r1860 34 34 import org.openstreetmap.josm.gui.ExtendedDialog; 35 35 import org.openstreetmap.josm.gui.MapFrame; 36 import org.openstreetmap.josm.gui.OptionPaneUtil; 36 37 import org.openstreetmap.josm.gui.download.DownloadSelection; 37 38 import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory; … … 51 52 List<String> plugins = new LinkedList<String>(); 52 53 Collection<String> cp = Main.pref.getCollection("plugins", null); 53 if (cp != null) 54 if (cp != null) { 54 55 plugins.addAll(cp); 55 if (System.getProperty("josm.plugins") != null) 56 } 57 if (System.getProperty("josm.plugins") != null) { 56 58 plugins.addAll(Arrays.asList(System.getProperty("josm.plugins").split(","))); 59 } 57 60 58 61 String [] oldplugins = new String[] {"mappaint", "unglueplugin", 59 "lang-de", "lang-en_GB", "lang-fr", "lang-it", "lang-pl", "lang-ro",60 "lang-ru", "ewmsplugin", "ywms", "tways-0.2", "geotagged", "landsat",61 "namefinder", "waypoints", "slippy_map_chooser", "tcx-support"};62 "lang-de", "lang-en_GB", "lang-fr", "lang-it", "lang-pl", "lang-ro", 63 "lang-ru", "ewmsplugin", "ywms", "tways-0.2", "geotagged", "landsat", 64 "namefinder", "waypoints", "slippy_map_chooser", "tcx-support"}; 62 65 for (String p : oldplugins) { 63 66 if (plugins.contains(p)) { 64 67 plugins.remove(p); 65 68 Main.pref.removeFromCollection("plugins", p); 66 JOptionPane.showMessageDialog(Main.parent, tr("Warning - loading of {0} plugin was requested. This plugin is no longer required.", p)); 69 OptionPaneUtil.showMessageDialog( 70 Main.parent, 71 tr("Loading of {0} plugin was requested. This plugin is no longer required.", p), 72 tr("Warning"), 73 JOptionPane.WARNING_MESSAGE 74 ); 67 75 } 68 76 } … … 75 83 PluginInformation info = PluginInformation.findPlugin(pluginName); 76 84 if (info != null) { 77 if (info.early != early) 85 if (info.early != early) { 78 86 continue; 87 } 79 88 if (info.mainversion > AboutAction.getVersionNumber()) { 80 JOptionPane.showMessageDialog(Main.parent, tr("Plugin {0} requires JOSM update to version {1}.", pluginName, 81 info.mainversion)); 89 OptionPaneUtil.showMessageDialog( 90 Main.parent, 91 tr("Plugin {0} requires JOSM update to version {1}.", pluginName, 92 info.mainversion), 93 tr("Warning"), 94 JOptionPane.WARNING_MESSAGE 95 ); 82 96 continue; 83 97 } … … 92 106 if(warn != null) 93 107 { 94 JOptionPane.showMessageDialog(Main.parent, 95 tr("Plugin {0} is required by plugin {1} but was not found.", 96 warn, pluginName)); 108 OptionPaneUtil.showMessageDialog(Main.parent, 109 tr("Plugin {0} is required by plugin {1} but was not found.", 110 warn, pluginName), 111 tr("Error"), 112 JOptionPane.ERROR_MESSAGE 113 ); 97 114 continue; 98 115 } 99 116 } 100 if (!p.containsKey(info.stage)) 117 if (!p.containsKey(info.stage)) { 101 118 p.put(info.stage, new LinkedList<PluginInformation>()); 119 } 102 120 p.get(info.stage).add(info); 103 121 } else if(early) { 104 JOptionPane.showMessageDialog(Main.parent, tr("Plugin not found: {0}.", pluginName)); 122 OptionPaneUtil.showMessageDialog( 123 Main.parent, 124 tr("Plugin not found: {0}.", pluginName), 125 tr("Error"), 126 JOptionPane.ERROR_MESSAGE 127 ); 105 128 } 106 129 } … … 114 137 Main.pref.put("pluginmanager.lastupdate",Long.toString(tim)); 115 138 } else if (d > maxTime) { 116 JOptionPane.showMessageDialog(Main.parent, 117 "<html>" + 118 tr("Last plugin update more than {0} days ago.", d) + 119 "<br><em>" + 120 tr("(You can change the number of days after which this warning appears<br>by setting the config option 'pluginmanager.warntime'.)") + 121 "</html>"); 139 OptionPaneUtil.showMessageDialog(Main.parent, 140 "<html>" + 141 tr("Last plugin update more than {0} days ago.", d) + 142 "<br><em>" + 143 tr("(You can change the number of days after which this warning appears<br>by setting the config option 'pluginmanager.warntime'.)") + 144 "</html>", 145 tr("Warning"), 146 JOptionPane.WARNING_MESSAGE 147 ); 122 148 } 123 149 } … … 125 151 // iterate all plugins and collect all libraries of all plugins: 126 152 List<URL> allPluginLibraries = new ArrayList<URL>(); 127 for (Collection<PluginInformation> c : p.values()) 128 for (PluginInformation info : c) 153 for (Collection<PluginInformation> c : p.values()) { 154 for (PluginInformation info : c) { 129 155 allPluginLibraries.addAll(info.libraries); 156 } 157 } 130 158 // create a classloader for all plugins: 131 159 URL[] jarUrls = new URL[allPluginLibraries.size()]; … … 146 174 147 175 int result = new ExtendedDialog(Main.parent, 148 tr("Disable plugin"),149 tr("Could not load plugin {0}. Delete from preferences?", info.name),150 new String[] {tr("Disable plugin"), tr("Keep plugin")},151 new String[] {"dialogs/delete.png", "cancel.png"}).getValue();176 tr("Disable plugin"), 177 tr("Could not load plugin {0}. Delete from preferences?", info.name), 178 new String[] {tr("Disable plugin"), tr("Keep plugin")}, 179 new String[] {"dialogs/delete.png", "cancel.png"}).getValue(); 152 180 153 181 if(result == 1) … … 161 189 } 162 190 public static void setMapFrame(MapFrame old, MapFrame map) { 163 for (PluginProxy plugin : pluginList) 191 for (PluginProxy plugin : pluginList) { 164 192 plugin.mapFrameInitialized(old, map); 193 } 165 194 } 166 195 … … 174 203 public static void addDownloadSelection(List<DownloadSelection> downloadSelections) 175 204 { 176 for (PluginProxy p : pluginList) 205 for (PluginProxy p : pluginList) { 177 206 p.addDownloadSelection(downloadSelections); 207 } 178 208 } 179 209 public static void getPreferenceSetting(Collection<PreferenceSettingFactory> settings) … … 187 217 { 188 218 if (!PluginDownloader.moveUpdatedPlugins()) { 189 JOptionPane.showMessageDialog(null, 219 OptionPaneUtil.showMessageDialog( 220 Main.parent, 190 221 tr("Activating the updated plugins failed. Check if JOSM has the permission to overwrite the existing ones."), 191 222 tr("Plugins"), JOptionPane.ERROR_MESSAGE); … … 197 228 198 229 // Check for an explicit problem when calling a plugin function 199 if (e instanceof PluginException) 230 if (e instanceof PluginException) { 200 231 plugin = ((PluginException)e).plugin; 232 } 201 233 202 234 if (plugin == null) … … 204 236 String name = null; 205 237 /** 206 * Analyze the stack of the argument and find a name of a plugin, if207 * some known problem pattern has been found.208 *209 * Note: This heuristic is not meant as discrimination against specific210 * plugins, but only to stop the flood of similar bug reports about plugins.211 * Of course, plugin writers are free to install their own version of212 * an exception handler with their email address listed to receive213 * bug reports ;-).214 */238 * Analyze the stack of the argument and find a name of a plugin, if 239 * some known problem pattern has been found. 240 * 241 * Note: This heuristic is not meant as discrimination against specific 242 * plugins, but only to stop the flood of similar bug reports about plugins. 243 * Of course, plugin writers are free to install their own version of 244 * an exception handler with their email address listed to receive 245 * bug reports ;-). 246 */ 215 247 for (StackTraceElement element : e.getStackTrace()) { 216 248 String c = element.getClassName(); 217 249 218 if (c.contains("wmsplugin.") || c.contains(".WMSLayer")) 250 if (c.contains("wmsplugin.") || c.contains(".WMSLayer")) { 219 251 name = "wmsplugin"; 220 if (c.contains("livegps.")) 252 } 253 if (c.contains("livegps.")) { 221 254 name = "livegps"; 222 if (c.startsWith("UtilsPlugin.")) 255 } 256 if (c.startsWith("UtilsPlugin.")) { 223 257 name = "UtilsPlugin"; 258 } 224 259 225 260 if (c.startsWith("org.openstreetmap.josm.plugins.")) { … … 229 264 } 230 265 } 231 if(name != null) 232 break; 266 if(name != null) { 267 break; 268 } 233 269 } 234 270 for (PluginProxy p : pluginList) … … 244 280 if (plugin != null) { 245 281 int answer = new ExtendedDialog(Main.parent, 246 tr("Disable plugin"),247 tr("An unexpected exception occurred that may have come from the ''{0}'' plugin.", plugin.info.name)282 tr("Disable plugin"), 283 tr("An unexpected exception occurred that may have come from the ''{0}'' plugin.", plugin.info.name) 248 284 + "\n" 249 285 + (plugin.info.author != null 250 ? tr("According to the information within the plugin, the author is {0}.", plugin.info.author)251 : "")252 + "\n"253 + tr("Try updating to the newest version of this plugin before reporting a bug.")254 + "\n"255 + tr("Should the plugin be disabled?"),256 new String[] {tr("Disable plugin"), tr("Cancel")},257 new String[] {"dialogs/delete.png", "cancel.png"}).getValue();286 ? tr("According to the information within the plugin, the author is {0}.", plugin.info.author) 287 : "") 288 + "\n" 289 + tr("Try updating to the newest version of this plugin before reporting a bug.") 290 + "\n" 291 + tr("Should the plugin be disabled?"), 292 new String[] {tr("Disable plugin"), tr("Cancel")}, 293 new String[] {"dialogs/delete.png", "cancel.png"}).getValue(); 258 294 if (answer == 1) { 259 295 List<String> plugins = new ArrayList<String>(Main.pref.getCollection("plugins", Collections.<String>emptyList())); … … 261 297 while (plugins.remove(plugin.info.name)) {} 262 298 Main.pref.putCollection("plugins", plugins); 263 JOptionPane.showMessageDialog(Main.parent, 264 tr("The plugin has been removed from the configuration. Please restart JOSM to unload the plugin.")); 299 OptionPaneUtil.showMessageDialog(Main.parent, 300 tr("The plugin has been removed from the configuration. Please restart JOSM to unload the plugin."), 301 tr("Information"), 302 JOptionPane.INFORMATION_MESSAGE); 265 303 } else { 266 JOptionPane.showMessageDialog(Main.parent, 267 tr("The plugin could not be removed. Probably it was already disabled")); 304 OptionPaneUtil.showMessageDialog( 305 Main.parent, 306 tr("The plugin could not be removed. Probably it was already disabled"), 307 tr("Error"), 308 JOptionPane.ERROR_MESSAGE 309 ); 268 310 } 269 311 return true; … … 276 318 String text = ""; 277 319 String pl = Main.pref.get("plugins"); 278 if(pl != null && pl.length() != 0) 320 if(pl != null && pl.length() != 0) { 279 321 text += "Plugins: "+pl+"\n"; 322 } 280 323 for (final PluginProxy pp : pluginList) { 281 324 text += "Plugin " + pp.info.name + (pp.info.version != null && !pp.info.version.equals("") ? " Version: "+pp.info.version+"\n" : "\n"); … … 302 345 a.setEditable(false); 303 346 a.setText(b.toString()); 304 JOptionPane.showMessageDialog(Main.parent, new JScrollPane(a)); 347 OptionPaneUtil.showMessageDialog( 348 Main.parent, 349 new JScrollPane(a), 350 tr("Plugin information"), 351 JOptionPane.INFORMATION_MESSAGE 352 ); 305 353 } 306 354 }), GBC.eol());
Note:
See TracChangeset
for help on using the changeset viewer.