Example usage for javax.swing JOptionPane DEFAULT_OPTION

List of usage examples for javax.swing JOptionPane DEFAULT_OPTION

Introduction

In this page you can find the example usage for javax.swing JOptionPane DEFAULT_OPTION.

Prototype

int DEFAULT_OPTION

To view the source code for javax.swing JOptionPane DEFAULT_OPTION.

Click Source Link

Document

Type meaning Look and Feel should not supply any options -- only use the options from the JOptionPane.

Usage

From source file:org.apache.jmeter.protocol.http.control.gui.WebServiceSamplerGui.java

/**
 * The method uses WSDLHelper to get the information from the WSDL. Since
 * the logic for getting the description is isolated to this method, we can
 * easily replace it with a different WSDL driver later on.
 *
 * @param url/*from w  w  w.ja  v  a2  s. c om*/
 * @param silent 
 * @return array of web methods
 */
public String[] browseWSDL(String url, boolean silent) {
    try {
        // We get the AuthManager and pass it to the WSDLHelper
        // once the sampler is updated to Axis, all of this stuff
        // should not be necessary. Now I just need to find the
        // time and motivation to do it.
        WebServiceSampler sampler = (WebServiceSampler) this.createTestElement();
        AuthManager manager = sampler.getAuthManager();
        HELPER = new WSDLHelper(url, manager);
        HELPER.parse();
        return HELPER.getWebMethods();
    } catch (Exception exception) {
        if (!silent) {
            JOptionPane.showConfirmDialog(this, JMeterUtils.getResString("wsdl_helper_error") // $NON-NLS-1$
                    + "\n" + exception, // $NON-NLS-1$
                    JMeterUtils.getResString("warning"), // $NON-NLS-1$
                    JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
        }
        return ArrayUtils.EMPTY_STRING_ARRAY;
    }
}

From source file:org.apache.jmeter.protocol.http.control.gui.WebServiceSamplerGui.java

/**
 * method from ActionListener/*from  w w w . j av a  2s  . c o  m*/
 *
 * @param event
 *            that occurred
 */
@Override
public void actionPerformed(ActionEvent event) {
    final Object eventSource = event.getSource();
    if (eventSource == selectButton) {
        this.configureFromWSDL();
    } else if (eventSource == useProxy) {
        // if use proxy is checked, we enable
        // the text fields for the host and port
        boolean use = useProxy.isSelected();
        if (use) {
            proxyHost.setEnabled(true);
            proxyPort.setEnabled(true);
        } else {
            proxyHost.setEnabled(false);
            proxyPort.setEnabled(false);
        }
    } else if (eventSource == wsdlButton) {
        final String wsdlText = wsdlField.getText();
        if (wsdlText != null && wsdlText.length() > 0) {
            fillWsdlMethods(wsdlText, false, null);
        } else {
            JOptionPane.showConfirmDialog(this, JMeterUtils.getResString("wsdl_url_error"), // $NON-NLS-1$
                    JMeterUtils.getResString("warning"), // $NON-NLS-1$
                    JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:org.bibsonomy.plugin.jabref.action.ExportSelectedEntriesAction.java

public void actionPerformed(ActionEvent e) {
    /*//from  w  w  w. j  a v  a  2 s.com
     * fetch selected entries
     */
    List<BibtexEntry> entries = Arrays.asList(getJabRefFrame().basePanel().getSelectedEntries());
    /*
     * check if they all have keywords
     */
    CheckTagsUtil ctu = new CheckTagsUtil(entries, getJabRefFrame());
    switch (ctu.hasAPostNoTagsAssigned()) {
    case JOptionPane.YES_OPTION:
        // tags missing & user has explicitly chosen to add default tag
        ctu.assignDefaultTag();
    case JOptionPane.DEFAULT_OPTION:
        // this means that all posts have tags
        ExportWorker worker = new ExportWorker(getJabRefFrame(), entries);
        performAsynchronously(worker);
        break;
    default:
        // happens when tags are missing, and user wants to cancel export
        LOG.debug("Selected post have no tags assigned");
    }

}

From source file:org.jajuk.base.Device.java

/**
 * Prepare manual refresh./*from  w ww . j a  v a2s . c  o  m*/
 * 
 * @param bAsk ask user to perform deep or fast refresh 
 * 
 * @return the user choice (deep or fast)
 * 
 * @throws JajukException if user canceled, device cannot be refreshed or device already
 * refreshing
 */
int prepareRefresh(final boolean bAsk) throws JajukException {
    if (bAsk) {
        final Object[] possibleValues = { Messages.getString("FilesTreeView.60"), // fast
                Messages.getString("FilesTreeView.61"), // deep
                Messages.getString("Cancel") };// cancel
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    choice = JOptionPane.showOptionDialog(JajukMainWindow.getInstance(),
                            Messages.getString("FilesTreeView.59"), Messages.getString("Option"),
                            JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, possibleValues,
                            possibleValues[0]);
                }
            });
        } catch (Exception e) {
            Log.error(e);
            choice = Device.OPTION_REFRESH_CANCEL;
        }
        if (choice == Device.OPTION_REFRESH_CANCEL) { // Cancel
            return choice;
        }
    }
    // JajukException are not trapped, will be thrown to the caller
    final Device device = this;
    if (!device.isMounted()) {
        // Leave if user canceled device mounting
        if (!device.mount(true)) {
            return Device.OPTION_REFRESH_CANCEL;
        }
    }
    if (bAlreadyRefreshing) {
        throw new JajukException(107);
    }
    return choice;
}

From source file:org.jajuk.services.startup.StartupEngineService.java

/**
 * Launch initial track at startup./*from  w  ww.ja  v  a2  s.co m*/
 */
public static void launchInitialTrack() {
    try {
        String startupMode = Conf.getString(Const.CONF_STARTUP_MODE);
        final File fifo = SessionService.getConfFileByPath(Const.FILE_FIFO);
        // Restore if required
        UtilSystem.recoverFileIfRequired(fifo);
        // User explicitly required nothing to start or he left jajuk stopped
        boolean doNotStartAnything = Const.STARTUP_MODE_NOTHING.equals(startupMode)
                || Conf.getBoolean(Const.CONF_STARTUP_STOPPED)
                //  CONF_STARTUP_ITEM is void at first jajuk session and until user launched an item
                || (Const.STARTUP_MODE_ITEM.equals(startupMode)
                        && StringUtils.isBlank(Conf.getString(Const.CONF_STARTUP_ITEM)))
                // Void collection
                || FileManager.getInstance().getElementCount() == 0
                // FIFO void or not exists
                || (!fifo.exists() || fifo.length() == 0);
        // Populate item to be started and load the stored queue
        populateStartupItems();
        // Check that the file to play is not null and try to mount its device if required 
        if (!doNotStartAnything && !isWebradioStartup()) {
            checkFileToPlay();
        }
        // Set the index of the file to play within the queue.
        // We still need to compute index of file to play even if we play nothing or a radio
        // because user may do a "play" and the next file index must be ready.
        // However, we don't need to test file availability with checkFileToPlay() method.
        updateIndex();
        // Push the new queue
        boolean bRepeat = Conf.getBoolean(Const.CONF_STATE_REPEAT_ALL);
        QueueModel.insert(UtilFeatures.createStackItems(alToPlay, bRepeat, false), 0);
        // Force queue index because insert increase it so it would be set to queue size after the insert
        QueueModel.setIndex(index);
        // Start the file or the radio
        // If user leaved jajuk in stopped mode, do nothing
        if (!doNotStartAnything && isWebradioStartup() && radio != null) {
            launchRadio();
        } else if (!doNotStartAnything && fileToPlay != null) {
            launchFile();
        }
    } catch (Exception e) {
        Log.error(e);
        Messages.getChoice(Messages.getErrorMessage(23), JOptionPane.DEFAULT_OPTION,
                JOptionPane.WARNING_MESSAGE);
    }
}

From source file:org.jajuk.services.startup.StartupEngineService.java

/**
 * Check that the file can actually be played and handle errors if it's not the case.
 * /*from   w ww .j  a va2s .  c  om*/
 * @return whether the file can actually be played
 */
private static boolean checkFileToPlay() {
    boolean result = true;
    // Try to mount the file to play
    if (fileToPlay != null) {
        if (!fileToPlay.isReady()) {
            // File exists but is not mounted, just notify the error
            // without annoying dialog at each startup try to mount
            // device
            Log.debug("Startup file located on an unmounted device" + ", try to mount it");
            try {
                fileToPlay.getDevice().mount(false);
                Log.debug("Mount OK");
            } catch (final Exception e) {
                Log.debug("Mount failed");
                final Properties pDetail = new Properties();
                pDetail.put(Const.DETAIL_CONTENT, fileToPlay);
                pDetail.put(Const.DETAIL_REASON, "10");
                ObservationManager.notify(new JajukEvent(JajukEvents.PLAY_ERROR, pDetail));
                result = false;
            }
        }
    } else {
        // file no more exists
        Messages.getChoice(Messages.getErrorMessage(23), JOptionPane.DEFAULT_OPTION,
                JOptionPane.WARNING_MESSAGE);
        // no more first file, we ignore any stored fifo as it may contains
        // others disappeared files
        result = false;
    }
    return result;
}

From source file:org.jajuk.ui.views.ParameterViewGUIHelper.java

/**
* Handle workspace change./*ww  w . j  a v a2s  .  c o m*/
*
*/
private void handleWorkspaceChange() {
    if (!Conf.getString(Const.CONF_TARGET_WORKSPACE_PATH).equals(pv.psJajukWorkspace.getUrl())) {
        Conf.setProperty(Const.CONF_TARGET_WORKSPACE_PATH, pv.psJajukWorkspace.getUrl());
        // Check workspace directory
        if (!pv.psJajukWorkspace.getUrl().trim().isEmpty()) {
            // Check workspace presence and create it if required
            final java.io.File fWorkspace = new java.io.File(pv.psJajukWorkspace.getUrl());
            if (!fWorkspace.exists() && !fWorkspace.mkdirs()) {
                Log.warn("Could not create directory " + fWorkspace.toString());
            }
            if (!fWorkspace.canRead()) {
                Messages.showErrorMessage(165);
                return;
            }
        }
        try {
            final String newWorkspace = pv.psJajukWorkspace.getUrl();
            // If target workspace doesn't exist, copy current repository to
            // the new workspace
            // (keep old repository for security and for use
            // by others users in multi-session mode)
            boolean bPreviousPathExist = true;
            // bPreviousPathExist is true if destination workspace already
            // exists,
            // it is then only a workspace switch
            if (!new java.io.File(pv.psJajukWorkspace.getUrl() + '/'
                    + (SessionService.isTestMode() ? ".jajuk_test_" + Const.TEST_VERSION : ".jajuk"))
                            .exists()) {
                UtilGUI.waiting();
                final java.io.File from = SessionService.getConfFileByPath("");
                final java.io.File dest = new java.io.File(newWorkspace + '/'
                        + (SessionService.isTestMode() ? ".jajuk_test_" + Const.TEST_VERSION : ".jajuk"));
                UtilSystem.copyRecursively(from, dest);
                bPreviousPathExist = false;
            }
            // Change the workspace so the very last conf (like current
            // track)
            // will be saved directly to target workspace. We don't do
            // this if the workspace already exist to avoid overwriting other
            // configuration.
            SessionService.setWorkspace(pv.psJajukWorkspace.getUrl());
            //Commit the bootstrap file
            SessionService.commitBootstrapFile();
            UtilGUI.stopWaiting();
            // Display a warning message and restart Jajuk
            if (bPreviousPathExist) {
                Messages.getChoice(Messages.getString("ParameterView.247"), JOptionPane.DEFAULT_OPTION,
                        JOptionPane.INFORMATION_MESSAGE);
            } else {
                Messages.getChoice(Messages.getString("ParameterView.209"), JOptionPane.DEFAULT_OPTION,
                        JOptionPane.INFORMATION_MESSAGE);
            }
            // Exit Jajuk
            try {
                ActionManager.getAction(JajukActions.EXIT).perform(null);
            } catch (Exception e1) {
                Log.error(e1);
            }
        } catch (final Exception e) {
            Messages.showErrorMessage(24);
            Log.error(e);
        }
    }
}

From source file:org.kepler.gui.kar.ImportModuleDependenciesAction.java

/** Check the dependencies and ask the user how to proceed. */
public ImportChoice checkDependencies() {

    ConfigurationManager cman = ConfigurationManager.getInstance();
    ConfigurationProperty cprop = cman.getProperty(KARFile.KARFILE_CONFIG_PROP_MODULE);
    ConfigurationProperty KARComplianceProp = cprop.getProperty(KARFile.KAR_COMPLIANCE_PROPERTY_NAME);
    String KARCompliance = KARComplianceProp.getValue();

    final ArrayList<String> dependencies = new ArrayList<String>();
    try {/* w w w.  j  av  a2s .c  o m*/
        if (_dependencies != null) {
            // dependencies were given
            dependencies.addAll(_dependencies);
        } else if (_archiveFile != null) {
            // kar file was given
            KARFile karFile = null;
            try {
                karFile = new KARFile(_archiveFile);
                dependencies.addAll(karFile.getModuleDependencies());
            } finally {
                if (karFile != null) {
                    karFile.close();
                }
            }
        } else {
            // karxml was given
            dependencies.addAll(_karXml.getModuleDependencies());
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    //ModuleTree moduleTree = ModuleTree.instance();
    //String currentModList = formattedCurrentModuleList(moduleTree);

    boolean dependencyMissingFullVersion = !(ModuleDependencyUtil
            .isDependencyVersioningInfoComplete(dependencies));
    LinkedHashMap<String, Version> unsatisfiedDependencies = ModuleDependencyUtil
            .getUnsatisfiedDependencies(dependencies);

    String keplerRestartMessage = null;
    String unableToOpenOrExportInStrictKARComplianceMessage = null;
    String manualActionRequired = null;
    String unSats = formattedUnsatisfiedDependencies(unsatisfiedDependencies);
    final List<String> unSatsAsList = new ArrayList<String>(unsatisfiedDependencies.keySet());

    String formattedDependencies = formatDependencies(dependencies);
    String htmlBGColor = "#"
            + Integer.toHexString(UIManager.getColor("OptionPane.background").getRGB() & 0x00ffffff);
    //XXX augment if additional strictness levels added
    if (KARCompliance.equals(KARFile.KAR_COMPLIANCE_STRICT)) {
        if (dependencyMissingFullVersion) {
            if (_exportMode) {
                unableToOpenOrExportInStrictKARComplianceMessage = "<html><body bgcolor=\"" + htmlBGColor
                        + "\">This KAR "
                        + "lacks complete versioning information in its module-dependency list:<strong>"
                        + formattedDependencies
                        + "</strong><br><br>You must change your KAR opening compliance "
                        + "preference to Relaxed before trying to export this KAR.<br><br>"
                        + "You can Force Export, but some artifacts may not be included in the KAR.</body></html>";
            } else {
                unableToOpenOrExportInStrictKARComplianceMessage = "<html><body bgcolor=\"" + htmlBGColor
                        + "\">This KAR "
                        + "lacks complete versioning information in its module-dependency list:<strong>"
                        + formattedDependencies
                        + "</strong><br><br>You must change your KAR opening compliance "
                        + "preference to Relaxed before trying to open this KAR.<br><br>"
                        + "You can attempt a Force Open, but this may cause unexpected errors.</body></html>";
            }
        } else {
            if (!unsatisfiedDependencies.isEmpty()) {
                if (_exportMode) {
                    keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor
                            + "\">Your KAR opening compliance preference is set to Strict. To export this KAR in<br>"
                            + "Strict mode you must restart Kepler with these additional module(s):<strong>"
                            + unSats
                            + "</strong><br><br>Would you like to download (if necessary) and restart Kepler using these modules now?"
                            + "<br><br><strong>WARNING: All unsaved work will be lost, and auto-updating turned off if it's on<br>"
                            + "(re-enable using the Tools=>Module Manager...)</strong><br><br>"
                            + "You can Force Export, but some artifacts may not be included in the KAR.</body></html>";
                } else {
                    keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor
                            + "\">Your KAR opening compliance preference is set to Strict. To open this KAR in<br>"
                            + "Strict mode you must restart Kepler with these additional module(s):<strong>"
                            + unSats
                            + "</strong><br><br>Would you like to download (if necessary) and restart Kepler using these modules now?"
                            + "<br><br><strong>WARNING: All unsaved work will be lost, and auto-updating turned off if it's on<br>"
                            + "(re-enable using the Tools=>Module Manager...)</strong><br><br>"
                            + "You can attempt a Force Open, but this may cause unexpected errors.</body></html>";
                }
            } else {
                if (_exportMode) {
                    keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor
                            + "\">Your KAR opening compliance preference is set to Strict. To export this KAR in<br>"
                            + "Strict mode you must restart Kepler using this module set in this order:<strong>"
                            + formattedDependencies
                            + "</strong><br><br>Would you like to restart Kepler using these modules now?"
                            + "<br><br><strong>WARNING: All unsaved work will be lost, and auto-updating turned off if it's on<br>"
                            + "(re-enable using the Tools=>Module Manager...)</strong><br><br>"
                            + "You can Force Export, but some artifacts may not be included in the KAR.</body></html>";
                } else {
                    keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor
                            + "\">Your KAR opening compliance preference is set to Strict. To open this KAR in<br>"
                            + "Strict mode you must restart Kepler using this module set in this order:<strong>"
                            + formattedDependencies
                            + "</strong><br><br>Would you like to restart Kepler using these modules now?"
                            + "<br><br><strong>WARNING: All unsaved work will be lost, and auto-updating turned off if it's on<br>"
                            + "(re-enable using the Tools=>Module Manager...)</strong><br><br>"
                            + "You can attempt a Force Open, but this may cause unexpected errors.</body></html>";
                }
            }
        }
    } else if (KARCompliance.equals(KARFile.KAR_COMPLIANCE_RELAXED)) {
        if (dependencyMissingFullVersion) {
            // if there's a dependency missing full version info, situation should be either 1) a 2.0 kar, in which case
            // it lacks the full mod dep list and so user must use MM, or 2) it's a 2.1 kar created from an svn 
            // checkout of kepler, in which case, the power user should use the build system to 
            // change to unreleased versions of a suite containing the required modules as necessary
            if (_exportMode) {
                manualActionRequired = "<html><body bgcolor=\"" + htmlBGColor + "\">This KAR "
                        + "requires the following unsatisfied module dependencies that lack complete versioning information:<strong>"
                        + unSats
                        + "</strong><br><br>Please use the Module Manager or build system to change to a suite that uses these modules.</strong>"
                        + "<br><br>You can Force Export, but some artifacts may not be included in the KAR.</body></html>";
            } else {
                manualActionRequired = "<html><body bgcolor=\"" + htmlBGColor + "\">This KAR "
                        + "requires the following unsatisfied module dependencies that lack complete versioning information:<strong>"
                        + unSats
                        + "</strong><br><br>Please use the Module Manager or build system to change to a suite that uses these modules.</strong>"
                        + "<br><br>You can attempt a Force Open, but this may cause unexpected errors.</body></html>";
            }
        } else {
            if (!unsatisfiedDependencies.isEmpty()) {
                if (_exportMode) {
                    keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor
                            + "\">This KAR requires you restart Kepler with these "
                            + "additional module(s):<strong>" + unSats + "</strong><br><br>Would you like to "
                            + "download (if necessary) and restart Kepler using these modules now?"
                            + "<br><br><strong>WARNING: All unsaved work will be lost</strong><br><br>"
                            + "You can Force Export, but some artifacts may not be included in the KAR.</body></html>";
                } else {
                    keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor
                            + "\">This KAR requires you restart Kepler with these "
                            + "additional module(s):<strong>" + unSats + "</strong><br><br>Would you like to "
                            + "download (if necessary) and restart Kepler using these modules now?"
                            + "<br><br><strong>WARNING: All unsaved work will be lost</strong><br><br>"
                            + "You can attempt a Force Open, but this may cause unexpected errors.</body></html>";
                }
            } else {
                //THIS SHOULDN'T HAPPEN
                log.error(
                        "ImportModuleDependenciesAction WARNING unsatisfiedDependencies is empty, this shouldn't happen, but is non fatal");
                if (_exportMode) {
                    keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor
                            + "\">This KAR requires you restart Kepler with these " + "module(s):<strong>"
                            + formattedDependencies + "</strong><br><br>Would you like to "
                            + "restart Kepler using these modules now?"
                            + "<br><br><strong>WARNING: All unsaved work will be lost</strong><br><br>"
                            + "You can Force Export, but some artifacts may not be included in the KAR.</body></html>";
                } else {
                    keplerRestartMessage = "<html><body bgcolor=\"" + htmlBGColor
                            + "\">This KAR requires you restart Kepler with these " + "module(s):<strong>"
                            + formattedDependencies + "</strong><br><br>Would you like to "
                            + "restart Kepler using these modules now?"
                            + "<br><br><strong>WARNING: All unsaved work will be lost</strong><br><br>"
                            + "You can attempt a Force Open, but this may cause unexpected errors.</body></html>";
                }
            }
        }
    }

    String[] optionsOkForceopen = { "OK", "Force Open" };
    String[] optionsOkForceexport = { "OK", "Force Export" };
    String[] optionsYesNoForceopen = { "Yes", "No", "Force Open" };
    String[] optionsYesNoForceexport = { "Yes", "No", "Force Export" };

    if (unableToOpenOrExportInStrictKARComplianceMessage != null) {
        JLabel label = new JLabel(unableToOpenOrExportInStrictKARComplianceMessage);
        if (_exportMode) {
            int choice = JOptionPane.showOptionDialog(parent, label, "Unable to export in Strict mode",
                    JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, optionsOkForceexport,
                    optionsOkForceexport[0]);
            if (optionsOkForceexport[choice].equals("Force Export")) {
                return ImportChoice.FORCE_EXPORT;
            }
        } else {
            int choice = JOptionPane.showOptionDialog(parent, label, "Unable to open in Strict mode",
                    JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, optionsOkForceopen,
                    optionsOkForceopen[0]);
            if (optionsOkForceopen[choice].equals("Force Open")) {
                return ImportChoice.FORCE_OPEN;
            }
        }
        return ImportChoice.DO_NOTHING;
    }

    if (manualActionRequired != null) {
        JLabel label = new JLabel(manualActionRequired);
        if (_exportMode) {
            int choice = JOptionPane.showOptionDialog(parent, label, "Use Module Manager",
                    JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, optionsOkForceexport,
                    optionsOkForceexport[0]);
            if (optionsOkForceexport[choice].equals("Force Export")) {
                return ImportChoice.FORCE_EXPORT;
            }
        } else {
            int choice = JOptionPane.showOptionDialog(parent, label, "Use Module Manager",
                    JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, optionsOkForceopen,
                    optionsOkForceopen[0]);
            if (optionsOkForceopen[choice].equals("Force Open")) {
                return ImportChoice.FORCE_OPEN;
            }
        }
        return ImportChoice.DO_NOTHING;
    }

    JLabel label = new JLabel(keplerRestartMessage);
    if (_exportMode) {
        int choice = JOptionPane.showOptionDialog(parent, label, "Confirm Kepler Restart",
                JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, optionsYesNoForceexport,
                optionsYesNoForceexport[1]);

        if (optionsYesNoForceexport[choice] == "No") {
            // user doesn't want to download.
            return ImportChoice.DO_NOTHING;
        } else if (optionsYesNoForceexport[choice].equals("Force Export")) {
            return ImportChoice.FORCE_EXPORT;
        }
    } else {
        int choice = JOptionPane.showOptionDialog(parent, label, "Confirm Kepler Restart",
                JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, optionsYesNoForceopen,
                optionsYesNoForceopen[1]);

        if (optionsYesNoForceopen[choice] == "No") {
            // user doesn't want to download.
            return ImportChoice.DO_NOTHING;
        } else if (optionsYesNoForceopen[choice].equals("Force Open")) {
            return ImportChoice.FORCE_OPEN;
        }
    }

    parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
        @Override
        public Void doInBackground() throws Exception {
            try {

                //download needed modules
                ModuleDownloader downloader = new ModuleDownloader();
                ModuleDownloadProgressMonitor mdpm = new ModuleDownloadProgressMonitor(parent);
                downloader.addListener(mdpm);
                if (!unSatsAsList.isEmpty()) {
                    downloader.downloadModules(unSatsAsList);
                } else {
                    // this shouldn't happen, but if it does, resorting
                    // to downloading all dependencies should be a safe bet
                    log.error("ImportModuleDependenciesAction WARNING unSatsAsList is empty, "
                            + "this shouldn't happen, but is non fatal");
                    downloader.downloadModules(dependencies);
                }

                //rewrite modules.txt
                ModulesTxt modulesTxt = ModulesTxt.instance();
                modulesTxt.clear();
                for (String dependency : dependencies) {
                    //System.out.println("ImportModuleDependency doInBackground modulesTxt.add("+dependency+")");
                    modulesTxt.add(dependency);
                }
                modulesTxt.write();

                //delete and write "unknown" to current-suite.txt
                CurrentSuiteTxt.delete();
                CurrentSuiteTxt.setName("unknown");

                // if KARCompliance is Strict, user is restarting w/ specific versions of modules
                // and we don't want them to potentially auto update on restart to available patches
                turnOffAutoUpdatesIfStrictMode();

                //restart Kepler using new modules
                spawnNewKeplerAndQuitCurrent();

                return null;
            } catch (Exception ex) {
                ex.printStackTrace();
                JOptionPane.showMessageDialog(parent, "Error downloading module: " + ex.getMessage());
                return null;
            }
        }

        @Override
        protected void done() {
            //never reached.
        }

    };

    worker.execute();

    parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));

    return ImportChoice.DOWNLOADING_AND_RESTARTING;
}

