/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation. 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: Actuate Corporation - initial API and implementation
 ******************************************************************************/

package org.eclipse.birt.report.designer.internal.ui.views.property;

import java.util.List;

import org.eclipse.birt.report.designer.core.model.views.property.PropertySheetRootElement;
import org.eclipse.birt.report.model.api.GroupPropertyHandle;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Image;

/**
 * Lable provide for property sheet tree view.
 */
public class ReportPropertySheetLabelProvider implements ITableLabelProvider
{

	private static final String PASSWORD_REPLACEMENT = "********";//$NON-NLS-1$ 

	public Image getColumnImage( Object element, int columnIndex )
	{
		return null;
	}

	public String getColumnText( Object element, int columnIndex )
	{
		if ( columnIndex == 0 )
		{
			if ( element instanceof List )
			{
				GroupPropertyHandle property = (GroupPropertyHandle) ( ( (List) element )
						.get( 0 ) );
				return property.getPropertyDefn( ).getGroupName( );
			}
			
			if(element instanceof PropertySheetRootElement)
			{
				return ((PropertySheetRootElement)element).getDisplayName();
			}
			GroupPropertyHandle property = (GroupPropertyHandle) element;
			return property.getPropertyDefn( ).getDisplayName( );
		}
		else if ( columnIndex == 1 && element instanceof GroupPropertyHandle )
		{
			GroupPropertyHandle propertyHandle = (GroupPropertyHandle) element;
			String value = null;
			if ( propertyHandle != null )
			{
				if ( propertyHandle.getStringValue( ) != null )
				{
					if ( propertyHandle.getPropertyDefn( ).isEncryptable( ) )
					{
						value = PASSWORD_REPLACEMENT;
					}
					else
					{
						value = propertyHandle.getStringValue( );
					}
				}
			}
			if ( value == null )
				value = ""; //$NON-NLS-1$ 
			return value;
		}
		else
			return ""; //$NON-NLS-1$ 
	}

	public void addListener( ILabelProviderListener listener )
	{
	}

	public void dispose( )
	{
	}

	public boolean isLabelProperty( Object element, String property )
	{
		return false;
	}

	public void removeListener( ILabelProviderListener listener )
	{
	}
}