Example usage for javax.swing JOptionPane showConfirmDialog

List of usage examples for javax.swing JOptionPane showConfirmDialog

Introduction

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

Prototype

public static int showConfirmDialog(Component parentComponent, Object message) throws HeadlessException 

Source Link

Document

Brings up a dialog with the options Yes, No and Cancel; with the title, Select an Option.

Usage

From source file:br.com.utfpr.pb.view.PedidoCompraView.java

private void salvar() {
    if (JOptionPane.showConfirmDialog(null, "Deseja finalizar o pedido?") == 0) {
        try {//from w w  w  .  j a  v  a  2  s. c o  m
            pedido.setEmissao(new Date());
            pedido.setPessoa((Pessoa) pessoa.getSelectedItem());
            pedido.getProdutos().forEach(e -> e.setPedido(pedido));
            pedido = pedidoController.save(pedido);
            /*if (JOptionPane.showConfirmDialog(null, "Pedido realizado com sucesso! Deseja imprimir?") == 0){
            imprimePedido(pedido);
            }*/
            zerarPedido();
        } catch (Exception e) {
            if (e instanceof ConstraintViolationException) {
                JOptionPane.showMessageDialog(null,
                        ValidationUtil.getInstance().getMessage((ConstraintViolationException) e));
            } else {
                JOptionPane.showMessageDialog(null, "Ocorreu um problema ao salvar.\n\n" + e.getMessage());
                e.printStackTrace();
            }
        }
    }
}

From source file:net.sf.housekeeper.swing.MainFrame.java

/**
 * Asks if data should be saved before it terminates the application.
 *///  w  w  w.jav  a  2s  . c om
private void exitApplication() {
    boolean exit = true;

    //Only show dialog for saving before exiting if any data has been
    // changed
    if (FoodItemManager.instance().hasChanged()) {
        final String question = LocalisationManager.INSTANCE.getText("gui.mainFrame.saveModificationsQuestion");
        final int option = JOptionPane.showConfirmDialog(view, question);

        //If user choses yes try to save. If that fails do not exit.
        if (option == JOptionPane.YES_OPTION) {
            try {
                PersistenceController.instance().saveDomainData();
            } catch (IOException e) {
                exit = false;
                showSavingErrorDialog();
                e.printStackTrace();
            }
        } else if (option == JOptionPane.CANCEL_OPTION) {
            exit = false;
        }
    }

    if (exit) {
        System.exit(0);
    }
}

From source file:com.mirth.connect.client.ui.SettingsPanelMap.java

public void doExportMap() {
    if (isSaveEnabled()) {
        int option = JOptionPane.showConfirmDialog(this, "Would you like to save the settings first?");

        if (option == JOptionPane.YES_OPTION) {
            if (!doSave()) {
                return;
            }/*from  w w w .j  a v  a 2s  .c  om*/
        } else if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) {
            return;
        }
    }

    final String workingId = getFrame().startWorking("Exporting " + getTabName() + " settings...");

    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {

        private Map<String, ConfigurationProperty> configurationMap;

        public Void doInBackground() {
            try {
                File file = getFrame().createFileForExport(null, "PROPERTIES");
                if (file != null) {
                    PropertiesConfiguration properties = new PropertiesConfiguration();
                    properties.setDelimiterParsingDisabled(true);
                    properties.setListDelimiter((char) 0);
                    properties.clear();
                    PropertiesConfigurationLayout layout = properties.getLayout();

                    configurationMap = getFrame().mirthClient.getConfigurationMap();
                    Map<String, ConfigurationProperty> sortedMap = new TreeMap<String, ConfigurationProperty>(
                            String.CASE_INSENSITIVE_ORDER);
                    sortedMap.putAll(configurationMap);

                    for (Entry<String, ConfigurationProperty> entry : sortedMap.entrySet()) {
                        String key = entry.getKey();
                        String value = entry.getValue().getValue();
                        String comment = entry.getValue().getComment();

                        if (StringUtils.isNotBlank(key)) {
                            properties.setProperty(key, value);
                            layout.setComment(key, StringUtils.isBlank(comment) ? null : comment);
                        }
                    }

                    properties.save(file);
                }
            } catch (Exception e) {
                getFrame().alertThrowable(getFrame(), e);
            }

            return null;
        }

        @Override
        public void done() {
            getFrame().stopWorking(workingId);
        }
    };

    worker.execute();
}

From source file:de.evaluationtool.gui.EvaluationFrameActionListener.java

