Example usage for javax.swing JOptionPane NO_OPTION

List of usage examples for javax.swing JOptionPane NO_OPTION

Introduction

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

Prototype

int NO_OPTION

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

Click Source Link

Document

Return value from class method if NO is chosen.

Usage

From source file:org.sybila.parasim.extension.projectmanager.model.components.RobustnessModel.java

@Override
public boolean removeCurrent() {
    checkCurrentName();/*from   w  w  w .j  a  v a 2 s  .c o  m*/
    if (getList().isUsedInExperiment(currentName)
            && (JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog(null,
                    "This setting is used in one or more experiments." + " Do you really want to delete it?",
                    "Delete Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE))) {
        return false;
    }
    getList().remove(currentName);
    setCurrentName(null);
    return true;
}

From source file:org.tellervo.desktop.bulkdataentry.command.ImportSelectedElementsCommand.java

/**
 * @see com.dmurph.mvc.control.ICommand#execute(com.dmurph.mvc.MVCEvent)
 *///from  w w  w.j ava  2 s .  c o m
@Override
public void execute(MVCEvent argEvent) {
    BulkImportModel model = BulkImportModel.getInstance();
    ElementModel emodel = model.getElementModel();
    ElementTableModel tmodel = emodel.getTableModel();

    ArrayList<IBulkImportSingleRowModel> selected = new ArrayList<IBulkImportSingleRowModel>();
    tmodel.getSelected(selected);

    // here is where we verify they contain required info
    HashSet<String> requiredMessages = new HashSet<String>();
    ArrayList<IBulkImportSingleRowModel> incompleteModels = new ArrayList<IBulkImportSingleRowModel>();

    HashSet<String> definedProps = new HashSet<String>();
    for (IBulkImportSingleRowModel som : selected) {

        definedProps.clear();
        for (String s : SingleElementModel.TABLE_PROPERTIES) {
            if (som.getProperty(s) != null) {
                definedProps.add(s);
            }
        }
        boolean incomplete = false;

        // object 
        if (!definedProps.contains(SingleElementModel.OBJECT)) {
            requiredMessages.add("Cannot import without a parent object.");
            incomplete = true;
        } else if (fixTempObjectCode(som)) {
            // There was a temp code but it is fixed now
        } else {
            requiredMessages.add("Cannot import as parent object has not been created yet");
            incomplete = true;
        }

        // type
        if (!definedProps.contains(SingleElementModel.TYPE)) {
            requiredMessages.add("Element must contain a type.");
            incomplete = true;
        }

        // taxon
        if (!definedProps.contains(SingleElementModel.TAXON)) {
            requiredMessages.add("Element must contain a taxon.");
            incomplete = true;
        }

        // title
        if (!definedProps.contains(SingleElementModel.TITLE)) {
            requiredMessages.add("Element must have a title");
            incomplete = true;
        }

        // lat/long
        if (definedProps.contains(SingleElementModel.LATITUDE)
                || definedProps.contains(SingleElementModel.LONGITUDE)) {
            if (!definedProps.contains(SingleElementModel.LATITUDE)
                    || !definedProps.contains(SingleElementModel.LONGITUDE)) {
                requiredMessages
                        .add("If coordinates are specified then both latitude and longitude are required");
                incomplete = true;
            } else {
                String attempt = som.getProperty(SingleElementModel.LATITUDE).toString().trim();
                try {
                    Double lat = Double.parseDouble(attempt);
                    if (lat > -90 || lat < 90) {
                        requiredMessages.add("Latitude must be between -90 and 90");
                        incomplete = true;
                    }
                } catch (NumberFormatException e) {
                    requiredMessages.add("Cannot parse '" + attempt + "' into a number.");
                    incomplete = true;
                }
                attempt = som.getProperty(SingleElementModel.LONGITUDE).toString().trim();
                try {
                    Double lng = Double.parseDouble(attempt);
                    if (lng > -180 || lng < 180) {
                        requiredMessages.add("Longitude must be between -180 and 180");
                        incomplete = true;
                    }
                } catch (NumberFormatException e) {
                    requiredMessages.add("Cannot parse '" + attempt + "' into a number.");
                    incomplete = true;
                }
            }
        }

        if (definedProps.contains(SingleElementModel.HEIGHT) || definedProps.contains(SingleElementModel.WIDTH)
                || definedProps.contains(SingleElementModel.DEPTH)
                || definedProps.contains(SingleElementModel.DIAMETER)) {
            if (!definedProps.contains(SingleElementModel.UNIT)) {
                requiredMessages.add("Units must be specified when dimensions are included");
                incomplete = true;
            }

            if ((definedProps.contains(SingleElementModel.HEIGHT)
                    && definedProps.contains(SingleElementModel.DIAMETER)
                    && !definedProps.contains(SingleElementModel.WIDTH)
                    && !definedProps.contains(SingleElementModel.DEPTH))) {
                // h+diam but not width or depth
            } else if ((definedProps.contains(SingleElementModel.HEIGHT)
                    && definedProps.contains(SingleElementModel.WIDTH)
                    && definedProps.contains(SingleElementModel.DEPTH)
                    && !definedProps.contains(SingleElementModel.DIAMETER))) {
                // h+w+d but not diam
            } else {
                requiredMessages.add(
                        "When dimensions are included they must be: height/width/depth or height/diameter.");
                incomplete = true;
            }

        }

        if (incomplete) {
            incompleteModels.add(som);
        }
    }

    if (!incompleteModels.isEmpty()) {
        StringBuilder message = new StringBuilder();
        message.append("Please correct the following errors:\n");
        message.append(StringUtils.join(requiredMessages.toArray(), "\n"));
        Alert.message(model.getMainView(), "Importing Errors", message.toString());
        return;
    }

    // now we actually create the models
    int i = -1;
    boolean hideErrorMessage = false;
    for (IBulkImportSingleRowModel srm : selected) {
        i++;
        SingleElementModel som = (SingleElementModel) srm;
        TridasElement origElement = new TridasElement();

        if (!som.isDirty()) {
            System.out.println("Element isn't dirty, not saving/updating: "
                    + som.getProperty(SingleElementModel.TITLE).toString());
        }

        som.populateToTridasElement(origElement);

        Object o = som.getProperty(SingleElementModel.OBJECT);
        TridasObject parentObject = null;
        if (o instanceof TridasObjectOrPlaceholder) {
            parentObject = ((TridasObjectOrPlaceholder) o).getTridasObject();
        } else if (o instanceof TridasObject) {
            parentObject = (TridasObject) o;
        }

        EntityResource<TridasElement> resource;

        if (origElement.getIdentifier() != null) {
            resource = new EntityResource<TridasElement>(origElement, TellervoRequestType.UPDATE,
                    TridasElement.class);
        } else {
            resource = new EntityResource<TridasElement>(origElement, parentObject, TridasElement.class);
        }

        // set up a dialog...
        Window parentWindow = SwingUtilities.getWindowAncestor(model.getMainView());
        TellervoResourceAccessDialog dialog = new TellervoResourceAccessDialog(parentWindow, resource, i,
                selected.size());

        resource.query();
        dialog.setVisible(true);

        if (!dialog.isSuccessful()) {

            if (hideErrorMessage) {
                continue;
            } else if (i < selected.size() - 1) {
                // More records remain
                Object[] options = { "Yes", "Yes, but hide further messages", "No" };
                int result = JOptionPane.showOptionDialog(BulkImportModel.getInstance().getMainView(), //parent
                        I18n.getText("error.savingChanges") + ":" + System.lineSeparator() + // message
                                dialog.getFailException().getLocalizedMessage() + System.lineSeparator()
                                + System.lineSeparator()
                                + "Would you like to continue importing the remaining records?",
                        I18n.getText("error"), // title 
                        JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]);

                if (result == JOptionPane.NO_OPTION) {
                    hideErrorMessage = true;
                    continue;
                } else if (result == JOptionPane.YES_OPTION) {
                    continue;
                } else {
                    break;
                }
            } else {
                JOptionPane.showMessageDialog(BulkImportModel.getInstance().getMainView(), //parent
                        I18n.getText("error.savingChanges") + ":" + System.lineSeparator() + // message
                                dialog.getFailException().getLocalizedMessage(),
                        I18n.getText("error"), // title 
                        JOptionPane.ERROR_MESSAGE); //option

                break;
            }
        }
        som.populateFromTridasElement(resource.getAssociatedResult());
        som.setDirty(false);
        tmodel.setSelected(som, false);

        // add to imported list or update existing
        if (origElement.getIdentifier() != null) {
            TridasElement found = null;
            for (TridasElement tox : model.getElementModel().getImportedList()) {
                if (tox.getIdentifier().getValue().equals(origElement.getIdentifier().getValue())) {
                    found = tox;
                    break;
                }
            }
            if (found == null) {
                log.warn(
                        "Error updating model.  Couldn't find the object in the model to update so adding to imported list.");
                model.getElementModel().getImportedList().add(resource.getAssociatedResult());
            } else {
                resource.getAssociatedResult().copyTo(found);
            }
        } else {
            model.getElementModel().getImportedList().add(resource.getAssociatedResult());
        }

    }

    //      
    //      // finally, update the combo boxes in the table to the new options
    //      DynamicJComboBoxEvent event = new DynamicJComboBoxEvent(emodel.getImportedDynamicComboBoxKey(), emodel.getImportedListStrings());
    //      event.dispatch();

    tmodel.fireTableDataChanged();
}

From source file:org.ut.biolab.medsavant.client.project.ProjectController.java

/**
 * Give user the option to publish unpublished changes or cancel them.
 * @return <code>true</code> if the user is able to proceed (i.e. they haven't cancelled or logged out)
 *//* ww  w.j a  v  a  2 s  . c o  m*/
public boolean promptToPublish(ProjectDetails pd) {
    Object[] options = new Object[] { "Publish", "Delete (Undo Changes)", "Cancel" };
    int option = JOptionPane.showOptionDialog(null,
            "<HTML>Publishing this table will log all users out of MedSavant, and restart the program. <BR>Are you sure you want to proceed?</HTML>",
            "Confirm", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options,
            options[2]);
    if (option == JOptionPane.NO_OPTION) {
        try {
            MedSavantClient.VariantManager.cancelPublish(LoginController.getSessionID(), pd.getProjectID(),
                    pd.getReferenceID(), pd.getUpdateID());
            return true;
        } catch (Exception ex) {
            ClientMiscUtils.reportError("Error cancelling publication of variants: %s", ex);
        }
    } else if (option == JOptionPane.YES_OPTION) {
        try {
            publishVariants(LoginController.getSessionID(), pd.getProjectID(), pd.getReferenceID(),
                    pd.getUpdateID(), null);
            //MedSavantClient.VariantManager.publishVariants(LoginController.getSessionID(), pd.getProjectID(), pd.getReferenceID(), pd.getUpdateID());
            //MedSavantClient.restart(null);
            //LoginController.getInstance().logout();
        } catch (Exception ex) {
            ClientMiscUtils.reportError("Error publishing variants: %s", ex);
        }
    }
    return false;
}

From source file:org.yccheok.jstock.gui.IndicatorPanel.java

private void alertIndicatorInstall(File file) {
    final IndicatorProjectManager.PreInstallStatus preInstallStatus = this.alertIndicatorProjectManager
            .getPreInstallStatus(file);/*from w  w  w. j  av  a2s . c om*/
    if (preInstallStatus == IndicatorProjectManager.PreInstallStatus.Collision) {
        final String output = MessageFormat.format(
                MessagesBundle.getString("question_message_do_you_want_to_overwrite_template"),
                IndicatorProjectManager.getProjectName(file));
        if (JOptionPane.showConfirmDialog(this, output,
                MessagesBundle.getString("question_title_do_you_want_to_overwrite"),
                JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) {
            return;
        }
    } else if (preInstallStatus == IndicatorProjectManager.PreInstallStatus.Unsafe) {
        JOptionPane.showMessageDialog(this,
                MessagesBundle.getString("warning_message_invalid_alert_indicator_file"),
                MessagesBundle.getString("warning_title_invalid_alert_indicator_file"),
                JOptionPane.WARNING_MESSAGE);
        return;
    }

    if (this.alertIndicatorProjectManager.install(file)) {
        this.syncJListWithIndicatorProjectManager(this.jList1, this.alertIndicatorProjectManager);
        this.jList1.setSelectedValue(IndicatorProjectManager.getProjectName(file), true);
    } else {
        JOptionPane.showMessageDialog(this,
                MessagesBundle.getString("warning_message_invalid_alert_indicator_file"),
                MessagesBundle.getString("warning_title_invalid_alert_indicator_file"),
                JOptionPane.WARNING_MESSAGE);
    }
}

From source file:org.yccheok.jstock.gui.IndicatorPanel.java

private void moduleIndicatorInstall(File file) {
    final IndicatorProjectManager.PreInstallStatus preInstallStatus = this.moduleIndicatorProjectManager
            .getPreInstallStatus(file);/* www.  j a v a  2s  . c o  m*/
    if (preInstallStatus == IndicatorProjectManager.PreInstallStatus.Collision) {
        final String output = MessageFormat.format(
                MessagesBundle.getString("question_message_do_you_want_to_overwrite_template"),
                IndicatorProjectManager.getProjectName(file));
        if (JOptionPane.showConfirmDialog(this, output,
                MessagesBundle.getString("question_title_do_you_want_to_overwrite"),
                JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) {
            return;
        }
    } else if (preInstallStatus == IndicatorProjectManager.PreInstallStatus.Unsafe) {
        JOptionPane.showMessageDialog(this,
                MessagesBundle.getString("warning_message_invalid_module_indicator_file"),
                MessagesBundle.getString("warning_title_invalid_module_indicator_file"),
                JOptionPane.WARNING_MESSAGE);
        return;
    }

    if (this.moduleIndicatorProjectManager.install(file)) {
        this.syncJListWithIndicatorProjectManager(this.jList2, this.moduleIndicatorProjectManager);
        this.jList2.setSelectedValue(IndicatorProjectManager.getProjectName(file), true);
    } else {
        JOptionPane.showMessageDialog(this,
                MessagesBundle.getString("warning_message_invalid_module_indicator_file"),
                MessagesBundle.getString("warning_title_invalid_module_indicator_file"),
                JOptionPane.WARNING_MESSAGE);
    }
}

From source file:org.yccheok.jstock.gui.SaveToCloudJDialog.java

private boolean promptUserToContinue(final List<Country> countryWithWatchlistFilesBeingIgnored) {
    if (countryWithWatchlistFilesBeingIgnored.isEmpty()) {
        // No watchlist file(s) is ignored.
        return true;
    }//w  w w .  ja  v a 2  s  . c  o  m

    int size = countryWithWatchlistFilesBeingIgnored.size();
    final String message;
    final String title;
    if (size == 1) {
        message = MessageFormat.format(
                MessagesBundle.getString("question_message_too_many_stocks_during_save_to_cloud_template"),
                countryWithWatchlistFilesBeingIgnored.get(0));
        title = MessagesBundle.getString("question_title_too_many_stocks_during_save_to_cloud");
    } else {
        message = MessageFormat.format(
                MessagesBundle.getString(
                        "question_message_too_many_stocks_in_multiple_countries_during_save_to_cloud_template"),
                size);
        title = MessagesBundle
                .getString("question_title_too_many_stocks_in_multiple_countries_during_save_to_cloud");
    }

    // Ensure thread safety when we pop up confirmation dialog box. Is it
    // possible to cause deadlock due to invokeAndWait?
    final int[] choice = new int[1];
    choice[0] = JOptionPane.NO_OPTION;
    if (SwingUtilities.isEventDispatchThread()) {
        choice[0] = JOptionPane.showConfirmDialog(SaveToCloudJDialog.this, message, title,
                JOptionPane.YES_NO_OPTION);
    } else {
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    choice[0] = JOptionPane.showConfirmDialog(SaveToCloudJDialog.this, message, title,
                            JOptionPane.YES_NO_OPTION);
                }
            });
        } catch (InterruptedException ex) {
            log.error(null, ex);
        } catch (InvocationTargetException ex) {
            log.error(null, ex);
        }
    }
    return choice[0] == JOptionPane.YES_OPTION;
}

