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) {
getShell().setText(CoreMessages.dialog_select_datasource_title);
Composite group = (Composite) super.createDialogArea(parent);
GridData gd = new GridData(GridData.FILL_BOTH);
group.setLayoutData(gd);
DBeaverCore core = DBeaverCore.getInstance();
DBNNode rootNode = null;
if (project != null) {
DBNProject projectNode = core.getNavigatorModel().getRoot().getProject(project);
if (projectNode != null) {
rootNode = projectNode.getDatabases();
}
}
if (rootNode == null) {
rootNode = core.getNavigatorModel().getRoot();
}
DatabaseNavigatorTree dataSourceTree = new DatabaseNavigatorTree(group, rootNode, SWT.SINGLE | SWT.BORDER, false);
dataSourceTree.setLayoutData(new GridData(GridData.FILL_BOTH));
final Text descriptionText = new Text(group, SWT.READ_ONLY);
descriptionText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
dataSourceTree.getViewer().addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
return element instanceof DBNProject || element instanceof DBNProjectDatabases || element instanceof DBNLocalFolder || element instanceof DBNDataSource;
}
});
dataSourceTree.getViewer().addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent 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);
}
}
});
dataSourceTree.getViewer().addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
if (getButton(IDialogConstants.OK_ID).isEnabled()) {
okPressed();
}
}
});
return group;
}
use of org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree in project dbeaver by serge-rider.
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);
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 500;
gd.heightHint = 500;
navigatorTree.setLayoutData(gd);
navigatorTree.getViewer().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) {
navigatorTree.getViewer().setSelection(new StructuredSelection(selectedNode));
selectedObjects.add(selectedNode);
}
navigatorTree.getViewer().addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
selectedObjects.clear();
IStructuredSelection selection = (IStructuredSelection) navigatorTree.getViewer().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 && matchesType(object.getClass(), true)) {
selectedObjects.add(node);
}
}
}
getButton(IDialogConstants.OK_ID).setEnabled(!selectedObjects.isEmpty());
}
});
return group;
}
use of org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree in project dbeaver by serge-rider.
the class NavigatorHandlerConnectionFilter method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
if (activePart instanceof DatabaseNavigatorView) {
DatabaseNavigatorTree navigatorTree = ((DatabaseNavigatorView) activePart).getNavigatorTree();
navigatorTree.setFilterShowConnected(!navigatorTree.isFilterShowConnected());
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 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.DatabaseNavigatorTree in project dbeaver by serge-rider.
the class SearchMetadataPage method createControl.
@Override
public void createControl(Composite parent) {
super.createControl(parent);
initializeDialogUnits(parent);
Composite searchGroup = new Composite(parent, SWT.NONE);
searchGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
searchGroup.setLayout(new GridLayout(3, false));
setControl(searchGroup);
UIUtils.createControlLabel(searchGroup, UISearchMessages.dialog_search_objects_label_object_name);
searchText = new Combo(searchGroup, SWT.DROP_DOWN);
searchText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
if (nameMask != null) {
searchText.setText(nameMask);
}
for (String history : searchHistory) {
searchText.add(history);
}
searchText.addModifyListener(e -> {
nameMask = searchText.getText();
updateEnablement();
});
Composite optionsGroup = new SashForm(searchGroup, SWT.NONE);
GridLayout layout = new GridLayout(2, true);
layout.marginHeight = 0;
layout.marginWidth = 0;
optionsGroup.setLayout(layout);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 3;
optionsGroup.setLayoutData(gd);
{
Group sourceGroup = UIUtils.createControlGroup(optionsGroup, UISearchMessages.dialog_search_objects_group_objects_source, 1, GridData.FILL_BOTH, 0);
gd = new GridData(GridData.FILL_BOTH);
// gd.heightHint = 300;
sourceGroup.setLayoutData(gd);
DBPPlatform platform = DBWorkbench.getPlatform();
final DBNProject projectNode = platform.getNavigatorModel().getRoot().getProjectNode(currentProject);
DBNNode rootNode = projectNode == null ? platform.getNavigatorModel().getRoot() : projectNode.getDatabases();
dataSourceTree = new DatabaseNavigatorTree(sourceGroup, rootNode, SWT.SINGLE);
gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 300;
dataSourceTree.setLayoutData(gd);
dataSourceTree.getViewer().addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof TreeNodeSpecial) {
return true;
}
if (element instanceof DBNNode) {
if (element instanceof DBNDatabaseFolder) {
DBNDatabaseFolder folder = (DBNDatabaseFolder) element;
Class<? extends DBSObject> folderItemsClass = folder.getChildrenClass();
return folderItemsClass != null && DBSObjectContainer.class.isAssignableFrom(folderItemsClass);
}
if (element instanceof DBNLocalFolder || element instanceof DBNProjectDatabases || element instanceof DBNDataSource || (element instanceof DBSWrapper && ((DBSWrapper) element).getObject() instanceof DBSObjectContainer)) {
return true;
}
}
return false;
}
});
dataSourceTree.getViewer().addSelectionChangedListener(event -> {
fillObjectTypes();
updateEnablement();
IStructuredSelection structSel = (IStructuredSelection) event.getSelection();
Object object = structSel.isEmpty() ? null : structSel.getFirstElement();
if (object instanceof DBNNode) {
for (DBNNode node = (DBNNode) object; node != null; node = node.getParentNode()) {
if (node instanceof DBNDataSource) {
DBNDataSource dsNode = (DBNDataSource) node;
try {
dsNode.initializeNode(null, status -> {
if (status.isOK()) {
UIUtils.asyncExec(() -> {
if (!dataSourceTree.isDisposed()) {
fillObjectTypes();
}
});
}
});
} catch (DBException e) {
// shouldn't be here
log.error(e);
}
break;
}
}
}
});
}
{
Group settingsGroup = UIUtils.createControlGroup(optionsGroup, "Settings", 2, GridData.FILL_BOTH, 0);
gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 300;
settingsGroup.setLayoutData(gd);
{
// new Label(searchGroup, SWT.NONE);
UIUtils.createControlLabel(settingsGroup, UISearchMessages.dialog_search_objects_label_name_match);
final Combo matchCombo = new Combo(settingsGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
matchCombo.add(UISearchMessages.dialog_search_objects_combo_starts_with, SearchMetadataConstants.MATCH_INDEX_STARTS_WITH);
matchCombo.add(UISearchMessages.dialog_search_objects_combo_contains, SearchMetadataConstants.MATCH_INDEX_CONTAINS);
matchCombo.add(UISearchMessages.dialog_search_objects_combo_like, SearchMetadataConstants.MATCH_INDEX_LIKE);
matchCombo.select(0);
matchCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
if (matchTypeIndex >= 0) {
matchCombo.select(matchTypeIndex);
}
matchCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
matchTypeIndex = matchCombo.getSelectionIndex();
}
});
matchCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
if (maxResults <= 0) {
maxResults = 100;
}
final Spinner maxResultsSpinner = UIUtils.createLabelSpinner(settingsGroup, UISearchMessages.dialog_search_objects_spinner_max_results, maxResults, 1, 10000);
maxResultsSpinner.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
maxResultsSpinner.addModifyListener(e -> maxResults = maxResultsSpinner.getSelection());
maxResultsSpinner.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
final Button caseCheckbox = UIUtils.createLabelCheckbox(settingsGroup, UISearchMessages.dialog_search_objects_case_sensitive, caseSensitive);
caseCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
caseSensitive = caseCheckbox.getSelection();
}
});
caseCheckbox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
Label otLabel = UIUtils.createControlLabel(settingsGroup, UISearchMessages.dialog_search_objects_group_object_types);
otLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
typesTable = new Table(settingsGroup, SWT.CHECK | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
typesTable.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// checkedTypes.clear();
for (TableItem item : typesTable.getItems()) {
DBSObjectType objectType = (DBSObjectType) item.getData();
if (item.getChecked()) {
checkedTypes.add(objectType);
} else {
checkedTypes.remove(objectType);
}
}
updateEnablement();
}
});
typesTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
TableItem[] selection = typesTable.getSelection();
if (selection.length > 0) {
TableItem tableItem = selection[0];
tableItem.setChecked(!tableItem.getChecked());
}
}
});
typesTable.setLayoutData(new GridData(GridData.FILL_BOTH));
UIUtils.createTableColumn(typesTable, SWT.LEFT, UISearchMessages.dialog_search_objects_column_type);
UIUtils.createTableColumn(typesTable, SWT.LEFT, UISearchMessages.dialog_search_objects_column_description);
}
UIUtils.asyncExec(this::loadState);
}
Aggregations