X-Git-Url: http://git.phpeclipse.com diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/PHPSourceConsole.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/PHPSourceConsole.java new file mode 100644 index 0000000..42c2956 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/view/PHPSourceConsole.java @@ -0,0 +1,157 @@ +package com.quantum.view; + +/********************************************************************** +Copyright (c) 2000, 2002 IBM Corp. and others. +All rights reserved. This program and the accompanying materials +are made available under the terms of the Common Public License v1.0 +which accompanies this distribution, and is available at +http://www.eclipse.org/legal/cpl-v10.html + +Contributors: + IBM Corporation - Initial implementation + Klaus Hartlage - www.eclipseproject.de +**********************************************************************/ +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.TextViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.part.ViewPart; + +import com.quantum.Messages; +import com.quantum.QuantumPlugin; + +/** + * The PHPSourceConsole is used to display the output from the PHP SQL wizards + * @see ViewPart + */ +public class PHPSourceConsole extends ViewPart { + + public static final String CONSOLE_ID = + "net.sourceforge.phpdt.sql.view.phpsourceconsoleview"; + + TextViewer viewer = null; + private Document document = null; + + /** + * The constructor. + */ + public PHPSourceConsole() { + } + + /** + * Insert the method's description here. + * @see ViewPart#createPartControl + */ + public void createPartControl(Composite parent) { + viewer = new TextViewer(parent, SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL); + GridData viewerData = new GridData(GridData.FILL_BOTH); + viewer.getControl().setLayoutData(viewerData); + viewer.setEditable(false); + + StyledText widget = viewer.getTextWidget(); + widget.setFont( + JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT)); + Action cutAction = new Action() { + public void run() { + viewer.getTextWidget().cut(); + } + }; + Action copyAction = new Action() { + public void run() { + viewer.getTextWidget().copy(); + } + }; + Action pasteAction = new Action() { + public void run() { + viewer.getTextWidget().paste(); + } + }; + + IActionBars bars = this.getViewSite().getActionBars(); + bars.setGlobalActionHandler(IWorkbenchActionConstants.CUT, cutAction); + bars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, copyAction); + bars.setGlobalActionHandler(IWorkbenchActionConstants.PASTE, pasteAction); + } + + /** + * Insert the method's description here. + * @see ViewPart#setFocus + */ + public void setFocus() { + } + + /** + * Set the text for the viewer + */ + private void setOutputText(String text) { + document = new Document(text); + viewer.setDocument(document); + } + + private void appendOutputText(String text) { + try { + if (document == null) { + document = new Document(text); + viewer.setDocument(document); + } + document.replace(document.getLength(), 0, text); + } catch (BadLocationException e) { + } + // viewer.setDocument(document); + } + + public static PHPSourceConsole getInstance() { + IWorkbenchPage page = + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + PHPSourceConsole console = (PHPSourceConsole) page.findView(PHPSourceConsole.CONSOLE_ID); + // if (PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE.getDefault().getPreferenceStore().getBoolean(PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE) == true) { + + try { + page.showView(PHPSourceConsole.CONSOLE_ID); + if (console == null) { + console = (PHPSourceConsole) page.findView(PHPSourceConsole.CONSOLE_ID); + } + } catch (PartInitException e) { + QuantumPlugin.getDefault().getLog().log( + new Status( + IStatus.ERROR, + QuantumPlugin.PLUGIN_ID, + 0, + Messages.getString("sqlconsole.viewopeningproblem"), + e)); + } + + // } + return console; + } + + /** + * Prints out the string represented by the string buffer + */ + public synchronized void print(String output) { + appendOutputText(output); + } + + /** + * Prints out the string represented by the string buffer + */ + public synchronized void println(String output) { + appendOutputText(output+'\n'); + } + + public synchronized void clear() { + setOutputText(""); + } +}