From abe55df4632bdbd33c669a333ecfe313eb3965dc Mon Sep 17 00:00:00 2001 From: khartlage Date: Fri, 7 Feb 2003 23:05:37 +0000 Subject: [PATCH] reworked the Console write() method --- .../phpeclipse/actions/PHPEclipseShowAction.java | 6 +- .../phpeclipse/actions/PHPStartApacheAction.java | 107 ++++++++++++++++++- .../phpeclipse/phpeditor/phpparser/PHPParser.java | 4 +- .../sourceforge/phpeclipse/views/PHPConsole.java | 46 +++++---- 4 files changed, 131 insertions(+), 32 deletions(-) diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java index a7c633c..13efe64 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java @@ -19,7 +19,6 @@ import java.util.Iterator; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import net.sourceforge.phpeclipse.views.PHPConsole; - import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; @@ -68,6 +67,7 @@ public class PHPEclipseShowAction implements IObjectActionDelegate { StructuredSelection selection = null; selection = (StructuredSelection) selectionProvider.getSelection(); + PHPConsole console = PHPConsole.getInstance(); IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); @@ -113,7 +113,7 @@ public class PHPEclipseShowAction implements IObjectActionDelegate { Runtime runtime = Runtime.getRuntime(); String command = form.format(arguments); - PHPConsole.write("External Browser command: "+command+"\n"); + console.write("External Browser command: "+command+"\n"); runtime.exec(command); // runtime.exec(store.getString(PHPeclipsePlugin.EXTERNAL_BROWSER_PREF) + " " + fileName); // runtime.exec("command.com /c start iexplore " + fileName); @@ -121,7 +121,7 @@ public class PHPEclipseShowAction implements IObjectActionDelegate { // MessageDialog.openInformation(shell, "localhostURL", "localhostURL: " + localhostURL); // this doesn't work under win98 ? // Program.launch(localhostURL); - PHPConsole.write("Internal Browser URL: "+localhostURL+"\n"); + console.write("Internal Browser URL: "+localhostURL+"\n"); open(new URL(localhostURL), shell, localhostURL); } } catch (MalformedURLException e) { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStartApacheAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStartApacheAction.java index 997768b..2928345 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStartApacheAction.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStartApacheAction.java @@ -11,18 +11,25 @@ Contributors: **********************************************************************/ package net.sourceforge.phpeclipse.actions; +import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.text.MessageFormat; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import net.sourceforge.phpeclipse.views.PHPConsole; - +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate { protected IWorkbenchWindow activeWindow = null; @@ -37,13 +44,42 @@ public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate { execute(form.format(arguments), "Start Apache: "); } +// public static void execute(String command, String consoleMessage) { +// // MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command); +// try { +// PHPConsole console = PHPConsole.getInstance(); +// console.write(consoleMessage + command + "\n"); +// Runtime runtime = Runtime.getRuntime(); +// +// // runs the command +// Process p = runtime.exec(command); +// +// if (PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE) == true) { +// +// OutputThread out = new OutputThread(p.getInputStream(), console); +// OutputThread err = new OutputThread(p.getErrorStream(), console); +// out.start(); +// err.start(); +// +// } +// +// } catch (IOException e) { +// +// System.err.println("Problem"); +// e.printStackTrace(); +// +// } +// +// } + public static String execute(String command, String consoleMessage) { - // MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command); + // MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command); try { - PHPConsole.write(consoleMessage+command+"\n"); + PHPConsole console = PHPConsole.getInstance(); + console.write(consoleMessage + command + "\n"); Runtime runtime = Runtime.getRuntime(); - // runs the command + // runs the command Process p = runtime.exec(command); // gets the input stream to have the post-compile-time information @@ -53,11 +89,39 @@ public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate { String consoleOutput = PHPConsole.getStringFromStream(stream); // prints out the information - PHPConsole.write(consoleOutput); + console.write(consoleOutput); return consoleOutput; } catch (IOException e) { - + + System.err.println("Problem"); + e.printStackTrace(); + + } + return ""; + } + public static String getParserOutput(String command, String consoleMessage) { + // MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command); + try { + PHPConsole console = PHPConsole.getInstance(); + console.write(consoleMessage + command + "\n"); + Runtime runtime = Runtime.getRuntime(); + + // runs the command + Process p = runtime.exec(command); + + // gets the input stream to have the post-compile-time information + InputStream stream = p.getInputStream(); + + // get the string from Stream + String consoleOutput = PHPConsole.getStringFromStream(stream); + + // prints out the information + console.write(consoleOutput); + return consoleOutput; + + } catch (IOException e) { + System.err.println("Problem"); e.printStackTrace(); @@ -76,4 +140,35 @@ public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate { public void dispose() { } + +// static class OutputThread extends Thread { +// InputStream fInputStream; +// PHPConsole console; +// +// OutputThread(InputStream inputStream, PHPConsole console) { +// this.fInputStream = inputStream; +// this.console = console; +// } +// +// public void run() { +// try { +// BufferedReader bin = new BufferedReader(new InputStreamReader(fInputStream)); +// +// String bufferRow; +// while ((bufferRow = bin.readLine()) != null) { +// +// // prints out the information +// console.write( bufferRow ); +// +// } +// bin.close(); +// +// } catch (IOException e) { +// MessageDialog.openError(null, "Error in output", e.toString()); +// } finally { +// +// } +// } +// } + } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/phpparser/PHPParser.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/phpparser/PHPParser.java index 010e977..c5a29c0 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/phpparser/PHPParser.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/phpparser/PHPParser.java @@ -3408,9 +3408,9 @@ public class PHPParser extends PHPKeywords { MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF)); String command = form.format(arguments); - String parserResult = PHPStartApacheAction.execute(command, "External parser: "); + String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: "); - try { + try { // parse the buffer to find the errors and warnings createMarkers(parserResult, file); } catch (CoreException e) { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java index 72416af..7bf0f41 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java @@ -62,7 +62,7 @@ public class PHPConsole extends ViewPart { 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() { @@ -114,31 +114,35 @@ public class PHPConsole extends ViewPart { // viewer.setDocument(document); } - /** - * Prints out the string represented by the string buffer - */ - public static void write(String output) { - try { - IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - PHPConsole console = (PHPConsole) page.findView(PHPConsole.CONSOLE_ID); + public static PHPConsole getInstance() { + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + PHPConsole console = (PHPConsole) page.findView(PHPConsole.CONSOLE_ID); + if (console == null) { + console = (PHPConsole) page.findView(PHPConsole.CONSOLE_ID); + } + if (PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE) == true) { - if (console != null) { - console.appendOutputText(output); - } else if (PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE) == true) { + try { page.showView(PHPConsole.CONSOLE_ID); - console = (PHPConsole) page.findView(PHPConsole.CONSOLE_ID); - console.setOutputText(output); + } catch (PartInitException e) { + PHPeclipsePlugin.getDefault().getLog().log( + new Status( + IStatus.ERROR, + PHPeclipsePlugin.getPluginId(), + 0, + PHPActionMessages.getString("PHPStartApacheAction.consoleViewOpeningProblem"), + e)); } - } catch (PartInitException e) { - PHPeclipsePlugin.getDefault().getLog().log( - new Status( - IStatus.ERROR, - PHPeclipsePlugin.getPluginId(), - 0, - PHPActionMessages.getString("PHPStartApacheAction.consoleViewOpeningProblem"), - e)); + } + return console; + } + /** + * Prints out the string represented by the string buffer + */ + public synchronized void write(String output) { + appendOutputText(output); } /** -- 1.7.1