/*******************************************************************************
 * Copyright (c) 2009 David A Carlson.
 * All rights reserved. This program and the accompanying materials
 * are 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:
 *     David A Carlson (XMLmodeling.com) - initial API and implementation
 *     
 * $Id$
 *******************************************************************************/
package org.openhealthtools.mdht.uml.cda.ui.filters;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.viewers.IFilter;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Property;

/**
 * Selects an object if it is a UML Class or Package with 
 * HL7Template stereotype applied.
 */
public class ValidationFilter implements IFilter {

	public static final String CDA_PACKAGE_NAME = "cda";
	
	public boolean select(Object object) {
		Element element = null;
		if (object instanceof Element)
			element = (Element) object;
		else if (object instanceof IAdaptable) {
			element = (Element) ((IAdaptable)object).getAdapter(Element.class);
		}
		
		Class templateClass = null;
		if (element instanceof Class) {
			templateClass = (Class) element;
		}
		else if (element instanceof Property) {
			templateClass = ((Property)element).getClass_();
		}
		
		if (templateClass != null && getCDAClass(templateClass) != null) {
			return true;
		}
		return false;
	}

	private Class getCDAClass(Class templateClass) {
		for (Classifier parent : templateClass.allParents()) {
			if (CDA_PACKAGE_NAME.equals(parent.getNearestPackage().getName()) 
					&& parent instanceof Class) {
				return (Class) parent;
			}
		}
		
		return null;
	}
	
}

@@ -703,24 +703,66 @@
 s.IFilter;%0D%0A
+import org.eclipse.uml2.uml.Association;%0D%0A
 import org.e
@@ -822,24 +822,65 @@
 lassifier;%0D%0A
+import org.eclipse.uml2.uml.Constraint;%0D%0A
 import org.e
@@ -1628,24 +1628,328 @@
 s_();%0D%0A%09%09%7D%0D%0A
+%09%09else if (element instanceof Association) %7B%0D%0A%09%09%09templateClass = ((Association)element).getMemberEnds().get(0).getClass_();%0D%0A%09%09%7D%0D%0A%09%09else if (element instanceof Constraint%0D%0A%09%09%09%09&& ((Constraint)element).getContext() instanceof Class) %7B%0D%0A%09%09%09templateClass = (Class) ((Constraint)element).getContext();%0D%0A%09%09%7D%0D%0A
 %09%09%0D%0A%09%09if (te

Include Association and Constraint.