Search in sources :

Example 91 with DBNDatabaseNode

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.

the class PostgreDebugPanelFunction method createFunctionGroup.

private void createFunctionGroup(Composite parent) {
    Group functionGroup = UIUtils.createControlGroup(parent, "Function", 2, GridData.VERTICAL_ALIGN_BEGINNING, SWT.DEFAULT);
    UIUtils.createControlLabel(functionGroup, "Function");
    functionCombo = new CSmartSelector<PostgreProcedure>(functionGroup, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY, new LabelProvider() {

        @Override
        public Image getImage(Object element) {
            return DBeaverIcons.getImage(DBIcon.TREE_PROCEDURE);
        }

        @Override
        public String getText(Object element) {
            if (element == null) {
                return "N/A";
            }
            return ((PostgreProcedure) element).getFullQualifiedSignature();
        }
    }) {

        @Override
        protected void dropDown(boolean drop) {
            if (drop) {
                DBNModel navigatorModel = DBWorkbench.getPlatform().getNavigatorModel();
                DBNDatabaseNode dsNode = navigatorModel.getNodeByObject(container.getDataSource());
                if (dsNode != null) {
                    DBNNode curNode = selectedFunction == null ? null : navigatorModel.getNodeByObject(selectedFunction);
                    DBNNode node = DBWorkbench.getPlatformUI().selectObject(parent.getShell(), "Select function to debug", dsNode, curNode, new Class[] { DBSInstance.class, DBSObjectContainer.class, PostgreProcedure.class }, new Class[] { PostgreProcedure.class }, null);
                    if (node instanceof DBNDatabaseNode && ((DBNDatabaseNode) node).getObject() instanceof PostgreProcedure) {
                        functionCombo.removeAll();
                        selectedFunction = (PostgreProcedure) ((DBNDatabaseNode) node).getObject();
                        functionCombo.addItem(selectedFunction);
                        functionCombo.select(selectedFunction);
                        updateParametersTable();
                        container.updateDialogState();
                    }
                    parametersTable.setEnabled(selectedFunction != null);
                }
            }
        }
    };
    functionCombo.addItem(null);
    GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.widthHint = UIUtils.getFontHeight(functionCombo) * 40 + 10;
    functionCombo.setLayoutData(gd);
    processIdText = UIUtils.createLabelText(functionGroup, "Process ID", "", SWT.BORDER, new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.widthHint = UIUtils.getFontHeight(processIdText) * 10 + 10;
    processIdText.setLayoutData(gd);
}
Also used : DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBSInstance(org.jkiss.dbeaver.model.struct.DBSInstance) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel) PostgreProcedure(org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure) DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) GridData(org.eclipse.swt.layout.GridData) LabelProvider(org.eclipse.jface.viewers.LabelProvider) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 92 with DBNDatabaseNode

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.

the class DatabaseLazyEditorInput method initializeRealInput.

