/*******************************************************************************
 * 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.jface.viewers.IFilter;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Type;

/**
 * Abstract class for filters that are based on CDA parent type.
 */
public abstract class CDAFilter implements IFilter {

	public static final String CDA_PACKAGE_NAME = "cda";
	
	public abstract boolean select(Object object);

	protected Class getCDAClass(Class templateClass) {
		Class cdaClass = null;
		
		// if the provided class is from CDA and not a template
		if (CDA_PACKAGE_NAME.equals(templateClass.getNearestPackage().getName()))
			return templateClass;
		
		for (Classifier parent : templateClass.allParents()) {
			// nearest package may be null if CDA model is not available
			if (parent.getNearestPackage() != null) {
				if (CDA_PACKAGE_NAME.equals(parent.getNearestPackage().getName()) && parent instanceof Class) {
					cdaClass = (Class) parent;
					break;
				}
			}
		}
		
		return cdaClass;
	}

	protected boolean isSection(Type templateClass) {
		if (templateClass instanceof Class) {
			Class cdaClass = getCDAClass((Class)templateClass);
			if (cdaClass != null && "Section".equals(cdaClass.getName()))
				return true;
		}
		
		return false;
	}
	
	protected boolean isClinicalStatement(Type templateClass) {
		if (templateClass instanceof Class) {
			Class cdaClass = getCDAClass((Class)templateClass);
			String cdaName = cdaClass==null ? null : cdaClass.getName();
			if (cdaClass != null && (
					"Act".equals(cdaName) || "Encounter".equals(cdaName)
					|| "Observation".equals(cdaName) || "ObservationMedia".equals(cdaName)
					|| "Organizer".equals(cdaName) || "Procedure".equals(cdaName)
					|| "RegionOfInterest".equals(cdaName) || "SubstanceAdministration".equals(cdaName)
					|| "Supply".equals(cdaName))) {
				return true;
			}
		}
		
		return false;
	}
	
}

@@ -619,16 +619,61 @@
 ers;%0D%0A%0D%0A
+import org.eclipse.core.runtime.IAdaptable;%0D%0A
 import o
@@ -703,24 +703,24 @@
 s.IFilter;%0D%0A
-
 import org.e
@@ -780,24 +780,62 @@
 lassifier;%0D%0A
+import org.eclipse.uml2.uml.Element;%0D%0A
 import org.e
@@ -1049,16 +1049,16 @@
 a%22;%0D%0A%09%0D%0A
-
 %09public 
@@ -1096,24 +1096,308 @@
 object);%0D%0A%0D%0A
+%09protected Element getElement(Object object) %7B%0D%0A%09%09Element element = null;%0D%0A%09%09if (object instanceof Element)%0D%0A%09%09%09element = (Element) object;%0D%0A%09%09else if (object instanceof IAdaptable)%0D%0A%09%09%09element = (Element) ((IAdaptable)object).getAdapter(Element.class);%0D%0A%09%09%0D%0A%09%09return element;%0D%0A%09%7D%0D%0A%0D%0A
 %09protected C

Add getElement() method.