Example usage for javax.swing JOptionPane OK_CANCEL_OPTION

List of usage examples for javax.swing JOptionPane OK_CANCEL_OPTION

Introduction

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

Prototype

int OK_CANCEL_OPTION

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

Click Source Link

Document

Type used for showConfirmDialog.

Usage

From source file:interfaces.InterfazPrincipal.java

private void TablaDeBuscarFacturaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TablaDeBuscarFacturaMouseClicked
    int fila = TablaDeBuscarFactura.getSelectedRow();
    int identificacion = (int) TablaDeBuscarFactura.getValueAt(fila, 1);

    Object opciones[] = { "Imprimir", "Guardar", " Eliminar", "Cancelar" };

    int opcion = JOptionPane.showOptionDialog(this,
            "Que operacin desea realizar con la factura  " + identificacion + "?", "Mensaje del sistema",
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, opciones, null);
    GenerarFactura generarFactura = new GenerarFactura();
    switch (opcion) {
    case 0://from   www . ja  v a2s . c  o m
        generarFactura.imprimirFactura(identificacion, this);
        break;
    case 1:
        PDDocument documento = generarFactura.crearFactura(identificacion, this);
        JFileChooser fc = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter("Archivo PDF", "pdf", "text");
        fc.setFileFilter(filter);
        fc.showSaveDialog(this);
        if (fc.getSelectedFile() != null) {
            File selectedFile = fc.getSelectedFile();
            try {

                documento.save(selectedFile + ".pdf");
                JOptionPane.showMessageDialog(this, "El archivo ha sido guardado en disco");

            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this,
                        "El Archivo no se puede leer!\nInformacin tcnica\n" + ex.toString());
            }
            break;
        }

    case 2:
        int confirmacion = JOptionPane.showConfirmDialog(this,
                "Quieres eliminar la factura " + identificacion + " factura?");

        if (confirmacion == JOptionPane.YES_OPTION) {
            ControladorFactura controladorFactura = new ControladorFactura();
            controladorFactura.deleteFactura(" where factura_id = " + identificacion);
        }
        break;
    case 3:
        break;
    default:
        break;

    }

}

From source file:com.cch.aj.entryrecorder.frame.SettingsJFrame.java

private void btnProductDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnProductDeleteActionPerformed
    int result = JOptionPane.showConfirmDialog(this, "Are you sure to delete this item", "Warning",
            JOptionPane.OK_CANCEL_OPTION);
    if (result == 0) {
        Product currentProduct = ((ComboBoxItem<Product>) this.cbProduct.getSelectedItem()).getItem();
        if ("- Select -".equals(currentProduct.getCode())) {
            return;
        }/*from  w  w w .  j  ava 2 s  .c om*/
        this.productService.DeleteEntity(currentProduct.getId());
        this.UpdateTabProduct(0);
    }
}