From source file:org.zeromeaner.gui.reskin.StandaloneFrame.java

private void createCards() {
    introPanel = new StandaloneLicensePanel();
    content.add(introPanel, CARD_INTRO);

    playCard = new JPanel(new BorderLayout());
    content.add(playCard, CARD_PLAY);/*from  w ww  .  ja v  a 2s .  c  om*/

    JPanel confirm = new JPanel(new GridBagLayout());
    JOptionPane option = new JOptionPane("A game is in open.  End this game?", JOptionPane.QUESTION_MESSAGE,
            JOptionPane.YES_NO_OPTION);
    option.addPropertyChangeListener(JOptionPane.VALUE_PROPERTY, new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (!CARD_PLAY_END.equals(currentCard))
                return;
            if (evt.getNewValue().equals(JOptionPane.YES_OPTION)) {
                gamePanel.shutdown();
                try {
                    gamePanel.shutdownWait();
                } catch (InterruptedException ie) {
                }
                contentCards.show(content, nextCard);
                currentCard = nextCard;
            }
            if (evt.getNewValue().equals(JOptionPane.NO_OPTION)) {
                contentCards.show(content, CARD_PLAY);
                currentCard = CARD_PLAY;
                playButton.setSelected(true);
            }

            ((JOptionPane) evt.getSource()).setValue(-1);
        }
    });
    GridBagConstraints cx = new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0);
    confirm.add(option, cx);
    content.add(confirm, CARD_PLAY_END);

    content.add(new StandaloneModeselectPanel(), CARD_MODESELECT);

    netplayCard = new JPanel(new BorderLayout());
    netplayCard.add(netLobby, BorderLayout.SOUTH);
    content.add(netplayCard, CARD_NETPLAY);

    confirm = new JPanel(new GridBagLayout());
    option = new JOptionPane("A netplay game is open.  End this game and disconnect?",
            JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
    option.addPropertyChangeListener(JOptionPane.VALUE_PROPERTY, new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (!CARD_NETPLAY_END.equals(currentCard))
                return;
            if (evt.getNewValue().equals(JOptionPane.YES_OPTION)) {
                gamePanel.shutdown();
                try {
                    gamePanel.shutdownWait();
                } catch (InterruptedException ie) {
                }
                netLobby.disconnect();
                contentCards.show(content, nextCard);
                currentCard = nextCard;
            }
            if (evt.getNewValue().equals(JOptionPane.NO_OPTION)) {
                contentCards.show(content, CARD_NETPLAY);
                currentCard = CARD_NETPLAY;
                netplayButton.setSelected(true);
            }

            ((JOptionPane) evt.getSource()).setValue(-1);
        }
    });
    cx = new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.NONE,
            new Insets(10, 10, 10, 10), 0, 0);
    confirm.add(option, cx);
    content.add(confirm, CARD_NETPLAY_END);

    StandaloneKeyConfig kc = new StandaloneKeyConfig(this);
    kc.load(0);
    content.add(kc, CARD_KEYS_1P);
    kc = new StandaloneKeyConfig(this);
    kc.load(1);
    content.add(kc, CARD_KEYS_2P);

    StandaloneGameTuningPanel gt = new StandaloneGameTuningPanel();
    gt.load(0);
    content.add(gt, CARD_TUNING_1P);
    gt = new StandaloneGameTuningPanel();
    gt.load(1);
    content.add(gt, CARD_TUNING_2P);

    StandaloneAISelectPanel ai = new StandaloneAISelectPanel();
    ai.load(0);
    content.add(ai, CARD_AI_1P);
    ai = new StandaloneAISelectPanel();
    ai.load(1);
    content.add(ai, CARD_AI_2P);

    StandaloneGeneralConfigPanel gc = new StandaloneGeneralConfigPanel();
    gc.load();
    content.add(gc, CARD_GENERAL);

    final JFileChooser fc = FileSystemViews.get().fileChooser("replay/");

    fc.setFileFilter(new FileFilter() {
        @Override
        public String getDescription() {
            return "Zeromeaner Replay Files";
        }

        @Override
        public boolean accept(File f) {
            return f.isDirectory() || f.getName().endsWith(".zrep");
        }
    });

    fc.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (!e.getActionCommand().equals(JFileChooser.APPROVE_SELECTION))
                return;
            JFileChooser fc = (JFileChooser) e.getSource();
            String path = fc.getSelectedFile().getPath();
            if (!path.contains("replay/"))
                path = "replay/" + path;
            startReplayGame(path);
        }
    });
    fc.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentShown(ComponentEvent e) {
            fc.rescanCurrentDirectory();
        }
    });
    content.add(fc, CARD_OPEN);

    content.add(new StandaloneFeedbackPanel(), CARD_FEEDBACK);
}

