@Override
        public void focusGained(FocusEvent e) {
          if (e.getOppositeComponent() != null) {
            JTextField valueTextField = editorComponent.getTextField();
            DataEditorSettings settings = cell.getRow().getModel().getSettings();
            if (settings.getGeneralSettings().getSelectContentOnCellEdit().value()) {
              valueTextField.selectAll();
            }

            Rectangle rectangle = new Rectangle(mainPanel.getLocation(), mainPanel.getSize());
            parentForm.getColumnsPanel().scrollRectToVisible(rectangle);
          }
        }
  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 DatasetEditorModel(DatasetEditor datasetEditor) throws SQLException {
   super(datasetEditor.getConnectionHandler());
   this.datasetEditor = datasetEditor;
   this.datasetRef = DBObjectRef.from(datasetEditor.getDataset());
   this.settings = DataEditorSettings.getInstance(datasetEditor.getProject());
   setHeader(new DatasetEditorModelHeader(datasetEditor, null));
 }
  private int computeRowCount() {
    int originalRowCount = getRowCount();
    int stateRowCount = getState().getRowCount();
    int fetchRowCount = Math.max(stateRowCount, originalRowCount);

    int fetchBlockSize = settings.getGeneralSettings().getFetchBlockSize().value();
    fetchRowCount = (fetchRowCount / fetchBlockSize + 1) * fetchBlockSize;

    return Math.max(fetchRowCount, fetchBlockSize);
  }
  public DatasetRecordEditorColumnForm(
      DatasetRecordEditorForm parentForm, DatasetEditorModelCell cell) {
    this.parentForm = parentForm;
    final DatasetEditorColumnInfo columnInfo = cell.getColumnInfo();
    DBColumn column = columnInfo.getColumn();
    DBDataType dataType = column.getDataType();
    Project project = column.getProject();
    regionalSettings = RegionalSettings.getInstance(project);

    columnLabel.setIcon(column.getIcon());
    columnLabel.setText(column.getName());
    dataTypeLabel.setText(dataType.getQualifiedName());
    dataTypeLabel.setForeground(UIUtil.getInactiveTextColor());

    DBNativeDataType nativeDataType = dataType.getNativeDataType();
    if (nativeDataType != null) {
      DataTypeDefinition dataTypeDefinition = nativeDataType.getDataTypeDefinition();
      GenericDataType genericDataType = dataTypeDefinition.getGenericDataType();

      DataEditorSettings dataEditorSettings = DataEditorSettings.getInstance(project);

      long dataLength = dataType.getLength();

      if (genericDataType.is(GenericDataType.DATE_TIME, GenericDataType.LITERAL)) {
        TextFieldWithPopup textFieldWithPopup = new TextFieldWithPopup(project);

        textFieldWithPopup.setPreferredSize(new Dimension(200, -1));
        JTextField valueTextField = textFieldWithPopup.getTextField();
        valueTextField.getDocument().addDocumentListener(documentListener);
        valueTextField.addKeyListener(keyAdapter);
        valueTextField.addFocusListener(focusListener);

        if (cell.getRow().getModel().isEditable()) {
          if (genericDataType == GenericDataType.DATE_TIME) {
            textFieldWithPopup.createCalendarPopup(false);
          }

          if (genericDataType == GenericDataType.LITERAL) {
            if (dataLength > 20 && !column.isPrimaryKey() && !column.isForeignKey())
              textFieldWithPopup.createTextAreaPopup(false);
            DataEditorValueListPopupSettings valueListPopupSettings =
                dataEditorSettings.getValueListPopupSettings();

            if (column.isForeignKey()
                || (dataLength <= valueListPopupSettings.getDataLengthThreshold()
                    && (!column.isSinglePrimaryKey()
                        || valueListPopupSettings.isActiveForPrimaryKeyColumns()))) {
              ListPopupValuesProvider valuesProvider =
                  new ListPopupValuesProvider() {
                    public List<String> getValues() {
                      return columnInfo.getPossibleValues();
                    }
                  };
              textFieldWithPopup.createValuesListPopup(valuesProvider, false);
            }
          }
        }
        editorComponent = textFieldWithPopup;
      } else if (genericDataType.is(GenericDataType.BLOB, GenericDataType.CLOB)) {
        editorComponent = new TextFieldWithTextEditor(project);
      } else {
        editorComponent = new BasicDataEditorComponent();
      }
    } else {
      editorComponent = new BasicDataEditorComponent();
      editorComponent.setEnabled(false);
      editorComponent.setEditable(false);
    }

    valueFieldPanel.add((Component) editorComponent, BorderLayout.CENTER);
    editorComponent.getTextField().setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
    setCell(cell);
  }