From source file:interfaces.InterfazPrincipal.java

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
    ControladorFlujoFactura controladorFlujoFactura = new ControladorFlujoFactura();
    ArrayList<String[]> listado = controladorFlujoFactura.getTodosFlujo_Factura("");
    DefaultTableModel modelo = (DefaultTableModel) TablaDeReporteDiario.getModel();

    if (modelo.getRowCount() > 0) {
        for (int k = modelo.getRowCount() - 1; k > -1; k--) {
            modelo.removeRow(k);//from   ww w  .  j  av  a 2 s  .c o  m
        }
    }
    int contador = 1;
    double abono = 0;
    double deuda = 0;
    for (int i = 0; i < listado.size(); i++) {
        String[] fila = listado.get(i);

        String[] partirEspacios = fila[3].split("\\s");
        //El primer string es la fecha sin hora
        //Ahora esparamos por -
        String[] tomarAgeMesDia = partirEspacios[0].split("-");

        //Realizar filtro
        int ageConsulta = Integer.parseInt(tomarAgeMesDia[0]);
        int mesConsulta = Integer.parseInt(tomarAgeMesDia[1]);
        int diaConsulta = Integer.parseInt(tomarAgeMesDia[2]);
        Calendar fechaDeLaBD = new GregorianCalendar(ageConsulta, mesConsulta, diaConsulta);

        int anioInicial = fechaReporteDiario.getSelectedDate().get(Calendar.YEAR);
        int mesInicial = fechaReporteDiario.getSelectedDate().get(Calendar.MONTH) + 1;
        int diaInicial = fechaReporteDiario.getSelectedDate().get(Calendar.DAY_OF_MONTH);
        Calendar fechaInicialRango = new GregorianCalendar(anioInicial, mesInicial, diaInicial);

        //fechaReporteDiarioHasta
        int anioFinal = fechaReporteDiarioHasta.getSelectedDate().get(Calendar.YEAR);
        int mesFinal = fechaReporteDiarioHasta.getSelectedDate().get(Calendar.MONTH) + 1;
        int diaFinal = fechaReporteDiarioHasta.getSelectedDate().get(Calendar.DAY_OF_MONTH);
        Calendar fechaFinalRango = new GregorianCalendar(anioFinal, mesFinal, diaFinal);

        //System.out.println("antes");
        //System.out.println("Va a comparar" + fechaDeLaBD.toString());
        //System.out.println(" con " + fechaInicialRango.toString());
        if (fechaDeLaBD.compareTo(fechaInicialRango) >= 0 && fechaDeLaBD.compareTo(fechaFinalRango) <= 0) {
            //System.out.println("Entra");
            Object[] row = new Object[5];
            row[0] = (contador);
            contador++;
            row[1] = fila[1];
            row[2] = fila[3];
            row[3] = fila[2];
            row[4] = fila[4];
            modelo.addRow(row);
            //flujo_id","factura_id","tipo_flujo","fecha","valor"
            /*System.out.println("fila 0" + fila[0]);
             System.out.println("fila 1" + fila[1]);
             System.out.println("fila 2" + fila[2]);
             System.out.println("fila 3" + fila[3]);*/
            if (fila[2].equals("abono")) {
                abono += Double.parseDouble(fila[4]);
            } else {
                deuda += Double.parseDouble(fila[4]);
            }
            ;
        }

    }
    ReporteDiarioAbono.setText(abono + "");
    ReporteDiarioDeuda.setText(deuda + "");
    TablaDeReporteDiario.setModel(modelo);
    Object opciones[] = { "Cerrar", "Imprimir", "Guardar en disco" };
    int opcion = JOptionPane.showOptionDialog(this, "Se ha generado el diario solicitado\nQue desea hacer?",
            "Elija una opcin", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, opciones,
            null);
    GenerarReporteDiario generarReporteDiario = new GenerarReporteDiario();
    switch (opcion) {
    case 1:
        generarReporteDiario.imprimiDiario(fechaReporteDiario.getSelectedDate(),
                fechaReporteDiarioHasta.getSelectedDate(), modelo, this);
        break;
    case 2:
        PDDocument documento = generarReporteDiario.crearDiario(fechaReporteDiario.getSelectedDate(),
                fechaReporteDiarioHasta.getSelectedDate(), modelo, this);
        JFileChooser fc = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter("Archivo PDF", "pdf", "text");
        fc.setFileFilter(filter);
        fc.showSaveDialog(this);
        if (fc.getSelectedFile() != null) {
            File selectedFile = fc.getSelectedFile();
            try {

                documento.save(selectedFile + ".pdf");
                JOptionPane.showMessageDialog(this, "El archivo ha sido guardado en disco");

            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, "EL Archivo no se puede leer!");
            }
        }
        break;

    default:
        break;
    }
}

From source file:com.cch.aj.entryrecorder.frame.SettingsJFrame.java

private void btnStaffDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStaffDeleteActionPerformed
    // TODO add your handling code here:
    int result = JOptionPane.showConfirmDialog(this, "Are you sure to delete this item", "Warning",
            JOptionPane.OK_CANCEL_OPTION);
    if (result == 0) {
        Staff currentStaff = ((ComboBoxItem<Staff>) this.cbStaff.getSelectedItem()).getItem();
        if ("- Select -".equals(currentStaff.getName())) {
            return;
        }/*w w  w. ja  v  a 2 s . c o  m*/
        this.staffService.DeleteEntity(currentStaff.getId());
        this.UpdateTabStaff(0);
    }
}

From source file:com.cch.aj.entryrecorder.frame.SettingsJFrame.java

private void btnEmbossingDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEmbossingDeleteActionPerformed
    int result = JOptionPane.showConfirmDialog(this, "Are you sure to delete this item", "Warning",
            JOptionPane.OK_CANCEL_OPTION);
    if (result == 0) {
        Embossing currentEmbossing = ((ComboBoxItem<Embossing>) this.cbEmbossing.getSelectedItem()).getItem();
        if ("- Select -".equals(currentEmbossing.getName())) {
            return;
        }/*from   www .  j a  va2s. com*/
        this.embossingService.DeleteEntity(currentEmbossing.getId());
        this.UpdateTabEmbossing(0);
    }
}

From source file:interfaces.InterfazPrincipal.java

