source: osm/applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsLoadAction.java@ 30666

Last change on this file since 30666 was 30666, checked in by donvip, 11 years ago

[josm_sds] see #josm10024 - update to JOSM 7578

File size: 3.4 KB
Line 
1//License: GPL.
2package org.openstreetmap.hot.sds;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7import java.io.File;
8import java.io.FileInputStream;
9import java.io.IOException;
10import java.io.InputStream;
11import java.io.UnsupportedEncodingException;
12import java.util.ArrayList;
13import java.util.Arrays;
14import java.util.List;
15
16import javax.xml.parsers.ParserConfigurationException;
17import javax.xml.parsers.SAXParserFactory;
18
19import org.openstreetmap.josm.Main;
20import org.openstreetmap.josm.gui.PleaseWaitRunnable;
21import org.openstreetmap.josm.gui.widgets.SwingFileChooser;
22import org.openstreetmap.josm.io.OsmTransferException;
23import org.xml.sax.InputSource;
24import org.xml.sax.SAXException;
25
26@SuppressWarnings("serial")
27public class SdsLoadAction extends SdsDiskAccessAction {
28
29 private SeparateDataStorePlugin plugin;
30
31 public SdsLoadAction(SeparateDataStorePlugin p) {
32 super(tr("Load..."), "sds_load", tr("Load separate data store data from a file."), null);
33 plugin = p;
34 }
35
36 public void actionPerformed(ActionEvent e) {
37 SwingFileChooser fc = createAndOpenFileChooser(true, true, null);
38 if (fc == null)
39 return;
40 File[] files = fc.getSelectedFiles();
41 openFiles(Arrays.asList(files));
42 }
43
44 public void openFiles(List<File> fileList) {
45 OpenFileTask task = new OpenFileTask(fileList, plugin);
46 Main.worker.submit(task);
47 }
48
49 public class OpenFileTask extends PleaseWaitRunnable {
50 private List<File> files;
51 private boolean canceled;
52 private SeparateDataStorePlugin plugin;
53
54 public OpenFileTask(List<File> files, SeparateDataStorePlugin p) {
55 super(tr("Loading files"), false /* don't ignore exception */);
56 this.files = new ArrayList<File>(files);
57 plugin = p;
58 }
59
60 @Override
61 protected void cancel() {
62 this.canceled = true;
63 }
64
65 @Override
66 protected void finish() {
67 // do nothing
68 }
69
70 @Override
71 protected void realRun() throws SAXException, IOException, OsmTransferException {
72 if (files == null || files.isEmpty()) return;
73
74 getProgressMonitor().setTicksCount(files.size());
75
76 for (File f : files) {
77 if (canceled) return;
78 getProgressMonitor().indeterminateSubTask(tr("Opening file ''{0}'' ...", f.getAbsolutePath()));
79
80 InputStream fileStream;
81 try {
82 fileStream = new FileInputStream(f);
83 SdsParser p = new SdsParser(Main.main.getCurrentDataSet(), plugin, false);
84 InputSource inputSource = new InputSource(fileStream);
85 SAXParserFactory.newInstance().newSAXParser().parse(inputSource, p);
86 } catch (UnsupportedEncodingException e1) {
87 // TODO Auto-generated catch block
88 e1.printStackTrace();
89 } catch (SAXException e) {
90 // TODO Auto-generated catch block
91 e.printStackTrace();
92 } catch (IOException e) {
93 // TODO Auto-generated catch block
94 e.printStackTrace();
95 } catch (ParserConfigurationException e) {
96 // TODO Auto-generated catch block
97 e.printStackTrace();
98 }
99
100 }
101 }
102 }
103}
Note: See TracBrowser for help on using the repository browser.