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 ISelectionProvider selectionProvider, 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, NavigatorCommands.CMD_OBJECT_OPEN);
// Get contribution item from menu item and check it's ID
try {
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);
}
}
}
} catch (Exception ex) {
log.debug(ex);
}
}
}
});
menuMgr.addMenuListener(manager -> {
ViewerColumnController columnController = ViewerColumnController.getFromControl(control);
if (columnController != null && columnController.isClickOnHeader()) {
columnController.fillConfigMenu(manager);
manager.add(new Separator());
return;
}
manager.add(new Separator());
addStandardMenuItem(workbenchSite, manager, selectionProvider);
if (menuListener != null) {
menuListener.menuAboutToShow(manager);
}
});
menuMgr.setRemoveAllWhenShown(true);
control.setMenu(menu);
return menuMgr;
}
use of org.jkiss.dbeaver.ui.controls.ViewerColumnController in project dbeaver by dbeaver.
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 dbeaver.
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();
}
}
use of org.jkiss.dbeaver.ui.controls.ViewerColumnController in project dbeaver by dbeaver.
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 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);
}
Aggregations