/*******************************************************************************
 * 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.chart.reportitem.ui.dialogs.widget;

import java.util.List;

import org.eclipse.birt.report.designer.ui.views.attributes.AttributesUtil;
import org.eclipse.birt.report.designer.ui.views.attributes.IPropertyDescriptor;
import org.eclipse.birt.report.designer.ui.views.attributes.providers.ChoiceSetFactory;
import org.eclipse.birt.report.designer.ui.views.attributes.providers.PropertyProcessor;
import org.eclipse.birt.report.model.api.metadata.IChoiceSet;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;

/**
 * The abstract implementation of IPropertyDescriptor interface. The abstract
 * class provides some common process.
 */
public abstract class PropertyDescriptorAdapter implements IPropertyDescriptor
{

	/**
	 * The view part.
	 */
	protected Control control;
	/**
	 * The model part.
	 */
	protected List modelList;
	/**
	 * The processor that handles the DE model.
	 */
	protected PropertyProcessor processor;

	/**
	 * Label showing the display name.
	 */
	protected Label label;

	/**
	 * Constructor
	 */
	public PropertyDescriptorAdapter( )
	{
		this( null );
	}

	/**
	 * Constructor. Keeps the processor.
	 * 
	 * @param processor
	 *            The processor that handles the DE model.
	 */
	public PropertyDescriptorAdapter( PropertyProcessor processor )
	{
		this.processor = processor;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.birt.report.designer.ui.extensions.IPropertyDescriptor#getPropertyProcessor()
	 */
	public PropertyProcessor getPropertyProcessor( )
	{
		return processor;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.birt.report.designer.ui.extensions.IPropertyDescriptor#getControl()
	 */
	public Control getControl( )
	{
		return control;
	}

	/**
	 * Sets the lable showing the display label.
	 * 
	 * @param label
	 */
	public void setDiplayNameLabel( Label label )
	{
		this.label = label;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.birt.report.designer.ui.extensions.IPropertyDescriptor#setModelList(java.util.List)
	 */
	public void setModelList( List modelList )
	{
		this.modelList = modelList;
	}

	/**
	 * Gets the model part.
	 * 
	 * @return The model List.
	 */
	protected List getModelList( )
	{
		return modelList;
	}

	/**
	 * Gets choice set for unit.
	 * 
	 * @return
	 */
	protected IChoiceSet getUnitChoiceSet( )
	{
		return ChoiceSetFactory.getDimensionChoiceSet( getPropertyProcessor( ).getElementName( ),
				getPropertyProcessor( ).getProperty( ) );

	}

	/**
	 * Handle exceptions.
	 */
	protected void handleError( Throwable e )
	{
		AttributesUtil.handleError( e );
	}
}