public IDatabaseEditorInput initializeRealInput(final DBRProgressMonitor monitor) throws DBException {
    // Get the node path.
    if (project != null) {
        dataSourceContainer = project.getDataSourceRegistry().getDataSource(dataSourceId);
    }
    if (dataSourceContainer == null) {
        // $NON-NLS-2$
        log.error("Can't find data source '" + dataSourceId + "'");
        return null;
    }
    if (project == null) {
        project = dataSourceContainer.getRegistry().getProject();
    }
    final DBNModel navigatorModel = DBWorkbench.getPlatform().getNavigatorModel();
    navigatorModel.ensureProjectLoaded(project);
    // dataSourceContainer, project, nodePath, nodeName, activePageId, activeFolderId
    DBPDataSource dataSource;
    while (!dataSourceContainer.isConnected()) {
        try {
            dataSourceContainer.connect(monitor, true, true);
        } catch (final DBException e) {
            // Connection error
            final Integer result = new UITask<Integer>() {

                @Override
                protected Integer runTask() {
                    ConnectionLostDialog clDialog = new ConnectionLostDialog(UIUtils.getActiveWorkbenchShell(), dataSourceContainer, e, "Close");
                    return clDialog.open();
                }
            }.execute();
            if (result == IDialogConstants.STOP_ID) {
                // Close editor
                return null;
            } else if (result == IDialogConstants.RETRY_ID) {
                continue;
            } else {
                return new ErrorEditorInput(GeneralUtils.makeExceptionStatus(e), navigatorModel.getNodeByObject(dataSourceContainer));
            }
        }
        break;
    }
    try {
        dataSource = dataSourceContainer.getDataSource();
        if (dataSource == null) {
            throw new DBException("Connection to '" + dataSourceContainer.getName() + "' canceled");
        }
        final DBNNode[] editorNodeResult = new DBNNode[1];
        DBExecUtils.tryExecuteRecover(monitor, dataSource, param -> {
            try {
                DBNDataSource dsNode = (DBNDataSource) navigatorModel.getNodeByObject(monitor, this.dataSourceContainer, true);
                if (dsNode == null) {
                    throw new DBException("Datasource '" + this.dataSourceContainer.getName() + "' navigator node not found");
                }
                dsNode.initializeNode(monitor, null);
                editorNodeResult[0] = navigatorModel.getNodeByPath(monitor, project, nodePath);
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            }
        });
        DBNNode node = editorNodeResult[0];
        if (node == null) {
            throw new DBException("Navigator node '" + nodePath + "' not found");
        }
        if (node instanceof DBNDatabaseNode) {
            DatabaseNodeEditorInput realInput = new DatabaseNodeEditorInput((DBNDatabaseNode) node);
            realInput.setDefaultFolderId(activeFolderId);
            realInput.setDefaultPageId(activePageId);
            return realInput;
        } else {
            throw new DBException("Database node has bad type: " + node.getClass().getName());
        }
    } catch (DBException e) {
        return new ErrorEditorInput(GeneralUtils.makeExceptionStatus(e), navigatorModel.getNodeByObject(dataSourceContainer));
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) UITask(org.jkiss.dbeaver.ui.UITask) ConnectionLostDialog(org.jkiss.dbeaver.ui.dialogs.ConnectionLostDialog) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 93 with DBNDatabaseNode

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.

the class DatabaseEditorInputFactory method saveState.

public static void saveState(IMemento memento, DatabaseEditorInput input) {
    if (!DBWorkbench.getPlatform().getPreferenceStore().getBoolean(DatabaseEditorPreferences.PROP_SAVE_EDITORS_STATE)) {
        return;
    }
    final DBCExecutionContext context = input.getExecutionContext();
    if (context == null) {
        // Detached - nothing to save
        return;
    }
    if (input.getDatabaseObject() != null && !input.getDatabaseObject().isPersisted()) {
        return;
    }
    final DBNDatabaseNode node = input.getNavigatorNode();
    memento.putString(TAG_CLASS, input.getClass().getName());
    memento.putString(TAG_PROJECT, context.getDataSource().getContainer().getProject().getName());
    memento.putString(TAG_DATA_SOURCE, context.getDataSource().getContainer().getId());
    memento.putString(TAG_NODE, node.getNodeItemPath());
    memento.putString(TAG_NODE_NAME, node.getNodeName());
    if (!CommonUtils.isEmpty(input.getDefaultPageId())) {
        memento.putString(TAG_ACTIVE_PAGE, input.getDefaultPageId());
    }
    if (!CommonUtils.isEmpty(input.getDefaultFolderId())) {
        memento.putString(TAG_ACTIVE_FOLDER, input.getDefaultFolderId());
    }
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 94 with DBNDatabaseNode

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.

the class EntityAddCommand method execute.

@Override
public void execute() {
    VoidProgressMonitor monitor = new VoidProgressMonitor();
    Point curLocation = location == null ? null : new Point(location);
    for (ERDEntity entity : entities) {
        boolean resolveRelations = false;
        if (entity.getObject() == null) {
            // Entity is not initialized
            if (entity.getDataSource() != null) {
                DBSObject selectedObject = DBUtils.getSelectedObject(DBUtils.getDefaultContext(entity.getDataSource(), false));
                DBNDatabaseNode dsNode = DBNUtils.getNodeByObject(selectedObject != null ? selectedObject : entity.getDataSource().getContainer());
                if (dsNode != null) {
                    DBNNode tableNode = DBWorkbench.getPlatformUI().selectObject(UIUtils.getActiveWorkbenchShell(), "Select a table", dsNode, null, new Class[] { DBSTable.class }, new Class[] { DBSTable.class }, null);
                    if (tableNode instanceof DBNDatabaseNode && ((DBNDatabaseNode) tableNode).getObject() instanceof DBSEntity) {
                        entity = ERDUtils.makeEntityFromObject(monitor, diagramPart.getDiagram(), Collections.emptyList(), (DBSEntity) ((DBNDatabaseNode) tableNode).getObject(), null);
                        // This actually only loads unresolved relations.
                        // This happens only with entities added on diagram during editing
                        entity.addModelRelations(monitor, diagramPart.getDiagram(), false, false);
                    }
                }
            }
        }
        if (entity.getObject() == null) {
            continue;
        }
        diagramPart.getDiagram().addEntity(entity, true);
        if (curLocation != null) {
            // Put new entities in specified location
            for (Object diagramChild : diagramPart.getChildren()) {
                if (diagramChild instanceof EntityPart) {
                    EntityPart entityPart = (EntityPart) diagramChild;
                    if (entityPart.getEntity() == entity) {
                        final Rectangle newBounds = new Rectangle();
                        final Dimension size = entityPart.getFigure().getPreferredSize();
                        newBounds.x = curLocation.x;
                        newBounds.y = curLocation.y;
                        newBounds.width = size.width;
                        newBounds.height = size.height;
                        entityPart.modifyBounds(newBounds);
                        curLocation.x += size.width + (size.width / 2);
                        break;
                    }
                }
            }
        }
        handleEntityChange(entity, false);
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ERDEntity(org.jkiss.dbeaver.erd.model.ERDEntity) Rectangle(org.eclipse.draw2d.geometry.Rectangle) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) Point(org.eclipse.draw2d.geometry.Point) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) Dimension(org.eclipse.draw2d.geometry.Dimension) EntityPart(org.jkiss.dbeaver.erd.ui.part.EntityPart) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 95 with DBNDatabaseNode

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.

the class DataTransferPagePipes method createInputsTable.

private void createInputsTable(Composite composite) {
    Composite panel = UIUtils.createComposite(composite, 1);
    // UIUtils.createControlLabel(panel, DTUIMessages.data_transfer_wizard_final_group_objects);
    inputsTable = new TableViewer(panel, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
    inputsTable.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    inputsTable.getTable().setLinesVisible(true);
    inputsTable.getTable().setHeaderVisible(true);
    inputsTable.setContentProvider(new ListContentProvider());
    UIUtils.createTableContextMenu(inputsTable.getTable(), null);
    DBNModel nModel = DBWorkbench.getPlatform().getNavigatorModel();
    CellLabelProvider labelProvider = new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            DBSObject element = (DBSObject) cell.getElement();
            if (cell.getColumnIndex() == 0) {
                DBNDatabaseNode objectNode = nModel.getNodeByObject(element);
                DBPImage icon = objectNode != null ? objectNode.getNodeIconDefault() : DBValueFormatting.getObjectImage(element);
                cell.setImage(DBeaverIcons.getImage(icon));
                cell.setText(DBUtils.getObjectFullName(element, DBPEvaluationContext.UI));
            } else if (element.getDescription() != null) {
                cell.setText(element.getDescription());
            }
        }
    };
    {
        TableViewerColumn columnName = new TableViewerColumn(inputsTable, SWT.LEFT);
        columnName.setLabelProvider(labelProvider);
        columnName.getColumn().setText(DTMessages.data_transfer_wizard_init_column_exported);
        TableViewerColumn columnDesc = new TableViewerColumn(inputsTable, SWT.LEFT);
        columnDesc.setLabelProvider(labelProvider);
        columnDesc.getColumn().setText(DTMessages.data_transfer_wizard_init_column_description);
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel) DBPImage(org.jkiss.dbeaver.model.DBPImage)

Aggregations

DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)222 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)85 DBException (org.jkiss.dbeaver.DBException)83 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)81 InvocationTargetException (java.lang.reflect.InvocationTargetException)53 ArrayList (java.util.ArrayList)44 GridData (org.eclipse.swt.layout.GridData)36 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)29 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)28 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)27 DBNModel (org.jkiss.dbeaver.model.navigator.DBNModel)26 ISelection (org.eclipse.jface.viewers.ISelection)21 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)21 DBNDatabaseFolder (org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)19 Collection (java.util.Collection)18 List (java.util.List)17 Composite (org.eclipse.swt.widgets.Composite)17 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)17 DBXTreeNode (org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode)17 SWT (org.eclipse.swt.SWT)15