Search in sources :

Example 76 with DBPProject

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

the class SQLToolExecuteSettings method loadConfiguration.

public void loadConfiguration(DBRRunnableContext runnableContext, Map<String, Object> config) {
    try {
        runnableContext.run(true, true, monitor -> {
            List<OBJECT_TYPE> objList = new ArrayList<>();
            for (Map<String, Object> objectConfig : JSONUtils.getObjectList(config, "objects")) {
                String projectName = CommonUtils.toString(objectConfig.get("project"));
                DBPProject project = CommonUtils.isEmpty(projectName) ? null : DBWorkbench.getPlatform().getWorkspace().getProject(projectName);
                if (project == null) {
                    log.error("Project '" + projectName + "' not found");
                    continue;
                }
                String objectId = CommonUtils.toString(objectConfig.get("objectId"));
                try {
                    OBJECT_TYPE object = (OBJECT_TYPE) DBUtils.findObjectById(monitor, project, objectId);
                    if (object != null) {
                        objList.add(object);
                    }
                } catch (DBException e) {
                    log.error("Can't find object '" + objectId + "' in project '" + project.getName() + "'");
                    warnings.add(e);
                }
            }
            objectList.addAll(objList);
        });
    } catch (InvocationTargetException e) {
        log.error(e.getTargetException());
    } catch (InterruptedException e) {
    // ignore
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) ArrayList(java.util.ArrayList) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 77 with DBPProject

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

the class DataSourceRegistry method getAllDataSources.

public static List<DBPDataSourceContainer> getAllDataSources() {
    List<DBPDataSourceContainer> result = new ArrayList<>();
    DBPWorkspace workspace = DBWorkbench.getPlatform().getWorkspace();
    for (DBPProject project : workspace.getProjects()) {
        if (project.isOpen() && project.isRegistryLoaded()) {
            result.addAll(project.getDataSourceRegistry().getDataSources());
        }
    }
    return result;
}
Also used : DBPWorkspace(org.jkiss.dbeaver.model.app.DBPWorkspace) DBPProject(org.jkiss.dbeaver.model.app.DBPProject)

Example 78 with DBPProject

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

the class WorkbenchInitializerCreateSampleDatabase method initializeWorkbenchWindow.

@Override
public void initializeWorkbenchWindow(IWorkbenchWindow window) {
    if (DBWorkbench.getPlatform().getPreferenceStore().getBoolean(PROP_SAMPLE_DB_CANCELED)) {
        // Create was canceled
        return;
    }
    if (DataSourceRegistry.getAllDataSources().size() > 1) {
        // Seems to be experienced user - no need in sampel db
        return;
    }
    DBPProject activeProject = DBWorkbench.getPlatform().getWorkspace().getActiveProject();
    if (activeProject == null || !activeProject.isRegistryLoaded()) {
        // No active project
        return;
    }
    DBPDataSourceRegistry registry = activeProject.getDataSourceRegistry();
    if (isSampleDatabaseExists(registry)) {
        // Already exist
        return;
    }
    if (!showCreateSampleDatabasePrompt(window.getShell())) {
        DBWorkbench.getPlatform().getPreferenceStore().setValue(PROP_SAMPLE_DB_CANCELED, true);
        return;
    }
    createSampleDatabase(registry);
}
Also used : DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)

Example 79 with DBPProject

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

the class DBUtils method getAllRegistries.

public static List<DBPDataSourceRegistry> getAllRegistries(boolean forceLoad) {
    List<DBPDataSourceRegistry> result = new ArrayList<>();
    for (DBPProject project : DBWorkbench.getPlatform().getWorkspace().getProjects()) {
        if (forceLoad || (project.isOpen() && project.isRegistryLoaded())) {
            project.ensureOpen();
            DBPDataSourceRegistry registry = project.getDataSourceRegistry();
            if (registry != null) {
                result.add(registry);
            }
        }
    }
    return result;
}
Also used : DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)

Example 80 with DBPProject

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

the class DBNModel method resourceChanged.

@Override
public void resourceChanged(IResourceChangeEvent event) {
    if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
        IResourceDelta delta = event.getDelta();
        for (IResourceDelta childDelta : delta.getAffectedChildren()) {
            if (childDelta.getResource() instanceof IProject) {
                IProject project = (IProject) childDelta.getResource();
                DBNProject projectNode = getRoot().getProjectNode(project);
                if (projectNode == null) {
                    if (childDelta.getKind() == IResourceDelta.ADDED) {
                        // New projectNode
                        DBPProject projectMeta = platform.getWorkspace().getProject(project);
                        if (projectMeta == null) {
                            log.error("Can't find project '" + project.getName() + "' metadata");
                        } else {
                            getRoot().addProject(projectMeta, true);
                        }
                    } else if (childDelta.getKind() != IResourceDelta.REMOVED) {
                        // Project not found - report an error
                        log.error("Project '" + childDelta.getResource().getName() + "' not found in navigator");
                    }
                } else {
                    if (childDelta.getKind() == IResourceDelta.REMOVED) {
                        // Project deleted
                        DBPProject projectMeta = platform.getWorkspace().getProject(project);
                        if (projectMeta == null) {
                            log.error("Can't find project '" + project.getName() + "' metadata");
                        } else {
                            getRoot().removeProject(projectMeta);
                        }
                    } else {
                        // Some resource changed within the projectNode
                        // Let it handle this event itself
                        projectNode.handleResourceChange(childDelta);
                    }
                }
            }
        }
    }
}
Also used : DBPProject(org.jkiss.dbeaver.model.app.DBPProject)

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