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:op.FrmMain.java

public void afterLogin() {
    OPDE.getDisplayManager().touch();/*from   w  w w  .j  a  v a2 s. c  om*/
    dlgLogin = null;

    if (OPDE.isTraining()) {
        JTextPane txtMessage = new JTextPane();
        txtMessage.setFont(new Font("Arial", Font.PLAIN, 18));
        txtMessage.setEditable(false);
        txtMessage.setContentType("text/html");
        txtMessage.setText(SYSTools.toHTMLForScreen(SYSTools.xx("opde.general.training.version.message")));

        JOptionPane.showConfirmDialog(this, txtMessage, SYSTools.xx("opde.general.training.version.title"),
                JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
    }

    if (specialities != null) {
        synchronized (specialities) {
            SYSTools.clear(specialities);
        }
    }

    specialities = Collections.synchronizedMap(new HashMap<Integer, Set<Resident>>());
    synchronized (specialities) {
        specialities.put(ResInfoTypeTools.TYPE_ABSENCE, new HashSet<Resident>());
        specialities.put(ResInfoTypeTools.TYPE_INFECTION, new HashSet<Resident>());
        specialities.put(ResInfoTypeTools.TYPE_WARNING, new HashSet<Resident>());
        specialities.put(ResInfoTypeTools.TYPE_ALLERGY, new HashSet<Resident>());
        specialities.put(ResInfoTypeTools.TYPE_DIABETES, new HashSet<Resident>());

        for (ResInfo info : ResInfoTools.getSpecialInfos()) {
            specialities.get(info.getResInfoType().getType()).add(info.getResident());
        }
    }

    prepareSearchArea();
    labelUSER.setText(OPDE.getLogin().getUser().getFullname());

    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            initPhase = true;
            double pos;
            try {
                pos = Double.parseDouble(
                        OPDE.getProps().getProperty("opde.mainframe:splitPaneLeftDividerLocation"));
            } catch (Exception e) {
                pos = 0.5d;
            }
            splitPaneLeft.setDividerLocation(0, SYSTools.getDividerInAbsolutePosition(splitPaneLeft, pos));
            initPhase = false;
            homeButton.doClick();
        }
    };

    SwingUtilities.invokeLater(runnable);
}

From source file:openqcm.mainGUI.java

/**
 * Creates new form mainGUI//from  w ww  .ja va 2s .c  om
 */
public mainGUI() {
    // Show the splash screen
    appInit();

    // Generated code initialize GUI components
    initComponents();
    CommentSection cs = new CommentSection();
    cs.setVisible(true);
    jButton3.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // display/center the jdialog when the button is pressed
            DateFormat df = new SimpleDateFormat("HH:mm:ss");
            Date dateobj = new Date();
            cs.addData(df.format(dateobj), jTextArea1.getText().toString());
        }

    });
    //add listener to the button
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent we) {
            String ObjButtons[] = { "Yes", "No" };
            int PromptResult = JOptionPane.showOptionDialog(null, "Are you sure you want to exit?",
                    "Online Examination System", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null,
                    ObjButtons, ObjButtons[1]);
            if (PromptResult == 0) {
                System.exit(0);
            }
        }

    });

    // Register a RawDataListener to receive data from Arduino.
    link.addRawDataListener(this);
}

From source file:org.accretegb.modules.germplasm.stockannotation.StockAnnotationPanel.java

/**
 * actions after click upload, clear buttons associated with Classification Code table, and actions after click inside ClassificationCode
 * table/*from w  w w .  j av  a2 s  .  c om*/
 */
