Ignore:
Timestamp:
2017-09-09T16:45:41+02:00 (7 years ago)
Author:
Don-vip
Message:

see #15229 - see #15182 - remove GUI references from OsmConnection

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/oauth/OAuthAuthorizationWizard.java

    r12686 r12803  
    2121import java.beans.PropertyChangeEvent;
    2222import java.beans.PropertyChangeListener;
     23import java.lang.reflect.InvocationTargetException;
     24import java.net.URL;
    2325import java.util.concurrent.Executor;
     26import java.util.concurrent.FutureTask;
    2427
    2528import javax.swing.AbstractAction;
     
    3033import javax.swing.JPanel;
    3134import javax.swing.JScrollPane;
     35import javax.swing.SwingUtilities;
    3236import javax.swing.UIManager;
    3337import javax.swing.event.HyperlinkEvent;
     
    5155import org.openstreetmap.josm.tools.OpenBrowser;
    5256import org.openstreetmap.josm.tools.UserCancelException;
     57import org.openstreetmap.josm.tools.Utils;
    5358
    5459/**
     
    333338    }
    334339
     340    /**
     341     * Obtains an OAuth access token for the connection. Afterwards, the token is accessible via {@link OAuthAccessTokenHolder}.
     342     * @param serverUrl the URL to OSM server
     343     * @throws InterruptedException if we're interrupted while waiting for the event dispatching thread to finish OAuth authorization task
     344     * @throws InvocationTargetException if an exception is thrown while running OAuth authorization task
     345     * @since 12803
     346     */
     347    public static void obtainAccessToken(final URL serverUrl) throws InvocationTargetException, InterruptedException {
     348        final Runnable authTask = new FutureTask<>(() -> {
     349            // Concerning Utils.newDirectExecutor: Main worker cannot be used since this connection is already
     350            // executed via main worker. The OAuth connections would block otherwise.
     351            final OAuthAuthorizationWizard wizard = new OAuthAuthorizationWizard(
     352                    Main.parent, serverUrl.toExternalForm(), Utils.newDirectExecutor());
     353            wizard.showDialog();
     354            return wizard;
     355        });
     356        // exception handling differs from implementation at GuiHelper.runInEDTAndWait()
     357        if (SwingUtilities.isEventDispatchThread()) {
     358            authTask.run();
     359        } else {
     360            SwingUtilities.invokeAndWait(authTask);
     361        }
     362    }
     363
    335364    class AuthorisationProcedureChangeListener implements ItemListener {
    336365        @Override
Note: See TracChangeset for help on using the changeset viewer.