Search in sources :

Example 66 with DBPProject

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

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)

Example 67 with DBPProject

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

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

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

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

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

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

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

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