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);
}
}
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;
}
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);
}
}
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();
}
}
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();
}
Aggregations