563N/A/*
563N/A * CDDL HEADER START
563N/A *
563N/A * The contents of this file are subject to the terms of the
563N/A * Common Development and Distribution License, Version 1.0 only
563N/A * (the "License"). You may not use this file except in compliance
563N/A * with the License.
563N/A *
563N/A * You can obtain a copy of the license at
563N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
563N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
563N/A * See the License for the specific language governing permissions
563N/A * and limitations under the License.
563N/A *
563N/A * When distributing Covered Code, include this CDDL HEADER in each
563N/A * file and include the License file at
563N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
563N/A * add the following below this CDDL HEADER, with the fields enclosed
873N/A * by brackets "[]" replaced with your own identifying information:
563N/A * Portions Copyright [yyyy] [name of copyright owner]
563N/A *
563N/A * CDDL HEADER END
563N/A *
563N/A *
5027N/A * Copyright 2006-2010 Sun Microsystems, Inc.
563N/A */
563N/A
563N/Apackage org.opends.quicksetup.util;
2086N/Aimport org.opends.messages.Message;
563N/A
563N/Aimport javax.swing.JFrame;
563N/A
563N/Aimport org.opends.quicksetup.ui.WebBrowserErrorDialog;
563N/Aimport org.opends.quicksetup.ui.QuickSetupStepPanel;
563N/A
563N/A/**
563N/A * This class is used to try to launch a URL in the user web browser.
563N/A *
563N/A * The class extends SwingWorker and tries to launch the URL using
563N/A * a WebBrowserLauncher object in the construct method.
563N/A * If there is a problem launching the user's browser, this class will display
563N/A * a WebBrowserErrorDialog to allow the user to copy to the system clipboard the
563N/A * URL we wanted to display.
563N/A *
563N/A * When is finished (successfully or unsuccessfully) it notifies the
563N/A * QuickSetupStepPanel passed in the constructor.
563N/A *
563N/A */
5027N/Apublic class URLWorker extends BackgroundTask<Object>
563N/A{
563N/A private QuickSetupStepPanel panel;
563N/A
563N/A private String url;
563N/A
563N/A /**
563N/A * Constructs a URLWorker.
563N/A * @param panel the panel that created this URLWorker and to which we will
563N/A * notify when we are over.
563N/A * @param url the url to be displayed.
563N/A */
563N/A public URLWorker(QuickSetupStepPanel panel, String url)
563N/A {
563N/A this.panel = panel;
563N/A this.url = url;
563N/A }
563N/A
563N/A /**
563N/A * {@inheritDoc}
563N/A */
563N/A public Object processBackgroundTask() throws WebBrowserException
563N/A {
563N/A try
563N/A {
563N/A WebBrowserLauncher.openURL(url);
623N/A } catch (Throwable t)
563N/A {
2086N/A // TODO: i18n
2086N/A throw new WebBrowserException(url, Message.raw("Bug: throwable"), t);
563N/A }
563N/A return null;
563N/A }
563N/A
563N/A /**
563N/A * {@inheritDoc}
563N/A */
563N/A public void backgroundTaskCompleted(Object returnValue,
563N/A Throwable throwable)
563N/A {
563N/A WebBrowserException ex = (WebBrowserException) throwable;
563N/A if (ex != null)
563N/A {
563N/A WebBrowserErrorDialog dlg =
563N/A new WebBrowserErrorDialog((JFrame) panel.getMainWindow(), ex);
563N/A dlg.setModal(false);
563N/A dlg.packAndShow();
563N/A }
563N/A // Notify to the panel that the worker has finished.
563N/A panel.urlWorkerFinished(this);
563N/A }
563N/A
563N/A /**
563N/A * Returns the URL that we are trying to launch in the users browser.
563N/A * @return the URL that we are trying to launch in the users browser.
563N/A */
563N/A public String getURL()
563N/A {
563N/A return url;
563N/A }
563N/A}