use of org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeSpecial in project dbeaver by dbeaver.
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 dbeaver.
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 SQLScriptTaskDataSourceSelectorDialog method createDialogArea.
@Override
protected Composite createDialogArea(Composite parent) {
Composite dialogArea = super.createDialogArea(parent);
INavigatorFilter dsFilter = new INavigatorFilter() {
@Override
public boolean filterFolders() {
return true;
}
@Override
public boolean isLeafObject(Object object) {
return object instanceof DBNDataSource;
}
@Override
public boolean select(Object element) {
return element instanceof DBNProject || element instanceof DBNProjectDatabases || element instanceof DBNLocalFolder || element instanceof DBNDataSource || element instanceof TreeNodeSpecial;
}
};
dataSourceTree = new DatabaseNavigatorTree(dialogArea, projectNode.getDatabases(), SWT.SINGLE | SWT.BORDER | SWT.CHECK, false, dsFilter);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 300;
gd.widthHint = 400;
dataSourceTree.setLayoutData(gd);
dataSourceTree.getViewer().addSelectionChangedListener(event -> {
updateSelectedDataSources();
});
return dialogArea;
}
use of org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeSpecial in project dbeaver by serge-rider.
the class SQLScriptTaskScriptSelectorDialog method createDialogArea.
@Override
protected Composite createDialogArea(Composite parent) {
Composite dialogArea = super.createDialogArea(parent);
INavigatorFilter scriptFilter = new INavigatorFilter() {
@Override
public boolean filterFolders() {
return true;
}
@Override
public boolean isLeafObject(Object object) {
return object instanceof DBNResource && ((DBNResource) object).getResource() instanceof IFile;
}
@Override
public boolean select(Object element) {
return element instanceof DBNLocalFolder || element instanceof DBNResource || element instanceof TreeNodeSpecial;
}
};
scriptsTree = new DatabaseNavigatorTree(dialogArea, projectNode, SWT.SINGLE | SWT.BORDER | SWT.CHECK, false, scriptFilter);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 300;
gd.widthHint = 400;
scriptsTree.setLayoutData(gd);
scriptsTree.getViewer().addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof TreeNodeSpecial) {
return true;
}
if (element instanceof DBNResource) {
return isResourceApplicable((DBNResource) element);
}
return false;
}
});
scriptsTree.getViewer().addSelectionChangedListener(event -> {
updateSelectedScripts();
});
scriptsTree.getViewer().expandToLevel(2);
scriptsTree.getViewer().getTree().setHeaderVisible(true);
createScriptColumns(scriptsTree.getViewer());
return dialogArea;
}
use of org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeSpecial in project dbeaver by serge-rider.
the class SQLToolTaskObjectSelectorDialog method createDialogArea.
@Override
protected Composite createDialogArea(Composite parent) {
Composite dialogArea = super.createDialogArea(parent);
INavigatorFilter dsFilter = new INavigatorFilter() {
@Override
public boolean filterFolders() {
return true;
}
@Override
public boolean isLeafObject(Object object) {
return object instanceof DBNDatabaseItem && taskType.appliesTo(((DBNDatabaseItem) object).getObject());
}
@Override
public boolean select(Object element) {
if (element instanceof DBNProject || element instanceof DBNProjectDatabases) {
return true;
}
if (element instanceof DBNLocalFolder) {
for (DBNDataSource ds : ((DBNLocalFolder) element).getNestedDataSources()) {
if (taskType.isDriverApplicable(ds.getDataSourceContainer().getDriver()) && (!showConnected || ds.getDataSourceContainer().isConnected())) {
return true;
}
}
return false;
}
if (element instanceof DBNDataSource) {
if (showConnected && !((DBNDataSource) element).getDataSourceContainer().isConnected()) {
return false;
}
return taskType.isDriverApplicable(((DBNDataSource) element).getDataSourceContainer().getDriver());
}
if (element instanceof DBNDatabaseItem) {
DBSObject object = ((DBNDatabaseItem) element).getObject();
return (DBSObjectContainer.class.isAssignableFrom(object.getClass()) || (taskType.matchesEntityElements() && DBSEntity.class.isAssignableFrom(object.getClass())) || taskType.appliesTo(object));
} else if (element instanceof DBNDatabaseFolder) {
Class<? extends DBSObject> childrenClass = ((DBNDatabaseFolder) element).getChildrenClass();
return childrenClass != null && (DBSObjectContainer.class.isAssignableFrom(childrenClass) || (taskType.matchesEntityElements() && DBSEntity.class.isAssignableFrom(childrenClass)) || taskType.matchesType(childrenClass));
}
return element instanceof TreeNodeSpecial;
}
};
dataSourceTree = new DatabaseNavigatorTree(dialogArea, projectNode.getDatabases(), SWT.SINGLE | SWT.BORDER | SWT.CHECK, false, dsFilter);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 300;
gd.widthHint = 400;
dataSourceTree.setLayoutData(gd);
dataSourceTree.getViewer().addSelectionChangedListener(event -> {
updateSelectedObjects();
});
final Button showConnectedCheck = new Button(dialogArea, SWT.CHECK);
showConnectedCheck.setText(UINavigatorMessages.label_show_connected);
showConnectedCheck.setSelection(showConnected);
showConnectedCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
showConnected = showConnectedCheck.getSelection();
dataSourceTree.getViewer().refresh();
}
});
return dialogArea;
}
Aggregations