/*******************************************************************************
 * 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.command;

import java.util.List;

import org.eclipse.birt.report.designer.core.model.SessionHandleAdapter;
import org.eclipse.birt.report.designer.internal.ui.util.ExceptionHandler;
import org.eclipse.birt.report.designer.internal.ui.util.Policy;
import org.eclipse.birt.report.designer.nls.Messages;
import org.eclipse.birt.report.model.api.CommandStack;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.SharedStyleHandle;
import org.eclipse.birt.report.model.api.command.StyleException;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.expressions.IEvaluationContext;

/**
 * 
 */

public class ApplyStyleHandler extends SelectionHandler
{


	private static final String STACK_MSG_APPLY_STYLE = Messages.getString( "ApplyStyleAction.stackMsg.applyStyle" ); //$NON-NLS-1$	

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
	public Object execute( ExecutionEvent event ) throws ExecutionException
	{
		super.execute( event );
		if ( Policy.TRACING_ACTIONS )
		{
			System.out.println( "Apply style rule action >> Run ..." ); //$NON-NLS-1$
		}
		CommandStack stack = SessionHandleAdapter.getInstance( )
				.getCommandStack( );
		stack.startTrans( STACK_MSG_APPLY_STYLE );

		boolean isChecked = true;
		SharedStyleHandle handle = null;

		IEvaluationContext context = (IEvaluationContext) event.getApplicationContext( );
		Object obj = context.getVariable( ICommandParameterNameContants.STYLE_HANDLE_NAME );
		if ( obj != null && obj instanceof SharedStyleHandle )
		{
			handle = (SharedStyleHandle) obj;
		}
		
		obj = context.getVariable( ICommandParameterNameContants.APPLAY_STYLE_ACTION_STYLE_CHECKED);
		if ( obj != null && obj instanceof Boolean )
		{
			isChecked = ((Boolean) obj).booleanValue( );
		}
		
		try
		{
			List handles = getElementHandles( );
			for ( int i = 0; i < handles.size( ); i++ )
			{
				( (DesignElementHandle) handles.get( i ) ).setStyle( isChecked ? handle
						: null );
			}
			stack.commit( );
		}
		catch ( StyleException e )
		{
			stack.rollbackAll( );
			ExceptionHandler.handle( e );
		}
		return Boolean.TRUE;
	}


}

@@ -824,16 +824,81 @@
 Policy;%0A
+import org.eclipse.birt.report.designer.internal.ui.util.UIUtil;%0A
 import o
@@ -2189,31 +2189,30 @@
 bject obj = 
-context
+UIUtil
 .getVariable
@@ -2203,33 +2203,53 @@
 Util.getVariable
-(
+FromContext( context,
  ICommandParamet
@@ -2397,23 +2397,22 @@
 %09%09obj = 
-context
+UIUtil
 .getVari
@@ -2415,17 +2415,37 @@
 Variable
-(
+FromContext( context,
  IComman
@@ -2471,41 +2471,26 @@
 nts.
-APPLAY_STYLE_ACTION_STYLE_CHECKED
+STYLE_HANDLE_NAME 
 );%0A%09

Change object cast method.