1 package com.quantum.view;
3 import com.quantum.Messages;
4 import com.quantum.QuantumPlugin;
6 import org.eclipse.jface.action.Action;
7 import org.eclipse.jface.action.IToolBarManager;
8 import org.eclipse.swt.SWT;
9 import org.eclipse.swt.custom.StyleRange;
10 import org.eclipse.swt.custom.StyledText;
11 import org.eclipse.swt.custom.StyledTextContent;
12 import org.eclipse.swt.events.DisposeEvent;
13 import org.eclipse.swt.events.DisposeListener;
14 import org.eclipse.swt.graphics.Color;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.ui.IActionBars;
17 import org.eclipse.ui.IWorkbenchActionConstants;
18 import org.eclipse.ui.part.ViewPart;
20 public class SQLLogView extends ViewPart implements LogConstants {
21 private Color QUERY_COLOR;
22 private Color WARNING_COLOR;
23 private Color DEFAULT_COLOR;
24 private Color ERROR_COLOR;
25 private Color RESULTS_COLOR;
26 private StyledText widget;
27 private static SQLLogView instance = null;
28 private static final String newLine = "\n"; //$NON-NLS-1$
29 public static SQLLogView getInstance() {
33 public void createPartControl(Composite parent) {
35 QUERY_COLOR = new Color(parent.getShell().getDisplay(), 0, 255, 0);
36 ERROR_COLOR = new Color(parent.getShell().getDisplay(), 255, 0, 0);
37 RESULTS_COLOR = new Color(parent.getShell().getDisplay(), 0, 0, 255);
38 DEFAULT_COLOR = new Color(parent.getShell().getDisplay(), 0, 0, 0);
39 WARNING_COLOR = new Color(parent.getShell().getDisplay(), 255, 127, 0);
40 widget = new StyledText(parent, SWT.H_SCROLL | SWT.V_SCROLL);
41 IActionBars bars = this.getViewSite().getActionBars();
42 bars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, copyAction);
43 bars.setGlobalActionHandler(IWorkbenchActionConstants.SELECT_ALL, selectAllAction);
45 IToolBarManager toolBar = getViewSite().getActionBars().getToolBarManager();
46 clearAction.setImageDescriptor(QuantumPlugin.getImageDescriptor("clear.gif")); //$NON-NLS-1$
47 clearAction.setToolTipText(Messages.getString("SQLLogView.ClearLog")); //$NON-NLS-1$
48 toolBar.add(clearAction);
50 widget.setEditable(false);
52 widget.addDisposeListener(new DisposeListener() {
53 public void widgetDisposed(DisposeEvent e) {
59 public void addText(int style, String text) {
60 text = text + newLine;
61 int start = widget.getText().length();
62 StyleRange styleRange = new StyleRange();
63 styleRange.start = start;
64 styleRange.length = text.length();
66 styleRange.foreground = QUERY_COLOR;
67 } else if (style == ERROR) {
68 styleRange.foreground = ERROR_COLOR;
69 } else if (style == RESULTS) {
70 styleRange.foreground = RESULTS_COLOR;
71 } else if (style == WARNING) {
72 styleRange.foreground = WARNING_COLOR;
74 styleRange.foreground = DEFAULT_COLOR;
77 widget.setStyleRange(styleRange);
78 revealEndOfDocument();
81 protected void revealEndOfDocument() {
82 StyledTextContent doc= widget.getContent();
83 int docLength= doc.getCharCount();
85 widget.setCaretOffset(docLength);
86 widget.showSelection();
90 public void setFocus() {
94 private Action copyAction = new Action() {
99 private Action selectAllAction = new Action() {
104 private Action clearAction = new Action() {
106 widget.setText(""); //$NON-NLS-1$