+
+ /**
+ * Actually import the {@link Story} into the main {@link LocalLibrary}.
+ * <p>
+ * Should be called inside the UI thread, will start a worker (i.e., this is
+ * asynchronous).
+ *
+ * @param parent
+ * a container we can use to show error messages if any
+ * @param url
+ * the {@link Story} to import by {@link URL}
+ * @param pg
+ * the optional progress reporter
+ * @param onSuccess
+ * Action to execute on success
+ */
+ static public void imprt(final Container parent, final String url,
+ final Progress pg, final Runnable onSuccess) {
+ final Progress fpg = pg;
+ new SwingWorker<Void, Void>() {
+ @Override
+ protected Void doInBackground() throws Exception {
+ Progress pg = fpg;
+ if (pg == null)
+ pg = new Progress();
+
+ try {
+ Instance.getInstance().getLibrary()
+ .imprt(BasicReader.getUrl(url), fpg);
+
+ fpg.done();
+ if (onSuccess != null) {
+ onSuccess.run();
+ }
+ } catch (IOException e) {
+ fpg.done();
+ if (e instanceof UnknownHostException) {
+ UiHelper.error(parent,
+ Instance.getInstance().getTransGui().getString(
+ StringIdGui.ERROR_URL_NOT_SUPPORTED,
+ url),
+ Instance.getInstance().getTransGui().getString(
+ StringIdGui.TITLE_ERROR),
+ null);
+ } else {
+ UiHelper.error(parent,
+ Instance.getInstance().getTransGui().getString(
+ StringIdGui.ERROR_URL_IMPORT_FAILED,
+ url, e.getMessage()),
+ Instance.getInstance().getTransGui()
+ .getString(StringIdGui.TITLE_ERROR),
+ e);
+ }
+ }
+
+ return null;
+ }
+ }.execute();
+ }