Search in sources :

Example 1 with DBPDataSourceRegistry

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

the class NavigatorHandlerLocalFolderCreate method createFolder.

public static boolean createFolder(IWorkbenchWindow workbenchWindow, IWorkbenchPart activePart, DBNProjectDatabases databases, final DBNLocalFolder parentFolder, final Collection<DBNDataSource> nodes, String newName) {
    if (newName == null) {
        newName = EnterNameDialog.chooseName(workbenchWindow.getShell(), "Folder name");
    }
    if (CommonUtils.isEmpty(newName)) {
        return false;
    }
    // Create folder and refresh databases root
    // DS container will reload folders on refresh
    final DBPDataSourceRegistry dsRegistry = databases.getDataSourceRegistry();
    DBPDataSourceFolder folder = dsRegistry.addFolder(parentFolder == null ? null : parentFolder.getFolder(), newName);
    for (DBNDataSource node : nodes) {
        node.setFolder(folder);
    }
    if (parentFolder != null && activePart instanceof NavigatorViewBase) {
        final TreeViewer viewer = ((NavigatorViewBase) activePart).getNavigatorViewer();
        if (viewer != null) {
            DBeaverUI.asyncExec(new Runnable() {

                @Override
                public void run() {
                    viewer.expandToLevel(parentFolder, 1);
                }
            });
        }
    }
    DBNModel.updateConfigAndRefreshDatabases(databases);
    return true;
}
Also used : DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DBPDataSourceFolder(org.jkiss.dbeaver.model.DBPDataSourceFolder) NavigatorViewBase(org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)

Example 2 with DBPDataSourceRegistry

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

the class DBNProject method readChildNodes.

@Override
protected DBNNode[] readChildNodes(DBRProgressMonitor monitor) throws DBException {
    IProject project = getProject();
    if (!project.isOpen()) {
        try {
            project.open(monitor.getNestedMonitor());
            project.refreshLocal(IFile.DEPTH_ONE, monitor.getNestedMonitor());
        } catch (CoreException e) {
            throw new DBException("Can't open project '" + project.getName() + "'", e);
        }
    }
    DBPDataSourceRegistry dataSourceRegistry = getModel().getPlatform().getProjectManager().getDataSourceRegistry(project);
    DBNNode[] children = super.readChildNodes(monitor);
    if (dataSourceRegistry != null) {
        children = ArrayUtils.insertArea(DBNNode.class, children, 0, new Object[] { new DBNProjectDatabases(this, dataSourceRegistry) });
    }
    return children;
}
Also used : DBException(org.jkiss.dbeaver.DBException) CoreException(org.eclipse.core.runtime.CoreException) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)

Example 3 with DBPDataSourceRegistry

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

the class DataSourceDescriptorManager method createNewObject.

@Override
public DataSourceDescriptor createNewObject(DBRProgressMonitor monitor, DBECommandContext commandContext, DBPObject parent, Object copyFrom) {
    if (copyFrom != null) {
        DataSourceDescriptor dsTpl = (DataSourceDescriptor) copyFrom;
        DBPDataSourceRegistry registry;
        DBPDataSourceFolder folder = null;
        if (parent instanceof DataSourceRegistry) {
            registry = (DBPDataSourceRegistry) parent;
        } else if (parent instanceof DBPDataSourceFolder) {
            folder = (DBPDataSourceFolder) parent;
            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);
        }
        // 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 {
        DBeaverUI.asyncExec(new Runnable() {

            @Override
            public void run() {
                CreateConnectionDialog dialog = new CreateConnectionDialog(DBeaverUI.getActiveWorkbenchWindow(), new NewConnectionWizard());
                dialog.open();
            }
        });
    }
    return null;
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry) DBPDataSourceFolder(org.jkiss.dbeaver.model.DBPDataSourceFolder) NewConnectionWizard(org.jkiss.dbeaver.ui.dialogs.connection.NewConnectionWizard) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry) CreateConnectionDialog(org.jkiss.dbeaver.ui.dialogs.connection.CreateConnectionDialog)

Example 4 with DBPDataSourceRegistry

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

the class DataSourceManagementToolbar method dispose.

private void dispose() {
    DBeaverCore.getInstance().getNavigatorModel().removeListener(this);
    IWorkbenchPage activePage = workbenchWindow.getActivePage();
    if (activePage != null) {
        pageListener.pageClosed(activePage);
    }
    DataSourceProviderRegistry.getInstance().removeDataSourceRegistryListener(this);
    for (DBPDataSourceRegistry registry : handledRegistries) {
        registry.removeDataSourceListener(this);
    }
    setActivePart(null);
    this.workbenchWindow.removePageListener(pageListener);
}
Also used : DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)

Example 5 with DBPDataSourceRegistry

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

the class NewConnectionWizard method performFinish.

/**
     * This method is called when 'Finish' button is pressed in
     * the wizard. We will create an operation and run it
     * using wizard as execution context.
     */
@Override
public boolean performFinish() {
    DriverDescriptor driver = getSelectedDriver();
    ConnectionPageSettings pageSettings = getPageSettings();
    DataSourceDescriptor dataSourceTpl = pageSettings == null ? getActiveDataSource() : pageSettings.getActiveDataSource();
    DBPDataSourceRegistry dataSourceRegistry = getDataSourceRegistry();
    DataSourceDescriptor dataSourceNew = new DataSourceDescriptor(dataSourceRegistry, dataSourceTpl.getId(), driver, dataSourceTpl.getConnectionConfiguration());
    dataSourceNew.copyFrom(dataSourceTpl);
    saveSettings(dataSourceNew);
    dataSourceRegistry.addDataSource(dataSourceNew);
    return true;
}
Also used : DriverDescriptor(org.jkiss.dbeaver.registry.driver.DriverDescriptor) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor)

Aggregations

DBPDataSourceRegistry (org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)5 DBPDataSourceFolder (org.jkiss.dbeaver.model.DBPDataSourceFolder)2 CoreException (org.eclipse.core.runtime.CoreException)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 DBException (org.jkiss.dbeaver.DBException)1 DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)1 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)1 DataSourceDescriptor (org.jkiss.dbeaver.registry.DataSourceDescriptor)1 DriverDescriptor (org.jkiss.dbeaver.registry.driver.DriverDescriptor)1 CreateConnectionDialog (org.jkiss.dbeaver.ui.dialogs.connection.CreateConnectionDialog)1 NewConnectionWizard (org.jkiss.dbeaver.ui.dialogs.connection.NewConnectionWizard)1 NavigatorViewBase (org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase)1