From source file:pcgen.gui2.dialog.ExportDialog.java

private void maybeOpenFile(File file) {
    UIPropertyContext context = UIPropertyContext.getInstance();
    String value = context.getProperty(UIPropertyContext.ALWAYS_OPEN_EXPORT_FILE);
    Boolean openFile = StringUtils.isEmpty(value) ? null : Boolean.valueOf(value);
    if (openFile == null) {
        JCheckBox checkbox = new JCheckBox();
        checkbox.setText("Always perform this action");

        JPanel message = PCGenFrame.buildMessageLabelPanel("Do you want to open " + file.getName() + "?",
                checkbox);//from  ww w.j av a 2s  . c  o  m
        int ret = JOptionPane.showConfirmDialog(this, message, "Select an Option", JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE);
        if (ret == JOptionPane.CLOSED_OPTION) {
            return;
        }
        openFile = BooleanUtils.toBoolean(ret, JOptionPane.YES_OPTION, JOptionPane.NO_OPTION);
        if (checkbox.isSelected()) {
            context.setBoolean(UIPropertyContext.ALWAYS_OPEN_EXPORT_FILE, openFile);
        }
    }
    if (!openFile) {
        return;
    }

    if (!Desktop.isDesktopSupported() || !Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
        pcgenFrame.showErrorMessage("Cannot Open " + file.getName(),
                "Operating System does not support this operation");
        return;
    }
    try {
        Desktop.getDesktop().open(file);
    } catch (IOException ex) {
        String message = "Failed to open " + file.getName();
        pcgenFrame.showErrorMessage(Constants.APPLICATION_NAME, message);
        Logging.errorPrint(message, ex);
    }
}

