package de.ugoe.cs.swe.exercises.lecture;

import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;

public class LectureFilter extends ViewerFilter {

	private String searchString;

	public void setSearchText(String s) {
		// Search must be a substring of the existing value
		this.searchString = ".*" + s + ".*";
	}

	//Filters only for first and last name of the lecturer, not the title or ID.
	@Override
	public boolean select(Viewer viewer, Object parentElement, Object element) {
		if (searchString == null || searchString.length() == 0) {
			return true;
		}
		Lecture lelement = (Lecture) element;
		if (lelement.getName().toLowerCase().matches(searchString.toLowerCase())) {
			return true;
		}
		return false;
	}
}

	