public void run() {
    // Class Method Instances
    File file;
    String msg, resourceMesg1, resourceMesg2;

    // Begin Execution of getting the
    // file and trying a load.

    file = new File(fileName);

    if (file.exists()) {
      // Importing data setting configuration
      // from state file
      loadState();
    } else {
      resourceMesg1 =
          resourceBundle.getResourceString(
              "LoadTableSQLStatement.dialogmessage.TheFile", "The File");

      resourceMesg2 =
          resourceBundle.getResourceString(
              "LoadTableSQLStatement.dialogmessage.DoesNotExist", "does not exists.");

      msg = resourceMesg1 + " " + fileName + " " + resourceMesg2;
      JOptionPane.showMessageDialog(null, msg, fileName, JOptionPane.ERROR_MESSAGE);
    }
  }
  private void loadState() {
    // Class Method Instances.
    byte[] dump;
    String dumpData, delimiter;
    String[] stateContent;
    String tableName, sqlQueryStatementString;
    String resourceTitleAlert, resourceError;

    // Obtain the data bytes from the selected file.
    dump = ReadDataFile.mainReadDataString(fileName, false);

    if (dump != null) {
      // System.out.println(new String(dump));
      dumpData = Utils.stateConvert(dump, true);
      // System.out.println(dumpData);

      if (!dumpData.equals("")) {
        delimiter = TableTabPanel.getStateDelimiter();

        // Data collected from file so now process to set a table state.

        if (dumpData.indexOf(delimiter) != -1) {
          stateContent = dumpData.split(delimiter);
          tableName = stateContent[0];
          sqlQueryStatementString = stateContent[4];
          // System.out.println(tableName + ": " + sqlQueryStatementString);

          if (selectedPanel.equals(Profiler_MenuBar.ACTION_FIELD_INFORMATION))
            TableFieldChartsPanel.setQueryStatement(tableName, sqlQueryStatementString);
          else if (selectedPanel.equals(Profiler_MenuBar.ACTION_FIELD_NUMBER_ANALYSIS))
            TableFieldAnalysisPanel.setQueryStatement(tableName, sqlQueryStatementString);
          else if (selectedPanel.equals(Profiler_MenuBar.ACTION_FIELD_CLUSTER_ANALYSIS))
            TableFieldClusterAnalysisPanel.setQueryStatement(tableName, sqlQueryStatementString);
        } else {
          resourceTitleAlert =
              resourceBundle.getResourceString("LoadTableSQLStatement.dialogtitle.Alert", "Alert");

          resourceError =
              resourceBundle.getResourceString(
                  "LoadTableSQLStatement.dialogmessage.UnableToDecode",
                  "Unable to Decode Configuration. Possible Corrupt File!");

          JOptionPane.showMessageDialog(
              null, resourceError, resourceTitleAlert, JOptionPane.ERROR_MESSAGE);
        }
      }
    }
  }
  public LoadSQLData(
      JavaFX_Charts fxcharts,
      String query,
      AResourceBundle resourceBundle,
      boolean showProgressBar) {
    this.fxcharts = fxcharts;
    this.resourceBundle = resourceBundle;
    this.showProgressBar = showProgressBar;

    // Initalize & Execute.
    dataSourceType = ConnectionManager.getDataSourceType();
    resourceTitleAlert = resourceBundle.getResourceString("LoadSQLData.dialogtitle.Alert", "Alert");
    execute(query);
  }
  protected Mapper_ToolBar(
      String title,
      Main_Frame parent,
      String path,
      AResourceBundle resourceBundle,
      MenuActionListener plugin) {
    super(title);
    mainFrame = parent;
    menuListener = plugin;

    // Constructor Instances
    String iconsDirectory, resource;
    ImageIcon openIcon, exitIcon;
    ImageIcon editPreferencesIcon;
    ImageIcon csvIcon;
    ImageIcon sqlQueryBucketIcon;
    JButton buttonItem;

    // Setting up icons directory and other instances.

    buttonItem = null;
    iconsDirectory = "images/icons/";

    // Tool Bar Configuration.
    setBorder(BorderFactory.createLoweredBevelBorder());
    setFloatable(false);

    // ===============
    // File Menu

    openIcon = resourceBundle.getResourceImage(iconsDirectory + "openIcon.png");

    resource = resourceBundle.getResourceString("Mapper_ToolBar.menu.Open", "Open");
    buttonItem = buttonItem(resource, openIcon, Mapper_MenuBar.ACTION_FILE_OPEN);
    add(buttonItem);

    // Exit
    exitIcon = resourceBundle.getResourceImage(iconsDirectory + "exitIcon.png");

    buttonItem = new JButton(exitIcon);
    buttonItem.setFocusable(false);
    buttonItem.setMargin(new Insets(0, 0, 0, 0));
    buttonItem.setActionCommand(MenuActionCommands.ACTION_EXIT);
    buttonItem.addActionListener(mainFrame);

    resource = resourceBundle.getResourceString("Mapper_ToolBar.menu.Exit", "Exit");
    buttonItem.setToolTipText(resource);
    add(buttonItem);

    addSeparator();

    // ===============
    // Edit Preferences

    editPreferencesIcon = resourceBundle.getResourceImage(iconsDirectory + "preferencesIcon.png");

    resource =
        resourceBundle.getResourceString(
            "Mapper_ToolBar.menu.SingleVariablePlots", "Single Variable Plots");
    buttonItem =
        buttonItem(
            resource,
            editPreferencesIcon,
            Mapper_MenuBar.ACTION_EDIT_PREFERENCES_SINGLE_VARIABLE_PLOTS);
    add(buttonItem);

    addSeparator();

    // ===============
    // Data Menu

    csvIcon = resourceBundle.getResourceImage(iconsDirectory + "csvImportIcon.png");

    resource =
        resourceBundle.getResourceString("Mapper_ToolBar.menu.ImportCSVFile", "Import CSV File");
    buttonItem = buttonItem(resource, csvIcon, Mapper_MenuBar.ACTION_DATA_IMPORT_CSV);
    add(buttonItem);

    addSeparator();

    // ===============
    // Tool Menu

    // SQL Query Bucket
    sqlQueryBucketIcon = resourceBundle.getResourceImage(iconsDirectory + "sqlQueryBucketIcon.png");

    buttonItem = new JButton(sqlQueryBucketIcon);
    buttonItem.setFocusable(false);
    buttonItem.setMargin(new Insets(0, 0, 0, 0));
    buttonItem.setActionCommand(MenuActionCommands.ACTION_SQL_QUERY_BUCKET);
    buttonItem.addActionListener(mainFrame);

    resource =
        resourceBundle.getResourceString("Mapper_ToolBar.menu.SQLQueryBucket", "SQL Query Bucket");
    buttonItem.setToolTipText(resource);
    add(buttonItem);
  }
  private void loadData(SQLQuery sqlQuery, Connection dbConnection) throws SQLException {
    // Class Method Instances
    String chartType;
    FX_Series fx_series;

    Object[] content;
    ProgressBar loadProgressBar;

    Iterator<String> columnNamesIterator;

    String columnName, columnClass, columnType;
    int columnSize;
    int rowsCount;
    int currentRow;
    int fieldPosition;
    boolean validInsert;
    boolean isContentNull;

    Object currentContentData;

    String sqlStatementString;
    Statement sqlStatement;
    ResultSet db_resultSet;

    // Set the type of series to be used.

    chartType = fxcharts.getChartType();

    if (chartType.equals(JavaFX_Charts.LINE_CHART)
        || chartType.equals(JavaFX_Charts.AREA_CHART)
        || chartType.equals(JavaFX_Charts.BUBBLE_CHART)
        || chartType.equals(JavaFX_Charts.SCATTER_CHART)) fx_series = new LineChartSeries("Data 0");
    else if (chartType.equals(JavaFX_Charts.CATEGORY_LINE_CHART)
        || chartType.equals(JavaFX_Charts.BAR_CHART)) fx_series = new BarChartSeries("Data 0");
    else if (chartType.equals(JavaFX_Charts.HORIZONTAL_BAR_CHART))
      fx_series = new HBarChartSeries("Data 0");
    else if (chartType.equals(JavaFX_Charts.PIE_CHART)) fx_series = new PieChartSeries("Data 0");
    else return;

    // Collect the row count of the table and setting
    // up a progress bar for tracking/canceling.

    currentRow = 0;
    fieldPosition = 0;
    validInsert = true;
    isContentNull = false;

    loadProgressBar = new ProgressBar("Load SQL Data");
    rowsCount = sqlQuery.getRowCount(dbConnection, dataSourceType);

    if (showProgressBar) {
      loadProgressBar.setTaskLength(rowsCount);
      loadProgressBar.pack();
      loadProgressBar.center();
    }
    loadProgressBar.setVisible(showProgressBar);

    // Setup the chart axis names and temporary content
    // storage.

    if (sqlQuery.getColumnNames().size() == 1) {
      fxcharts.getChartPane().setChartXAxisLabel("Line Index");
      fxcharts.getChartPane().setChartYAxisLabel(sqlQuery.getColumnNames().get(0));
    } else {
      fxcharts.getChartPane().setChartXAxisLabel(sqlQuery.getColumnNames().get(0));
      fxcharts.getChartPane().setChartYAxisLabel(sqlQuery.getColumnNames().get(1));
    }

    if (sqlQuery.getColumnNames().size() <= 2) content = new Object[2];
    else content = new Object[3];

    // Ok now ready so beginning by creating a SQL Statement
    // for data and proceeding with building the data to load.

    sqlStatement = null;
    db_resultSet = null;

    try {
      sqlStatement = dbConnection.createStatement();

      // Setting up to begin collecting information
      // on the given SQL statement.

      sqlStatementString = sqlQuery.getSQLQuery();

      // System.out.println(sqlStatementString);
      db_resultSet = sqlStatement.executeQuery(sqlStatementString);

      // Begin loading the data into the plot series.

      while (db_resultSet.next() && !loadProgressBar.isCanceled() && validInsert) {
        loadProgressBar.setCurrentValue(currentRow++);
        columnNamesIterator = sqlQuery.getColumnNames().iterator();

        while (columnNamesIterator.hasNext() && fieldPosition < content.length) {
          columnName = columnNamesIterator.next();
          columnClass = sqlQuery.getColumnClassHashMap().get(columnName);
          columnType = sqlQuery.getColumnTypeNameHashMap().get(columnName);
          columnSize = sqlQuery.getColumnSizeHashMap().get(columnName).intValue();

          // System.out.println(columnName + " " + columnClass + " " + columnType
          //                    + " " + columnSize + " ");

          // DATE Type Field
          if (columnType.equals("DATE")) {
            currentContentData = db_resultSet.getDate(columnName);

            if (currentContentData == null) {
              if (ASSIGN_NULL_ZERO)
                setNullData(sqlQuery.getColumnNames().size(), content, fieldPosition, currentRow);
              else isContentNull = true;
            } else {
              String dateString;

              if ((fieldPosition == 0
                      && (chartType.equals(JavaFX_Charts.BAR_CHART)
                          || chartType.equals(JavaFX_Charts.CATEGORY_LINE_CHART)
                          || chartType.equals(JavaFX_Charts.PIE_CHART)))
                  || (fieldPosition == 1 && chartType.equals(JavaFX_Charts.HORIZONTAL_BAR_CHART))
                  || (fieldPosition == 0
                      && sqlQuery.getColumnNames().size() == 1
                      && chartType.equals(JavaFX_Charts.HORIZONTAL_BAR_CHART)))
                dateString =
                    Utils.convertDBDateString_To_ViewDateString(
                        currentContentData + "",
                        DBTablesPanel.getGeneralDBProperties().getViewDateFormat());
              else {
                dateString = (currentContentData + "").replaceAll("-", "");
                dateString = dateString.substring(0, 4) + "." + dateString.substring(4);
              }

              if (sqlQuery.getColumnNames().size() == 1) {
                content[fieldPosition] = currentRow + "";
                content[1] = dateString;
              } else content[fieldPosition] = dateString;
            }
          }

          // TIME Type Fields
          else if (columnType.equals("TIME")
              || columnType.equals("TIMETZ")
              || columnType.equals("TIME WITH TIME ZONE")) {
            currentContentData = db_resultSet.getTime(columnName);

            if (currentContentData == null) {
              if (ASSIGN_NULL_ZERO)
                setNullData(sqlQuery.getColumnNames().size(), content, fieldPosition, currentRow);
              else isContentNull = true;
            } else {
              String timeString;

              if ((fieldPosition == 0
                      && (chartType.equals(JavaFX_Charts.BAR_CHART)
                          || chartType.equals(JavaFX_Charts.CATEGORY_LINE_CHART)
                          || chartType.equals(JavaFX_Charts.PIE_CHART)))
                  || (fieldPosition == 1 && chartType.equals(JavaFX_Charts.HORIZONTAL_BAR_CHART))
                  || (fieldPosition == 0
                      && sqlQuery.getColumnNames().size() == 1
                      && chartType.equals(JavaFX_Charts.HORIZONTAL_BAR_CHART)))
                timeString = currentContentData + "";
              else timeString = (currentContentData + "").replaceAll(":", "");

              if (sqlQuery.getColumnNames().size() == 1) {
                content[fieldPosition] = currentRow + "";
                content[1] = timeString;
              } else content[fieldPosition] = timeString;
            }
          }

          // DATETIME & TIMESTAMP Type Fields
          else if (columnType.equals("DATETIME") || columnType.indexOf("TIMESTAMP") != -1) {
            if (columnType.equals("TIMESTAMPLTZ"))
              currentContentData = db_resultSet.getString(columnName);
            else currentContentData = db_resultSet.getTimestamp(columnName);

            if (currentContentData == null) {
              if (ASSIGN_NULL_ZERO)
                setNullData(sqlQuery.getColumnNames().size(), content, fieldPosition, currentRow);
              else isContentNull = true;
            } else {
              String timestampString =
                  new SimpleDateFormat("yyyy-MM-DD HH:mm:ss").format(currentContentData);

              if ((fieldPosition == 0
                      && (chartType.equals(JavaFX_Charts.BAR_CHART)
                          || chartType.equals(JavaFX_Charts.CATEGORY_LINE_CHART)
                          || chartType.equals(JavaFX_Charts.PIE_CHART)))
                  || (fieldPosition == 1 && chartType.equals(JavaFX_Charts.HORIZONTAL_BAR_CHART))
                  || (fieldPosition == 0
                      && sqlQuery.getColumnNames().size() == 1
                      && chartType.equals(JavaFX_Charts.HORIZONTAL_BAR_CHART)))
                timestampString =
                    Utils.convertDBDateString_To_ViewDateString(
                            timestampString.substring(0, timestampString.indexOf(" ")),
                            DBTablesPanel.getGeneralDBProperties().getViewDateFormat())
                        + timestampString.substring(timestampString.indexOf(" "));
              else {
                timestampString = timestampString.replace("-", "");
                timestampString = timestampString.replace(":", "");
                timestampString = timestampString.replace(" ", "");
                timestampString =
                    timestampString.substring(0, 4) + "." + timestampString.substring(4);
                timestampString = timestampString.substring(0, 14);
              }

              if (sqlQuery.getColumnNames().size() == 1) {
                content[fieldPosition] = currentRow + "";
                content[1] = timestampString;
              } else content[fieldPosition] = timestampString;
            }
          }

          // BLOB/BYTEA/BINARY Type Field
          else if (Utils.isBlob(columnClass, columnType)) {
            Exception noBlobException = new Exception("BLOB");
            throw noBlobException;
          }

          // BIT Type Field
          else if (columnType.equals("BIT")) {
            currentContentData = db_resultSet.getByte(columnName);

            if (currentContentData == null) {
              if (ASSIGN_NULL_ZERO)
                setNullData(sqlQuery.getColumnNames().size(), content, fieldPosition, currentRow);
              else isContentNull = true;
            } else {
              String byteString = Byte.toString((byte) currentContentData);

              // Gets bit string.
              // Integer.toBinaryString(Integer.parseInt(byteString))

              if (sqlQuery.getColumnNames().size() == 1) {
                content[fieldPosition] = currentRow + "";
                content[1] = byteString;
              } else content[fieldPosition] = byteString;
            }
          }

          // TEXT/LONGTEXT Type Fields
          else if (Utils.isText(columnClass, columnType, true, columnSize)
              && !dataSourceType.equals(ConnectionManager.SQLITE)) {
            Exception noTextException = new Exception("TEXT");
            throw noTextException;
          }

          // Default Content. A normal table entry should
          // fall through here, to set content.
          else {
            currentContentData = db_resultSet.getString(columnName);

            if (currentContentData == null) {
              if (ASSIGN_NULL_ZERO)
                setNullData(sqlQuery.getColumnNames().size(), content, fieldPosition, currentRow);
              else isContentNull = true;
            } else {
              if (sqlQuery.getColumnNames().size() == 1) {
                content[fieldPosition] = currentRow + "";
                content[1] = currentContentData;
              } else content[fieldPosition] = currentContentData;
            }
          }
          fieldPosition++;
        }

        // Test Output
        /*
        for (int o = 0; o < content.length; o++)
           System.out.print("content[" + 0 + "] = " + content[o] + ", ");
        System.out.println();
        */

        // Add the current collected row data into
        // series.
        if (!isContentNull) {
          validInsert = insertData(fx_series, chartType, content);

          if (!validInsert) {
            loadProgressBar.setVisible(false);
            String message =
                resourceBundle.getResourceString(
                    "LoadSQLData.dialogmessage.InvalidPlotData,Row", "Invalid Plot Data, Row");

            JOptionPane.showMessageDialog(
                null,
                message + ": " + (currentRow - 1),
                resourceTitleAlert,
                JOptionPane.ERROR_MESSAGE);
          }
        }
        fieldPosition = 0;
        isContentNull = false;
      }

      // Add the series
      if (!loadProgressBar.isCanceled() && validInsert)
        (fxcharts.getChartPane()).addSeries(fx_series);
      else {
        fx_series.clear();
        // Runtime.getRuntime().gc();
      }

      // Closing out
      db_resultSet.close();
    } catch (Exception e) {
      loadProgressBar.setVisible(false);

      if (e instanceof SQLException)
        ConnectionManager.displaySQLErrors(((SQLException) e), "LoadSQLData loadData()");
      else {
        String message = resourceBundle.getResourceString("LoadSQLData.dialogmessage.Data", "Data");

        JOptionPane.showMessageDialog(
            null,
            e.toString() + " " + message + "!",
            resourceTitleAlert,
            JOptionPane.ERROR_MESSAGE);
      }
    } finally {
      try {
        if (db_resultSet != null) db_resultSet.close();
      } catch (SQLException sqle) {
        ConnectionManager.displaySQLErrors(((SQLException) sqle), "LoadSQLData loadData()");
      } finally {
        if (sqlStatement != null) sqlStatement.close();
      }
      loadProgressBar.dispose();
    }
  }