Example usage for javax.swing JOptionPane OK_OPTION

List of usage examples for javax.swing JOptionPane OK_OPTION

Introduction

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

Prototype

int OK_OPTION

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

Click Source Link

Document

Return value form class method if OK is chosen.

Usage

From source file:co.com.soinsoftware.hotelero.view.JFRoomService.java

private void jbtDeleteServiceActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jbtDeleteServiceActionPerformed
    final Invoice invoice = this.getInvoiceSelected();
    if (invoice == null) {
        ViewUtils.showMessage(this, MSG_ROOM_REQUIRED, ViewUtils.TITLE_REQUIRED_FIELDS,
                JOptionPane.ERROR_MESSAGE);
    } else {/*from  www.  j a va 2 s. c om*/
        final List<InvoiceItem> invoiceItemList = this.getInvoiceItemListFromTable();
        if (invoiceItemList != null && this.hasServiceToBeDeleted(invoiceItemList)) {
            final int confirmation = ViewUtils.showConfirmDialog(this, ViewUtils.MSG_DELETE_QUESTION,
                    ViewUtils.TITLE_SAVED);
            if (confirmation == JOptionPane.OK_OPTION) {
                long value = 0;
                for (final InvoiceItem invoiceItem : invoiceItemList) {
                    if (invoiceItem.isDelete()) {
                        invoiceItem.setEnabled(false);
                        invoiceItem.setUpdated(new Date());
                        invoiceItemController.save(invoiceItem);
                        value += invoiceItem.getValue();
                    }
                }
                final long invoiceValue = invoice.getValue() - value;
                invoice.setValue(invoiceValue);
                invoice.setUpdated(new Date());
                this.invoiceController.save(invoice);
                ViewUtils.showMessage(this, ViewUtils.MSG_DELETED, ViewUtils.TITLE_SAVED,
                        JOptionPane.INFORMATION_MESSAGE);
                this.refreshService();
            }
        } else {
            ViewUtils.showMessage(this, ViewUtils.MSG_UNSELECTED, ViewUtils.TITLE_SAVED,
                    JOptionPane.INFORMATION_MESSAGE);
        }
    }
}

From source file:contactsdirectory.frontend.MainJFrame.java