private void addClassificationCodeListeners() {

    classificationTablePanel.getEditButton().setEnabled(false);
    classificationTablePanel.getDeleteButton().setEnabled(false);
    classificationTablePanel.getUploadButton().setEnabled(false);
    classificationTablePanel.getClearButton().setEnabled(false);

    addClassificationCodeAddButtonListener();
    addClassificationCodeEditButtonListener();
    addClassificationCodeDeleteButtonListener();

    classificationTablePanel.getUploadButton().addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            int validRow = 0;
            int selectedRows[] = stockTablePanel.getTable().getSelectedRows();
            //System.out.print("\nselected row" + stockTablePanel.getTable().getSelectedRowCount());
            Integer sampVal = (Integer) ((DefaultTableModel) classificationTable.getModel()).getValueAt(
                    classificationSelectedRow,
                    classificationTable.getColumn("Classification id").getModelIndex());
            String germplasm = (String) ((DefaultTableModel) classificationTable.getModel()).getValueAt(
                    classificationSelectedRow,
                    classificationTable.getColumn("Classification Code").getModelIndex());
            for (int rowCounter = 0; rowCounter < stockTablePanel.getTable()
                    .getSelectedRowCount(); rowCounter++) {
                // only selected rows can be uploaded with data.
                if (!StringUtils
                        .isEmpty(String.valueOf(stockTablePanel.getTable().getValueAt(selectedRows[rowCounter],
                                stockTablePanel.getTable().getColumn(ColumnConstants.ACCESSION)
                                        .getModelIndex())))
                        || !(StringUtils.isEmpty(String.valueOf(
                                stockTablePanel.getTable().getValueAt(selectedRows[rowCounter], stockTablePanel
                                        .getTable().getColumn(ColumnConstants.PEDIGREE).getModelIndex()))))) {
                    stockTablePanel.getTable().setValueAt(sampVal, selectedRows[rowCounter],
                            stockTablePanel.getTable().getIndexOf(ColumnConstants.CLASSIFICATION_ID));
                    stockTablePanel.getTable().setValueAt(germplasm, selectedRows[rowCounter],
                            stockTablePanel.getTable().getIndexOf(ColumnConstants.CLASSIFICATION_CODE));
                    validRow++;
                }
            }
            ((DefaultTableModel) classificationTable.getModel()).setValueAt(false, classificationSelectedRow,
                    0);
            if (validRow != stockTablePanel.getTable().getSelectedRowCount()) {
                // AccreteGBLogger.logger.log(Level.INFO,
                // "Either Acceesion or Pedigree is mandatory for uploading");
                JOptionPane.showConfirmDialog(StockAnnotationPanel.this,
                        "Either Acceesion or Pedigree is mandatory for uploading", "Warning!",
                        JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);
            }
            clearClassificationCodeSelection();
        }
    });
    classificationTablePanel.getClearButton().addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            for (int rowCounter = 0; rowCounter < stockTablePanel.getTable().getRowCount(); rowCounter++) {
                if (!StringUtils.isEmpty(String.valueOf(stockTablePanel.getTable().getValueAt(rowCounter,
                        stockTablePanel.getTable().getColumn(ColumnConstants.ACCESSION).getModelIndex())))
                        || !(StringUtils.isEmpty(
                                String.valueOf(stockTablePanel.getTable().getValueAt(rowCounter, stockTablePanel
                                        .getTable().getColumn(ColumnConstants.PEDIGREE).getModelIndex()))))) {
                    stockTablePanel.getTable().setValueAt("", rowCounter,
                            stockTablePanel.getTable().getColumn("Classification id").getModelIndex());
                    stockTablePanel.getTable().setValueAt("", rowCounter,
                            stockTablePanel.getTable().getColumn("Classification Code").getModelIndex());
                }
            }
        }
    });
    classificationTable.addMouseListener(new MouseAdapter() {

        public void mouseReleased(MouseEvent e) {
            int row = classificationTable.getSelectedRow();
            classificationSelectedRow = row;
            if (row != -1) {
                classificationTablePanel.getEditButton().setEnabled(true);
                classificationTablePanel.getDeleteButton().setEnabled(true);
                if (stockTablePanel.getTable().getSelectedRowCount() > 0) {
                    classificationTablePanel.getUploadButton().setEnabled(true);
                }

            } else {
                classificationTablePanel.getEditButton().setEnabled(false);
                classificationTablePanel.getDeleteButton().setEnabled(false);
                classificationTablePanel.getUploadButton().setEnabled(false);
            }
        }
    });
}

