diff --git a/pmd-netbeans/src/pmd/Bundle.properties b/pmd-netbeans/src/pmd/Bundle.properties
index a123cb83c7..81ec115aae 100644
--- a/pmd-netbeans/src/pmd/Bundle.properties
+++ b/pmd-netbeans/src/pmd/Bundle.properties
@@ -10,3 +10,5 @@ OpenIDE-Module-Name=PMD
OpenIDE-Module-Display-Category=Tools
OpenIDE-Module-Short-Description=Runs the pmd tool
+
+LBL_pmd_annotation=Error found
diff --git a/pmd-netbeans/src/pmd/Fault.java b/pmd-netbeans/src/pmd/Fault.java
index 168f5f00df..8cb9a78ee2 100644
--- a/pmd-netbeans/src/pmd/Fault.java
+++ b/pmd-netbeans/src/pmd/Fault.java
@@ -95,4 +95,8 @@ public class Fault implements Comparable
{
return Integer.parseInt( fault.substring( fault.indexOf( '[' ) + 1, fault.indexOf( ']' ) ) );
}
-}
+
+ public static String getErrorMessage( String fault ) {
+ return fault.substring( fault.indexOf( ":" ) + 2 );
+ }
+}
\ No newline at end of file
diff --git a/pmd-netbeans/src/pmd/PMDAnnotation.java b/pmd-netbeans/src/pmd/PMDAnnotation.java
index 7345dc8f46..627d3d5266 100644
--- a/pmd-netbeans/src/pmd/PMDAnnotation.java
+++ b/pmd-netbeans/src/pmd/PMDAnnotation.java
@@ -26,30 +26,53 @@
*/
package pmd;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import org.openide.text.Annotation;
+import org.openide.text.Line;
/**
* Just a class thats mission is to mark the line where the
- * error is. It's using netbeans java compiler's annotationtype to
- * mark the line.
- * @todo create our own annotationtype
+ * error is. It's using pmd-annotation type to mark the line
* @author ole martin mørk
*/
-public class PMDAnnotation extends Annotation {
+public class PMDAnnotation extends Annotation implements PropertyChangeListener {
+ /** The error message shown on mouseover on the pmd icon */
+ private String errormessage = null;
+
/**
* The annotation type.
* @return org-netbeans-core-compiler-error
*/
public String getAnnotationType() {
- return "org-netbeans-core-compiler-error";
+ return "pmd-annotation";
}
+ /**
+ * Sets the current errormessage
+ * @param message the errormessage
+ */
+ public void setErrorMessage( String message ) {
+ errormessage = message;
+ }
+
/**
* A short description of this annotation
* @return the short description
*/
public String getShortDescription() {
- return "short description?";
+ return errormessage;
+ }
+
+ /**
+ * Invoked when the user change the content on the line where the
+ * annotation is attached
+ * @param propertyChangeEvent the event fired
+ */
+ public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
+ Line line = (Line)propertyChangeEvent.getSource();
+ line.removePropertyChangeListener( this );
+ detach();
}
}
\ No newline at end of file
diff --git a/pmd-netbeans/src/pmd/PMDOutputListener.java b/pmd-netbeans/src/pmd/PMDOutputListener.java
index 95d0f33803..228f2bced1 100644
--- a/pmd-netbeans/src/pmd/PMDOutputListener.java
+++ b/pmd-netbeans/src/pmd/PMDOutputListener.java
@@ -26,17 +26,16 @@
*/
package pmd;
-import org.openide.cookies.EditorCookie;
-import org.openide.cookies.OpenCookie;
+import org.openide.cookies.LineCookie;
import org.openide.loaders.DataObject;
import org.openide.text.Line;
import org.openide.text.Line.Set;
import org.openide.windows.OutputEvent;
import org.openide.windows.OutputListener;
-import org.openide.windows.WindowManager;
/**
+ * Listens for user actions on the output pane
* @author Ole-Martin Mørk
* @created 24. oktober 2002
*/
@@ -68,7 +67,6 @@ public class PMDOutputListener implements OutputListener
/**
* Removes the marking of the line.
- * @todo remove the marking when the line is edited
*/
public void detach()
{
@@ -81,19 +79,18 @@ public class PMDOutputListener implements OutputListener
*/
public void outputLineAction( OutputEvent outputEvent )
{
+ annotation.detach();
DataObject object = FaultRegistry.getDataObject( outputEvent.getLine() );
- OpenCookie openC = (OpenCookie)object.getCookie( OpenCookie.class );
- openC.open();
- EditorCookie cookie = (EditorCookie)WindowManager.getDefault().getRegistry().getActivatedNodes()[0].getCookie( EditorCookie.class );
- if( cookie != null ) {
- Set set = cookie.getLineSet();
- int lineNum = Fault.getLineNum( outputEvent.getLine() );
- Line line = set.getOriginal( lineNum - 1 );
- annotation.detach();
- annotation.attach( line );
- line.show( Line.SHOW_GOTO );
- }
+ LineCookie cookie = (LineCookie)object.getCookie( LineCookie.class );
+ Set set = cookie.getLineSet();
+ int lineNum = Fault.getLineNum( outputEvent.getLine() );
+ Line line = set.getOriginal( lineNum - 1 );
+ annotation.setErrorMessage( Fault.getErrorMessage( outputEvent.getLine() ) );
+ annotation.attach( line );
+ line.addPropertyChangeListener( annotation );
+ line.show( Line.SHOW_GOTO );
}
+
/**
* Not implemented
*/
diff --git a/pmd-netbeans/src/pmd/mf-layer.xml b/pmd-netbeans/src/pmd/mf-layer.xml
index 3a60f77368..2b0c750af6 100644
--- a/pmd-netbeans/src/pmd/mf-layer.xml
+++ b/pmd-netbeans/src/pmd/mf-layer.xml
@@ -1,34 +1,36 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
diff --git a/pmd-netbeans/src/pmd/resources/annotation.xml b/pmd-netbeans/src/pmd/resources/annotation.xml
new file mode 100644
index 0000000000..9be9876c02
--- /dev/null
+++ b/pmd-netbeans/src/pmd/resources/annotation.xml
@@ -0,0 +1,12 @@
+
+
+