Author: akazakov
Date: 2012-08-07 20:55:06 -0400 (Tue, 07 Aug 2012)
New Revision: 42899
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/BeansXmlValidationDelegate.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/multipage/DefaultMultipageEditor.java
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
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/EclipseUIUtil.java
Log:
https://issues.jboss.org/browse/JBIDE-10611 As-you-type CDI validation
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/BeansXmlValidationDelegate.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/BeansXmlValidationDelegate.java 2012-08-08
00:18:53 UTC (rev 42898)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/BeansXmlValidationDelegate.java 2012-08-08
00:55:06 UTC (rev 42899)
@@ -296,7 +296,6 @@
} catch(CoreException e) {
CDICorePlugin.getDefault().logError(e);
}
-
}
private void addLinkedResourcesForUnknownType(IFile beansXml, String typeName) {
@@ -432,10 +431,12 @@
private abstract class AbstractTypeValidator implements TypeValidator {
+ @Override
public String getTypeElementName() {
return "class"; //$NON-NLS-1$
}
+ @Override
public String validateType(CDICoreValidator.CDIValidationContext context, IType type)
throws JavaModelException {
if(!validateKindOfType(type)) {
return getIllegalTypeErrorMessage();
@@ -477,35 +478,43 @@
private class AlternativeClassValidator extends AbstractTypeValidator {
+ @Override
public boolean validateSourceType(CDICoreValidator.CDIValidationContext context, IType
type) {
IClassBean classBean = context.getCdiProject().getBeanClass(type);
return classBean!=null && classBean.isAlternative();
}
+ @Override
public String getParrentElementname() {
return "alternatives"; //$NON-NLS-1$
}
+ @Override
public String getEmptyTypeErrorMessage() {
return CDIValidationMessages.EMPTY_ALTERNATIVE_BEAN_CLASS_NAME;
}
-
+
+ @Override
public String getUnknownTypeErrorMessage() {
return CDIValidationMessages.UNKNOWN_ALTERNATIVE_BEAN_CLASS_NAME;
}
-
+
+ @Override
public int getUnknownTypeErrorMessageId() {
return CDIValidationErrorManager.UNKNOWN_ALTERNATIVE_BEAN_CLASS_NAME_ID;
}
+ @Override
public String getIllegalTypeErrorMessage() {
return CDIValidationMessages.ILLEGAL_ALTERNATIVE_BEAN_CLASS;
}
+ @Override
public int getIllegalTypeErrorMessageId() {
return CDIValidationErrorManager.ILLEGAL_ALTERNATIVE_BEAN_CLASS_ID;
}
+ @Override
public String getDuplicateTypeErrorMessage() {
return CDIValidationMessages.DUPLICATE_ALTERNATIVE_TYPE;
}
@@ -518,6 +527,7 @@
private class AlternativeStereotypeValidator extends AbstractTypeValidator {
+ @Override
public boolean validateSourceType(CDICoreValidator.CDIValidationContext context, IType
type) {
IStereotype stereotype = context.getCdiProject().getStereotype(type);
return stereotype!=null && stereotype.isAlternative();
@@ -533,30 +543,37 @@
return "stereotype"; //$NON-NLS-1$
}
+ @Override
public String getParrentElementname() {
return "alternatives"; //$NON-NLS-1$
}
+ @Override
public String getEmptyTypeErrorMessage() {
return CDIValidationMessages.EMPTY_ALTERNATIVE_ANNOTATION_NAME;
}
+ @Override
public String getUnknownTypeErrorMessage() {
return CDIValidationMessages.UNKNOWN_ALTERNATIVE_ANNOTATION_NAME;
}
+ @Override
public int getUnknownTypeErrorMessageId() {
return CDIValidationErrorManager.UNKNOWN_ALTERNATIVE_ANNOTATION_NAME_ID;
}
+ @Override
public String getIllegalTypeErrorMessage() {
return CDIValidationMessages.ILLEGAL_ALTERNATIVE_ANNOTATION;
}
+ @Override
public int getIllegalTypeErrorMessageId() {
return CDIValidationErrorManager.ILLEGAL_ALTERNATIVE_ANNOTATION_ID;
}
+ @Override
public String getDuplicateTypeErrorMessage() {
return CDIValidationMessages.DUPLICATE_ALTERNATIVE_TYPE;
}
@@ -569,35 +586,43 @@
private class DecoratorTypeValidator extends AbstractTypeValidator {
+ @Override
public boolean validateSourceType(CDICoreValidator.CDIValidationContext context, IType
type) {
IClassBean classBean = context.getCdiProject().getBeanClass(type);
return classBean instanceof IDecorator;
}
+ @Override
public String getParrentElementname() {
return "decorators"; //$NON-NLS-1$
}
+ @Override
public String getEmptyTypeErrorMessage() {
return CDIValidationMessages.EMPTY_DECORATOR_BEAN_CLASS_NAME;
}
-
+
+ @Override
public String getUnknownTypeErrorMessage() {
return CDIValidationMessages.UNKNOWN_DECORATOR_BEAN_CLASS_NAME;
}
-
+
+ @Override
public int getUnknownTypeErrorMessageId() {
return CDIValidationErrorManager.UNKNOWN_DECORATOR_BEAN_CLASS_NAME_ID;
}
+ @Override
public String getIllegalTypeErrorMessage() {
return CDIValidationMessages.ILLEGAL_DECORATOR_BEAN_CLASS;
}
+ @Override
public int getIllegalTypeErrorMessageId() {
return CDIValidationErrorManager.ILLEGAL_DECORATOR_BEAN_CLASS_ID;
}
+ @Override
public String getDuplicateTypeErrorMessage() {
return CDIValidationMessages.DUPLICATE_DECORATOR_CLASS;
}
@@ -610,35 +635,43 @@
private class InterceptorTypeValidator extends AbstractTypeValidator {
+ @Override
public boolean validateSourceType(CDICoreValidator.CDIValidationContext context, IType
type) {
IClassBean classBean = context.getCdiProject().getBeanClass(type);
return classBean instanceof IInterceptor;
}
+ @Override
public String getParrentElementname() {
return "interceptors"; //$NON-NLS-1$
}
+ @Override
public String getEmptyTypeErrorMessage() {
return CDIValidationMessages.EMPTY_INTERCEPTOR_CLASS_NAME;
}
-
+
+ @Override
public String getUnknownTypeErrorMessage() {
return CDIValidationMessages.UNKNOWN_INTERCEPTOR_CLASS_NAME;
}
-
+
+ @Override
public int getUnknownTypeErrorMessageId() {
return CDIValidationErrorManager.UNKNOWN_INTERCEPTOR_CLASS_NAME_ID;
}
+ @Override
public String getIllegalTypeErrorMessage() {
return CDIValidationMessages.ILLEGAL_INTERCEPTOR_CLASS;
}
+ @Override
public int getIllegalTypeErrorMessageId() {
return CDIValidationErrorManager.ILLEGAL_INTERCEPTOR_CLASS_ID;
}
+ @Override
public String getDuplicateTypeErrorMessage() {
return CDIValidationMessages.DUPLICATE_INTERCEPTOR_CLASS;
}
Modified:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/EclipseUIUtil.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/EclipseUIUtil.java 2012-08-08
00:18:53 UTC (rev 42898)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/EclipseUIUtil.java 2012-08-08
00:55:06 UTC (rev 42899)
@@ -10,7 +10,6 @@
******************************************************************************/
package org.jboss.tools.common.util;
-import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.resources.IFile;
@@ -31,7 +30,8 @@
private static class SafeRunnableForActivePage extends SafeRunnable {
- public ITextEditor activeEditor;
+ public ITextEditor activeTextEditor;
+ public IEditorPart activeEditor;
/*
* (non-Javadoc)
@@ -44,14 +44,14 @@
if (window != null) {
IWorkbenchPage page = window.getActivePage();
if (page != null) {
- IEditorPart editor = page.getActiveEditor();
- if (editor instanceof IEditorWrapper) {
- editor = ((IEditorWrapper) editor).getEditor();
+ activeEditor = page.getActiveEditor();
+ if (activeEditor instanceof IEditorWrapper) {
+ activeEditor = ((IEditorWrapper) activeEditor).getEditor();
}
- if (editor instanceof ITextEditor) {
- activeEditor = (ITextEditor) editor;
+ if (activeEditor instanceof ITextEditor) {
+ activeTextEditor = (ITextEditor) activeEditor;
} else {
- activeEditor = editor == null ? null :
(ITextEditor)editor.getAdapter(ITextEditor.class);
+ activeTextEditor = activeEditor == null ? null :
(ITextEditor)activeEditor.getAdapter(ITextEditor.class);
}
}
}
@@ -66,6 +66,16 @@
}
}
+ public static boolean isActiveEditorDirty() {
+ SafeRunnableForActivePage sr = new SafeRunnableForActivePage();
+ SafeRunnable.run(sr);
+ IEditorPart editor = sr.activeEditor;
+ if(editor!=null) {
+ return editor.isDirty();
+ }
+ return false;
+ }
+
/**
* Returns the active text editor.
* @return
@@ -73,7 +83,7 @@
public static ITextEditor getActiveEditor() {
SafeRunnableForActivePage sr = new SafeRunnableForActivePage();
SafeRunnable.run(sr);
- return sr.activeEditor;
+ return sr.activeTextEditor;
}
/**
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/multipage/DefaultMultipageEditor.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/multipage/DefaultMultipageEditor.java 2012-08-08
00:18:53 UTC (rev 42898)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editors/multipage/DefaultMultipageEditor.java 2012-08-08
00:55:06 UTC (rev 42899)
@@ -36,10 +36,11 @@
}
public boolean isDirty() {
- XModelObject o = getModelObject();
- if((o != null && o.isModified()) ||
- (textEditor != null && textEditor.isModified())) return true;
- return false;
+ return super.isDirty();
+// XModelObject o = getModelObject();
+// if((o != null && o.isModified()) ||
+// (textEditor != null && textEditor.isModified())) return true;
+// return false;
}
protected void setNormalMode() {
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-08-08
00:18:53 UTC (rev 42898)
+++
trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/AsYouTypeValidatorManager.java 2012-08-08
00:55:06 UTC (rev 42899)
@@ -86,35 +86,37 @@
static void removeMessages() {
UIJob job = new UIJob("Removing as-you-type JBT validation problems")
{
public IStatus runInUIThread(IProgressMonitor monitor) {
- ITextEditor e = EclipseUIUtil.getActiveEditor();
- if(e!=null && !e.isDirty()) {
- IEditorInput input = e.getEditorInput();
- IDocumentProvider dp = e.getDocumentProvider();
- IDocument doc = dp.getDocument(input);
- boolean ok = false;
- synchronized (reporters) {
- ok = reporters.contains(doc);
- }
- if(ok) {
- IAnnotationModel model = dp.getAnnotationModel(input);
- if(model instanceof AbstractMarkerAnnotationModel) {
- AbstractMarkerAnnotationModel anModel = ((AbstractMarkerAnnotationModel)model);
- synchronized (anModel.getLockObject()) {
- Iterator iterator = anModel.getAnnotationIterator();
- while (iterator.hasNext()) {
- Object o = iterator.next();
- if(o instanceof TemporaryAnnotation) {
- TemporaryAnnotation annotation = (TemporaryAnnotation)o;
- Map attributes = annotation.getAttributes();
- if(attributes!=null &&
attributes.get(TempMarkerManager.AS_YOU_TYPE_VALIDATION_ANNOTATION_ATTRIBUTE)!=null) {
+ if(!EclipseUIUtil.isActiveEditorDirty()) {
+ ITextEditor e = EclipseUIUtil.getActiveEditor();
+ if(e!=null) {
+ IEditorInput input = e.getEditorInput();
+ IDocumentProvider dp = e.getDocumentProvider();
+ IDocument doc = dp.getDocument(input);
+ boolean ok = false;
+ synchronized (reporters) {
+ ok = reporters.contains(doc);
+ }
+ if(ok) {
+ IAnnotationModel model = dp.getAnnotationModel(input);
+ if(model instanceof AbstractMarkerAnnotationModel) {
+ AbstractMarkerAnnotationModel anModel = ((AbstractMarkerAnnotationModel)model);
+ synchronized (anModel.getLockObject()) {
+ Iterator iterator = anModel.getAnnotationIterator();
+ while (iterator.hasNext()) {
+ Object o = iterator.next();
+ if(o instanceof TemporaryAnnotation) {
+ TemporaryAnnotation annotation = (TemporaryAnnotation)o;
+ Map attributes = annotation.getAttributes();
+ 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);
+ } else if(o instanceof TempJavaProblemAnnotation) {
+ TempJavaProblemAnnotation annotation = (TempJavaProblemAnnotation)o;
+ anModel.removeAnnotation(annotation);
}
- } else if(o instanceof DisabledAnnotation) {
- DisabledAnnotation annotation = (DisabledAnnotation)o;
- anModel.removeAnnotation(annotation);
- } else if(o instanceof TempJavaProblemAnnotation) {
- TempJavaProblemAnnotation annotation = (TempJavaProblemAnnotation)o;
- anModel.removeAnnotation(annotation);
}
}
}
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-08-08
00:18:53 UTC (rev 42898)
+++
trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/TempMarkerManager.java 2012-08-08
00:55:06 UTC (rev 42899)
@@ -212,8 +212,8 @@
protected void disableProblemAnnotations(final ITextSourceReference reference) {
UIJob job = new UIJob("As-you-type JBT validation. Disabling the marker
annotations.") {
public IStatus runInUIThread(IProgressMonitor monitor) {
- ITextEditor e = EclipseUIUtil.getActiveEditor();
- if(e!=null && e.isDirty()) {
+ if(EclipseUIUtil.isActiveEditorDirty()) {
+ ITextEditor e = EclipseUIUtil.getActiveEditor();
IEditorInput input = e.getEditorInput();
IDocumentProvider dp = e.getDocumentProvider();
if(document == dp.getDocument(input)) {