[jbosstools-commits] JBoss Tools SVN: r41652 - trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Jun 1 20:03:14 EDT 2012


Author: akazakov
Date: 2012-06-01 20:03:13 -0400 (Fri, 01 Jun 2012)
New Revision: 41652

Added:
   trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/DisabledAnnotation.java
Modified:
   trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/AsYouTypeValidatorManager.java
   trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/TempMarkerManager.java
Log:
https://issues.jboss.org/browse/JBIDE-10738 As-you-type EL validation

Modified: trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/AsYouTypeValidatorManager.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/AsYouTypeValidatorManager.java	2012-06-01 23:41:40 UTC (rev 41651)
+++ trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/AsYouTypeValidatorManager.java	2012-06-02 00:03:13 UTC (rev 41652)
@@ -103,6 +103,9 @@
 										if(attributes!=null && attributes.get(TempMarkerManager.AS_YOU_TYPE_VALIDATION_ANNOTATION_ATTRIBUTE)!=null) {
 											anModel.removeAnnotation(annotation);
 										}
+									} else if(o instanceof DisabledAnnotation) {
+										DisabledAnnotation annotation = (DisabledAnnotation)o;
+										anModel.removeAnnotation(annotation);
 									}
 								}
 							}

Added: trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/DisabledAnnotation.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/DisabledAnnotation.java	                        (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/DisabledAnnotation.java	2012-06-02 00:03:13 UTC (rev 41652)
@@ -0,0 +1,88 @@
+/******************************************************************************* 
+ * Copyright (c) 2012 Red Hat, Inc. 
+ * Distributed under license by Red Hat, Inc. All rights reserved. 
+ * This program is made available under the terms of the 
+ * Eclipse Public License v1.0 which accompanies this distribution, 
+ * and is available at http://www.eclipse.org/legal/epl-v10.html 
+ * 
+ * Contributors: 
+ * Red Hat, Inc. - initial API and implementation 
+ ******************************************************************************/
+package org.jboss.tools.common.validation;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.IAnnotationAccessExtension;
+import org.eclipse.jface.text.source.IAnnotationPresentation;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.ui.editors.text.EditorsUI;
+import org.eclipse.ui.internal.WorkbenchImages;
+import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
+import org.eclipse.ui.internal.util.BundleUtility;
+import org.eclipse.ui.texteditor.AnnotationPreference;
+import org.eclipse.ui.texteditor.AnnotationPreferenceLookup;
+import org.eclipse.ui.texteditor.ImageUtilities;
+
+/**
+ * @author Alexey Kazakov
+ */
+public class DisabledAnnotation extends Annotation implements IAnnotationPresentation {
+
+    private static final int WARNING_LAYER;
+    private static final int ERROR_LAYER;
+
+    private Map<String, Object> fAttributes = new HashMap<String, Object>();
+
+    private int seveirty = WARNING_LAYER;
+
+    static {
+        AnnotationPreferenceLookup lookup = EditorsUI.getAnnotationPreferenceLookup();
+        WARNING_LAYER = computeLayer("org.eclipse.wst.sse.ui.temp.warning", lookup); //$NON-NLS-1$
+        ERROR_LAYER = computeLayer("org.eclipse.wst.sse.ui.temp.error", lookup); //$NON-NLS-1$
+    }
+
+    private static int computeLayer(String annotationType, AnnotationPreferenceLookup lookup) {
+        Annotation annotation = new Annotation(annotationType, false, null);
+        AnnotationPreference preference= lookup.getAnnotationPreference(annotation);
+        if (preference != null) {
+            return preference.getPresentationLayer() + 1;
+        } else {
+            return IAnnotationAccessExtension.DEFAULT_LAYER + 1;
+        }
+    }
+
+	public DisabledAnnotation(String type, boolean isPersistent, String text, boolean warning) {
+		super(type, isPersistent, text);
+		this.seveirty = warning?WARNING_LAYER:ERROR_LAYER;
+	}
+
+	@Override
+	public int getLayer() {
+        return seveirty;
+	}
+
+	@Override
+	public void paint(GC gc, Canvas canvas, Rectangle bounds) {
+		String path = seveirty==WARNING_LAYER? (WorkbenchImages.ICONS_PATH + "dlcl16/showwarn_tsk.gif") : (WorkbenchImages.ICONS_PATH + "dlcl16/showerr_tsk.gif"); //$NON-NLS-1$
+        URL url = BundleUtility.find(IDEWorkbenchPlugin.IDE_WORKBENCH, path);
+        ImageDescriptor descriptor = ImageDescriptor.createFromURL(url);
+		Image image = descriptor.createImage(false);
+		ImageUtilities.drawImage(image, gc, canvas, bounds, SWT.CENTER, SWT.TOP);
+	}
+
+	public Object getAttribute(String key) {
+		return fAttributes.get(key);
+	}
+	
+	public void setAttribute(String key, Object value) {
+		fAttributes.put(key, value);
+	}
+}
\ No newline at end of file


Property changes on: trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/DisabledAnnotation.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/TempMarkerManager.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/TempMarkerManager.java	2012-06-01 23:41:40 UTC (rev 41651)
+++ trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/TempMarkerManager.java	2012-06-02 00:03:13 UTC (rev 41652)
@@ -11,9 +11,11 @@
 package org.jboss.tools.common.validation;
 
 import java.text.MessageFormat;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Locale;
+import java.util.Map;
 import java.util.Set;
 
 import org.eclipse.core.resources.IFile;
@@ -24,6 +26,8 @@
 import org.eclipse.core.runtime.Status;
 import org.eclipse.jdt.core.JavaModelException;
 import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.source.Annotation;
 import org.eclipse.jface.text.source.IAnnotationModel;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.progress.UIJob;
@@ -96,50 +100,8 @@
 		reporter.addMessage(validator, message);
 		return message;
 	}