From source file:org.accretegb.modules.germplasm.stockannotation.StockAnnotationPanel.java

/**
 * actions after click delete button associated with Classification Code table
 *///  w  w w .jav  a 2  s  .c  o  m
private void addClassificationCodeDeleteButtonListener() {
    classificationTablePanel.getDeleteButton().addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

            int selrow = classificationTable.getSelectedRow();
            int selcolumn = 0;

            String columnName = classificationTable.getColumnName(selcolumn + 1);
            String sampval = (String) classificationTable.getValueAt(selrow,
                    classificationTable.getColumn(ColumnConstants.CLASSIFICATION_CODE).getModelIndex());

            try {

                List<Passport> parentPassports = PassportDAO.getInstance().findByClassificationCode(sampval);
                if (parentPassports.size() > 0) {
                    if (LoggerUtils.isLogEnabled())
                        LoggerUtils.log(Level.INFO, "Classification Code has passport associated with " + "it. "
                                + "Cannot " + "delete");
                    JOptionPane.showConfirmDialog(StockAnnotationPanel.this,
                            "Cannot delete classification_code associated with passports", "Error!",
                            JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);
                    classificationTable.setValueAt(false, selrow, 0);
                    classificationTable.clearSelection();
                } else {
                    ClassificationDAO.getInstance().delete(sampval);
                    ((DefaultTableModel) classificationTable.getModel())
                            .removeRow(classificationTable.convertRowIndexToModel(selrow));
                    classificationTable.setForeground(Color.BLACK);
                    classificationSelectedRow = -1;
                }
            } catch (HibernateException ex) {
                if (LoggerUtils.isLogEnabled())
                    LoggerUtils.log(Level.INFO, ex.toString());
            }
            clearClassificationCodeSelection();
        }
    });
}

From source file:org.accretegb.modules.germplasm.stockannotation.StockAnnotationPanel.java

/**
 * actions after click edit button associated with Classification Code table
 *//*from   w  w  w. j  a va 2  s  . c  o m*/
private void addClassificationCodeEditButtonListener() {
    classificationTablePanel.getEditButton().addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

            classificationTablePanel.getDeleteButton().setEnabled(true);
            classificationTablePanel.getEditButton().setEnabled(true);

            JPanel newSource = new JPanel(new MigLayout("insets 0, gapx 0"));

            String labelNames[] = { "<HTML>Classification Code<FONT COLOR = Red>*" + "</FONT></HTML>",
                    "<HTML>Classification Type<FONT COLOR = Red>*" + "</FONT></HTML>" };

            int selRow = classificationTable.getSelectedRow();
            String oldClassificationCode = (String) classificationTable.getValueAt(selRow,
                    classificationTable.getColumn(ColumnConstants.CLASSIFICATION_CODE).getModelIndex());
            String oldGermplasm = (String) classificationTable.getValueAt(selRow,
                    classificationTable.getColumn("Classification Type").getModelIndex());

            String values[] = { oldClassificationCode, oldGermplasm };

            boolean validInput = false;
            JLabel labels[] = new JLabel[labelNames.length];
            final JTextField textBoxes[] = new JTextField[labelNames.length];

            for (int labelCounter = 0; labelCounter < labels.length; labelCounter++) {
                labels[labelCounter] = new JLabel(labelNames[labelCounter]);
                newSource.add(labels[labelCounter], "gapleft 10, push");
                textBoxes[labelCounter] = new JTextField();
                textBoxes[labelCounter].setPreferredSize(new Dimension(200, 0));
                textBoxes[labelCounter].setText(values[labelCounter]);
                newSource.add(textBoxes[labelCounter], "gapRight 10, wrap");
            }

            do {
                for (int textBoxCounter = 0; textBoxCounter < labelNames.length; textBoxCounter++)
                    textBoxes[textBoxCounter].setText(values[textBoxCounter]);

                int option = JOptionPane.showConfirmDialog(StockAnnotationPanel.this, newSource,
                        "Enter New Classification Code Information ", JOptionPane.DEFAULT_OPTION);

                validInput = true;

                if (option == JOptionPane.OK_OPTION) {

                    for (int valuesCounter = 0; valuesCounter < labelNames.length; valuesCounter++) {
                        values[valuesCounter] = textBoxes[valuesCounter].getText();
                        if (labelNames[valuesCounter].indexOf('*') != -1
                                && textBoxes[valuesCounter].getText().equals("")) {
                            if (LoggerUtils.isLogEnabled())
                                LoggerUtils.log(Level.INFO,
                                        labelNames[valuesCounter] + " " + "is " + "mandatory");
                            validInput = false;
                        }
                    }
                    if (validInput) {
                        Object newRow[] = updateClassificationCodeTable(values, oldClassificationCode);
                        ((DefaultTableModel) classificationTable.getModel())
                                .insertRow(classificationTable.getRowCount(), newRow);
                        for (int rowCounter = 0; rowCounter < classificationTable.getRowCount(); rowCounter++)
                            if (((String) classificationTable.getValueAt(rowCounter, classificationTable
                                    .getColumn(ColumnConstants.CLASSIFICATION_CODE).getModelIndex()))
                                            .equals(oldClassificationCode))
                                ((DefaultTableModel) classificationTable.getModel())
                                        .removeRow(classificationTable.convertRowIndexToModel(rowCounter));
                    }
                }

                if (!validInput)
                    JOptionPane.showConfirmDialog(StockAnnotationPanel.this,
                            "<HTML><FONT COLOR = Red>*</FONT> marked fields are mandatory.</HTML>", "Error!",
                            JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);

            } while (!validInput);
            clearClassificationCodeSelection();
        }

    });
}

