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;
20 import org.eclipse.core.runtime.IStatus;
21 import org.eclipse.core.runtime.Status;
22 import org.eclipse.jface.action.Action;
23 import org.eclipse.jface.resource.JFaceResources;
24 import org.eclipse.jface.text.BadLocationException;
25 import org.eclipse.jface.text.Document;
26 import org.eclipse.jface.text.TextViewer;
27 import org.eclipse.swt.SWT;
28 import org.eclipse.swt.custom.StyledText;
29 import org.eclipse.swt.layout.GridData;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.ui.IActionBars;
32 import org.eclipse.ui.IWorkbenchActionConstants;
33 import org.eclipse.ui.IWorkbenchPage;
34 import org.eclipse.ui.PartInitException;
35 import org.eclipse.ui.PlatformUI;
36 import org.eclipse.ui.part.ViewPart;
39 * The PHPConsole is used to display the output if you start MySQL/Apache
42 public class PHPConsole extends ViewPart {
44 public static final String CONSOLE_ID = "net.sourceforge.phpeclipse.views.phpconsoleview";
46 private TextViewer viewer = null;
47 private Document document = null;
56 * Insert the method's description here.
57 * @see ViewPart#createPartControl
59 public void createPartControl(Composite parent) {
60 viewer = new TextViewer(parent, SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL);
61 GridData viewerData = new GridData(GridData.FILL_BOTH);
62 viewer.getControl().setLayoutData(viewerData);
63 viewer.setEditable(false);
65 StyledText widget = viewer.getTextWidget();
66 widget.setFont(JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT));
67 Action cutAction = new Action() {
69 viewer.getTextWidget().cut();
72 Action copyAction = new Action() {
74 viewer.getTextWidget().copy();
77 Action pasteAction = new Action() {
79 viewer.getTextWidget().paste();
83 IActionBars bars = this.getViewSite().getActionBars();
84 bars.setGlobalActionHandler(IWorkbenchActionConstants.CUT, cutAction);
85 bars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, copyAction);
86 bars.setGlobalActionHandler(IWorkbenchActionConstants.PASTE, pasteAction);
90 * Insert the method's description here.
91 * @see ViewPart#setFocus
93 public void setFocus() {
97 * Set the text for the viewer
99 public void setOutputText(String text) {
100 document = new Document(text);
101 viewer.setDocument(document);
104 public void appendOutputText(String text) {
106 if (document == null) {
107 document = new Document(text);
108 viewer.setDocument(document);
110 document.replace(document.getLength(), 0, text);
111 } catch (BadLocationException e) {
113 // viewer.setDocument(document);
117 * Prints out the string represented by the string buffer
119 public static void write(String output) {
121 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
122 PHPConsole console = (PHPConsole) page.findView(PHPConsole.CONSOLE_ID);
124 if (console != null) {
125 console.appendOutputText(output);
126 } else if (PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE) == true) {
127 page.showView(PHPConsole.CONSOLE_ID);
128 console = (PHPConsole) page.findView(PHPConsole.CONSOLE_ID);
129 console.setOutputText(output);
131 } catch (PartInitException e) {
132 PHPeclipsePlugin.getDefault().getLog().log(
135 PHPeclipsePlugin.getPluginId(),
137 PHPActionMessages.getString("PHPStartApacheAction.consoleViewOpeningProblem"),
144 * Creates a string buffer from the given input stream
146 public static String getStringFromStream(InputStream stream) throws IOException {
147 StringBuffer buffer = new StringBuffer();
148 byte[] b = new byte[100];
150 while (finished != -1) {
151 finished = stream.read(b);
152 if (finished != -1) {
153 String current = new String(b, 0, finished);
154 buffer.append(current);
157 return buffer.toString();