1 package net.sourceforge.phpdt.sql.view;
3 /**********************************************************************
4 Copyright (c) 2000, 2002 IBM Corp. and others.
5 All rights reserved. This program and the accompanying materials
6 are made available under the terms of the Common Public License v1.0
7 which accompanies this distribution, and is available at
8 http://www.eclipse.org/legal/cpl-v10.html
11 IBM Corporation - Initial implementation
12 Klaus Hartlage - www.eclipseproject.de
13 **********************************************************************/
14 import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.runtime.Status;
18 import org.eclipse.jface.action.Action;
19 import org.eclipse.jface.resource.JFaceResources;
20 import org.eclipse.jface.text.BadLocationException;
21 import org.eclipse.jface.text.Document;
22 import org.eclipse.jface.text.TextViewer;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.custom.StyledText;
25 import org.eclipse.swt.layout.GridData;
26 import org.eclipse.swt.widgets.Composite;
27 import org.eclipse.ui.IActionBars;
28 import org.eclipse.ui.IWorkbenchActionConstants;
29 import org.eclipse.ui.IWorkbenchPage;
30 import org.eclipse.ui.PartInitException;
31 import org.eclipse.ui.PlatformUI;
32 import org.eclipse.ui.part.ViewPart;
35 * The PHPSourceConsole is used to display the output from the PHP SQL wizards
38 public class PHPSourceConsole extends ViewPart {
40 public static final String CONSOLE_ID =
41 "net.sourceforge.phpdt.sql.view.phpsourceconsoleview";
43 private TextViewer viewer = null;
44 private Document document = null;
49 public PHPSourceConsole() {
53 * Insert the method's description here.
54 * @see ViewPart#createPartControl
56 public void createPartControl(Composite parent) {
57 viewer = new TextViewer(parent, SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL);
58 GridData viewerData = new GridData(GridData.FILL_BOTH);
59 viewer.getControl().setLayoutData(viewerData);
60 viewer.setEditable(false);
62 StyledText widget = viewer.getTextWidget();
64 JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT));
65 Action cutAction = new Action() {
67 viewer.getTextWidget().cut();
70 Action copyAction = new Action() {
72 viewer.getTextWidget().copy();
75 Action pasteAction = new Action() {
77 viewer.getTextWidget().paste();
81 IActionBars bars = this.getViewSite().getActionBars();
82 bars.setGlobalActionHandler(IWorkbenchActionConstants.CUT, cutAction);
83 bars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, copyAction);
84 bars.setGlobalActionHandler(IWorkbenchActionConstants.PASTE, pasteAction);
88 * Insert the method's description here.
89 * @see ViewPart#setFocus
91 public void setFocus() {
95 * Set the text for the viewer
97 private void setOutputText(String text) {
98 document = new Document(text);
99 viewer.setDocument(document);
102 private void appendOutputText(String text) {
104 if (document == null) {
105 document = new Document(text);
106 viewer.setDocument(document);
108 document.replace(document.getLength(), 0, text);
109 } catch (BadLocationException e) {
111 // viewer.setDocument(document);
114 public static PHPSourceConsole getInstance() {
115 IWorkbenchPage page =
116 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
117 PHPSourceConsole console = (PHPSourceConsole) page.findView(PHPSourceConsole.CONSOLE_ID);
118 // if (PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE.getDefault().getPreferenceStore().getBoolean(PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE) == true) {
121 page.showView(PHPSourceConsole.CONSOLE_ID);
122 if (console == null) {
123 console = (PHPSourceConsole) page.findView(PHPSourceConsole.CONSOLE_ID);
125 } catch (PartInitException e) {
126 PHPEclipseSQLPlugin.getDefault().getLog().log(
129 PHPEclipseSQLPlugin.PLUGIN_ID,
131 Messages.getString("sqlconsole.viewopeningproblem"),
140 * Prints out the string represented by the string buffer
142 public synchronized void print(String output) {
143 appendOutputText(output);
147 * Prints out the string represented by the string buffer
149 public synchronized void println(String output) {
150 appendOutputText(output+'\n');
153 public synchronized void clear() {