Search in sources :

Example 1 with ProjectRegistry

use of org.jkiss.dbeaver.registry.ProjectRegistry in project dbeaver by serge-rider.

the class ApplicationWorkbenchWindowAdvisor method dispose.

@Override
public void dispose() {
    // Remove project listener
    DBeaverCore core = DBeaverCore.getInstance();
    if (core != null) {
        ProjectRegistry projectRegistry = core.getProjectRegistry();
        if (projectRegistry != null) {
            projectRegistry.removeProjectListener(this);
        }
    }
    super.dispose();
}
Also used : DBeaverCore(org.jkiss.dbeaver.core.DBeaverCore) ProjectRegistry(org.jkiss.dbeaver.registry.ProjectRegistry)

Example 2 with ProjectRegistry

use of org.jkiss.dbeaver.registry.ProjectRegistry in project dbeaver by dbeaver.

the class OpenHandler method getCurrentConnection.

@Nullable
private static DBPDataSourceContainer getCurrentConnection(ExecutionEvent event) {
    DBPDataSourceContainer dataSourceContainer = getDataSourceContainer(event, false);
    final ProjectRegistry projectRegistry = DBeaverCore.getInstance().getProjectRegistry();
    IProject project = dataSourceContainer != null ? dataSourceContainer.getRegistry().getProject() : projectRegistry.getActiveProject();
    if (dataSourceContainer == null) {
        final DataSourceRegistry dataSourceRegistry = projectRegistry.getDataSourceRegistry(project);
        if (dataSourceRegistry == null) {
            return null;
        }
        if (dataSourceRegistry.getDataSources().size() == 1) {
            dataSourceContainer = dataSourceRegistry.getDataSources().get(0);
        } else if (!dataSourceRegistry.getDataSources().isEmpty()) {
            SelectDataSourceDialog dialog = new SelectDataSourceDialog(HandlerUtil.getActiveShell(event), project, null);
            if (dialog.open() == IDialogConstants.CANCEL_ID) {
                return null;
            }
            dataSourceContainer = dialog.getDataSource();
        }
    }
    return dataSourceContainer;
}
Also used : DataSourceRegistry(org.jkiss.dbeaver.registry.DataSourceRegistry) ProjectRegistry(org.jkiss.dbeaver.registry.ProjectRegistry) SelectDataSourceDialog(org.jkiss.dbeaver.ui.dialogs.connection.SelectDataSourceDialog) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) IProject(org.eclipse.core.resources.IProject) Nullable(org.jkiss.code.Nullable)

Example 3 with ProjectRegistry

use of org.jkiss.dbeaver.registry.ProjectRegistry in project dbeaver by serge-rider.

the class NavigatorHandlerProjectSetActive method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection structSelection = (IStructuredSelection) selection;
        Object element = structSelection.getFirstElement();
        if (!(element instanceof DBNProject)) {
            return null;
        }
        DBNProject projectNode = (DBNProject) element;
        final ProjectRegistry projectRegistry = DBeaverCore.getInstance().getProjectRegistry();
        if (projectRegistry.getActiveProject() != projectNode.getProject()) {
            projectRegistry.setActiveProject(projectNode.getProject());
        }
    }
    return null;
}
Also used : DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ProjectRegistry(org.jkiss.dbeaver.registry.ProjectRegistry)

Example 4 with ProjectRegistry

use of org.jkiss.dbeaver.registry.ProjectRegistry in project dbeaver by serge-rider.

the class ResourcePropertyTester method test.

@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    if (!(receiver instanceof IResource)) {
        return false;
    }
    IResource resource = (IResource) receiver;
    final ProjectRegistry projectRegistry = DBeaverCore.getInstance().getProjectRegistry();
    DBPResourceHandler handler = projectRegistry.getResourceHandler(resource);
    if (handler == null) {
        return false;
    }
    switch(property) {
        case PROP_CAN_OPEN:
            return (handler.getFeatures(resource) & DBPResourceHandler.FEATURE_OPEN) != 0;
        case PROP_CAN_DELETE:
            return (handler.getFeatures(resource) & DBPResourceHandler.FEATURE_DELETE) != 0;
        case PROP_CAN_CREATE_FOLDER:
            return (handler.getFeatures(resource) & DBPResourceHandler.FEATURE_CREATE_FOLDER) != 0;
        case PROP_CAN_CREATE_LINK:
            return (handler.getFeatures(resource) & DBPResourceHandler.FEATURE_CREATE_FOLDER) != 0 && !resource.isLinked(IResource.CHECK_ANCESTORS);
        case PROP_CAN_SET_ACTIVE:
            return resource instanceof IProject && resource != projectRegistry.getActiveProject();
        case PROP_TYPE:
            final DBPResourceHandler resourceHandler = DBeaverCore.getInstance().getProjectRegistry().getResourceHandler(resource);
            return resourceHandler != null && expectedValue.equals(resourceHandler.getTypeName(resource));
    }
    return false;
}
Also used : ProjectRegistry(org.jkiss.dbeaver.registry.ProjectRegistry) DBPResourceHandler(org.jkiss.dbeaver.model.app.DBPResourceHandler) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 5 with ProjectRegistry

