Search in sources :

Example 21 with DBNDatabaseNode

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;
}
Also used : ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) GridLayout(org.eclipse.swt.layout.GridLayout) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) GridData(org.eclipse.swt.layout.GridData) ObjectCompilerLogViewer(org.jkiss.dbeaver.ui.controls.ObjectCompilerLogViewer) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) OracleSourceObject(org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject)

Example 22 with DBNDatabaseNode

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;
}
Also used : PostgreDataSource(org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource) PostgreDatabase(org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel) PostgreProcedure(org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IContainer(org.eclipse.core.resources.IContainer) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) PostgreSchema(org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 23 with DBNDatabaseNode

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();
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBSTable(org.jkiss.dbeaver.model.struct.rdb.DBSTable) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) Collection(java.util.Collection) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBSTableConstraint(org.jkiss.dbeaver.model.struct.rdb.DBSTableConstraint) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) ExasolTableUniqueKey(org.jkiss.dbeaver.ext.exasol.model.ExasolTableUniqueKey) ExasolTable(org.jkiss.dbeaver.ext.exasol.model.ExasolTable)

Example 24 with DBNDatabaseNode

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();
                }
            }
        });
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBSCatalog(org.jkiss.dbeaver.model.struct.rdb.DBSCatalog) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) DBPDataSourceInfo(org.jkiss.dbeaver.model.DBPDataSourceInfo) DBSSchema(org.jkiss.dbeaver.model.struct.rdb.DBSSchema) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBXTreeNode(org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode) CSmartCombo(org.jkiss.dbeaver.ui.controls.CSmartCombo) GridData(org.eclipse.swt.layout.GridData) DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 25 with DBNDatabaseNode

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;
}
Also used : ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Aggregations

DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)165 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)64 DBException (org.jkiss.dbeaver.DBException)60 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)60 InvocationTargetException (java.lang.reflect.InvocationTargetException)38 ArrayList (java.util.ArrayList)29 GridData (org.eclipse.swt.layout.GridData)27 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)21 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)21 DBNModel (org.jkiss.dbeaver.model.navigator.DBNModel)20 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)20 ISelection (org.eclipse.jface.viewers.ISelection)16 DBNDatabaseFolder (org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)15 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)13 SelectionEvent (org.eclipse.swt.events.SelectionEvent)13 DBXTreeNode (org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode)13 Collection (java.util.Collection)12 Composite (org.eclipse.swt.widgets.Composite)12 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)12 IEditorPart (org.eclipse.ui.IEditorPart)11