Exemplo n.º 1
0
  public SQLHistorySearchCtrl(
      SQLTextAreaServices sqlTextAreaServices,
      Session session,
      ObservableList<SQLHistoryEntry> items) {
    _sqlTextAreaServices = sqlTextAreaServices;

    FxmlHelper<SQLHistorySearchView> fxmlHelper = new FxmlHelper<>(SQLHistorySearchView.class);
    _view = fxmlHelper.getView();

    _dialog = new Stage();
    _dialog.setTitle(
        new I18n(getClass())
            .t("SQLHistorySearchCtrl.title", session.getMainTabContext().getSessionTabTitle()));
    _dialog.initModality(Modality.WINDOW_MODAL);
    _dialog.initOwner(AppState.get().getPrimaryStage());
    Region region = fxmlHelper.getRegion();
    _dialog.setScene(new Scene(region));

    GuiUtils.makeEscapeClosable(region);

    new StageDimensionSaver(
        "sqlhistorysearch",
        _dialog,
        new Pref(getClass()),
        region.getPrefWidth(),
        region.getPrefHeight(),
        _dialog.getOwner());

    _view.cboFilterType.setItems(
        FXCollections.observableList(Arrays.asList(SqlHistoryFilterType.values())));
    _view.cboFilterType.getSelectionModel().selectFirst();

    _view.btnApply.setOnAction(e -> onApply());
    _view.chkFiltered.setOnAction(e -> onChkFiltered());

    _view.split.getItems().add(_tblHistory);
    _view.split.getItems().add(_txtSqlPreview);

    _originalTableLoader = new RowObjectTableLoader<>();
    _originalTableLoader.initColsByAnnotations(SQLHistoryEntry.class);
    _originalTableLoader.addRowObjects(items);
    _currentLoader = _originalTableLoader.cloneLoader();
    _currentLoader.load(_tblHistory);

    _tblHistory
        .getSelectionModel()
        .selectedItemProperty()
        .addListener((observable, oldValue, newValue) -> onTableSelectionChanged());

    _tblHistory.setOnMouseClicked(e -> onTblHistoryClicked(e));

    _txtSqlPreview.setEditable(false);

    _dialog.setOnCloseRequest(e -> close());

    _view.txtFilter.requestFocus();

    _splitPositionSaver.apply(_view.split);
    _dialog.showAndWait();
  }
Exemplo n.º 2
0
  private void onApply() {
    List<SQLHistoryEntry> toFilter = _originalTableLoader.getRowObjects();

    ArrayList<SQLHistoryEntry> toRemove = new ArrayList<>();
    for (SQLHistoryEntry sqlHistoryEntry : toFilter) {
      if (false == matchesFilter(sqlHistoryEntry)) {
        toRemove.add(sqlHistoryEntry);
      }
    }

    boolean filtered;
    if (0 < toRemove.size()) {
      toFilter.removeAll(toRemove);

      _currentLoader = _originalTableLoader.cloneLoaderFor(toFilter);

      _tblHistory.getItems().clear();
      _currentLoader.load(_tblHistory);
      filtered = true;
    } else {
      _currentLoader = _originalTableLoader.cloneLoader();
      _currentLoader.load(_tblHistory);
      filtered = false;
    }

    try {
      _dontReactToChkFiltered = true;
      _view.chkFiltered.setSelected(filtered);
    } finally {
      _dontReactToChkFiltered = false;
    }
  }
Exemplo n.º 3
0
  private void onChkFiltered() {
    if (_dontReactToChkFiltered) {
      return;
    }

    if (_view.chkFiltered.isSelected()) {
      onApply();
    } else {
      _tblHistory.getItems().clear();
      _currentLoader = _originalTableLoader.cloneLoader();
      _currentLoader.load(_tblHistory);
    }
  }
Exemplo n.º 4
0
 private List<SQLHistoryEntry> getSelectedRowObjects() {
   ObservableList<Integer> selectedIndices = _tblHistory.getSelectionModel().getSelectedIndices();
   return _currentLoader.getRowObjectsForIndices(selectedIndices);
 }