use of org.jkiss.dbeaver.ui.controls.ViewerColumnController in project dbeaver by dbeaver.
the class GenericFilterValueEdit 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;
if (isCheckedTable)
for (DBDLabelValuePair row : sortedList) {
Object cellValue = row.getValue();
if (checkedValues.contains(cellValue)) {
TableItem t = (TableItem) table.testFindItem(row);
t.setChecked(true);
// ((CheckboxTableViewer) table).setChecked(row, true);
if (firstVisibleItem == null) {
firstVisibleItem = row;
}
}
}
ViewerColumnController vcc = ViewerColumnController.getFromControl(table.getTable());
if (vcc != null)
vcc.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.ui.controls.ViewerColumnController in project dbeaver by serge-rider.
the class DatabaseTasksView method createTaskRunTable.
private void createTaskRunTable(Composite parent) {
taskRunViewer = DialogUtils.createFilteredTree(parent, SWT.SINGLE | SWT.FULL_SELECTION, new NamedObjectPatternFilter(), TaskUIMessages.db_tasks_view_filtered_tree_text_error_message);
Tree taskrunTree = taskRunViewer.getTree();
taskrunTree.setHeaderVisible(true);
taskrunTree.setLayoutData(new GridData(GridData.FILL_BOTH));
taskRunColumnController = new ViewerColumnController("taskruns", taskRunViewer);
taskRunColumnController.addColumn(TaskUIMessages.db_tasks_view_column_controller_add_name_time, TaskUIMessages.db_tasks_view_column_controller_add_descr_start_time, SWT.LEFT, true, true, new TaskRunLabelProvider() {
@Override
protected void update(ViewerCell cell, DBTTaskRun taskRun) {
cell.setText(tasksTree.getDateFormat().format(taskRun.getStartTime()));
}
});
taskRunColumnController.addColumn(TaskUIMessages.db_tasks_view_column_controller_add_name_duration, TaskUIMessages.db_tasks_view_column_controller_add_descr_task_duration, SWT.LEFT, true, false, true, null, new TaskRunLabelProviderEx() {
@Override
public String getText(Object element, boolean forUI) {
DBTTaskRun taskRun = (DBTTaskRun) element;
return forUI ? RuntimeUtils.formatExecutionTime(taskRun.getRunDuration()) : String.valueOf(taskRun.getRunDuration());
}
@Override
protected void update(ViewerCell cell, DBTTaskRun taskRun) {
cell.setText(RuntimeUtils.formatExecutionTime(taskRun.getRunDuration()));
}
}, null);
taskRunColumnController.addColumn(TaskUIMessages.db_tasks_view_column_controller_add_name_result, TaskUIMessages.db_tasks_view_column_controller_add_descr_task_result, SWT.LEFT, true, false, new TaskRunLabelProvider() {
@Override
protected void update(ViewerCell cell, DBTTaskRun taskRun) {
if (taskRun.isRunSuccess()) {
cell.setText(TaskUIMessages.db_tasks_view_cell_text_success);
} else {
cell.setText(CommonUtils.notEmpty(taskRun.getErrorMessage()));
}
}
});
taskRunColumnController.setForceAutoSize(true);
taskRunColumnController.createColumns(true);
taskRunViewer.setContentProvider(new TreeRunContentProvider());
MenuManager menuMgr = createTaskRunContextMenu(taskRunViewer);
getSite().registerContextMenu(menuMgr, taskRunViewer);
taskRunViewer.addDoubleClickListener(event -> new ViewRunLogAction().run());
}
use of org.jkiss.dbeaver.ui.controls.ViewerColumnController in project dbeaver by serge-rider.
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 serge-rider.
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);
}
use of org.jkiss.dbeaver.ui.controls.ViewerColumnController in project dbeaver by serge-rider.
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);
}
Aggregations