use of org.jkiss.dbeaver.model.struct.DBSObjectContainer in project dbeaver by serge-rider.
the class DataSourceManagementToolbar method changeDataBaseSelection.
private void changeDataBaseSelection() {
if (databaseCombo == null || databaseCombo.isDisposed() || databaseCombo.getSelectionIndex() < 0) {
return;
}
DBPDataSourceContainer dsContainer = getDataSourceContainer();
final String newName = databaseCombo.getItemText(databaseCombo.getSelectionIndex());
if (dsContainer != null && dsContainer.isConnected()) {
final DBPDataSource dataSource = dsContainer.getDataSource();
new AbstractJob("Change active database") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
DBSObjectContainer oc = DBUtils.getAdapter(DBSObjectContainer.class, dataSource);
DBSObjectSelector os = DBUtils.getAdapter(DBSObjectSelector.class, dataSource);
if (os != null) {
final DBSObject defObject = os.getDefaultObject();
if (defObject instanceof DBSObjectContainer) {
// USe seconds level of active object
DBSObjectSelector os2 = DBUtils.getAdapter(DBSObjectSelector.class, defObject);
if (os2 != null && os2.supportsDefaultChange()) {
oc = (DBSObjectContainer) defObject;
os = os2;
}
}
}
if (oc != null && os != null && os.supportsDefaultChange()) {
DBSObject newChild = oc.getChild(monitor, newName);
if (newChild != null) {
os.setDefaultObject(monitor, newChild);
} else {
throw new DBException(MessageFormat.format(CoreMessages.toolbar_datasource_selector_error_database_not_found, newName));
}
} else {
throw new DBException(CoreMessages.toolbar_datasource_selector_error_database_change_not_supported);
}
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
return Status.OK_STATUS;
}
}.schedule();
}
}
use of org.jkiss.dbeaver.model.struct.DBSObjectContainer in project dbeaver by dbeaver.
the class DBVContainer method getRealContainer.
public DBSObjectContainer getRealContainer(DBRProgressMonitor monitor) throws DBException {
DBSObjectContainer realParent = parent.getRealContainer(monitor);
if (realParent == null) {
return null;
}
DBSObject child = realParent.getChild(monitor, name);
if (child instanceof DBSObjectContainer) {
return (DBSObjectContainer) child;
}
log.warn("Child '" + name + "' of '" + realParent.getName() + "' is not an object container");
return null;
}
use of org.jkiss.dbeaver.model.struct.DBSObjectContainer in project dbeaver by dbeaver.
the class DBVModel method getRealContainer.
@Override
public DBSObjectContainer getRealContainer(DBRProgressMonitor monitor) throws DBException {
DBPDataSource dataSource = dataSourceContainer.getDataSource();
if (dataSource instanceof DBSObjectContainer) {
return (DBSObjectContainer) dataSource;
}
log.warn("Datasource '" + dataSource + "' is not an object container");
return null;
}
use of org.jkiss.dbeaver.model.struct.DBSObjectContainer in project dbeaver by dbeaver.
the class ExasolCreateForeignKeyDialog method createSchemaSelector.
private void createSchemaSelector(Composite tableGroup) throws DBException {
// Here is a trick - we need to find schema/catalog container node and list its children
DBNDatabaseNode schemaContainerNode = null;
for (DBNNode node = ownerTableNode.getParentNode(); node != null; node = node.getParentNode()) {
if (node instanceof DBNDatabaseNode) {
DBSObject nodeObject = ((DBNDatabaseNode) node).getObject();
if (nodeObject instanceof DBSSchema || nodeObject instanceof DBSCatalog) {
if (node.getParentNode() instanceof DBNDatabaseNode) {
schemaContainerNode = (DBNDatabaseNode) node.getParentNode();
break;
}
}
}
}
if (schemaContainerNode != null) {
ILabelProvider labelProvider = new LabelProvider() {
@Override
public Image getImage(Object element) {
return DBeaverIcons.getImage(((DBNDatabaseNode) element).getNodeIcon());
}
@Override
public String getText(Object element) {
return ((DBNDatabaseNode) element).getNodeName();
}
};
boolean isSchema = (ownTable.getParentObject() instanceof DBSSchema);
DBPDataSourceInfo dsInfo = ownTable.getDataSource().getInfo();
UIUtils.createControlLabel(tableGroup, isSchema ? dsInfo.getSchemaTerm() : dsInfo.getCatalogTerm());
final CSmartCombo<DBNDatabaseNode> schemaCombo = new CSmartCombo<>(tableGroup, SWT.BORDER, labelProvider);
schemaCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
DBNDatabaseNode selectedNode = null;
for (DBNNode node : schemaContainerNode.getChildren(new VoidProgressMonitor())) {
if (node instanceof DBNDatabaseNode && ((DBNDatabaseNode) node).getObject() instanceof DBSObjectContainer) {
schemaCombo.addItem((DBNDatabaseNode) node);
if (((DBNDatabaseNode) node).getObject() == ownTable.getParentObject()) {
selectedNode = (DBNDatabaseNode) node;
}
}
}
if (selectedNode != null) {
schemaCombo.select(selectedNode);
}
schemaCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// Here is another trick
// We need to find table container node
// This node is a child of schema node and has the same meta as our original table parent node
DBNDatabaseNode newContainerNode = null;
DBXTreeNode tableContainerMeta = ((DBNDatabaseNode) ownerTableNode.getParentNode()).getMeta();
DBNDatabaseNode schemaNode = schemaCombo.getSelectedItem();
if (schemaNode.getMeta() == tableContainerMeta) {
newContainerNode = schemaNode;
} else {
try {
for (DBNNode child : schemaNode.getChildren(new VoidProgressMonitor())) {
if (child instanceof DBNDatabaseNode && ((DBNDatabaseNode) child).getMeta() == tableContainerMeta) {
newContainerNode = (DBNDatabaseNode) child;
break;
}
}
} catch (DBException e1) {
log.debug(e1);
// Shouldn't be here
}
}
if (newContainerNode != null) {
tableList.setRootNode(newContainerNode);
tableList.loadData();
}
}
});
}
}
use of org.jkiss.dbeaver.model.struct.DBSObjectContainer in project dbeaver by dbeaver.
the class DataSourceManagementToolbar method changeDataBaseSelection.
private void changeDataBaseSelection(DBNDatabaseNode node) {
DBPDataSourceContainer dsContainer = getDataSourceContainer();
final String newName = node.getNodeName();
if (dsContainer != null && dsContainer.isConnected()) {
final DBPDataSource dataSource = dsContainer.getDataSource();
new AbstractJob("Change active database") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
DBSObjectContainer oc = DBUtils.getAdapter(DBSObjectContainer.class, dataSource);
DBSObjectSelector os = DBUtils.getAdapter(DBSObjectSelector.class, dataSource);
if (os != null) {
final DBSObject defObject = os.getDefaultObject();
if (defObject instanceof DBSObjectContainer) {
// USe seconds level of active object
DBSObjectSelector os2 = DBUtils.getAdapter(DBSObjectSelector.class, defObject);
if (os2 != null && os2.supportsDefaultChange()) {
oc = (DBSObjectContainer) defObject;
os = os2;
}
}
}
if (oc != null && os != null && os.supportsDefaultChange()) {
DBSObject newChild = oc.getChild(monitor, newName);
if (newChild != null) {
os.setDefaultObject(monitor, newChild);
} else {
throw new DBException(MessageFormat.format(CoreMessages.toolbar_datasource_selector_error_database_not_found, newName));
}
} else {
throw new DBException(CoreMessages.toolbar_datasource_selector_error_database_change_not_supported);
}
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
return Status.OK_STATUS;
}
}.schedule();
}
}
Aggregations