Search in sources :

Example 26 with DBPProject

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

the class ProjectHandlerImpl method getFeatures.

@Override
public int getFeatures(IResource resource) {
    int features = FEATURE_CREATE_FOLDER | FEATURE_RENAME;
    DBPProject activeProject = DBWorkbench.getPlatform().getWorkspace().getActiveProject();
    if (activeProject == null || resource != activeProject.getEclipseProject()) {
        features |= FEATURE_DELETE;
    }
    return features;
}
Also used : DBPProject(org.jkiss.dbeaver.model.app.DBPProject)

Example 27 with DBPProject

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

the class BookmarksHandlerImpl method createBookmark.

/*
    static DBNDatabaseNode getTargetBookmarkNode(DBRProgressMonitor monitor, DBNBookmark bookmark)
    {
        IFile resource = (IFile) bookmark.getResource();
        final DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(resource.getProject());
        if (projectNode != null) {
            BookmarkStorage storage = bookmark.getStorage();
            final DBPDataSourceContainer dataSourceContainer = projectNode.getDatabases().getDataSourceRegistry().getDataSource(storage.getDataSourceId());
            if (dataSourceContainer != null) {
                final DBNDataSource dsNode = (DBNDataSource) DBNUtils.getNodeByObject(dataSourceContainer);
                if (dsNode != null) {
                    DBNDatabaseNode[] result = new DBNDatabaseNode[1];
                    dsNode.initializeNode(monitor, status -> {
                        if (status.isOK()) {
                            try {
                                BookmarkNodeLoader nodeLoader = new BookmarkNodeLoader(dsNode, storage, resource);
                                nodeLoader.run(monitor);
                                result[0] = nodeLoader.databaseNode;
                            } catch (Exception e) {
                                // Doesn't matter
                            }
                        }
                    });
                    return result[0];
                }
            }
        }
        return null;
    }
*/
public static void createBookmark(final DBNDatabaseNode node, String title, IFolder folder) throws DBException {
    if (folder == null) {
        final DBPProject project = node.getOwnerProject();
        if (project != null) {
            folder = getBookmarksFolder(project, true);
        }
    }
    if (folder == null) {
        throw new DBException("Can't detect folder for bookmark");
    }
    ContentUtils.checkFolderExists(folder);
    IFile file = ContentUtils.getUniqueFile(folder, CommonUtils.escapeFileName(title), BOOKMARK_EXT);
    updateBookmark(node, title, file);
}
Also used : DBException(org.jkiss.dbeaver.DBException) IFile(org.eclipse.core.resources.IFile) DBPProject(org.jkiss.dbeaver.model.app.DBPProject)

Example 28 with DBPProject

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

the class ProjectExportWizardPage method createControl.

@Override
public void createControl(Composite parent) {
    String outDir = DBWorkbench.getPlatform().getPreferenceStore().getString(PREF_PROJECTS_EXPORT_OUT_DIR);
    if (CommonUtils.isEmpty(outDir)) {
        outDir = RuntimeUtils.getUserHomeDir().getAbsolutePath();
    }
    Set<DBPProject> projectList = new LinkedHashSet<>();
    final ISelection selection = UIUtils.getActiveWorkbenchWindow().getActivePage().getSelection();
    if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
        for (Iterator<?> iter = ((IStructuredSelection) selection).iterator(); iter.hasNext(); ) {
            Object element = iter.next();
            IResource resource = RuntimeUtils.getObjectAdapter(element, IResource.class);
            if (resource != null) {
                projectList.add(DBWorkbench.getPlatform().getWorkspace().getProject(resource.getProject()));
            }
        }
    }
    if (projectList.isEmpty()) {
        DBPProject activeProject = DBWorkbench.getPlatform().getWorkspace().getActiveProject();
        if (activeProject != null) {
            projectList.add(activeProject);
        }
    }
    Composite placeholder = UIUtils.createPlaceholder(parent, 1);
    placeholder.setLayout(new GridLayout(1, false));
    // Project list
    projectsTable = new Table(placeholder, SWT.MULTI | SWT.CHECK | SWT.BORDER);
    GridData gd = new GridData(GridData.FILL_BOTH);
    projectsTable.setLayoutData(gd);
    projectsTable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updateState();
        }
    });
    for (DBPProject project : DBWorkbench.getPlatform().getWorkspace().getProjects()) {
        final TableItem item = new TableItem(projectsTable, SWT.NONE);
        item.setImage(DBeaverIcons.getImage(DBIcon.PROJECT));
        item.setText(project.getName());
        item.setData(project);
        if (projectList.contains(project)) {
            item.setChecked(true);
        }
    }
    final Composite fileNameGroup = UIUtils.createPlaceholder(placeholder, 2);
    fileNameGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // $NON-NLS-2$
    fileNameText = UIUtils.createLabelText(fileNameGroup, CoreMessages.dialog_project_export_wizard_start_label_output_file, null);
    fileNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fileNameText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            if (!CommonUtils.equalObjects(fileNameText.getText(), getArchiveFileName(getProjectsToExport()))) {
                fileNameEdited = true;
            }
        }
    });
    // Output folder
    Composite generalSettings = UIUtils.createPlaceholder(placeholder, 3);
    generalSettings.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    {
        UIUtils.createControlLabel(generalSettings, CoreMessages.dialog_project_export_wizard_start_label_directory);
        directoryText = new Text(generalSettings, SWT.BORDER);
        directoryText.setText(outDir);
        directoryText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        directoryText.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                updateState();
            }
        });
        Button openFolder = new Button(generalSettings, SWT.PUSH);
        openFolder.setImage(DBeaverIcons.getImage(DBIcon.TREE_FOLDER));
        openFolder.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.NONE);
                dialog.setMessage(CoreMessages.dialog_project_export_wizard_start_dialog_directory_message);
                dialog.setText(CoreMessages.dialog_project_export_wizard_start_dialog_directory_text);
                String directory = directoryText.getText();
                if (!CommonUtils.isEmpty(directory)) {
                    dialog.setFilterPath(directory);
                }
                directory = dialog.open();
                if (directory != null) {
                    directoryText.setText(directory);
                }
            }
        });
    }
    exportDriverCheck = UIUtils.createCheckbox(placeholder, CoreMessages.dialog_project_export_wizard_start_checkbox_libraries, false);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalSpan = 3;
    exportDriverCheck.setLayoutData(gd);
    setControl(placeholder);
    updateState();
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ISelection(org.eclipse.jface.viewers.ISelection) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IResource(org.eclipse.core.resources.IResource)

