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 if (document == null) {
87 document = new Document(text);
88 viewer.setDocument(document);
90 document.replace(document.getLength(), 0, text);
91 } catch (BadLocationException e) {
93 // viewer.setDocument(document);
97 * Prints out the string represented by the string buffer
99 public static void write(String output) {
101 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
102 PHPConsole console = (PHPConsole) page.findView(PHPConsole.CONSOLE_ID);
104 if (console != null) {
105 console.appendOutputText(output);
106 } else if (PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE) == true) {
107 page.showView(PHPConsole.CONSOLE_ID);
108 console = (PHPConsole) page.findView(PHPConsole.CONSOLE_ID);
109 console.setOutputText(output);
111 } catch (PartInitException e) {
112 PHPeclipsePlugin.getDefault().getLog().log(
115 PHPeclipsePlugin.getPluginId(),
117 PHPActionMessages.getString("PHPStartApacheAction.consoleViewOpeningProblem"),
124 * Creates a string buffer from the given input stream
126 public static String getStringFromStream(InputStream stream) throws IOException {
127 StringBuffer buffer = new StringBuffer();
128 byte[] b = new byte[100];
130 while (finished != -1) {
131 finished = stream.read(b);
132 if (finished != -1) {
133 String current = new String(b, 0, finished);
134 buffer.append(current);
137 return buffer.toString();