private String extractContent(
      DataGridPanel grid, String delimiter, boolean saveHeader, boolean ecloseWithDowbleQuotes) {
    JTable _table = grid.getTable();

    int numcols = _table.getSelectedColumnCount();
    int numrows = _table.getSelectedRowCount();

    if (numcols > 0 && numrows > 0) {
      StringBuffer sbf = new StringBuffer();
      int[] rowsselected = _table.getSelectedRows();
      int[] colsselected = _table.getSelectedColumns();

      if (saveHeader) {
        // put header name list
        for (int j = 0; j < numcols; j++) {
          String text =
              (String)
                  _table
                      .getTableHeader()
                      .getColumnModel()
                      .getColumn(colsselected[j])
                      .getHeaderValue();
          sbf.append(text);
          if (j < numcols - 1) sbf.append(delimiter);
        }
        sbf.append("\n");
      }

      // put content
      for (int i = 0; i < numrows; i++) {
        for (int j = 0; j < numcols; j++) {
          Object value = _table.getValueAt(rowsselected[i], colsselected[j]);
          String _value = "";
          if (value != null) {
            _value = value.toString();
          }
          if (ecloseWithDowbleQuotes) {
            sbf.append("\"").append(_value).append("\"");
          } else {
            sbf.append(_value);
          }

          if (j < numcols - 1) sbf.append(delimiter);
        }
        sbf.append("\n");
      }

      //            StringSelection stsel = new StringSelection(sbf.toString());
      //            Clipboard system = Toolkit.getDefaultToolkit().getSystemClipboard();
      //            system.setContents(stsel, stsel);
      return sbf.toString();
    }

    return null;
  }
    public static Image createImage(final JTable table, int column) {
      final int height =
          Math.max(20, Math.min(100, table.getSelectedRowCount() * table.getRowHeight()));
      final int width = table.getColumnModel().getColumn(column).getWidth();

      final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
      Graphics2D g2 = (Graphics2D) image.getGraphics();

      g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));

      drawSelection(table, column, g2, width);
      return image;
    }
    public void setSelected(AnActionEvent event, boolean b) {
      switch (command) {
        case REFRESH_RESULTSET:
          {
            QueryResultPanel resultPanel = getSelectedResultPanel();
            if (isConnected
                && resultPanel instanceof DataGridPanel
                && resultPanel.isRefreshSupported()) {
              try {
                resultPanel.refresh();
              } catch (DBException e) {
              }
            }
            break;
          }
        case CLOSE_PANEL:
          close();
          break;
        case STICKY_OPTION:
          selected ^= true;
          break;
        case EXPORT_DATA:
          {
            QueryResultPanel resultPanel = getSelectedResultPanel();
            if (resultPanel instanceof DataGridPanel) {
              DataGridPanel grid = (DataGridPanel) resultPanel;
              JTable _table = grid.getTable();

              int numcols = _table.getSelectedColumnCount();
              int numrows = _table.getSelectedRowCount();

              if (numcols == 0 && numrows == 0) {
                // nothing to copy
                return;
              }

              ExportSettings settings = new ExportSettings();
              settings.show();
              if (!settings.isOK()) {
                return;
              }

              File fileToSave = null;
              if (settings.saveToFile()) {
                String path = settings.getFilePathToSave();
                if (path == null || path.length() == 0) {
                  Messages.showInfoMessage(
                      "File not specified, content will be saved in Clipboard",
                      "File not specified");
                  //                            } else if (new File(path).getParentFile().exists())
                  // {
                } else {
                  // todo --
                  fileToSave = new File(path);
                }
              }

              String delimiter;
              switch (settings.getDelimiter()) {
                case TAB:
                  delimiter = "\t";
                  break;
                case COMMA:
                  delimiter = ",";
                  break;
                default: //  SEMICOLON:
                  delimiter = ";";
                  break;
              }

              String content =
                  extractContent(
                      grid,
                      delimiter,
                      settings.saveColumnHeaders(),
                      settings.encloseFieldsInDowubleQuotes());
              if (content != null) {
                if (fileToSave != null) {
                  // save in the file
                  try {
                    StringUtils.string2file(content, fileToSave);
                  } catch (IOException e) {
                    Messages.showErrorDialog(e.getMessage(), "Export failed");
                  }
                } else {
                  // save in Clipboard
                  StringSelection stsel = new StringSelection(content);
                  Clipboard system = Toolkit.getDefaultToolkit().getSystemClipboard();
                  system.setContents(stsel, stsel);
                }
              }
            }
            break;
          }
      }
      // notifyListeners(command);
    }