-/*
-	static class DisabledAnnotation extends Annotation implements IAnnotationPresentation {
 
-	    private static final int WARNING_LAYER;
-	    private static final int ERROR_LAYER;
-
-	    static {
-	        AnnotationPreferenceLookup lookup = EditorsUI.getAnnotationPreferenceLookup();
-	        WARNING_LAYER = computeLayer("org.eclipse.wst.sse.ui.temp.warning", lookup); //$NON-NLS-1$
-	        ERROR_LAYER = computeLayer("org.eclipse.wst.sse.ui.temp.error", lookup); //$NON-NLS-1$
-	    }
-
-	    private static int computeLayer(String annotationType, AnnotationPreferenceLookup lookup) {
-	        Annotation annotation = new Annotation(annotationType, false, null);
-	        AnnotationPreference preference= lookup.getAnnotationPreference(annotation);
-	        if (preference != null) {
-	            return preference.getPresentationLayer() + 1;
-	        } else {
-	            return IAnnotationAccessExtension.DEFAULT_LAYER + 1;
-	        }
-	    }
-
-		public DisabledAnnotation(String type, boolean isPersistent, String text) {
-			super(type, isPersistent, text);
-		}
-
-		@Override
-		public int getLayer() {
-	        return WARNING_LAYER;
-		}
-
-		@Override
-		public void paint(GC gc, Canvas canvas, Rectangle bounds) {
-			String path = WorkbenchImages.ICONS_PATH + "dlcl16/showwarn_tsk.gif"; //$NON-NLS-1$
-	        URL url = BundleUtility.find(IDEWorkbenchPlugin.IDE_WORKBENCH, path);
-	        ImageDescriptor descriptor = ImageDescriptor.createFromURL(url);
-			Image image = descriptor.createImage(false);
-//			ImageUtilities.drawImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK), gc, canvas, bounds, SWT.CENTER, SWT.TOP);
-			ImageUtilities.drawImage(image, gc, canvas, bounds, SWT.CENTER, SWT.TOP);
-		}
-	}
-*/
 	protected void disableProblemAnnotations(final ITextSourceReference reference) {
-		// Remove (TODO disable) all the existing problem annotations for the reference in case of as-you-type validation
         UIJob job = new UIJob("As-you-type JBT validation. Disabling the marker annotations.") {
 			public IStatus runInUIThread(IProgressMonitor monitor) {
 				ITextEditor e = EclipseUIUtil.getActiveEditor();
@@ -153,7 +115,7 @@
 							synchronized (anModel.getLockObject()) {
 								Iterator iterator = anModel.getAnnotationIterator(reference.getStartPosition(), reference.getLength(), true, true);
 								Set<MarkerAnnotation> annotationsToRemove = new HashSet<MarkerAnnotation>();
-//								Map<Annotation, Position> newAnnotations = new HashMap<Annotation, Position>();
+								Map<Annotation, Position> newAnnotations = new HashMap<Annotation, Position>();
 								while (iterator.hasNext()) {
 									Object o = iterator.next();
 									if(o instanceof MarkerAnnotation) {
@@ -162,11 +124,11 @@
 										try {
 											String type = marker.getType();
 											if(getMarkerType().equals(type)) {
-//												Annotation newAnnotation = new DisabledAnnotation(annotation.getType(), false, annotation.getText());
-//												int offset = marker.getAttribute(IMarker.CHAR_START, 0);
-//												int length = 0; // marker.getAttribute(IMarker.CHAR_END, 0) - offset;
-//												Position p = new Position(offset, length);
-//												newAnnotations.put(newAnnotation, p);
+												Annotation newAnnotation = new DisabledAnnotation(annotation.getType(), false, annotation.getText(), marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING) == IMarker.SEVERITY_WARNING);
+												int offset = marker.getAttribute(IMarker.CHAR_START, 0);
+												int length = 0; // marker.getAttribute(IMarker.CHAR_END, 0) - offset;
+												Position p = new Position(offset, length);
+												newAnnotations.put(newAnnotation, p);
 												annotationsToRemove.add(annotation);
 											}
 										} catch (CoreException ce) {
@@ -181,9 +143,9 @@
 								for (MarkerAnnotation annotation : annotationsToRemove) {
 									anModel.removeAnnotation(annotation);
 								}
-//								for (Annotation annotation : newAnnotations.keySet()) {
-//									anModel.addAnnotation(annotation, newAnnotations.get(annotation));
-//								}
+								for (Annotation annotation : newAnnotations.keySet()) {
+									anModel.addAnnotation(annotation, newAnnotations.get(annotation));
+								}
 							}
 						}
 					}



More information about the jbosstools-commits mailing list