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

package org.eclipse.birt.report.designer.ui.lib.explorer;

import java.io.File;

import org.eclipse.birt.report.designer.internal.ui.util.Policy;
import org.eclipse.birt.report.designer.ui.ContextMenuProvider;
import org.eclipse.birt.report.designer.ui.lib.explorer.action.AddElementtoReport;
import org.eclipse.birt.report.designer.ui.lib.explorer.action.AddLibraryAction;
import org.eclipse.birt.report.designer.ui.lib.explorer.action.AddSelectedLibToCurrentReportDesignAction;
import org.eclipse.birt.report.designer.ui.lib.explorer.action.RefreshLibExplorerAction;
import org.eclipse.birt.report.model.api.DataSetHandle;
import org.eclipse.birt.report.model.api.DataSourceHandle;
import org.eclipse.birt.report.model.api.EmbeddedImageHandle;
import org.eclipse.birt.report.model.api.MasterPageHandle;
import org.eclipse.birt.report.model.api.ParameterHandle;
import org.eclipse.birt.report.model.api.ReportItemHandle;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.ui.IWorkbenchActionConstants;

/**
 * This class provides the context menu for the single selection and multiple
 * selection
 * 
 * 
 */
public class LibraryExplorerContextMenuProvider extends ContextMenuProvider
{

	private RefreshLibExplorerAction refreshExplorerAction;
	private AddLibraryAction addLibraryAction;
	private AddSelectedLibToCurrentReportDesignAction useLibraryAction;


	/**
	 * constructor
	 * 
	 * @param viewer
	 *            the viewer
	 * @param registry
	 *            the registry
	 */
	public LibraryExplorerContextMenuProvider( TreeViewer viewer )
	{
		super( viewer );
		refreshExplorerAction = new RefreshLibExplorerAction( viewer );
		addLibraryAction = new AddLibraryAction( viewer );
		useLibraryAction = new AddSelectedLibToCurrentReportDesignAction( viewer );
	}

	/**
	 * Builds the context menu. Single selection menu and multiple selection
	 * menu are created while selecting just single element or multiple elements
	 * 
	 * 
	 * @param menu
	 *            the menu
	 */
	public void buildContextMenu( IMenuManager menu )
	{
		if ( Policy.TRACING_MENU_SHOW )
		{
			System.out.println( "Menu(for Views) >> Shows for library" ); //$NON-NLS-1$
		}

		menu.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) );

		IStructuredSelection selection = (IStructuredSelection) getViewer( ).getSelection( );
		if ( selection != null && selection.getFirstElement( ) != null )
		{
			Object selected = selection.getFirstElement( );

			refreshExplorerAction.setSelectedElement( selected );
			menu.add( refreshExplorerAction );
			menu.add( new Separator( ) );

			if ( selected instanceof File )
			{
				if ( ( (File) selected ).isDirectory( ) )
				{
					addLibraryAction.setFolder( (File) selected );
					menu.add( addLibraryAction );
				}
				else
				{
					addLibraryAction.setFolder( ( (File) selected ).getParentFile( ) );
					menu.add( addLibraryAction );
					if ( useLibraryAction.isEnabled( ) )
					{
						menu.add( useLibraryAction );
					}
				}
			}
			else if ( selected instanceof ReportItemHandle 
				|| selected instanceof DataSourceHandle
				|| selected instanceof DataSetHandle
				|| selected instanceof ParameterHandle
				|| selected instanceof MasterPageHandle
				|| selected instanceof EmbeddedImageHandle
				)
			{
				if(selection.size( ) == 1)
				{
					AddElementtoReport addElementAction = new AddElementtoReport( (StructuredViewer) getViewer() );
					addElementAction.setSelectedElement( selected );
					menu.add( addElementAction );					
				}

			}
		}
		else
		{
			refreshExplorerAction.setSelectedElement( null );
			menu.add( refreshExplorerAction );
			addLibraryAction.setFolder( null );
			menu.add( addLibraryAction );
		}
	}
}
<commit_msg>- Summary: Can't add cascading parameter group/parameter group to report from library explorer<commit_after>/*************************************************************************************
 * Copyright (c) 2004 Actuate Corporation and others.
 * 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 implementation.
 ************************************************************************************/

package org.eclipse.birt.report.designer.ui.lib.explorer;

import java.io.File;

