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:org.accretegb.modules.germplasm.stockannotation.StockAnnotationPanel.java

private JPanel addStockPanelToolButtons() {
    JPanel panel = new JPanel();
    panel.setLayout(new MigLayout("insets 0 0 0 0, gapx 0"));
    List<Integer> editableColumns = new ArrayList<Integer>();
    editableColumns.add(stockTablePanel.getTable().getIndexOf(ColumnConstants.ACCESSION));
    editableColumns.add(stockTablePanel.getTable().getIndexOf(ColumnConstants.PEDIGREE));
    editableColumns.add(stockTablePanel.getTable().getIndexOf(ColumnConstants.GENERATION));
    stockTablePanel.getTable().setEditableColumns(editableColumns);
    ;//from   w  ww  .  j  ava 2 s  . c  o m
    JButton importStockList = new JButton("Import Stocks By Search");
    JButton importHarvestGroup = new JButton("Import Stocks From Harvest Group");
    JPanel subPanel1 = new JPanel();
    subPanel1.setLayout(new MigLayout("insets 0 0 0 0, gapx 0"));
    subPanel1.add(importStockList, "gapRight 10");
    subPanel1.add(importHarvestGroup, "gapRight 10, wrap");
    panel.add(subPanel1, "gapLeft 10, spanx,wrap");
    importStockList.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            StocksInfoPanel stockInfoPanel = CreateStocksInfoPanel
                    .createStockInfoPanel("stock annotation popup");
            stockInfoPanel.setSize(new Dimension(500, 400));
            int option = JOptionPane.showConfirmDialog(null, stockInfoPanel, "Search Stock Packets",
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
            ArrayList<Integer> stockIds = new ArrayList<Integer>();

            if (option == JOptionPane.OK_OPTION) {
                DefaultTableModel model = (DefaultTableModel) stockTablePanel.getTable().getModel();
                CheckBoxIndexColumnTable stocksOutputTable = stockInfoPanel.getSaveTablePanel().getTable();
                for (int row = 0; row < stocksOutputTable.getRowCount(); ++row) {
                    int stockId = (Integer) stocksOutputTable.getValueAt(row,
                            stocksOutputTable.getIndexOf(ColumnConstants.STOCK_ID));
                    stockIds.add(stockId);
                }
                List<Stock> stocks = StockDAO.getInstance().getStocksByIds(stockIds);
                for (Stock stock : stocks) {
                    Object[] rowData = new Object[stockTablePanel.getTable().getColumnCount()];
                    rowData[0] = new Boolean(false);
                    Passport passport = stock.getPassport();
                    StockGeneration generation = stock.getStockGeneration();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.STOCK_NAME)] = stock
                            .getStockName();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.STOCK_ID)] = stock
                            .getStockId();
                    rowData[stockTablePanel.getTable()
                            .getIndexOf(ColumnConstants.GENERATION)] = generation == null ? null
                                    : generation.getGeneration();
                    rowData[stockTablePanel.getTable().getIndexOf(
                            ColumnConstants.PASSPORT_ID)] = passport == null ? null : passport.getPassportId();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.ACCESSION)] = passport == null
                            ? null
                            : passport.getAccession_name();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.PEDIGREE)] = passport == null
                            ? null
                            : passport.getPedigree();
                    rowData[stockTablePanel.getTable().getIndexOf(
                            ColumnConstants.CLASSIFICATION_CODE)] = passport.getClassification() == null ? null
                                    : passport.getClassification().getClassificationCode();
                    rowData[stockTablePanel.getTable().getIndexOf(
                            ColumnConstants.CLASSIFICATION_ID)] = passport.getClassification() == null ? null
                                    : passport.getClassification().getClassificationId();
                    rowData[stockTablePanel.getTable()
                            .getIndexOf(ColumnConstants.POPULATION)] = passport.getTaxonomy() == null ? null
                                    : passport.getTaxonomy().getPopulation();
                    rowData[stockTablePanel.getTable()
                            .getIndexOf(ColumnConstants.TAXONOMY_ID)] = passport.getTaxonomy() == null ? null
                                    : passport.getTaxonomy().getTaxonomyId();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.MODIFIED)] = new Boolean(
                            false);
                    model.addRow(rowData);
                }

            }

        }

    });

    importHarvestGroup.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            ArrayList<PMProject> projects = TokenRelationDAO.getInstance()
                    .findProjectObjects(LoginScreen.loginUserId);
            HashMap<String, Harvesting> name_tap = new HashMap<String, Harvesting>();
            for (PMProject project : projects) {
                List<HarvestingGroup> HarvestingGroups = HarvestingGroupDAO.getInstance()
                        .findByProjectid(project.getProjectId());
                for (HarvestingGroup hg : HarvestingGroups) {
                    Harvesting harvestingPanel = (Harvesting) getContext()
                            .getBean("Harvesting - " + project.getProjectId() + hg.getHarvestingGroupName());
                    name_tap.put(project.getProjectName() + "-" + hg.getHarvestingGroupName(), harvestingPanel);
                }

            }
            JPanel popup = new JPanel(new MigLayout("insets 0, gap 5"));
            JScrollPane jsp = new JScrollPane(popup) {
                @Override
                public Dimension getPreferredSize() {
                    return new Dimension(250, 320);
                }
            };
            ButtonGroup group = new ButtonGroup();
            for (String name : name_tap.keySet()) {
                JRadioButton button = new JRadioButton(name);
                group.add(button);
                popup.add(button, "wrap");

                button.setSelected(true);
            }
            String selected_group = null;
            int option = JOptionPane.showConfirmDialog(null, jsp, "Select Harvesting Group Name: ",
                    JOptionPane.OK_CANCEL_OPTION);
            if (option == JOptionPane.OK_OPTION) {
                for (Enumeration<AbstractButton> buttons = group.getElements(); buttons.hasMoreElements();) {
                    AbstractButton button = buttons.nextElement();
                    if (button.isSelected()) {
                        selected_group = button.getText();

                    }
                }
            }
            if (selected_group != null) {
                Harvesting harvestingPanel = name_tap.get(selected_group);
                DefaultTableModel model = (DefaultTableModel) stockTablePanel.getTable().getModel();
                ArrayList<String> stocknames = harvestingPanel.getStickerGenerator().getCreatedStocks();
                List<Stock> stocks = StockDAO.getInstance().getStocksByNames(stocknames);
                for (Stock stock : stocks) {
                    Object[] rowData = new Object[stockTablePanel.getTable().getColumnCount()];
                    rowData[0] = new Boolean(false);
                    Passport passport = stock.getPassport();
                    StockGeneration generation = stock.getStockGeneration();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.STOCK_NAME)] = stock
                            .getStockName();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.STOCK_ID)] = stock
                            .getStockId();
                    rowData[stockTablePanel.getTable()
                            .getIndexOf(ColumnConstants.GENERATION)] = generation == null ? null
                                    : generation.getGeneration();
                    rowData[stockTablePanel.getTable().getIndexOf(
                            ColumnConstants.PASSPORT_ID)] = passport == null ? null : passport.getPassportId();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.ACCESSION)] = passport == null
                            ? null
                            : passport.getAccession_name();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.PEDIGREE)] = passport == null
                            ? null
                            : passport.getPedigree();

                    rowData[stockTablePanel.getTable().getIndexOf(
                            ColumnConstants.CLASSIFICATION_CODE)] = passport.getClassification() == null ? null
                                    : passport.getClassification().getClassificationCode();
                    rowData[stockTablePanel.getTable().getIndexOf(
                            ColumnConstants.CLASSIFICATION_ID)] = passport.getClassification() == null ? null
                                    : passport.getClassification().getClassificationId();
                    rowData[stockTablePanel.getTable()
                            .getIndexOf(ColumnConstants.POPULATION)] = passport.getTaxonomy() == null ? null
                                    : passport.getTaxonomy().getPopulation();
                    rowData[stockTablePanel.getTable()
                            .getIndexOf(ColumnConstants.TAXONOMY_ID)] = passport.getTaxonomy() == null ? null
                                    : passport.getTaxonomy().getTaxonomyId();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.MODIFIED)] = new Boolean(
                            false);
                    model.addRow(rowData);
                }
            }

        }

    });
    getstockTablePanel().getTable().addFocusListener(new FocusAdapter() {
        public void focusLost(FocusEvent e) {
            int row = getstockTablePanel().getTable().getSelectionModel().getAnchorSelectionIndex();
            getstockTablePanel().getTable().setValueAt(true, row,
                    getstockTablePanel().getTable().getIndexOf(ColumnConstants.MODIFIED));
        }
    });
    JPanel subPanel2 = new JPanel();
    subPanel2.setLayout(new MigLayout("insets 0 0 0 0 , gapx 0"));
    subPanel2.add(new JLabel("Pedigree: "));
    this.pedigreeField = new JTextField(10);
    subPanel2.add(pedigreeField);
    JButton setPedigree = new JButton("set");
    setPedigree.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            for (int row : getstockTablePanel().getTable().getSelectedRows()) {
                getstockTablePanel().getTable().setValueAt(pedigreeField.getText(), row,
                        getstockTablePanel().getTable().getIndexOf(ColumnConstants.PEDIGREE));
                getstockTablePanel().getTable().setValueAt(true, row,
                        getstockTablePanel().getTable().getIndexOf(ColumnConstants.MODIFIED));
            }
        }
    });
    subPanel2.add(setPedigree, "gapRight 15");

    subPanel2.add(new JLabel("Accession: "));
    this.accessionField = new JTextField(10);
    subPanel2.add(accessionField);
    JButton setAccession = new JButton("set");
    setAccession.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            for (int row : getstockTablePanel().getTable().getSelectedRows()) {
                getstockTablePanel().getTable().setValueAt(accessionField.getText(), row,
                        getstockTablePanel().getTable().getIndexOf(ColumnConstants.ACCESSION));
                getstockTablePanel().getTable().setValueAt(true, row,
                        getstockTablePanel().getTable().getIndexOf(ColumnConstants.MODIFIED));

            }
        }
    });
    subPanel2.add(setAccession, "gapRight 15");

    subPanel2.add(new JLabel("Generarion: "));
    this.generarionField = new JTextField(10);
    subPanel2.add(generarionField);
    JButton setGeneration = new JButton("set");
    setGeneration.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            for (int row : getstockTablePanel().getTable().getSelectedRows()) {
                getstockTablePanel().getTable().setValueAt(generarionField.getText(), row,
                        getstockTablePanel().getTable().getIndexOf(ColumnConstants.GENERATION));
                getstockTablePanel().getTable().setValueAt(true, row,
                        getstockTablePanel().getTable().getIndexOf(ColumnConstants.MODIFIED));
            }
        }
    });
    subPanel2.add(setGeneration);

    panel.add(subPanel2, "gapLeft 10,spanx");
    return panel;

}

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