From source file:org.accretegb.modules.germplasm.stockannotation.StockAnnotationPanel.java

/**
 * actions after click add button associated with Classification Code table
 *///from   w w w.j a va  2  s .  c  o  m
private void addClassificationCodeAddButtonListener() {
    classificationTablePanel.getAddButton().addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            classificationTablePanel.getDeleteButton().setEnabled(false);
            classificationTablePanel.getEditButton().setEnabled(false);

            JPanel newSource = new JPanel(new MigLayout("insets 0, gapx 0"));

            String labelNames[] = { "<HTML>Classification Code<FONT COLOR = Red>*" + "</FONT></HTML>",
                    "<HTML>Classification Type<FONT COLOR = Red>*" + "</FONT></HTML>" };
            String values[] = { "", "" };

            boolean validInput = false;
            JLabel labels[] = new JLabel[labelNames.length];
            final JTextField textBoxes[] = new JTextField[labelNames.length];

            for (int labelCounter = 0; labelCounter < labels.length; labelCounter++) {
                labels[labelCounter] = new JLabel(labelNames[labelCounter]);
                newSource.add(labels[labelCounter], "gapleft 10, push");
                textBoxes[labelCounter] = new JTextField();
                textBoxes[labelCounter].setPreferredSize(new Dimension(200, 0));
                textBoxes[labelCounter].setText(values[labelCounter]);
                newSource.add(textBoxes[labelCounter], "gapRight 10, wrap");
            }

            do {
                for (int textBoxCounter = 0; textBoxCounter < labelNames.length; textBoxCounter++)
                    textBoxes[textBoxCounter].setText(values[textBoxCounter]);

                int option = JOptionPane.showConfirmDialog(StockAnnotationPanel.this, newSource,
                        "Enter New Classification Code Information ", JOptionPane.DEFAULT_OPTION);

                validInput = true;

                if (option == JOptionPane.OK_OPTION) {

                    for (int valuesCounter = 0; valuesCounter < labelNames.length; valuesCounter++) {
                        values[valuesCounter] = textBoxes[valuesCounter].getText();
                        if (labelNames[valuesCounter].indexOf('*') != -1
                                && textBoxes[valuesCounter].getText().equals("")) {
                            if (LoggerUtils.isLogEnabled())
                                LoggerUtils.log(Level.INFO,
                                        labelNames[valuesCounter] + " " + "is " + "mandatory");

                            validInput = false;
                        }
                    }
                    // insert new row to database & insert one row into table of interface
                    if (validInput) {

                        Object newRow[] = new Object[values.length + 2];
                        newRow[0] = new Boolean(false);
                        for (int columnCounter = 2; columnCounter < newRow.length; columnCounter++)
                            newRow[columnCounter] = values[columnCounter - 2];

                        try {
                            newRow[1] = ClassificationDAO.getInstance().insert(values).getClassificationId()
                                    .toString();
                        } catch (HibernateException ex) {
                            if (LoggerUtils.isLogEnabled())
                                LoggerUtils.log(Level.INFO, ex.toString());
                        }
                        ((DefaultTableModel) classificationTable.getModel())
                                .insertRow(classificationTable.getRowCount(), newRow);
                    }
                }
                if (!validInput)
                    JOptionPane.showConfirmDialog(StockAnnotationPanel.this,
                            "<HTML><FONT COLOR = Red>*</FONT> marked fields are mandatory.</HTML>", "Error!",
                            JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);

            } while (!validInput);

            clearClassificationCodeSelection();
        }
    });
}

