use of org.jkiss.dbeaver.model.data.DBDAttributeConstraint in project dbeaver by serge-rider.
the class FilterSettingsDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
getShell().setText(ResultSetMessages.controls_resultset_filter_title);
getShell().setImage(DBeaverIcons.getImage(UIIcon.FILTER));
Composite composite = (Composite) super.createDialogArea(parent);
TabFolder tabFolder = new TabFolder(composite, SWT.NONE);
tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
TreeColumn criteriaColumn;
{
Composite columnsGroup = UIUtils.createPlaceholder(tabFolder, 1);
FilteredTree filteredTree = new FilteredTree(columnsGroup, SWT.SINGLE | SWT.FULL_SELECTION | SWT.CHECK, new NamedObjectPatternFilter(), true) {
@Override
protected TreeViewer doCreateTreeViewer(Composite parent, int style) {
columnsViewer = new CheckboxTreeViewer(parent, style);
return columnsViewer;
}
};
columnsViewer.setContentProvider(new TreeContentProvider() {
@Override
public Object[] getChildren(Object parentElement) {
final java.util.List<DBDAttributeBinding> nestedBindings = ((DBDAttributeBinding) parentElement).getNestedBindings();
if (nestedBindings == null || nestedBindings.isEmpty()) {
return null;
}
final DBDAttributeBinding[] res = nestedBindings.toArray(new DBDAttributeBinding[0]);
Arrays.sort(res, activeSorter);
return res;
}
@Override
public boolean hasChildren(Object element) {
final java.util.List<DBDAttributeBinding> nestedBindings = ((DBDAttributeBinding) element).getNestedBindings();
return nestedBindings != null && !nestedBindings.isEmpty();
}
});
columnsViewer.setLabelProvider(new ColumnLabelProvider());
columnsViewer.setCheckStateProvider(new CheckStateProvider());
final Tree columnsTree = columnsViewer.getTree();
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 300;
columnsTree.setLayoutData(gd);
columnsTree.setHeaderVisible(true);
columnsTree.setLinesVisible(true);
UIUtils.createTreeColumn(columnsTree, SWT.LEFT, ResultSetMessages.controls_resultset_filter_column_name);
UIUtils.createTreeColumn(columnsTree, SWT.LEFT, "#");
UIUtils.createTreeColumn(columnsTree, SWT.LEFT, ResultSetMessages.controls_resultset_filter_column_order);
criteriaColumn = UIUtils.createTreeColumn(columnsTree, SWT.LEFT, ResultSetMessages.controls_resultset_filter_column_criteria);
treeEditor = new FilterSettingsTreeEditor(columnsTree);
columnsViewer.addCheckStateListener(event -> {
DBDAttributeConstraint constraint = getBindingConstraint((DBDAttributeBinding) event.getElement());
constraint.setVisible(event.getChecked());
});
{
ToolBar toolbar = new ToolBar(columnsGroup, SWT.HORIZONTAL | SWT.RIGHT);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.verticalIndent = 3;
toolbar.setLayoutData(gd);
toolbar.setLayout(new FillLayout());
moveTopButton = createToolItem(toolbar, ResultSetMessages.dialog_toolbar_move_to_top, UIIcon.ARROW_TOP, () -> {
int selectionIndex = getSelectionIndex(columnsViewer.getTree());
moveColumns(selectionIndex, 0);
});
moveTopButton.setEnabled(false);
moveUpButton = createToolItem(toolbar, ResultSetMessages.dialog_toolbar_move_up, UIIcon.ARROW_UP, () -> {
int selectionIndex = getSelectionIndex(columnsViewer.getTree());
swapColumns(selectionIndex, selectionIndex - 1);
});
moveUpButton.setEnabled(false);
moveDownButton = createToolItem(toolbar, ResultSetMessages.dialog_toolbar_move_down, UIIcon.ARROW_DOWN, () -> {
int selectionIndex = getSelectionIndex(columnsViewer.getTree());
swapColumns(selectionIndex, selectionIndex + 1);
});
moveDownButton.setEnabled(false);
moveBottomButton = createToolItem(toolbar, ResultSetMessages.dialog_toolbar_move_to_bottom, UIIcon.ARROW_BOTTOM, () -> {
int selectionIndex = getSelectionIndex(columnsViewer.getTree());
moveColumns(selectionIndex, getItemsCount() - 1);
});
moveBottomButton.setEnabled(false);
UIUtils.createToolBarSeparator(toolbar, SWT.VERTICAL);
createToolItem(toolbar, ResultSetMessages.dialog_toolbar_sort, UIIcon.SORT, () -> {
attributes.sort(ALPHA_SORTER);
for (int i = 0; i < attributes.size(); i++) {
final DBDAttributeConstraint constraint = getBindingConstraint(attributes.get(i));
constraint.setVisualPosition(i);
}
columnsViewer.refresh();
});
UIUtils.createToolBarSeparator(toolbar, SWT.VERTICAL);
ToolItem showAllButton = createToolItem(toolbar, ResultSetMessages.dialog_toolbar_show_all, null, () -> {
for (DBDAttributeConstraint constraint : constraints) {
constraint.setVisible(true);
}
columnsViewer.refresh();
});
showAllButton.setImage(UIUtils.getShardImage(ISharedImages.IMG_ETOOL_DEF_PERSPECTIVE));
ToolItem showNoneButton = createToolItem(toolbar, ResultSetMessages.dialog_toolbar_show_none, null, () -> {
for (DBDAttributeConstraint constraint : constraints) {
constraint.setVisible(false);
}
columnsViewer.refresh();
});
showNoneButton.setImage(UIUtils.getShardImage(ISharedImages.IMG_ELCL_REMOVEALL));
createToolItem(toolbar, ResultSetMessages.dialog_toolbar_reset, UIIcon.REFRESH, () -> {
dataFilter.reset();
constraints = new ArrayList<>(dataFilter.getConstraints());
refreshData();
// columnsViewer.refresh();
// $NON-NLS-1$
orderText.setText("");
// $NON-NLS-1$
whereText.setText("");
});
columnsViewer.addSelectionChangedListener(event -> {
int selectionIndex = getSelectionIndex(columnsViewer.getTree());
moveTopButton.setEnabled(selectionIndex > 0);
moveUpButton.setEnabled(selectionIndex > 0);
moveDownButton.setEnabled(selectionIndex >= 0 && selectionIndex < getItemsCount() - 1);
moveBottomButton.setEnabled(selectionIndex >= 0 && selectionIndex < getItemsCount() - 1);
});
}
TabItem libsTab = new TabItem(tabFolder, SWT.NONE);
libsTab.setText(ResultSetMessages.controls_resultset_filter_group_columns);
libsTab.setToolTipText("Set criteria and order for individual column(s)");
libsTab.setControl(columnsGroup);
}
createCustomFilters(tabFolder);
// Fill columns
columnsViewer.setInput(attributes);
refreshData();
// Pack UI
UIUtils.asyncExec(() -> UIUtils.packColumns(columnsViewer.getTree(), true, new float[] { .45f, .05f, .05f, .45f }));
if (criteriaColumn.getWidth() < 200) {
criteriaColumn.setWidth(200);
}
if (!resultSetViewer.supportsDataFilter()) {
Label warnLabel = new Label(composite, SWT.NONE);
warnLabel.setText(ResultSetMessages.controls_resultset_filter_warning_custom_order_disabled);
warnLabel.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_RED));
}
return parent;
}
use of org.jkiss.dbeaver.model.data.DBDAttributeConstraint in project dbeaver by serge-rider.
the class SchedulerJobLogEditor method getEditorDataFilter.
@Override
protected DBDDataFilter getEditorDataFilter() {
OracleSchedulerJob job = getDatabaseObject();
OracleTableBase logView = getJobLogView();
if (logView == null) {
return null;
}
List<DBDAttributeConstraint> constraints = new ArrayList<>();
try {
DBRProgressMonitor monitor = new VoidProgressMonitor();
OracleTableColumn ownerAttr = logView.getAttribute(monitor, "OWNER");
if (ownerAttr != null) {
DBDAttributeConstraint ac = new DBDAttributeConstraint(ownerAttr, ownerAttr.getOrdinalPosition());
ac.setVisible(false);
ac.setOperator(DBCLogicalOperator.EQUALS);
ac.setValue(job.getOwner());
constraints.add(ac);
}
OracleTableColumn jobNameAttr = logView.getAttribute(monitor, "JOB_NAME");
if (jobNameAttr != null) {
DBDAttributeConstraint ac = new DBDAttributeConstraint(jobNameAttr, jobNameAttr.getOrdinalPosition());
ac.setVisible(false);
ac.setOperator(DBCLogicalOperator.EQUALS);
ac.setValue(job.getName());
constraints.add(ac);
}
OracleTableColumn logDateAttr = logView.getAttribute(monitor, "LOG_DATE");
if (logDateAttr != null) {
DBDAttributeConstraint ac = new DBDAttributeConstraint(logDateAttr, logDateAttr.getOrdinalPosition());
ac.setOrderPosition(1);
ac.setOrderDescending(true);
ac.setVisible(true);
constraints.add(ac);
}
} catch (DBException e) {
log.error(e);
}
return new DBDDataFilter(constraints);
}
use of org.jkiss.dbeaver.model.data.DBDAttributeConstraint in project dbeaver by serge-rider.
the class VirtualAttributeAddAction method run.
@Override
public void run() {
DBVEntity vEntity = resultSetViewer.getModel().getVirtualEntity(false);
DBVEntityAttribute vAttr = new DBVEntityAttribute(vEntity, null, "vcolumn");
if (new EditVirtualAttributePage(resultSetViewer, vAttr).edit(resultSetViewer.getControl().getShell())) {
vAttr.setCustom(true);
vEntity.addVirtualAttribute(vAttr);
vEntity.persistConfiguration();
resultSetViewer.refreshMetaData();
DBDAttributeConstraint vAttrConstr = resultSetViewer.getModel().getDataFilter().getConstraint(vAttr, false);
if (vAttrConstr != null) {
}
}
}
use of org.jkiss.dbeaver.model.data.DBDAttributeConstraint in project dbeaver by serge-rider.
the class GenericFilterValueEdit method loadMultiValueList.
private void loadMultiValueList(@NotNull Collection<DBDLabelValuePair> values, boolean mergeResultsWithData) {
if (tableViewer == null || tableViewer.getControl() == null || tableViewer.getControl().isDisposed()) {
return;
}
Pattern pattern = null;
if (!CommonUtils.isEmpty(filterPattern) && attribute.getDataKind() == DBPDataKind.STRING) {
pattern = Pattern.compile(SQLUtils.makeLikePattern("%" + filterPattern + "%"), Pattern.CASE_INSENSITIVE);
}
// Get all values from actual RSV data
boolean hasNulls = false;
Map<Object, DBDLabelValuePair> rowData = new HashMap<>();
for (DBDLabelValuePair pair : values) {
final DBDLabelValuePair oldLabel = rowData.get(pair.getValue());
if (oldLabel != null) {
// Duplicate label for single key - may happen in case of composite foreign keys
String multiLabel = oldLabel.getLabel() + "," + pair.getLabel();
if (multiLabel.length() > 200) {
multiLabel = multiLabel.substring(0, 200) + MULTI_KEY_LABEL;
}
rowData.put(pair.getValue(), new DBDLabelValuePair(multiLabel, pair.getValue()));
} else {
rowData.put(pair.getValue(), pair);
}
}
if (mergeResultsWithData) {
// Add values from fetched rows
for (ResultSetRow row : viewer.getModel().getAllRows()) {
Object cellValue = viewer.getModel().getCellValue(attribute, row);
if (DBUtils.isNullValue(cellValue)) {
hasNulls = true;
continue;
}
if (!keyPresents(rowData, cellValue)) {
String itemString = attribute.getValueHandler().getValueDisplayString(attribute, cellValue, DBDDisplayFormat.UI);
rowData.put(cellValue, new DBDLabelValuePair(itemString, cellValue));
}
}
}
List<DBDLabelValuePair> sortedList = new ArrayList<>(rowData.values());
if (pattern != null) {
for (Iterator<DBDLabelValuePair> iter = sortedList.iterator(); iter.hasNext(); ) {
final DBDLabelValuePair valuePair = iter.next();
String itemString = attribute.getValueHandler().getValueDisplayString(attribute, valuePair.getValue(), DBDDisplayFormat.UI);
if (!pattern.matcher(itemString).matches() && (valuePair.getLabel() == null || !pattern.matcher(valuePair.getLabel()).matches())) {
iter.remove();
}
}
} else if (filterPattern != null && attribute.getDataKind() == DBPDataKind.NUMERIC) {
// Filter numeric values
double minValue = CommonUtils.toDouble(filterPattern);
for (Iterator<DBDLabelValuePair> iter = sortedList.iterator(); iter.hasNext(); ) {
final DBDLabelValuePair valuePair = iter.next();
String itemString = attribute.getValueHandler().getValueDisplayString(attribute, valuePair.getValue(), DBDDisplayFormat.EDIT);
double itemValue = CommonUtils.toDouble(itemString);
if (itemValue < minValue) {
iter.remove();
}
}
}
try {
Collections.sort(sortedList);
} catch (Exception e) {
// FIXME: This may happen in some crazy cases -
// FIXME: error "Comparison method violates its general contract!" happens in case of long strings sorting
// FIXME: Test on sakila.film.description
log.error("Error sorting value collection", e);
}
if (hasNulls) {
boolean nullPresents = false;
for (DBDLabelValuePair val : rowData.values()) {
if (DBUtils.isNullValue(val.getValue())) {
nullPresents = true;
break;
}
}
if (!nullPresents) {
sortedList.add(0, new DBDLabelValuePair(DBValueFormatting.getDefaultValueDisplayString(null, DBDDisplayFormat.UI), null));
}
}
Set<Object> checkedValues = new HashSet<>();
for (ResultSetRow row : rows) {
Object value = viewer.getModel().getCellValue(attribute, row);
checkedValues.add(value);
}
DBDAttributeConstraint constraint = viewer.getModel().getDataFilter().getConstraint(attribute);
if (constraint != null && constraint.getOperator() == DBCLogicalOperator.IN) {
// checkedValues.add(constraint.getValue());
if (constraint.getValue() instanceof Object[]) {
Collections.addAll(checkedValues, (Object[]) constraint.getValue());
}
}
checkedValues.addAll(savedValues);
tableViewer.setInput(sortedList);
DBDLabelValuePair firstVisibleItem = null;
if (isCheckedTable)
for (DBDLabelValuePair row : sortedList) {
Object cellValue = row.getValue();
if (checkedValues.contains(cellValue)) {
TableItem t = (TableItem) tableViewer.testFindItem(row);
t.setChecked(true);
// ((CheckboxTableViewer) tableViewer).setChecked(row, true);
if (firstVisibleItem == null) {
firstVisibleItem = row;
}
}
}
ViewerColumnController vcc = ViewerColumnController.getFromControl(tableViewer.getTable());
if (vcc != null) {
vcc.repackColumns();
} else {
UIUtils.packColumns(tableViewer.getTable(), true);
}
if (firstVisibleItem != null) {
final Widget item = tableViewer.testFindItem(firstVisibleItem);
if (item != null) {
tableViewer.getTable().setSelection((TableItem) item);
tableViewer.getTable().showItem((TableItem) item);
}
}
}
use of org.jkiss.dbeaver.model.data.DBDAttributeConstraint in project dbeaver by serge-rider.
the class SearchDataQuery method findRows.
private DBCStatistics findRows(@NotNull DBCSession session, @NotNull DBSDataContainer dataContainer, @NotNull TestDataReceiver dataReceiver) throws DBCException {
DBSEntity entity;
if (dataContainer instanceof DBSEntity) {
entity = (DBSEntity) dataContainer;
} else {
log.warn("Data container " + dataContainer + " isn't entity");
return null;
}
try {
List<DBDAttributeConstraint> constraints = new ArrayList<>();
for (DBSEntityAttribute attribute : CommonUtils.safeCollection(entity.getAttributes(session.getProgressMonitor()))) {
if (params.fastSearch) {
if (DBUtils.findAttributeIndex(session.getProgressMonitor(), attribute) == null) {
continue;
}
}
if (DBUtils.isPseudoAttribute(attribute) || DBUtils.isHiddenObject(attribute)) {
continue;
}
DBCLogicalOperator[] supportedOperators = DBUtils.getAttributeOperators(attribute);
DBCLogicalOperator operator;
Object value;
switch(attribute.getDataKind()) {
case BOOLEAN:
continue;
case NUMERIC:
if (!params.searchNumbers) {
continue;
}
if (!ArrayUtils.contains(supportedOperators, DBCLogicalOperator.EQUALS)) {
continue;
}
operator = DBCLogicalOperator.EQUALS;
try {
value = Integer.valueOf(params.searchString);
} catch (NumberFormatException e) {
try {
value = Long.valueOf(params.searchString);
} catch (NumberFormatException e1) {
try {
value = Double.valueOf(params.searchString);
} catch (NumberFormatException e2) {
try {
value = new BigDecimal(params.searchString);
} catch (Exception e3) {
// Not a number
continue;
}
}
}
}
break;
case CONTENT:
case BINARY:
if (!params.searchLOBs) {
continue;
}
case STRING:
if (!params.isCaseSensitive() && ArrayUtils.contains(supportedOperators, DBCLogicalOperator.ILIKE)) {
operator = DBCLogicalOperator.ILIKE;
value = "%" + params.searchString + "%";
} else if (ArrayUtils.contains(supportedOperators, DBCLogicalOperator.LIKE)) {
operator = DBCLogicalOperator.LIKE;
value = "%" + params.searchString + "%";
} else if (ArrayUtils.contains(supportedOperators, DBCLogicalOperator.EQUALS)) {
operator = DBCLogicalOperator.EQUALS;
value = params.searchString;
} else {
continue;
}
break;
default:
{
// On success search by exact match
if (!ArrayUtils.contains(supportedOperators, DBCLogicalOperator.EQUALS)) {
continue;
}
String typeName = attribute.getTypeName();
if (typeName.equals(DBConstants.TYPE_NAME_UUID) || typeName.equals(DBConstants.TYPE_NAME_UUID2)) {
try {
UUID uuid = UUID.fromString(params.searchString);
operator = DBCLogicalOperator.EQUALS;
value = uuid.toString();
} catch (Exception e) {
// No a UUID
continue;
}
} else {
continue;
}
}
}
DBDAttributeConstraint constraint = new DBDAttributeConstraint(attribute, constraints.size());
constraint.setOperator(operator);
constraint.setValue(value);
constraint.setVisible(true);
constraints.add(constraint);
}
if (constraints.isEmpty()) {
return null;
}
dataReceiver.filter = new DBDDataFilter(constraints);
dataReceiver.filter.setAnyConstraint(true);
DBCExecutionSource searchSource = new AbstractExecutionSource(dataContainer, session.getExecutionContext(), this);
return dataContainer.readData(searchSource, session, dataReceiver, dataReceiver.filter, -1, -1, 0, 0);
} catch (DBException e) {
throw new DBCException("Error finding rows", e);
}
}
Aggregations