<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.core.commands;

import java.util.Map;

import org.eclipse.birt.report.designer.core.DesignerConstants;
import org.eclipse.birt.report.designer.util.DEUtil;
import org.eclipse.birt.report.model.api.DataSourceHandle;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.SlotHandle;
import org.eclipse.birt.report.model.api.activity.SemanticException;
import org.eclipse.gef.commands.Command;

/**
 * This command adds an object to the model. The object is not created by this
 * command, but simply attached to the parent object.
 * 
 * 
 */

public class CreateCommand extends Command
{

	private Object parent;

	private Object after;

	private Map extendsData;

	/**
	 * Constructor
	 * 
	 * @param extendsData
	 */
	public CreateCommand( Map extendsData )
	{
		this.extendsData = extendsData;
	}

	/**
	 * Executes the Command. This method should not be called if the Command is
	 * not executable.
	 */
	public void execute( )
	{
		//DesignElementHandle newObject = (DesignElementHandle) extendsData.get( DesignerConstants.KEY_NEWOBJECT );
		DesignElementHandle newObject = getNewObject();
		if ( DesignerConstants.TRACING_COMMANDS )
		{
			System.out.println( "CreateCommand >> Starts ... " ); //$NON-NLS-1$
		}
		try
		{
			// For all virtual model node keep the SlotHandle
			if ( parent instanceof SlotHandle )
			{
				if ( after != null )
				{
					int pos = DEUtil.findInsertPosition( ( (SlotHandle) parent ).getElementHandle( ),
							(DesignElementHandle) after,
							( (SlotHandle) parent ).getSlotID( ) );
					( (SlotHandle) parent ).add( newObject, pos );

				}
				else
				{
					( (SlotHandle) parent ).add( newObject );
				}

			}
			else if( newObject instanceof DataSourceHandle)//simply add to datasource slot.
			{
				( (DesignElementHandle) parent ).addElement( newObject,
						ReportDesignHandle.DATA_SOURCE_SLOT );
			}
			else
			{
				// calculate the position of added element
				if ( after != null )
				{
					int pos = DEUtil.findInsertPosition( (DesignElementHandle) parent,
							(DesignElementHandle) after );
					int slotID = DEUtil.findSlotID( parent, after );

					( (DesignElementHandle) parent ).addElement( newObject,
							slotID,
							pos );
				}
				else
				{
					( (DesignElementHandle) parent ).addElement( newObject,
							DEUtil.getDefaultSlotID( parent ) );
				}
			}
			if ( DesignerConstants.TRACING_COMMANDS )
			{
				System.out.println( "CreateCommand >> Finished. " //$NON-NLS-1$
						+ DEUtil.getDisplayLabel( newObject )
						+ " created" ); //$NON-NLS-1$
			}
		}
		catch ( SemanticException e )
		{
			if ( DesignerConstants.TRACING_COMMANDS )
			{
				System.out.println( "CreateCommand >> Failed" ); //$NON-NLS-1$
			}
			e.printStackTrace( );
		}
	}

	/**
	 * Gets the parent edit part the new report element be added on.
	 * 
	 * @return Returns the parent.
	 */
	public Object getParent( )
	{
		return parent;
	}

	/**
	 * Sets the parent edit part the new report element be added on.
	 * 
	 * @param parent
	 *            The parent to set.
	 */
	public void setParent( Object parent )
	{
		this.parent = parent;
	}

	/**
	 * Gets the edit part the new report element be added after.
	 * 
	 * @param model
	 *            The model after the new element
	 */
	public void setAfter( Object model )
	{
		this.after = model;

	}
	
	/**
	 *  Get the new object
	 * @return
	 *   Return the object
	 */
	public DesignElementHandle getNewObject()
	{
		return (DesignElementHandle) extendsData.get( DesignerConstants.KEY_NEWOBJECT );
	}
}<commit_msg>- Summary:Fix bug crostab cell don't insert crosstab.Ready for bug 183907.<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.core.commands;

import java.util.Map;

