Example usage for javax.swing JOptionPane ERROR_MESSAGE

List of usage examples for javax.swing JOptionPane ERROR_MESSAGE

Introduction

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

Prototype

int ERROR_MESSAGE

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

Click Source Link

Document

Used for error messages.

Usage

From source file:com.moneydance.modules.features.importlist.io.DeleteOneOperation.java

@Override
public void execute(final List<File> files) {
    final File file = files.iterator().next();
    // ESCA-JAVA0166: IOException, SecurityException
    try {//w  w  w. j av a  2 s.  c o m
        LOG.info(String.format("Deleting file %s", file.getAbsoluteFile()));
        FileUtils.forceDelete(file);
    } catch (Exception e) { // $codepro.audit.disable caughtExceptions
        LOG.log(Level.WARNING, e.getMessage(), e);
        final String errorMessage = this.localizable.getErrorMessageDeleteFile(file.getName());
        final Object errorLabel = new JLabel(errorMessage);
        JOptionPane.showMessageDialog(null, // no parent component
                errorLabel, null, // no title
                JOptionPane.ERROR_MESSAGE);
    }
}

From source file:com.emr.schemas.DestinationTables.java

/**
 * Creates a new DestinationTables form.
 * @param sourceQuery {@link String} SQL Query for getting the source data.
 * @param selected_columns {@link List} List containing the selected source columns
 * @param sourceTables {@link List} List containing the source tables
 * @param relations {@link String} Relationship between the source tables
 * @param emrConn {@link Connection} KenyaEMR Database Connection object
 *//*from   ww w.  j  a va2s.  c  om*/
public DestinationTables(String sourceQuery, List selected_columns, List sourceTables, String relations,
        Connection emrConn, TableRelationsForm parent) {
    fileManager = null;
    dbManager = null;
    mpiConn = null;

    this.parent = parent;
    this.sourceQuery = sourceQuery;
    this.selected_columns = selected_columns;
    this.sourceTables = sourceTables;
    this.relations = relations;
    this.emrConn = emrConn;

    listModel = new DefaultListModel<String>();
    initComponents();
    this.setClosable(true);

    SourceTablesListener listSelectionListener = new SourceTablesListener(new JTextArea(), listOfTables);

    destinationTablesList.setCellRenderer(new CheckboxListCellRenderer());
    destinationTablesList.addListSelectionListener(listSelectionListener);
    destinationTablesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    //Create KenyaEMR DB connection
    fileManager = new FileManager();
    String[] settings = fileManager.getConnectionSettings("mpi_database.properties", "mpi");
    if (settings == null) {
        //Connection settings not found
        //Open MPIConnectionForm
        JOptionPane.showMessageDialog(null,
                "Database Settings not found. Please set the connection settings for the database first.",
                "MPI Database settings", JOptionPane.ERROR_MESSAGE);

    } else {
        if (settings.length < 1) {
            //Open MPIConnectionForm
            JOptionPane.showMessageDialog(null,
                    "Database Settings not found. Please set the connection settings for the database first.",
                    "MPI Database settings", JOptionPane.ERROR_MESSAGE);

        } else {
            //Connection settings are ok
            //We establish a connection
            dbManager = new DatabaseManager(settings[0], settings[1], settings[3], settings[4], settings[5]);
            mpiConn = dbManager.getConnection();
            if (mpiConn == null) {
                JOptionPane.showMessageDialog(null, "Test Connection Failed", "Connection Test",
                        JOptionPane.ERROR_MESSAGE);
            } else {
                //get emr schema
                getDatabaseMetaData();
            }
        }
    }
}

From source file:model.finance_management.Decision_Helper_Model.java