import org.eclipse.birt.report.designer.internal.ui.util.Policy;
import org.eclipse.birt.report.designer.ui.ContextMenuProvider;
import org.eclipse.birt.report.designer.ui.lib.explorer.action.AddElementtoReport;
import org.eclipse.birt.report.designer.ui.lib.explorer.action.AddLibraryAction;
import org.eclipse.birt.report.designer.ui.lib.explorer.action.AddSelectedLibToCurrentReportDesignAction;
import org.eclipse.birt.report.designer.ui.lib.explorer.action.RefreshLibExplorerAction;
import org.eclipse.birt.report.model.api.CascadingParameterGroupHandle;
import org.eclipse.birt.report.model.api.DataSetHandle;
import org.eclipse.birt.report.model.api.DataSourceHandle;
import org.eclipse.birt.report.model.api.EmbeddedImageHandle;
import org.eclipse.birt.report.model.api.MasterPageHandle;
import org.eclipse.birt.report.model.api.ParameterHandle;
import org.eclipse.birt.report.model.api.ReportElementHandle;
import org.eclipse.birt.report.model.api.ReportItemHandle;
import org.eclipse.birt.report.model.api.ScalarParameterHandle;
import org.eclipse.birt.report.model.api.StyleHandle;
import org.eclipse.birt.report.model.api.ThemeHandle;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.ui.IWorkbenchActionConstants;

/**
 * This class provides the context menu for the single selection and multiple
 * selection
 * 
 * 
 */
public class LibraryExplorerContextMenuProvider extends ContextMenuProvider
{

	private RefreshLibExplorerAction refreshExplorerAction;
	private AddLibraryAction addLibraryAction;
	private AddSelectedLibToCurrentReportDesignAction useLibraryAction;


	/**
	 * constructor
	 * 
	 * @param viewer
	 *            the viewer
	 * @param registry
	 *            the registry
	 */
	public LibraryExplorerContextMenuProvider( TreeViewer viewer )
	{
		super( viewer );
		refreshExplorerAction = new RefreshLibExplorerAction( viewer );
		addLibraryAction = new AddLibraryAction( viewer );
		useLibraryAction = new AddSelectedLibToCurrentReportDesignAction( viewer );
	}

	/**
	 * Builds the context menu. Single selection menu and multiple selection
	 * menu are created while selecting just single element or multiple elements
	 * 
	 * 
	 * @param menu
	 *            the menu
	 */
	public void buildContextMenu( IMenuManager menu )
	{
		if ( Policy.TRACING_MENU_SHOW )
		{
			System.out.println( "Menu(for Views) >> Shows for library" ); //$NON-NLS-1$
		}

		menu.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) );

		IStructuredSelection selection = (IStructuredSelection) getViewer( ).getSelection( );
		if ( selection != null && selection.getFirstElement( ) != null )
		{
			Object selected = selection.getFirstElement( );

			refreshExplorerAction.setSelectedElement( selected );
			menu.add( refreshExplorerAction );
			menu.add( new Separator( ) );

			if ( selected instanceof File )
			{
				if ( ( (File) selected ).isDirectory( ) )
				{
					addLibraryAction.setFolder( (File) selected );
					menu.add( addLibraryAction );
				}
				else
				{
					addLibraryAction.setFolder( ( (File) selected ).getParentFile( ) );
					menu.add( addLibraryAction );
					if ( useLibraryAction.isEnabled( ) )
					{
						menu.add( useLibraryAction );
					}
				}
			}
			else if (canAddtoReport(selected))
			{
				if(selection.size( ) == 1)
				{
					AddElementtoReport addElementAction = new AddElementtoReport( (StructuredViewer) getViewer() );
					addElementAction.setSelectedElement( selected );
					menu.add( addElementAction );					
				}

			}
		}
		else
		{
			refreshExplorerAction.setSelectedElement( null );
			menu.add( refreshExplorerAction );
			addLibraryAction.setFolder( null );
			menu.add( addLibraryAction );
		}
	}
	

	protected boolean canAddtoReport( Object transfer )
	{
		if ( transfer instanceof ReportElementHandle || transfer instanceof EmbeddedImageHandle)
		{
			if ( transfer instanceof ScalarParameterHandle
					&& ( (ScalarParameterHandle) transfer ).getContainer( ) instanceof CascadingParameterGroupHandle )
			{
				return false;
			}
			else if ( transfer instanceof StyleHandle
					&& ( (StyleHandle) transfer ).getContainer( ) instanceof ThemeHandle )
			{
				return false;
			}
			else if (transfer instanceof ThemeHandle)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		return false;
	}
	
}

{'fraction_non_alphanumeric': 0.12748020972550633, 'fraction_numerical': 0.002056132414927521, 'mean_word_length': 4.179978700745474, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1925656', 'n_tokens_mistral': 3157, 'n_tokens_neox': 2711, 'n_words': 582}