private void tablaMostrarComprasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaMostrarComprasMouseClicked
    // TODO add your handling code here:
    int fila = tablaMostrarCompras.getSelectedRow();
    int identificacion = (int) tablaMostrarCompras.getValueAt(fila, 0);

    Object opciones[] = { "Editar", "Eliminar" };
    ControladorCompraProveedor controladorCompraProveedor = new ControladorCompraProveedor();
    ControladorFlujoCompras controladorFlujoCompras = new ControladorFlujoCompras();

    int opcion = JOptionPane.showOptionDialog(this,
            "Que operacin desea realizar con la compra nmero " + identificacion + "?",
            "Mensaje del sistema", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null,
            opciones, null);//www  .  j  av  a2s.c om
    switch (opcion) {
    case 0:
        String valor = JOptionPane.showInputDialog("Desea cambiar el monto de la compra\nEl monto actual es: "
                + tablaMostrarCompras.getValueAt(fila, 3));
        Double.parseDouble(valor);

        controladorCompraProveedor.editarCompraProveedor(String.valueOf(identificacion), valor);

        //Editar flujos
        //Registrar nueva deuda
        controladorFlujoCompras.registrarFlujoDeuda(String.valueOf(identificacion), valor);
        controladorFlujoCompras.registrarFlujoAbono(String.valueOf(identificacion),
                String.valueOf(tablaMostrarCompras.getValueAt(fila, 3)));

        tablaMostrarCompras.setValueAt(valor, fila, 3);

        try {
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "El monto debe ser numrico", "Error",
                    JOptionPane.ERROR_MESSAGE);
        }
        break;
    case 1:
        int confirmacion = JOptionPane.showConfirmDialog(this,
                "Quieres eliminar la compra nmero " + identificacion + "?");

        if (confirmacion == JOptionPane.YES_OPTION) {
            controladorCompraProveedor
                    .eliminarCompraProveedor(" where  ID_Compra_Proveedor = " + identificacion);
            DefaultTableModel modeloTabla = (DefaultTableModel) tablaMostrarCompras.getModel();
            modeloTabla.removeRow(fila);
            tablaMostrarCompras.setModel(modeloTabla);

            //Eliminar flujo
            controladorFlujoCompras.borrarFlujosDeUnaCompraPorIDDeCompra(String.valueOf(identificacion));
        }
        break;
    default:
        break;
    }
}

From source file:net.sourceforge.squirrel_sql.plugins.sqlscript.table_script.CreateFileOfCurrentSQLCommand.java

/**
 * Create a new unmanaged connection, , which is not associated with the current session.
 * @return a new unmanaged connection or null, if no connection can be created.
 * @throws SQLException //from  w w w .jav a  2s  . c  o m
 */
private ISQLConnection createUnmanagedConnection() throws SQLException {
    ISQLConnection unmanagedConnection = getSession().createUnmanagedConnection();

    if (unmanagedConnection == null) {
        int option = JOptionPane.showConfirmDialog(null,
                "Unable to open a new connection. The current connection will be used instead.",
                "Unable to open a new Connection", JOptionPane.OK_CANCEL_OPTION);
        if (option == JOptionPane.CANCEL_OPTION) {
            return null;
        }
    } else {
        // we didn't want a autocommit
        unmanagedConnection.setAutoCommit(false);
    }
    return unmanagedConnection;
}

From source file:nl.tudelft.goal.SimpleIDE.FilePanel.java

/**
 * Helper method for {@link #handleFileRename(File, File)}. Asks the user
 * which of the given list of file references should be renamed. Returns a
 * new list of nodes that the user has selected. The given list is not
 * altered./* www . j a va  2s.c  om*/
 */
private List<FileNode> filterFiles(List<FileNode> nodes) {

    ArrayList<FileNode> filteredFiles = new ArrayList<FileNode>();

    // show requester which files to change.
    // we can not dump an array of checkboxes into the showOptionDialog
    // because it will show them next to each oter instead of below each
    // other.
    // and because it does not show the OK and Cancel buttons. So we use
    // ConfirmDialog isntead
    JPanel choicespanel = new JPanel();
    choicespanel.setLayout(new BoxLayout(choicespanel, BoxLayout.Y_AXIS));
    choicespanel.add(new JLabel("There are multiple mas's using the renamed file.\n" //$NON-NLS-1$
            + "Please select which ones have to be renamed")); //$NON-NLS-1$
    ArrayList<JCheckBox> choices = new ArrayList<JCheckBox>();
    for (FileNode n : nodes) {
        JCheckBox checkbox = new JCheckBox("" //$NON-NLS-1$
                + ((FileNode) n.getParent()).getFilename());
        choices.add(checkbox);
        choicespanel.add(checkbox);
    }

    int choice = JOptionPane.showConfirmDialog(this, choicespanel, "Select files to rename", //$NON-NLS-1$
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
    if (choice == JOptionPane.CANCEL_OPTION) {
        return null;
    }
    // and finally copy the requested filenames to array
    for (JCheckBox c : choices) {
        if (c.isSelected()) {
            for (FileNode n : nodes) {
                if (c.getText().equals(((FileNode) n.getParent()).getFilename())) {
                    filteredFiles.add(n);
                    break;
                }
            }
        }
    }

    return filteredFiles;
}

From source file:no.java.ems.client.swing.EmsClient.java

public static AuthenticationDialog runAuthenticationDialog(Component component) {
    AuthenticationDialog message = new AuthenticationDialog();
    JOptionPane.showOptionDialog(component, message, "Authenticate", JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.INFORMATION_MESSAGE, null, null, null);
    return message;
}

From source file:nz.govt.natlib.ndha.manualdeposit.bulkupload.BulkUploadForm.java

public boolean confirm(final String message, final boolean useYesNo) {
    int optionType;
    if (useYesNo) {
        optionType = JOptionPane.YES_NO_OPTION;
    } else {/*from  w ww.  ja  va2s . c  om*/
        optionType = JOptionPane.OK_CANCEL_OPTION;
    }
    return (JOptionPane.showConfirmDialog(this, message, "Please Confirm",
            optionType) == JOptionPane.OK_OPTION);
}