use of org.jkiss.dbeaver.model.data.DBDAttributeConstraint in project dbeaver by dbeaver.
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);
}
}
use of org.jkiss.dbeaver.model.data.DBDAttributeConstraint in project dbeaver by dbeaver.
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 dbeaver.
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 dbeaver.
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 dbeaver.
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);
}
Aggregations