use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class OracleCompilerDialog method createDialogArea.
@Override
protected Composite createDialogArea(Composite parent) {
GridData gd;
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(2, false));
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
{
Composite unitsGroup = new Composite(composite, SWT.NONE);
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 250;
gd.heightHint = 200;
gd.verticalIndent = 0;
gd.horizontalIndent = 0;
unitsGroup.setLayoutData(gd);
unitsGroup.setLayout(new GridLayout(1, false));
unitTable = new TableViewer(unitsGroup, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
{
final Table table = unitTable.getTable();
table.setLayoutData(new GridData(GridData.FILL_BOTH));
table.setLinesVisible(true);
table.setHeaderVisible(true);
}
ViewerColumnController columnController = new ViewerColumnController("OracleCompilerDialog", unitTable);
columnController.addColumn(OracleMessages.views_oracle_compiler_dialog_column_name, null, SWT.NONE, true, true, new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
DBSObject unit = (DBSObject) cell.getElement();
final DBNDatabaseNode node = NavigatorUtils.getNodeByObject(unit);
if (node != null) {
cell.setText(node.getNodeName());
cell.setImage(DBeaverIcons.getImage(node.getNodeIconDefault()));
} else {
cell.setText(unit.toString());
}
}
});
columnController.addColumn(OracleMessages.views_oracle_compiler_dialog_column_type, null, SWT.NONE, true, true, new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
DBSObject unit = (DBSObject) cell.getElement();
final DBNDatabaseNode node = NavigatorUtils.getNodeByObject(unit);
if (node != null) {
cell.setText(node.getNodeType());
} else {
// $NON-NLS-1$
cell.setText("???");
}
}
});
columnController.createColumns();
unitTable.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
getButton(COMPILE_ID).setEnabled(!selection.isEmpty());
}
});
unitTable.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
if (!selection.isEmpty()) {
OracleSourceObject unit = (OracleSourceObject) selection.getFirstElement();
NavigatorHandlerObjectOpen.openEntityEditor(unit);
}
}
});
unitTable.setContentProvider(new ListContentProvider());
unitTable.setInput(compileUnits);
}
{
Composite infoGroup = new Composite(composite, SWT.NONE);
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 400;
gd.heightHint = 200;
gd.verticalIndent = 0;
gd.horizontalIndent = 0;
infoGroup.setLayoutData(gd);
infoGroup.setLayout(new GridLayout(1, false));
compileLog = new ObjectCompilerLogViewer(infoGroup, true);
}
return composite;
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class PostgreSqlDebugCore method createConfiguration.
public static ILaunchConfigurationWorkingCopy createConfiguration(DBSObject launchable) throws CoreException {
boolean isInstance = launchable instanceof PostgreProcedure;
if (!isInstance) {
throw DebugCore.abort(PostgreDebugCoreMessages.PostgreSqlDebugCore_e_procedure_required);
}
PostgreProcedure procedure = (PostgreProcedure) launchable;
PostgreDataSource dataSource = procedure.getDataSource();
DBPDataSourceContainer dataSourceContainer = dataSource.getContainer();
PostgreDatabase database = procedure.getDatabase();
PostgreSchema schema = procedure.getContainer();
String databaseName = database.getName();
String schemaName = schema.getName();
String procedureName = procedure.getName();
Object[] bindings = new Object[] { dataSourceContainer.getName(), databaseName, procedureName, schemaName };
String name = NLS.bind(PostgreDebugCoreMessages.PostgreSqlDebugCore_launch_configuration_name, bindings);
// Let's use metadata area for storage
IContainer container = null;
ILaunchConfigurationWorkingCopy workingCopy = DebugCore.createConfiguration(container, CONFIGURATION_TYPE, name);
workingCopy.setAttribute(DebugCore.ATTR_DRIVER_ID, dataSourceContainer.getDriver().getId());
workingCopy.setAttribute(DebugCore.ATTR_DATASOURCE_ID, dataSourceContainer.getId());
workingCopy.setAttribute(DebugCore.ATTR_DATABASE_NAME, databaseName);
workingCopy.setAttribute(DebugCore.ATTR_SCHEMA_NAME, schemaName);
workingCopy.setAttribute(DebugCore.ATTR_PROCEDURE_OID, String.valueOf(procedure.getObjectId()));
workingCopy.setAttribute(DebugCore.ATTR_PROCEDURE_NAME, procedureName);
workingCopy.setAttribute(DebugCore.ATTR_ATTACH_PROCESS, DebugCore.ATTR_ATTACH_PROCESS_DEFAULT);
workingCopy.setAttribute(DebugCore.ATTR_ATTACH_KIND, DebugCore.ATTR_ATTACH_KIND_DEFAULT);
workingCopy.setAttribute(DebugCore.ATTR_SCRIPT_EXECUTE, DebugCore.ATTR_SCRIPT_EXECUTE_DEFAULT);
workingCopy.setAttribute(DebugCore.ATTR_SCRIPT_TEXT, DebugCore.composeScriptText(procedure));
final DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
DBNDatabaseNode node = navigatorModel.getNodeByObject(procedure);
workingCopy.setAttribute(DebugCore.ATTR_NODE_PATH, node.getNodeItemPath());
return workingCopy;
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class ExasolCreateForeignKeyDialog method handleRefTableSelect.
private void handleRefTableSelect(ISelection selection) {
DBNDatabaseNode refTableNode = null;
if (!selection.isEmpty() && selection instanceof IStructuredSelection && ((IStructuredSelection) selection).size() == 1) {
final Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof DBNDatabaseNode && ((DBNDatabaseNode) element).getObject() instanceof DBSTable && ((DBNDatabaseNode) element).getObject().isPersisted()) {
refTableNode = (DBNDatabaseNode) element;
}
}
if (refTableNode != null) {
if (refTableNode.getObject() == curRefTable) {
// The same selection
return;
} else {
curRefTable = (ExasolTable) refTableNode.getObject();
}
}
uniqueKeyCombo.removeAll();
try {
curConstraints = new ArrayList<>();
curConstraint = null;
if (refTableNode != null) {
final ExasolTable refTable = (ExasolTable) refTableNode.getObject();
DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
// Cache own table columns
ownTable.getAttributes(monitor);
// Cache ref table columns
refTable.getAttributes(monitor);
// Get constraints
final Collection<? extends ExasolTableUniqueKey> constraints = refTable.getConstraints(monitor);
if (!CommonUtils.isEmpty(constraints)) {
for (ExasolTableUniqueKey constraint : constraints) {
if (constraint.getConstraintType().isUnique()) {
curConstraints.add(constraint);
}
}
}
} catch (DBException e) {
throw new InvocationTargetException(e);
}
}
});
}
for (DBSTableConstraint constraint : curConstraints) {
uniqueKeyCombo.add(constraint.getName());
}
uniqueKeyCombo.select(0);
uniqueKeyCombo.setEnabled(curConstraints.size() > 1);
if (curConstraints.size() == 1) {
curConstraint = curConstraints.get(0);
}
} catch (InvocationTargetException e) {
DBUserInterface.getInstance().showError(CoreMessages.dialog_struct_edit_fk_error_load_constraints_title, CoreMessages.dialog_struct_edit_fk_error_load_constraints_message, e.getTargetException());
} catch (InterruptedException e) {
// do nothing
}
handleUniqueKeySelect();
updatePageState();
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode 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.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class CheckboxTreeManager method collectChildren.
private boolean collectChildren(DBRProgressMonitor monitor, final Object element, List<DBNDatabaseNode> targetChildren, List<DBNDatabaseNode> targetContainers, boolean onlyChecked) throws DBException {
if (element instanceof DBNDatabaseNode) {
for (ViewerFilter filter : filters) {
if (!filter.select(viewer, ((DBNDatabaseNode) element).getParentNode(), element)) {
return false;
}
}
boolean isChecked = ArrayUtils.contains(checkedElements, element);
for (Class<?> type : targetTypes) {
if (type.isInstance(((DBNDatabaseNode) element).getObject())) {
if (!onlyChecked || isChecked) {
targetChildren.add((DBNDatabaseNode) element);
}
return true;
}
}
((DBNDatabaseNode) element).initializeNode(monitor, null);
DBNDatabaseNode[] children = ((DBNDatabaseNode) element).getChildren(monitor);
if (!ArrayUtils.isEmpty(children)) {
boolean foundChild = false;
for (DBNDatabaseNode child : children) {
if (collectChildren(monitor, child, targetChildren, targetContainers, onlyChecked)) {
foundChild = true;
}
}
if (foundChild) {
if (!onlyChecked || isChecked) {
targetContainers.add((DBNDatabaseNode) element);
}
}
return foundChild;
}
}
return false;
}
Aggregations