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

import org.eclipse.birt.report.designer.internal.ui.views.IRequestConstants;
import org.eclipse.birt.report.designer.nls.Messages;
import org.eclipse.birt.report.designer.ui.views.ProviderFactory;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.LibraryHandle;
import org.eclipse.birt.report.model.api.SimpleMasterPageHandle;
import org.eclipse.gef.Request;
import org.eclipse.jface.viewers.IStructuredSelection;

/**
 * 
 */

public class RevertToTemplateAction extends AbstractElementAction
{

	private static final String DEFAULT_TEXT = Messages.getString( "RevertToTemplateAction.text" ); //$NON-NLS-1$	

	public RevertToTemplateAction( Object selectedObject )
	{
		super( selectedObject, DEFAULT_TEXT );
	}

	/**
	 * @param selectedObject
	 * @param text
	 */
	public RevertToTemplateAction( Object selectedObject, String text )
	{
		super( selectedObject, text );
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.birt.report.designer.internal.ui.views.actions.AbstractElementAction#doAction()
	 */
	protected boolean doAction( ) throws Exception
	{
		if ( getSelectedElement( ) == null )
		{
			return false;
		}

		else if ( getSelectedElement( ).isTemplateParameterValue( ) )
		{
			return ProviderFactory.createProvider( getSelectedElement( ) )
					.performRequest( getSelectedElement( ),
							new Request( IRequestConstants.REQUST_REVERT_TO_TEMPLATEITEM ) );
		}
		return false;
	}

	/**
	 * @return the model of selected GUI object.
	 */
	DesignElementHandle getSelectedElement( )
	{
		Object obj = super.getSelection( );
		if ( obj instanceof IStructuredSelection )
		{
			IStructuredSelection selection = (IStructuredSelection) obj;
			if ( selection.size( ) != 1 )
			{// multiple selection
				return null;
			}
			obj = selection.getFirstElement( );
		}
		if ( obj instanceof DesignElementHandle )
		{
			return (DesignElementHandle) obj;
		}
		return null;
	}

	public boolean isEnabled( )
	{
		if ( getSelectedElement( ) == null )
		{
			return false;
		}

		return super.isEnabled( )
				&& getSelectedElement( ).canTransformToTemplate( )
				&& getSelectedElement( ).isTemplateParameterValue( )
				// Can't create place holder in Simple Master Page
				&& !( getSelectedElement( ).getContainer( ) instanceof SimpleMasterPageHandle )
				&& !( getSelectedElement( ).getRoot( ) instanceof LibraryHandle );
	}

}<commit_msg>- Summary: the report items which were reverted from template items can not be revert to template items in Master Page<commit_after>/*******************************************************************************
 * 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.actions;

import org.eclipse.birt.report.designer.internal.ui.views.IRequestConstants;
import org.eclipse.birt.report.designer.nls.Messages;
import org.eclipse.birt.report.designer.ui.views.ProviderFactory;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.LibraryHandle;
import org.eclipse.birt.report.model.api.SimpleMasterPageHandle;
import org.eclipse.gef.Request;
import org.eclipse.jface.viewers.IStructuredSelection;

/**
 * 
 */

public class RevertToTemplateAction extends AbstractElementAction
{

	private static final String DEFAULT_TEXT = Messages.getString( "RevertToTemplateAction.text" ); //$NON-NLS-1$	

	public RevertToTemplateAction( Object selectedObject )
	{
		super( selectedObject, DEFAULT_TEXT );
	}

	/**
	 * @param selectedObject
	 * @param text
	 */
	public RevertToTemplateAction( Object selectedObject, String text )
	{
		super( selectedObject, text );
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.birt.report.designer.internal.ui.views.actions.AbstractElementAction#doAction()
	 */
	protected boolean doAction( ) throws Exception
	{
		if ( getSelectedElement( ) == null )
		{
			return false;
		}

		else if ( getSelectedElement( ).isTemplateParameterValue( ) )
		{
			return ProviderFactory.createProvider( getSelectedElement( ) )
					.performRequest( getSelectedElement( ),
							new Request( IRequestConstants.REQUST_REVERT_TO_TEMPLATEITEM ) );
		}
		return false;
	}

	/**
	 * @return the model of selected GUI object.
	 */
	DesignElementHandle getSelectedElement( )
	{
		Object obj = super.getSelection( );
		if ( obj instanceof IStructuredSelection )
		{
			IStructuredSelection selection = (IStructuredSelection) obj;
			if ( selection.size( ) != 1 )
			{// multiple selection
				return null;
			}
			obj = selection.getFirstElement( );
		}
		if ( obj instanceof DesignElementHandle )
		{
			return (DesignElementHandle) obj;
		}
		return null;
	}

	public boolean isEnabled( )
	{
		if ( getSelectedElement( ) == null )
		{
			return false;
		}

		return super.isEnabled( )
				&& getSelectedElement( ).canTransformToTemplate( )
				&& getSelectedElement( ).isTemplateParameterValue( )
				// Remove this type check to fix bug 148330
			//	&& !( getSelectedElement( ).getContainer( ) instanceof SimpleMasterPageHandle )
				&& !( getSelectedElement( ).getRoot( ) instanceof LibraryHandle );
	}

}
{'fraction_non_alphanumeric': 0.15177698076296056, 'fraction_numerical': 0.004238669709814151, 'mean_word_length': 4.279690189328743, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1470772', 'n_tokens_mistral': 1937, 'n_tokens_neox': 1723, 'n_words': 398}