Changeset 1647 in josm for trunk/src


Ignore:
Timestamp:
2009-06-07T02:56:33+02:00 (15 years ago)
Author:
stoecker
Message:

fixed plugin handling a bit

Location:
trunk/src/org/openstreetmap/josm
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/PreferencesAction.java

    r1212 r1647  
    2323 * @author imi
    2424 */
    25 public class PreferencesAction extends JosmAction {
     25public class PreferencesAction extends JosmAction implements Runnable {
    2626
    2727    /**
     
    3737     */
    3838    public void actionPerformed(ActionEvent e) {
     39        new Thread(this).start();
     40    }
     41
     42    public void run() {
    3943        PreferenceDialog prefDlg = new PreferenceDialog();
    4044        prefDlg.setMinimumSize(new Dimension(400,300));
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java

    r1465 r1647  
    3939        private int num = 1;
    4040        private String msg = "";
    41        
     41
    4242        public Task(boolean newLayer, OsmServerReader reader, boolean silent,
    4343                int numLayers, String msg) {
     
    6565                dataSet.dataSources.add(new DataSource(currentBounds, "OpenStreetMap server"));
    6666            }
    67            
     67
    6868            OsmDataLayer layer = new OsmDataLayer(dataSet, tr("Data Layer {0}", num), null);
    6969            if (newLayer)
     
    7171            else
    7272                Main.main.editLayer().mergeFrom(layer);
    73            
     73
    7474            Main.pleaseWaitDlg.setCustomText("");
    7575        }
     
    9494            double t = minlon; minlon = maxlon; maxlon = t;
    9595        }
    96        
     96
    9797        boolean newLayer = action != null
    9898                                && (action.dialog == null || action.dialog.newLayer.isSelected());
     
    104104                message);
    105105        currentBounds = new Bounds(new LatLon(minlat, minlon), new LatLon(maxlat, maxlon));
    106         // We need submit instead of execute so we can wait for it to finish and get the error 
     106        // We need submit instead of execute so we can wait for it to finish and get the error
    107107        // message if necessary. If no one calls getErrorMessage() it just behaves like execute.
    108         task = Main.worker.submit(t, t);       
     108        task = Main.worker.submit(t, t);
    109109    }
    110    
     110
    111111    public void download(DownloadAction action, double minlat, double minlon,
    112112            double maxlat, double maxlon) {
     
    135135        return "osm";
    136136    }
    137    
     137
    138138    /**
    139139     * Finds the number of data layers currently opened
     
    149149        return num;
    150150    }
    151    
     151
    152152   /*
    153153    * (non-Javadoc)
     
    156156    public String getErrorMessage() {
    157157        if(task == null)
    158             return "";       
     158            return "";
    159159
    160160        try {
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r1557 r1647  
    2828     */
    2929    public String version;
    30    
     30
    3131    /**
    3232     * All nodes goes here, even when included in other data (ways etc). This enables the instant
  • trunk/src/org/openstreetmap/josm/gui/GettingStarted.java

    r1562 r1647  
    9999            //    everytime because of something we can't read.
    100100            return (Main.pref.getInteger("cache.motd.html.version", myVersion) == myVersion)
    101                                         && Main.pref.get("cache.motd.html.lang").equals(myLang);
     101            && Main.pref.get("cache.motd.html.lang").equals(myLang);
    102102        }
    103103    }
  • trunk/src/org/openstreetmap/josm/gui/PleaseWaitDialog.java

    r1465 r1647  
    5454        });
    5555    }
    56    
    57     public void setIndeterminate(boolean newValue) {   
     56
     57    public void setIndeterminate(boolean newValue) {
    5858        UIManager.put("ProgressBar.cycleTime", UIManager.getInt("ProgressBar.repaintInterval") * 100);
    5959        progressBar.setIndeterminate(newValue);
    6060    }
    61    
     61
    6262    /**
    6363     * Sets a custom text line below currentAction. Can be used to display additional information
     
    7070            return;
    7171        }
    72        
     72
    7373        customText.setVisible(true);
    7474        customText.setText(text);
  • trunk/src/org/openstreetmap/josm/gui/PleaseWaitRunnable.java

    r1493 r1647  
    3434
    3535    private final String title;
    36    
     36
    3737    /**
    3838     * Create the runnable object with a given message for the user.
    39      */   
     39     */
    4040    public PleaseWaitRunnable(String title) {
    4141        this(title, false);
     
    4545     * Create the runnable object with a given message for the user.
    4646     * @param title Message for user
    47      * @param ignoreException If true, exception will be propaged to calling code. If false then 
     47     * @param ignoreException If true, exception will be propaged to calling code. If false then
    4848     * exception will be thrown directly in EDT. When this runnable is executed using executor framework
    4949     * then use false unless you read result of task (because exception will get lost if you don't)
     
    118118                    public void run() {
    119119                        throw new RuntimeException(e);
    120                     }               
     120                    }
    121121                });
    122122            }
  • trunk/src/org/openstreetmap/josm/plugins/PluginDownloader.java

    r1645 r1647  
    2323import java.net.URL;
    2424import java.util.Arrays;
     25import java.util.concurrent.Future;
    2526import java.util.Collection;
    26 import java.util.regex.Matcher;
    27 import java.util.regex.Pattern;
     27import java.util.LinkedList;
    2828
    2929import javax.swing.JOptionPane;
     
    3939    private static final class UpdateTask extends PleaseWaitRunnable {
    4040        private final Collection<PluginInformation> toUpdate;
     41        public final Collection<PluginInformation> failed = new LinkedList<PluginInformation>();
    4142        private String errors = "";
    4243        private int count = 0;
     44        private boolean update;
    4345
    44         private UpdateTask(Collection<PluginInformation> toUpdate) {
    45             super(tr("Update Plugins"));
     46        private UpdateTask(Collection<PluginInformation> toUpdate, boolean up) {
     47            super(up ? tr("Update Plugins") : tr("Download Plugins"));
     48            update = up;
    4649            this.toUpdate = toUpdate;
    4750        }
     
    5255
    5356        @Override protected void finish() {
     57            Main.pleaseWaitDlg.setVisible(false);
    5458            if (errors.length() > 0)
    5559                JOptionPane.showMessageDialog(Main.parent, tr("There were problems with the following plugins:\n\n {0}",errors));
    5660            else
    57                 JOptionPane.showMessageDialog(Main.parent, trn("{0} Plugin successfully updated. Please restart JOSM.", "{0} Plugins successfully updated. Please restart JOSM.", count, count));
     61                JOptionPane.showMessageDialog(Main.parent, trn("{0} Plugin successfully downloaded. Please restart JOSM.", "{0} Plugins successfully downloaded. Please restart JOSM.", count, count));
    5862        }
    5963
     
    6367                pluginDir.mkdirs();
    6468            for (PluginInformation d : toUpdate) {
     69                Main.pleaseWaitDlg.currentAction.setText(tr("Downloading Plugin {0}...", d.name));
    6570                File pluginFile = new File(pluginDir, d.name + ".jar.new");
    6671                if (download(d, pluginFile))
     72                {
    6773                    count++;
     74                    failed.add(d);
     75                }
    6876                else
    6977                    errors += d.name + "\n";
     
    103111    }
    104112
    105     public static boolean downloadPlugin(PluginInformation pd) {
    106         File file = new File(Main.pref.getPluginsDirFile(), pd.name + ".jar");
    107         if (!download(pd, file)) {
    108             JOptionPane.showMessageDialog(Main.parent, tr("Could not download plugin: {0} from {1}", pd.name, pd.downloadlink));
    109         } else {
    110             try {
    111                 PluginInformation.findPlugin(pd.name);
    112                 return true;
    113             } catch (Exception e) {
    114                 e.printStackTrace();
    115                 JOptionPane.showMessageDialog(Main.parent, tr("The plugin {0} seems to be broken or could not be downloaded automatically.", pd.name));
    116             }
    117         }
    118         if (file.exists())
    119             file.delete();
    120         return false;
    121     }
    122 
    123113    private static boolean download(PluginInformation pd, File file) {
    124114        if(pd.mainversion > AboutAction.getVersionNumber())
     
    141131            out.close();
    142132            in.close();
     133            new PluginInformation(file);
    143134            return true;
    144         } catch (MalformedURLException e) {
    145             e.printStackTrace();
    146         } catch (FileNotFoundException e) {
    147             e.printStackTrace();
    148         } catch (IOException e) {
     135        } catch (Exception e) {
    149136            e.printStackTrace();
    150137        }
     138        file.delete(); /* cleanup */
    151139        return false;
    152140    }
    153141
    154142    public static void update(Collection<PluginInformation> update) {
    155         Main.worker.execute(new UpdateTask(update));
     143        Main.worker.execute(new UpdateTask(update, true));
     144    }
     145
     146    public Collection<PluginInformation> download(Collection<PluginInformation> download) {
     147        UpdateTask t = new UpdateTask(download, false);
     148        try {
     149            Future<UpdateTask> ta = Main.worker.submit(t, t);
     150            t = ta.get();
     151            return t.failed;
     152        }
     153        catch(java.lang.InterruptedException e) {}
     154        catch(java.util.concurrent.ExecutionException e) {}
     155        return download;
    156156    }
    157157
  • trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java

    r1645 r1647  
    110110        stage = stageStr == null ? 50 : Integer.parseInt(stageStr);
    111111        version = attr.getValue("Plugin-Version");
    112         try {
    113             mainversion = Integer.parseInt(attr.getValue("Plugin-Mainversion"));
    114         } catch(NumberFormatException e) {
    115             e.printStackTrace();
    116         }
     112        try { mainversion = Integer.parseInt(attr.getValue("Plugin-Mainversion")); }
     113        catch(NumberFormatException e) {}
    117114        author = attr.getValue("Author");
    118115
  • trunk/src/org/openstreetmap/josm/plugins/PluginSelection.java

    r1623 r1647  
    9898        String msg = "";
    9999        for (Entry<String, Boolean> entry : pluginMap.entrySet()) {
    100             if (entry.getValue() && PluginInformation.findPlugin(entry.getKey()) == null) {
    101                 toDownload.add(availablePlugins.get(entry.getKey()));
    102                 msg += entry.getKey() + "\n";
     100            if(entry.getValue())
     101            {
     102                String name = entry.getKey();
     103                PluginInformation ap = availablePlugins.get(name);
     104                PluginInformation pi = PluginInformation.findPlugin(name);
     105                boolean add = false;
     106                if(pi == null)
     107                    add = true;
     108                else if(!pi.version.equals(ap.version))
     109                {
     110                    add = true;
     111                    for (PluginProxy proxy : PluginHandler.pluginList)
     112                        if(proxy.info.name.equals(ap.name))
     113                            add = false;
     114                }
     115                if(add)
     116                {
     117                    toDownload.add(ap);
     118                    msg += name + "\n";
     119                }
    103120            }
    104121        }
     
    109126                        new String[] {tr("Download Plugins"), tr("Cancel")},
    110127                        new String[] {"download.png", "cancel.png"}).getValue();
    111             if (answer != 1)
    112                 for (PluginInformation pd : toDownload)
    113                     pluginMap.put(pd.name, false);
    114             else
    115                 for (PluginInformation pd : toDownload)
    116                     if (!PluginDownloader.downloadPlugin(pd))
    117                         pluginMap.put(pd.name, false);
     128            Collection<PluginInformation> error =
     129            (answer != 1 ? toDownload : new PluginDownloader().download(toDownload));
     130            for (PluginInformation pd : error)
     131                pluginMap.put(pd.name, false);
    118132
    119133        }
     
    209223            pluginCheck.addActionListener(new ActionListener(){
    210224                public void actionPerformed(ActionEvent e) {
    211                     // if user enabled a plugin, it is not loaded but found somewhere on disk: offer to delete jar
    212                     if (pluginCheck.isSelected()) {
    213                         PluginInformation plinfo = PluginInformation.findPlugin(plugin.name);
    214                         if ((getLoaded(plugin.name) == null) && (plinfo != null)) {
    215                             try {
    216                                 int answer = new ExtendedDialog(Main.parent,
    217                                     tr("Plugin already exists"),
    218                                     tr("Plugin archive already available. Do you want to download"
    219                                         + " the current version by deleting existing archive?\n\n{0}",
    220                                         plinfo.file.getCanonicalPath()),
    221                                     new String[] {tr("Delete and Download"), tr("Cancel")},
    222                                     new String[] {"download.png", "cancel.png"}).getValue();
    223 
    224                                 if (answer == 1) {
    225                                     if (!plinfo.file.delete()) {
    226                                         JOptionPane.showMessageDialog(Main.parent, tr("Error deleting plugin file: {0}", plinfo.file.getCanonicalPath()));
    227                                     }
    228                                 }
    229                             } catch (IOException e1) {
    230                                 e1.printStackTrace();
    231                                 JOptionPane.showMessageDialog(Main.parent, tr("Error deleting plugin file: {0}", e1.getMessage()));
    232                             }
    233                         }
    234                     }
    235225                    pluginMap.put(plugin.name, pluginCheck.isSelected());
    236226                }
Note: See TracChangeset for help on using the changeset viewer.