use of org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree 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.DatabaseNavigatorTree in project dbeaver by serge-rider.
the class SelectDataSourceDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
showConnected = getDialogBoundsSettings().getBoolean(PARAM_SHOW_CONNECTED);
showAllProjects = getDialogBoundsSettings().getBoolean(PARAM_SHOW_ALL_PROJECTS);
Composite group = (Composite) super.createDialogArea(parent);
GridData gd = new GridData(GridData.FILL_BOTH);
group.setLayoutData(gd);
rootNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot();
projectNode = null;
if (project != null) {
DBNProject projectBaseNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(project);
if (projectBaseNode != null) {
projectNode = projectBaseNode.getDatabases();
}
}
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;
}
};
DatabaseNavigatorTree dataSourceTree = new DatabaseNavigatorTree(group, getTreeRootNode(), SWT.SINGLE | SWT.BORDER, false, dsFilter) {
@Override
protected void onTreeRefresh() {
DBNNode treeRootNode = getTreeRootNode();
if (dataSource != null && projectNode != null) {
DBPDataSourceFolder dsFolder;
for (dsFolder = dataSource.getFolder(); dsFolder != null; dsFolder = dsFolder.getParent()) {
if (dsFolder.getParent() == null) {
break;
}
}
if (dsFolder != null) {
// Expand only current DS folder
DBNLocalFolder folderNode = projectNode.getFolderNode(dsFolder);
if (folderNode != null) {
expandFolders(this, folderNode);
}
} else {
// Do not expand anything
}
return;
}
expandFolders(this, treeRootNode);
}
};
gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 500;
gd.minimumHeight = 100;
gd.minimumWidth = 100;
dataSourceTree.setLayoutData(gd);
final TreeViewer treeViewer = dataSourceTree.getViewer();
final Text descriptionText = new Text(group, SWT.READ_ONLY);
descriptionText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
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);
}
getDialogBoundsSettings().put(PARAM_SHOW_CONNECTED, showConnected);
}
});
final Button showAllProjectsCheck = new Button(group, SWT.CHECK);
showAllProjectsCheck.setText(UINavigatorMessages.label_show_all_projects);
showAllProjectsCheck.setSelection(showAllProjects);
showAllProjectsCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
showAllProjects = showAllProjectsCheck.getSelection();
treeViewer.getControl().setRedraw(false);
try {
dataSourceTree.reloadTree(getTreeRootNode());
if (showAllProjects) {
treeViewer.expandToLevel(3);
}
} finally {
treeViewer.getControl().setRedraw(true);
}
getDialogBoundsSettings().put(PARAM_SHOW_ALL_PROJECTS, showAllProjects);
}
});
if (this.dataSource != null) {
DBNDatabaseNode dsNode = DBWorkbench.getPlatform().getNavigatorModel().getNodeByObject(this.dataSource);
if (dsNode != null) {
treeViewer.setSelection(new StructuredSelection(dsNode), true);
}
}
group.setTabList(new Control[] { dataSourceTree, showConnectedCheck, showAllProjectsCheck });
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();
}
}
return element instanceof DBNProject || element instanceof DBNProjectDatabases || element instanceof DBNLocalFolder || element instanceof DBNDataSource;
}
});
treeViewer.addSelectionChangedListener(event -> {
IStructuredSelection structSel = (IStructuredSelection) event.getSelection();
Object selNode = structSel.isEmpty() ? null : structSel.getFirstElement();
if (selNode instanceof DBNDataSource) {
dataSource = ((DBNDataSource) selNode).getObject();
getButton(IDialogConstants.OK_ID).setEnabled(true);
String description = dataSource.getDescription();
if (description == null) {
description = dataSource.getName();
}
descriptionText.setText(description);
} else {
dataSource = null;
getButton(IDialogConstants.OK_ID).setEnabled(false);
}
});
treeViewer.addDoubleClickListener(event -> {
if (getButton(IDialogConstants.OK_ID).isEnabled()) {
okPressed();
}
});
UIUtils.asyncExec(() -> {
Point treeSize = dataSourceTree.getViewer().getTree().computeSize(SWT.DEFAULT, SWT.DEFAULT);
Point shellSize = getShell().getSize();
if (treeSize.x >= shellSize.x) {
Point shellCompSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT);
getShell().setSize(shellCompSize.x, shellSize.y);
getShell().layout(true);
}
dataSourceTree.getFilterControl().setFocus();
if (showConnected) {
treeViewer.expandAll();
}
});
closeOnFocusLost(treeViewer.getControl(), dataSourceTree.getFilterControl(), descriptionText, showConnectedCheck, showAllProjectsCheck);
return group;
}
use of org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree in project dbeaver by serge-rider.
the class NavigatorHandlerFilterObjectType method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
if (activePart instanceof DatabaseNavigatorView) {
DatabaseNavigatorTree navigatorTree = ((DatabaseNavigatorView) activePart).getNavigatorTree();
DatabaseNavigatorTreeFilterObjectType objectType = CommonUtils.valueOf(DatabaseNavigatorTreeFilterObjectType.class, event.getParameter("type"), DatabaseNavigatorTreeFilterObjectType.table);
if (objectType == navigatorTree.getFilterObjectType()) {
return null;
}
navigatorTree.setFilterObjectType(objectType);
navigatorTree.getViewer().getControl().setRedraw(false);
try {
navigatorTree.getViewer().refresh();
} finally {
navigatorTree.getViewer().getControl().setRedraw(true);
}
}
ActionUtils.fireCommandRefresh(NavigatorCommands.CMD_FILTER_CONNECTIONS);
return null;
}
use of org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree in project dbeaver by serge-rider.
the class NavigatorHandlerConnectionFilter method updateElement.
@Override
public void updateElement(UIElement element, Map parameters) {
IWorkbenchPartSite partSite = UIUtils.getWorkbenchPartSite(element.getServiceLocator());
if (partSite != null && partSite.getPart() instanceof DatabaseNavigatorView) {
DatabaseNavigatorTree navigatorTree = ((DatabaseNavigatorView) partSite.getPart()).getNavigatorTree();
element.setIcon(DBeaverIcons.getImageDescriptor(navigatorTree.isFilterShowConnected() ? UIIcon.FILTER_RESET : UIIcon.FILTER_APPLY));
String actionName = navigatorTree.isFilterShowConnected() ? "Show all" : "Show connected only";
element.setText(actionName);
element.setTooltip(actionName);
}
}
use of org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree in project dbeaver by dbeaver.
the class DiagramCreateWizardPage method createControl.
@Override
public void createControl(Composite parent) {
Composite placeholder = UIUtils.createPlaceholder(parent, 1);
Composite configGroup = UIUtils.createControlGroup(placeholder, ERDUIMessages.wizard_page_diagram_create_group_settings, 2, GridData.FILL_BOTH, 0);
// $NON-NLS-1$
final Text projectNameText = UIUtils.createLabelText(configGroup, "Name", null);
projectNameText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
diagram.setName(projectNameText.getText());
updateState();
}
});
Label contentLabel = UIUtils.createControlLabel(configGroup, ERDUIMessages.wizard_page_diagram_create_label_init_content);
GridData gd = new GridData(GridData.BEGINNING);
gd.horizontalSpan = 2;
contentLabel.setLayoutData(gd);
final DBNProject rootNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(DBWorkbench.getPlatform().getWorkspace().getActiveProject());
if (rootNode == null) {
setControl(placeholder);
return;
}
contentTree = new DatabaseNavigatorTree(configGroup, rootNode.getDatabases(), SWT.SINGLE | SWT.CHECK);
gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 2;
gd.heightHint = 400;
contentTree.setLayoutData(gd);
CheckboxTreeViewer viewer = (CheckboxTreeViewer) contentTree.getViewer();
viewer.setCheckStateProvider(new ICheckStateProvider() {
@Override
public boolean isChecked(Object element) {
return false;
}
@Override
public boolean isGrayed(Object element) {
if (element instanceof DBNDatabaseNode && !(element instanceof DBNDataSource)) {
DBSObject object = ((DBNDatabaseNode) element).getObject();
if (object instanceof DBSTable) {
return false;
}
}
return true;
}
});
if (entitySelection != null) {
viewer.setSelection(entitySelection, true);
viewer.setCheckedElements(entitySelection.toArray());
}
setControl(placeholder);
}
Aggregations