/**
 * actions after click edit button associated with Classification Code table
 *///ww  w . j  av a2  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
 *//*  w w w.  ja v a 2 s .com*/
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 edit button associated with Taxonomy table
 *///from   w  ww .jav a  2 s  . c  om
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
 *///  ww w  .  j  a  v  a 2s  .  c om
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();
        }
    });
}

From source file:org.alex73.skarynka.scan.ui.scan.ScanDialogController.java

private ScanDialogController(PanelEditController panelController) {
    this.panelController = panelController;
    this.book = panelController.getBook();
    int currentZoom = DataStorage.device.getZoom();

    Dimension[] deviceImageSizes = DataStorage.device.getImageSize();
    Dimension imageSize = deviceImageSizes[0];
    for (int i = 1; i < deviceImageSizes.length; i++) {
        if (!imageSize.equals(deviceImageSizes[i])) {
            JOptionPane.showMessageDialog(DataStorage.mainFrame,
                    Messages.getString("ERROR_WRONG_NOTEQUALSSIZE"), Messages.getString("ERROR_TITLE"),
                    JOptionPane.ERROR_MESSAGE);
            return;
        }/*  w w w.j  a v  a2 s .  c om*/
    }

    int pagesCount = book.getPagesCount();
    if (pagesCount > 0) {
        int bookZoom = book.zoom;

        if (bookZoom != currentZoom) {
            if (JOptionPane.showConfirmDialog(DataStorage.mainFrame,
                    Messages.getString("ERROR_WRONG_ZOOM", pagesCount, bookZoom, currentZoom),
                    Messages.getString("ERROR_TITLE"), JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.WARNING_MESSAGE) != JOptionPane.OK_OPTION) {
                return;
            }
        }
        if (imageSize.width != book.imageSizeX || imageSize.height != book.imageSizeY) {
            if (JOptionPane.showConfirmDialog(DataStorage.mainFrame,
                    Messages.getString("ERROR_WRONG_IMAGESIZE", pagesCount,
                            s(new Dimension(book.imageSizeX, book.imageSizeY)), s(imageSize)),
                    Messages.getString("ERROR_TITLE"), JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.WARNING_MESSAGE) != JOptionPane.OK_OPTION) {
                return;
            }
            for (String page : book.listPages()) {
                Book2.PageInfo pi = book.getPageInfo(page);
                pi.cropPosX = Integer.MIN_VALUE;
                pi.cropPosY = Integer.MIN_VALUE;
            }
        }
    }

    book.zoom = currentZoom;
    book.imageSizeX = imageSize.width;
    book.imageSizeY = imageSize.height;
    String dpi = Context.getSettings().get("dpi." + book.zoom);
    if (dpi != null) {
        book.dpi = Integer.parseInt(dpi);
    } else {
        book.dpi = 300;
    }

    dialog = new ScanDialog(DataStorage.mainFrame, true);
    dialog.btnClose.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    });

    dialog.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosed(WindowEvent e) {
            DataStorage.device.setPreviewPanels();
            panelController.show();
        }
    });

    init(dialog.controlLeft, dialog.liveLeft);
    init(dialog.controlRight, dialog.liveRight);

    checkNumbers();
    showStatus();

    boolean[] visible = DataStorage.device.setPreviewPanels(dialog.liveLeft, dialog.liveRight);
    dialog.controlLeft.setVisible(visible[0]);
    dialog.controlRight.setVisible(visible[1]);
    dialog.liveLeft.setVisible(visible[0]);
    dialog.liveRight.setVisible(visible[1]);

    int[] rotations = DataStorage.device.getRotations();
    dialog.liveLeft.setRotation(rotations[0]);
    dialog.liveRight.setRotation(rotations[1]);

    dialog.setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());
    dialog.validate();
    dialog.controlLeft.txtNumber.setVisible(false);
    dialog.controlLeft.txtNumber.setVisible(false);

    int keyCode = HIDScanController.getKeyCode(Context.getSettings().get("hidscan-keys"));
    if (keyCode != 0) {
        addAction(keyCode, actionScan);
    }
    if (keyCode != KeyEvent.VK_F1) {
        addAction(KeyEvent.VK_F1, actionScan);
    }
    dialog.btnScan.addActionListener(actionScan);
    addAction(KeyEvent.VK_F2, actionRescan);
    dialog.btnRescan.addActionListener(actionRescan);

    dialog.setVisible(true);
}

