use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by serge-rider.
the class DBeaverStackRenderer method populateFileMenu.
private void populateFileMenu(@NotNull final Menu menu, @NotNull final IWorkbenchPart workbenchPart, @Nullable final IFile inputFile, @NotNull final File file) {
IWorkbenchPage activePage = workbenchPart.getSite().getWorkbenchWindow().getActivePage();
if (activePage.getActiveEditor() != workbenchPart) {
activePage.activate(workbenchPart);
}
new MenuItem(menu, SWT.SEPARATOR);
{
MenuItem menuItemOpenFolder = new MenuItem(menu, SWT.NONE);
menuItemOpenFolder.setText(CoreMessages.editor_file_open_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(CoreMessages.editor_file_copy_path);
menuItemOthers.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String filePath = file.getAbsolutePath();
UIUtils.setClipboardContents(Display.getCurrent(), TextTransfer.getInstance(), filePath);
}
});
}
{
{
String deleteText = ActionUtils.findCommandName(SQLEditorCommands.CMD_SQL_DELETE_THIS_SCRIPT);
// $NON-NLS-1$
String shortcut = ActionUtils.findCommandDescription(SQLEditorCommands.CMD_SQL_DELETE_THIS_SCRIPT, workbenchPart.getSite(), true);
if (shortcut != null) {
deleteText += "\t" + shortcut;
}
MenuItem menuItemDelete = new MenuItem(menu, SWT.NONE);
menuItemDelete.setText(deleteText);
menuItemDelete.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ActionUtils.runCommand(SQLEditorCommands.CMD_SQL_DELETE_THIS_SCRIPT, workbenchPart.getSite());
}
});
}
if (inputFile != null) {
MenuItem menuItemOthers = new MenuItem(menu, SWT.NONE);
String renameText = CoreMessages.editor_file_rename;
if (workbenchPart instanceof SQLEditor) {
// $NON-NLS-1$
renameText += "\t" + ActionUtils.findCommandDescription(SQLEditorCommands.CMD_SQL_RENAME, workbenchPart.getSite(), true);
}
menuItemOthers.setText(renameText);
menuItemOthers.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// $NON-NLS-1$
SQLEditorHandlerRenameFile.renameFile(workbenchPart, inputFile, "file");
}
});
}
}
}
use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by serge-rider.
the class SQLEditorHandlerMaximizeResultsPanel method updateElement.
@Override
public void updateElement(UIElement element, Map parameters) {
IWorkbenchWindow workbenchWindow = element.getServiceLocator().getService(IWorkbenchWindow.class);
if (workbenchWindow == null || workbenchWindow.getActivePage() == null) {
return;
}
IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor();
if (activeEditor == null) {
return;
}
SQLEditor editor = RuntimeUtils.getObjectAdapter(activeEditor, SQLEditor.class);
if (editor != null) {
if (editor.hasMaximizedControl()) {
element.setText(SQLEditorMessages.action_menu_sqleditor_restoreResultsPanel);
} else {
element.setText(SQLEditorMessages.action_menu_sqleditor_maximizeResultsPanel);
}
}
}
use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by serge-rider.
the class OpenLinkInWindowHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
SQLEditor editor = RuntimeUtils.getObjectAdapter(HandlerUtil.getActiveEditor(event), SQLEditor.class);
if (editor == null) {
DBWorkbench.getPlatformUI().showError(TITLE, "No suitable editor was found for SQL");
return null;
}
ISelection selection = editor.getSelectionProvider().getSelection();
if (isSelectedTextNullOrEmpty(selection)) {
DBWorkbench.getPlatformUI().showError(TITLE, "No text was selected");
return null;
}
TextSelection textSelection = (TextSelection) selection;
String googleLink = SEARCH_WEB_ADDRESS_PREFIX + textSelection.getText().replaceAll(" ", "%20").trim();
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
UIUtils.launchProgram(googleLink);
} else {
DBWorkbench.getPlatformUI().showError(TITLE, "Desktop is not supported.");
}
return null;
}
use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by serge-rider.
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, 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];
UIUtils.syncExec(() -> {
try {
final IWorkbenchWindow workbenchWindow = UIUtils.getActiveWorkbenchWindow();
final IncludeEditorInput input = new IncludeEditorInput(finalIncFile, fileContents);
SQLEditor sqlEditor = SQLEditorHandlerOpenEditor.openSQLConsole(workbenchWindow, new SQLNavigatorContext(scriptContext.getExecutionContext()), input);
final IncludeScriptListener scriptListener = new IncludeScriptListener(workbenchWindow, sqlEditor, statusFlag);
boolean execResult = sqlEditor.processSQL(false, true, null, scriptListener);
if (!execResult) {
statusFlag[0] = true;
}
} catch (Throwable e) {
log.error(e);
statusFlag[0] = true;
}
});
// 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 serge-rider.
the class WorkbenchContextListener method activatePartContexts.
void activatePartContexts(IWorkbenchPart part) {
IContextService contextService = PlatformUI.getWorkbench().getService(IContextService.class);
if (contextService == null) {
return;
}
try {
contextService.deferUpdates(true);
if (part instanceof INavigatorModelView) {
// We check for instanceof (do not use adapter) because otherwise it become active
// for all entity editor and clashes with SQL editor and other complex stuff.
// if (activationNavigator != null) {
// //log.debug("Double activation of navigator context");
// contextService.deactivateContext(activationNavigator);
// }
// activationNavigator = contextService.activateContext(INavigatorModelView.NAVIGATOR_CONTEXT_ID);
}
if (part instanceof SQLEditorBase || part.getAdapter(SQLEditorBase.class) != null) {
if (activationSQL != null) {
// log.debug("Double activation of SQL context");
contextService.deactivateContext(activationSQL);
}
activationSQL = contextService.activateContext(SQLEditorContributions.SQL_EDITOR_CONTEXT);
}
if (part.getAdapter(ResultSetViewer.class) != null || (part instanceof SQLEditor) || (part instanceof EntityEditor && ((EntityEditor) part).getDatabaseObject() instanceof DBSDataContainer)) {
if (activationResults != null) {
contextService.deactivateContext(activationResults);
}
activationResults = contextService.activateContext(RESULTS_CONTEXT_ID);
}
// Refresh auto-commit element state (#3315)
// Refresh OpenSeparateConnection
ActionUtils.fireCommandRefresh(ConnectionCommands.CMD_TOGGLE_AUTOCOMMIT, SQLEditorCommands.CMD_TOGGLE_SEPARATE_CONNECTION);
} finally {
contextService.deferUpdates(false);
}
}
Aggregations