From source file:pcgen.gui2.PCGenFrame.java

public boolean closeAllCharacters() {
    final int CLOSE_OPT_CHOOSE = 2;
    ListFacade<CharacterFacade> characters = CharacterManager.getCharacters();
    if (characters.isEmpty()) {
        return true;
    }//from w w w .j a  v  a  2 s .co m
    int saveAllChoice = CLOSE_OPT_CHOOSE;

    List<CharacterFacade> characterList = new ArrayList<>();
    List<CharacterFacade> unsavedPCs = new ArrayList<>();
    for (CharacterFacade characterFacade : characters) {
        if (characterFacade.isDirty()) {
            unsavedPCs.add(characterFacade);
        } else {
            characterList.add(characterFacade);
        }
    }
    if (unsavedPCs.size() > 1) {
        Object[] options = new Object[] { LanguageBundle.getString("in_closeOptSaveAll"), //$NON-NLS-1$
                LanguageBundle.getString("in_closeOptSaveNone"), //$NON-NLS-1$
                LanguageBundle.getString("in_closeOptChoose"), //$NON-NLS-1$
                LanguageBundle.getString("in_cancel") //$NON-NLS-1$
        };
        saveAllChoice = JOptionPane.showOptionDialog(this, LanguageBundle.getString("in_closeOptSaveTitle"), //$NON-NLS-1$
                Constants.APPLICATION_NAME, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
                null, options, options[0]);
    }
    if (saveAllChoice == 3) {
        // Cancel
        return false;
    }
    if (saveAllChoice == 1) {
        // Save none
        CharacterManager.removeAllCharacters();
        return true;
    }

    for (CharacterFacade character : unsavedPCs) {
        int saveSingleChoice = JOptionPane.YES_OPTION;

        if (saveAllChoice == CLOSE_OPT_CHOOSE) {
            saveSingleChoice = JOptionPane.showConfirmDialog(this,
                    LanguageBundle.getFormattedString("in_savePcChoice", character //$NON-NLS-1$
                            .getNameRef().get()),
                    Constants.APPLICATION_NAME, JOptionPane.YES_NO_CANCEL_OPTION);
        }

        if (saveSingleChoice == JOptionPane.YES_OPTION) {//If you get here then the user either selected "Yes to All" or "Yes"
            if (saveCharacter(character)) {
                characterList.add(character);
            }
        } else if (saveSingleChoice == JOptionPane.NO_OPTION) {
            characterList.add(character);
        } else if (saveSingleChoice == JOptionPane.CANCEL_OPTION) {
            return false;
        }
    }

    for (CharacterFacade character : characterList) {
        CharacterManager.removeCharacter(character);
    }
    return characters.isEmpty();
}

