use of org.jkiss.dbeaver.model.navigator.DBNNode in project dbeaver by serge-rider.
the class EditForeignKeyPage 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(VoidProgressMonitor.INSTANCE)) {
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(VoidProgressMonitor.INSTANCE)) {
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.navigator.DBNNode in project dbeaver by serge-rider.
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();
}
use of org.jkiss.dbeaver.model.navigator.DBNNode in project dbeaver by serge-rider.
the class NodeEditorInputFactory method saveState.
public static void saveState(IMemento memento, NodeEditorInput input) {
final DBNNode node = input.getNavigatorNode();
memento.putString(TAG_NODE, node.getNodeItemPath());
}
use of org.jkiss.dbeaver.model.navigator.DBNNode in project dbeaver by serge-rider.
the class DiagramCreateWizard method performFinish.
@Override
public boolean performFinish() {
try {
Collection<DBNNode> initialContent = pageContent.getInitialContent();
List<DBSObject> rootObjects = new ArrayList<>();
for (DBNNode node : initialContent) {
if (node instanceof DBNDatabaseNode) {
rootObjects.add(((DBNDatabaseNode) node).getObject());
}
}
DiagramCreator creator = new DiagramCreator(rootObjects);
DBeaverUI.run(getContainer(), true, true, creator);
NavigatorHandlerObjectOpen.openResource(creator.diagramFile, DBeaverUI.getActiveWorkbenchWindow());
} catch (InterruptedException ex) {
return false;
} catch (InvocationTargetException ex) {
UIUtils.showErrorDialog(getShell(), "Create error", "Cannot create diagram", ex.getTargetException());
return false;
}
return true;
}
use of org.jkiss.dbeaver.model.navigator.DBNNode in project dbeaver by serge-rider.
the class DiagramCreateWizardPage method getInitialContent.
Collection<DBNNode> getInitialContent() {
if (contentTree == null) {
return Collections.emptyList();
}
List<DBNNode> nodes = new ArrayList<>();
CheckboxTreeViewer viewer = (CheckboxTreeViewer) contentTree.getViewer();
for (Object obj : viewer.getCheckedElements()) {
DBNNode node = (DBNNode) obj;
nodes.add(node);
}
return nodes;
}
Aggregations