From source file:org.apache.cayenne.modeler.action.ImportDataMapAction.java

protected void importDataMap() {
    File dataMapFile = selectDataMap(Application.getFrame());
    if (dataMapFile == null) {
        return;/*from w  w  w  .j a v  a2 s. c om*/
    }

    DataMap newMap;

    try {
        URL url = dataMapFile.toURI().toURL();

        try (InputStream in = url.openStream();) {
            InputSource inSrc = new InputSource(in);
            inSrc.setSystemId(dataMapFile.getAbsolutePath());
            newMap = new MapLoader().loadDataMap(inSrc);
        }

        ConfigurationNode root = getProjectController().getProject().getRootNode();
        newMap.setName(NameBuilder.builder(newMap, root).baseName(newMap.getName()).name());

        Resource baseResource = ((DataChannelDescriptor) root).getConfigurationSource();

        if (baseResource != null) {
            Resource dataMapResource = baseResource
                    .getRelativeResource(nameMapper.configurationLocation(newMap));
            newMap.setConfigurationSource(dataMapResource);
        }

        getProjectController().addDataMap(this, newMap);
    } catch (Exception ex) {
        logObj.info("Error importing DataMap.", ex);
        JOptionPane.showMessageDialog(Application.getFrame(), "Error reading DataMap: " + ex.getMessage(),
                "Can't Open DataMap", JOptionPane.OK_OPTION);
    }
}

