Search in sources :

Example 11 with DBPProject

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

the class SQLScriptTaskPageSettings method loadSettings.

public void loadSettings() {
    SQLScriptExecuteSettings settings = sqlWizard.getSettings();
    List<String> scriptFiles = settings.getScriptFiles();
    for (String filePath : scriptFiles) {
        IFile file = SQLScriptExecuteSettings.getWorkspaceFile(filePath);
        if (file == null) {
            log.debug("Script file '" + filePath + "' not found");
            continue;
        }
        DBPProject currentProject = DBWorkbench.getPlatform().getWorkspace().getProject(file.getProject());
        if (currentProject == null) {
            log.debug("Project '" + file.getProject().getName() + "' not found");
            continue;
        }
        DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(currentProject);
        if (projectNode != null) {
            DBNResource resource = projectNode.findResource(file);
            if (resource != null) {
                selectedScripts.add(resource);
            }
        }
    }
    scriptsViewer.setInput(selectedScripts);
    for (DBPDataSourceContainer dataSource : settings.getDataSources()) {
        DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(dataSource.getProject());
        DBNDataSource dsNode = projectNode.getDatabases().getDataSource(dataSource);
        if (dsNode != null) {
            selectedDataSources.add(dsNode);
        }
    }
    dataSourceViewer.setInput(selectedDataSources);
// if (!selectedDataSources.isEmpty()) {
// dataSourceTree.getCheckboxViewer().setCheckedElements(selectedDataSources.toArray());
// dataSourceTree.getCheckboxViewer().reveal(selectedDataSources.get(0));
// }
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) IFile(org.eclipse.core.resources.IFile) SQLScriptExecuteSettings(org.jkiss.dbeaver.tools.sql.SQLScriptExecuteSettings) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 12 with DBPProject

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

the class SQLScriptExecuteSettings method loadConfiguration.

public void loadConfiguration(DBRRunnableContext runnableContext, Map<String, Object> config) {
    // Legacy config support (single datasource
    String projectName = JSONUtils.getString(config, "project");
    DBPProject project = CommonUtils.isEmpty(projectName) ? null : DBWorkbench.getPlatform().getWorkspace().getProject(projectName);
    if (project != null) {
        String dataSourceContainerId = JSONUtils.getString(config, "dataSourceContainer");
        if (!CommonUtils.isEmpty(dataSourceContainerId)) {
            DBPDataSourceContainer dataSource = project.getDataSourceRegistry().getDataSource(dataSourceContainerId);
            if (dataSource != null) {
                dataSources.add(dataSource);
            }
        }
    } else {
        // Modern config (datasource list)
        List<Map<String, Object>> dsConfig = JSONUtils.getObjectList(config, "dataSources");
        for (Map<String, Object> dsInfo : dsConfig) {
            projectName = JSONUtils.getString(dsInfo, "project");
            project = CommonUtils.isEmpty(projectName) ? null : DBWorkbench.getPlatform().getWorkspace().getProject(projectName);
            if (project != null) {
                String dataSourceContainerId = JSONUtils.getString(dsInfo, "dataSource");
                if (!CommonUtils.isEmpty(dataSourceContainerId)) {
                    DBPDataSourceContainer dataSource = project.getDataSourceRegistry().getDataSource(dataSourceContainerId);
                    if (dataSource != null) {
                        dataSources.add(dataSource);
                    }
                }
            }
        }
    }
    scriptFiles = JSONUtils.deserializeStringList(config, "scriptFiles");
    ignoreErrors = JSONUtils.getBoolean(config, "ignoreErrors");
    dumpQueryResultsToLog = JSONUtils.getBoolean(config, "dumpQueryResultsToLog");
    autoCommit = JSONUtils.getBoolean(config, "autoCommit");
}
Also used : DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 13 with DBPProject

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

the class DiagramCreateWizard method init.

