Search in sources :

Example 41 with DBPProject

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

the class SQLEditorHandlerOpenEditor method openEditor.

private static void openEditor(ExecutionEvent event) throws ExecutionException, CoreException, InterruptedException {
    SQLNavigatorContext editorContext = getCurrentContext(event);
    DBPProject project = editorContext.getProject();
    checkProjectIsOpen(project);
    IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    final IFolder rootFolder = SQLEditorUtils.getScriptsFolder(project, true);
    final List<SQLEditorUtils.ResourceInfo> scriptTree = SQLEditorUtils.findScriptTree(project, rootFolder, editorContext.getDataSourceContainer());
    if (scriptTree.isEmpty()) {
        // Create new script
        final IFile newScript = SQLEditorUtils.createNewScript(project, rootFolder, editorContext);
        openResource(newScript, editorContext);
    } else {
        // Show script chooser
        ScriptSelectorPanel.showTree(workbenchWindow, editorContext, rootFolder, scriptTree);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) IFolder(org.eclipse.core.resources.IFolder)

Example 42 with DBPProject

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

the class AbstractNativeToolSettings method loadSettings.

public void loadSettings(DBRRunnableContext runnableContext, DBPPreferenceStore preferenceStore) throws DBException {
    if (dataSourceContainer == null && !CommonUtils.isEmpty(databaseObjects)) {
        BASE_OBJECT baseObject = databaseObjects.get(0);
        dataSourceContainer = baseObject instanceof DBPDataSourceContainer ? (DBPDataSourceContainer) baseObject : baseObject.getDataSource().getContainer();
    }
    if (dataSourceContainer == null) {
        String dsID = preferenceStore.getString("dataSource");
        if (!CommonUtils.isEmpty(dsID)) {
            String projectName = preferenceStore.getString("project");
            DBPProject project = CommonUtils.isEmpty(projectName) ? null : DBWorkbench.getPlatform().getWorkspace().getProject(projectName);
            if (project == null) {
                if (!CommonUtils.isEmpty(projectName)) {
                    log.error("Can't find project '" + projectName + "' for tool configuration");
                }
                project = DBWorkbench.getPlatform().getWorkspace().getActiveProject();
            }
            dataSourceContainer = project.getDataSourceRegistry().getDataSource(dsID);
            if (dataSourceContainer == null) {
                log.error("Can't find datasource '" + dsID + "' in project '" + project.getName() + "' for tool configuration");
            }
        }
    }
    if (preferenceStore instanceof DBPPreferenceMap && dataSourceContainer != null) {
        List<String> databaseObjectList = ((DBPPreferenceMap) preferenceStore).getObject("databaseObjects");
        if (!CommonUtils.isEmpty(databaseObjectList)) {
            DBPProject finalProject = dataSourceContainer.getProject();
            try {
                runnableContext.run(true, true, monitor -> {
                    monitor.beginTask("Load database object list", databaseObjectList.size());
                    try {
                        for (String objectId : databaseObjectList) {
                            monitor.subTask("Load " + objectId);
                            try {
                                DBSObject object = DBUtils.findObjectById(monitor, finalProject, objectId);
                                if (object != null) {
                                    databaseObjects.add((BASE_OBJECT) object);
                                    dataSourceContainer = object instanceof DBPDataSourceContainer ? (DBPDataSourceContainer) object : object.getDataSource().getContainer();
                                }
                            } catch (Throwable e) {
                                throw new DBException("Can't find database object '" + objectId + "' in project '" + finalProject.getName() + "' for task configuration", e);
                            }
                            monitor.worked(1);
                        }
                    } catch (Exception e) {
                        throw new InvocationTargetException(e);
                    } finally {
                        monitor.done();
                    }
                });
            } catch (InvocationTargetException e) {
                throw new DBException("Error loading objects configuration", e.getTargetException());
            } catch (InterruptedException e) {
            // Ignore
            }
        }
    }
    extraCommandArgs = preferenceStore.getString(PROP_NAME_EXTRA_ARGS);
    clientHomeName = preferenceStore.getString("clientHomeName");
    if (preferenceStore instanceof DBPPreferenceMap) {
        toolUserName = preferenceStore.getString("tool.user");
        toolUserPassword = preferenceStore.getString("tool.password");
        try {
            final SecuredPasswordEncrypter encrypter = new SecuredPasswordEncrypter();
            if (!CommonUtils.isEmpty(toolUserName))
                toolUserName = encrypter.decrypt(toolUserName);
            if (!CommonUtils.isEmpty(toolUserPassword))
                toolUserPassword = encrypter.decrypt(toolUserPassword);
        } catch (Exception e) {
            throw new DBException("Error decrypting user credentials", e);
        }
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPPreferenceMap(org.jkiss.dbeaver.model.preferences.DBPPreferenceMap) SecuredPasswordEncrypter(org.jkiss.dbeaver.runtime.encode.SecuredPasswordEncrypter) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 43 with DBPProject

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

the class TaskHandlerCreate method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    DBPProject project = NavigatorUtils.getSelectedProject();
    /*
        CreateTaskConfigurationDialog dialog = new CreateTaskConfigurationDialog(
            HandlerUtil.getActiveShell(event),
            project
        );
*/
    TaskConfigurationWizardDialog dialog = new TaskConfigurationWizardDialog(HandlerUtil.getActiveWorkbenchWindow(event));
    if (dialog.open() == IDialogConstants.OK_ID) {
        DBTTaskManager taskManager = project.getTaskManager();
        try {
        /*
                DBTTaskConfigurator configurator = dialog.getSelectedCategory().createConfigurator();
                DBTTask task = taskManager.createTask(
                    dialog.getSelectedTaskType(),
                    dialog.getTaskName(),
                    dialog.getTaskDescription(),
                    dialog.getInitialProperties());
                if (!configurator.createTaskConfigWizard(task)) {
                    taskManager.deleteTaskConfiguration(task);
                }
*/
        } catch (Exception e) {
            DBWorkbench.getPlatformUI().showError("Create task failed", "Error while creating new task", e);
        }
    }
    return null;
}
Also used : DBTTaskManager(org.jkiss.dbeaver.model.task.DBTTaskManager) TaskConfigurationWizardDialog(org.jkiss.dbeaver.tasks.ui.wizard.TaskConfigurationWizardDialog) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 44 with DBPProject

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

the class DatabaseBrowserView method getNodeFromSecondaryId.

public static DBNNode getNodeFromSecondaryId(String id) throws DBException {
    int divPos = id.indexOf('|');
    if (divPos == -1) {
        throw new DBException("Bad secondary ID: " + id);
    }
    String projectName = id.substring(0, divPos);
    String nodePath = id.substring(divPos + 1).replace("~", ":");
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    if (project == null) {
        throw new DBException("Project '" + projectName + "' not found");
    }
    final DBNModel navigatorModel = DBWorkbench.getPlatform().getNavigatorModel();
    DBNNode node = null;
    DBPProject projectMeta = DBWorkbench.getPlatform().getWorkspace().getProject(project);
    if (projectMeta != null) {
        navigatorModel.ensureProjectLoaded(projectMeta);
        node = navigatorModel.getNodeByPath(new VoidProgressMonitor(), projectMeta, nodePath);
    }
    if (node == null) {
        log.error("Node " + nodePath + " not found for browse view");
        node = new DBNEmptyNode();
    }
    return node;
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBNEmptyNode(org.jkiss.dbeaver.model.navigator.DBNEmptyNode) IProject(org.eclipse.core.resources.IProject) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel)

Example 45 with DBPProject

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

the class PrefPageProjectResourceSettings method performDefaults.

@Override
protected void performDefaults() {
    resourceTable.removeAll();
    DBPWorkspace workspace = DBWorkbench.getPlatform().getWorkspace();
    for (DBPResourceHandlerDescriptor descriptor : workspace.getResourceHandlerDescriptors()) {
        if (!descriptor.isManagable()) {
            continue;
        }
        TableItem item = new TableItem(resourceTable, SWT.NONE);
        item.setData(descriptor);
        final DBPImage icon = descriptor.getIcon();
        if (icon != null) {
            item.setImage(DBeaverIcons.getImage(icon));
        }
        item.setText(0, descriptor.getName());
        DBPProject projectMeta = getProjectMeta();
        String defaultRoot = projectMeta == null ? null : descriptor.getDefaultRoot(projectMeta);
        if (defaultRoot != null) {
            item.setText(1, defaultRoot);
        }
    }
    UIUtils.packColumns(resourceTable, true);
    super.performDefaults();
}
Also used : DBPWorkspace(org.jkiss.dbeaver.model.app.DBPWorkspace) DBPResourceHandlerDescriptor(org.jkiss.dbeaver.model.app.DBPResourceHandlerDescriptor) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBPImage(org.jkiss.dbeaver.model.DBPImage)

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