From source file:org.myrobotlab.service.MarySpeech.java

private void showProgressPanel(List<ComponentDescription> comps, boolean install) {
    final ProgressPanel pp = new ProgressPanel(comps, install);
    final JOptionPane optionPane = new JOptionPane(pp, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION,
            null, new String[] { "Abort" }, "Abort");
    // optionPane.setPreferredSize(new Dimension(640,480));
    final JDialog dialog = new JDialog((Frame) null, "Progress", false);
    dialog.setContentPane(optionPane);//  w ww.  j av a2s  .  c  o m
    optionPane.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
            String prop = e.getPropertyName();

            if (dialog.isVisible() && (e.getSource() == optionPane)
                    && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
                pp.requestExit();
                dialog.setVisible(false);
            }
        }
    });
    dialog.pack();
    dialog.setVisible(true);
    new Thread(pp).start();
}

From source file:org.nuclos.client.main.MainController.java

private void handleMessage(final Message msg) {
    try {/* w ww.j a va2 s . com*/
        if ((msg.getJMSCorrelationID() == null
                || msg.getJMSCorrelationID().equals(MainController.this.getUserName()))
                && msg instanceof ObjectMessage) {
            final Object objMessage = ((ObjectMessage) msg).getObject();

            if (objMessage.getClass().equals(ApiMessageImpl.class)) {
                final ApiMessageImpl apiMsg = (ApiMessageImpl) ((ObjectMessage) msg).getObject();
                LOG.info("Handle " + apiMsg);
                Component parent = null;
                if (apiMsg.getReceiverId() != null) {
                    MainFrameTab target = MainFrameTab.getMainFrameTab(apiMsg.getReceiverId());
                    parent = target;
                    if (target != null) {
                        if (apiMsg.getMessage().isOverlay()) {
                            OverlayOptionPane.showMessageDialog(target, apiMsg.getMessage().getMessage(),
                                    apiMsg.getMessage().getTitle(), new OvOpAdapter() {
                                    });
                            return;
                        }
                    } else {
                        LOG.warn(String.format("Receiver with id %s not found!", apiMsg.getReceiverId()));
                    }
                }

                if (parent == null) {
                    parent = Main.getInstance().getMainFrame();
                }
                JOptionPane.showMessageDialog(parent, apiMsg.getMessage().getMessage(),
                        apiMsg.getMessage().getTitle(), JOptionPane.INFORMATION_MESSAGE);
            } else if (objMessage.getClass().equals(RuleNotification.class)) {
                final RuleNotification notification = (RuleNotification) ((ObjectMessage) msg).getObject();
                getNotificationDialog().addMessage(notification);
                switch (notification.getPriority()) {
                case LOW:
                    // just add the message, nothing else.
                    break;
                case NORMAL:
                    getMainFrame().getMessagePanel().startFlashing();
                    break;
                case HIGH:
                    getNotificationDialog().setVisible(true);
                    break;
                default:
                    LOG.warn("Undefined message priority: " + notification.getPriority());
                }
                LOG.info("Handled RuleNotification " + notification.toDescription());
            } else if (objMessage.getClass().equals(CommandMessage.class)) {
                final CommandMessage command = (CommandMessage) ((ObjectMessage) msg).getObject();
                switch (command.getCommand()) {
                case CommandMessage.CMD_SHUTDOWN:
                    getNotificationDialog().addMessage(new RuleNotification(Priority.HIGH,
                            getSpringLocaleDelegate().getMessage("MainController.19",
                                    "Der Client wird auf Anweisung des Administrators in 10 Sekunden beendet."),
                            "Administrator"));
                    getNotificationDialog().setVisible(true);

                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                Thread.sleep(10000);
                            } catch (InterruptedException e) {
                                // do nothing
                            } finally {
                                MainController.this.cmdExit();
                            }
                        }
                    });
                    break;
                }
                LOG.info("Handled CommandMessage " + command);
            } else if (objMessage.getClass().equals(CommandInformationMessage.class)) {
                final CommandInformationMessage command = (CommandInformationMessage) ((ObjectMessage) msg)
                        .getObject();
                switch (command.getCommand()) {
                case CommandInformationMessage.CMD_INFO_SHUTDOWN:
                    Object[] options = { "OK" };
                    int decision = JOptionPane.showOptionDialog(getMainFrame(), command.getInfo(),
                            getSpringLocaleDelegate().getMessage("MainController.17",
                                    "Administrator - Passwort\u00e4nderung"),
                            JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options,
                            options[0]);
                    if (decision == 0 || decision == JOptionPane.CLOSED_OPTION
                            || decision == JOptionPane.NO_OPTION) {
                        new Thread(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    Thread.sleep(10000);
                                } catch (InterruptedException e) {
                                    // do nothing
                                } finally {
                                    MainController.this.cmdExit();
                                }
                            }
                        }, "MainController.handleMessage.cmdExit").run();
                    }
                    break;
                }
                LOG.info("Handled CommandInformationMessage " + command);
            }
        } else {
            LOG.warn(getSpringLocaleDelegate().getMessage("MainController.14",
                    "Message of type {0} received, while an ObjectMessage was expected.",
                    msg.getClass().getName()));
        }
    } catch (JMSException ex) {
        LOG.warn("Exception thrown in JMS message listener.", ex);
    }
}