Search in sources :

Example 21 with DBDAttributeConstraint

use of org.jkiss.dbeaver.model.data.DBDAttributeConstraint in project dbeaver by serge-rider.

the class ResultSetFilterPanel method setCustomDataFilter.

private void setCustomDataFilter() {
    DBCExecutionContext context = viewer.getExecutionContext();
    if (context == null) {
        return;
    }
    String condition = filtersText.getText();
    StringBuilder currentCondition = new StringBuilder();
    SQLUtils.appendConditionString(viewer.getModel().getDataFilter(), context.getDataSource(), null, currentCondition, true);
    if (currentCondition.toString().trim().equals(condition.trim())) {
        // The same
        return;
    }
    DBDDataFilter newFilter = new DBDDataFilter(viewer.getModel().getDataFilter());
    for (DBDAttributeConstraint ac : newFilter.getConstraints()) {
        ac.setCriteria(null);
    }
    newFilter.setWhere(condition);
    viewer.setDataFilter(newFilter, true);
// viewer.getControl().setFocus();
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBDDataFilter(org.jkiss.dbeaver.model.data.DBDDataFilter) DBDAttributeConstraint(org.jkiss.dbeaver.model.data.DBDAttributeConstraint)

Example 22 with DBDAttributeConstraint

use of org.jkiss.dbeaver.model.data.DBDAttributeConstraint in project dbeaver by serge-rider.

the class FilterByAttributeAction method run.

@Override
public void run() {
    Object value = type.getValue(resultSetViewer, attribute, operator, false);
    if (operator.getArgumentCount() != 0 && value == null) {
        return;
    }
    DBDDataFilter filter = new DBDDataFilter(resultSetViewer.getModel().getDataFilter());
    DBDAttributeConstraint constraint = filter.getConstraint(attribute);
    if (constraint != null) {
        constraint.setOperator(operator);
        constraint.setValue(value);
        resultSetViewer.setDataFilter(filter, true);
    }
}
Also used : DBDDataFilter(org.jkiss.dbeaver.model.data.DBDDataFilter) DBDAttributeConstraint(org.jkiss.dbeaver.model.data.DBDAttributeConstraint)

Example 23 with DBDAttributeConstraint

use of org.jkiss.dbeaver.model.data.DBDAttributeConstraint in project dbeaver by serge-rider.

the class FilterResetAttributeAction method run.

@Override
public void run() {
    DBDDataFilter dataFilter = new DBDDataFilter(resultSetViewer.getModel().getDataFilter());
    DBDAttributeConstraint constraint = dataFilter.getConstraint(attribute);
    if (constraint != null) {
        constraint.setCriteria(null);
        resultSetViewer.setDataFilter(dataFilter, true);
    }
}
Also used : DBDDataFilter(org.jkiss.dbeaver.model.data.DBDDataFilter) DBDAttributeConstraint(org.jkiss.dbeaver.model.data.DBDAttributeConstraint)

Example 24 with DBDAttributeConstraint

use of org.jkiss.dbeaver.model.data.DBDAttributeConstraint in project dbeaver by serge-rider.

the class FilterSettingsDialog method swapColumns.

private void swapColumns(int curIndex, int newIndex) {
    final DBDAttributeConstraint c1 = getBindingConstraint((DBDAttributeBinding) columnsViewer.getTree().getItem(curIndex).getData());
    final DBDAttributeConstraint c2 = getBindingConstraint((DBDAttributeBinding) columnsViewer.getTree().getItem(newIndex).getData());
    final int vp2 = c2.getVisualPosition();
    c2.setVisualPosition(c1.getVisualPosition());
    c1.setVisualPosition(vp2);
    refreshData();
    moveTopButton.setEnabled(newIndex > 0);
    moveUpButton.setEnabled(newIndex > 0);
    moveDownButton.setEnabled(newIndex < getItemsCount() - 1);
    moveBottomButton.setEnabled(newIndex < getItemsCount() - 1);
}
Also used : DBDAttributeConstraint(org.jkiss.dbeaver.model.data.DBDAttributeConstraint) DBDAttributeConstraint(org.jkiss.dbeaver.model.data.DBDAttributeConstraint)

Example 25 with DBDAttributeConstraint

use of org.jkiss.dbeaver.model.data.DBDAttributeConstraint in project dbeaver by serge-rider.

the class FilterSettingsDialog method okPressed.

@Override
protected void okPressed() {
    treeEditor.okPressed();
    boolean hasVisibleColumns = false;
    for (DBDAttributeConstraint constraint : dataFilter.getConstraints()) {
        // constraint.setVisualPosition(this.constraints.indexOf(constraint));
        if (constraint.isVisible()) {
            hasVisibleColumns = true;
        }
    }
    if (!hasVisibleColumns) {
        UIUtils.showMessageBox(getShell(), "Bad filter", "You have to set at least one column visible", SWT.ICON_WARNING);
        return;
    }
    if (!CommonUtils.isEmpty(orderText.getText())) {
        dataFilter.setOrder(orderText.getText());
    } else {
        dataFilter.setOrder(null);
    }
    if (!CommonUtils.isEmpty(whereText.getText())) {
        dataFilter.setWhere(whereText.getText());
    } else {
        dataFilter.setWhere(null);
    }
    boolean filtersChanged = true;
    if (dataFilter.equalFilters(resultSetViewer.getModel().getDataFilter(), true)) {
        // Only attribute visibility was changed
        filtersChanged = false;
    }
    resultSetViewer.setDataFilter(dataFilter, filtersChanged);
    super.okPressed();
}
Also used : DBDAttributeConstraint(org.jkiss.dbeaver.model.data.DBDAttributeConstraint)

Aggregations

DBDAttributeConstraint (org.jkiss.dbeaver.model.data.DBDAttributeConstraint)28 DBDDataFilter (org.jkiss.dbeaver.model.data.DBDDataFilter)13 DBException (org.jkiss.dbeaver.DBException)7 Expression (net.sf.jsqlparser.expression.Expression)4 AndExpression (net.sf.jsqlparser.expression.operators.conditional.AndExpression)4 Table (net.sf.jsqlparser.schema.Table)4 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)4 ArrayList (java.util.ArrayList)3 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)3 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 java.util (java.util)2 List (java.util.List)2 Pattern (java.util.regex.Pattern)2 ControlEnableState (org.eclipse.jface.dialogs.ControlEnableState)2 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)2 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)2 org.eclipse.jface.viewers (org.eclipse.jface.viewers)2 SWT (org.eclipse.swt.SWT)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2