use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by serge-rider.
the class ExecuteHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
SQLEditor editor = RuntimeUtils.getObjectAdapter(HandlerUtil.getActiveEditor(event), SQLEditor.class);
if (editor == null) {
log.error("No active SQL editor found");
return null;
}
String actionId = event.getCommand().getId();
switch(actionId) {
case CoreCommands.CMD_EXECUTE_STATEMENT:
editor.processSQL(false, false);
break;
case CoreCommands.CMD_EXECUTE_STATEMENT_NEW:
editor.processSQL(true, false);
break;
case CoreCommands.CMD_EXECUTE_SCRIPT:
editor.processSQL(false, true);
break;
case CoreCommands.CMD_EXECUTE_SCRIPT_NEW:
editor.processSQL(true, true);
break;
case CoreCommands.CMD_EXECUTE_ROW_COUNT:
editor.processSQL(false, false, new SQLQueryTransformerCount());
break;
case CoreCommands.CMD_EXECUTE_EXPRESSION:
editor.processSQL(false, false, new SQLQueryTransformerExpression());
break;
case CoreCommands.CMD_EXPLAIN_PLAN:
editor.explainQueryPlan();
break;
default:
log.error("Unsupported SQL editor command: " + actionId);
break;
}
return null;
}
use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by dbeaver.
the class SQLCommandInclude method handleCommand.
@Override
public boolean handleCommand(SQLControlCommand command, final SQLScriptContext scriptContext) throws DBException {
String fileName = command.getParameter();
if (CommonUtils.isEmpty(fileName)) {
throw new DBException("Empty input file");
}
fileName = GeneralUtils.replaceVariables(fileName, new ScriptVariablesResolver(scriptContext)).trim();
fileName = DBUtils.getUnQuotedIdentifier(scriptContext.getExecutionContext().getDataSource(), fileName);
File curFile = scriptContext.getSourceFile();
File incFile = curFile == null ? new File(fileName) : new File(curFile.getParent(), fileName);
if (!incFile.exists()) {
incFile = new File(fileName);
}
if (!incFile.exists()) {
throw new DBException("File '" + fileName + "' not found");
}
final String fileContents;
try (InputStream is = new FileInputStream(incFile)) {
Reader reader = new InputStreamReader(is, IDEEncoding.getResourceEncoding());
fileContents = IOUtils.readToString(reader);
} catch (IOException e) {
throw new DBException("IO error reading file '" + fileName + "'", e);
}
final File finalIncFile = incFile;
final boolean[] statusFlag = new boolean[1];
DBeaverUI.syncExec(new Runnable() {
@Override
public void run() {
final IWorkbenchWindow workbenchWindow = DBeaverUI.getActiveWorkbenchWindow();
final IncludeEditorInput input = new IncludeEditorInput(finalIncFile, fileContents);
SQLEditor sqlEditor = OpenHandler.openSQLConsole(workbenchWindow, scriptContext.getExecutionContext().getDataSource().getContainer(), input);
final IncludeScriptListener scriptListener = new IncludeScriptListener(workbenchWindow, sqlEditor, statusFlag);
sqlEditor.processSQL(false, true, null, scriptListener);
}
});
// Wait until script finished
while (!statusFlag[0]) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
break;
}
}
return true;
}
use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by dbeaver.
the class DBeaverStackRenderer method populateFileMenu.
private void populateFileMenu(@NotNull final Menu menu, @NotNull final IWorkbenchPart workbenchPart, @Nullable final IFile inputFile, @NotNull final File file) {
new MenuItem(menu, SWT.SEPARATOR);
{
MenuItem menuItemOpenFolder = new MenuItem(menu, SWT.NONE);
menuItemOpenFolder.setText("Open Folder in Explorer");
menuItemOpenFolder.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (file.getParentFile().isDirectory()) {
UIUtils.launchProgram(file.getParentFile().getAbsolutePath());
}
}
});
}
{
MenuItem menuItemOthers = new MenuItem(menu, SWT.NONE);
menuItemOthers.setText("Copy File Path");
menuItemOthers.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String filePath = file.getAbsolutePath();
UIUtils.setClipboardContents(Display.getCurrent(), TextTransfer.getInstance(), filePath);
}
});
}
if (inputFile != null) {
MenuItem menuItemOthers = new MenuItem(menu, SWT.NONE);
String renameText = "Rename File";
if (workbenchPart instanceof SQLEditor) {
renameText += "\t" + ActionUtils.findCommandDescription(CoreCommands.CMD_SQL_RENAME, workbenchPart.getSite(), true);
}
menuItemOthers.setText(renameText);
menuItemOthers.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
RenameHandler.renameFile(workbenchPart, inputFile, "file");
}
});
}
}
use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by serge-rider.
the class SQLEditorHandlerToggleEditorLayout method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
SQLEditor editor = RuntimeUtils.getObjectAdapter(HandlerUtil.getActiveEditor(event), SQLEditor.class);
if (editor != null) {
String curPresentationName = DBWorkbench.getPlatform().getPreferenceStore().getString(SQLPreferenceConstants.RESULT_SET_ORIENTATION);
SQLEditor.ResultSetOrientation curOrientation = CommonUtils.valueOf(SQLEditor.ResultSetOrientation.class, curPresentationName, SQLEditor.ResultSetOrientation.HORIZONTAL);
if (curOrientation == SQLEditor.ResultSetOrientation.HORIZONTAL) {
curOrientation = SQLEditor.ResultSetOrientation.VERTICAL;
} else {
curOrientation = SQLEditor.ResultSetOrientation.HORIZONTAL;
}
DBWorkbench.getPlatform().getPreferenceStore().setValue(SQLPreferenceConstants.RESULT_SET_ORIENTATION, curOrientation.name());
try {
editor.getActivePreferenceStore().save();
} catch (IOException e) {
log.error("Error saving editor preferences", e);
}
}
return null;
}
use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor 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();
}
}
Aggregations