1 package net.sourceforge.phpdt.sql.view;
3 import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
5 import org.eclipse.jface.action.Action;
6 import org.eclipse.jface.action.IToolBarManager;
7 import org.eclipse.swt.SWT;
8 import org.eclipse.swt.custom.StyleRange;
9 import org.eclipse.swt.custom.StyledText;
10 import org.eclipse.swt.custom.StyledTextContent;
11 import org.eclipse.swt.events.DisposeEvent;
12 import org.eclipse.swt.events.DisposeListener;
13 import org.eclipse.swt.graphics.Color;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.ui.IActionBars;
16 import org.eclipse.ui.IWorkbenchActionConstants;
17 import org.eclipse.ui.part.ViewPart;
19 public class SQLLogView extends ViewPart implements LogConstants {
20 private Color QUERY_COLOR;
21 private Color WARNING_COLOR;
22 private Color DEFAULT_COLOR;
23 private Color ERROR_COLOR;
24 private Color RESULTS_COLOR;
25 private StyledText widget;
26 private static SQLLogView instance = null;
27 private static final String newLine = "\n";
28 public static SQLLogView getInstance() {
32 public void createPartControl(Composite parent) {
34 QUERY_COLOR = new Color(parent.getShell().getDisplay(), 0, 255, 0);
35 ERROR_COLOR = new Color(parent.getShell().getDisplay(), 255, 0, 0);
36 RESULTS_COLOR = new Color(parent.getShell().getDisplay(), 0, 0, 255);
37 DEFAULT_COLOR = new Color(parent.getShell().getDisplay(), 0, 0, 0);
38 WARNING_COLOR = new Color(parent.getShell().getDisplay(), 255, 127, 0);
39 widget = new StyledText(parent, SWT.H_SCROLL | SWT.V_SCROLL);
40 IActionBars bars = this.getViewSite().getActionBars();
41 bars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, copyAction);
42 bars.setGlobalActionHandler(IWorkbenchActionConstants.SELECT_ALL, selectAllAction);
44 IToolBarManager toolBar = getViewSite().getActionBars().getToolBarManager();
45 clearAction.setImageDescriptor(PHPEclipseSQLPlugin.getImageDescriptor("clear.gif"));
46 clearAction.setToolTipText("Clear Log");
47 toolBar.add(clearAction);
49 widget.setEditable(false);
51 widget.addDisposeListener(new DisposeListener() {
52 public void widgetDisposed(DisposeEvent e) {
58 public void addText(int style, String text) {
59 text = text + newLine;
60 int start = widget.getText().length();
61 StyleRange styleRange = new StyleRange();
62 styleRange.start = start;
63 styleRange.length = text.length();
65 styleRange.foreground = QUERY_COLOR;
66 } else if (style == ERROR) {
67 styleRange.foreground = ERROR_COLOR;
68 } else if (style == RESULTS) {
69 styleRange.foreground = RESULTS_COLOR;
70 } else if (style == WARNING) {
71 styleRange.foreground = WARNING_COLOR;
73 styleRange.foreground = DEFAULT_COLOR;
76 widget.setStyleRange(styleRange);
77 revealEndOfDocument();
80 protected void revealEndOfDocument() {
81 StyledTextContent doc= widget.getContent();
82 int docLength= doc.getCharCount();
84 widget.setCaretOffset(docLength);
85 widget.showSelection();
89 public void setFocus() {
93 private Action copyAction = new Action() {
98 private Action selectAllAction = new Action() {
103 private Action clearAction = new Action() {