Search in sources :

Example 1 with DBPProject

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

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 2 with DBPProject

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

the class ProjectHandlerImpl method openResource.

@Override
public void openResource(@NotNull IResource resource) {
    DBPProject project = DBWorkbench.getPlatform().getWorkspace().getProject((IProject) resource);
    if (project == null) {
        DBWorkbench.getPlatformUI().showError("No project", "Can't get project metadata for resource " + resource.getName());
        return;
    }
    MultiPageWizardDialog dialog = new MultiPageWizardDialog(UIUtils.getActiveWorkbenchWindow(), new EditProjectWizard(project));
    dialog.open();
}
Also used : EditProjectWizard(org.jkiss.dbeaver.ui.project.EditProjectWizard) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) MultiPageWizardDialog(org.jkiss.dbeaver.ui.dialogs.MultiPageWizardDialog)

Example 3 with DBPProject

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

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 4 with DBPProject

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

the class SampleDatabaseHandler method execute.

@Override
public Object execute(ExecutionEvent event) {
    DBPProject activeProject = DBWorkbench.getPlatform().getWorkspace().getActiveProject();
    if (activeProject == null || !activeProject.isRegistryLoaded()) {
        // No active project
        return null;
    }
    DBPDataSourceRegistry registry = activeProject.getDataSourceRegistry();
    Shell shell = UIUtils.getActiveWorkbenchShell();
    if (WorkbenchInitializerCreateSampleDatabase.isSampleDatabaseExists(registry)) {
        UIUtils.showMessageBox(shell, SampleDatabaseMessages.dialog_already_created_title, SampleDatabaseMessages.dialog_already_created_description, SWT.ICON_WARNING);
        return null;
    }
    if (WorkbenchInitializerCreateSampleDatabase.showCreateSampleDatabasePrompt(shell)) {
        WorkbenchInitializerCreateSampleDatabase.createSampleDatabase(registry);
    }
    return null;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)

Example 5 with DBPProject

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

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)

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