package org.openhealthtools.mdht.uml.cda.ui.util;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.EnumerationLiteral;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Stereotype;
import org.openhealthtools.mdht.uml.cda.resources.util.CDAProfileUtil;
import org.openhealthtools.mdht.uml.cda.resources.util.ICDAProfileConstants;
import org.openhealthtools.mdht.uml.cda.ui.internal.Activator;
import org.openhealthtools.mdht.uml.common.notation.INotationProvider;

public class CDAAnnotationProvider implements INotationProvider, IExecutableExtension {

	public final static int CDA_CLASS_ANNOTATION = IHL7Appearance.DISP_TEMPLATE_ID;
	public final static int CDA_ASSOCIATION_ANNOTATION = IHL7Appearance.DISP_VOCABULARY;
	public final static int CDA_PROPERTY_ANNOTATION = IHL7Appearance.DISP_VOCABULARY | IHL7Appearance.DISP_UPDATE_MODE;

	public static final String SEVERITY_ERROR = "ERROR";
	public static final String SEVERITY_WARNING = "WARNING";
	public static final String SEVERITY_INFO = "INFO";

	public String getPrintString(Element element) {
		String printString = null;

		if (element instanceof Class) {
			printString = CDAClassNotation.getCustomLabel((Class)element, IHL7Appearance.DEFAULT_HL7_CLASS);
		}
		else if (element instanceof Association) {
			printString = CDAAssociationNotation.getCustomLabel((Association)element, IHL7Appearance.DISP_NAME);
		}
		else if (element instanceof Property) {
			printString = CDAPropertyNotation.getCustomLabel((Property)element, IHL7Appearance.DEFAULT_HL7_PROPERTY);
		}
		
		return printString;
	}

	public String getAnnotation(Element element) {
		String annotation = null;
		
		if (element instanceof Class) {
			annotation = CDAClassNotation.getCustomLabel((Class)element, CDA_CLASS_ANNOTATION);
		}
		else if (element instanceof Association) {
			annotation = CDAAssociationNotation.getCustomLabel((Association)element, CDA_ASSOCIATION_ANNOTATION);
		}
		else if (element instanceof Property) {
			annotation = CDAPropertyNotation.getCustomLabel((Property)element, CDA_PROPERTY_ANNOTATION);
		}
		
		return annotation;
	}

	public Object getElementImage(Element element) {
		return null;
	}

	public Object getAnnotationImage(Element element) {
		Stereotype validationSupport = CDAProfileUtil.getAppliedCDAStereotype(element, ICDAProfileConstants.VALIDATION);
		if (validationSupport != null) {
			EnumerationLiteral literal = (EnumerationLiteral) element.getValue(validationSupport, ICDAProfileConstants.VALIDATION_SEVERITY);
			if (literal != null) {
				String severity = literal.getName();

				if (SEVERITY_INFO.equals(severity)) {
					return Activator.getDefault().getBundledImage("/icons/full/obj16/information.gif");
				} else if (SEVERITY_WARNING.equals(severity)) {
					return Activator.getDefault().getBundledImage("/icons/full/obj16/warning.gif");
				} else if (SEVERITY_ERROR.equals(severity)) {
					return Activator.getDefault().getBundledImage("/icons/full/obj16/error.gif");
				}
			}
		}
		
		return null;
	}

	public void setInitializationData(IConfigurationElement config, String propertyName, Object data)
			throws CoreException {
		// do nothing
	}

}

@@ -201,24 +201,72 @@
 Extension;%0D%0A
+import org.eclipse.emf.common.util.Enumerator;%0D%0A
 import org.e
@@ -2735,57 +2735,24 @@
 %0A%09%09%09
-EnumerationLiteral literal = (EnumerationLiteral)
+Object literal =
  ele
@@ -2835,61 +2835,227 @@
 %0A%09%09%09
-if (literal != null) %7B%0D%0A%09%09%09%09String severity = 
+String severity = null;%0D%0A%09%09%09if (literal instanceof EnumerationLiteral) %7B%0D%0A%09%09%09%09severity = ((EnumerationLiteral)literal).getName();%0D%0A%09%09%09%7D%0D%0A%09%09%09else if (literal instanceof Enumerator) %7B%0D%0A%09%09%09%09severity = ((Enumerator)
 literal
+)
 .get
@@ -3063,16 +3063,53 @@
 ame();%0D%0A
+%09%09%09%7D%0D%0A%09%09%09%0D%0A%09%09%09if (severity != null) %7B
 %0D%0A%09%09%09%09if

Support static profile definition.