private void saveXML() {
    JFileChooser chooser = new JFileChooser("Save evaluation result as alignment XML");
    chooser.setCurrentDirectory(frame.defaultDirectory);
    int returnVal = chooser.showSaveDialog(frame);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        if (chooser.getSelectedFile().exists() && (JOptionPane.showConfirmDialog(frame,
                "File already exists. Overwrite?") != JOptionPane.YES_OPTION)) {
            return;
        }//from  w  w  w. ja  v  a 2  s  . co  m
        try {
            frame.saveXML(chooser.getSelectedFile(), SaveXMLMode.SAVE_EVERYTHING);
        } catch (JDOMException | IOException e) {
            JOptionPane.showConfirmDialog(frame, e, "Error saving XML", JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:it.txt.access.capability.demo.soap.client.view.ClientGUIController.java

@Override
public void windowClosing(WindowEvent e) {

    if (clientGUI.getReturnCode() == ClientGUI.FINISH_RETURN_CODE) {
        stopClientAndCloseApplication();
    } else {//from   w  ww.  jav  a2s .c  o  m
        int resp = JOptionPane.showConfirmDialog(clientGUI, "Are you sure you want to close?");
        if (resp == JOptionPane.YES_OPTION) {
            stopClientAndCloseApplication();
        }
    }
}

From source file:de.evaluationtool.gui.EvaluationFrameActionListener.java

private void saveTSV() {
    JFileChooser chooser = new JFileChooser("Save evaluation result as TSV");
    chooser.setCurrentDirectory(frame.defaultDirectory);
    int returnVal = chooser.showSaveDialog(frame);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        if (chooser.getSelectedFile().exists() && (JOptionPane.showConfirmDialog(frame,
                "File already exists. Overwrite?") != JOptionPane.YES_OPTION)) {
            return;
        }/* w  w w  .ja v  a  2  s. c  o  m*/
        frame.saveTSV(chooser.getSelectedFile());
    }
}

From source file:gtu._work.etc.EnglishAdd.java

void setDefaultSave() {
    this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    this.addWindowListener(new WindowAdapter() {
        public void windowOpened(WindowEvent e) {
        }/*w  w  w . j  a  v a 2  s . c  o  m*/

        public void windowClosing(WindowEvent e) {
            if (JOptionPane.showConfirmDialog(null, "?") == JOptionPane.YES_OPTION) {
                String words = wordTextArea.getText();
                if (StringUtils.isNotBlank(words) && currentFile != null) {
                    FileUtil.saveToFile(currentFile, words, "BIG5");
                }

                gtu.swing.util.JFrameUtil.setVisible(false, EnglishAdd.this);
                EnglishAdd.this.dispose();
            }
        }
    });
}

From source file:de.evaluationtool.gui.EvaluationFrameActionListener.java

private void saveReferenceXML() {
    JFileChooser chooser = new JFileChooser(
            "Save as alignment xml format. YOUR EVALUATION WILL NOT BE SAVED, ONLY A COPY OF THE INPUT.");
    chooser.setCurrentDirectory(new File("."));
    int returnVal = chooser.showSaveDialog(frame);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        if (chooser.getSelectedFile().exists() && (JOptionPane.showConfirmDialog(frame,
                "File already exists. Overwrite?") != JOptionPane.YES_OPTION)) {
            return;
        }//  ww  w .ja  v  a 2 s .c om
        frame.saveReferenceXML(chooser.getSelectedFile(), true);
    }
}

From source file:com.stonelion.zooviewer.ui.JZVNodePanel.java

/**
 * Returns the 'Update' action./*  www. j a  va 2  s  .  co m*/
 *
 * @return the action
 */
@SuppressWarnings("serial")
private Action getUpdateAction() {
    if (updateAction == null) {
        String actionCommand = bundle.getString(UPDATE_NODE_KEY);
        String actionKey = bundle.getString(UPDATE_NODE_KEY + ".action");
        updateAction = new AbstractAction(actionCommand, Icons.UPDATE) {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("actionPerformed(): action = " + e.getActionCommand());
                if (checkAction()) {
                    model.updateData(nodes[0].getPath(), taUpdate.getText().getBytes(getCharset()));
                }
            }

            private boolean checkAction() {
                // No node or several nodes selected
                if (nodes == null || nodes.length > 1) {
                    return false;
                }
                // No parent
                if (nodes == null || nodes.length != 1) {
                    JOptionPane.showMessageDialog(JZVNodePanel.this,
                            bundle.getString("dlg.error.updateWithoutParent"),
                            bundle.getString("dlg.error.title"), JOptionPane.ERROR_MESSAGE);
                    return false;
                }

                return (JOptionPane.showConfirmDialog(JZVNodePanel.this,
                        bundle.getString("dlg.confirm.update")) == JOptionPane.YES_OPTION);
            }
        };
        updateAction.putValue(Action.ACTION_COMMAND_KEY, actionKey);
    }
    return updateAction;
}

From source file:biz.wolschon.finance.jgnucash.panels.TaxReportPanel.java

/**
 * Show a dialog to export/*from  w  w  w .  j  a va  2 s . c  om*/
 * a CSV-file that contains the
 * shown {@link TransactionSum}s
 * for each month, year or day.
 */
protected void showExportCSVDialog() {
    JFileChooser fc = new JFileChooser();
    fc.setAcceptAllFileFilterUsed(true);
    fc.addChoosableFileFilter(new FileFilter() {

        @Override
        public boolean accept(final File aF) {
            return aF.isDirectory() || aF.getName().endsWith(".csv");
        }

        @Override
        public String getDescription() {
            return "CSV-file";
        }
    });
    int dialogResult = fc.showSaveDialog(this);
    if (dialogResult != JFileChooser.APPROVE_OPTION) {
        return;
    }
    File file = fc.getSelectedFile();
    if (file.exists()) {
        int confirmation = JOptionPane.showConfirmDialog(this, "File exists. Replace file?");
        if (confirmation != JOptionPane.YES_OPTION) {
            showExportCSVDialog();
            return;
        }
    }
    ExportGranularities gran = (ExportGranularities) myExportGranularityCombobox.getSelectedItem();
    try {
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        exportCSV(file, gran);
    } finally {
        setCursor(Cursor.getDefaultCursor());
    }
}