Search in sources :

Example 56 with DBNDataSource

use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by serge-rider.

the class OpenHandler method getDataSourceContainers.

private static List<DBPDataSourceContainer> getDataSourceContainers(ExecutionEvent event) {
    List<DBPDataSourceContainer> containers = new ArrayList<>();
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        for (Object obj : ((IStructuredSelection) selection).toArray()) {
            if (obj instanceof DBNLocalFolder) {
                for (DBNDataSource ds : ((DBNLocalFolder) obj).getDataSources()) {
                    containers.add(ds.getDataSourceContainer());
                }
            } else {
                DBSObject selectedObject = DBUtils.getFromObject(obj);
                if (selectedObject != null) {
                    if (selectedObject instanceof DBPDataSourceContainer) {
                        containers.add((DBPDataSourceContainer) selectedObject);
                    } else {
                        containers.add(selectedObject.getDataSource().getContainer());
                    }
                }
            }
        }
    }
    if (containers.isEmpty()) {
        IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
        DBPDataSourceContainer partContainer = getDataSourceContainers(activePart);
        if (partContainer != null) {
            containers.add(partContainer);
        }
    }
    return containers;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNLocalFolder(org.jkiss.dbeaver.model.navigator.DBNLocalFolder) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) ArrayList(java.util.ArrayList) ISelection(org.eclipse.jface.viewers.ISelection) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 57 with DBNDataSource

use of org.jkiss.dbeaver.model.navigator.DBNDataSource 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, ERDMessages.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, ERDMessages.wizard_page_diagram_create_label_init_content);
    GridData gd = new GridData(GridData.BEGINNING);
    gd.horizontalSpan = 2;
    contentLabel.setLayoutData(gd);
    final DBNProject rootNode = DBeaverCore.getInstance().getNavigatorModel().getRoot().getProject(DBeaverCore.getInstance().getProjectRegistry().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);
}
Also used : DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) DBSTable(org.jkiss.dbeaver.model.struct.rdb.DBSTable) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) ICheckStateProvider(org.eclipse.jface.viewers.ICheckStateProvider) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) DatabaseNavigatorTree(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 58 with DBNDataSource

use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by dbeaver.

the class NavigatorHandlerLocalFolderCreate method createFolder.

public static boolean createFolder(IWorkbenchWindow workbenchWindow, IWorkbenchPart activePart, DBNProjectDatabases databases, final DBNLocalFolder parentFolder, final Collection<DBNDataSource> nodes, String newName) {
    if (newName == null) {
        newName = EnterNameDialog.chooseName(workbenchWindow.getShell(), "Folder name");
    }
    if (CommonUtils.isEmpty(newName)) {
        return false;
    }
    // Create folder and refresh databases root
    // DS container will reload folders on refresh
    final DBPDataSourceRegistry dsRegistry = databases.getDataSourceRegistry();
    DBPDataSourceFolder folder = dsRegistry.addFolder(parentFolder == null ? null : parentFolder.getFolder(), newName);
    for (DBNDataSource node : nodes) {
        node.setFolder(folder);
    }
    if (parentFolder != null && activePart instanceof NavigatorViewBase) {
        final TreeViewer viewer = ((NavigatorViewBase) activePart).getNavigatorViewer();
        if (viewer != null) {
            DBeaverUI.asyncExec(new Runnable() {

                @Override
                public void run() {
                    viewer.expandToLevel(parentFolder, 1);
                }
            });
        }
    }
    DBNModel.updateConfigAndRefreshDatabases(databases);
    return true;
}
Also used : DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DBPDataSourceFolder(org.jkiss.dbeaver.model.DBPDataSourceFolder) NavigatorViewBase(org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)

Example 59 with DBNDataSource

use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by dbeaver.

the class EntityEditorInput method getToolTipText.

@Override
public String getToolTipText() {
    StringBuilder toolTip = new StringBuilder();
    for (DBNNode node = getNavigatorNode(); node != null; node = node.getParentNode()) {
        if (node instanceof DBSFolder) {
            continue;
        }
        toolTip.append(node.getNodeType());
        toolTip.append(": ");
        toolTip.append(node.getNodeName());
        toolTip.append(" \n");
        if (node instanceof DBNDataSource) {
            break;
        }
    }
    return toolTip.toString();
}
Also used : DBSFolder(org.jkiss.dbeaver.model.struct.DBSFolder) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource)

Aggregations

DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)59 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)26 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)23 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)17 DBException (org.jkiss.dbeaver.DBException)15 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)13 DBNResource (org.jkiss.dbeaver.model.navigator.DBNResource)12 DBNProject (org.jkiss.dbeaver.model.navigator.DBNProject)10 ArrayList (java.util.ArrayList)8 ISelection (org.eclipse.jface.viewers.ISelection)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 DBNLocalFolder (org.jkiss.dbeaver.model.navigator.DBNLocalFolder)8 IFile (org.eclipse.core.resources.IFile)6 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)6 SQLScriptExecuteSettings (org.jkiss.dbeaver.tools.sql.SQLScriptExecuteSettings)6 GridData (org.eclipse.swt.layout.GridData)5 IResource (org.eclipse.core.resources.IResource)4 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)4 ICheckStateProvider (org.eclipse.jface.viewers.ICheckStateProvider)4 ModifyEvent (org.eclipse.swt.events.ModifyEvent)4