diff options
author | Darin Swanson | 2003-09-12 18:00:56 +0000 |
---|---|---|
committer | Darin Swanson | 2003-09-12 18:00:56 +0000 |
commit | da3fa8a02b788da7915ffe18135656fca89ad72d (patch) | |
tree | 08293cfd76ae5066ea6f19b7646fac7fd5764814 | |
parent | 7934f747b45a68c2dfe5304311b6126bbff6748e (diff) | |
download | eclipse.platform.debug-da3fa8a02b788da7915ffe18135656fca89ad72d.tar.gz eclipse.platform.debug-da3fa8a02b788da7915ffe18135656fca89ad72d.tar.xz eclipse.platform.debug-da3fa8a02b788da7915ffe18135656fca89ad72d.zip |
Bug 37263 - Support for generic console
39 files changed, 3245 insertions, 40 deletions
diff --git a/org.eclipse.ui.console/.classpath b/org.eclipse.ui.console/.classpath index 7ad3a20bb..d2cdb1bc5 100644 --- a/org.eclipse.ui.console/.classpath +++ b/org.eclipse.ui.console/.classpath @@ -5,5 +5,6 @@ <classpathentry kind="src" path="/org.eclipse.ui"/> <classpathentry kind="src" path="/org.eclipse.core.runtime"/> <classpathentry kind="src" path="/org.eclipse.core.boot"/> + <classpathentry kind="src" path="/org.eclipse.jface.text"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/org.eclipse.ui.console/.project b/org.eclipse.ui.console/.project index 76978fa7b..f33fa8688 100644 --- a/org.eclipse.ui.console/.project +++ b/org.eclipse.ui.console/.project @@ -5,6 +5,7 @@ <projects> <project>org.eclipse.core.boot</project> <project>org.eclipse.core.runtime</project> + <project>org.eclipse.jface.text</project> <project>org.eclipse.ui</project> </projects> <buildSpec> diff --git a/org.eclipse.ui.console/icons/full/clcl16/clear_co.gif b/org.eclipse.ui.console/icons/full/clcl16/clear_co.gif Binary files differnew file mode 100644 index 000000000..255832653 --- /dev/null +++ b/org.eclipse.ui.console/icons/full/clcl16/clear_co.gif diff --git a/org.eclipse.ui.console/icons/full/clcl16/pin.gif b/org.eclipse.ui.console/icons/full/clcl16/pin.gif Binary files differnew file mode 100644 index 000000000..9997124ca --- /dev/null +++ b/org.eclipse.ui.console/icons/full/clcl16/pin.gif diff --git a/org.eclipse.ui.console/icons/full/cview16/console_view.gif b/org.eclipse.ui.console/icons/full/cview16/console_view.gif Binary files differnew file mode 100644 index 000000000..e6d5b138d --- /dev/null +++ b/org.eclipse.ui.console/icons/full/cview16/console_view.gif diff --git a/org.eclipse.ui.console/icons/full/dlcl16/clear_co.gif b/org.eclipse.ui.console/icons/full/dlcl16/clear_co.gif Binary files differnew file mode 100644 index 000000000..d873c49b8 --- /dev/null +++ b/org.eclipse.ui.console/icons/full/dlcl16/clear_co.gif diff --git a/org.eclipse.ui.console/icons/full/dlcl16/pin.gif b/org.eclipse.ui.console/icons/full/dlcl16/pin.gif Binary files differnew file mode 100644 index 000000000..e2e1b463d --- /dev/null +++ b/org.eclipse.ui.console/icons/full/dlcl16/pin.gif diff --git a/org.eclipse.ui.console/icons/full/elcl16/clear_co.gif b/org.eclipse.ui.console/icons/full/elcl16/clear_co.gif Binary files differnew file mode 100644 index 000000000..6faf8d66f --- /dev/null +++ b/org.eclipse.ui.console/icons/full/elcl16/clear_co.gif diff --git a/org.eclipse.ui.console/icons/full/elcl16/pin.gif b/org.eclipse.ui.console/icons/full/elcl16/pin.gif Binary files differnew file mode 100644 index 000000000..9d247759c --- /dev/null +++ b/org.eclipse.ui.console/icons/full/elcl16/pin.gif diff --git a/org.eclipse.ui.console/icons/full/eview16/console_view.gif b/org.eclipse.ui.console/icons/full/eview16/console_view.gif Binary files differnew file mode 100644 index 000000000..f60aba167 --- /dev/null +++ b/org.eclipse.ui.console/icons/full/eview16/console_view.gif diff --git a/org.eclipse.ui.console/plugin.properties b/org.eclipse.ui.console/plugin.properties index b6439b0a5..93f0ceef3 100644 --- a/org.eclipse.ui.console/plugin.properties +++ b/org.eclipse.ui.console/plugin.properties @@ -10,4 +10,8 @@ ############################################################################### pluginName=Console -providerName=Eclipse.org
\ No newline at end of file +providerName=Eclipse.org +ConsoleView.name=Console + +ConsoleFontDefinition.description= The console text font is used by the generic console +ConsoleFontDefinition.label= Console Text Font
\ No newline at end of file diff --git a/org.eclipse.ui.console/plugin.xml b/org.eclipse.ui.console/plugin.xml index 753763e47..5ee5968a1 100644 --- a/org.eclipse.ui.console/plugin.xml +++ b/org.eclipse.ui.console/plugin.xml @@ -1,21 +1,43 @@ <?xml version="1.0" encoding="UTF-8"?> <plugin - id="org.eclipse.ui.console" - name="%pluginName" - version="3.0.0" - provider-name="%providerName" - class="org.eclipse.ui.internal.console.ConsolePlugin"> + id="org.eclipse.ui.console" + name="%pluginName" + version="3.0.0" + provider-name="%providerName" + class="org.eclipse.ui.console.ConsolePlugin"> - <runtime> - <library name="console.jar"> - <export name="*"/> - <packages prefixes="org.eclipse.ui.console, org.eclipse.ui.internal.console"/> - </library> - </runtime> - <requires> - <import plugin="org.apache.xerces"/> - <import plugin="org.eclipse.core.resources"/> - <import plugin="org.eclipse.ui"/> - <import plugin="org.eclipse.help"/> + <runtime> + <library name="console.jar"> + <export name="*"/> + <packages prefixes="org.eclipse.ui.console, org.eclipse.ui.internal.console"/> + </library> + </runtime> + <requires> + <import plugin="org.apache.xerces"/> + <import plugin="org.eclipse.core.resources"/> + <import plugin="org.eclipse.ui"/> + <import plugin="org.eclipse.jface.text"/> + <import plugin="org.eclipse.help"/> </requires> + <extension + point="org.eclipse.ui.views"> + <view + name="%ConsoleView.name" + icon="icons/full/cview16/console_view.gif" + category="org.eclipse.ui" + class="org.eclipse.ui.internal.console.ConsoleView" + id="org.eclipse.ui.console.ConsoleView"> + </view> + </extension> + <extension + point="org.eclipse.ui.fontDefinitions"> + <fontDefinition + label="%ConsoleFontDefinition.label" + defaultsTo="org.eclipse.jface.textfont" + id="org.eclipse.ui.console.ConsoleFont"> + <description> + %ConsoleFontDefinition.description + </description> + </fontDefinition> + </extension> </plugin> diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/console/AbstractConsole.java b/org.eclipse.ui.console/src/org/eclipse/ui/console/AbstractConsole.java new file mode 100644 index 000000000..a1ad3b799 --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/console/AbstractConsole.java @@ -0,0 +1,219 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.console; + +import org.eclipse.core.runtime.ISafeRunnable; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.ListenerList; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.jface.viewers.IBasicPropertyConstants; +import org.eclipse.ui.internal.console.ConsoleMessages; + +/** + * Common function for consoles. + * <p> + * Clients implementing consoles should subclass this class. + * </p> + * @since 3.0 + */ +public abstract class AbstractConsole implements IConsole { + + // property listeners + private ListenerList fListeners; + + /** + * Console name + */ + private String fName = null; + + /** + * Console image descriptor + */ + private ImageDescriptor fImageDescriptor = null; + + /** + * Used to notify this console of lifecycle methods <code>init()</code> + * and <code>dispose()</code>. + */ + class Lifecycle implements IConsoleListener { + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.console.IConsoleListener#consolesAdded(org.eclipse.debug.internal.ui.console.IConsole[]) + */ + public void consolesAdded(IConsole[] consoles) { + for (int i = 0; i < consoles.length; i++) { + IConsole console = consoles[i]; + if (console == AbstractConsole.this) { + init(); + } + } + + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.console.IConsoleListener#consolesRemoved(org.eclipse.debug.internal.ui.console.IConsole[]) + */ + public void consolesRemoved(IConsole[] consoles) { + for (int i = 0; i < consoles.length; i++) { + IConsole console = consoles[i]; + if (console == AbstractConsole.this) { + ConsolePlugin.getDefault().getConsoleManager().removeConsoleListener(this); + dispose(); + } + } + } + } + + /** + * Notifies listeners of property changes, handling any exceptions + */ + class PropertyNotifier implements ISafeRunnable { + + private IPropertyChangeListener fListener; + private PropertyChangeEvent fEvent; + + /** + * @see org.eclipse.core.runtime.ISafeRunnable#handleException(java.lang.Throwable) + */ + public void handleException(Throwable exception) { + IStatus status = new Status(IStatus.ERROR, ConsolePlugin.getUniqueIdentifier(), IConsoleConstants.INTERNAL_ERROR, ConsoleMessages.getString("AbstractConsole.0"), exception); //$NON-NLS-1$ + ConsolePlugin.log(status); + } + + /** + * @see org.eclipse.core.runtime.ISafeRunnable#run() + */ + public void run() throws Exception { + fListener.propertyChange(fEvent); + } + + /** + * Notifies listeners of the property change + * + * @param property the property that has changed + */ + public void notify(PropertyChangeEvent event) { + if (fListeners == null) { + return; + } + fEvent = event; + Object[] copiedListeners= fListeners.getListeners(); + for (int i= 0; i < copiedListeners.length; i++) { + fListener = (IPropertyChangeListener)copiedListeners[i]; + Platform.run(this); + } + fListener = null; + } + } + + /** + * Constructs a new console with the given name and image. + * + * @param name console name, cannot be <code>null</code> + * @param imageDescriptor image descriptor, or <code>null</code> if none + */ + public AbstractConsole(String name, ImageDescriptor imageDescriptor) { + setName(name); + setImageDescriptor(imageDescriptor); + ConsolePlugin.getDefault().getConsoleManager().addConsoleListener(new Lifecycle()); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.console.IConsole#getName() + */ + public String getName() { + return fName; + } + + /** + * Sets the name of this console to the specified value and notifies + * property listeners of the change. + * + * @param name the new name + */ + protected void setName(String name) { + String old = fName; + fName = name; + firePropertyChange(this, IBasicPropertyConstants.P_TEXT, old, name); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.console.IConsole#getImageDescriptor() + */ + public ImageDescriptor getImageDescriptor() { + return fImageDescriptor; + } + + /** + * Sets the image descriptor for this console to the specified value and notifies + * property listeners of the change. + * + * @param imageDescriptor the new image descriptor + */ + protected void setImageDescriptor(ImageDescriptor imageDescriptor) { + ImageDescriptor old = fImageDescriptor; + fImageDescriptor =imageDescriptor; + firePropertyChange(this, IBasicPropertyConstants.P_IMAGE, old, imageDescriptor); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.console.IConsole#addPropertyChangeListener(IPropertyChangeListener) + */ + public void addPropertyChangeListener(IPropertyChangeListener listener) { + if (fListeners == null) { + fListeners = new ListenerList(); + } + fListeners.add(listener); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.console.IConsole#removePropertyChangeListener(IPropertyChangeListener) + */ + public void removePropertyChangeListener(IPropertyChangeListener listener) { + if (fListeners != null) { + fListeners.remove(listener); + } + } + + /** + * Notify all listeners that the given property has changed. + * + * @param source the object on which a property has changed + * @param property identifier of the property that has changed + * @param oldValue the old value of the property, or <code>null</code> + * @param newValue the new value of the property, or <code>null</code> + */ + public void firePropertyChange(Object source, String property, Object oldValue, Object newValue) { + if (fListeners == null) { + return; + } + PropertyNotifier notifier = new PropertyNotifier(); + notifier.notify(new PropertyChangeEvent(source, property, oldValue, newValue)); + } + + /** + * Called when this console is added to the console manager. Default + * implementation does nothing. Subclasses may override. + */ + protected void init() { + } + + /** + * Called when this console is removed from the console manager. Default + * implementation does nothing. Subclasses may override. + */ + protected void dispose() { + } +} diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/console/ConsolePlugin.java b/org.eclipse.ui.console/src/org/eclipse/ui/console/ConsolePlugin.java new file mode 100644 index 000000000..5ec0bfa90 --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/console/ConsolePlugin.java @@ -0,0 +1,133 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.ui.console; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPluginDescriptor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.internal.console.ConsoleManager; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +public class ConsolePlugin extends AbstractUIPlugin { + + /** + * Singleton console manager + */ + private IConsoleManager fConsoleManager = null; + + /** + * The singleton console plugin instance + */ + private static ConsolePlugin fgPlugin= null; + + /** + * Returns the singleton instance of the console plugin. + */ + public static ConsolePlugin getDefault() { + return fgPlugin; + } + + public ConsolePlugin(IPluginDescriptor descriptor) { + super(descriptor); + fgPlugin = this; + } + + /** + * Convenience method which returns the unique identifier of this plugin. + */ + public static String getUniqueIdentifier() { + if (getDefault() == null) { + // If the default instance is not yet initialized, + // return a static identifier. This identifier must + // match the plugin id defined in plugin.xml + return "org.eclipse.ui.console"; //$NON-NLS-1$ + } + return getDefault().getDescriptor().getUniqueIdentifier(); + } + + /** + * Logs the specified status with this plug-in's log. + * + * @param status status to log + */ + public static void log(IStatus status) { + getDefault().getLog().log(status); + } + + /** + * Logs the specified throwable with this plug-in's log. + * + * @param t throwable to log + */ + public static void log(Throwable t) { + log(newErrorStatus("Error logged from Debug UI: ", t)); //$NON-NLS-1$ + } + + /** + * Returns a new error status for this plugin with the given message + * @param message the message to be included in the status + * @param exception the exception to be included in the status or <code>null</code> if none + * @return a new error status + */ + public static IStatus newErrorStatus(String message, Throwable exception) { + return new Status(IStatus.ERROR, getUniqueIdentifier(), IConsoleConstants.INTERNAL_ERROR, message, exception); + } + + /** + * Returns the console manager. The manager will be created lazily on + * the first access. + * + * @return IConsoleManager + */ + public IConsoleManager getConsoleManager() { + if (fConsoleManager == null) { + fConsoleManager = new ConsoleManager(); + } + return fConsoleManager; + } + + /** + * Returns the standard display to be used. The method first checks, if + * the thread calling this method has an associated display. If so, this + * display is returned. Otherwise the method returns the default display. + */ + public static Display getStandardDisplay() { + Display display= Display.getCurrent(); + if (display == null) { + display= Display.getDefault(); + } + return display; + } + + /** + * Utility method with conventions + */ + public static void errorDialog(Shell shell, String title, String message, Throwable t) { + IStatus status; + if (t instanceof CoreException) { + status= ((CoreException)t).getStatus(); + // if the 'message' resource string and the IStatus' message are the same, + // don't show both in the dialog + if (status != null && message.equals(status.getMessage())) { + message= null; + } + } else { + status= new Status(IStatus.ERROR, getUniqueIdentifier(), IConsoleConstants.INTERNAL_ERROR, "Error within Debug UI: ", t); //$NON-NLS-1$ + log(status); + } + ErrorDialog.openError(shell, title, message, status); + } +} diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/console/IConsole.java b/org.eclipse.ui.console/src/org/eclipse/ui/console/IConsole.java new file mode 100644 index 000000000..935399eeb --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/console/IConsole.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.console; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.ui.part.IPageBookViewPage; + +/** + * A logical console. A console is commonly used to display messages. For example, + * a console may display the output streams of a system process. A console can be + * displayed by one or more views. + * <p> + * Clients may implement this interface. + * </p> + * @since 3.0 + */ +public interface IConsole { + + /** + * Returns the name of this console. + * + * @return the name of this console + */ + public String getName(); + + /** + * Returns an image descriptor for this console, or <code>null</code> + * if none. + * + * @return an image descriptor for this console, or <code>null</code> + * if none + */ + public ImageDescriptor getImageDescriptor(); + + /** + * Creates and returns a new page for this console. The page is displayed + * for this console in the console given view. + * + * @param view the view in which the page is to be created + * @return a page book view page representation of this console + */ + public IPageBookViewPage createPage(IConsoleView view); + + /** + * Adds a listener for changes to properties of this console. + * Has no effect if an identical listener is already registered. + * <p> + * The changes supported by the console view are as follows: + * <ul> + * <li><code>IBasicPropertyConstants.P_TEXT</code> - indicates the name + * of a console has changed</li> + * <li><code>IBasicPropertyConstants.P_IMAGE</code> - indicates the image + * of a console has changed</li> + * </ul> + * </p> + * <p> + * Clients may define additional properties as required. + * </p> + * + * @param listener a property change listener + */ + public void addPropertyChangeListener(IPropertyChangeListener listener); + + /** + * Removes the given property listener from this console page. + * Has no effect if an identical listener is not alread registered. + * + * @param listener a property listener + */ + public void removePropertyChangeListener(IPropertyChangeListener listener); + +} diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/console/IConsoleConstants.java b/org.eclipse.ui.console/src/org/eclipse/ui/console/IConsoleConstants.java new file mode 100644 index 000000000..a5fd5e50b --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/console/IConsoleConstants.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.ui.console; + +public interface IConsoleConstants { + + /** + * Consoleplug-in identifier (value <code>"org.eclipse.ui.console"</code>). + */ + public static final String PLUGIN_ID = ConsolePlugin.getUniqueIdentifier(); + + /** + * Console view identifier (value <code>"org.eclipse.ui.console.ConsoleView"</code>). + */ + public static final String ID_CONSOLE_VIEW= "org.eclipse.ui.console.ConsoleView"; //$NON-NLS-1$ + + /** + * The name of the font to use for the Console. + */ + public static final String CONSOLE_FONT= "org.eclipse.ui.console.ConsoleFont"; //$NON-NLS-1$ + + /** + * Identifier for a launch group in a menu (value <code>"launchGroup"</code>). + */ + public static final String LAUNCH_GROUP = "launchGroup"; //$NON-NLS-1$ + + /** + * Identifier for an output group in a menu (value + * <code>"outputGroup"</code>). + */ + public static final String OUTPUT_GROUP = "outputGroup"; //$NON-NLS-1$ + + /** + * Console view image identifier + * + */ + public static final String IMG_VIEW_CONSOLE= "IMG_VIEW_CONSOLE"; //$NON-NLS-1$ + + /** + * Clear action image identifier. + */ + public static final String IMG_LCL_CLEAR= "IMG_LCL_CLEAR"; //$NON-NLS-1$ + + /** + * Status code indicating an unexpected internal error. + */ + public static final int INTERNAL_ERROR = 120; +} diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/console/IConsoleListener.java b/org.eclipse.ui.console/src/org/eclipse/ui/console/IConsoleListener.java new file mode 100644 index 000000000..7d22c8a21 --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/console/IConsoleListener.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.console; + +/** + * A console listener is notified when consoles are added or removed from + * the console manager. + * <p> + * Clients may implement this interface. + * </p> + * @since 3.0 + */ +public interface IConsoleListener { + + /** + * Notification the given consoles have been added to the console + * manager. + * + * @param consoles added consoles + */ + public void consolesAdded(IConsole[] consoles); + + /** + * Notification the given consoles have been removed from the + * console manager. + * + * @param consoles removed consoles + */ + public void consolesRemoved(IConsole[] consoles); + +} diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/console/IConsoleManager.java b/org.eclipse.ui.console/src/org/eclipse/ui/console/IConsoleManager.java new file mode 100644 index 000000000..1f2b7bb39 --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/console/IConsoleManager.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.console; + +/** + * Manages consoles. + * <p> + * Clients are not intended to implement this interface. + * </p> + * @since 3.0 + */ +public interface IConsoleManager { + + /** + * Registers the given listener for console notifications. Has + * no effect if an identical listener is already registered. + * + * @param listener listener to register + */ + public void addConsoleListener(IConsoleListener listener); + + /** + * Deregisters the given listener for console notifications. Has + * no effect if an identical listener is not already registered. + * + * @param listener listener to deregister + */ + public void removeConsoleListener(IConsoleListener listener); + + /** + * Adds the given consoles to the console manager. Has no effect for + * equivalent consoles already registered. The consoles will be added + * to any existing console views. + * + * @param consoles consoles to add + */ + public void addConsoles(IConsole[] consoles); + + /** + * Removes the given consoles from the console manager. If the consoles are + * being displayed in any console views, the associated pages will be closed. + * + * @param consoles consoles to remove + */ + public void removeConsoles(IConsole[] consoles); + + /** + * Returns a collection of consoles registered with the console manager. + * + * @return a collection of consoles registered with the console manager + */ + public IConsole[] getConsoles(); +} diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/console/IConsoleView.java b/org.eclipse.ui.console/src/org/eclipse/ui/console/IConsoleView.java new file mode 100644 index 000000000..8c4382ad1 --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/console/IConsoleView.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.console; + +import org.eclipse.ui.IViewPart; + +/** + * A view that displays consoles registered with the console manager. + * <p> + * Clients are not intended to implement this interface. + * </p> + * @since 3.0 + */ +public interface IConsoleView extends IViewPart { + + /** + * Displays the page for the given console in this console view. + * Has no effect if this console view has a pinned console. + * + * @param console console to display, cannot be <code>null</code> + */ + public void display(IConsole console); + + /** + * Displays and pins the given console in this console view. No + * other console can be displayed until this console view is + * un-pinned. Specifying <code>null</code> un-pins this console + * + * @param console console to pin, or <code>null</code> to un-pin + */ + public void pin(IConsole console); + + /** + * Returns whether this console view is currently pinned to a + * specific console. + * + * @return whether this console view is currently pinned to a + * specific console + */ + public boolean isPinned(); + + /** + * Returns the console currently being displayed, or <code>null</code> + * if none + * + * @return the console currently being displayed, or <code>null</code> + * if none + */ + public IConsole getConsole(); + +} diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/console/MessageConsole.java b/org.eclipse.ui.console/src/org/eclipse/ui/console/MessageConsole.java new file mode 100644 index 000000000..359fba637 --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/console/MessageConsole.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.console; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.text.IDocument; +import org.eclipse.swt.graphics.Font; +import org.eclipse.ui.internal.console.MessageConsolePage; +import org.eclipse.ui.internal.console.MessageConsolePartitioner; +import org.eclipse.ui.internal.console.MessageConsoleStream; +import org.eclipse.ui.part.IPageBookViewPage; + +/** + * A console that displays messages. + * <p> + * Clients may instantiate this class. + * </p> + * @since 3.0 + */ +public class MessageConsole extends AbstractConsole { + + /** + * The font used by this console + */ + private Font fFont = null; + + /** + * Property constant indicating the font of this console has changed. + */ + public static final String P_FONT = ConsolePlugin.getUniqueIdentifier() + ".P_FONT"; //$NON-NLS-1$ + + /** + * Property constant indicating the color of a stream has changed. + */ + public static final String P_STREAM_COLOR = ConsolePlugin.getUniqueIdentifier() + ".P_STREAM_COLOR"; //$NON-NLS-1$ + + // document partitioner + private MessageConsolePartitioner fPartitioner = null; + + /** + * Constructs a new message console. + * + * @param name console name + * @param imageDescriptor console image descriptor or <code>null</code> + * if none + */ + public MessageConsole(String name, ImageDescriptor imageDescriptor) { + super(name, imageDescriptor); + fPartitioner = new MessageConsolePartitioner(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.console.IConsole#createPage(org.eclipse.debug.internal.ui.console.IConsoleView) + */ + public IPageBookViewPage createPage(IConsoleView view) { + return new MessageConsolePage(view, this); + } + + /** + * Sets the font used by this console + * + * @param font font + */ + public void setFont(Font font) { + Font old = fFont; + fFont = font; + firePropertyChange(this, P_FONT, old, font); + } + + /** + * Returns the font for this console + * + * @return font for this console + */ + public Font getFont() { + if (fFont == null) { + return JFaceResources.getTextFont(); + } else { + return fFont; + } + } + + /** + * Returns a new message stream connected to this console. + * + * @return a new message stream connected to this console + */ + public MessageConsoleStream newMessageStream() { + return new MessageConsoleStream(this); + } + + /** + * Appends the given message to this console, from the specified stream. + * + * @param text message + * @param stream stream the message belongs to + */ + public synchronized void appendToDocument(String text, MessageConsoleStream stream) { + fPartitioner.appendToDocument(text, stream); + } + + /** + * Returns the document this console writes to. + * + * @return the document this console wites to + */ + public IDocument getDocument() { + return fPartitioner.getDocument(); + } +} +
\ No newline at end of file diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/console/actions/ClearOutputAction.java b/org.eclipse.ui.console/src/org/eclipse/ui/console/actions/ClearOutputAction.java new file mode 100644 index 000000000..23efdf3ef --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/console/actions/ClearOutputAction.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.console.actions; + + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsoleConstants; +import org.eclipse.ui.help.WorkbenchHelp; +import org.eclipse.ui.internal.console.ConsoleMessages; +import org.eclipse.ui.internal.console.ConsolePluginImages; +import org.eclipse.ui.internal.console.IConsoleHelpContextIds; +import org.eclipse.ui.internal.console.IInternalConsoleConstants; + +/** + * Clears the output of the selected launches + */ +public class ClearOutputAction extends Action { + + private ITextViewer fViewer; + + public ClearOutputAction(ITextViewer viewer) { + super(ConsoleMessages.getString("ClearOutputAction.title")); //$NON-NLS-1$ + fViewer= viewer; + setToolTipText(ConsoleMessages.getString("ClearOutputAction.toolTipText")); //$NON-NLS-1$ + setHoverImageDescriptor(ConsolePluginImages.getImageDescriptor(IConsoleConstants.IMG_LCL_CLEAR)); + setDisabledImageDescriptor(ConsolePluginImages.getImageDescriptor(IInternalConsoleConstants.IMG_DLCL_CLEAR)); + setImageDescriptor(ConsolePluginImages.getImageDescriptor(IInternalConsoleConstants.IMG_ELCL_CLEAR)); + WorkbenchHelp.setHelp( + this, + IConsoleHelpContextIds.CLEAR_CONSOLE_ACTION); + } + + /** + * @see org.eclipse.jface.action.IAction#run() + */ + public void run() { + BusyIndicator.showWhile(ConsolePlugin.getStandardDisplay(), new Runnable() { + public void run() { + IDocument document = fViewer.getDocument(); + if (document != null) { + document.set(""); //$NON-NLS-1$ + } + fViewer.setSelectedRange(0, 0); + } + }); + } +} + diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/console/actions/TextViewerAction.java b/org.eclipse.ui.console/src/org/eclipse/ui/console/actions/TextViewerAction.java new file mode 100644 index 000000000..c0206586a --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/console/actions/TextViewerAction.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.console.actions; + + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.text.ITextOperationTarget; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.ui.texteditor.IUpdate; + +public class TextViewerAction extends Action implements IUpdate { + + private int fOperationCode= -1; + private ITextOperationTarget fOperationTarget; + + public TextViewerAction(ITextViewer viewer, int operationCode) { + fOperationCode= operationCode; + fOperationTarget= viewer.getTextOperationTarget(); + update(); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.texteditor.IUpdate#update() + * + * Updates the enabled state of the action. + * Fires a property change if the enabled state changes. + * + * @see org.eclipse.jface.action.Action#firePropertyChange(String, Object, Object) + */ + public void update() { + + boolean wasEnabled= isEnabled(); + boolean isEnabled= (fOperationTarget != null && fOperationTarget.canDoOperation(fOperationCode)); + setEnabled(isEnabled); + + if (wasEnabled != isEnabled) { + firePropertyChange(ENABLED, wasEnabled ? Boolean.TRUE : Boolean.FALSE, isEnabled ? Boolean.TRUE : Boolean.FALSE); + } + } + + /* (non-Javadoc) + * @see org.eclipse.jface.action.IAction#run() + */ + public void run() { + if (fOperationCode != -1 && fOperationTarget != null) { + fOperationTarget.doOperation(fOperationCode); + } + } + + public void configureAction(String text, String toolTipText, String description) { + setText(text); + setToolTipText(toolTipText); + setDescription(description); + } +}
\ No newline at end of file diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/console/actions/TextViewerGotoLineAction.java b/org.eclipse.ui.console/src/org/eclipse/ui/console/actions/TextViewerGotoLineAction.java new file mode 100644 index 000000000..d421a0f33 --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/console/actions/TextViewerGotoLineAction.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.console.actions; + + +import java.text.MessageFormat; + +import org.eclipse.jface.dialogs.IInputValidator; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.internal.console.ConsoleMessages; + +public class TextViewerGotoLineAction extends TextViewerAction { + + /** + * Validates whether the text found in the input field of the + * dialog forms a valid line number, i.e. one to which can be + * jumped. + */ + class NumberValidator implements IInputValidator { + + public String isValid(String input) { + try { + int i= Integer.parseInt(input); + if (i <= 0 || fLastLine < i) + return ConsoleMessages.getString("TextViewerGotoLineAction.Line_number_out_of_range_1"); //$NON-NLS-1$ + + } catch (NumberFormatException x) { + return ConsoleMessages.getString("TextViewerGotoLineAction.Not_a_number_2"); //$NON-NLS-1$ + } + + return null; + } + } + + protected int fLastLine; + protected ITextViewer fTextViewer; + + /** + * Constructs a goto line action for the viewer using the provided resource bundle + */ + public TextViewerGotoLineAction(ITextViewer viewer) { + super(viewer, -1); + fTextViewer= viewer; + setText(ConsoleMessages.getString("TextViewerGotoLineAction.Go_to_&Line...@Ctrl+L_4")); //$NON-NLS-1$ + setToolTipText(ConsoleMessages.getString("TextViewerGotoLineAction.Go_To_Line_1")); //$NON-NLS-1$ + setDescription(ConsoleMessages.getString("TextViewerGotoLineAction.Go_To_Line_1")); //$NON-NLS-1$ + } + + /** + * @see TextViewerAction#update() + */ + public void update() { + } + + /** + * Jumps to the line. + */ + protected void gotoLine(int line) { + + IDocument document= fTextViewer.getDocument(); + try { + int start= document.getLineOffset(line); + int length= document.getLineLength(line); + fTextViewer.getTextWidget().setSelection(start, start + length); + fTextViewer.revealRange(start, length); + } catch (BadLocationException x) { + ConsolePlugin.errorDialog(fTextViewer.getTextWidget().getShell(), ConsoleMessages.getString("TextViewerGotoLineAction.Go_To_Line_1"), ConsoleMessages.getString("TextViewerGotoLineAction.Exceptions_occurred_attempt_to_go_to_line_2"), x); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + /* (non-Javadoc) + * @see org.eclipse.jface.action.IAction#run() + */ + public void run() { + try { + Point selection= fTextViewer.getTextWidget().getSelection(); + IDocument document= fTextViewer.getDocument(); + fLastLine= document.getLineOfOffset(document.getLength()) + 1; + int startLine= selection == null ? 1 : fTextViewer.getTextWidget().getLineAtOffset(selection.x) + 1; + String title= ConsoleMessages.getString("TextViewerGotoLineAction.Go_To_Line_1"); //$NON-NLS-1$ + String message= MessageFormat.format(ConsoleMessages.getString("TextViewerGotoLineAction.Enter_line_number__8"), new Object[] {new Integer(fLastLine)}); //$NON-NLS-1$ + String value= Integer.toString(startLine); + Shell activeShell= fTextViewer.getTextWidget().getShell(); + InputDialog d= new InputDialog(activeShell, title, message, value, new NumberValidator()); + if (d.open() == Window.OK) { + try { + int line= Integer.parseInt(d.getValue()); + gotoLine(line - 1); + } catch (NumberFormatException x) { + ConsolePlugin.errorDialog(activeShell, ConsoleMessages.getString("TextViewerGotoLineAction.Go_To_Line_1"), ConsoleMessages.getString("TextViewerGotoLineAction.Exceptions_occurred_attempt_to_go_to_line_2"), x); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + } catch (BadLocationException x) { + ConsolePlugin.errorDialog(fTextViewer.getTextWidget().getShell(), ConsoleMessages.getString("TextViewerGotoLineAction.Go_To_Line_1"), ConsoleMessages.getString("TextViewerGotoLineAction.Exceptions_occurred_attempt_to_go_to_line_2"), x); //$NON-NLS-1$ //$NON-NLS-2$ + return; + } + } +}
\ No newline at end of file diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleDropDownAction.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleDropDownAction.java new file mode 100644 index 000000000..573ed35fe --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleDropDownAction.java @@ -0,0 +1,127 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.console; + + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.ActionContributionItem; +import org.eclipse.jface.action.IMenuCreator; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.IConsoleConstants; +import org.eclipse.ui.console.IConsoleListener; +import org.eclipse.ui.console.IConsoleView; +import org.eclipse.ui.texteditor.IUpdate; + +/** + * Drop down action in the console to select the console to display. + */ +class ConsoleDropDownAction extends Action implements IMenuCreator, IConsoleListener, IUpdate { + + private IConsoleView fView; + private Menu fMenu; + + /* (non-Javadoc) + * @see org.eclipse.ui.texteditor.IUpdate#update() + */ + public void update() { + IConsole[] consoles = ConsolePlugin.getDefault().getConsoleManager().getConsoles(); + setEnabled(consoles.length > 1); + } + + public ConsoleDropDownAction(IConsoleView view) { + fView= view; + setText(ConsoleMessages.getString("ConsoleDropDownAction.0")); //$NON-NLS-1$ + setToolTipText(ConsoleMessages.getString("ConsoleDropDownAction.1")); //$NON-NLS-1$ + setImageDescriptor(ConsolePluginImages.getImageDescriptor(IConsoleConstants.IMG_VIEW_CONSOLE)); + setMenuCreator(this); + ConsolePlugin.getDefault().getConsoleManager().addConsoleListener(this); + update(); + } + + public void dispose() { + if (fMenu != null) + fMenu.dispose(); + + fView= null; + ConsolePlugin.getDefault().getConsoleManager().removeConsoleListener(this); + } + + public Menu getMenu(Menu parent) { + return null; + } + + public Menu getMenu(Control parent) { + if (fMenu != null) + fMenu.dispose(); + + fMenu= new Menu(parent); + IConsole[] consoles= ConsolePlugin.getDefault().getConsoleManager().getConsoles(); + IConsole current = fView.getConsole(); + for (int i = 0; i < consoles.length; i++) { + IConsole console = consoles[i]; + Action action = new ShowConsoleAction(fView, console); + action.setChecked(console.equals(current)); + addActionToMenu(fMenu, action); + } + return fMenu; + } + + protected void addActionToMenu(Menu parent, Action action) { + ActionContributionItem item= new ActionContributionItem(action); + item.fill(parent, -1); + } + + protected void addMenuSeparator() { + new MenuItem(fMenu, SWT.SEPARATOR); + } + + public void run() { + // do nothing - this is a menu + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.console.IConsoleListener#consolesAdded(org.eclipse.debug.internal.ui.console.IConsole[]) + */ + public void consolesAdded(IConsole[] consoles) { + Display display = ConsolePlugin.getStandardDisplay(); + display.asyncExec(new Runnable() { + public void run() { + update(); + } + }); + } + + /* (non-Javadoc) + * + * Dispose the menu when a launch is removed, such that the actions in this + * menu do not hang on to associated resources. + * + * @see org.eclipse.debug.internal.ui.console.IConsoleListener#consolesRemoved(org.eclipse.debug.internal.ui.console.IConsole[]) + */ + public void consolesRemoved(IConsole[] consoles) { + Display display = ConsolePlugin.getStandardDisplay(); + display.asyncExec(new Runnable() { + public void run() { + if (fMenu != null) { + fMenu.dispose(); + } + update(); + } + }); + } + +} diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleManager.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleManager.java new file mode 100644 index 000000000..5cbcbe25f --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleManager.java @@ -0,0 +1,169 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.console; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.ISafeRunnable; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.util.ListenerList; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.IConsoleConstants; +import org.eclipse.ui.console.IConsoleListener; +import org.eclipse.ui.console.IConsoleManager; + +/** + * The singleton console manager. + * + * @since 3.0 + */ +public class ConsoleManager implements IConsoleManager { + + /** + * Console listeners + */ + private ListenerList fListeners = null; + + /** + * List of registered consoles + */ + private List fConsoles = new ArrayList(10); + + // change notification constants + private final static int ADDED = 1; + private final static int REMOVED = 2; + + /** + * Notifies a console listener of additions or removals + */ + class ConsoleNotifier implements ISafeRunnable { + + private IConsoleListener fListener; + private int fType; + private IConsole[] fChanged; + + /** + * @see org.eclipse.core.runtime.ISafeRunnable#handleException(java.lang.Throwable) + */ + public void handleException(Throwable exception) { + IStatus status = new Status(IStatus.ERROR, ConsolePlugin.getUniqueIdentifier(), IConsoleConstants.INTERNAL_ERROR, ConsoleMessages.getString("ConsoleManager.0"), exception); //$NON-NLS-1$ + ConsolePlugin.log(status); + } + + /** + * @see org.eclipse.core.runtime.ISafeRunnable#run() + */ + public void run() throws Exception { + switch (fType) { + case ADDED: + fListener.consolesAdded(fChanged); + break; + case REMOVED: + fListener.consolesRemoved(fChanged); + break; + } + } + + /** + * Notifies the given listener of the adds/removes + * + * @param consoles the consoles that changed + * @param update the type of change + */ + public void notify(IConsole[] consoles, int update) { + if (fListeners == null) { + return; + } + fChanged = consoles; + fType = update; + Object[] copiedListeners= fListeners.getListeners(); + for (int i= 0; i < copiedListeners.length; i++) { + fListener = (IConsoleListener)copiedListeners[i]; + Platform.run(this); + } + fChanged = null; + fListener = null; + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.console.IConsoleManager#addConsoleListener(org.eclipse.debug.internal.ui.console.IConsoleListener) + */ + public void addConsoleListener(IConsoleListener listener) { + if (fListeners == null) { + fListeners = new ListenerList(5); + } + fListeners.add(listener); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.console.IConsoleManager#removeConsoleListener(org.eclipse.debug.internal.ui.console.IConsoleListener) + */ + public void removeConsoleListener(IConsoleListener listener) { + if (fListeners != null) { + fListeners.remove(listener); + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.console.IConsoleManager#addConsoles(org.eclipse.debug.internal.ui.console.IConsole[]) + */ + public synchronized void addConsoles(IConsole[] consoles) { + List added = new ArrayList(consoles.length); + for (int i = 0; i < consoles.length; i++) { + IConsole console = consoles[i]; + if (!fConsoles.contains(console)) { + fConsoles.add(console); + added.add(console); + } + } + if (!added.isEmpty()) { + fireUpdate((IConsole[])added.toArray(new IConsole[added.size()]), ADDED); + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.console.IConsoleManager#removeConsoles(org.eclipse.debug.internal.ui.console.IConsole[]) + */ + public synchronized void removeConsoles(IConsole[] consoles) { + List removed = new ArrayList(consoles.length); + for (int i = 0; i < consoles.length; i++) { + IConsole console = consoles[i]; + if (fConsoles.remove(console)) { + removed.add(console); + } + } + if (!removed.isEmpty()) { + fireUpdate((IConsole[])removed.toArray(new IConsole[removed.size()]), REMOVED); + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.console.IConsoleManager#getConsoles() + */ + public synchronized IConsole[] getConsoles() { + return (IConsole[])fConsoles.toArray(new IConsole[fConsoles.size()]); + } + + /** + * Fires notification. + * + * @param consoles consoles added/removed + * @param type ADD or REMOVE + */ + private void fireUpdate(IConsole[] consoles, int type) { + new ConsoleNotifier().notify(consoles, type); + } +} diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleMessages.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleMessages.java new file mode 100644 index 000000000..6c89e23f6 --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleMessages.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.console; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +/** + * ConsoleMessages + */ +public class ConsoleMessages { + + private static final String BUNDLE_NAME = "org.eclipse.ui.internal.console.ConsoleMessages"; //$NON-NLS-1$ + + private static final ResourceBundle RESOURCE_BUNDLE = + ResourceBundle.getBundle(BUNDLE_NAME); + + private ConsoleMessages() { + } + + public static String getString(String key) { + try { + return RESOURCE_BUNDLE.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } +} diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleMessages.properties b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleMessages.properties new file mode 100644 index 000000000..f96d8d849 --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleMessages.properties @@ -0,0 +1,43 @@ +############################################################################### +# Copyright (c) 2000, 2003 IBM Corporation and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Common Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/cpl-v10.html +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### + +AbstractConsole.0=Exception occurred during console property change notification. + +ConsoleDropDownAction.0=Select Console +ConsoleDropDownAction.1=Display Selected Console + +ConsoleManager.0=An exception occurred during console notification + +ConsoleView.0=Console +ConsoleView.1=Console - {0} + +find_replace_action.label=&Find/Replace...@Ctrl+F +find_replace_action.tooltip=Find/Replace +find_replace_action.image= +find_replace_action.description=Find/Replace + +MessageConsolePage.&Copy@Ctrl+C_6=&Copy@Ctrl+C +MessageConsolePage.Copy_7=Copy +MessageConsolePage.Select_&All@Ctrl+A_12=Select &All@Ctrl+A +MessageConsolePage.Select_All=Select All + +PinConsoleAction.0=Pi&n Console +PinConsoleAction.1=Pin Console + +ClearOutputAction.title=Clea&r +ClearOutputAction.toolTipText=Clear Console + +TextViewerGotoLineAction.Enter_line_number__8=Enter line number (1...{0}): +TextViewerGotoLineAction.Exceptions_occurred_attempt_to_go_to_line_2=Exceptions occurred attempt to go to line +TextViewerGotoLineAction.Go_to_&Line...@Ctrl+L_4=Go to &Line...@Ctrl+L +TextViewerGotoLineAction.Go_To_Line_1=Go to Line +TextViewerGotoLineAction.Line_number_out_of_range_1=Line number out of range +TextViewerGotoLineAction.Not_a_number_2=Not a number diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsolePluginImages.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsolePluginImages.java new file mode 100644 index 000000000..398cd870d --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsolePluginImages.java @@ -0,0 +1,170 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.console; + + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsoleConstants; + +/** + * The images provided by the debug plugin. + */ +public class ConsolePluginImages { + + /** + * The image registry containing <code>Image</code>s. + */ + private static ImageRegistry imageRegistry; + + /** + * A table of all the <code>ImageDescriptor</code>s. + */ + private static HashMap imageDescriptors; + + /* Declare Common paths */ + private static URL ICON_BASE_URL= null; + + static { + String pathSuffix = "icons/full/"; //$NON-NLS-1$ + + try { + ICON_BASE_URL= new URL(ConsolePlugin.getDefault().getDescriptor().getInstallURL(), pathSuffix); + } catch (MalformedURLException e) { + // do nothing + } + } + + // Use IPath and toOSString to build the names to ensure they have the slashes correct + private final static String LOCALTOOL= "clcl16/"; //basic colors - size 16x16 //$NON-NLS-1$ + private final static String DLCL= "dlcl16/"; //disabled - size 16x16 //$NON-NLS-1$ + private final static String ELCL= "elcl16/"; //enabled - size 16x16 //$NON-NLS-1$ + private final static String VIEW= "cview16/"; // views //$NON-NLS-1$ + + /** + * Declare all images + */ + private static void declareImages() { + // Actions + + //local toolbars + declareRegistryImage(IConsoleConstants.IMG_LCL_CLEAR, LOCALTOOL + "clear_co.gif"); //$NON-NLS-1$ + declareRegistryImage(IInternalConsoleConstants.IMG_LCL_PIN, LOCALTOOL + "pin.gif"); //$NON-NLS-1$ + + // disabled local toolbars + declareRegistryImage(IInternalConsoleConstants.IMG_DLCL_CLEAR, DLCL + "clear_co.gif"); //$NON-NLS-1$ + declareRegistryImage(IInternalConsoleConstants.IMG_DLCL_PIN, DLCL + "pin.gif"); //$NON-NLS-1$ + + // enabled local toolbars + declareRegistryImage(IInternalConsoleConstants.IMG_ELCL_CLEAR, ELCL + "clear_co.gif"); //$NON-NLS-1$ + declareRegistryImage(IInternalConsoleConstants.IMG_ELCL_PIN, ELCL + "pin.gif"); //$NON-NLS-1$ + + // Views + declareRegistryImage(IConsoleConstants.IMG_VIEW_CONSOLE, VIEW + "console_view.gif"); //$NON-NLS-1$ + } + + /** + * Declare an Image in the registry table. + * @param key The key to use when registering the image + * @param path The path where the image can be found. This path is relative to where + * this plugin class is found (i.e. typically the packages directory) + */ + private final static void declareRegistryImage(String key, String path) { + ImageDescriptor desc= ImageDescriptor.getMissingImageDescriptor(); + try { + desc= ImageDescriptor.createFromURL(makeIconFileURL(path)); + } catch (MalformedURLException me) { + ConsolePlugin.log(me); + } + imageRegistry.put(key, desc); + imageDescriptors.put(key, desc); + } + + /** + * Returns the ImageRegistry. + */ + public static ImageRegistry getImageRegistry() { + if (imageRegistry == null) { + initializeImageRegistry(); + } + return imageRegistry; + } + + /** + * Initialize the image registry by declaring all of the required + * graphics. This involves creating JFace image descriptors describing + * how to create/find the image should it be needed. + * The image is not actually allocated until requested. + * + * Prefix conventions + * Wizard Banners WIZBAN_ + * Preference Banners PREF_BAN_ + * Property Page Banners PROPBAN_ + * Color toolbar CTOOL_ + * Enable toolbar ETOOL_ + * Disable toolbar DTOOL_ + * Local enabled toolbar ELCL_ + * Local Disable toolbar DLCL_ + * Object large OBJL_ + * Object small OBJS_ + * View VIEW_ + * Product images PROD_ + * Misc images MISC_ + * + * Where are the images? + * The images (typically gifs) are found in the same location as this plugin class. + * This may mean the same package directory as the package holding this class. + * The images are declared using this.getClass() to ensure they are looked up via + * this plugin class. + * @see JFace's ImageRegistry + */ + public static ImageRegistry initializeImageRegistry() { + imageRegistry= new ImageRegistry(ConsolePlugin.getStandardDisplay()); + imageDescriptors = new HashMap(30); + declareImages(); + return imageRegistry; + } + + /** + * Returns the <code>Image<code> identified by the given key, + * or <code>null</code> if it does not exist. + */ + public static Image getImage(String key) { + return getImageRegistry().get(key); + } + + /** + * Returns the <code>ImageDescriptor<code> identified by the given key, + * or <code>null</code> if it does not exist. + */ + public static ImageDescriptor getImageDescriptor(String key) { + if (imageDescriptors == null) { + initializeImageRegistry(); + } + return (ImageDescriptor)imageDescriptors.get(key); + } + + private static URL makeIconFileURL(String iconPath) throws MalformedURLException { + if (ICON_BASE_URL == null) { + throw new MalformedURLException(); + } + + return new URL(ICON_BASE_URL, iconPath); + } +} + + diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleView.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleView.java new file mode 100644 index 000000000..8b5eb91cd --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleView.java @@ -0,0 +1,452 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.console; + +import java.text.MessageFormat; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.jface.viewers.IBasicPropertyConstants; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.IConsoleConstants; +import org.eclipse.ui.console.IConsoleListener; +import org.eclipse.ui.console.IConsoleManager; +import org.eclipse.ui.console.IConsoleView; +import org.eclipse.ui.part.IPage; +import org.eclipse.ui.part.IPageBookViewPage; +import org.eclipse.ui.part.MessagePage; +import org.eclipse.ui.part.PageBook; +import org.eclipse.ui.part.PageBookView; + +/** + * Page book console view. + * + * @since 3.0 + */ +public class ConsoleView extends PageBookView implements IConsoleView, IConsoleListener, IPropertyChangeListener { + + /** + * Whether this console is pinned. + */ + private boolean fPinned = false; + + /** + * The console being displayed, or <code>null</code> if none + */ + private IConsole fActiveConsole = null; + + /** + * Map of consoles to dummy console parts (used to close pages) + */ + private Map fConsoleToPart; + + /** + * Map of parts to consoles + */ + private Map fPartToConsole; + + // actions + private PinConsoleAction fPinAction = null; + private ConsoleDropDownAction fDisplayConsoleAction = null; + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.AbstractDebugView#getControl() + */ + protected Control getControl() { + return getPageBook(); + } + + private boolean isAvailable() { + return getPageBook() != null && !getPageBook().isDisposed(); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) + */ + public void propertyChange(PropertyChangeEvent event) { + Object source = event.getSource(); + if (source instanceof IConsole && event.getProperty().equals(IBasicPropertyConstants.P_TEXT)) { + if (source.equals(getConsole())) { + updateTitle(); + } + } + + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart) + */ + public void partClosed(IWorkbenchPart part) { + if (isPinned()) { + // if closing the pinned console, un-pin + IConsole console = (IConsole)fPartToConsole.get(part); + if (console != null && console.equals(getConsole())) { + pin(null); + } + } + super.partClosed(part); + fPinAction.update(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.console.IConsoleView#getConsole() + */ + public IConsole getConsole() { + return fActiveConsole; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.part.PageBookView#showPageRec(org.eclipse.ui.part.PageBookView.PageRec) + */ + protected void showPageRec(PageRec pageRec) { + if (!isPinned()) { + super.showPageRec(pageRec); + fActiveConsole = (IConsole)fPartToConsole.get(pageRec.part); + updateTitle(); + // update console actions + if (fPinAction != null) { + fPinAction.update(); + } + } + } + + /** + * Updates the view title based on the active console + */ + protected void updateTitle() { + IConsole console = getConsole(); + if (console == null) { + setTitle(ConsoleMessages.getString("ConsoleView.0")); //$NON-NLS-1$ + } else { + setTitle(MessageFormat.format(ConsoleMessages.getString("ConsoleView.1"), new String[]{console.getName()})); //$NON-NLS-1$ + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.part.PageBookView#doDestroyPage(org.eclipse.ui.IWorkbenchPart, org.eclipse.ui.part.PageBookView.PageRec) + */ + protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) { + IPage page = pageRecord.page; + page.dispose(); + pageRecord.dispose(); + + IConsole console = (IConsole)fPartToConsole.get(part); + console.removePropertyChangeListener(this); + + // empty cross-reference cache + fPartToConsole.remove(part); + fConsoleToPart.remove(console); + + // update console actions + fPinAction.update(); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.part.PageBookView#doCreatePage(org.eclipse.ui.IWorkbenchPart) + */ + protected PageRec doCreatePage(IWorkbenchPart dummyPart) { + ConsoleWorkbenchPart part = (ConsoleWorkbenchPart)dummyPart; + IConsole console = part.getConsole(); + IPageBookViewPage page = console.createPage(this); + initPage(page); + page.createControl(getPageBook()); + console.addPropertyChangeListener(this); + PageRec rec = new PageRec(dummyPart, page); + return rec; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.part.PageBookView#isImportant(org.eclipse.ui.IWorkbenchPart) + */ + protected boolean isImportant(IWorkbenchPart part) { + return part instanceof ConsoleWorkbenchPart; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchPart#dispose() + */ + public void dispose() { + super.dispose(); + ConsolePlugin.getDefault().getConsoleManager().removeConsoleListener(this); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.part.PageBookView#createDefaultPage(org.eclipse.ui.part.PageBook) + */ + protected IPage createDefaultPage(PageBook book) { + MessagePage page = new MessagePage(); + page.createControl(getPageBook()); + initPage(page); + return page; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.console.IConsoleListener#consolesAdded(org.eclipse.debug.internal.ui.console.IConsole[]) + */ + public void consolesAdded(final IConsole[] consoles) { + if (isAvailable()) { + Runnable r = new Runnable() { + public void run() { + for (int i = 0; i < consoles.length; i++) { + if (isAvailable()) { + IConsole console = consoles[i]; + ConsoleWorkbenchPart part = new ConsoleWorkbenchPart(console, getSite()); + fConsoleToPart.put(console, part); + fPartToConsole.put(part, console); + partActivated(part); + } + } + } + }; + asyncExec(r); + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.console.IConsoleListener#consolesRemoved(org.eclipse.ui.console.IConsole[]) + */ + public void consolesRemoved(final IConsole[] consoles) { + if (isAvailable()) { + Runnable r = new Runnable() { + public void run() { + for (int i = 0; i < consoles.length; i++) { + if (isAvailable()) { + IConsole console = consoles[i]; + ConsoleWorkbenchPart part = (ConsoleWorkbenchPart)fConsoleToPart.get(console); + if (part != null) { + partClosed(part); + } + if (getConsole() == null) { + IConsole[] available = ConsolePlugin.getDefault().getConsoleManager().getConsoles(); + if (available.length > 0) { + display(available[available.length - 1]); + } + } + } + } + } + }; + asyncExec(r); + } + } + + /** + * Constructs a console view + */ + public ConsoleView() { + super(); + fConsoleToPart = new HashMap(); + fPartToConsole = new HashMap(); + } + + /** + * This method is never called for this view. + * + * @see org.eclipse.debug.ui.AbstractDebugView#createViewer(org.eclipse.swt.widgets.Composite) + */ + protected Viewer createViewer(Composite parent) { + return null; + } + + /** + * Creates a pop-up menu on the given control. The menu + * is registered with this view's site, such that other + * plug-ins may contribute to the menu. Subclasses should + * call this method, specifying the menu control as the + * control used in their viewer (for example, tree viewer). + * Subclasses must implement the method + * <code>#fillContextMenu(IMenuManager)</code> which will + * be called each time the context menu is realized. + * + * @param menuControl the control with which the pop-up + * menu will be associated with. + */ + protected void createContextMenu(Control menuControl) { + MenuManager menuMgr= new MenuManager("#PopUp"); //$NON-NLS-1$ + menuMgr.setRemoveAllWhenShown(true); + menuMgr.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager mgr) { + fillContextMenu(mgr); + } + }); + Menu menu= menuMgr.createContextMenu(menuControl); + menuControl.setMenu(menu); + + // register the context menu such that other plugins may contribute to it + if (getSite() != null) { + getSite().registerContextMenu(menuMgr, null); + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.AbstractDebugView#createActions() + */ + protected void createActions() { + fPinAction = new PinConsoleAction(this); + fDisplayConsoleAction = new ConsoleDropDownAction(this); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.AbstractDebugView#getHelpContextId() + */ + protected String getHelpContextId() { + return IConsoleHelpContextIds.CONSOLE_VIEW; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.AbstractDebugView#fillContextMenu(org.eclipse.jface.action.IMenuManager) + */ + protected void fillContextMenu(IMenuManager menu) { + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.AbstractDebugView#configureToolBar(org.eclipse.jface.action.IToolBarManager) + */ + protected void configureToolBar(IToolBarManager mgr) { + mgr.add(new Separator(IConsoleConstants.LAUNCH_GROUP)); + mgr.add(new Separator(IConsoleConstants.OUTPUT_GROUP)); + mgr.add(fPinAction); + mgr.add(fDisplayConsoleAction); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.console.IConsoleView#display(org.eclipse.debug.internal.ui.console.IConsole) + */ + public void display(IConsole console) { + if (!isPinned()) { + ConsoleWorkbenchPart part = (ConsoleWorkbenchPart)fConsoleToPart.get(console); + if (part != null) { + partActivated(part); + } + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.console.IConsoleView#pin(org.eclipse.debug.internal.ui.console.IConsole) + */ + public void pin(IConsole console) { + if (console == null) { + fPinned = false; + } else { + display(console); + fPinned = true; + } + if (fPinAction != null) { + fPinAction.update(); + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.console.IConsoleView#isPinned() + */ + public boolean isPinned() { + return fPinned; + } + + /** + * @see PageBookView#getBootstrapPart() + */ + protected IWorkbenchPart getBootstrapPart() { + return null; + } + + /** + * Registers the given runnable with the display + * associated with this view's control, if any. + * + * @see org.eclipse.swt.widgets.Display#asyncExec(java.lang.Runnable) + */ + public void asyncExec(Runnable r) { + if (isAvailable()) { + getControl().getDisplay().asyncExec(r); + } + } + + /** + * Creates this view's underlying viewer and actions. + * Hooks a pop-up menu to the underlying viewer's control, + * as well as a key listener. When the delete key is pressed, + * the <code>REMOVE_ACTION</code> is invoked. Hooks help to + * this view. Subclasses must implement the following methods + * which are called in the following order when a view is + * created:<ul> + * <li><code>createViewer(Composite)</code> - the context + * menu is hooked to the viewer's control.</li> + * <li><code>createActions()</code></li> + * <li><code>configureToolBar(IToolBarManager)</code></li> + * <li><code>getHelpContextId()</code></li> + * </ul> + * @see IWorkbenchPart#createPartControl(Composite) + * @see AbstractDebugView#createPartControl(Composite) + * @see AbstractDebugView#createActions() + * @see AbstractDebugView#configureToolBar(IToolBarManager) + * @see AbstractDebugView#getHelpContextId() + * @see AbstractDebugView#fillContextMenu(IMenuManager) + */ + public void createPartControl(Composite parent) { + //registerPartListener(); + super.createPartControl(parent); + createActions(); + IToolBarManager tbm= getViewSite().getActionBars().getToolBarManager(); + configureToolBar(tbm); + updateForExistingConsoles(); + getViewSite().getActionBars().updateActionBars(); +// Viewer viewer = getViewer(); +// if (viewer != null) { +// createContextMenu(viewer.getControl()); +// } + //WorkbenchHelp.setHelp(parent, getHelpContextId()); +// if (viewer != null) { +// getViewer().getControl().addKeyListener(new KeyAdapter() { +// public void keyPressed(KeyEvent e) { +// handleKeyPressed(e); +// } +// }); +// if (getViewer() instanceof StructuredViewer) { +// ((StructuredViewer)getViewer()).addDoubleClickListener(this); +// } +// } + // create the message page + //setMessagePage(new MessagePage()); + //getMessagePage().createControl(getPageBook()); + //initPage(getMessagePage()); + +// if (fEarlyMessage != null) { //bug 28127 +// showMessage(fEarlyMessage); +// fEarlyMessage= null; +// } + } + + /** + * Initialize for existing consoles + */ + private void updateForExistingConsoles() { + IConsoleManager manager = ConsolePlugin.getDefault().getConsoleManager(); + // create pages for consoles + IConsole[] consoles = manager.getConsoles(); + consolesAdded(consoles); + // add as a listener + manager.addConsoleListener(this); + } +} diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleWorkbenchPart.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleWorkbenchPart.java new file mode 100644 index 000000000..dd0ac5b97 --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleWorkbenchPart.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.console; + +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IPropertyListener; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchPartSite; +import org.eclipse.ui.console.*; + +/** + * Fake part to use as keys in page book for console pages + */ +public class ConsoleWorkbenchPart implements IWorkbenchPart { + + private IConsole fConsole = null; + private IWorkbenchPartSite fSite = null; + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object obj) { + return (obj instanceof ConsoleWorkbenchPart) && + fConsole.equals(((ConsoleWorkbenchPart)obj).fConsole); + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + public int hashCode() { + return fConsole.hashCode(); + } + + /** + * Constructs a part for the given console that binds to the given + * site + */ + public ConsoleWorkbenchPart(IConsole console, IWorkbenchPartSite site) { + fConsole = console; + fSite = site; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchPart#addPropertyListener(org.eclipse.ui.IPropertyListener) + */ + public void addPropertyListener(IPropertyListener listener) { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) + */ + public void createPartControl(Composite parent) { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchPart#dispose() + */ + public void dispose() { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchPart#getSite() + */ + public IWorkbenchPartSite getSite() { + return fSite; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchPart#getTitle() + */ + public String getTitle() { + return ""; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchPart#getTitleImage() + */ + public Image getTitleImage() { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchPart#getTitleToolTip() + */ + public String getTitleToolTip() { + return ""; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchPart#removePropertyListener(org.eclipse.ui.IPropertyListener) + */ + public void removePropertyListener(IPropertyListener listener) { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchPart#setFocus() + */ + public void setFocus() { + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) + */ + public Object getAdapter(Class adapter) { + return null; + } + + /** + * Returns the console assocaited with this part. + * + * @return console assocaited with this part + */ + protected IConsole getConsole() { + return fConsole; + } +} diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IConsoleHelpContextIds.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IConsoleHelpContextIds.java new file mode 100644 index 000000000..b81cbea77 --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IConsoleHelpContextIds.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.console; + +import org.eclipse.ui.console.IConsoleConstants; + +/** + * Help context ids for the debug ui. + * <p> + * This interface contains constants only; it is not intended to be implemented + * or extended. + * </p> + * + */ +public interface IConsoleHelpContextIds { + + public static final String PREFIX = IConsoleConstants.PLUGIN_ID + "."; //$NON-NLS-1$ + + // Actions + public static final String CLEAR_CONSOLE_ACTION = PREFIX + "clear_console_action_context"; //$NON-NLS-1$ + public static final String CONSOLE_SCROLL_LOCK_ACTION = PREFIX + "console_scroll_lock_action_context"; //$NON-NLS-1$ + + // Views + public static final String CONSOLE_VIEW = PREFIX + "console_view_context"; //$NON-NLS-1$ + + // Preference pages + public static final String CONSOLE_PREFERENCE_PAGE = PREFIX + "console_preference_page_context"; //$NON-NLS-1$ +} + diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsolePlugin.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IInternalConsoleConstants.java index 4250f7289..5796bf8c6 100644 --- a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsolePlugin.java +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IInternalConsoleConstants.java @@ -8,28 +8,18 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ - package org.eclipse.ui.internal.console; - -import org.eclipse.core.runtime.IPluginDescriptor; -import org.eclipse.ui.plugin.AbstractUIPlugin; - -public class ConsolePlugin extends AbstractUIPlugin { - - /** - * The singleton console plugin instance - */ - private static ConsolePlugin fgPlugin= null; - - /** - * Returns the singleton instance of the console plugin. - */ - public static ConsolePlugin getDefault() { - return fgPlugin; - } - - public ConsolePlugin(IPluginDescriptor descriptor) { - super(descriptor); - fgPlugin = this; - } + +public interface IInternalConsoleConstants { + + // tool images + public static final String IMG_LCL_PIN = "IMG_LCL_PIN"; //$NON-NLS-1$ + + // disabled local tool images + public static final String IMG_DLCL_PIN = "IMG_DLCL_PIN"; //$NON-NLS-1$ + public static final String IMG_DLCL_CLEAR= "IMG_DLCL_CLEAR"; //$NON-NLS-1$ + + // enabled local tool images + public static final String IMG_ELCL_PIN = "IMG_ELCL_PIN"; //$NON-NLS-1$ + public static final String IMG_ELCL_CLEAR= "IMG_ELCL_CLEAR"; //$NON-NLS-1$ } diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/MessageConsolePage.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/MessageConsolePage.java new file mode 100644 index 000000000..3c535eb2c --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/MessageConsolePage.java @@ -0,0 +1,342 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.console; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.ResourceBundle; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.text.IFindReplaceTarget; +import org.eclipse.jface.text.ITextOperationTarget; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.VerifyKeyListener; +import org.eclipse.swt.events.VerifyEvent; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.Widget; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.console.*; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsoleConstants; +import org.eclipse.ui.console.IConsoleView; +import org.eclipse.ui.console.actions.ClearOutputAction; +import org.eclipse.ui.console.actions.TextViewerAction; +import org.eclipse.ui.console.actions.TextViewerGotoLineAction; +import org.eclipse.ui.part.IPageBookViewPage; +import org.eclipse.ui.part.IPageSite; +import org.eclipse.ui.texteditor.FindReplaceAction; +import org.eclipse.ui.texteditor.ITextEditorActionConstants; +import org.eclipse.ui.texteditor.IUpdate; + +/** + * A page for a console connected to I/O streams of a process + * + * @since 3.0 + */ +public class MessageConsolePage implements IPageBookViewPage, IAdaptable, IPropertyChangeListener { + + //page site + private IPageSite fSite = null; + + // viewer + private MessageConsoleViewer fViewer = null; + + // the view this page is contained in + private IConsoleView fView; + + // the console this page displays + private MessageConsole fConsole; + + // text selection listener + private ISelectionChangedListener fTextListener = new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + updateSelectionDependentActions(); + }}; + + // actions + private ClearOutputAction fClearOutputAction; + private Map fGlobalActions= new HashMap(10); + private List fSelectionActions = new ArrayList(3); + + // menus + private Menu fMenu; + + /** + * Constructs a new process page + */ + public MessageConsolePage(IConsoleView view, MessageConsole console) { + fView = view; + fConsole = console; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.part.IPageBookViewPage#getSite() + */ + public IPageSite getSite() { + return fSite; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.part.IPageBookViewPage#init(org.eclipse.ui.part.IPageSite) + */ + public void init(IPageSite site) throws PartInitException { + fSite = site; + + } + + /* (non-Javadoc) + * @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite) + */ + public void createControl(Composite parent) { + fViewer = new MessageConsoleViewer(parent); + fViewer.setDocument(getConsole().getDocument()); + + MenuManager manager= new MenuManager("#MessageConsole", "#MessageConsole"); //$NON-NLS-1$ //$NON-NLS-2$ + manager.setRemoveAllWhenShown(true); + manager.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager m) { + contextMenuAboutToShow(m); + } + }); + fMenu= manager.createContextMenu(getControl()); + getControl().setMenu(fMenu); + + IPageSite site= getSite(); + site.registerContextMenu(ConsolePlugin.getUniqueIdentifier() + ".messageConsole", manager, getViewer()); //$NON-NLS-1$ + site.setSelectionProvider(getViewer()); + + createActions(); + configureToolBar(getSite().getActionBars().getToolBarManager()); + + fViewer.getSelectionProvider().addSelectionChangedListener(fTextListener); + setFont(getConsole().getFont()); + getConsole().addPropertyChangeListener(this); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) + */ + public void propertyChange(PropertyChangeEvent event) { + Object source = event.getSource(); + if (source.equals(getConsole()) && event.getProperty().equals(MessageConsole.P_FONT)) { + setFont(getConsole().getFont()); + } + } + + + /* (non-Javadoc) + * @see org.eclipse.ui.part.IPage#dispose() + */ + public void dispose() { + getConsole().removePropertyChangeListener(this); + fViewer.getSelectionProvider().removeSelectionChangedListener(fTextListener); + + if (fMenu != null && !fMenu.isDisposed()) { + fMenu.dispose(); + fMenu= null; + } + + if (fViewer != null) { + fViewer.dispose(); + fViewer = null; + } + fSite = null; + fSelectionActions.clear(); + } + + + /** + * Fill the context menu + * + * @param menu menu + */ + protected void contextMenuAboutToShow(IMenuManager menu) { + menu.add((IAction)fGlobalActions.get(IWorkbenchActionConstants.COPY)); + menu.add((IAction)fGlobalActions.get(IWorkbenchActionConstants.SELECT_ALL)); + menu.add(new Separator("FIND")); //$NON-NLS-1$ + menu.add((IAction)fGlobalActions.get(IWorkbenchActionConstants.FIND)); + menu.add((IAction)fGlobalActions.get(ITextEditorActionConstants.GOTO_LINE)); + menu.add(fClearOutputAction); + menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); + + } + + /* (non-Javadoc) + * @see org.eclipse.ui.part.IPage#getControl() + */ + public Control getControl() { + if (fViewer != null) { + return fViewer.getControl(); + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.part.IPage#setActionBars(org.eclipse.ui.IActionBars) + */ + public void setActionBars(IActionBars actionBars) { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.part.IPage#setFocus() + */ + public void setFocus() { + Control control = getControl(); + if (control != null) { + control.setFocus(); + } + updateSelectionDependentActions(); + } + + protected void createActions() { + fClearOutputAction= new ClearOutputAction(getViewer()); + + // In order for the clipboard actions to accessible via their shortcuts + // (e.g., Ctrl-C, Ctrl-V), we *must* set a global action handler for + // each action + IActionBars actionBars= getSite().getActionBars(); + TextViewerAction action= new TextViewerAction(getViewer(), ITextOperationTarget.COPY); + action.configureAction(ConsoleMessages.getString("MessageConsolePage.&Copy@Ctrl+C_6"), ConsoleMessages.getString("MessageConsolePage.Copy_7"), ConsoleMessages.getString("MessageConsolePage.Copy_7")); //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ + action.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); + action.setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED)); + action.setHoverImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY_HOVER)); + setGlobalAction(actionBars, IWorkbenchActionConstants.COPY, action); + action= new TextViewerAction(getViewer(), ITextOperationTarget.SELECT_ALL); + action.configureAction(ConsoleMessages.getString("MessageConsolePage.Select_&All@Ctrl+A_12"), ConsoleMessages.getString("MessageConsolePage.Select_All"), ConsoleMessages.getString("MessageConsolePage.Select_All")); //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ + setGlobalAction(actionBars, IWorkbenchActionConstants.SELECT_ALL, action); + + //XXX Still using "old" resource access + ResourceBundle bundle= ResourceBundle.getBundle("org.eclipse.ui.internal.console.ConsoleMessages"); //$NON-NLS-1$ + setGlobalAction(actionBars, IWorkbenchActionConstants.FIND, new FindReplaceAction(bundle, "find_replace_action.", getConsoleView())); //$NON-NLS-1$ + + action= new TextViewerGotoLineAction(getViewer()); + setGlobalAction(actionBars, ITextEditorActionConstants.GOTO_LINE, action); + + actionBars.updateActionBars(); + + getViewer().getTextWidget().addVerifyKeyListener(new VerifyKeyListener() { + public void verifyKey(VerifyEvent event) { + if (event.stateMask == SWT.CTRL && event.keyCode == 0 && event.character == 0x0C) { + IAction gotoLine= (IAction)fGlobalActions.get(ITextEditorActionConstants.GOTO_LINE); + if (gotoLine.isEnabled()) { + gotoLine.run(); + event.doit= false; + } + } + } + }); + + fSelectionActions.add(IWorkbenchActionConstants.COPY); + fSelectionActions.add(IWorkbenchActionConstants.FIND); + } + + protected void updateSelectionDependentActions() { + Iterator iterator= fSelectionActions.iterator(); + while (iterator.hasNext()) { + updateAction((String)iterator.next()); + } + } + + protected void updateAction(String actionId) { + IAction action= (IAction)fGlobalActions.get(actionId); + if (action instanceof IUpdate) { + ((IUpdate) action).update(); + } + } + + protected void setGlobalAction(IActionBars actionBars, String actionID, IAction action) { + fGlobalActions.put(actionID, action); + actionBars.setGlobalActionHandler(actionID, action); + } + + /** + * Returns the viewer in this page. + * + * @return the viewer in this page + */ + protected MessageConsoleViewer getViewer() { + return fViewer; + } + + /** + * @see AbstractDebugView#configureToolBar(IToolBarManager) + */ + protected void configureToolBar(IToolBarManager mgr) { + mgr.appendToGroup(IConsoleConstants.OUTPUT_GROUP, fClearOutputAction); + } + + /** + * Returns the view this page is contained in + * + * @return the view this page is contained in + */ + protected IConsoleView getConsoleView() { + return fView; + } + + /** + * Returns the console this page is displaying + * + * @return the console this page is displaying + */ + protected MessageConsole getConsole() { + return fConsole; + } + + /** + * @see WorkbenchPart#getAdapter(Class) + */ + public Object getAdapter(Class required) { + if (IFindReplaceTarget.class.equals(required)) { + return getViewer().getFindReplaceTarget(); + } + if (Widget.class.equals(required)) { + return getViewer().getTextWidget(); + } + return null; + } + + /** + * Sets the font for this page. + * + * @param font font + */ + protected void setFont(Font font) { + getViewer().getTextWidget().setFont(font); + } + + /** + * Refreshes this page + */ + protected void refresh() { + getViewer().refresh(); + } +} diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/MessageConsolePartition.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/MessageConsolePartition.java new file mode 100644 index 000000000..f8fcacefa --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/MessageConsolePartition.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.console; + + +import org.eclipse.jface.text.TypedRegion; +import org.eclipse.ui.console.ConsolePlugin; + +/** + * A partition from a message stream connected to a message console. + */ +public class MessageConsolePartition extends TypedRegion { + + /** + * Associated stream + */ + private MessageConsoleStream fStream; + + /** + * Partition type + */ + public static final String MESSAGE_PARTITION_TYPE = ConsolePlugin.getUniqueIdentifier() + ".MESSAGE_PARTITION_TYPE"; //$NON-NLS-1$ + + public MessageConsolePartition(MessageConsoleStream stream, int offset, int length) { + super(offset, length, MESSAGE_PARTITION_TYPE); + fStream = stream; + } + + + /** + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object partition) { + if (super.equals(partition)) { + fStream.equals(((MessageConsolePartition)partition).getStream()); + } + return false; + } + + /** + * @see java.lang.Object#hashCode() + */ + public int hashCode() { + return super.hashCode() + fStream.hashCode(); + } + + /** + * Returns this partition's stream + * + * @return this partition's stream + */ + public MessageConsoleStream getStream() { + return fStream; + } + + /** + * Returns whether this partition is allowed to be combined with the + * given partition. + * + * @param partition + * @return boolean + */ + public boolean canBeCombinedWith(MessageConsolePartition partition) { + int start = getOffset(); + int end = start + getLength(); + int otherStart = partition.getOffset(); + int otherEnd = otherStart + partition.getLength(); + boolean overlap = (otherStart >= start && otherStart <= end) || (start >= otherStart && start <= otherEnd); + return overlap && getType().equals(partition.getType()) && getStream().equals(partition.getStream()); + } + + /** + * Returns a new partition representing this and the given parition + * combined. + * + * @param partition + * @return partition + */ + public MessageConsolePartition combineWith(MessageConsolePartition partition) { + int start = getOffset(); + int end = start + getLength(); + int otherStart = partition.getOffset(); + int otherEnd = otherStart + partition.getLength(); + int theStart = Math.min(start, otherStart); + int theEnd = Math.max(end, otherEnd); + return createNewPartition(theStart, theEnd - theStart); + } + + /** + * Creates a new patition of this type with the given color, offset, + * and length. + * + * @param offset + * @param length + * @return a new partition with the given range + */ + public MessageConsolePartition createNewPartition(int offset, int length) { + return new MessageConsolePartition(getStream(), offset, length); + } +} diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/MessageConsolePartitioner.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/MessageConsolePartitioner.java new file mode 100644 index 000000000..2bd316586 --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/MessageConsolePartitioner.java @@ -0,0 +1,225 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.ui.internal.console; + + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.DocumentEvent; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IDocumentPartitioner; +import org.eclipse.jface.text.IDocumentPartitionerExtension; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITypedRegion; +import org.eclipse.jface.text.Region; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.console.ConsolePlugin; + +/** + * A console that displays text messages. + * + * @since 3.0 + */ +public class MessageConsolePartitioner implements IDocumentPartitioner, IDocumentPartitionerExtension { + + /** + * The associated docuemnt + */ + private IDocument fDocument = null; + + /** + * List of partitions + */ + private List fPartitions = new ArrayList(5); + + /** + * The stream that was last appended to + */ + private MessageConsoleStream fLastStream = null; + + /** + * @see org.eclipse.jface.text.IDocumentPartitioner#connect(org.eclipse.jface.text.IDocument) + */ + public void connect(IDocument document) { + fDocument = document; + document.setDocumentPartitioner(this); + } + + /** + * @see org.eclipse.jface.text.IDocumentPartitioner#disconnect() + */ + public void disconnect() { + fDocument.setDocumentPartitioner(null); + } + + /** + * @see org.eclipse.jface.text.IDocumentPartitioner#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent) + */ + public void documentAboutToBeChanged(DocumentEvent event) { + } + + /** + * @see org.eclipse.jface.text.IDocumentPartitioner#documentChanged(org.eclipse.jface.text.DocumentEvent) + */ + public boolean documentChanged(DocumentEvent event) { + return documentChanged2(event) != null; + } + + /** + * @see org.eclipse.jface.text.IDocumentPartitioner#getLegalContentTypes() + */ + public String[] getLegalContentTypes() { + return new String[] {MessageConsolePartition.MESSAGE_PARTITION_TYPE}; + } + + /** + * @see org.eclipse.jface.text.IDocumentPartitioner#getContentType(int) + */ + public String getContentType(int offset) { + ITypedRegion partition = getPartition(offset); + if (partition != null) { + return partition.getType(); + } + return null; + } + + /** + * @see org.eclipse.jface.text.IDocumentPartitioner#computePartitioning(int, int) + */ + public ITypedRegion[] computePartitioning(int offset, int length) { + if (offset == 0 && length == fDocument.getLength()) { + return (ITypedRegion[])fPartitions.toArray(new ITypedRegion[fPartitions.size()]); + } else { + int end = offset + length; + List list = new ArrayList(); + for (int i = 0; i < fPartitions.size(); i++) { + ITypedRegion partition = (ITypedRegion)fPartitions.get(i); + int partitionStart = partition.getOffset(); + int partitionEnd = partitionStart + partition.getLength(); + if ((offset >= partitionStart && offset <= partitionEnd) || + (offset < partitionStart && end >= partitionStart)) { + list.add(partition); + } + } + return (ITypedRegion[])list.toArray(new ITypedRegion[list.size()]); + } + } + + /** + * @see org.eclipse.jface.text.IDocumentPartitioner#getPartition(int) + */ + public ITypedRegion getPartition(int offset) { + for (int i = 0; i < fPartitions.size(); i++) { + ITypedRegion partition = (ITypedRegion)fPartitions.get(i); + int start = partition.getOffset(); + int end = start + partition.getLength(); + if (offset >= start && offset < end) { + return partition; + } + } + return null; + } + + /** + * @see org.eclipse.jface.text.IDocumentPartitionerExtension#documentChanged2(org.eclipse.jface.text.DocumentEvent) + */ + public IRegion documentChanged2(DocumentEvent event) { + String text = event.getText(); + if (getDocument().getLength() == 0) { + // cleared + fPartitions.clear(); + return new Region(0,0); + } + addPartition(new MessageConsolePartition(fLastStream, event.getOffset(), text.length())); + ITypedRegion[] affectedRegions = computePartitioning(event.getOffset(), text.length()); + if (affectedRegions.length == 0) { + return null; + } + if (affectedRegions.length == 1) { + return affectedRegions[0]; + } + int affectedLength = affectedRegions[0].getLength(); + for (int i = 1; i < affectedRegions.length; i++) { + ITypedRegion region = affectedRegions[i]; + affectedLength += region.getLength(); + } + return new Region(affectedRegions[0].getOffset(), affectedLength); + } + + /** + * Adds a new colored input partition, combining with the previous partition if + * possible. + */ + private MessageConsolePartition addPartition(MessageConsolePartition partition) { + if (fPartitions.isEmpty()) { + fPartitions.add(partition); + } else { + int index = fPartitions.size() - 1; + MessageConsolePartition last = (MessageConsolePartition)fPartitions.get(index); + if (last.canBeCombinedWith(partition)) { + // replace with a single partition + partition = last.combineWith(partition); + fPartitions.set(index, partition); + } else { + // different kinds - add a new parition + fPartitions.add(partition); + } + } + return partition; + } + + /** + * Creates a new paritioner and document, and connects this partitioner + * to the document. + */ + public MessageConsolePartitioner() { + IDocument doc = new Document(); + connect(doc); + } + + /** + * Adds the new text to the document. + * + * @param text the text to append + * @param stream the stream to append to + */ + public synchronized void appendToDocument(final String text, final MessageConsoleStream stream) { + Runnable r = new Runnable() { + public void run() { + fLastStream = stream; + try { + fDocument.replace(fDocument.getLength(), 0, text); + } catch (BadLocationException e) { + } + } + }; + Display display = ConsolePlugin.getStandardDisplay(); + if (display != null) { + display.asyncExec(r); + } + } + + /** + * Returns the document this partitioner is connected to, or <code>null</code> + * if none. + * + * @return the document this partitioner is connected to, or <code>null</code> + * if none + */ + public IDocument getDocument() { + return fDocument; + } + +} diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/MessageConsoleStream.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/MessageConsoleStream.java new file mode 100644 index 000000000..dc170c6c2 --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/MessageConsoleStream.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.console; + +import org.eclipse.swt.graphics.Color; +import org.eclipse.ui.console.MessageConsole; + +/** + * Used to write messages to a message console. A message console may have more + * than one stream connected to it. Each stream may be displayed in a different + * color. + * + * @since 3.0 + */ +public class MessageConsoleStream { + + private MessageConsole fConsole = null; + + private Color fColor = null; + + /** + * Constructs a new stream connected to the given console. + * + * @param partitioner the partitioner to write messages to + */ + public MessageConsoleStream(MessageConsole console) { + fConsole = console; + } + + /** + * Appends the specified message to this stream. + * + * @param message message to append + */ + public void print(String message) { + fConsole.appendToDocument(message, this); + } + + + /** + * Appends a line separator string to this stream. + */ + public void println() { + print("\n"); //$NON-NLS-1$ + } + + /** + * Appends the specified message to this stream, followed by a line + * separator string. + * + * @param message message to print + */ + public void println(String message) { + print(message); + println(); + } + + /** + * Sets the color of this message stream + * + * @param color color of this message stream, possibly <code>null</code> + */ + public void setColor(Color color) { + Color old = fColor; + fColor = color; + fConsole.firePropertyChange(this, MessageConsole.P_STREAM_COLOR, old, color); + } + + /** + * Returns the color of this message stream, or <code>null</code> + * if default. + * + * @return the color of this message stream, or <code>null</code> + */ + public Color getColor() { + return fColor; + } + +} diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/MessageConsoleViewer.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/MessageConsoleViewer.java new file mode 100644 index 000000000..438578022 --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/MessageConsoleViewer.java @@ -0,0 +1,153 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.console; + + +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.jface.text.ITypedRegion; +import org.eclipse.jface.text.TextViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.LineStyleEvent; +import org.eclipse.swt.custom.LineStyleListener; +import org.eclipse.swt.custom.StyleRange; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; + +public class MessageConsoleViewer extends TextViewer implements LineStyleListener { + + protected InternalDocumentListener fInternalDocumentListener= new InternalDocumentListener(); + + /** + * Internal document listener. + */ + class InternalDocumentListener implements IDocumentListener { + /** + * @see IDocumentListener#documentAboutToBeChanged(DocumentEvent) + */ + public void documentAboutToBeChanged(DocumentEvent e) { + } + + /** + * @see IDocumentListener#documentChanged(DocumentEvent) + */ + public void documentChanged(DocumentEvent e) { + revealEndOfDocument(); + } + } + + /** + * Creates a new console viewer and adds verification checking + * to only allow text modification if the text is being modified + * in the editable portion of the underlying document. + * + * @see org.eclipse.swt.events.VerifyListener + */ + public MessageConsoleViewer(Composite parent) { + super(parent, getSWTStyles()); + getTextWidget().setDoubleClickEnabled(true); + getTextWidget().setFont(parent.getFont()); + getTextWidget().addLineStyleListener(this); + getTextWidget().setEditable(false); + } + + /** + * Returns the SWT style flags used when instantiating this viewer + */ + private static int getSWTStyles() { + int styles= SWT.H_SCROLL | SWT.V_SCROLL; + return styles; + } + + /** + * Reveals (makes visible) the end of the current document + */ + protected void revealEndOfDocument() { + IDocument doc = getDocument(); + int lines = doc.getNumberOfLines(); + try { + // lines are 0-based + int lineStartOffset = doc.getLineOffset(lines - 1); + StyledText widget= getTextWidget(); + if (lineStartOffset > 0) { + widget.setCaretOffset(lineStartOffset); + widget.showSelection(); + } + int lineEndOffset = lineStartOffset + doc.getLineLength(lines - 1); + if (lineEndOffset > 0) { + widget.setCaretOffset(lineEndOffset); + } + } catch (BadLocationException e) { + } + } + + /** + * @see ITextViewer#setDocument(IDocument) + */ + public void setDocument(IDocument doc) { + IDocument oldDoc= getDocument(); + IDocument document= doc; + if (oldDoc == null && document == null) { + return; + } + if (oldDoc != null) { + oldDoc.removeDocumentListener(fInternalDocumentListener); + if (oldDoc.equals(document)) { + document.addDocumentListener(fInternalDocumentListener); + return; + } + } + + super.setDocument(document); + if (document != null) { + revealEndOfDocument(); + document.addDocumentListener(fInternalDocumentListener); + } + } + + /** + * @see IFindReplaceTarget#canPerformFind() + */ + protected boolean canPerformFind() { + return (getTextWidget() != null && getVisibleDocument() != null && getVisibleDocument().getLength() > 0); + } + + /** + * Dispose this viewer and resources + */ + public void dispose() { + } + + /** + * @see org.eclipse.swt.custom.LineStyleListener#lineGetStyle(org.eclipse.swt.custom.LineStyleEvent) + */ + public void lineGetStyle(LineStyleEvent event) { + IDocument document = getDocument(); + if (document != null) { + MessageConsolePartitioner partitioner = (MessageConsolePartitioner)document.getDocumentPartitioner(); + if (partitioner != null) { + ITypedRegion[] regions = partitioner.computePartitioning(event.lineOffset, event.lineOffset + event.lineText.length()); + StyleRange[] styles = new StyleRange[regions.length]; + for (int i = 0; i < regions.length; i++) { + MessageConsolePartition partition = (MessageConsolePartition)regions[i]; + Color color = partition.getStream().getColor(); + styles[i] = new StyleRange(partition.getOffset(), partition.getLength(), color, null); + } + event.styles = styles; + } + } + } + +} + diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/PinConsoleAction.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/PinConsoleAction.java new file mode 100644 index 000000000..22b55fe0a --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/PinConsoleAction.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.console; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.ui.console.IConsoleView; +import org.eclipse.ui.texteditor.IUpdate; + +/** + * Pins the currently visible console in a console view. + */ +public class PinConsoleAction extends Action implements IUpdate { + + private IConsoleView fView = null; + + /** + * Constructs a 'pin console' action + */ + public PinConsoleAction(IConsoleView view) { + super(ConsoleMessages.getString("PinConsoleAction.0"), IAction.AS_CHECK_BOX); //$NON-NLS-1$ + setToolTipText(ConsoleMessages.getString("PinConsoleAction.1")); //$NON-NLS-1$ + setImageDescriptor(ConsolePluginImages.getImageDescriptor(IInternalConsoleConstants.IMG_ELCL_PIN)); + setDisabledImageDescriptor(ConsolePluginImages.getImageDescriptor(IInternalConsoleConstants.IMG_DLCL_PIN)); + setHoverImageDescriptor(ConsolePluginImages.getImageDescriptor(IInternalConsoleConstants.IMG_LCL_PIN)); + fView = view; + update(); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.action.IAction#run() + */ + public void run() { + if (isChecked()) { + fView.pin(fView.getConsole()); + } else { + fView.pin(null); + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.texteditor.IUpdate#update() + */ + public void update() { + setEnabled(fView.getConsole() != null); + setChecked(fView.isPinned()); + } + +} diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ShowConsoleAction.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ShowConsoleAction.java new file mode 100644 index 000000000..70b99d5b5 --- /dev/null +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ShowConsoleAction.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.console; + +import org.eclipse.jface.action.Action; +import org.eclipse.ui.console.*; + +/** + * Shows a specific console in the console view + */ +public class ShowConsoleAction extends Action { + + private IConsole fConsole; + private IConsoleView fView; + + /* (non-Javadoc) + * @see org.eclipse.jface.action.IAction#run() + */ + public void run() { + if (!fConsole.equals(fView.getConsole())) { + // only change if required (and un-pin the console if pinned) + fView.pin(null); + fView.display(fConsole); + } + } + + /** + * Constructs an action to display the given console. + * + * @param view the console view in which the given console is contained + * @param console the console + */ + public ShowConsoleAction(IConsoleView view, IConsole console) { + super(); + fConsole = console; + fView = view; + setText(console.getName()); + setImageDescriptor(console.getImageDescriptor()); + } + + + +} |