Search in sources :

Example 46 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by serge-rider.

the class DatabaseNavigatorLabelProvider method getForeground.

@Override
public Color getForeground(Object element) {
    if (element instanceof DBNNode) {
        DBNNode node = (DBNNode) element;
        if (node instanceof DBNDataSource) {
            DBPDataSourceContainer ds = ((DBNDataSource) element).getDataSourceContainer();
            Color bgColor = UIUtils.getConnectionColor(ds.getConnectionConfiguration());
            return bgColor == null ? null : UIUtils.getContrastColor(bgColor);
        }
        if (node.isLocked()) {
            return lockedForeground;
        }
        if (node instanceof DBSWrapper && ((DBSWrapper) node).getObject() != null && !((DBSWrapper) node).getObject().isPersisted()) {
            return transientForeground;
        }
    }
    return null;
}
Also used : DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) Color(org.eclipse.swt.graphics.Color) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 47 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by serge-rider.

the class GotoObjectDialog method fillContentProvider.

@Override
protected void fillContentProvider(AbstractContentProvider contentProvider, ItemsFilter itemsFilter, IProgressMonitor progressMonitor) throws CoreException {
    DBSStructureAssistant structureAssistant = DBUtils.getAdapter(DBSStructureAssistant.class, context.getDataSource());
    if (structureAssistant == null) {
        return;
    }
    String nameMask = ((ObjectFilter) itemsFilter).getNameMask();
    DBRProgressMonitor monitor = RuntimeUtils.makeMonitor(progressMonitor);
    try {
        monitor.beginTask("Search for '" + nameMask + "'", 100);
        List<DBSObjectType> typesToSearch = new ArrayList<>();
        for (DBSObjectType type : structureAssistant.getSearchObjectTypes()) {
            if (!isValidObjectType(type)) {
                // Skip attributes (columns), methods, etc
                continue;
            }
            if (!Boolean.TRUE.equals(enabledTypes.get(type.getTypeName()))) {
                continue;
            }
            typesToSearch.add(type);
        }
        ObjectFinder objectFinder = new ObjectFinder(structureAssistant, monitor, context, typesToSearch, nameMask);
        DBExecUtils.tryExecuteRecover(monitor, context.getDataSource(), objectFinder);
        DBPDataSourceContainer dsContainer = context.getDataSource().getContainer();
        for (DBSObjectReference ref : objectFinder.getResult()) {
            DBSObjectFilter filter = dsContainer.getObjectFilter(ref.getObjectClass(), ref.getContainer(), true);
            if (filter == null || !filter.isEnabled() || filter.matches(ref.getName())) {
                contentProvider.add(ref, itemsFilter);
            }
        }
    } catch (DBException e) {
        throw new CoreException(GeneralUtils.makeExceptionStatus(e));
    } finally {
        monitor.done();
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) StyledString(org.eclipse.jface.viewers.StyledString) CoreException(org.eclipse.core.runtime.CoreException) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 48 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by serge-rider.

the class DebugUtils method findDatabaseObject.

public static DBSObject findDatabaseObject(DBGController controller, Object identifier, DBRProgressMonitor monitor) throws DBException {
    DBPDataSourceContainer container = controller.getDataSourceContainer();
    Map<String, Object> context = controller.getDebugConfiguration();
    return resolveDatabaseObject(container, context, identifier, monitor);
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 49 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by serge-rider.

the class DatabaseLaunchDelegate method launch.

@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    DBPDataSourceContainer datasourceDescriptor = DebugUtils.getDataSourceContainer(configuration);
    DBGController controller = createController(datasourceDescriptor, configuration.getAttributes());
    if (controller == null) {
        String message = NLS.bind("Unable to find debug controller for datasource {0}", datasourceDescriptor);
        throw new CoreException(DebugUtils.newErrorStatus(message));
    }
    DatabaseProcess process = createProcess(launch, configuration.getName());
    DatabaseDebugTarget target = createDebugTarget(launch, controller, process);
    target.connect(monitor);
    launch.addDebugTarget(target);
}
Also used : DatabaseDebugTarget(org.jkiss.dbeaver.debug.core.model.DatabaseDebugTarget) CoreException(org.eclipse.core.runtime.CoreException) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DBGController(org.jkiss.dbeaver.debug.DBGController) DatabaseProcess(org.jkiss.dbeaver.debug.core.model.DatabaseProcess)

Example 50 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by serge-rider.

the class PostgreFDWConfigWizardPageConfig method loadSettings.

private void loadSettings() {
    DBPDataSourceContainer targetDataSource = getWizard().getSelectedDataSource();
    if (targetDataSource == null) {
        setErrorMessage("No target data source");
        return;
    }
    // Fill FDW list
    try {
        getWizard().getRunnableContext().run(false, true, monitor -> {
            try {
                schemaList = new ArrayList<>();
                schemaList.addAll(getWizard().getDatabase().getSchemas(monitor));
                // Fill from both installed FDW and pre-configured FDW
                fdwList = new ArrayList<>();
                for (PostgreForeignDataWrapper fdw : CommonUtils.safeCollection(getWizard().getDatabase().getForeignDataWrappers(monitor))) {
                    PostgreFDWConfigWizard.FDWInfo fdwInfo = new PostgreFDWConfigWizard.FDWInfo();
                    fdwInfo.installedFDW = fdw;
                    fdwList.add(fdwInfo);
                }
                for (FDWConfigDescriptor fdw : FDWConfigRegistry.getInstance().getConfigDescriptors()) {
                    boolean found = false;
                    for (PostgreFDWConfigWizard.FDWInfo fdwInfo : fdwList) {
                        if (fdwInfo.getId().equals(fdw.getFdwId())) {
                            fdwInfo.fdwDescriptor = fdw;
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        PostgreFDWConfigWizard.FDWInfo fdwInfo = new PostgreFDWConfigWizard.FDWInfo();
                        fdwInfo.fdwDescriptor = fdw;
                        fdwList.add(fdwInfo);
                    }
                }
            } catch (DBException e) {
                throw new InvocationTargetException(e);
            }
        });
    } catch (InvocationTargetException e) {
        log.debug(e.getTargetException());
        setErrorMessage(e.getTargetException().getMessage());
        return;
    } catch (InterruptedException e) {
        return;
    }
    setErrorMessage(null);
    // Detect FDW from target container
    PostgreFDWConfigWizard.FDWInfo fdwInfo = getWizard().getSelectedFDW();
    if (fdwInfo == null) {
        FDWConfigDescriptor fdwConfig = FDWConfigRegistry.getInstance().findFirstMatch(targetDataSource);
        if (fdwConfig != null) {
            for (PostgreFDWConfigWizard.FDWInfo fdw : fdwList) {
                if (fdw.fdwDescriptor == fdwConfig) {
                    fdwInfo = fdw;
                    break;
                }
            }
        }
    }
    fdwCombo.removeAll();
    for (PostgreFDWConfigWizard.FDWInfo fdw : fdwList) {
        String fdwName = fdw.getId();
        if (!CommonUtils.isEmpty(fdw.getDescription())) {
            fdwName += " (" + fdw.getDescription() + ")";
        }
        fdwCombo.add(fdwName);
    }
    if (fdwInfo != null) {
        getWizard().setSelectedFDW(fdwInfo);
        fdwCombo.setText(fdwInfo.getId());
    }
    schemaCombo.removeAll();
    for (PostgreSchema schema : schemaList) {
        schemaCombo.add(schema.getName());
    }
    PostgreSchema selectedSchema = getWizard().getSelectedSchema();
    if (selectedSchema != null) {
        schemaCombo.setText(selectedSchema.getName());
    } else {
        PostgreSchema publicSchema = DBUtils.findObject(schemaList, PostgreConstants.PUBLIC_SCHEMA_NAME);
        if (publicSchema != null) {
            schemaCombo.setText(publicSchema.getName());
            getWizard().setSelectedSchema(publicSchema);
        }
    }
    refreshFDWProperties();
    if (CommonUtils.isEmpty(fdwServerText.getText())) {
        String fdwServerId = (fdwInfo == null ? targetDataSource.getDriver().getId() : fdwInfo.getId()) + "_srv";
        getWizard().setFdwServerId(fdwServerId);
        fdwServerText.setText(fdwServerId);
    }
    // Fill entities
    targetDataSourceText.setText(targetDataSource.getName());
    targetDriverText.setText(targetDataSource.getDriver().getName());
    entityTable.removeAll();
    for (DBNDatabaseNode entityNode : getWizard().getSelectedEntities()) {
        TableItem item = new TableItem(entityTable, SWT.NONE);
        item.setImage(0, DBeaverIcons.getImage(entityNode.getNodeIconDefault()));
        item.setText(0, entityNode.getNodeFullName());
    }
    UIUtils.packColumns(entityTable, false);
    propsEditor.repackColumns();
    updatePageCompletion();
}
Also used : DBException(org.jkiss.dbeaver.DBException) PostgreForeignDataWrapper(org.jkiss.dbeaver.ext.postgresql.model.PostgreForeignDataWrapper) InvocationTargetException(java.lang.reflect.InvocationTargetException) FDWConfigDescriptor(org.jkiss.dbeaver.ext.postgresql.model.fdw.FDWConfigDescriptor) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) PostgreSchema(org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Aggregations

DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)230 DBException (org.jkiss.dbeaver.DBException)32 ArrayList (java.util.ArrayList)31 IFile (org.eclipse.core.resources.IFile)30 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)27 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)27 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)24 InvocationTargetException (java.lang.reflect.InvocationTargetException)22 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)19 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)19 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)18 SelectionEvent (org.eclipse.swt.events.SelectionEvent)18 DBPProject (org.jkiss.dbeaver.model.app.DBPProject)18 DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)18 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)17 GridData (org.eclipse.swt.layout.GridData)16 IEditorPart (org.eclipse.ui.IEditorPart)16 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)16 DBNResource (org.jkiss.dbeaver.model.navigator.DBNResource)16 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)13