public void add() {

    getAll();/*from   w ww  .j  a  va  2s .c o m*/
    String sql = "INSERT INTO decision_helper"
            + "(`Daily Profit Goal`,`Monthly Profit Goal`,`Annual Profit Goal`)" + " VALUES(" + "'"
            + this.dailyprofitgoal + "'," + "'" + this.monthlyprofitgoal + "'," + "'" + this.annualprofitgoal
            + "'" + ")";
    System.out.println(sql);

    try {
        pst = con.prepareStatement(sql);
        pst.execute();

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e, "Error", JOptionPane.ERROR_MESSAGE);
    }

}

From source file:com.emr.utilities.CSVLoader.java

/**
* Parse CSV file using OpenCSV library and load in 
* given database table. /*from w  ww .  j ava  2 s  .  c  o  m*/
* @param csvFile {@link String} Input CSV file
* @param tableName {@link String} Database table name to import data
* @param truncateBeforeLoad {@link boolean} Truncate the table before inserting 
*          new records.
 * @param destinationColumns {@link String[]} Array containing the destination columns
*/
public void loadCSV(String csvFile, String tableName, boolean truncateBeforeLoad, String[] destinationColumns,
        List columnsToBeMapped) throws Exception {
    CSVReader csvReader = null;
    if (null == this.connection) {
        throw new Exception("Not a valid connection.");
    }
    try {

        csvReader = new CSVReader(new FileReader(csvFile), this.seprator);

    } catch (Exception e) {
        String stacktrace = org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace(e);
        JOptionPane.showMessageDialog(null, "Error occured while executing file. Error Details: " + stacktrace,
                "File Error", JOptionPane.ERROR_MESSAGE);
        throw new Exception("Error occured while executing file. " + stacktrace);
    }
    String[] headerRow = csvReader.readNext();

    if (null == headerRow) {
        throw new FileNotFoundException(
                "No columns defined in given CSV file." + "Please check the CSV file format.");
    }
    //Get indices of columns to be mapped
    List mapColumnsIndices = new ArrayList();
    for (Object o : columnsToBeMapped) {
        String column = (String) o;
        column = column.substring(column.lastIndexOf(".") + 1, column.length());
        int i;

        for (i = 0; i < headerRow.length; i++) {

            if (headerRow[i].equals(column)) {
                mapColumnsIndices.add(i);
            }
        }
    }

    String questionmarks = StringUtils.repeat("?,", headerRow.length);
    questionmarks = (String) questionmarks.subSequence(0, questionmarks.length() - 1);

    String query = SQL_INSERT.replaceFirst(TABLE_REGEX, tableName);
    query = query.replaceFirst(KEYS_REGEX, StringUtils.join(destinationColumns, ","));
    query = query.replaceFirst(VALUES_REGEX, questionmarks);

    String log_query = query.substring(0, query.indexOf("VALUES("));

    String[] nextLine;
    Connection con = null;
    PreparedStatement ps = null;
    PreparedStatement ps2 = null;
    PreparedStatement reader = null;
    ResultSet rs = null;
    try {
        con = this.connection;
        con.setAutoCommit(false);
        ps = con.prepareStatement(query);

        File file = new File("sqlite/db");
        if (!file.exists()) {
            file.createNewFile();
        }
        db = new SQLiteConnection(file);
        db.open(true);

        //if destination table==person, also add an entry in the table person_identifier
        //get column indices for the person_id and uuid columns
        int person_id_column_index = -1;
        int uuid_column_index = -1;
        int maxLength = 100;
        int firstname_index = -1;
        int middlename_index = -1;
        int lastname_index = -1;
        int clanname_index = -1;
        int othername_index = -1;
        if (tableName.equals("person")) {
            int i;
            ps2 = con.prepareStatement(
                    "insert ignore into person_identifier(person_id,identifier_type_id,identifier) values(?,?,?)");
            for (i = 0; i < headerRow.length; i++) {
                if (headerRow[i].equals("person_id")) {
                    person_id_column_index = i;
                }
                if (headerRow[i].equals("uuid")) {
                    uuid_column_index = i;
                }
                /*if(headerRow[i].equals("first_name")){
                    System.out.println("Found firstname index: " + i);
                    firstname_index=i;
                }
                if(headerRow[i].equals("middle_name")){
                    System.out.println("Found firstname index: " + i);
                    middlename_index=i;
                }
                if(headerRow[i].equals("last_name")){
                    System.out.println("Found firstname index: " + i);
                    lastname_index=i;
                }
                if(headerRow[i].equals("clan_name")){
                    System.out.println("Found firstname index: " + i);
                    clanname_index=i;
                }
                if(headerRow[i].equals("other_name")){
                    System.out.println("Found firstname index: " + i);
                    othername_index=i;
                }*/
            }
        }

        if (truncateBeforeLoad) {
            //delete data from table before loading csv
            try (Statement stmnt = con.createStatement()) {
                stmnt.execute("DELETE FROM " + tableName);
                stmnt.close();
            }
        }
        if (tableName.equals("person")) {
            try (Statement stmt2 = con.createStatement()) {
                stmt2.execute(
                        "ALTER TABLE person CHANGE COLUMN first_name first_name VARCHAR(50) NULL DEFAULT NULL AFTER person_guid,CHANGE COLUMN middle_name middle_name VARCHAR(50) NULL DEFAULT NULL AFTER first_name,CHANGE COLUMN last_name last_name VARCHAR(50) NULL DEFAULT NULL AFTER middle_name;");
                stmt2.close();
            }
        }
        final int batchSize = 1000;
        int count = 0;
        Date date = null;

        while ((nextLine = csvReader.readNext()) != null) {

            if (null != nextLine) {
                int index = 1;
                int person_id = -1;
                String uuid = "";
                int identifier_type_id = 3;
                if (tableName.equals("person")) {
                    reader = con.prepareStatement(
                            "select identifier_type_id from identifier_type where identifier_type_name='UUID'");
                    rs = reader.executeQuery();
                    if (!rs.isBeforeFirst()) {
                        //no uuid row
                        //insert it
                        Integer numero = 0;
                        Statement stmt = con.createStatement();
                        numero = stmt.executeUpdate(
                                "insert into identifier_type(identifier_type_id,identifier_type_name) values(50,'UUID')",
                                Statement.RETURN_GENERATED_KEYS);
                        ResultSet rs2 = stmt.getGeneratedKeys();
                        if (rs2.next()) {
                            identifier_type_id = rs2.getInt(1);
                        }
                        rs2.close();
                        stmt.close();
                    } else {
                        while (rs.next()) {
                            identifier_type_id = rs.getInt("identifier_type_id");
                        }
                    }

                }
                int counter = 1;
                String temp_log = log_query + "VALUES("; //string to be logged

                for (String string : nextLine) {
                    //if current index is in the list of columns to be mapped, we apply that mapping
                    for (Object o : mapColumnsIndices) {
                        int i = (int) o;
                        if (index == (i + 1)) {
                            //apply mapping to this column
                            string = applyDataMapping(string);
                        }
                    }
                    if (tableName.equals("person")) {
                        //get person_id and uuid

                        if (index == (person_id_column_index + 1)) {
                            person_id = Integer.parseInt(string);
                        }

                        if (index == (uuid_column_index + 1)) {
                            uuid = string;
                        }

                    }
                    //check if string is a date
                    if (string.matches("\\d{2}-[a-zA-Z]{3}-\\d{4} \\d{2}:\\d{2}:\\d{2}")
                            || string.matches("\\d{2}-[a-zA-Z]{3}-\\d{4}")) {
                        java.sql.Date dt = formatDate(string);
                        temp_log = temp_log + "'" + dt.toString() + "'";
                        ps.setDate(index++, dt);
                    } else {
                        if ("".equals(string)) {
                            temp_log = temp_log + "''";
                            ps.setNull(index++, Types.NULL);
                        } else {
                            temp_log = temp_log + "'" + string + "'";
                            ps.setString(index++, string);
                        }

                    }
                    if (counter < headerRow.length) {
                        temp_log = temp_log + ",";
                    } else {
                        temp_log = temp_log + ");";
                        System.out.println(temp_log);
                    }
                    counter++;
                }
                if (tableName.equals("person")) {
                    if (!"".equals(uuid) && person_id != -1) {
                        ps2.setInt(1, person_id);
                        ps2.setInt(2, identifier_type_id);
                        ps2.setString(3, uuid);

                        ps2.addBatch();
                    }
                }

                ps.addBatch();
            }
            if (++count % batchSize == 0) {
                ps.executeBatch();
                if (tableName.equals("person")) {
                    ps2.executeBatch();
                }
            }
        }
        ps.executeBatch(); // insert remaining records
        if (tableName.equals("person")) {
            ps2.executeBatch();
        }

        con.commit();
    } catch (Exception e) {
        if (con != null)
            con.rollback();
        if (db != null)
            db.dispose();
        String stacktrace = org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace(e);
        JOptionPane.showMessageDialog(null, "Error occured while executing file. Error Details: " + stacktrace,
                "File Error", JOptionPane.ERROR_MESSAGE);
        throw new Exception("Error occured while executing file. " + stacktrace);
    } finally {
        if (null != reader)
            reader.close();
        if (null != ps)
            ps.close();
        if (null != ps2)
            ps2.close();
        if (null != con)
            con.close();

        csvReader.close();
    }
}

