<commit_before>/*******************************************************************************
 * Copyright (c) 2012 MEDEVIT <<EMAIL>>.
 * 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:
 *     MEDEVIT <<EMAIL>> - initial API and implementation
 ******************************************************************************/
package ch.elexis.core.ui.contacts.views.provider;

import org.eclipse.jface.viewers.DecoratingLabelProvider;
import org.eclipse.jface.viewers.ILabelDecorator;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;

import ch.elexis.core.model.IContact;

/**
 * @author <NAME>
 * 
 */
public class TableDecoratingLabelProvider extends DecoratingLabelProvider implements
		ITableLabelProvider {
	
	ITableLabelProvider provider;
	ILabelDecorator decorator;
	
	/**
	 * @param provider
	 * @param decorator
	 */
	public TableDecoratingLabelProvider(ILabelProvider provider, ILabelDecorator decorator){
		super(provider, decorator);
		this.provider = (ITableLabelProvider) provider;
		this.decorator = decorator;
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
	 */
	public Image getColumnImage(Object element, int columnIndex){
		Image image = provider.getColumnImage(element, columnIndex);
		if (decorator != null) {
			Image decorated = decorator.decorateImage(image, element);
			if (decorated != null) {
				return decorated;
			}
		}
		return image;
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
	 */
	public String getColumnText(Object element, int columnIndex){
		String text = provider.getColumnText(element, columnIndex);
		if (decorator != null) {
			String decorated = decorator.decorateText(text, element);
			if (decorated != null) {
				return decorated;
			}
		}
		return text;
	}
	
	@Override
	public Color getForeground(Object element){
		IContact c = (IContact) element;
		if (c.isDeleted())
			return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
		return null;
	}
	
}<commit_msg>[20563] TableDecoratingLabelProvider handle different IContact instances<commit_after>/*******************************************************************************
 * Copyright (c) 2012 MEDEVIT <<EMAIL>>.
 * 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:
 *     MEDEVIT <<EMAIL>> - initial API and implementation
 ******************************************************************************/
package ch.elexis.core.ui.contacts.views.provider;

import org.eclipse.jface.viewers.DecoratingLabelProvider;
import org.eclipse.jface.viewers.ILabelDecorator;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;

import ch.elexis.core.model.IContact;

/**
 * @author <NAME>
 * 
 */
public class TableDecoratingLabelProvider extends DecoratingLabelProvider implements
		ITableLabelProvider {
	
	ITableLabelProvider provider;
	ILabelDecorator decorator;
	
	/**
	 * @param provider
	 * @param decorator
	 */
	public TableDecoratingLabelProvider(ILabelProvider provider, ILabelDecorator decorator){
		super(provider, decorator);
		this.provider = (ITableLabelProvider) provider;
		this.decorator = decorator;
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
	 */
	public Image getColumnImage(Object element, int columnIndex){
		Image image = provider.getColumnImage(element, columnIndex);
		if (decorator != null) {
			Image decorated = decorator.decorateImage(image, element);
			if (decorated != null) {
				return decorated;
			}
		}
		return image;
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
	 */
	public String getColumnText(Object element, int columnIndex){
		String text = provider.getColumnText(element, columnIndex);
		if (decorator != null) {
			String decorated = decorator.decorateText(text, element);
			if (decorated != null) {
				return decorated;
			}
		}
		return text;
	}
	
	@Override
	public Color getForeground(Object element){
		if (element instanceof ch.elexis.core.data.interfaces.IContact) {
			ch.elexis.core.data.interfaces.IContact c =
				(ch.elexis.core.data.interfaces.IContact) element;
			if (c.isDeleted())
				return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
		} else if (element instanceof IContact) {
			IContact c = (IContact) element;
			if (c.isDeleted())
				return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
		}
		return null;
	}
	
}
{'fraction_non_alphanumeric': 0.16221267052887312, 'fraction_numerical': 0.0039245000934404785, 'mean_word_length': 4.730192719486081, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6726511', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1588, 'n_words': 348}