Search in sources :

Example 21 with DBPProject

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

the class EditorUtils method setFileDataSource.

public static void setFileDataSource(@NotNull IFile file, @NotNull DatabaseEditorContext context) {
    DBPProject projectMeta = DBWorkbench.getPlatform().getWorkspace().getProject(file.getProject());
    if (projectMeta == null) {
        return;
    }
    DBPDataSourceContainer dataSourceContainer = context.getDataSourceContainer();
    String dataSourceId = dataSourceContainer == null ? null : dataSourceContainer.getId();
    projectMeta.setResourceProperty(file, PROP_SQL_DATA_SOURCE_ID, dataSourceId);
    if (!isDefaultContextSettings(context)) {
        projectMeta.setResourceProperty(file, PROP_CONTEXT_DEFAULT_DATASOURCE, dataSourceId);
        String catalogName = getDefaultCatalogName(context);
        if (catalogName != null)
            projectMeta.setResourceProperty(file, PROP_CONTEXT_DEFAULT_CATALOG, catalogName);
        String schemaName = getDefaultSchemaName(context);
        if (catalogName != null || schemaName != null)
            projectMeta.setResourceProperty(file, PROP_CONTEXT_DEFAULT_SCHEMA, schemaName);
    }
}
Also used : DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 22 with DBPProject

use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.

the class DataSourceDescriptorManager method createNewObject.

@Override
public DataSourceDescriptor createNewObject(DBRProgressMonitor monitor, DBECommandContext commandContext, Object container, Object copyFrom, Map<String, Object> options) {
    if (copyFrom != null) {
        DataSourceDescriptor dsTpl = (DataSourceDescriptor) copyFrom;
        DBPDataSourceRegistry registry;
        DBPDataSourceFolder folder = null;
        if (container instanceof DataSourceRegistry) {
            registry = (DBPDataSourceRegistry) container;
        } else if (container instanceof DBPProject) {
            registry = ((DBPProject) container).getDataSourceRegistry();
        } else if (container instanceof DBPDataSourceFolder) {
            folder = (DBPDataSourceFolder) container;
            registry = folder.getDataSourceRegistry();
        } else {
            registry = dsTpl.getRegistry();
        }
        DataSourceDescriptor dataSource = new DataSourceDescriptor(registry, DataSourceDescriptor.generateNewId(dsTpl.getDriver()), dsTpl.getDriver(), new DBPConnectionConfiguration(dsTpl.getConnectionConfiguration()));
        dataSource.copyFrom(dsTpl);
        if (folder != null) {
            dataSource.setFolder(folder);
        } else if (dsTpl.getRegistry() == registry) {
            // Copy folder only if we copy in the same project
            dataSource.setFolder(dsTpl.getFolder());
        }
        // Generate new name
        String origName = dsTpl.getName();
        String newName = origName;
        for (int i = 0; ; i++) {
            if (registry.findDataSourceByName(newName) == null) {
                break;
            }
            newName = origName + " " + (i + 1);
        }
        dataSource.setName(newName);
        registry.addDataSource(dataSource);
    } else {
        UIUtils.asyncExec(() -> NewConnectionDialog.openNewConnectionDialog(UIUtils.getActiveWorkbenchWindow()));
    }
    return null;
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry) DBPDataSourceFolder(org.jkiss.dbeaver.model.DBPDataSourceFolder) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)

Example 23 with DBPProject

use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.

the class DiagramLoader method load.

public static void load(DBRProgressMonitor monitor, IProject project, DiagramPart diagramPart, InputStream in) throws XMLException, DBException {
    monitor.beginTask("Parse diagram", 1);
    final EntityDiagram diagram = diagramPart.getDiagram();
    DBPProject projectMeta = DBWorkbench.getPlatform().getWorkspace().getProject(project);
    if (projectMeta == null) {
        throw new DBException("Cannot find datasource registry for project '" + project.getName() + "'");
    }
    final Document document = XMLUtils.parseDocument(in);
    monitor.done();
    loadDiagram(monitor, document, projectMeta, diagram);
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) Document(org.w3c.dom.Document)

Example 24 with DBPProject

use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.

the class DiagramLoader method extractContainers.

public static List<DBPDataSourceContainer> extractContainers(IFile resource) throws IOException, XMLException, DBException {
    List<DBPDataSourceContainer> containers = new ArrayList<>();
    DBPProject projectMeta = DBWorkbench.getPlatform().getWorkspace().getProject(resource.getProject());
    if (projectMeta == null) {
        return containers;
    }
    try (InputStream is = resource.getContents()) {
        final Document document = XMLUtils.parseDocument(is);
        final Element diagramElem = document.getDocumentElement();
        final Element entitiesElem = XMLUtils.getChildElement(diagramElem, TAG_ENTITIES);
        if (entitiesElem != null) {
            // Parse data source
            for (Element dsElem : XMLUtils.getChildElementList(entitiesElem, TAG_DATA_SOURCE)) {
                String dsId = dsElem.getAttribute(ATTR_ID);
                if (!CommonUtils.isEmpty(dsId)) {
                    // Get connected datasource
                    final DBPDataSourceContainer dataSourceContainer = projectMeta.getDataSourceRegistry().getDataSource(dsId);
                    if (dataSourceContainer != null) {
                        containers.add(dataSourceContainer);
                    }
                }
            }
        }
    } catch (CoreException e) {
        throw new DBException("Error reading resource contents", e);
    }
    return containers;
}
Also used : DBException(org.jkiss.dbeaver.DBException) CoreException(org.eclipse.core.runtime.CoreException) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) Document(org.w3c.dom.Document)

Example 25 with DBPProject

use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.

the class ProjectHandlerImpl method openResource.

@Override
public void openResource(@NotNull IResource resource) {
    DBPProject project = DBWorkbench.getPlatform().getWorkspace().getProject((IProject) resource);
    if (project == null) {
        DBWorkbench.getPlatformUI().showError("No project", "Can't get project metadata for resource " + resource.getName());
        return;
    }
    MultiPageWizardDialog dialog = new MultiPageWizardDialog(UIUtils.getActiveWorkbenchWindow(), new EditProjectWizard(project));
    dialog.open();
}
Also used : EditProjectWizard(org.jkiss.dbeaver.ui.project.EditProjectWizard) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) MultiPageWizardDialog(org.jkiss.dbeaver.ui.dialogs.MultiPageWizardDialog)

Aggregations

DBPProject (org.jkiss.dbeaver.model.app.DBPProject)90 IFile (org.eclipse.core.resources.IFile)20 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)18 DBException (org.jkiss.dbeaver.DBException)14 DBPDataSourceRegistry (org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)14 IFolder (org.eclipse.core.resources.IFolder)8 DBPWorkspace (org.jkiss.dbeaver.model.app.DBPWorkspace)8 IResource (org.eclipse.core.resources.IResource)6 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)6 SelectionEvent (org.eclipse.swt.events.SelectionEvent)6 IEditorPart (org.eclipse.ui.IEditorPart)6 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)6 GridData (org.eclipse.swt.layout.GridData)5 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 ArrayList (java.util.ArrayList)4 CoreException (org.eclipse.core.runtime.CoreException)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 DBPImage (org.jkiss.dbeaver.model.DBPImage)4 Document (org.w3c.dom.Document)4