From source file:serial.ChartFromSerial.java

/**
 * Creates new form JavaArduinoInterfacingAttempt
 *///from  www .j  a  v  a 2s .  c  o m
public ChartFromSerial() {
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        System.out.println(e);
    }
    initComponents();

    //set autoscroll
    autoScroll_chkBx.setSelected(true);
    autoScrollEnabled = true;

    //create the graph
    defaultSeries = new XYSeries(graphName);
    defaultDataset = new XYSeriesCollection(defaultSeries);
    defaultChart = ChartFactory.createXYLineChart(graphName, xAxisLabel, yAxisLabel, defaultDataset);
    graph = new ChartPanel(defaultChart);
    chartPanel.add(graph, BorderLayout.CENTER);
    graph.setVisible(true);

    //create the text log
    text = new JTextArea();
    text.setEditable(false);
    textScrollPane = new JScrollPane(text);
    textScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    textPanel.add(textScrollPane, BorderLayout.CENTER);
    textScrollPane.setVisible(true);

    //Populate the combo box
    portNames = SerialPort.getCommPorts();
    while (portNames.length == 0) {
        if (JOptionPane.showConfirmDialog(rootPane, "No connected devices found.\nWould you like to refresh?",
                "Could not connect to any devices.", JOptionPane.YES_NO_OPTION,
                JOptionPane.ERROR_MESSAGE) == JOptionPane.NO_OPTION) {
            buttonsOff();
            return;
        } else {
            portNames = SerialPort.getCommPorts();
        }
    }
    portList_jCombo.removeAllItems();
    for (SerialPort portName : portNames) {
        portList_jCombo.addItem(portName.getSystemPortName());
    }
}