private void editPerson() {
    if (jListPerson.getSelectedIndex() < 0) {
        JOptionPane.showMessageDialog(this, localizedTexts.getString("noPersonSelected"), "",
                JOptionPane.INFORMATION_MESSAGE);
        return;/* w w  w  .  j a v a 2s .com*/
    }

    final PersonJDialog dialog = new PersonJDialog(this, true);
    dialog.setPerson(getSelectedPerson());//.getContact());        

    if (JOptionPane.OK_OPTION == dialog.showDialog())//contact != null)
    {
        Person person = dialog.getPerson();

        try {
            jProgressBar.setIndeterminate(true);
            jProgressBar.setVisible(true);

            EditPersonSwingWorker worker = new EditPersonSwingWorker(person);
            worker.execute();

            jProgressBar.setVisible(false);
            jProgressBar.setIndeterminate(false);
            updatePersonDetail();
        } catch (RuntimeException e) {
            JOptionPane.showMessageDialog(this, localizedTexts.getString("noPersonEdited"),
                    localizedTexts.getString("errorMsgTitle"), JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:com.freedomotic.jfrontend.MainWindow.java

private void mnuRemoveRoomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuRemoveRoomActionPerformed

    ZoneLogic zone = drawer.getSelectedZone();

    if (zone == null) {
        JOptionPane.showMessageDialog(this, i18n.msg("select_room_first"));
    } else {/*from  w  w w .j ava2 s.c o  m*/
        if (JOptionPane.showConfirmDialog(this,
                i18n.msg("really_delete_room_X", new Object[] { zone.getPojo().getName() }),
                i18n.msg("room_delete_confirm_title"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
            drawer.getCurrEnv().removeZone(zone);
            drawer.createHandles(null);
        }
    }
}

From source file:br.com.postalis.folhapgto.proc.TelaPrincipal.java

private void btnPosFolhaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPosFolhaActionPerformed
    carregarParametros();/*from w w w  . java2s.c  o m*/
    int confirmacao = JOptionPane.showConfirmDialog(null,
            "Deseja importar os descontos efetuados ps folha para a referncia: " + txtMesAno + "?",
            "Importao ps folha", JOptionPane.OK_CANCEL_OPTION);
    if (confirmacao == JOptionPane.OK_OPTION) {
        new Thread() {
            public void run() {
                try {
                    txtStatusProc
                            .setText("Executando importao ps folha para a referncia: " + txtMesAno + "...");
                    btnPosFolha.setEnabled(false);
                    ExitStatus retorno = new SvcFolhaPgtoImpl().consultarDescPosFolha(usuario, anoMesRef,
                            dtRef);
                    if (retorno.equals(EnumExistStatus.VAZIO.getStatus())) {
                        txtStatusProc.setText(
                                "A importao ps folha no disponvel para a referncia: " + txtMesAno + ".");
                        Thread.sleep(10000);
                        txtStatusProc.setText("");
                    } else if (retorno.equals(EnumExistStatus.SUCESSO.getStatus())) {
                        txtStatusProc.setText(
                                "Importao concluida com sucesso para a referncia: " + txtMesAno + ".");
                        Thread.sleep(10000);
                        txtStatusProc.setText("");
                    } else {
                        throw new Exception("O tipo de resultado no esperado: " + retorno.getExitCode());
                    }
                } catch (Exception ex) {
                    String msg = "Erro ao executar a importao ps folha para a referncia: " + txtMesAno
                            + ": ";
                    LOGGER.error(msg + ex.getMessage());
                    txtStatusProc.setText(msg);
                } finally {
                    btnPosFolha.setEnabled(true);
                }
            }
        }.start();
    }
}

From source file:contactsdirectory.frontend.MainJFrame.java

private void addPerson() {
    final PersonJDialog dialog = new PersonJDialog(this, true);
    if (JOptionPane.OK_OPTION == dialog.showDialog())//contact != null)
    {/*from  w w  w .  j  a va2  s  .c  o  m*/
        Person person = dialog.getPerson();

        try {
            jProgressBar.setIndeterminate(true);
            jProgressBar.setVisible(true);

            NewPersonSwingWorker worker = new NewPersonSwingWorker(person);
            worker.execute();

            ((DefaultListModel<Person>) jListPerson.getModel()).addElement(person);

            jProgressBar.setVisible(false);
            jProgressBar.setIndeterminate(false);
        } catch (RuntimeException e) {
            JOptionPane.showMessageDialog(this, localizedTexts.getString("noPersonAdded"),
                    localizedTexts.getString("errorMsgTitle"), JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:br.com.postalis.folhapgto.proc.TelaPrincipal.java

private void btnExportarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportarActionPerformed
    carregarParametros();/*from  w w  w . j av a2  s  . c  om*/
    int confirmacao = JOptionPane.showConfirmDialog(null,
            "Exportar folha de pagamento para a referncia: " + txtMesAno + "?",
            "Exportao da folha de pagamento", JOptionPane.OK_CANCEL_OPTION);
    if (confirmacao == JOptionPane.OK_OPTION) {
        new Thread() {
            public void run() {
                try {
                    txtStatusProc.setText("Executando exportao para a referncia: " + txtMesAno + "...");
                    btnExportar.setEnabled(false);
                    ExitStatus retorno = new SvcFolhaPgtoImpl().exportarFolhaPgto(usuario, anoMesRef, dtRef);
                    if (retorno.equals(EnumExistStatus.VAZIO.getStatus())) {
                        txtStatusProc
                                .setText("No exitem lanamentos a exportar na referncia: " + txtMesAno + ".");
                        Thread.sleep(10000);
                        txtStatusProc.setText("");
                    } else if (retorno.equals(EnumExistStatus.SUCESSO.getStatus())) {
                        txtStatusProc.setText(
                                "Exportao concluida com sucesso para a referncia: " + txtMesAno + ".");
                        Thread.sleep(10000);
                        txtStatusProc.setText("");
                    } else {
                        throw new Exception("O tipo de resultado no esperado: " + retorno.getExitCode());
                    }
                } catch (Exception ex) {
                    String msg = "Erro ao executar a exportao da folha para a referncia: " + txtMesAno
                            + ": ";
                    LOGGER.error(msg + ex.getMessage());
                    txtStatusProc.setText(msg);
                } finally {
                    preencherTabela();
                    btnExportar.setEnabled(true);
                }

            }
        }.start();
    }
}

From source file:ca.osmcanada.osvuploadr.JPMain.java

private void jbUploadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbUploadActionPerformed
    String path = ca.osmcanada.osvuploadr.JFMain.class.getProtectionDomain().getCodeSource().getLocation()
            .getPath();//from   www .  j  a  va  2 s  .  co  m
    String decodedPath = "";
    try {
        decodedPath = new File(URLDecoder.decode(path, "UTF-8")).getParentFile().getPath();
    } catch (Exception ex) {
        Logger.getLogger(JPMain.class.getName()).log(Level.SEVERE, "decodePath", ex);
    }
    File id = new File(decodedPath + "/access_token.txt");
    String accessToken = "";
    System.out.println("id_file exists:" + id.exists());
    if (!id.exists()) {
        try {
            String[] buttons = { new String(r.getString("automatically").getBytes(), "UTF-8"),
                    new String(r.getString("manually").getBytes(), "UTF-8"),
                    new String(r.getString("cancel").getBytes(), "UTF-8") };
            int rc = JOptionPane.showOptionDialog(null,
                    new String(r.getString("login_to_osm").getBytes(), "UTF-8"),
                    new String(r.getString("confirmation").getBytes(), "UTF-8"),
                    JOptionPane.INFORMATION_MESSAGE, 0, null, buttons, buttons[0]);
            String token = "";
            System.out.println("GetOSMUser");
            switch (rc) {
            case 0:
                String usr = "";
                String psw = "";
                JTextField tf = new JTextField();
                JPasswordField pf = new JPasswordField();
                rc = JOptionPane.showConfirmDialog(null, tf,
                        new String(r.getString("email_osm_usr").getBytes(), "UTF-8"),
                        JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
                if (rc == JOptionPane.OK_OPTION) {
                    usr = tf.getText();
                } else {
                    return;
                }

                rc = JOptionPane.showConfirmDialog(null, pf,
                        new String(r.getString("enter_password").getBytes(), "UTF-8"),
                        JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
                if (rc == JOptionPane.OK_OPTION) {
                    psw = new String(pf.getPassword());
                } else {
                    return;
                }
                token = GetOSMUser(usr, psw);
                break;
            case 1:
                token = GetOSMUser();
                break;
            case 2:
                return;

            }
            Path targetPath = Paths.get("./access_token.txt");
            byte[] bytes = token.split("\\|")[0].getBytes(StandardCharsets.UTF_8);
            Files.write(targetPath, bytes, StandardOpenOption.CREATE);
            accessToken = token.split("\\|")[0];
            String accessSecret = token.split("\\|")[1];
            SendAuthTokens(accessToken, accessSecret);
        } catch (Exception ex) {
            Logger.getLogger(JPMain.class.getName()).log(Level.SEVERE, "GetOSMUser", ex);
        }
    } else {
        try {
            List<String> token = Files.readAllLines(Paths.get(id.getPath()));
            if (token.size() > 0) {
                accessToken = token.get(0); //read first line
            }
        } catch (Exception ex) {
            Logger.getLogger(JPMain.class.getName()).log(Level.SEVERE, "readAllLines", ex);
        }
    }
    System.out.println("Access Token obtained from file or OSM:" + accessToken);

    //Start processing list
    for (String item : listDir.getItems()) {
        System.out.println("Processing folder:" + item);
        Process(item, accessToken);
    }
    //um = new UploadManager(listDir.getItems());
    //um.start();

}

From source file:edu.ku.brc.af.core.db.MySQLBackupService.java

/**
 * @param key/*from   ww  w  .ja v a  2  s .  c  o  m*/
 * @param diff
 */
private void showEZDBBackupMessage(final String key, final int diff) {
    File ezdbFile = DBConnection.getEmbeddedDataDir();
    String emdDirPath = ezdbFile != null ? ezdbFile.getAbsolutePath() : "N/A";
    String line1 = key != null ? getLocalizedMessage(key, diff) : "";
    String msg = String.format(getResourceString("MySQLBackupService.EZDB_BACKUP"), line1, emdDirPath);

    int rv = UIRegistry.askYesNoLocalized("MySQLBackupService.DIRBTN", "CLOSE", msg,
            getResourceString("MySQLBackupService.BK_NOW_TITLE"));
    if (rv == JOptionPane.OK_OPTION) {
        try {
            String urlString = UIRegistry.getResourceString("MySQLBackupService.EZDB_BACKUP_LINK");
            AttachmentUtils.openURI(new URL(urlString).toURI());
        } catch (Exception e) {
            e.printStackTrace();

        }
    }
}

From source file:com.igormaznitsa.jhexed.swing.editor.ui.MainForm.java

private void menuFileNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuFileNewActionPerformed
    if (JOptionPane.showConfirmDialog(this, "Do you really want to start new map?", "Confirmation",
            JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
        resetState();//from   ww w. ja  v a2s  . c o  m
    }
}

From source file:de.whiledo.iliasdownloader2.swing.service.MainController.java

protected void chooseServer() {
    final TwoObjectsX<String, String> serverAndClientId = new TwoObjectsX<String, String>(
            iliasProperties.getIliasServerURL(), iliasProperties.getIliasClient());
    final boolean noConfigDoneYet = serverAndClientId.getObjectA() == null
            || serverAndClientId.getObjectA().trim().isEmpty();

    final JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());

    final JLabel labelServer = new JLabel("Server: " + serverAndClientId.getObjectA());
    final JLabel labelClientId = new JLabel("Client Id: " + serverAndClientId.getObjectB());

    JComboBox<LoginType> comboboxLoginType = null;
    JComboBox<DownloadMethod> comboboxDownloadMethod = null;

    final Runnable findOutClientId = new Runnable() {

        @Override//  w  ww  .java  2 s  . c om
        public void run() {
            try {
                String s = IliasUtil.findClientByLoginPageOrWebserviceURL(serverAndClientId.getObjectA());
                serverAndClientId.setObjectB(s);
                labelClientId.setText("Client Id: " + s);
            } catch (Exception e1) {
                showError("Client Id konnte nicht ermittelt werden", e1);
            }
        }
    };

    final Runnable promptInputServer = new Runnable() {

        @Override
        public void run() {

            String s = JOptionPane.showInputDialog(panel,
                    "Geben Sie die Ilias Loginseitenadresse oder Webserviceadresse ein",
                    serverAndClientId.getObjectA());
            if (s != null) {
                try {
                    s = IliasUtil.findSOAPWebserviceByLoginPage(s.trim());

                    if (!s.toLowerCase().startsWith("https://")) {
                        JOptionPane.showMessageDialog(mainFrame,
                                "Achtung! Die von Ihnen angegebene Adresse beginnt nicht mit 'https://'.\nDie Verbindung ist daher nicht ausreichend gesichert. Ein Angreifer knnte Ihre Ilias Daten und Ihr Passwort abgreifen",
                                "Achtung, nicht geschtzt", JOptionPane.WARNING_MESSAGE);
                    }

                    serverAndClientId.setObjectA(s);
                    labelServer.setText("Server: " + serverAndClientId.getObjectA());

                    if (noConfigDoneYet) {
                        findOutClientId.run();
                    }
                } catch (IliasException e1) {
                    showError(
                            "Bitte geben Sie die Adresse der Ilias Loginseite oder die des Webservice an. Die Adresse der Loginseite muss 'login.php' enthalten",
                            e1);
                }
            }
        }
    };

    {
        JPanel panel2 = new JPanel(new BorderLayout());

        panel2.add(labelServer, BorderLayout.NORTH);
        panel2.add(labelClientId, BorderLayout.SOUTH);

        panel.add(panel2, BorderLayout.NORTH);
    }
    {
        JPanel panel2 = new JPanel(new BorderLayout());

        JPanel panel3 = new JPanel(new GridLayout());
        {
            JButton b = new JButton("Server ndern");
            b.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    promptInputServer.run();
                }
            });
            panel3.add(b);

            b = new JButton("Client Id ndern");
            b.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    String s = JOptionPane.showInputDialog(panel, "Client Id eingeben",
                            serverAndClientId.getObjectB());
                    if (s != null) {
                        serverAndClientId.setObjectB(s);
                        labelClientId.setText("Client Id: " + serverAndClientId.getObjectB());
                    }

                }
            });
            panel3.add(b);

            b = new JButton("Client Id automatisch ermitteln");
            b.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    findOutClientId.run();
                }
            });
            panel3.add(b);
        }
        panel2.add(panel3, BorderLayout.NORTH);

        panel3 = new JPanel(new GridLayout(0, 2, 5, 2));
        {
            panel3.add(new JLabel("Loginmethode: "));
            comboboxLoginType = new JComboBox<LoginType>();
            FunctionsX.setComboBoxLayoutString(comboboxLoginType, new ObjectDoInterface<LoginType, String>() {

                @Override
                public String doSomething(LoginType loginType) {
                    switch (loginType) {
                    case DEFAULT:
                        return "Standard";
                    case LDAP:
                        return "LDAP";
                    case CAS:
                        return "CAS";
                    default:
                        return "<Fehler>";
                    }
                }

            });
            val model = ((DefaultComboBoxModel<LoginType>) comboboxLoginType.getModel());
            for (LoginType loginType : LoginType.values()) {
                model.addElement(loginType);
            }
            model.setSelectedItem(iliasProperties.getLoginType());
            panel3.add(comboboxLoginType);

            JLabel label = new JLabel("Dateien herunterladen ber:");
            label.setToolTipText("Die restliche Kommunikation luft immer ber den SOAP Webservice");
            panel3.add(label);
            comboboxDownloadMethod = new JComboBox<DownloadMethod>();
            FunctionsX.setComboBoxLayoutString(comboboxDownloadMethod,
                    new ObjectDoInterface<DownloadMethod, String>() {

                        @Override
                        public String doSomething(DownloadMethod downloadMethod) {
                            switch (downloadMethod) {
                            case WEBSERVICE:
                                return "SOAP Webservice (Standard)";
                            case WEBDAV:
                                return "WEBDAV";
                            default:
                                return "<Fehler>";
                            }
                        }

                    });
            val model2 = ((DefaultComboBoxModel<DownloadMethod>) comboboxDownloadMethod.getModel());
            for (DownloadMethod downloadMethod : DownloadMethod.values()) {
                model2.addElement(downloadMethod);
            }
            model2.setSelectedItem(iliasProperties.getDownloadMethod());
            panel3.add(comboboxDownloadMethod);
        }
        panel2.add(panel3, BorderLayout.WEST);

        panel.add(panel2, BorderLayout.SOUTH);
    }

    if (noConfigDoneYet) {
        promptInputServer.run();
    }

    if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(mainFrame, panel, "Server konfigurieren",
            JOptionPane.OK_CANCEL_OPTION)) {
        if (syncService != null) {
            syncService.logoutIfLoggedIn();
        }
        iliasProperties.setIliasServerURL(serverAndClientId.getObjectA());
        iliasProperties.setIliasClient(serverAndClientId.getObjectB());
        iliasProperties.setLoginType((LoginType) comboboxLoginType.getSelectedItem());
        iliasProperties.setDownloadMethod((DownloadMethod) comboboxDownloadMethod.getSelectedItem());
        saveProperties(iliasProperties);
        updateTitleCaption();
    }

}