import org.eclipse.birt.report.designer.core.DesignerConstants;
import org.eclipse.birt.report.designer.util.DEUtil;
import org.eclipse.birt.report.model.api.DataSourceHandle;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.SlotHandle;
import org.eclipse.birt.report.model.api.activity.SemanticException;
import org.eclipse.gef.commands.Command;

/**
 * This command adds an object to the model. The object is not created by this
 * command, but simply attached to the parent object.
 * 
 * 
 */

public class CreateCommand extends Command
{

	private Object parent;

	private Object after;

	private Map extendsData;

	/**
	 * Constructor
	 * 
	 * @param extendsData
	 */
	public CreateCommand( Map extendsData )
	{
		this.extendsData = extendsData;
	}

	/**
	 * Executes the Command. This method should not be called if the Command is
	 * not executable.
	 */
	public void execute( )
	{
		//DesignElementHandle newObject = (DesignElementHandle) extendsData.get( DesignerConstants.KEY_NEWOBJECT );
		DesignElementHandle newObject = getNewObject();
		if ( DesignerConstants.TRACING_COMMANDS )
		{
			System.out.println( "CreateCommand >> Starts ... " ); //$NON-NLS-1$
		}
		try
		{
			// For all virtual model node keep the SlotHandle
			if ( parent instanceof SlotHandle )
			{
				if ( after != null )
				{
					int pos = DEUtil.findInsertPosition( ( (SlotHandle) parent ).getElementHandle( ),
							(DesignElementHandle) after,
							( (SlotHandle) parent ).getSlotID( ) );
					( (SlotHandle) parent ).add( newObject, pos );

				}
				else
				{
					( (SlotHandle) parent ).add( newObject );
				}

			}
			else if( newObject instanceof DataSourceHandle)//simply add to datasource slot.
			{
				( (DesignElementHandle) parent ).addElement( newObject,
						ReportDesignHandle.DATA_SOURCE_SLOT );
			}
			else
			{
				// calculate the position of added element
				if ( after != null )
				{
					int pos = DEUtil.findInsertPosition( (DesignElementHandle) parent,
							(DesignElementHandle) after );
					int slotID = DEUtil.findSlotID( parent, after );

					( (DesignElementHandle) parent ).addElement( newObject,
							slotID,
							pos );
				}
				else if (DEUtil.getDefaultSlotID( parent ) != -1)
				{
					( (DesignElementHandle) parent ).addElement( newObject,
							DEUtil.getDefaultSlotID( parent ) );
				}
				else
				{
					( (DesignElementHandle) parent ).add(DEUtil.getDefaultContentName( parent ) , newObject);
				}
			}
			if ( DesignerConstants.TRACING_COMMANDS )
			{
				System.out.println( "CreateCommand >> Finished. " //$NON-NLS-1$
						+ DEUtil.getDisplayLabel( newObject )
						+ " created" ); //$NON-NLS-1$
			}
		}
		catch ( SemanticException e )
		{
			if ( DesignerConstants.TRACING_COMMANDS )
			{
				System.out.println( "CreateCommand >> Failed" ); //$NON-NLS-1$
			}
			e.printStackTrace( );
		}
	}

	/**
	 * Gets the parent edit part the new report element be added on.
	 * 
	 * @return Returns the parent.
	 */
	public Object getParent( )
	{
		return parent;
	}

	/**
	 * Sets the parent edit part the new report element be added on.
	 * 
	 * @param parent
	 *            The parent to set.
	 */
	public void setParent( Object parent )
	{
		this.parent = parent;
	}

	/**
	 * Gets the edit part the new report element be added after.
	 * 
	 * @param model
	 *            The model after the new element
	 */
	public void setAfter( Object model )
	{
		this.after = model;

	}
	
	/**
	 *  Get the new object
	 * @return
	 *   Return the object
	 */
	public DesignElementHandle getNewObject()
	{
		return (DesignElementHandle) extendsData.get( DesignerConstants.KEY_NEWOBJECT );
	}
}
{'fraction_non_alphanumeric': 0.1400092187139894, 'fraction_numerical': 0.0035722516708919104, 'mean_word_length': 3.1407442748091605, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4633283', 'n_tokens_mistral': 3018, 'n_tokens_neox': 2522, 'n_words': 688}