Search in sources :

Example 41 with DBNDataSource

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

the class DatabaseNavigatorLabelProvider method getToolTipText.

@Override
public String getToolTipText(Object element) {
    if (!DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.NAVIGATOR_SHOW_TOOLTIPS)) {
        return null;
    }
    if (element instanceof DBNDataSource) {
        final DBPDataSourceContainer ds = ((DBNDataSource) element).getDataSourceContainer();
        if (ds != null) {
            StringBuilder info = new StringBuilder();
            info.append("Name: ").append(ds.getName()).append("\n");
            final DBPConnectionConfiguration cfg = ds.getConnectionConfiguration();
            if (!CommonUtils.isEmpty(cfg.getUrl())) {
                info.append("URL: ").append(cfg.getUrl()).append("\n");
            } else if (!CommonUtils.isEmpty(cfg.getDatabaseName())) {
                info.append("Database: ").append(cfg.getDatabaseName()).append("\n");
            }
            if (!CommonUtils.isEmpty(cfg.getUserName())) {
                info.append("User: ").append(cfg.getUserName()).append("\n");
            }
            if (!CommonUtils.isEmpty(ds.getDescription())) {
                info.append("Description: ").append(ds.getDescription()).append("\n");
            }
            /*
                if (cfg.getConnectionType() != null) {
                    info.append("Type: ").append(cfg.getConnectionType().getName()).append("\n");
                }
*/
            if (ds.isConnectionReadOnly()) {
                info.append("Read-only connection\n");
            }
            if (ds.isProvided()) {
                info.append("Provided connection\n");
            }
            return info.toString().trim();
        }
    } else if (element instanceof DBNNode) {
        if (element instanceof DBNResource && !DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.NAVIGATOR_SHOW_CONTENTS_IN_TOOLTIP)) {
            return null;
        }
        final String description = ((DBNNode) element).getNodeDescription();
        if (!CommonUtils.isEmptyTrimmed(description)) {
            return description;
        }
        return ((DBNNode) element).getNodeName();
    }
    return null;
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 42 with DBNDataSource

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

the class AbstractSearchPage method loadTreeState.

protected List<DBNNode> loadTreeState(DBRProgressMonitor monitor, DBPProject project, String sources) {
    final List<DBNNode> result = new ArrayList<>();
    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 = DBWorkbench.getPlatform().getNavigatorModel().getDataSourceByPath(project, nodePath);
                if (dsNode == null || brokenDataSources.contains(dsNode)) {
                    continue;
                }
                DBNNode node = DBWorkbench.getPlatform().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 43 with DBNDataSource

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

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)) {
        if (adaptableObject instanceof DBNDatabaseFolder) {
            adaptableObject = ((DBNDatabaseFolder) adaptableObject).getParentObject();
        }
        DBPObject object = null;
        if (adaptableObject instanceof DBSWrapper) {
            object = ((DBSWrapper) adaptableObject).getObject();
        } else if (adaptableObject instanceof DBPObject) {
            object = (DBPObject) adaptableObject;
        }
        if (object instanceof DBSObject) {
            object = DBUtils.getPublicObject((DBSObject) object);
        }
        if (object != null && adapterType.isAssignableFrom(object.getClass())) {
            return adapterType.cast(object);
        }
    // } else if (IProject.class == adapterType) {
    // DBPProject project = null;
    // if (adaptableObject instanceof DBNNode) {
    // project = ((DBNNode) adaptableObject).getOwnerProject();
    // }
    // return project == null ? null : adapterType.cast(project.getEclipseProject());
    } 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, ModelMessages.model_navigator_Name, meta.getName());
                // $NON-NLS-1$
                props.addProperty(null, "desc", ModelMessages.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) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder) WorkbenchAdapter(org.eclipse.ui.model.WorkbenchAdapter) IWorkbenchAdapter(org.eclipse.ui.model.IWorkbenchAdapter) DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource)

Example 44 with DBNDataSource

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

the class PostgreFDWConfigWizard method collectAvailableDataSources.

void collectAvailableDataSources(DBRProgressMonitor monitor) {
    if (availableDataSources != null) {
        return;
    }
    Set<DBPDataSourceContainer> dataSources = new LinkedHashSet<>();
    Set<DBSEntity> entities = new LinkedHashSet<>();
    DBPDataSourceContainer curDataSource = database.getDataSource().getContainer();
    // Find all virtual connections
    DBVModel vModel = curDataSource.getVirtualModel();
    monitor.beginTask("Check virtual foreign keys", 1);
    collectAvailableDataSources(monitor, vModel, dataSources, entities);
    monitor.done();
    DBNModel navModel = DBWorkbench.getPlatform().getNavigatorModel();
    // Check global FK references cache
    Map<String, List<DBVEntityForeignKey>> grCache = DBVModel.getGlobalReferenceCache();
    monitor.beginTask("Check external references", grCache.size());
    for (Map.Entry<String, List<DBVEntityForeignKey>> grEntry : grCache.entrySet()) {
        DBNDataSource refDataSource = navModel.getDataSourceByPath(database.getDataSource().getContainer().getProject(), grEntry.getKey());
        if (refDataSource != null && refDataSource.getDataSourceContainer() == curDataSource) {
            try {
                for (DBVEntityForeignKey rfk : grEntry.getValue()) {
                    monitor.subTask("Check " + rfk.getEntity().getFullyQualifiedName(DBPEvaluationContext.UI));
                    DBSEntity refEntity = rfk.getEntity().getRealEntity(monitor);
                    if (refEntity != null) {
                        dataSources.add(refEntity.getDataSource().getContainer());
                        entities.add(refEntity);
                    }
                }
            } catch (DBException e) {
                log.debug("Error getting referenced entity", e);
            }
        }
        monitor.worked(1);
    }
    monitor.done();
    // Check already configured FDW
    // Done
    availableDataSources = new ArrayList<>(dataSources);
    proposedEntities = new ArrayList<>(entities);
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBVEntityForeignKey(org.jkiss.dbeaver.model.virtual.DBVEntityForeignKey) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBVModel(org.jkiss.dbeaver.model.virtual.DBVModel) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 45 with DBNDataSource

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

the class DatabaseNodeEditorInput 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