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 org.eclipse.core.runtime.IStatus;
15 import org.eclipse.core.runtime.Status;
16 import org.eclipse.jface.action.Action;
17 import org.eclipse.jface.resource.JFaceResources;
18 import org.eclipse.jface.text.BadLocationException;
19 import org.eclipse.jface.text.Document;
20 import org.eclipse.jface.text.TextViewer;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.custom.StyledText;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.ui.IActionBars;
26 import org.eclipse.ui.IWorkbenchActionConstants;
27 import org.eclipse.ui.IWorkbenchPage;
28 import org.eclipse.ui.PartInitException;
29 import org.eclipse.ui.PlatformUI;
30 import org.eclipse.ui.part.ViewPart;
32 import net.sourceforge.phpdt.sql.Messages;
33 import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
36 * The PHPSourceConsole is used to display the output from the PHP SQL wizards
39 public class PHPSourceConsole extends ViewPart {
41 public static final String CONSOLE_ID =
42 "net.sourceforge.phpdt.sql.view.phpsourceconsoleview";
44 TextViewer viewer = null;
45 private Document document = null;
50 public PHPSourceConsole() {
54 * Insert the method's description here.
55 * @see ViewPart#createPartControl
57 public void createPartControl(Composite parent) {
58 viewer = new TextViewer(parent, SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL);
59 GridData viewerData = new GridData(GridData.FILL_BOTH);
60 viewer.getControl().setLayoutData(viewerData);
61 viewer.setEditable(false);
63 StyledText widget = viewer.getTextWidget();
65 JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT));
66 Action cutAction = new Action() {
68 viewer.getTextWidget().cut();
71 Action copyAction = new Action() {
73 viewer.getTextWidget().copy();
76 Action pasteAction = new Action() {
78 viewer.getTextWidget().paste();
82 IActionBars bars = this.getViewSite().getActionBars();
83 bars.setGlobalActionHandler(IWorkbenchActionConstants.CUT, cutAction);
84 bars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, copyAction);
85 bars.setGlobalActionHandler(IWorkbenchActionConstants.PASTE, pasteAction);
89 * Insert the method's description here.
90 * @see ViewPart#setFocus
92 public void setFocus() {
96 * Set the text for the viewer
98 private void setOutputText(String text) {
99 document = new Document(text);
100 viewer.setDocument(document);
103 private void appendOutputText(String text) {
105 if (document == null) {
106 document = new Document(text);
107 viewer.setDocument(document);
109 document.replace(document.getLength(), 0, text);
110 } catch (BadLocationException e) {
112 // viewer.setDocument(document);
115 public static PHPSourceConsole getInstance() {
116 IWorkbenchPage page =
117 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
118 PHPSourceConsole console = (PHPSourceConsole) page.findView(PHPSourceConsole.CONSOLE_ID);
119 // if (PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE.getDefault().getPreferenceStore().getBoolean(PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE) == true) {
122 page.showView(PHPSourceConsole.CONSOLE_ID);
123 if (console == null) {
124 console = (PHPSourceConsole) page.findView(PHPSourceConsole.CONSOLE_ID);
126 } catch (PartInitException e) {
127 PHPEclipseSQLPlugin.getDefault().getLog().log(
130 PHPEclipseSQLPlugin.PLUGIN_ID,
132 Messages.getString("sqlconsole.viewopeningproblem"),
141 * Prints out the string represented by the string buffer
143 public synchronized void print(String output) {
144 appendOutputText(output);
148 * Prints out the string represented by the string buffer
150 public synchronized void println(String output) {
151 appendOutputText(output+'\n');
154 public synchronized void clear() {