Search in sources :

Example 1 with DBNDataSource

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

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 2 with DBNDataSource

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

the class AbstractSearchPage method loadTreeState.

protected static List<DBNNode> loadTreeState(DBRProgressMonitor monitor, DBPPreferenceStore store, String propName) {
    final List<DBNNode> result = new ArrayList<>();
    final String sources = store.getString(propName);
    if (!CommonUtils.isEmpty(sources)) {
        // Keep broken datasources to make connect attempt only once
        Set<DBNDataSource> brokenDataSources = new HashSet<>();
        // Find all nodes
        //$NON-NLS-1$
        StringTokenizer st = new StringTokenizer(sources, "|");
        while (st.hasMoreTokens()) {
            String nodePath = st.nextToken();
            try {
                DBNDataSource dsNode = DBeaverCore.getInstance().getNavigatorModel().getDataSourceByPath(nodePath);
                if (dsNode == null || brokenDataSources.contains(dsNode)) {
                    continue;
                }
                DBNNode node = DBeaverCore.getInstance().getNavigatorModel().getNodeByPath(monitor, dsNode.getOwnerProject(), nodePath);
                if (node != null) {
                    result.add(node);
                } else {
                    brokenDataSources.add(dsNode);
                }
            } catch (DBException e) {
                log.error(e);
            }
        }
    }
    return result;
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource)

Example 3 with DBNDataSource

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

the class AbstractSearchPage method loadTreeState.

protected static List<DBNNode> loadTreeState(DBRProgressMonitor monitor, DBPPreferenceStore store, String propName) {
    final List<DBNNode> result = new ArrayList<>();
    final String sources = store.getString(propName);
    if (!CommonUtils.isEmpty(sources)) {
        // Keep broken datasources to make connect attempt only once
        Set<DBNDataSource> brokenDataSources = new HashSet<>();
        // Find all nodes
        // $NON-NLS-1$
        StringTokenizer st = new StringTokenizer(sources, "|");
        while (st.hasMoreTokens()) {
            String nodePath = st.nextToken();
            try {
                DBNDataSource dsNode = DBeaverCore.getInstance().getNavigatorModel().getDataSourceByPath(nodePath);
                if (dsNode == null || brokenDataSources.contains(dsNode)) {
                    continue;
                }
                DBNNode node = DBeaverCore.getInstance().getNavigatorModel().getNodeByPath(monitor, dsNode.getOwnerProject(), nodePath);
                if (node != null) {
                    result.add(node);
                } else {
                    brokenDataSources.add(dsNode);
                }
            } catch (DBException e) {
                log.error(e);
            }
        }
    }
    return result;
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource)

Example 4 with DBNDataSource

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

the class NavigatorAdapterFactory method getAdapter.

