use of org.jkiss.dbeaver.model.data.DBDLabelValuePair in project dbeaver by serge-rider.
the class FilterValueEditDialog method okPressed.
@Override
protected void okPressed() {
if (table != null) {
java.util.List<Object> values = new ArrayList<>();
for (DBDLabelValuePair item : getMultiValues()) {
if (table.getChecked(item)) {
values.add(item.getValue());
}
}
value = values.toArray();
} else if (editor != null) {
try {
value = editor.extractEditorValue();
} catch (DBException e) {
log.error("Can't get editor value", e);
}
} else {
value = textControl.getText();
}
super.okPressed();
}
use of org.jkiss.dbeaver.model.data.DBDLabelValuePair in project dbeaver by serge-rider.
the class FilterValueEditDialog method createMultiValueSelector.
private void createMultiValueSelector(Composite composite) {
table = CheckboxTableViewer.newCheckList(composite, SWT.BORDER | SWT.MULTI | SWT.CHECK | SWT.FULL_SELECTION);
table.getTable().setLinesVisible(true);
table.getTable().setHeaderVisible(true);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 400;
gd.heightHint = 300;
table.getTable().setLayoutData(gd);
table.setContentProvider(new ListContentProvider());
ViewerColumnController columnController = new ViewerColumnController(getClass().getName(), table);
columnController.addColumn("Value", "Value", SWT.LEFT, true, true, new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return attr.getValueHandler().getValueDisplayString(attr, ((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();
MenuManager menuMgr = new MenuManager();
menuMgr.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager manager) {
UIUtils.fillDefaultTableContextMenu(manager, table.getTable());
manager.add(new Separator());
manager.add(new Action("Select &All") {
@Override
public void run() {
for (DBDLabelValuePair row : getMultiValues()) {
table.setChecked(row, true);
}
}
});
manager.add(new Action("Select &None") {
@Override
public void run() {
for (DBDLabelValuePair row : getMultiValues()) {
table.setChecked(row, false);
}
}
});
}
});
menuMgr.setRemoveAllWhenShown(true);
table.getTable().setMenu(menuMgr.createContextMenu(table.getTable()));
if (attr.getDataKind() == DBPDataKind.STRING) {
// Create filter text
final Text valueFilterText = new Text(composite, SWT.BORDER);
valueFilterText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
valueFilterText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
filterPattern = valueFilterText.getText();
if (filterPattern.isEmpty()) {
filterPattern = null;
}
loadValues();
}
});
}
filterPattern = null;
loadValues();
}
use of org.jkiss.dbeaver.model.data.DBDLabelValuePair in project dbeaver by dbeaver.
the class AbstractMockValueGenerator method generateValue.
@Override
public Object generateValue(DBRProgressMonitor monitor) throws DBException, IOException {
if (isFirstRun) {
isFirstRun = false;
isUnique = DBUtils.checkUnique(monitor, dbsEntity, attribute);
if (isUnique && (attribute instanceof DBSAttributeEnumerable)) {
uniqueValues = new HashSet<>();
Collection<DBDLabelValuePair> valuePairs = readColumnValues(monitor, dbsEntity.getDataSource(), (DBSAttributeEnumerable) attribute, UNIQUE_VALUES_SET_SIZE);
for (DBDLabelValuePair pair : valuePairs) {
uniqueValues.add(pair.getValue());
}
}
}
if (isUnique) {
int attempts = 0;
Object value = null;
while (value == null || uniqueValues.contains(value)) {
if (attempts > UNIQUE_VALUE_GEN_ATTEMPTS) {
throw new DBException("\n Can't generate appropriate unique value for the '" + attribute.getName() + "' <" + attribute.getFullTypeName() + "> attribute.\n" + " Try to change the generator or its parameters.\n");
}
if (monitor.isCanceled()) {
return null;
}
value = generateOneValue(monitor);
attempts++;
}
uniqueValues.add(value);
return value;
} else {
return generateOneValue(monitor);
}
}
use of org.jkiss.dbeaver.model.data.DBDLabelValuePair in project dbeaver by dbeaver.
the class FKGenerator method generateOneValue.
@Override
public Object generateOneValue(DBRProgressMonitor monitor) throws DBException, IOException {
if (refValues == null) {
refValues = new ArrayList<>();
List<DBSEntityReferrer> attributeReferrers = DBUtils.getAttributeReferrers(monitor, (DBSEntityAttribute) attribute);
// TODO only the first
DBSEntityReferrer fk = attributeReferrers.get(0);
List<? extends DBSEntityAttributeRef> references = ((DBSEntityReferrer) fk).getAttributeReferences(monitor);
DBSTableForeignKeyColumn column = null;
for (DBSEntityAttributeRef ref : references) {
if (((DBPNamedObject) ref).getName().equals(attribute.getName())) {
column = (DBSTableForeignKeyColumn) ref;
}
}
if (column == null) {
throw new DBException("Can't find reference column for '" + attribute.getName() + "'");
}
int numberRefRecords = DBUtils.checkUnique(monitor, dbsEntity, attribute) ? UNIQ_REF_RECORDS_LIMIT : REF_RECORDS_LIMIT;
Collection<DBDLabelValuePair> values = readColumnValues(monitor, fk.getDataSource(), (DBSAttributeEnumerable) column.getReferencedColumn(), numberRefRecords);
for (DBDLabelValuePair value : values) {
refValues.add(value.getValue());
}
}
return refValues.get(random.nextInt(refValues.size()));
}
use of org.jkiss.dbeaver.model.data.DBDLabelValuePair in project dbeaver by dbeaver.
the class FilterValueEditDialog method okPressed.
@Override
protected void okPressed() {
if (handler.table != null) {
java.util.List<Object> values = new ArrayList<>();
for (DBDLabelValuePair item : handler.getMultiValues()) {
if (((TableItem) handler.table.testFindItem(item)).getChecked()) {
values.add(item.getValue());
}
}
value = values.toArray();
} else if (handler.editor != null) {
try {
value = handler.editor.extractEditorValue();
} catch (DBException e) {
log.error("Can't get editor value", e);
}
} else {
value = handler.textControl.getText();
}
super.okPressed();
}
Aggregations