Search in sources :

Example 36 with DBPProject

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

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

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

the class ResultSetViewer method dispose.

// //////////////////////////////////////////////////////////
// Misc
private void dispose() {
    if (themeChangeListener != null) {
        PlatformUI.getWorkbench().getThemeManager().removePropertyChangeListener(themeChangeListener);
        themeChangeListener = null;
    }
    DBWorkbench.getPlatform().getDataSourceProviderRegistry().getGlobalDataSourcePreferenceStore().removePropertyChangeListener(dataPropertyListener);
    DBWorkbench.getPlatform().getPreferenceStore().removePropertyChangeListener(dataPropertyListener);
    if (activePresentation != null) {
        activePresentation.dispose();
    }
    DBPProject project = container.getProject();
    if (project != null) {
        project.getDataSourceRegistry().removeDataSourceListener(this);
    }
    savePresentationSettings();
    clearData();
    for (ToolBarManager tb : toolbarList) {
        try {
            tb.dispose();
        } catch (Throwable e) {
            // ignore
            log.debug("Error disposing toolbar " + tb, e);
        }
    }
    toolbarList.clear();
    UIUtils.dispose(this.sizingGC);
}
Also used : DBPProject(org.jkiss.dbeaver.model.app.DBPProject)

Example 38 with DBPProject

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

the class SQLEditorHandlerOpenObjectConsole method openConsole.

void openConsole(IWorkbenchWindow workbenchWindow, DBRRunnableWithResult<String> generator, SQLNavigatorContext navigatorContext, String title, boolean doRun, ISelection currentSelection) throws Exception {
    UIUtils.runInUI(workbenchWindow, generator);
    String sql = CommonUtils.notEmpty(generator.getResult());
    DBPProject project = navigatorContext.getProject();
    SQLEditorHandlerOpenEditor.checkProjectIsOpen(project);
    IFolder folder = SQLEditorHandlerOpenEditor.getCurrentScriptFolder(currentSelection);
    IFile scriptFile = SQLEditorUtils.createNewScript(project, folder, navigatorContext);
    FileEditorInput sqlInput = new FileEditorInput(scriptFile);
    SQLEditor editor = (SQLEditor) workbenchWindow.getActivePage().openEditor(sqlInput, SQLEditor.class.getName());
    if (editor != null) {
        editor.getDocument().set(sql);
        AbstractJob execJob = new AbstractJob("Execute SQL in console") {

            @Override
            protected IStatus run(DBRProgressMonitor monitor) {
                // So let's give it a chance and wait for 10 seconds
                for (int i = 0; i < 100; i++) {
                    if (editor.getExecutionContext() != null) {
                        break;
                    }
                    RuntimeUtils.pause(100);
                }
                return Status.OK_STATUS;
            }
        };
        if (doRun) {
            execJob.addJobChangeListener(new JobChangeAdapter() {

                @Override
                public void done(IJobChangeEvent event) {
                    UIUtils.syncExec(() -> editor.processSQL(false, false));
                }
            });
        }
        execJob.schedule();
    }
}
Also used : AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) SQLEditor(org.jkiss.dbeaver.ui.editors.sql.SQLEditor) IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) IFolder(org.eclipse.core.resources.IFolder)

Example 39 with DBPProject

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

the class SQLEditorHandlerOpenEditor method openNewEditor.

public static IFile openNewEditor(@NotNull SQLNavigatorContext editorContext, ISelection selection) throws CoreException {
    DBPProject project = editorContext.getProject();
    checkProjectIsOpen(project);
    IFolder folder = getCurrentScriptFolder(selection);
    IFile scriptFile = SQLEditorUtils.createNewScript(project, folder, editorContext);
    openResource(scriptFile, editorContext);
    return scriptFile;
}
Also used : IFile(org.eclipse.core.resources.IFile) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) IFolder(org.eclipse.core.resources.IFolder)

Example 40 with DBPProject

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

the class SQLEditorHandlerOpenEditor method openRecentScript.

public static void openRecentScript(@NotNull IWorkbenchWindow workbenchWindow, @NotNull SQLNavigatorContext editorContext, @Nullable IFolder scriptFolder) throws CoreException {
    final DBPProject project = editorContext.getProject();
    checkProjectIsOpen(project);
    SQLEditorUtils.ResourceInfo res = SQLEditorUtils.findRecentScript(project, editorContext);
    if (res != null) {
        openResourceEditor(workbenchWindow, res, editorContext);
    } else {
        IFile scriptFile = SQLEditorUtils.createNewScript(project, scriptFolder, editorContext);
        openResource(scriptFile, editorContext);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) SQLEditorUtils(org.jkiss.dbeaver.ui.editors.sql.SQLEditorUtils)

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