@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
    setWindowTitle(ERDUIMessages.wizard_diagram_create_title);
    setNeedsProgressMonitor(true);
    IFolder diagramFolder = null;
    if (selection != null) {
        Object element = selection.getFirstElement();
        if (element != null) {
            diagramFolder = Platform.getAdapterManager().getAdapter(element, IFolder.class);
        }
    }
    if (diagramFolder == null) {
        DBPProject activeProject = DBWorkbench.getPlatform().getWorkspace().getActiveProject();
        if (activeProject == null) {
            errorMessage = "Can't create diagram without active project";
        } else {
            try {
                diagramFolder = ERDResourceHandler.getDiagramsFolder(activeProject, true);
            } catch (CoreException e) {
                errorMessage = e.getMessage();
            }
        }
        // Check for entity selection
        if (selection != null && !selection.isEmpty()) {
            if (Platform.getAdapterManager().getAdapter(selection.getFirstElement(), DBSEntity.class) != null) {
                entitySelection = selection;
            }
        }
    }
    this.folder = diagramFolder;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) IFolder(org.eclipse.core.resources.IFolder)

Example 14 with DBPProject

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

the class KeepAliveListenerJob method run.

@Override
protected IStatus run(DBRProgressMonitor monitor) {
    if (platform.isShuttingDown()) {
        return Status.OK_STATUS;
    }
    if (lastPingTime > 0 && System.currentTimeMillis() - lastPingTime > SYSTEM_SUSPEND_INTERVAL) {
        log.debug("System suspend detected! Reinitialize all remote connections.");
    }
    lastPingTime = System.currentTimeMillis();
    final DBPWorkspace workspace = platform.getWorkspace();
    for (DBPProject project : workspace.getProjects()) {
        if (project.isOpen() && project.isRegistryLoaded()) {
            DBPDataSourceRegistry dataSourceRegistry = project.getDataSourceRegistry();
            for (DBPDataSourceContainer ds : dataSourceRegistry.getDataSources()) {
                checkDataSourceAlive(ds);
            }
        }
    }
    if (!platform.isShuttingDown()) {
        scheduleMonitor();
    }
    return Status.OK_STATUS;
}
Also used : DBPWorkspace(org.jkiss.dbeaver.model.app.DBPWorkspace) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 15 with DBPProject

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

the class ApplicationWorkbenchWindowAdvisor method computeTitle.

private String computeTitle() {
    // Use hardcoded pref constants to avoid E4.7 compile dependency
    IPreferenceStore ps = IDEWorkbenchPlugin.getDefault().getPreferenceStore();
    // $NON-NLS-1$
    StringJoiner sj = new StringJoiner(" - ");
    if (ps.getBoolean("SHOW_LOCATION_NAME")) {
        String workspaceName = ps.getString("WORKSPACE_NAME");
        if (workspaceName != null && workspaceName.length() > 0) {
            sj.add(workspaceName);
        }
    }
    if (ps.getBoolean("SHOW_LOCATION")) {
        String workspaceLocation = Platform.getLocation().toOSString();
        sj.add(workspaceLocation);
    }
    if (ps.getBoolean("SHOW_PERSPECTIVE_IN_TITLE")) {
        DBPProject activeProject = DBWorkbench.getPlatform().getWorkspace().getActiveProject();
        if (activeProject != null) {
            // $NON-NLS-1$
            sj.add(activeProject.getName());
        }
    }
    if (ps.getBoolean("SHOW_PRODUCT_IN_TITLE")) {
        sj.add(GeneralUtils.getProductTitle());
    }
    IWorkbenchWindow window = getWindowConfigurer().getWindow();
    if (window != null) {
        IWorkbenchPage activePage = window.getActivePage();
        if (activePage != null) {
            IEditorPart activeEditor = activePage.getActiveEditor();
            if (activeEditor != null) {
                sj.add(activeEditor.getTitle());
            }
        }
    }
    return sj.toString();
}
Also used : DBPProject(org.jkiss.dbeaver.model.app.DBPProject) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) StringJoiner(java.util.StringJoiner)

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