From source file:org.apache.cayenne.modeler.action.OpenProjectAction.java

/** Opens specified project file. File must already exist. */
public void openProject(File file) {
    try {//from   w w w  .j  av  a  2s  .  c o m
        if (!file.exists()) {
            JOptionPane.showMessageDialog(Application.getFrame(),
                    "Can't open project - file \"" + file.getPath() + "\" does not exist", "Can't Open Project",
                    JOptionPane.OK_OPTION);
            return;
        }

        CayenneModelerController controller = Application.getInstance().getFrameController();
        controller.addToLastProjListAction(file.getAbsolutePath());

        URL url = file.toURL();
        Resource rootSource = new URLResource(url);

        ProjectUpgrader upgrader = getApplication().getInjector().getInstance(ProjectUpgrader.class);
        UpgradeHandler handler = upgrader.getUpgradeHandler(rootSource);
        UpgradeMetaData md = handler.getUpgradeMetaData();

        if (UpgradeType.DOWNGRADE_NEEDED == md.getUpgradeType()) {
            JOptionPane.showMessageDialog(Application.getFrame(),
                    "Can't open project - it was created using a newer version of the Modeler",
                    "Can't Open Project", JOptionPane.OK_OPTION);
            closeProject(false);
        } else if (UpgradeType.INTERMEDIATE_UPGRADE_NEEDED == md.getUpgradeType()) {
            JOptionPane.showMessageDialog(Application.getFrame(),
                    // TODO: andrus 05/02/2010 - this message shows intermediate
                    // version of the project XML, not the Modeler code
                    // version that
                    // can be used for upgrade
                    "Can't upgrade project. Open the project in the Modeler v."
                            + md.getIntermediateUpgradeVersion()
                            + " to do an intermediate upgrade before you can upgrade to v."
                            + md.getSupportedVersion(),
                    "Can't Upgrade Project", JOptionPane.OK_OPTION);
            closeProject(false);
        } else if (UpgradeType.UPGRADE_NEEDED == md.getUpgradeType()) {
            if (processUpgrades(md)) {
                // perform upgrade
                logObj.info("Will upgrade project " + url.getPath());
                Resource upgraded = handler.performUpgrade();
                if (upgraded != null) {
                    Project project = openProjectResourse(upgraded, controller);

                    getProjectController().getFileChangeTracker().pauseWatching();
                    getProjectController().getFileChangeTracker().reconfigure();

                    // if project file name changed
                    // need upgrade all
                    if (!file.getAbsolutePath().equals(project.getConfigurationResource().getURL().getPath())) {
                        controller.changePathInLastProjListAction(file.getAbsolutePath(),
                                project.getConfigurationResource().getURL().getPath());
                    }
                } else {
                    closeProject(false);
                }
            }
        } else {
            openProjectResourse(rootSource, controller);
        }
    } catch (Exception ex) {
        logObj.warn("Error loading project file.", ex);
        ErrorDebugDialog.guiWarning(ex, "Error loading project");
    }
}

