1 package net.sourceforge.phpeclipse.views;
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 **********************************************************************/
15 import java.io.IOException;
16 import java.io.InputStream;
18 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
19 import net.sourceforge.phpeclipse.actions.PHPActionMessages;
21 import org.eclipse.core.runtime.IStatus;
22 import org.eclipse.core.runtime.Status;
23 import org.eclipse.jface.action.Action;
24 import org.eclipse.jface.resource.JFaceResources;
25 import org.eclipse.jface.text.BadLocationException;
26 import org.eclipse.jface.text.Document;
27 import org.eclipse.jface.text.TextViewer;
28 import org.eclipse.swt.SWT;
29 import org.eclipse.swt.custom.StyledText;
30 import org.eclipse.swt.layout.GridData;
31 import org.eclipse.swt.widgets.Composite;
32 import org.eclipse.ui.IActionBars;
33 import org.eclipse.ui.IWorkbenchActionConstants;
34 import org.eclipse.ui.IWorkbenchPage;
35 import org.eclipse.ui.PartInitException;
36 import org.eclipse.ui.PlatformUI;
37 import org.eclipse.ui.part.ViewPart;
40 * The PHPConsole is used to display the output if you start MySQL/Apache
43 public class PHPConsole extends ViewPart {
45 public static final String CONSOLE_ID = "net.sourceforge.phpeclipse.views.phpconsoleview";
47 private TextViewer viewer = null;
48 private Document document = null;
57 * Insert the method's description here.
58 * @see ViewPart#createPartControl
60 public void createPartControl(Composite parent) {
61 viewer = new TextViewer(parent, SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL);
62 GridData viewerData = new GridData(GridData.FILL_BOTH);
63 viewer.getControl().setLayoutData(viewerData);
64 viewer.setEditable(false);
66 StyledText widget = viewer.getTextWidget();
67 widget.setFont(JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT));
68 Action cutAction = new Action() {
70 viewer.getTextWidget().cut();
73 Action copyAction = new Action() {
75 viewer.getTextWidget().copy();
78 Action pasteAction = new Action() {
80 viewer.getTextWidget().paste();
84 IActionBars bars = this.getViewSite().getActionBars();
85 bars.setGlobalActionHandler(IWorkbenchActionConstants.CUT, cutAction);
86 bars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, copyAction);
87 bars.setGlobalActionHandler(IWorkbenchActionConstants.PASTE, pasteAction);
91 * Insert the method's description here.
92 * @see ViewPart#setFocus
94 public void setFocus() {
98 * Set the text for the viewer
100 public void setOutputText(String text) {
101 document = new Document(text);
102 viewer.setDocument(document);
105 public void appendOutputText(String text) {
107 if (document == null) {
108 document = new Document(text);
109 viewer.setDocument(document);
111 document.replace(document.getLength(), 0, text);
112 } catch (BadLocationException e) {
114 // viewer.setDocument(document);
117 public static PHPConsole getInstance() {
118 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
119 PHPConsole console = (PHPConsole) page.findView(PHPConsole.CONSOLE_ID);
120 if (console == null) {
121 console = (PHPConsole) page.findView(PHPConsole.CONSOLE_ID);
123 if (PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE) == true) {
126 page.showView(PHPConsole.CONSOLE_ID);
127 } catch (PartInitException e) {
128 PHPeclipsePlugin.getDefault().getLog().log(
131 PHPeclipsePlugin.getPluginId(),
133 PHPActionMessages.getString("PHPStartApacheAction.consoleViewOpeningProblem"),
142 * Prints out the string represented by the string buffer
144 public synchronized void write(String output) {
145 appendOutputText(output);
149 * Creates a string buffer from the given input stream
151 public static String getStringFromStream(InputStream stream) throws IOException {
152 StringBuffer buffer = new StringBuffer();
153 byte[] b = new byte[100];
155 while (finished != -1) {
156 finished = stream.read(b);
157 if (finished != -1) {
158 String current = new String(b, 0, finished);
159 buffer.append(current);
162 return buffer.toString();