use of org.jkiss.dbeaver.ui.controls.ViewerColumnController 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.ui.controls.ViewerColumnController in project dbeaver by serge-rider.
the class ProjectExplorerView method createColumns.
private void createColumns(final TreeViewer viewer) {
final Color shadowColor = viewer.getControl().getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
final ILabelProvider mainLabelProvider = (ILabelProvider) viewer.getLabelProvider();
columnController = new ViewerColumnController("projectExplorer", viewer);
columnController.setForceAutoSize(true);
columnController.addColumn("Name", "Resource name", SWT.LEFT, true, true, new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return mainLabelProvider.getText(element);
}
@Override
public Image getImage(Object element) {
Image image = mainLabelProvider.getImage(element);
if (element instanceof DBNResource) {
image = labelDecorator.decorateImage(image, element);
}
return image;
}
@Override
public String getToolTipText(Object element) {
if (mainLabelProvider instanceof IToolTipProvider) {
return ((IToolTipProvider) mainLabelProvider).getToolTipText(element);
}
return null;
}
});
columnController.addColumn("DataSource", "Datasource(s) associated with resource", SWT.LEFT, true, false, new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof DBNDatabaseNode) {
return ((DBNDatabaseNode) element).getDataSourceContainer().getName();
} else if (element instanceof DBNResource) {
Collection<DBPDataSourceContainer> containers = ((DBNResource) element).getAssociatedDataSources();
if (!CommonUtils.isEmpty(containers)) {
StringBuilder text = new StringBuilder();
for (DBPDataSourceContainer container : containers) {
if (text.length() > 0) {
text.append(", ");
}
text.append(container.getName());
}
return text.toString();
}
}
return "";
}
@Override
public Image getImage(Object element) {
/*
DBNNode node = (DBNNode) element;
if (node instanceof DBNDatabaseNode) {
return DBeaverIcons.getImage(((DBNDatabaseNode) node).getDataSourceContainer().getDriver().getIcon());
} else if (node instanceof DBNResource) {
Collection<DBPDataSourceContainer> containers = ((DBNResource) node).getAssociatedDataSources();
if (containers != null && containers.size() == 1) {
return DBeaverIcons.getImage((containers.iterator().next().getDriver().getIcon()));
}
}
*/
return null;
}
@Override
public String getToolTipText(Object element) {
if (element instanceof DBNResource) {
Collection<DBPDataSourceContainer> containers = ((DBNResource) element).getAssociatedDataSources();
if (!CommonUtils.isEmpty(containers)) {
StringBuilder text = new StringBuilder();
for (DBPDataSourceContainer container : containers) {
String description = container.getDescription();
if (CommonUtils.isEmpty(description)) {
description = container.getName();
}
if (!CommonUtils.isEmpty(description)) {
if (text.length() > 0) {
text.append(", ");
}
text.append(description);
}
}
return text.toString();
}
}
return null;
}
});
columnController.addColumn("Preview", "Script content preview", SWT.LEFT, false, false, new LazyLabelProvider(shadowColor) {
@Override
public String getLazyText(Object element) {
if (element instanceof DBNNode) {
return ((DBNNode) element).getNodeDescription();
} else {
return null;
}
}
});
columnController.addColumn("Size", "File size", SWT.LEFT, false, false, true, null, new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof DBNResource) {
IResource resource = ((DBNResource) element).getResource();
if (resource instanceof IFile) {
return String.valueOf(resource.getLocation().toFile().length());
}
}
return "";
}
}, null);
columnController.addColumn("Modified", "Time the file was last modified", SWT.LEFT, false, false, new ColumnLabelProvider() {
private SimpleDateFormat sdf = new SimpleDateFormat(DBConstants.DEFAULT_TIMESTAMP_FORMAT);
@Override
public String getText(Object element) {
if (element instanceof DBNResource) {
IResource resource = ((DBNResource) element).getResource();
if (resource instanceof IFile || resource instanceof IFolder) {
long lastModified = resource.getLocation().toFile().lastModified();
if (lastModified <= 0) {
return "";
}
return sdf.format(new Date(lastModified));
}
}
return "";
}
});
columnController.addColumn("Type", "Resource type", SWT.LEFT, false, false, new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof DBNResource) {
IResource resource = ((DBNResource) element).getResource();
ProgramInfo program = ProgramInfo.getProgram(resource);
if (program != null) {
return program.getProgram().getName();
}
}
return "";
}
});
UIUtils.asyncExec(() -> columnController.createColumns(true));
}
use of org.jkiss.dbeaver.ui.controls.ViewerColumnController in project dbeaver by serge-rider.
the class PostgreCreateExtensionDialog method createDialogArea.
@Override
protected Composite createDialogArea(Composite parent) {
final Composite composite = super.createDialogArea(parent);
final Composite group = new Composite(composite, SWT.NONE);
group.setLayout(new GridLayout(2, false));
GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 600;
gd.heightHint = 200;
gd.verticalIndent = 0;
gd.horizontalIndent = 0;
group.setLayoutData(gd);
// $NON-NLS-2$
final Text databaseText = UIUtils.createLabelText(group, PostgreMessages.dialog_create_extension_database, newextension.getDatabase().getName(), SWT.BORDER | SWT.READ_ONLY);
final Combo schemaCombo = UIUtils.createLabelCombo(group, PostgreMessages.dialog_create_extension_schema, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
final Label lblExtension = UIUtils.createLabel(group, PostgreMessages.dialog_create_extension_name);
extTable = new TableViewer(group, SWT.BORDER | SWT.UNDERLINE_SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
{
final Table table = extTable.getTable();
table.setLayoutData(new GridData(GridData.FILL_BOTH));
table.setLinesVisible(true);
table.setHeaderVisible(true);
table.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
UIUtils.packColumns(table);
UIUtils.maxTableColumnsWidth(table);
table.removeControlListener(this);
}
});
}
ViewerColumnController columnController = new ViewerColumnController("AvailabelExtensionDialog", extTable);
columnController.addColumn(PostgreMessages.dialog_create_extension_column_name, null, SWT.NONE, true, true, new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
cell.setText(((PostgreAvailableExtension) cell.getElement()).getName());
}
});
columnController.addColumn(PostgreMessages.dialog_create_extension_column_version, null, SWT.NONE, true, true, new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
cell.setText(((PostgreAvailableExtension) cell.getElement()).getVersion());
}
});
columnController.addColumn(PostgreMessages.dialog_create_extension_column_description, null, SWT.NONE, true, true, new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
cell.setText(((PostgreAvailableExtension) cell.getElement()).getDescription());
}
});
columnController.createColumns();
extTable.addSelectionChangedListener(event -> {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
if (!selection.isEmpty()) {
// installed.get(extensionCombo.getSelectionIndex());
extension = (PostgreAvailableExtension) selection.getFirstElement();
checkEnabled();
}
});
extTable.setContentProvider(new ListContentProvider());
schemaCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
schema = allSchemas.get(schemaCombo.getSelectionIndex());
checkEnabled();
}
});
new AbstractJob("Load schemas") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
allSchemas = new ArrayList<>(newextension.getDatabase().getSchemas(monitor));
UIUtils.syncExec(() -> {
for (PostgreSchema schema : allSchemas) {
schemaCombo.add(schema.getName());
}
schema = DBUtils.findObject(allSchemas, PostgreConstants.PUBLIC_SCHEMA_NAME);
if (schema != null) {
schemaCombo.setText(schema.getName());
}
});
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
return Status.OK_STATUS;
}
}.schedule();
new AbstractJob("Load available extensions") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
final List<PostgreAvailableExtension> installed = new ArrayList<>(newextension.getDatabase().getAvailableExtensions(monitor));
UIUtils.syncExec(() -> {
extTable.setInput(installed);
});
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
return Status.OK_STATUS;
}
}.schedule();
return composite;
}
use of org.jkiss.dbeaver.ui.controls.ViewerColumnController in project dbeaver by dbeaver.
the class SQLScriptTaskDataSourceSelectorDialog method createScriptColumns.
static void createScriptColumns(ColumnViewer viewer) {
final ILabelProvider mainLabelProvider = (ILabelProvider) viewer.getLabelProvider();
ViewerColumnController columnController = new ViewerColumnController("sqlTaskScriptViewer", viewer);
columnController.setForceAutoSize(true);
columnController.addColumn(ModelMessages.model_navigator_Name, DTUIMessages.sql_script_task_data_source_selection_dialog_column_description_script, SWT.LEFT, true, true, new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return mainLabelProvider.getText(element);
}
@Override
public Image getImage(Object element) {
return mainLabelProvider.getImage(element);
}
@Override
public String getToolTipText(Object element) {
if (mainLabelProvider instanceof IToolTipProvider) {
return ((IToolTipProvider) mainLabelProvider).getToolTipText(element);
}
return null;
}
});
columnController.addColumn(ModelMessages.model_navigator_Connection, DTUIMessages.sql_script_task_data_source_selection_dialog_column_description_script_data_source, SWT.LEFT, true, true, new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof DBNResource) {
Collection<DBPDataSourceContainer> containers = ((DBNResource) element).getAssociatedDataSources();
if (!CommonUtils.isEmpty(containers)) {
StringBuilder text = new StringBuilder();
for (DBPDataSourceContainer container : containers) {
if (text.length() > 0) {
text.append(", ");
}
text.append(container.getName());
}
return text.toString();
}
}
return "";
}
@Override
public Image getImage(Object element) {
return null;
}
});
columnController.createColumns(true);
}
use of org.jkiss.dbeaver.ui.controls.ViewerColumnController in project dbeaver by dbeaver.
the class SQLScriptTaskScriptSelectorDialog method createScriptColumns.
static void createScriptColumns(ColumnViewer viewer) {
final ILabelProvider mainLabelProvider = (ILabelProvider) viewer.getLabelProvider();
ViewerColumnController columnController = new ViewerColumnController("sqlTaskScriptViewer", viewer);
columnController.setForceAutoSize(true);
columnController.addColumn(ModelMessages.model_navigator_Name, DTUIMessages.sql_script_task_selector_dialog_column_description_script, SWT.LEFT, true, true, new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return mainLabelProvider.getText(element);
}
@Override
public Image getImage(Object element) {
return mainLabelProvider.getImage(element);
}
@Override
public String getToolTipText(Object element) {
if (mainLabelProvider instanceof IToolTipProvider) {
return ((IToolTipProvider) mainLabelProvider).getToolTipText(element);
}
return null;
}
});
columnController.addColumn(ModelMessages.model_navigator_Connection, DTUIMessages.sql_script_task_selector_dialog_column_description_script_data_source, SWT.LEFT, true, true, new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof DBNResource) {
Collection<DBPDataSourceContainer> containers = ((DBNResource) element).getAssociatedDataSources();
if (!CommonUtils.isEmpty(containers)) {
StringBuilder text = new StringBuilder();
for (DBPDataSourceContainer container : containers) {
if (text.length() > 0) {
text.append(", ");
}
text.append(container.getName());
}
return text.toString();
}
}
return "";
}
@Override
public Image getImage(Object element) {
return null;
}
});
columnController.createColumns(true);
}
Aggregations