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, 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 NavigatorUtils method createContextMenu.
public static MenuManager createContextMenu(final IWorkbenchSite workbenchSite, final Viewer viewer, final IMenuListener menuListener) {
final Control control = viewer.getControl();
final MenuManager menuMgr = new MenuManager();
Menu menu = menuMgr.createContextMenu(control);
menu.addMenuListener(new MenuListener() {
@Override
public void menuHidden(MenuEvent e) {
}
@Override
public void menuShown(MenuEvent e) {
Menu m = (Menu) e.widget;
DBNNode node = getSelectedNode(viewer.getSelection());
if (node != null && !node.isLocked() && node.allowsOpen()) {
String commandID = NavigatorUtils.getNodeActionCommand(DBXTreeNodeHandler.Action.open, node, CoreCommands.CMD_OBJECT_OPEN);
// Get contribution item from menu item and check it's ID
for (MenuItem item : m.getItems()) {
Object itemData = item.getData();
if (itemData instanceof IContributionItem) {
String contribId = ((IContributionItem) itemData).getId();
if (contribId != null && contribId.equals(commandID)) {
m.setDefaultItem(item);
}
}
}
}
}
});
menuMgr.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(final IMenuManager manager) {
ViewerColumnController columnController = ViewerColumnController.getFromControl(control);
if (columnController != null && columnController.isClickOnHeader()) {
columnController.fillConfigMenu(manager);
manager.add(new Separator());
return;
}
manager.add(new GroupMarker(MB_NAVIGATOR_ADDITIONS));
final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
final DBNNode selectedNode = getSelectedNode(viewer);
if (selectedNode != null && !selectedNode.isLocked() && workbenchSite != null) {
// Add "Set active object" menu
if (selectedNode.isPersisted() && selectedNode instanceof DBNDatabaseNode && !(selectedNode instanceof DBNDatabaseFolder) && ((DBNDatabaseNode) selectedNode).getObject() != null) {
final DBSObjectSelector activeContainer = DBUtils.getParentAdapter(DBSObjectSelector.class, ((DBNDatabaseNode) selectedNode).getObject());
if (activeContainer != null && activeContainer.supportsDefaultChange()) {
DBSObject activeChild;
activeChild = activeContainer.getDefaultObject();
if (activeChild != ((DBNDatabaseNode) selectedNode).getObject()) {
DBNDatabaseNode databaseNode = (DBNDatabaseNode) selectedNode;
if (databaseNode.getObject() != null && (activeChild == null || activeChild.getClass() == databaseNode.getObject().getClass())) {
// + databaseNode.getNodeType();
String text = "Set Active ";
// Fill context menu
IAction action = ActionUtils.makeAction(new NavigatorActionSetActiveObject(), workbenchSite, selection, text, null, null);
manager.add(action);
}
}
}
}
manager.add(new Separator());
manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
manager.add(new GroupMarker(IActionConstants.MB_ADDITIONS_END));
// Add properties button
if (PreferencesUtil.hasPropertiesContributors(selection.getFirstElement())) {
manager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_PROPERTIES));
}
if (selectedNode.isPersisted()) {
// Add refresh button
manager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_REFRESH));
}
}
manager.add(new GroupMarker(CoreCommands.GROUP_TOOLS));
if (menuListener != null) {
menuListener.menuAboutToShow(manager);
}
}
});
menuMgr.setRemoveAllWhenShown(true);
control.setMenu(menu);
control.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
menuMgr.dispose();
}
});
return menuMgr;
}
use of org.jkiss.dbeaver.ui.controls.ViewerColumnController in project dbeaver by dbeaver.
the class NavigatorUtils method createContextMenu.
public static MenuManager createContextMenu(final IWorkbenchSite workbenchSite, final Viewer viewer, final IMenuListener menuListener) {
final Control control = viewer.getControl();
final MenuManager menuMgr = new MenuManager();
Menu menu = menuMgr.createContextMenu(control);
menu.addMenuListener(new MenuListener() {
@Override
public void menuHidden(MenuEvent e) {
}
@Override
public void menuShown(MenuEvent e) {
Menu m = (Menu) e.widget;
DBNNode node = getSelectedNode(viewer.getSelection());
if (node != null && !node.isLocked() && node.allowsOpen()) {
String commandID = NavigatorUtils.getNodeActionCommand(DBXTreeNodeHandler.Action.open, node, CoreCommands.CMD_OBJECT_OPEN);
// Get contribution item from menu item and check it's ID
for (MenuItem item : m.getItems()) {
Object itemData = item.getData();
if (itemData instanceof IContributionItem) {
String contribId = ((IContributionItem) itemData).getId();
if (contribId != null && contribId.equals(commandID)) {
m.setDefaultItem(item);
}
}
}
}
}
});
menuMgr.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(final IMenuManager manager) {
ViewerColumnController columnController = ViewerColumnController.getFromControl(control);
if (columnController != null && columnController.isClickOnHeader()) {
columnController.fillConfigMenu(manager);
manager.add(new Separator());
return;
}
manager.add(new GroupMarker(CoreCommands.GROUP_NAVIGATOR_ADDITIONS));
final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
final DBNNode selectedNode = getSelectedNode(viewer);
if (selectedNode != null && !selectedNode.isLocked() && workbenchSite != null) {
// Add "Set active object" menu
if (selectedNode.isPersisted() && selectedNode instanceof DBNDatabaseNode && !(selectedNode instanceof DBNDatabaseFolder) && ((DBNDatabaseNode) selectedNode).getObject() != null) {
final DBSObjectSelector activeContainer = DBUtils.getParentAdapter(DBSObjectSelector.class, ((DBNDatabaseNode) selectedNode).getObject());
if (activeContainer != null && activeContainer.supportsDefaultChange()) {
DBSObject activeChild;
activeChild = activeContainer.getDefaultObject();
if (activeChild != ((DBNDatabaseNode) selectedNode).getObject()) {
DBNDatabaseNode databaseNode = (DBNDatabaseNode) selectedNode;
if (databaseNode.getObject() != null && (activeChild == null || activeChild.getClass() == databaseNode.getObject().getClass())) {
manager.add(ActionUtils.makeCommandContribution(workbenchSite, CoreCommands.CMD_OBJECT_SET_ACTIVE));
}
}
}
}
manager.add(new Separator());
manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
manager.add(new GroupMarker(IActionConstants.MB_ADDITIONS_END));
// Add properties button
if (PreferencesUtil.hasPropertiesContributors(selection.getFirstElement())) {
manager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_PROPERTIES));
}
if (selectedNode.isPersisted()) {
// Add refresh button
manager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_REFRESH));
}
}
manager.add(new GroupMarker(CoreCommands.GROUP_TOOLS));
manager.add(new GroupMarker(CoreCommands.GROUP_TOOLS_END));
if (menuListener != null) {
menuListener.menuAboutToShow(manager);
}
}
});
menuMgr.setRemoveAllWhenShown(true);
control.setMenu(menu);
control.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
menuMgr.dispose();
}
});
return menuMgr;
}
use of org.jkiss.dbeaver.ui.controls.ViewerColumnController in project dbeaver by serge-rider.
the class OracleCompilerDialog method createDialogArea.
@Override
protected Composite createDialogArea(Composite parent) {
GridData gd;
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(2, false));
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
{
Composite unitsGroup = new Composite(composite, SWT.NONE);
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 250;
gd.heightHint = 200;
gd.verticalIndent = 0;
gd.horizontalIndent = 0;
unitsGroup.setLayoutData(gd);
unitsGroup.setLayout(new GridLayout(1, false));
unitTable = new TableViewer(unitsGroup, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
{
final Table table = unitTable.getTable();
table.setLayoutData(new GridData(GridData.FILL_BOTH));
table.setLinesVisible(true);
table.setHeaderVisible(true);
}
ViewerColumnController columnController = new ViewerColumnController("OracleCompilerDialog", unitTable);
columnController.addColumn(OracleUIMessages.views_oracle_compiler_dialog_column_name, null, SWT.NONE, true, true, new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
DBSObject unit = (DBSObject) cell.getElement();
final DBNDatabaseNode node = DBNUtils.getNodeByObject(unit);
if (node != null) {
cell.setText(node.getNodeName());
cell.setImage(DBeaverIcons.getImage(node.getNodeIconDefault()));
} else {
cell.setText(unit.toString());
}
}
});
columnController.addColumn(OracleUIMessages.views_oracle_compiler_dialog_column_type, null, SWT.NONE, true, true, new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
DBSObject unit = (DBSObject) cell.getElement();
final DBNDatabaseNode node = DBNUtils.getNodeByObject(unit);
if (node != null) {
cell.setText(node.getNodeType());
} else {
// $NON-NLS-1$
cell.setText("???");
}
}
});
columnController.createColumns();
unitTable.addSelectionChangedListener(event -> {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
getButton(COMPILE_ID).setEnabled(!selection.isEmpty());
});
unitTable.addDoubleClickListener(event -> {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
if (!selection.isEmpty()) {
OracleSourceObject unit = (OracleSourceObject) selection.getFirstElement();
NavigatorHandlerObjectOpen.openEntityEditor(unit);
}
});
unitTable.setContentProvider(new ListContentProvider());
unitTable.setInput(compileUnits);
}
{
Composite infoGroup = new Composite(composite, SWT.NONE);
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 400;
gd.heightHint = 200;
gd.verticalIndent = 0;
gd.horizontalIndent = 0;
infoGroup.setLayoutData(gd);
infoGroup.setLayout(new GridLayout(1, false));
compileLog = new ObjectCompilerLogViewer(infoGroup, null, true);
}
return composite;
}
use of org.jkiss.dbeaver.ui.controls.ViewerColumnController in project dbeaver by serge-rider.
the class ObjectListControl method setListData.
protected void setListData(Collection<OBJECT_TYPE> items, boolean append) {
final Control itemsControl = itemsViewer.getControl();
if (itemsControl.isDisposed()) {
return;
}
itemsControl.setRedraw(false);
try {
final boolean reload = !append && (CommonUtils.isEmpty(objectList)) || (columnController == null);
{
// Collect list of items' classes
final List<Class<?>> classList = new ArrayList<>();
Class<?>[] baseTypes = getListBaseTypes(items);
if (!ArrayUtils.isEmpty(baseTypes)) {
Collections.addAll(classList, baseTypes);
}
if (!CommonUtils.isEmpty(items)) {
for (OBJECT_TYPE item : items) {
Object object = getObjectValue(item);
if (object != null && !classList.contains(object.getClass())) {
// and we need to show "Name" instead of particular name props
for (int i = 0; i < classList.size(); i++) {
Class<?> c = classList.get(i);
if (!c.isInterface() && c.isAssignableFrom(object.getClass())) {
classList.remove(i);
} else {
i++;
}
}
classList.add(object.getClass());
}
if (renderer.isTree()) {
Map<OBJECT_TYPE, Boolean> collectedSet = new IdentityHashMap<>();
collectItemClasses(item, classList, collectedSet);
}
}
}
IPropertyFilter propertyFilter = new DataSourcePropertyFilter(ObjectListControl.this instanceof IDataSourceContainerProvider ? ((IDataSourceContainerProvider) ObjectListControl.this).getDataSourceContainer() : null);
// Collect all properties
PropertySourceAbstract propertySource = getListPropertySource();
List<ObjectPropertyDescriptor> allProps = ObjectAttributeDescriptor.extractAnnotations(propertySource, classList, propertyFilter);
if (!CommonUtils.isEmpty(items)) {
// Remove hidden properties (we need to check them against all items)
try {
allProps.removeIf(p -> {
for (OBJECT_TYPE item : items) {
Object objectValue = getObjectValue(item);
if (p.isPropertyVisible(objectValue, objectValue)) {
return false;
}
}
return true;
});
} catch (Throwable e) {
log.debug(e);
}
}
if (reload) {
clearListData();
columnController = new ViewerColumnController<>(getListConfigId(classList), getItemsViewer());
}
// Create columns from classes' annotations
for (ObjectPropertyDescriptor prop : allProps) {
if (!propertySource.hasProperty(prop)) {
if (prop.isOptional()) {
// Check whether at least one itme has this property
boolean propHasValue = false;
if (!CommonUtils.isEmpty(items)) {
for (OBJECT_TYPE item : items) {
try {
Object propValue = prop.readValue(getObjectValue(item), null, true);
if (propValue != null) {
propHasValue = true;
break;
}
} catch (Throwable e) {
// Just ignore this
}
}
}
if (!propHasValue) {
continue;
}
}
propertySource.addProperty(prop);
createColumn(prop);
}
}
}
if (itemsControl.isDisposed()) {
return;
}
if (reload) {
columnController.createColumns(false);
}
if (reload || objectList.isEmpty()) {
// Set viewer content
objectList = CommonUtils.isEmpty(items) ? new ArrayList<>() : new ArrayList<>(items);
// Pack columns
sampleItems = true;
try {
List<OBJECT_TYPE> sampleList;
if (objectList.size() > 200) {
sampleList = objectList.subList(0, 100);
} else {
sampleList = objectList;
}
itemsViewer.setInput(sampleList);
if (renderer.isTree()) {
((TreeViewer) itemsViewer).expandToLevel(4);
}
if (reload) {
columnController.repackColumns();
}
} finally {
sampleItems = false;
}
// Set real content
itemsViewer.setInput(objectList);
} else if (items != null) {
if (append) {
// Simply append new list to the tail
for (OBJECT_TYPE newObject : items) {
if (!objectList.contains(newObject)) {
objectList.add(newObject);
}
}
} else {
// Update object list
if (!objectList.equals(items)) {
int newListSize = items.size();
int itemIndex = 0;
for (OBJECT_TYPE newObject : items) {
if (itemIndex >= objectList.size()) {
// Add to tail
objectList.add(itemIndex, newObject);
} else {
OBJECT_TYPE oldObject = objectList.get(itemIndex);
if (!CommonUtils.equalObjects(oldObject, newObject)) {
// Replace old object
objectList.set(itemIndex, newObject);
}
}
itemIndex++;
}
while (objectList.size() > newListSize) {
objectList.remove(objectList.size() - 1);
}
}
}
itemsViewer.refresh();
}
} finally {
itemsControl.setRedraw(true);
}
setInfo(getItemsLoadMessage(objectList.size()));
if (IS_MACOS_BIG_SUR) {
// [#10162]
itemsControl.redraw();
}
}
Aggregations