Search in sources :

Example 6 with DBPDataSourceContainer

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

the class OpenHandler method openEditor.

private static void openEditor(ExecutionEvent event) throws ExecutionException, CoreException {
    List<DBPDataSourceContainer> containers = getDataSourceContainers(event);
    IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    IProject project = !containers.isEmpty() ? containers.get(0).getRegistry().getProject() : DBeaverCore.getInstance().getProjectRegistry().getActiveProject();
    checkProjectIsOpen(project);
    final DBPDataSourceContainer[] containerList = containers.toArray(new DBPDataSourceContainer[containers.size()]);
    final IFolder rootFolder = ResourceUtils.getScriptsFolder(project, true);
    final List<ResourceUtils.ResourceInfo> scriptTree = ResourceUtils.findScriptTree(rootFolder, containerList.length == 0 ? null : containerList);
    if (scriptTree.isEmpty() && containerList.length == 1) {
        // Create new script
        final IFile newScript = ResourceUtils.createNewScript(project, rootFolder, containers.isEmpty() ? null : containers.get(0));
        NavigatorHandlerObjectOpen.openResource(newScript, workbenchWindow);
    } else {
        // Show script chooser
        ScriptSelectorPanel selector = new ScriptSelectorPanel(workbenchWindow, containerList, rootFolder);
        selector.showTree(scriptTree);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder) ScriptSelectorPanel(org.jkiss.dbeaver.ui.controls.ScriptSelectorPanel)

Example 7 with DBPDataSourceContainer

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

the class OpenObjectConsoleHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    DBPDataSourceContainer ds = null;
    List<DBSObject> selectedObjects = NavigatorUtils.getSelectedObjects(HandlerUtil.getCurrentSelection(event));
    List<DBSEntity> entities = new ArrayList<>();
    for (DBSObject object : selectedObjects) {
        if (object instanceof DBSEntity) {
            entities.add((DBSEntity) object);
            ds = object.getDataSource().getContainer();
        }
    }
    DBRRunnableWithResult<String> generator = GenerateSQLContributor.SELECT_GENERATOR(entities, true);
    DBeaverUI.runInUI(workbenchWindow, generator);
    String sql = generator.getResult();
    SQLEditor editor = OpenHandler.openSQLConsole(workbenchWindow, ds, "Query", sql);
    if (editor != null) {
        editor.processSQL(false, false);
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) SQLEditor(org.jkiss.dbeaver.ui.editors.sql.SQLEditor) ArrayList(java.util.ArrayList) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 8 with DBPDataSourceContainer

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

the class DatabaseEditorInputFactory method createElement.

@Override
public IAdaptable createElement(IMemento memento) {
    // Get the node path.
    final String inputClass = memento.getString(TAG_CLASS);
    final String nodePath = memento.getString(TAG_NODE);
    final String nodeName = memento.getString(TAG_NODE_NAME);
    final String dataSourceId = memento.getString(TAG_DATA_SOURCE);
    if (nodePath == null || inputClass == null || dataSourceId == null) {
        //$NON-NLS-2$
        log.error("Corrupted memento");
        return null;
    }
    final String activePageId = memento.getString(TAG_ACTIVE_PAGE);
    final String activeFolderId = memento.getString(TAG_ACTIVE_FOLDER);
    final DBPDataSourceContainer dataSourceContainer = DataSourceRegistry.findDataSource(dataSourceId);
    if (dataSourceContainer == null) {
        //$NON-NLS-2$
        log.error("Can't find data source '" + dataSourceId + "'");
        return null;
    }
    if (lookupEditor && !dataSourceContainer.isConnected()) {
        //. for some object. Connection must be instantiated.
        return null;
    }
    final IProject project = dataSourceContainer.getRegistry().getProject();
    final DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
    navigatorModel.ensureProjectLoaded(project);
    return new DatabaseLazyEditorInput(dataSourceContainer, project, nodePath, nodeName, activePageId, activeFolderId);
}
Also used : DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) IProject(org.eclipse.core.resources.IProject) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel)

Example 9 with DBPDataSourceContainer

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

the class ResourceUtils method findChildScripts.

private static boolean findChildScripts(ResourceInfo folder, @Nullable DBPDataSourceContainer[] containers) throws CoreException {
    boolean hasScripts = false;
    for (IResource resource : ((IFolder) folder.resource).members()) {
        if (resource instanceof IFile && SCRIPT_FILE_EXTENSION.equals(resource.getFileExtension())) {
            final DBPDataSourceContainer scriptDataSource = EditorUtils.getFileDataSource((IFile) resource);
            if (containers == null || ArrayUtils.containsRef(containers, scriptDataSource)) {
                folder.children.add(new ResourceInfo((IFile) resource, scriptDataSource));
                hasScripts = true;
            }
        } else if (resource instanceof IFolder) {
            final ResourceInfo folderInfo = new ResourceInfo((IFolder) resource);
            if (findChildScripts(folderInfo, containers)) {
                folder.children.add(folderInfo);
                hasScripts = true;
            }
        }
    }
    return hasScripts;
}
Also used : IFile(org.eclipse.core.resources.IFile) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 10 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.

the class WMIConnectionPage method loadSettings.

@Override
public void loadSettings() {
    // Load values from new connection info
    DBPDataSourceContainer activeDataSource = site.getActiveDataSource();
    DBPConnectionConfiguration connectionInfo = activeDataSource.getConnectionConfiguration();
    if (connectionInfo.getHostName() == null) {
        connectionInfo.setHostName(DEFAULT_HOST);
    }
    if (connectionInfo.getDatabaseName() == null) {
        connectionInfo.setDatabaseName(DEFAULT_NAMESPACE);
    }
    if (hostText != null) {
        hostText.setText(CommonUtils.notEmpty(connectionInfo.getHostName()));
    }
    if (domainText != null) {
        domainText.setText(CommonUtils.notEmpty(connectionInfo.getServerName()));
    }
    if (usernameText != null) {
        usernameText.setText(CommonUtils.notEmpty(connectionInfo.getUserName()));
    }
    if (passwordText != null) {
        passwordText.setText(CommonUtils.notEmpty(connectionInfo.getUserPassword()));
    }
    if (namespaceCombo != null) {
        namespaceCombo.setText(CommonUtils.notEmpty(connectionInfo.getDatabaseName()));
    }
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Aggregations

DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)148 IFile (org.eclipse.core.resources.IFile)22 ArrayList (java.util.ArrayList)21 DBException (org.jkiss.dbeaver.DBException)19 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)19 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)19 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)14 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)14 InvocationTargetException (java.lang.reflect.InvocationTargetException)13 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)13 DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)12 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)12 IFolder (org.eclipse.core.resources.IFolder)11 IEditorPart (org.eclipse.ui.IEditorPart)11 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)10 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)9 GridData (org.eclipse.swt.layout.GridData)9 IDataSourceContainerProvider (org.jkiss.dbeaver.model.IDataSourceContainerProvider)9