Author: koen.aers(a)jboss.com
Date: 2011-01-24 16:43:26 -0500 (Mon, 24 Jan 2011)
New Revision: 28584
Added:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/ColorManager.java
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/Console.java
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/InputReadJob.java
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/StreamListener.java
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/ConsoleViewer.java
Removed:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/action/ConsoleTerminateAction.java
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/Console.java
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/ConsoleLineNotifier.java
Modified:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/Activator.java
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/runtime/Manager.java
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/ConsolePage.java
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/ConsoleView.java
Log:
cleanup and refactorings
Modified:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/Activator.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/Activator.java 2011-01-24
21:17:45 UTC (rev 28583)
+++
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/Activator.java 2011-01-24
21:43:26 UTC (rev 28584)
@@ -1,39 +1,22 @@
package org.jboss.tools.seam.forge;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.jboss.tools.seam.forge.runtime.Manager;
import org.osgi.framework.BundleContext;
-/**
- * The activator class controls the plug-in life cycle
- */
public class Activator extends AbstractUIPlugin {
- // The plug-in ID
public static final String PLUGIN_ID = "org.jboss.tools.seam.forge";
//$NON-NLS-1$
- // The shared instance
private static Activator plugin;
- /**
- * The constructor
- */
- public Activator() {
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
- */
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
- */
public void stop(BundleContext context) throws Exception {
if (Manager.INSTANCE.isForgeRunning()) {
Manager.INSTANCE.stopForge();
@@ -42,13 +25,16 @@
super.stop(context);
}
- /**
- * Returns the shared instance
- *
- * @return the shared instance
- */
public static Activator getDefault() {
return plugin;
}
+ public static void log(Throwable t) {
+ getDefault().getLog().log(newErrorStatus("Error logged from Forge Plugin: ",
t));
+ }
+
+ private static IStatus newErrorStatus(String message, Throwable exception) {
+ return new Status(IStatus.ERROR, PLUGIN_ID, IStatus.INFO, message, exception);
+ }
+
}
Deleted:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/action/ConsoleTerminateAction.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/action/ConsoleTerminateAction.java 2011-01-24
21:17:45 UTC (rev 28583)
+++
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/action/ConsoleTerminateAction.java 2011-01-24
21:43:26 UTC (rev 28584)
@@ -1,97 +0,0 @@
-package org.jboss.tools.seam.forge.action;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.debug.core.DebugPlugin;
-import org.eclipse.debug.core.ILaunch;
-import org.eclipse.debug.core.ILaunchManager;
-import org.eclipse.debug.core.commands.ITerminateHandler;
-import org.eclipse.debug.core.model.IDebugTarget;
-import org.eclipse.debug.core.model.IProcess;
-import org.eclipse.debug.internal.ui.DebugPluginImages;
-import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
-import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
-import org.eclipse.debug.internal.ui.commands.actions.DebugCommandService;
-import org.eclipse.debug.internal.ui.views.console.ConsoleMessages;
-import org.eclipse.jface.action.Action;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.texteditor.IUpdate;
-import org.jboss.tools.seam.forge.view.Console;
-
-/**
- * ConsoleTerminateAction
- */
-public class ConsoleTerminateAction extends Action implements IUpdate {
-
- private Console fConsole;
- private IWorkbenchWindow fWindow;
-
- /**
- * Creates a terminate action for the console
- */
- public ConsoleTerminateAction(IWorkbenchWindow window, Console console) {
- super(ConsoleMessages.ConsoleTerminateAction_0);
- PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
IDebugHelpContextIds.CONSOLE_TERMINATE_ACTION);
- fConsole = console;
- fWindow = window;
- setToolTipText(ConsoleMessages.ConsoleTerminateAction_1);
- setImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_LCL_TERMINATE));
- setDisabledImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_TERMINATE));
- setHoverImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_LCL_TERMINATE));
- PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
IDebugHelpContextIds.CONSOLE_TERMINATE_ACTION);
- update();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.texteditor.IUpdate#update()
- */
- public void update() {
- IProcess process = fConsole.getProcess();
- setEnabled(process.canTerminate());
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.action.IAction#run()
- */
- public void run() {
- IProcess process = fConsole.getProcess();
- List targets = collectTargets(process);
- targets.add(process);
- DebugCommandService service = DebugCommandService.getService(fWindow);
- service.executeCommand(ITerminateHandler.class, targets.toArray(), null);
- }
-
- /**
- * Collects targets associated with a process.
- *
- * @param process
- * @return associated targets
- */
- private List collectTargets(IProcess process) {
- ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
- ILaunch[] launches = launchManager.getLaunches();
- List targets = new ArrayList();
- for (int i = 0; i < launches.length; i++) {
- ILaunch launch = launches[i];
- IProcess[] processes = launch.getProcesses();
- for (int j = 0; j < processes.length; j++) {
- IProcess process2 = processes[j];
- if (process2.equals(process)) {
- IDebugTarget[] debugTargets = launch.getDebugTargets();
- for (int k = 0; k < debugTargets.length; k++) {
- targets.add(debugTargets[k]);
- }
- return targets; // all possible targets have been terminated for the
launch.
- }
- }
- }
- return targets;
- }
-
- public void dispose() {
- fConsole = null;
- }
-
-}
Added:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/ColorManager.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/ColorManager.java
(rev 0)
+++
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/ColorManager.java 2011-01-24
21:43:26 UTC (rev 28584)
@@ -0,0 +1,43 @@
+package org.jboss.tools.seam.forge.console;
+
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+
+class ColorManager {
+
+ private static ColorManager INSTANCE;
+
+ private ColorManager() {}
+
+ public static ColorManager getInstance() {
+ if (INSTANCE == null) {
+ INSTANCE= new ColorManager();
+ }
+ return INSTANCE;
+ }
+
+ protected Map<RGB, Color> fColorTable= new HashMap<RGB, Color>(10);
+
+ public Color getColor(RGB rgb) {
+ Color color= (Color) fColorTable.get(rgb);
+ if (color == null) {
+ color= new Color(Display.getCurrent(), rgb);
+ fColorTable.put(rgb, color);
+ }
+ return color;
+ }
+
+ public void dispose() {
+ Iterator<Color> e= fColorTable.values().iterator();
+ while (e.hasNext())
+ ((Color) e.next()).dispose();
+ }
+}
+
+
Property changes on:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/ColorManager.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/Console.java
(from rev 28554,
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/Console.java)
===================================================================
---
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/Console.java
(rev 0)
+++
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/Console.java 2011-01-24
21:43:26 UTC (rev 28584)
@@ -0,0 +1,144 @@
+package org.jboss.tools.seam.forge.console;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.debug.core.DebugEvent;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.IDebugEventSetListener;
+import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.debug.core.model.IStreamMonitor;
+import org.eclipse.debug.core.model.IStreamsProxy;
+import org.eclipse.debug.ui.IDebugUIConstants;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.console.IOConsole;
+import org.eclipse.ui.console.IOConsoleInputStream;
+import org.eclipse.ui.console.IOConsoleOutputStream;
+
+public class Console extends IOConsole implements IDebugEventSetListener {
+
+ private static final RGB INPUT_STREAM_RGB = new RGB(25, 225, 25);
+ private static final RGB ERROR_STREAM_RGB = new RGB(225, 25, 25);
+ private static final RGB OUTPUT_STREAM_RGB = new RGB(0, 0, 0);
+ private static final RGB CONSOLE_BACKGROUND_RGB = new RGB(255, 255, 255);
+
+ private IProcess process = null;
+ private IOConsoleInputStream input;
+ private boolean streamsClosed = false;
+ private List<StreamListener> streamListeners = new
ArrayList<StreamListener>();
+
+ public Console(IProcess process) {
+ super("Forge Console", null, null, null, true);
+ this.process = process;
+ input = getInputStream();
+ input.setColor(ColorManager.getInstance().getColor(INPUT_STREAM_RGB));
+ connect();
+ }
+
+ public IOConsoleOutputStream getStream(String streamIdentifier) {
+ for (StreamListener listener : streamListeners) {
+ if (listener.getStreamId().equals(streamIdentifier)) {
+ return listener.getStream();
+ }
+ }
+ return null;
+ }
+
+ public void dispose() {
+ super.dispose();
+ closeStreams();
+ disposeStreams();
+ DebugPlugin.getDefault().removeDebugEventListener(this);
+ }
+
+ private synchronized void closeStreams() {
+ if (streamsClosed) {
+ return;
+ }
+ for (StreamListener listener : streamListeners) {
+ listener.closeStream();
+ }
+ try {
+ input.close();
+ } catch (IOException e) {
+ }
+ streamsClosed = true;
+ }
+
+ private synchronized void disposeStreams() {
+ for (StreamListener listener : streamListeners) {
+ listener.dispose();
+ }
+ input = null;
+ }
+
+ protected void init() {
+ super.init();
+ if (process.isTerminated()) {
+ closeStreams();
+ } else {
+ DebugPlugin.getDefault().addDebugEventListener(this);
+ }
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ setFont(JFaceResources.getFont(IDebugUIConstants.PREF_CONSOLE_FONT));
+
setBackground(ColorManager.getInstance().getColor(CONSOLE_BACKGROUND_RGB));
+ }
+ });
+ }
+
+ public void handleDebugEvents(DebugEvent[] events) {
+ for (int i = 0; i < events.length; i++) {
+ DebugEvent event = events[i];
+ if (event.getSource().equals(process)) {
+ if (event.getKind() == DebugEvent.TERMINATE) {
+ closeStreams();
+ DebugPlugin.getDefault().removeDebugEventListener(this);
+ }
+ }
+ }
+ }
+
+ public void connect() {
+ IStreamsProxy streamsProxy = process.getStreamsProxy();
+ IStreamMonitor streamMonitor = streamsProxy.getErrorStreamMonitor();
+ if (streamMonitor != null) {
+ connect(streamMonitor, IDebugUIConstants.ID_STANDARD_ERROR_STREAM);
+ }
+ streamMonitor = streamsProxy.getOutputStreamMonitor();
+ if (streamMonitor != null) {
+ connect(streamMonitor, IDebugUIConstants.ID_STANDARD_OUTPUT_STREAM);
+ }
+ InputReadJob inputReadJob = new InputReadJob(streamsProxy, input);
+ inputReadJob.setSystem(true);
+ inputReadJob.schedule();
+ }
+
+ private void connect(IStreamMonitor streamMonitor, String streamIdentifier) {
+ IOConsoleOutputStream stream = newOutputStream();
+ Color color = getColor(streamIdentifier);
+ stream.setColor(color);
+ synchronized (streamMonitor) {
+ StreamListener listener = new StreamListener(streamIdentifier, streamMonitor,
stream, getEncoding());
+ streamListeners.add(listener);
+ }
+ }
+
+ public Color getColor(String streamIdentifer) {
+ if (IDebugUIConstants.ID_STANDARD_OUTPUT_STREAM.equals(streamIdentifer)) {
+ return ColorManager.getInstance().getColor(OUTPUT_STREAM_RGB);
+ }
+ if (IDebugUIConstants.ID_STANDARD_ERROR_STREAM.equals(streamIdentifer)) {
+ return ColorManager.getInstance().getColor(ERROR_STREAM_RGB);
+ }
+ if (IDebugUIConstants.ID_STANDARD_INPUT_STREAM.equals(streamIdentifer)) {
+ return ColorManager.getInstance().getColor(INPUT_STREAM_RGB);
+ }
+ return null;
+ }
+
+}
Property changes on:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/Console.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/InputReadJob.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/InputReadJob.java
(rev 0)
+++
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/InputReadJob.java 2011-01-24
21:43:26 UTC (rev 28584)
@@ -0,0 +1,40 @@
+package org.jboss.tools.seam.forge.console;
+
+import java.io.IOException;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.debug.core.model.IStreamsProxy;
+import org.eclipse.ui.console.IOConsoleInputStream;
+import org.jboss.tools.seam.forge.Activator;
+
+class InputReadJob extends Job {
+
+ private IStreamsProxy streamsProxy;
+ private IOConsoleInputStream input;
+
+ InputReadJob(IStreamsProxy streamsProxy, IOConsoleInputStream input) {
+ super("Forge Console Input Job");
+ this.input = input;
+ this.streamsProxy = streamsProxy;
+ }
+
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ byte[] b = new byte[1024];
+ int read = 0;
+ while (input != null && read >= 0) {
+ read = input.read(b);
+ if (read > 0) {
+ String s = new String(b, 0, read);
+ streamsProxy.write(s);
+ }
+ }
+ } catch (IOException e) {
+ Activator.log(e);
+ }
+ return Status.OK_STATUS;
+ }
+}
Property changes on:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/InputReadJob.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/StreamListener.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/StreamListener.java
(rev 0)
+++
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/StreamListener.java 2011-01-24
21:43:26 UTC (rev 28584)
@@ -0,0 +1,101 @@
+package org.jboss.tools.seam.forge.console;
+
+import java.io.IOException;
+
+import org.eclipse.debug.core.IStreamListener;
+import org.eclipse.debug.core.model.IFlushableStreamMonitor;
+import org.eclipse.debug.core.model.IStreamMonitor;
+import org.eclipse.ui.console.IOConsoleOutputStream;
+import org.jboss.tools.seam.forge.Activator;
+
+class StreamListener implements IStreamListener {
+
+ private IOConsoleOutputStream stream;
+ private IStreamMonitor streamMonitor;
+ private String streamId;
+ private boolean flushed = false;
+ private boolean listenerRemoved = false;
+ private String encoding;
+
+ StreamListener(String streamIdentifier, IStreamMonitor monitor, IOConsoleOutputStream
stream, String encoding) {
+ this.streamId = streamIdentifier;
+ this.streamMonitor = monitor;
+ this.stream = stream;
+ this.encoding = encoding;
+ streamMonitor.addListener(this);
+ streamAppended(null, monitor);
+ }
+
+ String getStreamId() {
+ return streamId;
+ }
+
+ IOConsoleOutputStream getStream() {
+ return stream;
+ }
+
+ public void streamAppended(String text, IStreamMonitor monitor) {
+ if (flushed) {
+ try {
+ if (stream != null) {
+ if (encoding == null)
+ stream.write(text);
+ else
+ stream.write(text.getBytes(encoding));
+ }
+ } catch (IOException e) {
+ Activator.log(e);
+ }
+ } else {
+ String contents = null;
+ synchronized (streamMonitor) {
+ flushed = true;
+ contents = streamMonitor.getContents();
+ if (streamMonitor instanceof IFlushableStreamMonitor) {
+ IFlushableStreamMonitor m = (IFlushableStreamMonitor) streamMonitor;
+ m.flushContents();
+ m.setBuffered(false);
+ }
+ }
+ try {
+ if (contents != null && contents.length() > 0) {
+ if (stream != null) {
+ stream.write(contents);
+ }
+ }
+ } catch (IOException e) {
+ Activator.log(e);
+ }
+ }
+ }
+
+ void closeStream() {
+ if (streamMonitor == null) {
+ return;
+ }
+ synchronized (streamMonitor) {
+ streamMonitor.removeListener(this);
+ if (!flushed) {
+ String contents = streamMonitor.getContents();
+ streamAppended(contents, streamMonitor);
+ }
+ listenerRemoved = true;
+ try {
+ if (stream != null) {
+ stream.close();
+ }
+ } catch (IOException e) {
+ }
+ }
+ }
+
+ void dispose() {
+ if (!listenerRemoved) {
+ closeStream();
+ }
+ stream = null;
+ streamMonitor = null;
+ streamId = null;
+ }
+}
+
Property changes on:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/StreamListener.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/runtime/Manager.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/runtime/Manager.java 2011-01-24
21:17:45 UTC (rev 28583)
+++
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/runtime/Manager.java 2011-01-24
21:43:26 UTC (rev 28584)
@@ -9,18 +9,14 @@
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.core.internal.jobs.JobManager;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
@@ -34,8 +30,6 @@
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
import org.eclipse.jdt.launching.JavaRuntime;
-import org.eclipse.swt.widgets.Display;
-import org.jboss.tools.seam.forge.Activator;
import org.osgi.framework.Bundle;
public class Manager implements IDebugEventSetListener {
@@ -78,7 +72,6 @@
try {
file = FileLocator.getBundleFile(bundle);
} catch (IOException e1) {
- // TODO Auto-generated catch block
e1.printStackTrace();
}
if (file == null) return;
@@ -109,10 +102,6 @@
classpath.add(systemLibsEntry.getMemento());
workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH,
classpath);
workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH,
false);
-// workingCopy.setAttribute(
-// IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
-// "-Dforge.home=/Users/koen/Downloads/forge-1.0.0.Alpha1 "); // +
-// "-Dseam.forge.shell.colorEnabled=true" );
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
IPath path = root.getLocation();
@@ -168,19 +157,6 @@
propertyChangeSupport.removePropertyChangeListener("runtimeState",
listener);
}
- private IStatus createStatus(String message) {
- return new Status(
- IStatus.INFO,
- Activator.getDefault().getBundle().getSymbolicName(),
- IStatus.OK,
- message,
- null);
- }
-
- private void log(String message) {
- Activator.getDefault().getLog().log(createStatus(message));
- }
-
protected void finalize() throws Throwable {
if (forgeProcess != null) {
if (!forgeProcess.isTerminated()) {
Deleted:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/Console.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/Console.java 2011-01-24
21:17:45 UTC (rev 28583)
+++
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/Console.java 2011-01-24
21:43:26 UTC (rev 28584)
@@ -1,823 +0,0 @@
-package org.jboss.tools.seam.forge.view;
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.core.internal.jobs.JobManager;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IStorage;
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.PlatformObject;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.core.variables.IStringVariableManager;
-import org.eclipse.core.variables.VariablesPlugin;
-import org.eclipse.debug.core.DebugEvent;
-import org.eclipse.debug.core.DebugPlugin;
-import org.eclipse.debug.core.IDebugEventSetListener;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchConfigurationType;
-import org.eclipse.debug.core.IStreamListener;
-import org.eclipse.debug.core.model.IFlushableStreamMonitor;
-import org.eclipse.debug.core.model.IProcess;
-import org.eclipse.debug.core.model.IStreamMonitor;
-import org.eclipse.debug.core.model.IStreamsProxy;
-import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
-import org.eclipse.debug.internal.core.IInternalDebugCoreConstants;
-import org.eclipse.debug.internal.ui.DebugPluginImages;
-import org.eclipse.debug.internal.ui.DebugUIPlugin;
-import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
-import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants;
-import org.eclipse.debug.internal.ui.views.console.ConsoleMessages;
-import org.eclipse.debug.ui.DebugUITools;
-import org.eclipse.debug.ui.IDebugUIConstants;
-import org.eclipse.debug.ui.console.IConsole;
-import org.eclipse.debug.ui.console.IConsoleColorProvider;
-import org.eclipse.debug.ui.console.IConsoleHyperlink;
-import org.eclipse.debug.ui.console.IConsoleLineTracker;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IPersistableElement;
-import org.eclipse.ui.IStorageEditorInput;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.console.ConsolePlugin;
-import org.eclipse.ui.console.IHyperlink;
-import org.eclipse.ui.console.IOConsole;
-import org.eclipse.ui.console.IOConsoleInputStream;
-import org.eclipse.ui.console.IOConsoleOutputStream;
-import org.eclipse.ui.console.IPatternMatchListener;
-import org.eclipse.ui.console.PatternMatchEvent;
-import org.eclipse.ui.console.TextConsole;
-import org.eclipse.ui.editors.text.EditorsUI;
-import org.eclipse.ui.part.FileEditorInput;
-import org.eclipse.ui.progress.UIJob;
-
-/**
- * A console for a system process with standard I/O streams.
- *
- * @since 3.0
- */
-public class Console extends IOConsole implements IConsole, IDebugEventSetListener,
IPropertyChangeListener {
- private IProcess fProcess = null;
-
- private List fStreamListeners = new ArrayList();
-
- private IConsoleColorProvider fColorProvider;
-
- private IOConsoleInputStream fInput;
-
- private FileOutputStream fFileOutputStream;
-
- private boolean fAllocateConsole = true;
-
- private boolean fStreamsClosed = false;
-
- private InputReadJob inputReadJob;
-
- /**
- * Proxy to a console document
- */
- public Console(IProcess process, IConsoleColorProvider colorProvider) {
- this(process, colorProvider, null);
- }
-
- /**
- * Constructor
- * @param process the process to associate with this console
- * @param colorProvider the colour provider for this console
- * @param encoding the desired encoding for this console
- */
- public Console(IProcess process, IConsoleColorProvider colorProvider, String
encoding) {
- super(IInternalDebugCoreConstants.EMPTY_STRING,
IDebugUIConstants.ID_PROCESS_CONSOLE_TYPE, null, encoding, true);
- fProcess = process;
-
- ILaunchConfiguration configuration =
process.getLaunch().getLaunchConfiguration();
- String file = null;
- boolean append = false;
- if (configuration != null) {
- try {
- file = configuration.getAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_FILE,
(String) null);
- if (file != null) {
- IStringVariableManager stringVariableManager =
VariablesPlugin.getDefault().getStringVariableManager();
- file = stringVariableManager.performStringSubstitution(file);
- append =
configuration.getAttribute(IDebugUIConstants.ATTR_APPEND_TO_FILE, false);
- }
- } catch (CoreException e) {
- }
- }
-
- if (file != null && configuration != null) {
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- IWorkspaceRoot root = workspace.getRoot();
- Path path = new Path(file);
- IFile ifile = root.getFileForLocation(path);
- String message = null;
-
- try {
- String fileLoc = null;
- if (ifile != null) {
- if (append && ifile.exists()) {
- ifile.appendContents(new ByteArrayInputStream(new byte[0]), true,
true, new NullProgressMonitor());
- } else {
- if (ifile.exists()) {
- ifile.delete(true, new NullProgressMonitor());
- }
- ifile.create(new ByteArrayInputStream(new byte[0]), true, new
NullProgressMonitor());
- }
- }
-
- File outputFile = new File(file);
- fFileOutputStream = new FileOutputStream(outputFile, append);
- fileLoc = outputFile.getAbsolutePath();
-
- message = MessageFormat.format(ConsoleMessages.ProcessConsole_1, new
String[] {fileLoc});
- addPatternMatchListener(new ConsoleLogFilePatternMatcher(fileLoc));
- } catch (FileNotFoundException e) {
- message = MessageFormat.format(ConsoleMessages.ProcessConsole_2, new
String[] {file});
- } catch (CoreException e) {
- DebugUIPlugin.log(e);
- }
- if (message != null) {
- try {
- IOConsoleOutputStream stream = newOutputStream();
- stream.write(message);
- stream.close();
- } catch (IOException e) {
- DebugUIPlugin.log(e);
- }
- }
- try {
- fAllocateConsole =
configuration.getAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_CONSOLE, true);
- } catch (CoreException e) {
- }
- }
-
- fColorProvider = colorProvider;
- fInput = getInputStream();
- colorProvider.connect(fProcess, this);
-
- setName(computeName());
-
- Color color =
fColorProvider.getColor(IDebugUIConstants.ID_STANDARD_INPUT_STREAM);
- fInput.setColor(color);
-
- IConsoleLineTracker[] lineTrackers =
DebugUIPlugin.getDefault().getProcessConsoleManager().getLineTrackers(process);
- if (lineTrackers.length > 0) {
- addPatternMatchListener(new ConsoleLineNotifier());
- }
- }
-
- /**
- * Computes and returns the image descriptor for this console.
- *
- * @return an image descriptor for this console or <code>null</code>
- */
- protected ImageDescriptor computeImageDescriptor() {
- ILaunchConfiguration configuration =
getProcess().getLaunch().getLaunchConfiguration();
- if (configuration != null) {
- ILaunchConfigurationType type;
- try {
- type = configuration.getType();
- return DebugPluginImages.getImageDescriptor(type.getIdentifier());
- } catch (CoreException e) {
- DebugUIPlugin.log(e);
- }
- }
- return null;
- }
-
- /**
- * Computes and returns the current name of this console.
- *
- * @return a name for this console
- */
- protected String computeName() {
- String label = null;
- IProcess process = getProcess();
- ILaunchConfiguration config = process.getLaunch().getLaunchConfiguration();
-
- label = process.getAttribute(IProcess.ATTR_PROCESS_LABEL);
- if (label == null) {
- if (config == null) {
- label = process.getLabel();
- } else {
- // check if PRIVATE config
- if (DebugUITools.isPrivate(config)) {
- label = process.getLabel();
- } else {
- String type = null;
- try {
- type = config.getType().getName();
- } catch (CoreException e) {
- }
- StringBuffer buffer = new StringBuffer();
- buffer.append(config.getName());
- if (type != null) {
- buffer.append(" ["); //$NON-NLS-1$
- buffer.append(type);
- buffer.append("] "); //$NON-NLS-1$
- }
- buffer.append(process.getLabel());
- label = buffer.toString();
- }
- }
- }
-
- if (process.isTerminated()) {
- return MessageFormat.format(ConsoleMessages.ProcessConsole_0, new String[] {
label });
- }
- return label;
- }
-
- /**
- * @see
org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
- */
- public void propertyChange(PropertyChangeEvent evt) {
- String property = evt.getProperty();
- IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
- if (property.equals(IDebugPreferenceConstants.CONSOLE_WRAP) ||
property.equals(IDebugPreferenceConstants.CONSOLE_WIDTH)) {
- boolean fixedWidth =
store.getBoolean(IDebugPreferenceConstants.CONSOLE_WRAP);
- if (fixedWidth) {
- int width = store.getInt(IDebugPreferenceConstants.CONSOLE_WIDTH);
- setConsoleWidth(width);
- } else {
- setConsoleWidth(-1);
- }
- } else if
(property.equals(IDebugPreferenceConstants.CONSOLE_LIMIT_CONSOLE_OUTPUT) ||
property.equals(IDebugPreferenceConstants.CONSOLE_HIGH_WATER_MARK) ||
property.equals(IDebugPreferenceConstants.CONSOLE_LOW_WATER_MARK)) {
- boolean limitBufferSize =
store.getBoolean(IDebugPreferenceConstants.CONSOLE_LIMIT_CONSOLE_OUTPUT);
- if (limitBufferSize) {
- int highWater =
store.getInt(IDebugPreferenceConstants.CONSOLE_HIGH_WATER_MARK);
- int lowWater =
store.getInt(IDebugPreferenceConstants.CONSOLE_LOW_WATER_MARK);
- if (highWater > lowWater) {
- setWaterMarks(lowWater, highWater);
- }
- } else {
- setWaterMarks(-1, -1);
- }
- } else if (property.equals(IDebugPreferenceConstants.CONSOLE_TAB_WIDTH)) {
- int tabWidth = store.getInt(IDebugPreferenceConstants.CONSOLE_TAB_WIDTH);
- setTabWidth(tabWidth);
- } else if (property.equals(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT)) {
- boolean activateOnOut =
store.getBoolean(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT);
- IOConsoleOutputStream stream =
getStream(IDebugUIConstants.ID_STANDARD_OUTPUT_STREAM);
- if (stream != null) {
-// stream.setActivateOnWrite(activateOnOut);
- }
- } else if (property.equals(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR)) {
- boolean activateOnErr =
store.getBoolean(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR);
- IOConsoleOutputStream stream =
getStream(IDebugUIConstants.ID_STANDARD_ERROR_STREAM);
- if (stream != null) {
-// stream.setActivateOnWrite(activateOnErr);
- }
- } else if (property.equals(IDebugPreferenceConstants.CONSOLE_SYS_OUT_COLOR)) {
- IOConsoleOutputStream stream =
getStream(IDebugUIConstants.ID_STANDARD_OUTPUT_STREAM);
- if (stream != null) {
-
stream.setColor(fColorProvider.getColor(IDebugUIConstants.ID_STANDARD_OUTPUT_STREAM));
- }
- } else if (property.equals(IDebugPreferenceConstants.CONSOLE_SYS_ERR_COLOR)) {
- IOConsoleOutputStream stream =
getStream(IDebugUIConstants.ID_STANDARD_ERROR_STREAM);
- if (stream != null) {
-
stream.setColor(fColorProvider.getColor(IDebugUIConstants.ID_STANDARD_ERROR_STREAM));
- }
- } else if (property.equals(IDebugPreferenceConstants.CONSOLE_SYS_IN_COLOR)) {
- if (fInput != null) {
-
fInput.setColor(fColorProvider.getColor(IDebugUIConstants.ID_STANDARD_INPUT_STREAM));
- }
- } else if (property.equals(IDebugUIConstants.PREF_CONSOLE_FONT)) {
- setFont(JFaceResources.getFont(IDebugUIConstants.PREF_CONSOLE_FONT));
- } else if (property.equals(IDebugPreferenceConstants.CONSOLE_BAKGROUND_COLOR)) {
-
setBackground(DebugUIPlugin.getPreferenceColor(IDebugPreferenceConstants.CONSOLE_BAKGROUND_COLOR));
- }
- }
-
- /**
- * @see org.eclipse.debug.ui.console.IConsole#getStream(java.lang.String)
- */
- public IOConsoleOutputStream getStream(String streamIdentifier) {
- for (Iterator i = fStreamListeners.iterator(); i.hasNext();) {
- StreamListener listener = (StreamListener) i.next();
- if (listener.fStreamId.equals(streamIdentifier)) {
- return listener.fStream;
- }
- }
- return null;
- }
-
- /**
- * @see org.eclipse.debug.ui.console.IConsole#getProcess()
- */
- public IProcess getProcess() {
- return fProcess;
- }
-
- /**
- * @see org.eclipse.ui.console.IOConsole#dispose()
- */
- protected void dispose() {
- super.dispose();
- fColorProvider.disconnect();
- closeStreams();
- disposeStreams();
- DebugPlugin.getDefault().removeDebugEventListener(this);
-
DebugUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this);
- JFaceResources.getFontRegistry().removeListener(this);
- }
-
- /**
- * cleanup method to clsoe all of the open stream to this console
- */
- public synchronized void closeStreams() {
- if (fStreamsClosed) {
- return;
- }
- for (Iterator i = fStreamListeners.iterator(); i.hasNext();) {
- StreamListener listener = (StreamListener) i.next();
- listener.closeStream();
- }
- if (fFileOutputStream != null) {
- synchronized (fFileOutputStream) {
- try {
- fFileOutputStream.flush();
- fFileOutputStream.close();
- } catch (IOException e) {
- }
- }
- }
- try {
- fInput.close();
- } catch (IOException e) {
- }
- fStreamsClosed = true;
- }
-
- /**
- * disposes ofthe listeners for each of the stream associated with this console
- */
- private synchronized void disposeStreams() {
- for (Iterator i = fStreamListeners.iterator(); i.hasNext();) {
- StreamListener listener = (StreamListener) i.next();
- listener.dispose();
- }
- fFileOutputStream = null;
- fInput = null;
- }
-
- /**
- * @see org.eclipse.ui.console.AbstractConsole#init()
- */
- protected void init() {
- super.init();
- if (fProcess.isTerminated()) {
- closeStreams();
- resetName();
- } else {
- DebugPlugin.getDefault().addDebugEventListener(this);
- }
- IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
- store.addPropertyChangeListener(this);
- JFaceResources.getFontRegistry().addListener(this);
- if (store.getBoolean(IDebugPreferenceConstants.CONSOLE_WRAP)) {
- setConsoleWidth(store.getInt(IDebugPreferenceConstants.CONSOLE_WIDTH));
- }
- setTabWidth(store.getInt(IDebugPreferenceConstants.CONSOLE_TAB_WIDTH));
-
- if (store.getBoolean(IDebugPreferenceConstants.CONSOLE_LIMIT_CONSOLE_OUTPUT)) {
- int highWater =
store.getInt(IDebugPreferenceConstants.CONSOLE_HIGH_WATER_MARK);
- int lowWater =
store.getInt(IDebugPreferenceConstants.CONSOLE_LOW_WATER_MARK);
- setWaterMarks(lowWater, highWater);
- }
-
- DebugUIPlugin.getStandardDisplay().asyncExec(new Runnable() {
- public void run() {
- setFont(JFaceResources.getFont(IDebugUIConstants.PREF_CONSOLE_FONT));
-
setBackground(DebugUIPlugin.getPreferenceColor(IDebugPreferenceConstants.CONSOLE_BAKGROUND_COLOR));
- }
- });
- }
-
- /**
- * Notify listeners when name changes.
- *
- * @see
org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(org.eclipse.debug.core.DebugEvent[])
- */
- public void handleDebugEvents(DebugEvent[] events) {
- for (int i = 0; i < events.length; i++) {
- DebugEvent event = events[i];
- if (event.getSource().equals(getProcess())) {
- if (event.getKind() == DebugEvent.TERMINATE) {
- closeStreams();
- DebugPlugin.getDefault().removeDebugEventListener(this);
- }
- resetName();
- }
- }
- }
-
- /**
- * resets the name of this console to the original computed name
- */
- private void resetName() {
- final String newName = computeName();
- String name = getName();
- if (!name.equals(newName)) {
- UIJob job = new UIJob("Update console title") { //$NON-NLS-1$
- public IStatus runInUIThread(IProgressMonitor monitor) {
- Console.this.setName(newName);
- warnOfContentChange();
- return Status.OK_STATUS;
- }
- };
- job.setSystem(true);
- job.schedule();
- }
- }
-
- /**
- * send notification of a change of content in this console
- */
- private void warnOfContentChange() {
-
ConsolePlugin.getDefault().getConsoleManager().warnOfContentChange(DebugUITools.getConsole(fProcess));
- }
-
- /**
- * @see
org.eclipse.debug.ui.console.IConsole#connect(org.eclipse.debug.core.model.IStreamsProxy)
- */
- public void connect(IStreamsProxy streamsProxy) {
- IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
- IStreamMonitor streamMonitor = streamsProxy.getErrorStreamMonitor();
- if (streamMonitor != null) {
- connect(streamMonitor, IDebugUIConstants.ID_STANDARD_ERROR_STREAM,
- store.getBoolean(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR));
- }
- streamMonitor = streamsProxy.getOutputStreamMonitor();
- if (streamMonitor != null) {
- connect(streamMonitor, IDebugUIConstants.ID_STANDARD_OUTPUT_STREAM,
- store.getBoolean(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT));
- }
- if (inputReadJob == null) {
- inputReadJob = new InputReadJob(streamsProxy);
- }
- inputReadJob.setSystem(true);
- inputReadJob.schedule();
-// InputReadJob readJob = new InputReadJob(streamsProxy);
-// readJob.setSystem(true);
-// readJob.schedule();
- }
-
- public Job getInputReadJob() {
- return inputReadJob;
- }
-
- /**
- * @see
org.eclipse.debug.ui.console.IConsole#connect(org.eclipse.debug.core.model.IStreamMonitor,
java.lang.String)
- */
- public void connect(IStreamMonitor streamMonitor, String streamIdentifier) {
- connect(streamMonitor, streamIdentifier, false);
- }
-
- /**
- * Connects the given stream monitor to a new output stream with the given
identifier.
- *
- * @param streamMonitor stream monitor
- * @param streamIdentifier stream identifier
- * @param activateOnWrite whether the stream should displayed when written to
- */
- private void connect(IStreamMonitor streamMonitor, String streamIdentifier, boolean
activateOnWrite) {
- IOConsoleOutputStream stream = null;
- if (fAllocateConsole) {
- stream = newOutputStream();
- Color color = fColorProvider.getColor(streamIdentifier);
- stream.setColor(color);
-// stream.setActivateOnWrite(activateOnWrite);
- }
- synchronized (streamMonitor) {
- StreamListener listener = new StreamListener(streamIdentifier, streamMonitor,
stream);
- fStreamListeners.add(listener);
- }
- }
-
- /**
- * @see
org.eclipse.debug.ui.console.IConsole#addLink(org.eclipse.debug.ui.console.IConsoleHyperlink,
int, int)
- */
- public void addLink(IConsoleHyperlink link, int offset, int length) {
- try {
- addHyperlink(link, offset, length);
- } catch (BadLocationException e) {
- DebugUIPlugin.log(e);
- }
- }
-
- /**
- * @see
org.eclipse.debug.ui.console.IConsole#addLink(org.eclipse.ui.console.IHyperlink, int,
int)
- */
- public void addLink(IHyperlink link, int offset, int length) {
- try {
- addHyperlink(link, offset, length);
- } catch (BadLocationException e) {
- DebugUIPlugin.log(e);
- }
- }
-
- /**
- * @see
org.eclipse.debug.ui.console.IConsole#getRegion(org.eclipse.debug.ui.console.IConsoleHyperlink)
- */
- public IRegion getRegion(IConsoleHyperlink link) {
- return super.getRegion(link);
- }
-
- /**
- * This class listens to a specified IO stream
- */
- private class StreamListener implements IStreamListener {
-
- private IOConsoleOutputStream fStream;
-
- private IStreamMonitor fStreamMonitor;
-
- private String fStreamId;
-
- private boolean fFlushed = false;
-
- private boolean fListenerRemoved = false;
-
- public StreamListener(String streamIdentifier, IStreamMonitor monitor,
IOConsoleOutputStream stream) {
- this.fStreamId = streamIdentifier;
- this.fStreamMonitor = monitor;
- this.fStream = stream;
- fStreamMonitor.addListener(this);
- //fix to bug 121454. Ensure that output to fast processes is processed.
- streamAppended(null, monitor);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.debug.core.IStreamListener#streamAppended(java.lang.String,
- * org.eclipse.debug.core.model.IStreamMonitor)
- */
- public void streamAppended(String text, IStreamMonitor monitor) {
- String encoding = getEncoding();
- if (fFlushed) {
- try {
- if (fStream != null) {
- if (encoding == null)
- fStream.write(text);
- else
- fStream.write(text.getBytes(encoding));
- }
- if (fFileOutputStream != null) {
- synchronized (fFileOutputStream) {
- if (encoding == null)
- fFileOutputStream.write(text.getBytes());
- else
- fFileOutputStream.write(text.getBytes(encoding));
- }
- }
- } catch (IOException e) {
- DebugUIPlugin.log(e);
- }
- } else {
- String contents = null;
- synchronized (fStreamMonitor) {
- fFlushed = true;
- contents = fStreamMonitor.getContents();
- if (fStreamMonitor instanceof IFlushableStreamMonitor) {
- IFlushableStreamMonitor m = (IFlushableStreamMonitor)
fStreamMonitor;
- m.flushContents();
- m.setBuffered(false);
- }
- }
- try {
- if (contents != null && contents.length() > 0) {
- if (fStream != null) {
- fStream.write(contents);
- }
- if (fFileOutputStream != null) {
- synchronized (fFileOutputStream) {
- fFileOutputStream.write(contents.getBytes());
- }
- }
- }
- } catch (IOException e) {
- DebugUIPlugin.log(e);
- }
- }
- }
-
- public void closeStream() {
- if (fStreamMonitor == null) {
- return;
- }
- synchronized (fStreamMonitor) {
- fStreamMonitor.removeListener(this);
- if (!fFlushed) {
- String contents = fStreamMonitor.getContents();
- streamAppended(contents, fStreamMonitor);
- }
- fListenerRemoved = true;
- try {
- if (fStream != null) {
- fStream.close();
- }
- } catch (IOException e) {
- }
- }
- }
-
- public void dispose() {
- if (!fListenerRemoved) {
- closeStream();
- }
- fStream = null;
- fStreamMonitor = null;
- fStreamId = null;
- }
- }
-
- private class InputReadJob extends Job {
-
- private IStreamsProxy streamsProxy;
-
- InputReadJob(IStreamsProxy streamsProxy) {
- super("Forge Console Input Job"); //$NON-NLS-1$
- this.streamsProxy = streamsProxy;
- }
-
- protected IStatus run(IProgressMonitor monitor) {
- try {
- byte[] b = new byte[1024];
- int read = 0;
- while (fInput != null && read >= 0) {
- read = fInput.read(b);
- if (read > 0) {
- String s = new String(b, 0, read);
- streamsProxy.write(s);
- }
- }
- } catch (IOException e) {
- DebugUIPlugin.log(e);
- }
- return Status.OK_STATUS;
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.console.IConsole#getImageDescriptor()
- */
- public ImageDescriptor getImageDescriptor() {
- if (super.getImageDescriptor() == null) {
- setImageDescriptor(computeImageDescriptor());
- }
- return super.getImageDescriptor();
- }
-
- private class ConsoleLogFilePatternMatcher implements IPatternMatchListener {
- String fFilePath;
-
- public ConsoleLogFilePatternMatcher(String filePath) {
- fFilePath = escape(filePath);
- }
-
- private String escape(String path) {
- StringBuffer buffer = new StringBuffer(path);
- int index = buffer.indexOf("\\"); //$NON-NLS-1$
- while (index >= 0) {
- buffer.insert(index, '\\');
- index = buffer.indexOf("\\", index+2); //$NON-NLS-1$
- }
- return buffer.toString();
- }
-
- public String getPattern() {
- return fFilePath;
- }
-
- public void matchFound(PatternMatchEvent event) {
- try {
- addHyperlink(new ConsoleLogFileHyperlink(fFilePath), event.getOffset(),
event.getLength());
- removePatternMatchListener(this);
- } catch (BadLocationException e) {
- }
- }
-
- public int getCompilerFlags() {
- return 0;
- }
-
- public String getLineQualifier() {
- return null;
- }
-
- public void connect(TextConsole console) {
- }
-
- public void disconnect() {
- }
- }
-
- private class ConsoleLogFileHyperlink implements IHyperlink {
- String fFilePath;
- ConsoleLogFileHyperlink(String filePath) {
- fFilePath = filePath;
- }
-
- public void linkActivated() {
- IEditorInput input;
- Path path = new Path(fFilePath);
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- IFile ifile = root.getFileForLocation(path);
- if (ifile == null) { // The file is not in the workspace
- File file = new File(fFilePath);
- LocalFileStorage lfs = new LocalFileStorage(file);
- input = new StorageEditorInput(lfs, file);
-
- } else {
- input = new FileEditorInput(ifile);
- }
-
- IWorkbenchPage activePage =
DebugUIPlugin.getActiveWorkbenchWindow().getActivePage();
- try {
- activePage.openEditor(input, EditorsUI.DEFAULT_TEXT_EDITOR_ID, true);
- } catch (PartInitException e) {
- }
- }
- public void linkEntered() {
- }
- public void linkExited() {
- }
- }
-
- class StorageEditorInput extends PlatformObject implements IStorageEditorInput {
- private File fFile;
- private IStorage fStorage;
-
- public StorageEditorInput(IStorage storage, File file) {
- fStorage = storage;
- fFile = file;
- }
-
- public IStorage getStorage() {
- return fStorage;
- }
-
- public ImageDescriptor getImageDescriptor() {
- return null;
- }
-
- public String getName() {
- return getStorage().getName();
- }
-
- public IPersistableElement getPersistable() {
- return null;
- }
-
- public String getToolTipText() {
- return getStorage().getFullPath().toOSString();
- }
-
- public boolean equals(Object object) {
- return object instanceof StorageEditorInput &&
- getStorage().equals(((StorageEditorInput)object).getStorage());
- }
-
- public int hashCode() {
- return getStorage().hashCode();
- }
-
- public boolean exists() {
- return fFile.exists();
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.console.AbstractConsole#getHelpContextId()
- */
- public String getHelpContextId() {
- return IDebugHelpContextIds.PROCESS_CONSOLE;
- }
-}
Deleted:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/ConsoleLineNotifier.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/ConsoleLineNotifier.java 2011-01-24
21:17:45 UTC (rev 28583)
+++
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/ConsoleLineNotifier.java 2011-01-24
21:43:26 UTC (rev 28584)
@@ -1,151 +0,0 @@
-package org.jboss.tools.seam.forge.view;
-
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.debug.internal.ui.DebugUIPlugin;
-import org.eclipse.debug.ui.console.IConsoleLineTracker;
-import org.eclipse.debug.ui.console.IConsoleLineTrackerExtension;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.ui.console.IConsoleConstants;
-import org.eclipse.ui.console.IPatternMatchListener;
-import org.eclipse.ui.console.PatternMatchEvent;
-import org.eclipse.ui.console.TextConsole;
-
-/**
- * Tracks text appended to the console and notifies listeners in terms of whole
- * lines.
- */
-public class ConsoleLineNotifier implements IPatternMatchListener,
IPropertyChangeListener {
- /**
- * Console listeners
- */
- private List fListeners = new ArrayList(2);
-
- /**
- * The console this notifier is tracking
- */
- private Console fConsole = null;
-
- /* (non-Javadoc)
- * @see
org.eclipse.ui.console.IPatternMatchListenerDelegate#connect(org.eclipse.ui.console.TextConsole)
- */
- public void connect(TextConsole console) {
- if (console instanceof Console) {
- fConsole = (Console)console;
-
- IConsoleLineTracker[] lineTrackers =
DebugUIPlugin.getDefault().getProcessConsoleManager().getLineTrackers(fConsole.getProcess());
- for (int i = 0; i < lineTrackers.length; i++) {
- lineTrackers[i].init(fConsole);
- addConsoleListener(lineTrackers[i]);
- }
-
- fConsole.addPropertyChangeListener(this);
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.console.IPatternMatchListener#disconnect()
- */
- public synchronized void disconnect() {
- try {
- IDocument document = fConsole.getDocument();
- if (document != null) {
- int lastLine = document.getNumberOfLines() - 1;
- if (document.getLineDelimiter(lastLine) == null) {
- IRegion lineInformation = document.getLineInformation(lastLine);
- lineAppended(lineInformation);
- }
- }
- } catch (BadLocationException e) {
- }
- }
-
- /**
- * Notification the console's streams have been closed
- */
- public synchronized void consoleClosed() {
- int size = fListeners.size();
- for (int i = 0; i < size; i++) {
- IConsoleLineTracker tracker = (IConsoleLineTracker) fListeners.get(i);
- if (tracker instanceof IConsoleLineTrackerExtension) {
- ((IConsoleLineTrackerExtension) tracker).consoleClosed();
- }
- tracker.dispose();
- }
-
- fConsole = null;
- fListeners = null;
- }
-
- /**
- * Adds the given listener to the list of listeners notified when a line of
- * text is appended to the console.
- *
- * @param listener
- */
- public void addConsoleListener(IConsoleLineTracker listener) {
- if (!fListeners.contains(listener))
- fListeners.add(listener);
- }
-
- /* (non-Javadoc)
- * @see
org.eclipse.ui.console.IPatternMatchListener#matchFound(org.eclipse.ui.console.PatternMatchEvent)
- */
- public void matchFound(PatternMatchEvent event) {
- try {
- IDocument document = fConsole.getDocument();
- int lineOfOffset = document.getLineOfOffset(event.getOffset());
- String delimiter = document.getLineDelimiter(lineOfOffset);
- int strip = delimiter==null ? 0 : delimiter.length();
- Region region = new Region(event.getOffset(), event.getLength()-strip);
- lineAppended(region);
- } catch (BadLocationException e) {}
- }
-
- public void lineAppended(IRegion region) {
- int size = fListeners.size();
- for (int i=0; i<size; i++) {
- IConsoleLineTracker tracker = (IConsoleLineTracker) fListeners.get(i);
- tracker.lineAppended(region);
- }
- }
-
- /* (non-Javadoc)
- * @see
org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
- */
- public void propertyChange(PropertyChangeEvent event) {
- if(event.getProperty().equals(IConsoleConstants.P_CONSOLE_OUTPUT_COMPLETE)) {
- fConsole.removePropertyChangeListener(this);
- consoleClosed();
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.console.IPatternMatchListener#getPattern()
- */
- public String getPattern() {
- return ".*\\r(\\n?)|.*\\n"; //$NON-NLS-1$
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.console.IPatternMatchListener#getCompilerFlags()
- */
- public int getCompilerFlags() {
- return 0;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.console.IPatternMatchListener#getLineQualifier()
- */
- public String getLineQualifier() {
- return "\\n|\\r"; //$NON-NLS-1$
- }
-
-}
Modified:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/ConsolePage.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/ConsolePage.java 2011-01-24
21:17:45 UTC (rev 28583)
+++
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/ConsolePage.java 2011-01-24
21:43:26 UTC (rev 28584)
@@ -1,11 +1,10 @@
package org.jboss.tools.seam.forge.view;
-import org.eclipse.debug.ui.console.ConsoleColorProvider;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.console.TextConsoleViewer;
-import org.eclipse.ui.internal.console.IOConsoleViewer;
import org.eclipse.ui.part.Page;
+import org.jboss.tools.seam.forge.console.Console;
import org.jboss.tools.seam.forge.runtime.Manager;
public class ConsolePage extends Page {
@@ -15,8 +14,8 @@
@Override
public void createControl(Composite parent) {
- console = new Console(Manager.INSTANCE.getProcess(), new ConsoleColorProvider());
- viewer = new IOConsoleViewer(parent, console);
+ console = new Console(Manager.INSTANCE.getProcess());
+ viewer = new ConsoleViewer(parent, console);
console.initialize();
}
Modified:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/ConsoleView.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/ConsoleView.java 2011-01-24
21:17:45 UTC (rev 28583)
+++
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/ConsoleView.java 2011-01-24
21:43:26 UTC (rev 28584)
@@ -3,18 +3,16 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
-import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.DebugPlugin;
-import org.eclipse.debug.internal.ui.views.console.ProcessConsole;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.MessagePage;
import org.eclipse.ui.part.PageBook;
import org.eclipse.ui.part.PageSite;
import org.eclipse.ui.part.ViewPart;
+import org.jboss.tools.seam.forge.console.Console;
import org.jboss.tools.seam.forge.runtime.Manager;
public class ConsoleView extends ViewPart implements PropertyChangeListener {
Added:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/ConsoleViewer.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/ConsoleViewer.java
(rev 0)
+++
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/ConsoleViewer.java 2011-01-24
21:43:26 UTC (rev 28584)
@@ -0,0 +1,113 @@
+package org.jboss.tools.seam.forge.view;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentListener;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.console.ConsolePlugin;
+import org.eclipse.ui.console.IConsoleDocumentPartitioner;
+import org.eclipse.ui.console.TextConsole;
+import org.eclipse.ui.console.TextConsoleViewer;
+
+public class ConsoleViewer extends TextConsoleViewer {
+
+ private boolean fAutoScroll = true;
+
+ private IDocumentListener fDocumentListener;
+
+ public ConsoleViewer(Composite parent, TextConsole console) {
+ super(parent, console);
+ }
+
+ public boolean isAutoScroll() {
+ return fAutoScroll;
+ }
+
+ public void setAutoScroll(boolean scroll) {
+ fAutoScroll = scroll;
+ }
+
+ protected void handleVerifyEvent(VerifyEvent e) {
+ IDocument doc = getDocument();
+ String[] legalLineDelimiters = doc.getLegalLineDelimiters();
+ String eventString = e.text;
+ try {
+ IConsoleDocumentPartitioner partitioner = (IConsoleDocumentPartitioner)
doc.getDocumentPartitioner();
+ if (!partitioner.isReadOnly(e.start)) {
+ boolean isCarriageReturn = false;
+ for (int i = 0; i < legalLineDelimiters.length; i++) {
+ if (e.text.equals(legalLineDelimiters[i])) {
+ isCarriageReturn = true;
+ break;
+ }
+ }
+
+ if (!isCarriageReturn) {
+ super.handleVerifyEvent(e);
+ return;
+ }
+ }
+
+ int length = doc.getLength();
+ if (e.start == length) {
+ super.handleVerifyEvent(e);
+ } else {
+ try {
+ doc.replace(length, 0, eventString);
+ } catch (BadLocationException e1) {
+ }
+ e.doit = false;
+ }
+ } finally {
+ StyledText text = (StyledText) e.widget;
+ text.setCaretOffset(text.getCharCount());
+ }
+ }
+
+ public void setReadOnly() {
+ ConsolePlugin.getStandardDisplay().asyncExec(new Runnable() {
+ public void run() {
+ StyledText text = getTextWidget();
+ if (text != null && !text.isDisposed()) {
+ text.setEditable(false);
+ }
+ }
+ });
+ }
+
+ public boolean isReadOnly() {
+ return !getTextWidget().getEditable();
+ }
+
+ public void setDocument(IDocument document) {
+ IDocument oldDocument= getDocument();
+
+ super.setDocument(document);
+
+ if (oldDocument != null) {
+ oldDocument.removeDocumentListener(getDocumentListener());
+ }
+ if (document != null) {
+ document.addDocumentListener(getDocumentListener());
+ }
+ }
+
+ private IDocumentListener getDocumentListener() {
+ if (fDocumentListener == null) {
+ fDocumentListener= new IDocumentListener() {
+ public void documentAboutToBeChanged(DocumentEvent event) {
+ }
+
+ public void documentChanged(DocumentEvent event) {
+ if (fAutoScroll) {
+ revealEndOfDocument();
+ }
+ }
+ };
+ }
+ return fDocumentListener;
+ }
+}
Property changes on:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/view/ConsoleViewer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain