提交 d63b0345 编写于 作者: M Marat Kalibekov

#5986 - Migrate sql server output component to text console viewer


Former-commit-id: 9fd40f7c
上级 78c413cd
......@@ -24,7 +24,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.jface.text;visibility:=reexport,
org.eclipse.ui.editors;visibility:=reexport,
org.eclipse.ui.ide,
org.eclipse.ui.workbench.texteditor;visibility:=reexport
org.eclipse.ui.workbench.texteditor;visibility:=reexport,
org.eclipse.ui.console
Export-Package: org.jkiss.dbeaver.runtime.sql,
org.jkiss.dbeaver.ui.controls,
org.jkiss.dbeaver.ui.controls.querylog,
......
......@@ -173,7 +173,7 @@ public class SQLEditor extends SQLEditorBase implements
private CTabItem activeResultsTab;
private SQLLogPanel logViewer;
private SQLEditorOutputViewer outputViewer;
private SQLEditorOutputConsoleViewer outputViewer;
private volatile QueryProcessor curQueryProcessor;
private final List<QueryProcessor> queryProcessors = new ArrayList<>();
......@@ -952,7 +952,7 @@ public class SQLEditor extends SQLEditorBase implements
// Extra views
//planView = new ExplainPlanViewer(this, resultTabs);
logViewer = new SQLLogPanel(resultTabs, this);
outputViewer = new SQLEditorOutputViewer(getSite(), resultTabs, SWT.NONE);
outputViewer = new SQLEditorOutputConsoleViewer(getSite(), resultTabs, SWT.NONE);
// Create results tab
createQueryProcessor(true, true);
......@@ -1063,7 +1063,7 @@ public class SQLEditor extends SQLEditorBase implements
}
}
if (view == outputViewer) {
if (view == outputViewer.getControl()) {
updateOutputViewerIcon(false);
outputViewer.resetNewOutput();
}
......@@ -1116,7 +1116,7 @@ public class SQLEditor extends SQLEditorBase implements
if (resultsSash.getMaximizedControl() != null) {
resultsSash.setMaximizedControl(null);
}
showExtraView(SQLEditorCommands.CMD_SQL_SHOW_OUTPUT, SQLEditorMessages.editors_sql_output, SQLEditorMessages.editors_sql_output_tip, IMG_OUTPUT, outputViewer);
showExtraView(SQLEditorCommands.CMD_SQL_SHOW_OUTPUT, SQLEditorMessages.editors_sql_output, SQLEditorMessages.editors_sql_output_tip, IMG_OUTPUT, outputViewer.getControl());
}
public void showExecutionLogPanel() {
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.editors.sql;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Font;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.TextConsoleViewer;
import org.eclipse.ui.themes.ITheme;
import org.jkiss.dbeaver.model.sql.SQLConstants;
import org.jkiss.dbeaver.ui.controls.StyledTextUtils;
public class SQLEditorOutputConsoleViewer extends TextConsoleViewer {
private MessageConsole console;
private boolean hasNewOutput;
private SQLEditorOutputConsoleViewer(IWorkbenchPartSite site, CTabFolder resultTabs, int styles, MessageConsole console) {
super(resultTabs, console);
this.console = console;
this.getText().setMargins(5, 5, 5, 5);
setEditable(false);
createContextMenu(site);
refreshStyles();
OutputStream consoleOutputStream = console.newOutputStream();
OutputStream out = new OutputStream() {
@Override
public void write(final byte[] buf, final int off, final int len) throws IOException {
consoleOutputStream.write(buf, off, len);
hasNewOutput = true;
}
@Override
public void flush() throws IOException {
consoleOutputStream.flush();
}
@Override
public void close() throws IOException {
consoleOutputStream.flush();
}
@Override
public void write(int b) throws IOException {
consoleOutputStream.write(b);
}
};
writer = new PrintWriter(out, true);
}
public SQLEditorOutputConsoleViewer(IWorkbenchPartSite site, CTabFolder resultTabs, int styles) {
this(site, resultTabs, styles, new MessageConsole("sql-output", null));
}
public boolean isDisposed() {
return this.getControl().isDisposed();
}
private PrintWriter writer;
public PrintWriter getOutputWriter() {
return writer;
}
public void scrollToEnd() {
revealEndOfDocument();
}
public boolean isVisible() {
return getControl().getVisible();
}
public void resetNewOutput() {
hasNewOutput = false;
}
public void clearOutput() {
console.clearConsole();
}
public void refreshStyles() {
ITheme currentTheme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();
Font outputFont = currentTheme.getFontRegistry().get(SQLConstants.CONFIG_FONT_OUTPUT);
if (outputFont != null) {
getTextWidget().setFont(outputFont);
}
getTextWidget().setForeground(currentTheme.getColorRegistry().get(SQLConstants.CONFIG_COLOR_TEXT));
getTextWidget().setBackground(currentTheme.getColorRegistry().get(SQLConstants.CONFIG_COLOR_BACKGROUND));
}
public StyledText getText() {
return getTextWidget();
}
public boolean isHasNewOutput() {
return hasNewOutput;
}
private void createContextMenu(IWorkbenchPartSite site) {
MenuManager menuMgr = new MenuManager();
menuMgr.addMenuListener(manager -> {
StyledTextUtils.fillDefaultStyledTextContextMenu(manager, getTextWidget());
manager.add(new Separator());
manager.add(new Action("Clear") {
@Override
public void run() {
clearOutput();
}
});
});
menuMgr.setRemoveAllWhenShown(true);
getTextWidget().setMenu(menuMgr.createContextMenu(getTextWidget()));
getTextWidget().addDisposeListener(e -> menuMgr.dispose());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册