From source file:br.com.topsys.cd.applet.AssinaturaApplet.java

public String assinar(byte[] dados) {
    String retorno = null;/*from  ww  w.ja  v a  2  s  .  c  om*/

    try {

        X509Certificado certificadoAux = new X509Certificado(Base64.decodeBase64(this.certificado));

        if (certificadoAux.equals(this.certificadoDigital.getX509Certificado())) {

            retorno = Base64.encodeBase64String(
                    new AssinaturaDigital().assinarDocumento(this.certificadoDigital, dados));

        } else {

            JOptionPane.showMessageDialog(null, "Certificado digital diferente do usurio do sistema!",
                    "Aviso", JOptionPane.ERROR_MESSAGE);
        }

    } catch (CertificadoDigitalException | ExcecaoX509 ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage(), "Aviso", JOptionPane.ERROR_MESSAGE);
        this.closeError();
    }

    return retorno;

}

From source file:com.sec.ose.osi.UIMain.java

private static boolean isRunning() {
    log.debug("Running Test...");
    String execCMD = "";
    String protexStr = "";
    String osName = System.getProperty("os.name").toLowerCase();
    if (osName.indexOf("win") >= 0) {
        // windows
        execCMD = "TASKLIST /V /FO CSV /FI \"IMAGENAME eq javaw.exe\" /NH";
        protexStr = "osit";
    } else if (osName.indexOf("nix") >= 0 || osName.indexOf("nux") >= 0) {
        execCMD = "ps -ef";
        protexStr = "java -jar ./lib/" + OSIT_JAR_FILE_NAME;
    } else {/*www . j  a v  a2s .  co m*/
        JOptionPane.showMessageDialog(null, osName + " is not supported. The program will be closed.", "Error",
                JOptionPane.ERROR_MESSAGE);
        //         System.exit(-1);
    }

    InputStreamReader isr = null;
    try {
        Process p = Runtime.getRuntime().exec(execCMD);
        isr = new InputStreamReader(p.getInputStream(), "UTF-8");
        BufferedReader reader = new BufferedReader(isr);

        String str = null;
        int count = 0;
        while ((str = reader.readLine()) != null) {
            log.debug("### ONLY ONE OSI PROCESS CHECK : " + str.toLowerCase());
            if (str.toLowerCase().contains(protexStr.toLowerCase())) {
                if (++count > 1) {
                    reader.close();
                    return true;
                }
            }
        }
    } catch (IOException e1) {
        log.warn(e1.getMessage());
    } finally {
        try {
            if (isr != null) {
                isr.close();
            }
        } catch (Exception e) {
            log.debug(e);
        }
    }
    return false;
}