From source file:org.accretegb.modules.germplasm.stockannotation.StockAnnotationPanel.java

/**
 * actions after click upload, clear buttons associated with Taxonomy table, and actions after click taxonomy table
 *//*from w  w  w.  j  av  a2  s  .c  o m*/
private void addTaxonomyListeners() {

    // no edit, delete, upload, clear functions allowed
    taxonomyTablePanel.getEditButton().setEnabled(false);
    taxonomyTablePanel.getDeleteButton().setEnabled(false);
    taxonomyTablePanel.getUploadButton().setEnabled(false);
    taxonomyTablePanel.getClearButton().setEnabled(false);

    // add, edit, delete button listener
    addTaxonomyAddButtonListener();
    addTaxonomyEditButtonListener();
    addTaxonomyDeleteButtonListener();

    // actions after click upload button
    taxonomyTablePanel.getUploadButton().addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            int validRow = 0;
            int selectedRows[] = stockTablePanel.getTable().getSelectedRows();
            String taxVal = (String) ((DefaultTableModel) taxonomyTable.getModel())
                    .getValueAt(taxonomySelectedRow, taxonomyTable.getColumn("Taxonomy id").getModelIndex());
            String value = ""
                    + ((String) ((DefaultTableModel) taxonomyTable.getModel()).getValueAt(taxonomySelectedRow,
                            taxonomyTable.getColumn("Genus").getModelIndex())).charAt(0)
                    + ((String) ((DefaultTableModel) taxonomyTable.getModel()).getValueAt(
                            taxonomySelectedRow, taxonomyTable.getColumn("Species").getModelIndex())).charAt(0)
                    + " ("
                    + ((String) ((DefaultTableModel) taxonomyTable.getModel()).getValueAt(taxonomySelectedRow,
                            taxonomyTable.getColumn("Race").getModelIndex()))
                    + ") "
                    + ((String) ((DefaultTableModel) taxonomyTable.getModel()).getValueAt(taxonomySelectedRow,
                            taxonomyTable.getColumn(ColumnConstants.POPULATION).getModelIndex()));

            for (int rowCounter = 0; rowCounter < stockTablePanel.getTable()
                    .getSelectedRowCount(); rowCounter++) {
                // only selected rows can be uploaded data.
                if (!StringUtils
                        .isEmpty(String.valueOf(stockTablePanel.getTable().getValueAt(selectedRows[rowCounter],
                                stockTablePanel.getTable().getColumn(ColumnConstants.ACCESSION)
                                        .getModelIndex())))
                        || !(StringUtils.isEmpty(String.valueOf(
                                stockTablePanel.getTable().getValueAt(selectedRows[rowCounter], stockTablePanel
                                        .getTable().getColumn(ColumnConstants.PEDIGREE).getModelIndex()))))) {
                    stockTablePanel.getTable().setValueAt(taxVal, selectedRows[rowCounter],
                            stockTablePanel.getTable().getColumn("Taxonomy id").getModelIndex());
                    stockTablePanel.getTable().setValueAt(value, selectedRows[rowCounter],
                            stockTablePanel.getTable().getColumn("Population").getModelIndex());
                    validRow++;
                }
            }

            if (validRow != stockTablePanel.getTable().getSelectedRowCount()) {
                // AccreteGBLogger.logger.log(Level.INFO,
                // "Either Acceesion or Pedigree is mandatory for uploading");
                JOptionPane.showConfirmDialog(StockAnnotationPanel.this,
                        "Either Acceesion or Pedigree is mandatory for uploading", "Warning!",
                        JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);
            }
            ((DefaultTableModel) taxonomyTable.getModel()).setValueAt(false, taxonomySelectedRow, 0);
            clearTaxonomySelection();
        }
    });

    // actions after click clear button
    taxonomyTablePanel.getClearButton().addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            for (int rowCounter = 0; rowCounter < stockTablePanel.getTable().getRowCount(); rowCounter++) {
                if ((Boolean) stockTablePanel.getTable().getValueAt(rowCounter, 0) == true) {
                    stockTablePanel.getTable().setValueAt("", rowCounter,
                            stockTablePanel.getTable().getColumn("Taxonomy id").getModelIndex());
                    stockTablePanel.getTable().setValueAt("", rowCounter,
                            stockTablePanel.getTable().getColumn("Population").getModelIndex());
                }
            }
        }
    });

    // actions to do after click taxonomy table
    taxonomyTable.addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent e) {
            int row = taxonomyTable.getSelectedRow();
            taxonomySelectedRow = row;
            if (row != -1) {
                taxonomyTablePanel.getEditButton().setEnabled(true);
                taxonomyTablePanel.getDeleteButton().setEnabled(true);
                if (stockTablePanel.getTable().getRowCount() > 0) {
                    taxonomyTablePanel.getUploadButton().setEnabled(true);
                }

            } else {
                taxonomyTablePanel.getEditButton().setEnabled(false);
                taxonomyTablePanel.getDeleteButton().setEnabled(false);
                taxonomyTablePanel.getUploadButton().setEnabled(false);
            }
        }
    });
}