From source file:pl.kotcrab.arget.gui.ContactsPanel.java

public ContactsPanel(final Profile profile, MainWindowCallback callback) {
    this.profile = profile;

    setLayout(new BorderLayout());

    table = new JTable(new ContactsTableModel(profile.contacts));

    table.setDefaultRenderer(ContactInfo.class, new ContactsTableEditor(table, callback));
    table.setDefaultEditor(ContactInfo.class, new ContactsTableEditor(table, callback));
    table.setShowGrid(false);//from w w  w  .j  a  v  a2  s.  c o m
    table.setTableHeader(null);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setRowHeight(40);

    final JPopupMenu popupMenu = new JPopupMenu();

    {
        JMenuItem menuModify = new JMenuItem("Modify");
        JMenuItem menuDelete = new JMenuItem("Delete");

        popupMenu.add(menuModify);
        popupMenu.add(menuDelete);

        menuModify.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String key = Base64.encodeBase64String(profile.rsa.getPublicKey().getEncoded());
                new CreateContactDialog(MainWindow.instance, key,
                        (ContactInfo) table.getValueAt(table.getSelectedRow(), 0));
                ProfileIO.saveProfile(profile);
                updateContactsTable();
            }
        });

        menuDelete.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                ContactInfo contact = (ContactInfo) table.getValueAt(table.getSelectedRow(), 0);

                if (contact.status == ContactStatus.CONNECTED_SESSION) {
                    JOptionPane.showMessageDialog(MainWindow.instance,
                            "This contact cannot be deleted because session is open.", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }

                int result = JOptionPane.showConfirmDialog(MainWindow.instance,
                        "Are you sure you want to delete '" + contact.name + "'?", "Warning",
                        JOptionPane.YES_NO_OPTION);

                if (result == JOptionPane.NO_OPTION || result == JOptionPane.CLOSED_OPTION)
                    return;

                profile.contacts.remove(contact);
                ProfileIO.saveProfile(profile);
                updateContactsTable();
            }
        });
    }

    table.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                Point p = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), table);

                int rowNumber = table.rowAtPoint(p);
                table.editCellAt(rowNumber, 0);
                table.getSelectionModel().setSelectionInterval(rowNumber, rowNumber);

                popupMenu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });

    JScrollPane tableScrollPane = new JScrollPane(table);
    tableScrollPane.setBorder(new EmptyBorder(0, 0, 0, 0));

    add(tableScrollPane, BorderLayout.CENTER);
}