Example 29 with DBPProject

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

the class ConnectionPageDriver method createControl.

@Override
public void createControl(Composite parent) {
    Composite placeholder = UIUtils.createComposite(parent, 1);
    {
        driverSelectViewer = new DriverSelectViewer(placeholder, this, wizard.getAvailableProvides(), true);
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.heightHint = 200;
        driverSelectViewer.getControl().setLayoutData(gd);
    }
    setControl(placeholder);
    Composite controlsGroup = UIUtils.createComposite(placeholder, 5);
    controlsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // Navigator view preset
    {
        Composite presetComposite = new Composite(controlsGroup, SWT.NONE);
        presetComposite.setLayout(new RowLayout());
        new Label(presetComposite, SWT.NONE).setImage(DBeaverIcons.getImage(UIIcon.CONFIGURATION));
        new Label(presetComposite, SWT.NONE).setText("Connection view:  ");
        for (DataSourceNavigatorSettings.Preset p : DataSourceNavigatorSettings.PRESETS.values()) {
            if (p != DataSourceNavigatorSettings.PRESET_CUSTOM) {
                Button pButton = new Button(presetComposite, SWT.RADIO);
                pButton.setText(p.getName());
                pButton.setToolTipText(p.getDescription());
                if (p == navigatorPreset) {
                    pButton.setSelection(true);
                }
                pButton.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        if (pButton.getSelection()) {
                            navigatorPreset = p;
                            DBeaverActivator.getInstance().getPreferences().setValue(DEFAULT_NAVIGATOR_SETTINGS_RESET, navigatorPreset.getId());
                        }
                    }
                });
            }
        }
    }
    {
        // Spacer
        new Label(controlsGroup, SWT.NONE).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    }
    {
        // Sorter
        Composite orderGroup = new Composite(controlsGroup, SWT.NONE);
        orderGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
        orderGroup.setLayout(new RowLayout());
        new Label(orderGroup, SWT.NONE).setImage(DBeaverIcons.getImage(UIIcon.SORT));
        new Label(orderGroup, SWT.NONE).setText("Sort by: ");
        for (DriverSelectViewer.OrderBy ob : DriverSelectViewer.OrderBy.values()) {
            Button obScoreButton = new Button(orderGroup, SWT.RADIO);
            obScoreButton.setText(ob.getLabel());
            obScoreButton.setToolTipText(ob.getDescription());
            obScoreButton.setData(ob);
            if (ob == driverSelectViewer.getOrderBy()) {
                obScoreButton.setSelection(true);
            }
            obScoreButton.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    driverSelectViewer.setOrderBy((DriverSelectViewer.OrderBy) obScoreButton.getData());
                }
            });
        }
    }
    {
        // Spacer
        new Label(controlsGroup, SWT.NONE).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    }
    final List<DBPProject> projects = DBWorkbench.getPlatform().getWorkspace().getProjects();
    if (projects.size() == 1) {
        if (connectionProject == null) {
            connectionProject = projects.get(0);
        }
    } else if (projects.size() > 1) {
        Composite projectGroup = UIUtils.createComposite(controlsGroup, 3);
        projectGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
        new Label(projectGroup, SWT.NONE).setImage(DBeaverIcons.getImage(DBIcon.PROJECT));
        UIUtils.createControlLabel(projectGroup, CoreMessages.dialog_connection_driver_project);
        final Combo projectCombo = new Combo(projectGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
        projectCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        for (DBPProject project : projects) {
            projectCombo.add(project.getName());
        }
        if (connectionProject == null) {
            projectCombo.select(0);
            connectionProject = projects.get(0);
        } else {
            projectCombo.setText(connectionProject.getName());
        }
        projectCombo.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                connectionProject = projects.get(projectCombo.getSelectionIndex());
            }
        });
        if (projects.size() < 2) {
        // projectCombo.setEnabled(false);
        }
    } else {
        setErrorMessage("You need to create a project first");
    }
    UIUtils.setHelp(placeholder, IHelpContextIds.CTX_CON_WIZARD_DRIVER);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) Combo(org.eclipse.swt.widgets.Combo) DriverSelectViewer(org.jkiss.dbeaver.ui.dialogs.driver.DriverSelectViewer) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 30 with DBPProject

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

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)

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