use of org.jkiss.dbeaver.registry.ProjectRegistry in project dbeaver by serge-rider.

the class DBeaverCore method initialize.

private void initialize() {
    long startTime = System.currentTimeMillis();
    log.debug("Initialize Core...");
    // Register properties adapter
    this.workspace = ResourcesPlugin.getWorkspace();
    this.localSystem = new OSDescriptor(Platform.getOS(), Platform.getOSArch());
    QMUtils.initApplication(this);
    this.queryManager = new QMControllerImpl();
    this.qmLogWriter = new QMLogFileWriter();
    this.queryManager.registerMetaListener(qmLogWriter);
    // Init default network settings
    Authenticator.setDefault(new GlobalProxyAuthenticator());
    ProxySelector.setDefault(new GlobalProxySelector(ProxySelector.getDefault()));
    this.certificateStorage = new DefaultCertificateStorage(new File(DBeaverActivator.getInstance().getStateLocation().toFile(), "security"));
    // Init project registry
    this.projectRegistry = new ProjectRegistry(workspace);
    // Projects registry
    initializeProjects();
    // Navigator model
    this.navigatorModel = new DBNModel(this);
    this.navigatorModel.initialize();
    // Activate plugin services
    for (IPluginService pluginService : PluginServiceRegistry.getInstance().getServices()) {
        try {
            pluginService.activateService();
            activatedServices.add(pluginService);
        } catch (Throwable e) {
            log.error("Error activating plugin service", e);
        }
    }
    // Keep-alive job
    new KeepAliveJob().scheduleMonitor();
    log.debug("Core initialized (" + (System.currentTimeMillis() - startTime) + "ms)");
}
Also used : DefaultCertificateStorage(org.jkiss.dbeaver.model.impl.app.DefaultCertificateStorage) QMControllerImpl(org.jkiss.dbeaver.runtime.qm.QMControllerImpl) GlobalProxyAuthenticator(org.jkiss.dbeaver.runtime.net.GlobalProxyAuthenticator) QMLogFileWriter(org.jkiss.dbeaver.runtime.qm.QMLogFileWriter) KeepAliveJob(org.jkiss.dbeaver.runtime.jobs.KeepAliveJob) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel) GlobalProxySelector(org.jkiss.dbeaver.runtime.net.GlobalProxySelector) IPluginService(org.jkiss.dbeaver.runtime.IPluginService) ProjectRegistry(org.jkiss.dbeaver.registry.ProjectRegistry) OSDescriptor(org.jkiss.dbeaver.model.runtime.OSDescriptor) File(java.io.File)

Aggregations

ProjectRegistry (org.jkiss.dbeaver.registry.ProjectRegistry)10 IProject (org.eclipse.core.resources.IProject)4 DBeaverCore (org.jkiss.dbeaver.core.DBeaverCore)3 IResource (org.eclipse.core.resources.IResource)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 Nullable (org.jkiss.code.Nullable)2 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)2 DBPResourceHandler (org.jkiss.dbeaver.model.app.DBPResourceHandler)2 DBNProject (org.jkiss.dbeaver.model.navigator.DBNProject)2 DataSourceRegistry (org.jkiss.dbeaver.registry.DataSourceRegistry)2 File (java.io.File)1 DefaultCertificateStorage (org.jkiss.dbeaver.model.impl.app.DefaultCertificateStorage)1 DBNModel (org.jkiss.dbeaver.model.navigator.DBNModel)1 OSDescriptor (org.jkiss.dbeaver.model.runtime.OSDescriptor)1 DataSourceDescriptor (org.jkiss.dbeaver.registry.DataSourceDescriptor)1 IPluginService (org.jkiss.dbeaver.runtime.IPluginService)1 KeepAliveJob (org.jkiss.dbeaver.runtime.jobs.KeepAliveJob)1 GlobalProxyAuthenticator (org.jkiss.dbeaver.runtime.net.GlobalProxyAuthenticator)1 GlobalProxySelector (org.jkiss.dbeaver.runtime.net.GlobalProxySelector)1