use of org.jkiss.dbeaver.model.data.DBDLabelValuePair in project dbeaver by dbeaver.
the class FilterValueEditDialog method createMultiValueSelector.
private void createMultiValueSelector(Composite composite) {
GridData layoutData = new GridData(GridData.FILL_BOTH);
layoutData.widthHint = 400;
layoutData.heightHint = 300;
handler.setupTable(composite, SWT.BORDER | SWT.MULTI | SWT.CHECK | SWT.FULL_SELECTION, true, true, layoutData);
ViewerColumnController columnController = new ViewerColumnController(getClass().getName(), handler.getTableViewer());
columnController.addColumn("Value", "Value", SWT.LEFT, true, true, new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return handler.getAttribute().getValueHandler().getValueDisplayString(handler.getAttribute(), ((DBDLabelValuePair) element).getValue(), DBDDisplayFormat.UI);
}
});
columnController.addColumn("Description", "Row description (composed from dictionary columns)", SWT.LEFT, true, true, new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((DBDLabelValuePair) element).getLabel();
}
});
columnController.createColumns(true);
Action[] elements = new Action[] { new Action("Select &All") {
@Override
public void run() {
for (TableItem item : handler.getTableViewer().getTable().getItems()) {
item.setChecked(true);
}
}
}, new Action("Select &None") {
@Override
public void run() {
for (TableItem item : handler.getTableViewer().getTable().getItems()) {
item.setChecked(false);
}
}
} };
handler.addContextMenu(elements);
handler.addFilterTextbox(composite);
handler.setFilterPattern(null);
handler.loadValues(null);
columnController.createColumns(true);
}
use of org.jkiss.dbeaver.model.data.DBDLabelValuePair in project dbeaver by serge-rider.
the class FilterValueEditDialog method loadMultiValueList.
private void loadMultiValueList(@NotNull Collection<DBDLabelValuePair> values) {
Pattern pattern = null;
if (!CommonUtils.isEmpty(filterPattern)) {
pattern = Pattern.compile(SQLUtils.makeLikePattern("%" + filterPattern + "%"), Pattern.CASE_INSENSITIVE);
}
// Get all values from actual RSV data
boolean hasNulls = false;
java.util.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);
}
}
// Add values from fetched rows
for (ResultSetRow row : viewer.getModel().getAllRows()) {
Object cellValue = viewer.getModel().getCellValue(attr, row);
if (DBUtils.isNullValue(cellValue)) {
hasNulls = true;
continue;
}
if (!rowData.containsKey(cellValue)) {
String itemString = attr.getValueHandler().getValueDisplayString(attr, cellValue, DBDDisplayFormat.UI);
rowData.put(cellValue, new DBDLabelValuePair(itemString, cellValue));
}
}
java.util.List<DBDLabelValuePair> sortedList = new ArrayList<>(rowData.values());
Collections.sort(sortedList);
if (pattern != null) {
for (Iterator<DBDLabelValuePair> iter = sortedList.iterator(); iter.hasNext(); ) {
final DBDLabelValuePair valuePair = iter.next();
String itemString = attr.getValueHandler().getValueDisplayString(attr, valuePair.getValue(), DBDDisplayFormat.UI);
if (!pattern.matcher(itemString).matches() && (valuePair.getLabel() == null || !pattern.matcher(valuePair.getLabel()).matches())) {
iter.remove();
}
}
}
Collections.sort(sortedList);
if (hasNulls) {
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(attr, row);
checkedValues.add(value);
}
table.setInput(sortedList);
DBDLabelValuePair firstVisibleItem = null;
for (DBDLabelValuePair row : sortedList) {
Object cellValue = row.getValue();
if (checkedValues.contains(cellValue)) {
table.setChecked(row, true);
if (firstVisibleItem == null) {
firstVisibleItem = row;
}
}
}
ViewerColumnController.getFromControl(table.getTable()).repackColumns();
if (firstVisibleItem != null) {
final Widget item = table.testFindItem(firstVisibleItem);
if (item != null) {
table.getTable().setSelection((TableItem) item);
table.getTable().showItem((TableItem) item);
}
}
}
use of org.jkiss.dbeaver.model.data.DBDLabelValuePair in project dbeaver by dbeaver.
the class FilterValueEditPopup method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
DBSEntityReferrer descReferrer = ResultSetUtils.getEnumerableConstraint(filter.getAttribute());
Composite group = (Composite) super.createDialogArea(parent);
{
Composite labelComposite = UIUtils.createComposite(group, 2);
labelComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label controlLabel = UIUtils.createControlLabel(labelComposite, "Choose value(s) to filter by");
controlLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
if (descReferrer instanceof DBSEntityAssociation) {
Link hintLabel = UIUtils.createLink(labelComposite, "(<a>Define Description</a>)", new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
EditDictionaryPage editDictionaryPage = new EditDictionaryPage(((DBSEntityAssociation) descReferrer).getAssociatedEntity());
if (editDictionaryPage.edit(parent.getShell())) {
filter.loadValues(null);
}
}
});
hintLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
} else {
UIUtils.createEmptyLabel(labelComposite, 1, 1);
}
}
Text filterTextbox = filter.addFilterTextbox(group);
filterTextbox.setFocus();
filterTextbox.addTraverseListener(e -> {
Table table = filter.getTableViewer().getTable();
if (e.detail == SWT.TRAVERSE_ARROW_PREVIOUS || e.detail == SWT.TRAVERSE_ARROW_NEXT) {
if (table.getSelectionIndex() < 0 && table.getItemCount() > 0) {
table.setSelection(0);
}
table.setFocus();
} else if (e.detail == SWT.TRAVERSE_RETURN) {
applyFilterValue();
}
});
UIUtils.addEmptyTextHint(filterTextbox, text -> "Type partial value to search");
Composite tableComposite = UIUtils.createComposite(group, 1);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 400;
gd.heightHint = 300;
tableComposite.setLayoutData(gd);
filter.setupTable(tableComposite, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL | (filter.getOperator() == DBCLogicalOperator.IN ? SWT.CHECK : SWT.NONE), true, descReferrer != null, new GridData(GridData.FILL_BOTH));
Table table = filter.getTableViewer().getTable();
TableViewerColumn resultsetColumn = new TableViewerColumn(filter.getTableViewer(), UIUtils.createTableColumn(table, SWT.NONE, "Value"));
resultsetColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return filter.getAttribute().getValueHandler().getValueDisplayString(filter.getAttribute(), ((DBDLabelValuePair) element).getValue(), DBDDisplayFormat.UI);
}
});
TableViewerColumn descColumn;
if (descReferrer != null) {
descColumn = new TableViewerColumn(filter.getTableViewer(), UIUtils.createTableColumn(table, SWT.NONE, "Description"));
descColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((DBDLabelValuePair) element).getLabel();
}
});
}
filter.getTableViewer().addSelectionChangedListener(event -> {
value = filter.getFilterValue();
// okPressed();
});
filter.getTableViewer().addDoubleClickListener(event -> applyFilterValue());
filter.setFilterPattern(null);
filter.loadValues(() -> UIUtils.asyncExec(() -> UIUtils.packColumns(table, false)));
filter.createFilterButton(ResultSetMessages.sql_editor_resultset_filter_panel_btn_apply, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
applyFilterValue();
}
});
closeOnFocusLost(filterTextbox, table);
return tableComposite;
}
use of org.jkiss.dbeaver.model.data.DBDLabelValuePair in project dbeaver by dbeaver.
the class GenericFilterValueEdit method getFilterValue.
@Nullable
public Object getFilterValue() {
if (tableViewer != null) {
Set<Object> values = new LinkedHashSet<>();
for (DBDLabelValuePair item : getMultiValues()) {
if (((TableItem) tableViewer.testFindItem(item)).getChecked()) {
values.add(item.getValue());
}
}
values.addAll(savedValues);
return values.toArray();
} else if (editor != null) {
try {
return editor.extractEditorValue();
} catch (DBException e) {
log.error("Can't get editor value", e);
}
}
return null;
}
Aggregations