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;
17 import java.text.MessageFormat;
19 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
20 import net.sourceforge.phpeclipse.actions.PHPActionMessages;
21 import org.eclipse.core.runtime.CoreException;
22 import org.eclipse.core.runtime.IStatus;
23 import org.eclipse.core.runtime.Status;
24 import org.eclipse.jface.action.IAction;
25 import org.eclipse.jface.preference.IPreferenceStore;
26 import org.eclipse.jface.text.BadLocationException;
27 import org.eclipse.jface.text.Document;
28 import org.eclipse.jface.text.TextViewer;
29 import org.eclipse.jface.viewers.ISelection;
30 import org.eclipse.swt.SWT;
31 import org.eclipse.swt.layout.GridData;
32 import org.eclipse.swt.widgets.Composite;
33 import org.eclipse.ui.IWorkbenchPage;
34 import org.eclipse.ui.IWorkbenchWindow;
35 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
36 import org.eclipse.ui.PartInitException;
37 import org.eclipse.ui.PlatformUI;
38 import org.eclipse.ui.part.ViewPart;
39 import sun.security.krb5.internal.crypto.e;
42 * The PHPConsole is used to display the output if you start MySQL/Apache
45 public class PHPConsole extends ViewPart {
47 public static final String CONSOLE_ID = "net.sourceforge.phpeclipse.views.phpconsoleview";
49 private TextViewer viewer = null;
50 private Document document = null;
59 * Insert the method's description here.
60 * @see ViewPart#createPartControl
62 public void createPartControl(Composite parent) {
63 viewer = new TextViewer(parent, SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL);
64 GridData viewerData = new GridData(GridData.FILL_BOTH);
65 viewer.getControl().setLayoutData(viewerData);
66 viewer.setEditable(false);
70 * Insert the method's description here.
71 * @see ViewPart#setFocus
73 public void setFocus() {
77 * Set the text for the viewer
79 public void setOutputText(String text) {
80 document = new Document(text);
81 viewer.setDocument(document);
84 public void appendOutputText(String text) {
86 document.replace(document.getLength(), 0, text);
87 } catch (BadLocationException e) {
89 // viewer.setDocument(document);
93 * Prints out the string represented by the string buffer
95 static public void write(String output) {
97 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
98 PHPConsole console = (PHPConsole) page.findView(PHPConsole.CONSOLE_ID);
100 if (console != null) {
101 console.appendOutputText(output);
103 PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE) == true) {
104 page.showView(PHPConsole.CONSOLE_ID);
105 console = (PHPConsole) page.findView(PHPConsole.CONSOLE_ID);
106 console.setOutputText(output);
108 } catch (PartInitException e) {
109 PHPeclipsePlugin.getDefault().getLog().log(
110 new Status(IStatus.ERROR, PHPeclipsePlugin.getPluginId(), 0, PHPActionMessages.getString("PHPStartApacheAction.consoleViewOpeningProblem"), e));
116 * Creates a string buffer from the given input stream
118 static public String getStringFromStream(InputStream stream) throws IOException {
119 StringBuffer buffer = new StringBuffer();
120 byte[] b = new byte[100];
122 while (finished != -1) {
123 finished = stream.read(b);
124 if (finished != -1) {
125 String current = new String(b, 0, finished);
126 buffer.append(current);
129 return buffer.toString();