use of org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTreeFilter in project dbeaver by dbeaver.
the class BrowseObjectDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
getShell().setText(title);
Composite group = (Composite) super.createDialogArea(parent);
GridData gd = new GridData(GridData.FILL_BOTH);
group.setLayoutData(gd);
navigatorTree = new DatabaseNavigatorTree(group, rootNode, (singleSelection ? SWT.SINGLE : SWT.MULTI) | SWT.BORDER, false, new DatabaseNavigatorTreeFilter());
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 500;
gd.heightHint = 500;
navigatorTree.setLayoutData(gd);
final TreeViewer treeViewer = navigatorTree.getViewer();
treeViewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof TreeLoadNode || element instanceof DBNLocalFolder) {
return true;
}
if (element instanceof DBNNode) {
if (element instanceof DBNDatabaseFolder) {
DBNDatabaseFolder folder = (DBNDatabaseFolder) element;
Class<? extends DBSObject> folderItemsClass = folder.getChildrenClass();
return folderItemsClass != null && matchesType(folderItemsClass, false);
}
if (element instanceof DBNProject || element instanceof DBNProjectDatabases || element instanceof DBNDataSource || (element instanceof DBSWrapper && matchesType(((DBSWrapper) element).getObject().getClass(), false))) {
return true;
}
}
return false;
}
});
if (selectedNode != null) {
treeViewer.setSelection(new StructuredSelection(selectedNode));
selectedObjects.add(selectedNode);
}
treeViewer.addSelectionChangedListener(event -> {
selectedObjects.clear();
IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
for (Iterator iter = selection.iterator(); iter.hasNext(); ) {
DBNNode node = (DBNNode) iter.next();
if (node instanceof DBSWrapper) {
DBSObject object = DBUtils.getAdapter(DBSObject.class, ((DBSWrapper) node).getObject());
if (object != null) {
if (!matchesType(object.getClass(), true)) {
selectedObjects.clear();
break;
}
selectedObjects.add(node);
}
}
}
getButton(IDialogConstants.OK_ID).setEnabled(!selectedObjects.isEmpty());
});
treeViewer.addDoubleClickListener(event -> okPressed());
treeViewer.getTree().setFocus();
return group;
}
use of org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTreeFilter in project dbeaver by serge-rider.
the class ObjectBrowserDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
getShell().setText(title);
Composite group = (Composite) super.createDialogArea(parent);
GridData gd = new GridData(GridData.FILL_BOTH);
group.setLayoutData(gd);
DatabaseNavigatorTreeFilter filter = new DatabaseNavigatorTreeFilter() {
@Override
public boolean isLeafObject(Object object) {
if (leafTypes != null && leafTypes.length > 0) {
if (object instanceof DBNDatabaseNode) {
DBSObject dbObject = ((DBNDatabaseNode) object).getObject();
if (dbObject != null) {
for (Class<?> leafType : leafTypes) {
if (leafType.isAssignableFrom(dbObject.getClass())) {
return true;
}
}
}
}
}
return super.isLeafObject(object);
}
};
navigatorTree = new DatabaseNavigatorTree(group, rootNode, (singleSelection ? SWT.SINGLE : SWT.MULTI) | SWT.BORDER, false, filter);
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 500;
gd.heightHint = 500;
navigatorTree.setLayoutData(gd);
final TreeViewer treeViewer = navigatorTree.getViewer();
treeViewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (showConnected) {
if (element instanceof DBNDataSource) {
return ((DBNDataSource) element).getDataSource() != null;
}
if (element instanceof DBNLocalFolder) {
return ((DBNLocalFolder) element).hasConnected();
}
}
if (element instanceof TreeNodeSpecial || element instanceof DBNLocalFolder) {
return true;
}
if (element instanceof DBNNode) {
if (element instanceof DBNDatabaseFolder) {
DBNDatabaseFolder folder = (DBNDatabaseFolder) element;
Class<? extends DBSObject> folderItemsClass = folder.getChildrenClass();
return folderItemsClass != null && matchesType(folderItemsClass, false);
}
if (element instanceof DBNProject || element instanceof DBNProjectDatabases || element instanceof DBNDataSource || (element instanceof DBSWrapper && matchesType(((DBSWrapper) element).getObject().getClass(), false))) {
return true;
}
}
return false;
}
});
if (selectedNode != null) {
treeViewer.setSelection(new StructuredSelection(selectedNode));
if (!(selectedNode instanceof DBNDataSource) || ((DBNDataSource) selectedNode).getDataSourceContainer().isConnected()) {
treeViewer.expandToLevel(selectedNode, 1);
}
selectedObjects.add(selectedNode);
}
treeViewer.addSelectionChangedListener(event -> {
selectedObjects.clear();
specialNode = null;
IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
for (Iterator iter = selection.iterator(); iter.hasNext(); ) {
Object node = iter.next();
if (node instanceof DBNNode && node instanceof DBSWrapper) {
DBSObject object = DBUtils.getAdapter(DBSObject.class, ((DBSWrapper) node).getObject());
if (object != null) {
if (!matchesType(object.getClass(), true)) {
selectedObjects.clear();
break;
}
selectedObjects.add((DBNNode) node);
}
} else if (node instanceof TreeNodeSpecial) {
specialNode = (TreeNodeSpecial) node;
}
}
getButton(IDialogConstants.OK_ID).setEnabled(!selectedObjects.isEmpty());
});
treeViewer.addDoubleClickListener(event -> {
if (!selectedObjects.isEmpty()) {
okPressed();
} else if (specialNode != null) {
specialNode.handleDefaultAction(navigatorTree);
}
});
treeViewer.getTree().setFocus();
final Button showConnectedCheck = new Button(group, SWT.CHECK);
showConnectedCheck.setText(UINavigatorMessages.label_show_connected);
showConnectedCheck.setSelection(showConnected);
showConnectedCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
showConnected = showConnectedCheck.getSelection();
treeViewer.getControl().setRedraw(false);
try {
treeViewer.refresh();
if (showConnected) {
treeViewer.expandAll();
}
} finally {
treeViewer.getControl().setRedraw(true);
}
}
});
return group;
}
use of org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTreeFilter in project dbeaver by dbeaver.
the class ObjectBrowserDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
getShell().setText(title);
Composite group = (Composite) super.createDialogArea(parent);
GridData gd = new GridData(GridData.FILL_BOTH);
group.setLayoutData(gd);
DatabaseNavigatorTreeFilter filter = new DatabaseNavigatorTreeFilter() {
@Override
public boolean isLeafObject(Object object) {
if (leafTypes != null && leafTypes.length > 0) {
if (object instanceof DBNDatabaseNode) {
DBSObject dbObject = ((DBNDatabaseNode) object).getObject();
if (dbObject != null) {
for (Class<?> leafType : leafTypes) {
if (leafType.isAssignableFrom(dbObject.getClass())) {
return true;
}
}
}
}
}
return super.isLeafObject(object);
}
};
navigatorTree = new DatabaseNavigatorTree(group, rootNode, (singleSelection ? SWT.SINGLE : SWT.MULTI) | SWT.BORDER, false, filter);
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 500;
gd.heightHint = 500;
navigatorTree.setLayoutData(gd);
final TreeViewer treeViewer = navigatorTree.getViewer();
treeViewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (showConnected) {
if (element instanceof DBNDataSource) {
return ((DBNDataSource) element).getDataSource() != null;
}
if (element instanceof DBNLocalFolder) {
return ((DBNLocalFolder) element).hasConnected();
}
}
if (element instanceof TreeNodeSpecial || element instanceof DBNLocalFolder) {
return true;
}
if (element instanceof DBNNode) {
if (element instanceof DBNDatabaseFolder) {
DBNDatabaseFolder folder = (DBNDatabaseFolder) element;
Class<? extends DBSObject> folderItemsClass = folder.getChildrenClass();
return folderItemsClass != null && matchesType(folderItemsClass, false);
}
if (element instanceof DBNProject || element instanceof DBNProjectDatabases || element instanceof DBNDataSource || (element instanceof DBSWrapper && matchesType(((DBSWrapper) element).getObject().getClass(), false))) {
return true;
}
}
return false;
}
});
if (selectedNode != null) {
treeViewer.setSelection(new StructuredSelection(selectedNode));
if (!(selectedNode instanceof DBNDataSource) || ((DBNDataSource) selectedNode).getDataSourceContainer().isConnected()) {
treeViewer.expandToLevel(selectedNode, 1);
}
selectedObjects.add(selectedNode);
}
treeViewer.addSelectionChangedListener(event -> {
selectedObjects.clear();
specialNode = null;
IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
for (Iterator iter = selection.iterator(); iter.hasNext(); ) {
Object node = iter.next();
if (node instanceof DBNNode && node instanceof DBSWrapper) {
DBSObject object = DBUtils.getAdapter(DBSObject.class, ((DBSWrapper) node).getObject());
if (object != null) {
if (!matchesType(object.getClass(), true)) {
selectedObjects.clear();
break;
}
selectedObjects.add((DBNNode) node);
}
} else if (node instanceof TreeNodeSpecial) {
specialNode = (TreeNodeSpecial) node;
}
}
getButton(IDialogConstants.OK_ID).setEnabled(!selectedObjects.isEmpty());
});
treeViewer.addDoubleClickListener(event -> {
if (!selectedObjects.isEmpty()) {
okPressed();
} else if (specialNode != null) {
specialNode.handleDefaultAction(navigatorTree);
}
});
treeViewer.getTree().setFocus();
final Button showConnectedCheck = new Button(group, SWT.CHECK);
showConnectedCheck.setText(UINavigatorMessages.label_show_connected);
showConnectedCheck.setSelection(showConnected);
showConnectedCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
showConnected = showConnectedCheck.getSelection();
treeViewer.getControl().setRedraw(false);
try {
treeViewer.refresh();
if (showConnected) {
treeViewer.expandAll();
}
} finally {
treeViewer.getControl().setRedraw(true);
}
}
});
return group;
}
Aggregations