From source file:org.accretegb.modules.germplasm.stockannotation.StockAnnotationPanel.java

/**
 * actions after delete button associated with Taxonomy table
 *///from  w  w  w.j  a  va  2 s . c o  m
private void addTaxonomyDeleteButtonListener() {

    taxonomyTablePanel.getDeleteButton().addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            int selrow = taxonomyTable.getSelectedRow();
            int selcolumn = 0;

            // String columnName = taxonomyTable.getColumnName(selcolumn + 1);
            String taxval = (String) taxonomyTable.getModel().getValueAt(taxonomySelectedRow,
                    taxonomyTable.getColumn("Taxonomy id").getModelIndex());

            // actions on database

            try {
                // can't delete if a passport is associate with this taxonomy id
                List<Passport> parentPassports = PassportDAO.getInstance()
                        .findByTaxonomy(Integer.parseInt(taxval));
                if (parentPassports.size() > 0) {
                    if (LoggerUtils.isLogEnabled()) {
                        LoggerUtils.log(Level.INFO,
                                "Taxonomy has passport associated " + "with it. Cannot delete");
                    }
                    JOptionPane.showConfirmDialog(StockAnnotationPanel.this,
                            "Cannot delete taxonomy associated with passports", "Error!",
                            JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);
                    taxonomyTable.setValueAt(false, selrow, 0);
                    taxonomyTable.clearSelection();
                }
                // otherwise delete record from database and delete row from table
                else {
                    TaxonomyDAO.getInstance().delete(Integer.parseInt(taxval));
                    for (int i = 0; i < ((DefaultTableModel) taxonomyTable.getModel()).getRowCount(); i++)
                        if (i == taxonomySelectedRow) {
                            ((DefaultTableModel) taxonomyTable.getModel())
                                    .removeRow(taxonomyTable.convertRowIndexToModel(i));
                            break;
                        }
                    // no selected row after delete
                    taxonomySelectedRow = -1;
                    taxonomyTable.setForeground(Color.BLACK);
                }
            } catch (HibernateException ex) {
                if (LoggerUtils.isLogEnabled()) {
                    LoggerUtils.log(Level.INFO, ex.toString());
                }
            }
            clearTaxonomySelection();
        }
    });
}