From source file:it.unibo.alchemist.utils.L.java

private static void log(final Level level, final String message) {
    LOGGER.log(level, message);//ww w  . j a  va 2  s.c om
    flush();
    if (gui && level.equals(Level.SEVERE)) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                JOptionPane.showMessageDialog(null, message, "Error", JOptionPane.ERROR_MESSAGE);
            }
        });
    }
}

From source file:com.emr.utilities.DatabaseManager.java

/**
 * Close the connection//  www .ja va 2s .  c  o  m
 */
public void cleanUp() {
    try {
        if (conn != null)
            conn.close();
    } catch (SQLException se) {
        String stacktrace = org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace(se);
        JOptionPane.showMessageDialog(null, "Error occured while executing file. Error Details: " + stacktrace,
                "File Error", JOptionPane.ERROR_MESSAGE);

    }
}

From source file:edu.harvard.mcz.imagecapture.data.UnitTrayLabelTableModel.java

public void addRow() {
    UnitTrayLabel newLabel = new UnitTrayLabel();
    UnitTrayLabelLifeCycle uls = new UnitTrayLabelLifeCycle();
    try {//from  w  ww  .jav  a 2 s. c o m
        //TODO: Finish making this a configuration option.
        int nextOrdinalMethod = NEXT_ORDINAL_ZERO;
        int nextOrdinal = 0;
        if (nextOrdinalMethod == NEXT_ORDINAL_MAXPLUSONE) {
            nextOrdinal = uls.findMaxOrdinal() + 1;
        }
        if (nextOrdinalMethod == NEXT_ORDINAL_ZERO) {
            nextOrdinal = 0;
        }
        newLabel.setOrdinal(nextOrdinal);
        uls.persist(newLabel);
        this.labels.add(newLabel);
        this.fireTableDataChanged();
    } catch (SaveFailedException e1) {
        JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(),
                "Save of new record failed.\n" + e1.getMessage(), "Save Failed", JOptionPane.ERROR_MESSAGE);
    }
}