@Override
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
    if (adapterType == DBPDataSourceContainer.class) {
        if (adaptableObject instanceof DBNDataSource) {
            return adapterType.cast(((DBNDataSource) adaptableObject).getDataSourceContainer());
        }
        DBSObject object = DBUtils.getFromObject(adaptableObject);
        if (object == null) {
            return null;
        }
        if (object instanceof DBPDataSourceContainer) {
            return adapterType.cast(object);
        }
        DBPDataSource dataSource = object.getDataSource();
        return dataSource == null ? null : adapterType.cast(dataSource.getContainer());
    } else if (DBPObject.class.isAssignableFrom(adapterType)) {
        DBPObject object = null;
        if (adaptableObject instanceof DBSWrapper) {
            object = ((DBSWrapper) adaptableObject).getObject();
        } else if (adaptableObject instanceof DBPObject) {
            object = (DBPObject) adaptableObject;
        }
        if (object != null && adapterType.isAssignableFrom(object.getClass())) {
            return adapterType.cast(object);
        }
    } else if (IResource.class.isAssignableFrom(adapterType)) {
        if (adaptableObject instanceof DBNResource) {
            return ((DBNResource) adaptableObject).getAdapter(adapterType);
        }
    } else if (adapterType == IPropertySource.class) {
        DBPObject dbObject = null;
        if (adaptableObject instanceof DBSWrapper) {
            dbObject = ((DBSWrapper) adaptableObject).getObject();
        } else if (adaptableObject instanceof DBPObject) {
            dbObject = (DBPObject) adaptableObject;
        }
        if (dbObject instanceof IPropertySource) {
            return adapterType.cast(dbObject);
        }
        if (dbObject instanceof DBPPropertySource) {
            return adapterType.cast(new PropertySourceDelegate((DBPPropertySource) dbObject));
        }
        if (dbObject instanceof IAdaptable) {
            Object adapter = ((IAdaptable) dbObject).getAdapter(IPropertySource.class);
            if (adapter != null) {
                return adapterType.cast(adapter);
            }
            adapter = ((IAdaptable) dbObject).getAdapter(DBPPropertySource.class);
            if (adapter != null) {
                return adapterType.cast(new PropertySourceDelegate((DBPPropertySource) adapter));
            }
        }
        if (dbObject != null) {
            PropertyCollector props = new PropertyCollector(adaptableObject, dbObject, true);
            props.collectProperties();
            if (props.isEmpty() && adaptableObject instanceof DBSObject) {
                // Add default properties
                DBSObject meta = (DBSObject) adaptableObject;
                // $NON-NLS-1$
                props.addProperty(null, DBConstants.PROP_ID_NAME, CoreMessages.model_navigator_Name, meta.getName());
                // $NON-NLS-1$
                props.addProperty(null, "desc", CoreMessages.model_navigator_Description, meta.getDescription());
            }
            return adapterType.cast(new PropertySourceDelegate(props));
        }
    } else if (adapterType == IWorkbenchAdapter.class) {
        // Workbench adapter
        if (adaptableObject instanceof DBNNode) {
            final DBNNode node = (DBNNode) adaptableObject;
            WorkbenchAdapter workbenchAdapter = new WorkbenchAdapter() {

                @Override
                public ImageDescriptor getImageDescriptor(Object object) {
                    return DBeaverIcons.getImageDescriptor(node.getNodeIconDefault());
                }

                @Override
                public String getLabel(Object o) {
                    return node.getNodeName();
                }

                @Override
                public Object getParent(Object o) {
                    return node.getParentNode();
                }
            };
            return adapterType.cast(workbenchAdapter);
        } else {
            return null;
        }
    }
    return null;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) PropertySourceDelegate(org.jkiss.dbeaver.ui.properties.PropertySourceDelegate) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBPPropertySource(org.jkiss.dbeaver.model.preferences.DBPPropertySource) PropertyCollector(org.jkiss.dbeaver.runtime.properties.PropertyCollector) IPropertySource(org.eclipse.ui.views.properties.IPropertySource) WorkbenchAdapter(org.eclipse.ui.model.WorkbenchAdapter) IWorkbenchAdapter(org.eclipse.ui.model.IWorkbenchAdapter) DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource)

Example 5 with DBNDataSource

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

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)

Aggregations

DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)39 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)16 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)15 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)12 DBException (org.jkiss.dbeaver.DBException)10 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)9 DBNResource (org.jkiss.dbeaver.model.navigator.DBNResource)7 ArrayList (java.util.ArrayList)6 ISelection (org.eclipse.jface.viewers.ISelection)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 DBNLocalFolder (org.jkiss.dbeaver.model.navigator.DBNLocalFolder)6 DBNProject (org.jkiss.dbeaver.model.navigator.DBNProject)6 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)5 GridData (org.eclipse.swt.layout.GridData)4 NavigatorViewBase (org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase)4 Iterator (java.util.Iterator)3 IFile (org.eclipse.core.resources.IFile)3 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)3 ICheckStateProvider (org.eclipse.jface.viewers.ICheckStateProvider)3 TreeViewer (org.eclipse.jface.viewers.TreeViewer)3