From source file:org.accretegb.modules.germplasm.stockannotation.StockAnnotationPanel.java

/**
 * actions after edit button associated with Taxonomy table
 *///from   www . j  a  v  a 2s.  co  m
private void addTaxonomyEditButtonListener() {
    taxonomyTablePanel.getEditButton().addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

            taxonomyTablePanel.getDeleteButton().setEnabled(false);
            taxonomyTablePanel.getEditButton().setEnabled(false);

            // create a new panel for edit interface
            JPanel newSource = new JPanel(new MigLayout("insets 0, gapx 0"));

            String labelNames[] = { "<HTML>Genus<FONT COLOR = Red>*" + "</FONT></HTML>",
                    "<HTML>Species Type<FONT COLOR = Red>*" + "</FONT></HTML>", "Subspecies", "Subtaxa", "Race",
                    "Common Name", ColumnConstants.POPULATION, "Gto" };

            // get current selected row
            int selRow = taxonomyTable.getSelectedRow();
            String values[] = { taxonomyTable.getValueAt(selRow, 2).toString(),
                    taxonomyTable.getValueAt(selRow, 3).toString(),
                    taxonomyTable.getValueAt(selRow, 4) == null ? ""
                            : taxonomyTable.getValueAt(selRow, 4).toString(),
                    taxonomyTable.getValueAt(selRow, 5) == null ? ""
                            : taxonomyTable.getValueAt(selRow, 5).toString(),
                    taxonomyTable.getValueAt(selRow, 6) == null ? ""
                            : taxonomyTable.getValueAt(selRow, 6).toString(),
                    taxonomyTable.getValueAt(selRow, 7) == null ? ""
                            : taxonomyTable.getValueAt(selRow, 7).toString(),
                    taxonomyTable.getValueAt(selRow, 8) == null ? ""
                            : taxonomyTable.getValueAt(selRow, 8).toString(),
                    taxonomyTable.getValueAt(selRow, 9) == null ? ""
                            : taxonomyTable.getValueAt(selRow, 9).toString() };

            // check if input is valid
            boolean validInput = false;

            // create new components for edit interface
            JLabel labels[] = new JLabel[labelNames.length];
            final JTextField textBoxes[] = new JTextField[labelNames.length];

            // add components to new panel, write data from table to text field
            for (int columnIndex = 0; columnIndex < labels.length; columnIndex++) {
                labels[columnIndex] = new JLabel(labelNames[columnIndex]);
                newSource.add(labels[columnIndex], "gapleft 10, push");

                textBoxes[columnIndex] = new JTextField();
                textBoxes[columnIndex].setPreferredSize(new Dimension(200, 0));
                textBoxes[columnIndex].setText(values[columnIndex]);
                newSource.add(textBoxes[columnIndex], "gapRight 10, wrap");
            }

            do {
                // after editing, reset text for textfield
                for (int textBoxCounter = 0; textBoxCounter < labelNames.length; textBoxCounter++)
                    textBoxes[textBoxCounter].setText(values[textBoxCounter]);

                // showConfirmDialog(Component parentComponent, Object message, String title, int optionType)
                int option = JOptionPane.showConfirmDialog(StockAnnotationPanel.this, newSource,
                        "Enter New Taxonomy Information ", JOptionPane.DEFAULT_OPTION);
                validInput = true;

                if (option == JOptionPane.OK_OPTION) {

                    for (int valueCounter = 0; valueCounter < labelNames.length; valueCounter++) {
                        values[valueCounter] = textBoxes[valueCounter].getText();
                        if (labelNames[valueCounter].indexOf('*') != -1
                                && textBoxes[valueCounter].getText().equals("")) {
                            if (LoggerUtils.isLogEnabled())
                                LoggerUtils.log(Level.INFO, labelNames[valueCounter] + " is mandatory");
                            validInput = false; // input is invalid
                        }
                    }
                    // if input is valid
                    if (validInput) {
                        // update database
                        Object newRow[] = updateTaxonomyTable(values);
                        // update table
                        ((DefaultTableModel) taxonomyTable.getModel()).insertRow(taxonomyTable.getRowCount(),
                                newRow);
                    }
                }
                // if input is valid
                if (!validInput)
                    JOptionPane.showConfirmDialog(StockAnnotationPanel.this,
                            "<HTML><FONT COLOR = Red>*</FONT> marked fields are mandatory.</HTML>", "Error!",
                            JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);

            } while (!validInput);
            clearTaxonomySelection();
        }
    });
}

