use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by dbeaver.
the class SQLEditorHandlerOpenEditor 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;
}
use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by dbeaver.
the class NNAHDataSourceTunnel method getNodeActionToolTip.
@Override
public String getNodeActionToolTip(INavigatorModelView view, DBNNode node) {
StringBuilder tip = new StringBuilder("Network handlers enabled:");
for (DBWHandlerConfiguration handler : ((DBNDataSource) node).getDataSourceContainer().getConnectionConfiguration().getHandlers()) {
if (handler.isEnabled()) {
tip.append("\n -").append(handler.getHandlerDescriptor().getLabel());
String hostName = handler.getStringProperty(DBWHandlerConfiguration.PROP_HOST);
if (!CommonUtils.isEmpty(hostName)) {
tip.append(": ").append(hostName);
}
}
}
return tip.toString();
}
use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by dbeaver.
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;
}
use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by dbeaver.
the class DatabaseNavigatorLabelProvider method getForeground.
@Override
public Color getForeground(Object element) {
if (element instanceof DBNNode) {
DBNNode node = (DBNNode) element;
if (node instanceof DBNDataSource) {
DBPDataSourceContainer ds = ((DBNDataSource) element).getDataSourceContainer();
Color bgColor = UIUtils.getConnectionColor(ds.getConnectionConfiguration());
return bgColor == null ? null : UIUtils.getContrastColor(bgColor);
}
if (node.isLocked()) {
return lockedForeground;
}
if (node instanceof DBSWrapper && ((DBSWrapper) node).getObject() != null && !((DBSWrapper) node).getObject().isPersisted()) {
return transientForeground;
}
}
return null;
}
use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by dbeaver.
the class TargetPrefPage method setElement.
@Override
public void setElement(IAdaptable element) {
this.element = element;
if (this.element == null) {
return;
}
dataSourceContainer = element instanceof DBPDataSourceContainer ? (DBPDataSourceContainer) element : null;
containerNode = element.getAdapter(DBNDataSource.class);
if (containerNode == null) {
final DBPDataSourceContainer dsContainer = element.getAdapter(DBPDataSourceContainer.class);
if (dsContainer != null) {
containerNode = (DBNDataSource) DBWorkbench.getPlatform().getNavigatorModel().findNode(dsContainer);
} else {
IDatabaseEditorInput dbInput = element.getAdapter(IDatabaseEditorInput.class);
if (dbInput != null) {
DBNNode dbNode = dbInput.getNavigatorNode();
if (dbNode instanceof DBNDataSource) {
containerNode = (DBNDataSource) dbNode;
}
} else if (element instanceof DBPContextProvider) {
DBCExecutionContext context = ((DBPContextProvider) element).getExecutionContext();
if (context != null) {
containerNode = (DBNDataSource) DBWorkbench.getPlatform().getNavigatorModel().findNode(context.getDataSource().getContainer());
}
} else if (element instanceof DBPDataSourceContainer) {
containerNode = (DBNDataSource) DBWorkbench.getPlatform().getNavigatorModel().findNode((DBPDataSourceContainer) element);
}
}
}
if (dataSourceContainer == null && containerNode != null) {
dataSourceContainer = containerNode.getDataSourceContainer();
}
}
Aggregations