reworked the Console write() method
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / views / PHPConsole.java
index 72416af..7bf0f41 100644 (file)
@@ -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);
   }
 
   /**