From source file:org.accretegb.modules.germplasm.stockannotation.StockAnnotationPanel.java

/**
 * actions after add button associated with Taxonomy table
 *//*from w  w w .j  a v a2  s.  c  o m*/
private void addTaxonomyAddButtonListener() {

    taxonomyTablePanel.getAddButton().addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            taxonomyTablePanel.getDeleteButton().setEnabled(false);
            taxonomyTablePanel.getEditButton().setEnabled(false);

            // interface for adding new record
            JPanel newSource = new JPanel(new MigLayout("insets 0, gapx 0"));

            String labelNames[] = { "<HTML>Genus<FONT COLOR = Red>*" + "</FONT></HTML>",
                    "<HTML>Species Type<FONT COLOR = Red>*" + "</FONT></HTML>", "Subspecies", "Subtaxa", "Race",
                    "Common Name", ColumnConstants.POPULATION, "Gto" };
            String values[] = { "", "", "", "", "", "", "", "" };

            boolean validInput = false;
            JLabel labels[] = new JLabel[labelNames.length];
            final JTextField textBoxes[] = new JTextField[labelNames.length];

            for (int labelIndex = 0; labelIndex < labels.length; labelIndex++) {
                labels[labelIndex] = new JLabel(labelNames[labelIndex]);
                newSource.add(labels[labelIndex], "gapleft 10, push");
                textBoxes[labelIndex] = new JTextField();
                textBoxes[labelIndex].setPreferredSize(new Dimension(200, 0));
                textBoxes[labelIndex].setText(values[labelIndex]);
                newSource.add(textBoxes[labelIndex], "gapRight 10, wrap");
            }

            do {
                for (int columnIndex = 0; columnIndex < labelNames.length; columnIndex++)
                    textBoxes[columnIndex].setText(values[columnIndex]);

                int option = JOptionPane.showConfirmDialog(StockAnnotationPanel.this, newSource,
                        "Enter New Taxonomy Information ", JOptionPane.DEFAULT_OPTION);
                validInput = true;

                if (option == JOptionPane.OK_OPTION) {

                    for (int valueCounter = 0; valueCounter < labelNames.length; valueCounter++) {
                        values[valueCounter] = String.valueOf(textBoxes[valueCounter].getText())
                                .equalsIgnoreCase("") ? "NULL" : textBoxes[valueCounter].getText();
                        if (labelNames[valueCounter].indexOf('*') != -1
                                && textBoxes[valueCounter].getText().equals("")) {
                            if (LoggerUtils.isLogEnabled())
                                LoggerUtils.log(Level.INFO,
                                        labelNames[valueCounter] + " " + "is " + "mandatory");

                            validInput = false;
                        }
                    }
                    if (validInput) {
                        // insert new record to database
                        Object newRow[] = insertTaxonomyValues(values);
                        // insert new row to table
                        ((DefaultTableModel) taxonomyTable.getModel()).insertRow(taxonomyTable.getRowCount(),
                                newRow);
                    }
                }

                if (!validInput)
                    JOptionPane.showConfirmDialog(StockAnnotationPanel.this,
                            "<HTML><FONT COLOR = Red>*</FONT> marked fields are mandatory.</HTML>", "Error!",
                            JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);

            } while (!validInput);
            clearTaxonomySelection();
        }
    });
}