use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.
the class NavigatorHandlerFilterConfig method configureFilters.
public static void configureFilters(Shell shell, DBNNode node) {
final DBNDatabaseFolder folder = (DBNDatabaseFolder) node;
DBXTreeItem itemsMeta = folder.getItemsMeta();
if (itemsMeta != null) {
DBSObjectFilter objectFilter = folder.getNodeFilter(itemsMeta, true);
if (objectFilter == null) {
objectFilter = new DBSObjectFilter();
}
boolean globalFilter = folder.getValueObject() instanceof DBPDataSource;
String parentName = "?";
if (folder.getValueObject() instanceof DBSObject) {
parentName = ((DBSObject) folder.getValueObject()).getName();
}
EditObjectFilterDialog dialog = new EditObjectFilterDialog(shell, globalFilter ? "All " + node.getNodeType() : node.getNodeType() + " of " + parentName, objectFilter, globalFilter);
switch(dialog.open()) {
case IDialogConstants.OK_ID:
folder.setNodeFilter(itemsMeta, dialog.getFilter());
NavigatorHandlerRefresh.refreshNavigator(Collections.singletonList(folder));
break;
case EditObjectFilterDialog.SHOW_GLOBAL_FILTERS_ID:
objectFilter = folder.getDataSource().getContainer().getObjectFilter(folder.getChildrenClass(), null, false);
dialog = new EditObjectFilterDialog(shell, "All " + node.getNodeType(), objectFilter != null ? objectFilter : new DBSObjectFilter(), true);
if (dialog.open() == IDialogConstants.OK_ID) {
// Set global filter
folder.getDataSource().getContainer().setObjectFilter(folder.getChildrenClass(), null, dialog.getFilter());
folder.getDataSource().getContainer().persistConfiguration();
NavigatorHandlerRefresh.refreshNavigator(Collections.singletonList(folder));
}
break;
}
}
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.
the class NavigatorHandlerLinkEditor method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
if (activeEditor == null) {
return null;
}
NavigatorViewBase navigatorView = NavigatorUtils.getActiveNavigatorView(event);
if (navigatorView == null) {
return null;
}
if (navigatorView instanceof ProjectExplorerView) {
if (activeEditor instanceof SQLEditor) {
IFile file = EditorUtils.getFileFromInput(activeEditor.getEditorInput());
if (file != null) {
showResourceInNavigator(navigatorView, file);
}
} else if (activeEditor.getEditorInput() instanceof ProjectFileEditorInput) {
IFile editorFile = ((ProjectFileEditorInput) activeEditor.getEditorInput()).getFile();
showResourceInNavigator(navigatorView, editorFile);
}
} else if (activeEditor.getEditorInput() instanceof IDatabaseEditorInput) {
IDatabaseEditorInput editorInput = (IDatabaseEditorInput) activeEditor.getEditorInput();
DBNNode dbnNode = editorInput.getNavigatorNode();
if (dbnNode != null) {
navigatorView.showNode(dbnNode);
}
} else if (activeEditor instanceof IDataSourceContainerProvider) {
DBPDataSourceContainer dsContainer = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
@NotNull final DBSObject activeObject;
if (dsContainer != null) {
DBPDataSource dataSource = dsContainer.getDataSource();
if (dataSource != null) {
activeObject = DBUtils.getDefaultOrActiveObject(dataSource);
} else {
activeObject = dsContainer;
}
final NavigatorViewBase view = navigatorView;
DBeaverUI.runInUI(activePage.getWorkbenchWindow(), new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
DBSObject showObject = activeObject;
if (showObject instanceof DBPDataSource) {
showObject = ((DBPDataSource) showObject).getContainer();
}
DBNDatabaseNode objectNode = view.getModel().getNodeByObject(monitor, showObject, true);
if (objectNode != null) {
view.showNode(objectNode);
}
}
});
}
}
activePage.activate(navigatorView);
return null;
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.
the class NavigatorHandlerObjectBase method getCommandTarget.
protected static CommandTarget getCommandTarget(IWorkbenchWindow workbenchWindow, DBNContainer container, Class<?> childType, boolean openEditor) throws DBException {
final Object parentObject = container.getValueObject();
DBSObject objectToSeek = null;
if (parentObject instanceof DBSObject) {
final DBEStructEditor parentStructEditor = EntityEditorsRegistry.getInstance().getObjectManager(parentObject.getClass(), DBEStructEditor.class);
if (parentStructEditor != null && RuntimeUtils.isTypeSupported(childType, parentStructEditor.getChildTypes())) {
objectToSeek = (DBSObject) parentObject;
}
}
if (objectToSeek != null) {
for (final IEditorReference editorRef : workbenchWindow.getActivePage().getEditorReferences()) {
final IEditorPart editor = editorRef.getEditor(false);
if (editor instanceof IDatabaseEditor) {
final IDatabaseEditorInput editorInput = ((IDatabaseEditor) editor).getEditorInput();
if (editorInput.getDatabaseObject() == objectToSeek) {
workbenchWindow.getActivePage().activate(editor);
switchEditorFolder(container, editor);
return new CommandTarget((IDatabaseEditor) editor);
}
}
}
if (openEditor && container instanceof DBNDatabaseNode) {
final IDatabaseEditor editor = (IDatabaseEditor) NavigatorHandlerObjectOpen.openEntityEditor((DBNDatabaseNode) container, null, workbenchWindow);
if (editor != null) {
switchEditorFolder(container, editor);
return new CommandTarget(editor);
}
}
}
if (container instanceof DBNDatabaseNode) {
// No editor found - create new command context
DBPDataSource dataSource = ((DBNDatabaseNode) container).getObject().getDataSource();
if (dataSource != null) {
return new CommandTarget(new SimpleCommandContext(dataSource.getDefaultContext(true), !openEditor));
}
}
return new CommandTarget();
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.
the class AbstractDataSourceHandler method getDataSourceContainer.
protected static DBPDataSourceContainer getDataSourceContainer(ExecutionEvent event, boolean useEditor) {
if (useEditor) {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor != null) {
DBPDataSourceContainer container = getDataSourceContainer(editor);
if (container != null) {
return container;
}
}
return null;
}
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
DBPDataSourceContainer container = getDataSourceContainer(activePart);
if (container != null) {
return container;
}
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
DBSObject selectedObject = NavigatorUtils.getSelectedObject((IStructuredSelection) selection);
if (selectedObject instanceof DBPDataSourceContainer) {
return (DBPDataSourceContainer) selectedObject;
} else if (selectedObject != null) {
DBPDataSource dataSource = selectedObject.getDataSource();
return dataSource == null ? null : dataSource.getContainer();
}
}
return null;
}
use of org.jkiss.dbeaver.model.struct.DBSObject 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;
}
Aggregations