Changeset 2994 in josm


Ignore:
Timestamp:
2010-02-15T20:47:41+01:00 (14 years ago)
Author:
bastiK
Message:

fixed #4534 - non-closable error message when opening files

File:
1 edited

Legend:

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

    r2980 r2994  
    1919import javax.swing.JFileChooser;
    2020import javax.swing.JOptionPane;
     21import javax.swing.SwingUtilities;
    2122import javax.swing.filechooser.FileFilter;
    2223
     
    9495
    9596        protected void alertFilesNotMatchingWithImporter(Collection<File> files, FileImporter importer) {
    96             StringBuffer msg = new StringBuffer();
     97            final StringBuffer msg = new StringBuffer();
    9798            msg.append("<html>");
    9899            msg.append(
    99100                    trn(
    100                             "Cannot open {0} file with the file importer ''{1}''. Skipping the following files:",
    101                             "Cannot open {0} files with the file importer ''{1}''. Skipping the following files:",
     101                            "Cannot open {0} file with the file importer ''{1}''.",
     102                            "Cannot open {0} files with the file importer ''{1}''.",
    102103                            files.size(),
    103104                            files.size(),
     
    111112            msg.append("</ul>");
    112113
    113             HelpAwareOptionPane.showOptionDialog(
    114                     Main.parent,
    115                     msg.toString(),
    116                     tr("Warning"),
    117                     JOptionPane.WARNING_MESSAGE,
    118                     HelpUtil.ht("/Action/OpenFile#ImporterCantImportFiles")
    119             );
     114            SwingUtilities.invokeLater(new Runnable() {
     115                public void run() {
     116                    HelpAwareOptionPane.showOptionDialog(
     117                            Main.parent,
     118                            msg.toString(),
     119                            tr("Warning"),
     120                            JOptionPane.WARNING_MESSAGE,
     121                            HelpUtil.ht("/Action/OpenFile#ImporterCantImportFiles")
     122                    );
     123                }
     124            });
    120125        }
    121126
    122127        protected void alertFilesWithUnknownImporter(Collection<File> files) {
    123             StringBuffer msg = new StringBuffer();
     128            final StringBuffer msg = new StringBuffer();
    124129            msg.append("<html>");
    125130            msg.append(
    126131                    trn(
    127                             "Cannot open {0} file because no suitable file importer is available. Skipping the following files:",
    128                             "Cannot open {0} files because no suitable file importer is available. Skipping the following files:",
     132                            "Cannot open {0} file because no suitable file importer is available.",
     133                            "Cannot open {0} files because no suitable file importer is available.",
    129134                            files.size(),
    130135                            files.size()
     
    136141            }
    137142            msg.append("</ul>");
    138 
    139             HelpAwareOptionPane.showOptionDialog(
    140                     Main.parent,
    141                     msg.toString(),
    142                     tr("Warning"),
    143                     JOptionPane.WARNING_MESSAGE,
    144                     HelpUtil.ht("/Action/OpenFile#MissingImporterForFiles")
    145             );
     143           
     144            SwingUtilities.invokeLater(new Runnable() {
     145                public void run() {
     146                    HelpAwareOptionPane.showOptionDialog(
     147                            Main.parent,
     148                            msg.toString(),
     149                            tr("Warning"),
     150                            JOptionPane.WARNING_MESSAGE,
     151                            HelpUtil.ht("/Action/OpenFile#MissingImporterForFiles")
     152                    );
     153                }
     154            });
    146155        }
    147156
     
    172181                List<File> filesNotMatchingWithImporter = new LinkedList<File>();
    173182                List<File> filesMatchingWithImporter = new LinkedList<File>();
    174                 for (File f : files) {
     183                for (final File f : files) {
    175184                    if (!chosenImporter.acceptFile(f)) {
    176185                        if (f.isDirectory()) {
    177                             JOptionPane.showMessageDialog(Main.parent, tr(
    178                                     "<html>Cannot open directory ''{0}''.<br>Please select a file.</html>", f
    179                                     .getAbsolutePath()), tr("Open file"), JOptionPane.ERROR_MESSAGE);
     186                            SwingUtilities.invokeLater(new Runnable() {
     187                                public void run() {
     188                                    JOptionPane.showMessageDialog(Main.parent, tr(
     189                                            "<html>Cannot open directory ''{0}''.<br>Please select a file.</html>",
     190                                            f.getAbsolutePath()), tr("Open file"), JOptionPane.ERROR_MESSAGE);
     191                                }
     192                            });
     193                            // TODO when changing to Java 6: Don't cancel the
     194                            // task here but use different modality. (Currently 2 dialogs
     195                            // would block each other.)
     196                            return;
    180197                        } else {
    181198                            filesNotMatchingWithImporter.add(f);
     
    188205                if (!filesNotMatchingWithImporter.isEmpty()) {
    189206                    alertFilesNotMatchingWithImporter(filesNotMatchingWithImporter, chosenImporter);
    190                 }
    191                 if (!filesNotMatchingWithImporter.isEmpty()) {
     207                    // TODO when changing to Java 6: Don't cancel the
     208                    // task here but use different modality. (Currently 2 dialogs
     209                    // would block each other.)
     210                    return;
     211                }
     212                if (!filesMatchingWithImporter.isEmpty()) {
    192213                    importData(chosenImporter, filesMatchingWithImporter);
    193214                }
     
    209230                if (!filesWithUnknownImporter.isEmpty()) {
    210231                    alertFilesWithUnknownImporter(filesWithUnknownImporter);
     232                    // TODO when changing to Java 6: Don't cancel the
     233                    // task here but use different modality. (Currently 2 dialogs
     234                    // would block each other.)
     235                    return;
    211236                }
    212237                List<FileImporter> ims = new ArrayList<FileImporter>(map.keySet());
Note: See TracChangeset for help on using the changeset viewer.