Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.ui.console')
-rw-r--r--org.eclipse.ui.console/console work.txt38
-rw-r--r--org.eclipse.ui.console/plugin.properties2
-rw-r--r--org.eclipse.ui.console/plugin.xml2
-rw-r--r--org.eclipse.ui.console/schema/ConsolePatternMatchListener.exsd129
-rw-r--r--org.eclipse.ui.console/src/org/eclipse/ui/console/IConsoleConstants.java14
-rw-r--r--org.eclipse.ui.console/src/org/eclipse/ui/console/IConsoleManager.java10
-rw-r--r--org.eclipse.ui.console/src/org/eclipse/ui/console/IOConsole.java48
-rw-r--r--org.eclipse.ui.console/src/org/eclipse/ui/console/IPatternMatchListener.java16
-rw-r--r--org.eclipse.ui.console/src/org/eclipse/ui/console/IPatternMatchListenerDelegate.java35
-rw-r--r--org.eclipse.ui.console/src/org/eclipse/ui/console/MessageConsole.java2
-rw-r--r--org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleManager.java46
-rw-r--r--org.eclipse.ui.console/src/org/eclipse/ui/internal/console/PatternMatchListener.java64
-rw-r--r--org.eclipse.ui.console/src/org/eclipse/ui/internal/console/PatternMatchListenerExtension.java128
13 files changed, 530 insertions, 4 deletions
diff --git a/org.eclipse.ui.console/console work.txt b/org.eclipse.ui.console/console work.txt
new file mode 100644
index 000000000..9eff53b4c
--- /dev/null
+++ b/org.eclipse.ui.console/console work.txt
@@ -0,0 +1,38 @@
+1. Extension Point: IPatternMatchListenerDelegate
+ id:
+ class: (new IPatternMatchListenerDelegate... only matchFound())
+ regex:
+ flags:
+ enablement:
+ test consoleType
+
+2. IConsoleManager
+ #getPatternMatchExtensions(IConsole)
+ #getPageParticipantExtensions(IConsole)
+
+3. IOConsole
+ get/setAttribute()
+ ATTR_CONSOLE_TYPE
+
+4. IConsolePageParticipantDelegate
+ init(IPageBookViewPage)
+ dispose()
+ contextMenuAboutToShoe(MenuThing)
+ toolbar(toolbar manager)
+
+5. Extension Point: IConsolePageParticipantDelegate
+ id:
+ class:
+ enablement:
+
+6. Extension: ConsoleFactory
+ id:
+ class:
+ enablement:
+ label:
+ image:
+
+7. IConsoleFactory (really a delegate)
+ IConsole openConsole()
+
+8. Clean up the junk that isn't used anymore. (ConsoleDocumentPartitioner, ConsoleDocumentProvider...) \ No newline at end of file
diff --git a/org.eclipse.ui.console/plugin.properties b/org.eclipse.ui.console/plugin.properties
index 5470175f3..986502caf 100644
--- a/org.eclipse.ui.console/plugin.properties
+++ b/org.eclipse.ui.console/plugin.properties
@@ -18,3 +18,5 @@ ViewCommand.consoleView.description=Show the Console view
ConsoleFontDefinition.description= The console text font is used by the generic console
ConsoleFontDefinition.label= Console Text Font
+
+ConsolePatternMatchListenerName= Console Pattern Match Listener \ No newline at end of file
diff --git a/org.eclipse.ui.console/plugin.xml b/org.eclipse.ui.console/plugin.xml
index 16c975b4e..dac378e1d 100644
--- a/org.eclipse.ui.console/plugin.xml
+++ b/org.eclipse.ui.console/plugin.xml
@@ -17,7 +17,9 @@
<import plugin="org.eclipse.jface.text"/>
<import plugin="org.eclipse.ui.workbench.texteditor"/>
<import plugin="org.eclipse.core.runtime"/>
+ <import plugin="org.eclipse.core.expressions"/>
</requires>
+ <extension-point id="consolePatternMatchListener" name="%ConsolePatternMatchListenerName" schema="schema/ConsolePatternMatchListener.exsd"/>
<extension
diff --git a/org.eclipse.ui.console/schema/ConsolePatternMatchListener.exsd b/org.eclipse.ui.console/schema/ConsolePatternMatchListener.exsd
new file mode 100644
index 000000000..38c167bb5
--- /dev/null
+++ b/org.eclipse.ui.console/schema/ConsolePatternMatchListener.exsd
@@ -0,0 +1,129 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.ui.console">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.ui.console" id="ConsolePatternMatchListener" name="%ConsolePatternMatchListenerName"/>
+ </appInfo>
+ <documentation>
+ This extension point provides notification when console input or output matches a specified regular expression.
+ </documentation>
+ </annotation>
+
+ <include schemaLocation="schema://org.eclipse.core.expressions/schema/expressionLanguage.exsd"/>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="consolePatternMatchListener" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+ a fully qualified identifier of the target extension point
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+ an optional identifier of the extension instance
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+ an optional name of the extension instance
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="consolePatternMatchListener">
+ <complexType>
+ <sequence>
+ <element ref="enablement"/>
+ </sequence>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+ specifies a unique identifier for this Console Pattern Match Listener
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+ specifies a fully qualified name of a Java class that implements IPatternMatchListenerDelegate
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="regex" type="string" use="required">
+ <annotation>
+ <documentation>
+ specifies the regular expression that should be matched
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="flags" type="string">
+ <annotation>
+ <documentation>
+ specifies flags to be used when matching the pattern. Acceptable flags are defined in java.util.regex.Pattern and should be specified as Strings (eg &quot;Pattern.MULTILINE&quot; or &quot;MULTILINE&quot;)
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ 3.1
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+ Copyright (c) 2000, 2004 IBM Corporation and others.&lt;br&gt;
+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
+&lt;a href=&quot;http://www.eclipse.org/legal/cpl-v10.html&quot;&gt;http://www.eclipse.org/legal/cpl-v10.html&lt;/a&gt;
+ </documentation>
+ </annotation>
+
+</schema>
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
index 5bd8bf823..58ca5d6d9 100644
--- a/org.eclipse.ui.console/src/org/eclipse/ui/console/IConsoleConstants.java
+++ b/org.eclipse.ui.console/src/org/eclipse/ui/console/IConsoleConstants.java
@@ -27,6 +27,12 @@ public interface IConsoleConstants {
* 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$
+
+ /**
+ * Type identifier for MessageConsole
+ * @since 3.1
+ */
+ public static final String MESSAGE_CONSOLE_TYPE = "org.eclipse.ui.MessageConsole"; //$NON-NLS-1$
/**
* The name of the font to use for the Console (value <code>"org.eclipse.ui.console.ConsoleFont"</code>).
@@ -58,4 +64,12 @@ public interface IConsoleConstants {
* Status code indicating an unexpected internal error.
*/
public static final int INTERNAL_ERROR = 120;
+
+ /**
+ * Console Pattern Match Listener extension point identifier
+ * (value <code>"consolePatternMatchListener"</code>).
+ *
+ * @since 3.1
+ */
+ public static final String EXTENSION_POINT_CONSOLE_PATTERN_MATCH_LISTENER = "consolePatternMatchListener"; //$NON-NLS-1$
}
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
index db3234ec1..8fd4a0070 100644
--- a/org.eclipse.ui.console/src/org/eclipse/ui/console/IConsoleManager.java
+++ b/org.eclipse.ui.console/src/org/eclipse/ui/console/IConsoleManager.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.ui.console;
+
/**
* Manages consoles.
* <p>
@@ -75,4 +76,13 @@ public interface IConsoleManager {
* @param console the console that has changed
*/
public void warnOfContentChange(IConsole console);
+
+ /**
+ * Returns an array of pattern match listeners which should be enabled for
+ * the given console.
+ * @param console The console for which PatternMatchListeners are required
+ * @return an array of IPatternMatchListner
+ * @since 3.1
+ */
+ public IPatternMatchListener[] getPatternMatchListeners(IConsole console);
}
diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/console/IOConsole.java b/org.eclipse.ui.console/src/org/eclipse/ui/console/IOConsole.java
index f929bcdc8..e43d83c32 100644
--- a/org.eclipse.ui.console/src/org/eclipse/ui/console/IOConsole.java
+++ b/org.eclipse.ui.console/src/org/eclipse/ui/console/IOConsole.java
@@ -13,6 +13,7 @@ package org.eclipse.ui.console;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -107,8 +108,13 @@ public class IOConsole extends AbstractConsole implements IDocumentListener {
private ArrayList patterns = new ArrayList();
- public IOConsole(String name, ImageDescriptor imageDescriptor) {
+ private String type;
+
+ private HashMap attributes = new HashMap();
+
+ public IOConsole(String name, String consoleType, ImageDescriptor imageDescriptor) {
super(name, imageDescriptor);
+ type = consoleType;
inputStream = new IOConsoleInputStream(this);
partitioner = new IOConsolePartitioner(inputStream, this);
Document document = new Document();
@@ -116,7 +122,42 @@ public class IOConsole extends AbstractConsole implements IDocumentListener {
partitioner.connect(document);
document.addDocumentListener(this);
}
+
+ public IOConsole(String name, ImageDescriptor imageDescriptor) {
+ this(name, null, imageDescriptor);
+ }
+
+ /**
+ * @return Returns the type.
+ */
+ public String getType() {
+ return type;
+ }
+ /**
+ * @param type The type to set.
+ */
+ public void setType(String type) {
+ this.type = type;
+ }
+
+
+ /**
+ * @return Returns the attribute matching the specified key.
+ */
+ public String getAttribute(String key) {
+ return (String)attributes.get(key);
+ }
+ /**
+ * @param key The key used to store the attribute
+ * @param value The attribute to set.
+ */
+ public void setAttribute(String key, String value) {
+ synchronized(attributes) {
+ attributes.put(key, value);
+ }
+ }
+
/**
* Returns the document this console writes to.
*
@@ -319,6 +360,9 @@ public class IOConsole extends AbstractConsole implements IDocumentListener {
synchronized (patterns) {
patterns.clear();
}
+ synchronized(attributes) {
+ attributes.clear();
+ }
}
/**
@@ -334,6 +378,7 @@ public class IOConsole extends AbstractConsole implements IDocumentListener {
Pattern pattern = Pattern.compile(matchListener.getPattern(), matchListener.getCompilerFlags());
CompiledPatternMatchListener notifier = new CompiledPatternMatchListener(pattern, matchListener);
patterns.add(notifier);
+ matchListener.connect(this);
try {
testForMatch(notifier, 0);
@@ -352,6 +397,7 @@ public class IOConsole extends AbstractConsole implements IDocumentListener {
CompiledPatternMatchListener element = (CompiledPatternMatchListener) iter.next();
if (element.listener == matchListener) {
iter.remove();
+ matchListener.disconnect();
}
}
}
diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/console/IPatternMatchListener.java b/org.eclipse.ui.console/src/org/eclipse/ui/console/IPatternMatchListener.java
index 0f9039954..421413b40 100644
--- a/org.eclipse.ui.console/src/org/eclipse/ui/console/IPatternMatchListener.java
+++ b/org.eclipse.ui.console/src/org/eclipse/ui/console/IPatternMatchListener.java
@@ -27,6 +27,10 @@ public interface IPatternMatchListener {
*/
public String getPattern();
+ /**
+ * Returns an int to be used by <code>Pattern.compile(String regex, int flags)</code>
+ * @return
+ */
public int getCompilerFlags();
/**
@@ -34,6 +38,18 @@ public interface IPatternMatchListener {
*
* @param event event describing where the match was found
*/
+
public void matchFound(PatternMatchEvent event);
+
+ /**
+ * Connects this PatternMatchListener to the console
+ * @param console The console this Listener is attached to
+ */
+ public void connect(IConsole console);
+
+ /**
+ * Disconnects this PatternMatchListener from the console
+ */
+ public void disconnect();
}
diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/console/IPatternMatchListenerDelegate.java b/org.eclipse.ui.console/src/org/eclipse/ui/console/IPatternMatchListenerDelegate.java
new file mode 100644
index 000000000..ab8d7863c
--- /dev/null
+++ b/org.eclipse.ui.console/src/org/eclipse/ui/console/IPatternMatchListenerDelegate.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 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;
+
+/**
+ * @see org.eclipse.ui.console.IOConsole
+ * @since 3.1
+ */
+public interface IPatternMatchListenerDelegate {
+ /**
+ * Connects the delegate to the console being monitored
+ * @param console the console being monitored
+ */
+ public void connect(IConsole console);
+
+ /**
+ * Disconnects the delegate from the console
+ */
+ public void disconnect();
+
+ /**
+ * Notification that a match has been found.
+ *
+ * @param event event describing where the match was found
+ */
+ public void matchFound(PatternMatchEvent event);
+}
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
index 5af3d4be0..3a2cdc1f0 100644
--- a/org.eclipse.ui.console/src/org/eclipse/ui/console/MessageConsole.java
+++ b/org.eclipse.ui.console/src/org/eclipse/ui/console/MessageConsole.java
@@ -27,7 +27,7 @@ import org.eclipse.ui.part.IPageBookViewPage;
public class MessageConsole extends IOConsole {
public MessageConsole(String name, ImageDescriptor imageDescriptor) {
- super(name, imageDescriptor);
+ super(name, IConsoleConstants.MESSAGE_CONSOLE_TYPE, imageDescriptor);
}
/**
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
index 0f008cf44..ddc31bdda 100644
--- 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
@@ -11,8 +11,12 @@
package org.eclipse.ui.internal.console;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
@@ -29,6 +33,8 @@ 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.console.IOConsole;
+import org.eclipse.ui.console.IPatternMatchListener;
/**
* The singleton console manager.
@@ -50,6 +56,8 @@ public class ConsoleManager implements IConsoleManager {
// change notification constants
private final static int ADDED = 1;
private final static int REMOVED = 2;
+
+ private List fPatternMatchListeners;
/**
* Notifies a console listener of additions or removals
@@ -129,7 +137,14 @@ public class ConsoleManager implements IConsoleManager {
public synchronized void addConsoles(IConsole[] consoles) {
List added = new ArrayList(consoles.length);
for (int i = 0; i < consoles.length; i++) {
- IConsole console = consoles[i];
+ IConsole console = consoles[i];
+ if(console instanceof IOConsole) {
+ IOConsole ioconsole = (IOConsole)console;
+ IPatternMatchListener[] matchListeners = getPatternMatchListeners(ioconsole);
+ for (int j = 0; j < matchListeners.length; j++) {
+ ioconsole.addPatternMatchListener(matchListeners[j]);
+ }
+ }
if (!fConsoles.contains(console)) {
fConsoles.add(console);
added.add(console);
@@ -237,5 +252,32 @@ public class ConsoleManager implements IConsoleManager {
}
}
}
-
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.console.IConsoleManager#getPatternMatchListenerDelegates(org.eclipse.ui.console.IConsole)
+ */
+ public IPatternMatchListener[] getPatternMatchListeners(IConsole console) {
+ if (fPatternMatchListeners == null) {
+ fPatternMatchListeners = new ArrayList();
+ IExtensionPoint extensionPoint= Platform.getExtensionRegistry().getExtensionPoint(ConsolePlugin.getUniqueIdentifier(), IConsoleConstants.EXTENSION_POINT_CONSOLE_PATTERN_MATCH_LISTENER);
+ IConfigurationElement[] elements = extensionPoint.getConfigurationElements();
+ for (int i = 0; i < elements.length; i++) {
+ IConfigurationElement extension = elements[i];
+ PatternMatchListenerExtension listener = new PatternMatchListenerExtension(extension);
+ fPatternMatchListeners.add(listener); //$NON-NLS-1$
+ }
+ }
+ ArrayList list = new ArrayList();
+ for(Iterator i = fPatternMatchListeners.iterator(); i.hasNext(); ) {
+ PatternMatchListenerExtension extension = (PatternMatchListenerExtension) i.next();
+ try {
+ if (extension.isEnabledFor(console)) {
+ list.add(new PatternMatchListener(extension));
+ }
+ } catch (CoreException e) {
+ ConsolePlugin.log(e);
+ }
+ }
+ return (PatternMatchListener[])list.toArray(new PatternMatchListener[0]);
+ }
}
diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/PatternMatchListener.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/PatternMatchListener.java
new file mode 100644
index 000000000..b927bc620
--- /dev/null
+++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/PatternMatchListener.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 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.core.runtime.CoreException;
+import org.eclipse.ui.console.IConsole;
+import org.eclipse.ui.console.IPatternMatchListener;
+import org.eclipse.ui.console.IPatternMatchListenerDelegate;
+import org.eclipse.ui.console.PatternMatchEvent;
+
+public class PatternMatchListener implements IPatternMatchListener {
+
+ private PatternMatchListenerExtension fExtension;
+ private IPatternMatchListenerDelegate fDelegate;
+
+ public PatternMatchListener(PatternMatchListenerExtension extension) throws CoreException {
+ fExtension = extension;
+ fDelegate = fExtension.createDelegate();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.console.IPatternMatchListener#getPattern()
+ */
+ public String getPattern() {
+ return fExtension.getPattern();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.console.IPatternMatchListener#getCompilerFlags()
+ */
+ public int getCompilerFlags() {
+ return fExtension.getCompilerFlags();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.console.IPatternMatchListener#matchFound(org.eclipse.ui.console.PatternMatchEvent)
+ */
+ public void matchFound(PatternMatchEvent event) {
+ fDelegate.matchFound(event);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.console.IPatternMatchListener#connect(org.eclipse.ui.console.IConsole)
+ */
+ public void connect(IConsole console) {
+ fDelegate.connect(console);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.console.IPatternMatchListener#disconnect()
+ */
+ public void disconnect() {
+ fDelegate.disconnect();
+ }
+
+}
diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/PatternMatchListenerExtension.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/PatternMatchListenerExtension.java
new file mode 100644
index 000000000..41fafba93
--- /dev/null
+++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/PatternMatchListenerExtension.java
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 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.lang.reflect.Field;
+
+import org.eclipse.core.expressions.EvaluationContext;
+import org.eclipse.core.expressions.EvaluationResult;
+import org.eclipse.core.expressions.Expression;
+import org.eclipse.core.expressions.ExpressionConverter;
+import org.eclipse.core.expressions.ExpressionTagNames;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.ui.IPluginContribution;
+import org.eclipse.ui.console.ConsolePlugin;
+import org.eclipse.ui.console.IConsole;
+import org.eclipse.ui.console.IPatternMatchListenerDelegate;
+
+public class PatternMatchListenerExtension implements IPluginContribution {
+
+ private IConfigurationElement fConfig;
+ private Expression fEnablementExpression;
+ private String fPattern;
+ private int fFlags = -1;
+
+ public PatternMatchListenerExtension(IConfigurationElement extension) {
+ fConfig = extension;
+ }
+
+ public int parseFlags(String flagsElement) {
+ int val = 0;
+ if (flagsElement == null) {
+ return val;
+ }
+
+ try {
+ flagsElement = flagsElement.replaceAll("Pattern.", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ String[] tokens = flagsElement.split("\\s\\|\\s"); //$NON-NLS-1$
+ Class clazz = Class.forName("java.util.regex.Pattern"); //$NON-NLS-1$
+
+ for (int i = 0; i < tokens.length; i++) {
+ Field field = clazz.getDeclaredField(tokens[i]);
+ val |= field.getInt(null);
+ }
+ } catch (ClassNotFoundException e) {
+ ConsolePlugin.log(e);
+ } catch (NoSuchFieldException e) {
+ ConsolePlugin.log(e);
+ } catch (IllegalAccessException e) {
+ ConsolePlugin.log(e);
+ }
+ return val;
+ }
+
+ public boolean isEnabledFor(IConsole console) throws CoreException {
+ EvaluationContext context = new EvaluationContext(null, console);
+ EvaluationResult evaluationResult = getEnablementExpression().evaluate(context);
+ return evaluationResult == EvaluationResult.TRUE;
+ }
+
+ public String getId() {
+ return fConfig.getAttribute("id"); //$NON-NLS-1$
+ }
+
+ /**
+ * @return
+ * @throws CoreException
+ */
+ public IPatternMatchListenerDelegate createDelegate() throws CoreException {
+ return (IPatternMatchListenerDelegate) fConfig.createExecutableExtension("class"); //$NON-NLS-1$
+ }
+
+ public Expression getEnablementExpression() throws CoreException {
+ if (fEnablementExpression == null) {
+ IConfigurationElement[] elements = fConfig.getChildren(ExpressionTagNames.ENABLEMENT);
+ IConfigurationElement enablement = elements.length > 0 ? elements[0] : null;
+
+ if (enablement != null) {
+ fEnablementExpression = ExpressionConverter.getDefault().perform(enablement);
+ }
+ }
+ return fEnablementExpression;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.console.IPatternMatchListener#getPattern()
+ */
+ public String getPattern() {
+ if (fPattern == null) {
+ fPattern = fConfig.getAttributeAsIs("regex"); //$NON-NLS-1$
+ }
+ return fPattern;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.console.IPatternMatchListener#getCompilerFlags()
+ */
+ public int getCompilerFlags() {
+ if(fFlags < 0) {
+ String flagsAttribute = fConfig.getAttributeAsIs("flags"); //$NON-NLS-1$
+ fFlags = parseFlags(flagsAttribute);
+ }
+ return fFlags;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPluginContribution#getLocalId()
+ */
+ public String getLocalId() {
+ return getId();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IPluginContribution#getPluginId()
+ */
+ public String getPluginId() {
+ return fConfig.getDeclaringExtension().getNamespace();
+ }
+
+}

Back to the top