From source file:org.apache.syncope.ide.netbeans.view.ResourceExplorerTopComponent.java

private void leafRightClickAction(final MouseEvent evt, final DefaultMutableTreeNode node) {
    JPopupMenu menu = new JPopupMenu();
    JMenuItem deleteItem = new JMenuItem("Delete");
    menu.add(deleteItem);//w w w. j  a  v a2  s. co  m

    deleteItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            int result = JOptionPane.showConfirmDialog(null, "Are you sure to delete the item?");
            if (result == JOptionPane.OK_OPTION) {
                DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
                boolean deleted;
                if (parent.getUserObject().equals(PluginConstants.MAIL_TEMPLATES)) {
                    deleted = mailTemplateManagerService.delete((String) node.getUserObject());
                } else {
                    deleted = reportTemplateManagerService.delete((String) node.getUserObject());
                }
                if (deleted) {
                    node.removeFromParent();
                    treeModel.reload(parent);
                } else {
                    JOptionPane.showMessageDialog(null, "Error while deleting new element", "Error",
                            JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    });

    menu.show(evt.getComponent(), evt.getX(), evt.getY());
}

From source file:org.archiviststoolkit.mydomain.DomainTableWorkSurface.java

public void onDelete() {
    selectedRow = this.getTable().getSelectedRow();
    if (selectedRow != -1) {
        int response = JOptionPane.showConfirmDialog(ApplicationFrame.getInstance(),
                "Are you sure you want to delete " + table.getSelectedRows().length + " record(s)",
                "Delete records", JOptionPane.YES_NO_OPTION);
        if (response == JOptionPane.OK_OPTION) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    int[] selectedRows = table.getSelectedRows();

                    if (selectedRows.length != 0) {
                        onRemoveGroup(selectedRows);
                    }//from ww  w  . j  a v  a  2s  . c om
                }
            });
        }
    } else {
        JOptionPane.showMessageDialog(dialog, "You must select at least one record to delete.");
    }
}