use of org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeSpecial 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.load.TreeNodeSpecial in project dbeaver by serge-rider.
the class NavigatorViewBase method createNavigatorTree.
private DatabaseNavigatorTree createNavigatorTree(Composite parent, DBNNode rootNode) {
// Create tree
final DatabaseNavigatorTree navigatorTree = new DatabaseNavigatorTree(parent, rootNode, getTreeStyle(), false, getNavigatorFilter());
createTreeColumns(navigatorTree);
navigatorTree.getViewer().addSelectionChangedListener(event -> onSelectionChange((IStructuredSelection) event.getSelection()));
navigatorTree.getViewer().getTree().addListener(SWT.MouseDoubleClick, event -> {
event.doit = false;
});
navigatorTree.getViewer().getTree().addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
super.mouseDoubleClick(e);
}
@Override
public void mouseDown(MouseEvent e) {
super.mouseDown(e);
}
@Override
public void mouseUp(MouseEvent e) {
super.mouseUp(e);
}
});
navigatorTree.getViewer().addDoubleClickListener(event -> {
TreeViewer viewer = tree.getViewer();
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
for (Object node : selection.toArray()) {
// Object node = selection.getFirstElement();
if ((node instanceof DBNResource && ((DBNResource) node).getResource() instanceof IFolder)) {
toggleNode(viewer, node);
} else if (node instanceof DBNDataSource) {
NavigatorPreferences.DoubleClickBehavior dsBehaviorDefault = CommonUtils.valueOf(NavigatorPreferences.DoubleClickBehavior.class, DBWorkbench.getPlatform().getPreferenceStore().getString(NavigatorPreferences.NAVIGATOR_CONNECTION_DOUBLE_CLICK), NavigatorPreferences.DoubleClickBehavior.EDIT);
if (dsBehaviorDefault == NavigatorPreferences.DoubleClickBehavior.EXPAND) {
toggleNode(viewer, node);
} else {
DBPDataSourceContainer dataSource = ((DBNDataSource) node).getObject();
switch(dsBehaviorDefault) {
case EDIT:
NavigatorHandlerObjectOpen.openEntityEditor((DBNDataSource) node, null, UIUtils.getActiveWorkbenchWindow());
break;
case CONNECT:
{
UIServiceConnections serviceConnections = DBWorkbench.getService(UIServiceConnections.class);
if (serviceConnections != null) {
if (dataSource.isConnected()) {
serviceConnections.disconnectDataSource(dataSource);
} else {
serviceConnections.connectDataSource(dataSource, null);
}
}
break;
}
case SQL_EDITOR:
{
UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
if (serviceSQL != null) {
serviceSQL.openRecentScript(dataSource);
}
break;
}
case SQL_EDITOR_NEW:
{
UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
if (serviceSQL != null) {
serviceSQL.openNewScript(dataSource);
}
break;
}
}
}
} else if (node instanceof TreeNodeSpecial) {
((TreeNodeSpecial) node).handleDefaultAction(navigatorTree);
} else {
String defaultEditorPageId = null;
NavigatorPreferences.DoubleClickBehavior dcBehaviorDefault = CommonUtils.valueOf(NavigatorPreferences.DoubleClickBehavior.class, DBWorkbench.getPlatform().getPreferenceStore().getString(NavigatorPreferences.NAVIGATOR_OBJECT_DOUBLE_CLICK));
if (node instanceof DBNDatabaseNode && ((DBNDatabaseNode) node).getObject() instanceof DBSDataContainer) {
defaultEditorPageId = DBWorkbench.getPlatform().getPreferenceStore().getString(NavigatorPreferences.NAVIGATOR_DEFAULT_EDITOR_PAGE);
}
boolean hasChildren = node instanceof DBNNode && ((DBNNode) node).hasChildren(true);
if (hasChildren && dcBehaviorDefault == NavigatorPreferences.DoubleClickBehavior.EXPAND) {
toggleNode(viewer, node);
} else {
Map<String, Object> parameters = null;
if (!CommonUtils.isEmpty(defaultEditorPageId)) {
parameters = Collections.singletonMap(MultiPageDatabaseEditor.PARAMETER_ACTIVE_PAGE, defaultEditorPageId);
}
NavigatorUtils.executeNodeAction(DBXTreeNodeHandler.Action.open, node, parameters, getSite());
}
}
}
});
// Hook context menu
NavigatorUtils.addContextMenu(this.getSite(), navigatorTree.getViewer());
// Add drag and drop support
NavigatorUtils.addDragAndDropSupport(navigatorTree.getViewer());
DBWorkbench.getPlatform().getPreferenceStore().addPropertyChangeListener(this);
return navigatorTree;
}
use of org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeSpecial in project dbeaver by serge-rider.
the class DatabaseNavigatorContentProvider method getChildren.
@Override
public Object[] getChildren(final Object parent) {
if (parent instanceof TreeNodeSpecial) {
return EMPTY_CHILDREN;
}
if (!(parent instanceof DBNNode)) {
return EMPTY_CHILDREN;
}
// view.getNavigatorModel().findNode(parent);
final DBNNode parentNode = (DBNNode) parent;
/*
if (parentNode == null) {
log.error("Can't find parent node '" + ((DBSObject) parent).getName() + "' in model");
return EMPTY_CHILDREN;
}
*/
if (!parentNode.hasChildren(true)) {
return EMPTY_CHILDREN;
}
if (parentNode instanceof DBNDatabaseNode && ((DBNDatabaseNode) parentNode).needsInitialization()) {
return TreeLoadVisualizer.expandChildren(navigatorTree.getViewer(), new TreeLoadService("Loading", ((DBNDatabaseNode) parentNode)));
} else {
try {
// Read children with null monitor cos' it's not a lazy node
// and no blocking process will occur
DBNNode[] children = DBNUtils.getNodeChildrenFiltered(new VoidProgressMonitor(), parentNode, true);
if (ArrayUtils.isEmpty(children)) {
return EMPTY_CHILDREN;
} else {
int longListFetchSize = Math.max(NavigatorPreferences.MIN_LONG_LIST_FETCH_SIZE, DBWorkbench.getPlatform().getPreferenceStore().getInt(NavigatorPreferences.NAVIGATOR_LONG_LIST_FETCH_SIZE));
if (children.length > longListFetchSize) {
Object[] curChildren = new Object[longListFetchSize + 1];
System.arraycopy(children, 0, curChildren, 0, longListFetchSize);
curChildren[longListFetchSize] = new TreeNodeLazyExpander(parentNode, children, longListFetchSize);
return curChildren;
}
return children;
}
} catch (Throwable ex) {
DBWorkbench.getPlatformUI().showError("Navigator error", ex.getMessage(), ex);
// Collapse this item
UIUtils.asyncExec(() -> {
navigatorTree.getViewer().collapseToLevel(parent, 1);
navigatorTree.getViewer().refresh(parent);
});
return EMPTY_CHILDREN;
}
}
}
use of org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeSpecial 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