private ResultSet loadResultSet(boolean useCurrentFilter) throws SQLException {
    Connection connection = connectionHandler.getStandaloneConnection();
    DBDataset dataset = getDataset();
    if (dataset != null) {
      Project project = dataset.getProject();
      DatasetFilter filter = DatasetFilterManager.EMPTY_FILTER;
      if (useCurrentFilter) {
        DatasetFilterManager filterManager = DatasetFilterManager.getInstance(project);
        filter = filterManager.getActiveFilter(dataset);
        if (filter == null) filter = DatasetFilterManager.EMPTY_FILTER;
      }

      String selectStatement = filter.createSelectStatement(dataset, getState().getSortingState());
      Statement statement =
          isReadonly()
              ? connection.createStatement()
              : connection.createStatement(
                  ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
      checkDisposed();
      int timeout = settings.getGeneralSettings().getFetchTimeout().value();
      if (timeout != -1) {
        statement.setQueryTimeout(timeout);
      }
      return statement.executeQuery(selectStatement);
    }
    return null;
  }
  public void duplicateRecord(int rowIndex) {
    DatasetEditorTable editorTable = getEditorTable();
    if (editorTable != null) {
      DBDataset dataset = getDataset();
      try {
        editorTable.stopCellEditing();
        int insertIndex = rowIndex + 1;
        resultSet.moveToInsertRow();
        DatasetEditorModelRow oldRow = getRowAtIndex(rowIndex);
        DatasetEditorModelRow newRow = createRow(getRowCount() + 1);
        newRow.setInsert(true);
        newRow.updateDataFromRow(oldRow);
        addRowAtIndex(insertIndex, newRow);
        notifyRowsInserted(insertIndex, insertIndex);

        editorTable.selectCell(insertIndex, editorTable.getSelectedColumn());
        isInserting = true;
        if (dataset != null) {
          getConnectionHandler().notifyChanges(dataset.getVirtualFile());
        }
      } catch (SQLException e) {
        if (dataset != null) {
          MessageUtil.showErrorDialog(
              "Could not duplicate record in " + dataset.getQualifiedNameWithType() + ".", e);
        }
      }
    }
  }
  public DatasetEditorModelHeader(DatasetEditor datasetEditor, ResultSet resultSet)
      throws SQLException {
    DBDataset dataset = datasetEditor.getDataset();
    if (dataset != null) {
      if (resultSet == null) {
        DatasetColumnSetup columnSetup = datasetEditor.getState().getColumnSetup();
        List<DatasetColumnState> columnStates = columnSetup.getColumnStates();
        if (columnStates.size() != dataset.getColumns().size()) {
          columnSetup.init(dataset);
        }

        int index = 0;
        for (DatasetColumnState columnState : columnStates) {
          DBColumn column = dataset.getColumn(columnState.getName());
          ColumnInfo columnInfo = new DatasetEditorColumnInfo(column, index, column.getPosition());
          addColumnInfo(columnInfo);
          index++;
        }
      } else {
        ResultSetMetaData metaData = resultSet.getMetaData();
        int columnCount = metaData.getColumnCount();
        for (int i = 0; i < columnCount; i++) {
          String name = metaData.getColumnName(i + 1);
          DBColumn column = dataset.getColumn(name);
          ColumnInfo columnInfo = new DatasetEditorColumnInfo(column, i, i + 1);
          addColumnInfo(columnInfo);
        }
      }
    }
  }
 /**
  * ************************************************************** Editor actions *
  * **************************************************************
  */
 public void deleteRecords(int[] rowIndexes) {
   DatasetEditorTable editorTable = getEditorTable();
   if (editorTable != null) {
     editorTable.fireEditingCancel();
     for (int index : rowIndexes) {
       DatasetEditorModelRow row = getRowAtIndex(index);
       if (!row.isDeleted()) {
         int rsRowIndex = row.getResultSetRowIndex();
         row.delete();
         if (row.isDeleted()) {
           shiftResultSetRowIndex(rsRowIndex, -1);
           notifyRowUpdated(index);
         }
       }
       isModified = true;
     }
     DBDataset dataset = getDataset();
     if (dataset != null) {
       getConnectionHandler().notifyChanges(dataset.getVirtualFile());
     }
   }
 }
 public boolean isEditable() {
   DBDataset dataset = getDataset();
   return dataset != null && dataset.isEditable(DBContentType.DATA);
 }