<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.internal.ui.views.outline;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.eclipse.birt.report.designer.core.model.SessionHandleAdapter;
import org.eclipse.birt.report.designer.core.util.mediator.request.IRequestConvert;
import org.eclipse.birt.report.designer.core.util.mediator.request.ReportRequest;
import org.eclipse.birt.report.designer.internal.ui.editors.parts.event.IModelEventProcessor;
import org.eclipse.birt.report.designer.internal.ui.editors.schematic.editparts.ReportEventRunnable;
import org.eclipse.birt.report.designer.internal.ui.editors.schematic.editparts.AbstractModelEventProcessor.IModelEventFactory;
import org.eclipse.birt.report.designer.internal.ui.extension.ExtendedElementUIPoint;
import org.eclipse.birt.report.designer.internal.ui.extension.ExtensionPointManager;
import org.eclipse.birt.report.designer.internal.ui.extension.experimental.EditpartExtensionManager;
import org.eclipse.birt.report.designer.internal.ui.extension.experimental.PaletteEntryExtension;
import org.eclipse.birt.report.designer.internal.ui.views.DesignerOutlineEventProcessor;
import org.eclipse.birt.report.designer.internal.ui.views.NonGEFSynchronizerWithTreeView;
import org.eclipse.birt.report.designer.internal.ui.views.RenameListener;
import org.eclipse.birt.report.designer.internal.ui.views.ViewContextMenuProvider;
import org.eclipse.birt.report.designer.internal.ui.views.ViewsTreeProvider;
import org.eclipse.birt.report.designer.internal.ui.views.actions.GlobalActionFactory;
import org.eclipse.birt.report.designer.internal.ui.views.actions.ImportLibraryAction;
import org.eclipse.birt.report.designer.internal.ui.views.outline.dnd.DesignerDragListener;
import org.eclipse.birt.report.designer.internal.ui.views.outline.dnd.DesignerDropListener;
import org.eclipse.birt.report.designer.internal.ui.views.outline.dnd.IDropConstraint;
import org.eclipse.birt.report.designer.ui.views.ProviderFactory;
import org.eclipse.birt.report.model.api.CascadingParameterGroupHandle;
import org.eclipse.birt.report.model.api.CellHandle;
import org.eclipse.birt.report.model.api.CssSharedStyleHandle;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.ModuleHandle;
import org.eclipse.birt.report.model.api.ParameterGroupHandle;
import org.eclipse.birt.report.model.api.ScalarParameterHandle;
import org.eclipse.birt.report.model.api.SlotHandle;
import org.eclipse.birt.report.model.api.activity.NotificationEvent;
import org.eclipse.birt.report.model.api.command.ContentEvent;
import org.eclipse.birt.report.model.api.core.IDesignElement;
import org.eclipse.birt.report.model.api.css.CssStyleSheetHandle;
import org.eclipse.birt.report.model.api.validators.IValidationListener;
import org.eclipse.birt.report.model.api.validators.ValidationEvent;
import org.eclipse.gef.dnd.TemplateTransfer;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.actions.RetargetAction;
import org.eclipse.ui.views.contentoutline.ContentOutlinePage;

/**
 * Outline page to show the tree structure of IR Model
 */
public class DesignerOutlinePage extends ContentOutlinePage implements
// Listener,
		IValidationListener,
		IModelEventFactory
{

	/**
	 * the root report design of outline tree
	 */
	private ModuleHandle reportHandle;

	private NonGEFSynchronizerWithTreeView synchronizer;

	// private ListenerElementVisitor visitor;

	/**
	 * Instantiates DesignerOutlinePage, and sets the IR Model's root report
	 * design object
	 */
	public DesignerOutlinePage( ModuleHandle reportHandle )
	{
		this.reportHandle = reportHandle;
	}

	/**
	 * Creates the SWT control for this page under the given parent control.
	 * <p>
	 * Clients should not call this method (the workbench calls this method when
	 * it needs to, which may be never).
	 * </p>
	 * 
	 * @param parent
	 *            the parent control
	 */
	public void createControl( Composite parent )
	{
		super.createControl( parent );
		// added by gao 2004.08.05
		createContextMenu( );
		ViewsTreeProvider provider = new ViewsTreeProvider( );

		getTreeViewer( ).setContentProvider( provider );

		getTreeViewer( ).setLabelProvider( provider );

		getSelectionSynchronizer( ).setTreeViewer( getTreeViewer( ) );

		// add inline renaming support
		new RenameListener( getTreeViewer( ) ).apply( );

		getTreeViewer( ).setSorter( new ItemSorter( ) );

		addDragAndDropListener( );

		init( reportHandle );

		getTreeViewer( ).expandToLevel( 2 );

		final Tree tree = getTreeViewer( ).getTree( );
		//184790
		tree.addListener(SWT.PaintItem, new Listener() {

			public void handleEvent(Event event)
			{
				if(event.item.getData( ) instanceof CssStyleSheetHandle || event.item.getData( ) instanceof CssSharedStyleHandle){
					TreeItem item = (TreeItem)event.item;
					Color red = Display.getCurrent( ).getSystemColor(SWT.COLOR_DARK_GRAY);
					item.setForeground( red );
				}
			}} );
		// Adds mouse listener to disable Cell multi-selection
		tree.addMouseListener( new MouseAdapter( ) {

			public void mouseDown( MouseEvent e )
			{
				if ( ( e.stateMask & SWT.CTRL ) != 0
						|| ( e.stateMask & SWT.SHIFT ) != 0 )
				{
					setSingleSelection( e );
				}<commit_msg>- Summary: Imported CSS style become grey when firstly use CSS then import CSS[00]<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.internal.ui.views.outline;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.eclipse.birt.report.designer.core.model.SessionHandleAdapter;
import org.eclipse.birt.report.designer.core.util.mediator.request.IRequestConvert;
import org.eclipse.birt.report.designer.core.util.mediator.request.ReportRequest;
import org.eclipse.birt.report.designer.internal.ui.editors.parts.event.IModelEventProcessor;
import org.eclipse.birt.report.designer.internal.ui.editors.schematic.editparts.ReportEventRunnable;
import org.eclipse.birt.report.designer.internal.ui.editors.schematic.editparts.AbstractModelEventProcessor.IModelEventFactory;
import org.eclipse.birt.report.designer.internal.ui.extension.ExtendedElementUIPoint;
import org.eclipse.birt.report.designer.internal.ui.extension.ExtensionPointManager;
import org.eclipse.birt.report.designer.internal.ui.extension.experimental.EditpartExtensionManager;
import org.eclipse.birt.report.designer.internal.ui.extension.experimental.PaletteEntryExtension;
import org.eclipse.birt.report.designer.internal.ui.views.DesignerOutlineEventProcessor;
import org.eclipse.birt.report.designer.internal.ui.views.NonGEFSynchronizerWithTreeView;
import org.eclipse.birt.report.designer.internal.ui.views.RenameListener;
import org.eclipse.birt.report.designer.internal.ui.views.ViewContextMenuProvider;
import org.eclipse.birt.report.designer.internal.ui.views.ViewsTreeProvider;
import org.eclipse.birt.report.designer.internal.ui.views.actions.GlobalActionFactory;
import org.eclipse.birt.report.designer.internal.ui.views.actions.ImportLibraryAction;
import org.eclipse.birt.report.designer.internal.ui.views.outline.dnd.DesignerDragListener;
import org.eclipse.birt.report.designer.internal.ui.views.outline.dnd.DesignerDropListener;
import org.eclipse.birt.report.designer.internal.ui.views.outline.dnd.IDropConstraint;
import org.eclipse.birt.report.designer.ui.views.ProviderFactory;
import org.eclipse.birt.report.model.api.CascadingParameterGroupHandle;
import org.eclipse.birt.report.model.api.CellHandle;
import org.eclipse.birt.report.model.api.CssSharedStyleHandle;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.ModuleHandle;
import org.eclipse.birt.report.model.api.ParameterGroupHandle;
import org.eclipse.birt.report.model.api.ScalarParameterHandle;
import org.eclipse.birt.report.model.api.SlotHandle;
import org.eclipse.birt.report.model.api.activity.NotificationEvent;
import org.eclipse.birt.report.model.api.command.ContentEvent;
import org.eclipse.birt.report.model.api.core.IDesignElement;
import org.eclipse.birt.report.model.api.css.CssStyleSheetHandle;
import org.eclipse.birt.report.model.api.validators.IValidationListener;
import org.eclipse.birt.report.model.api.validators.ValidationEvent;
import org.eclipse.gef.dnd.TemplateTransfer;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.actions.RetargetAction;
import org.eclipse.ui.views.contentoutline.ContentOutlinePage;

/**
 * Outline page to show the tree structure of IR Model
 */
public class DesignerOutlinePage extends ContentOutlinePage implements
// Listener,
		IValidationListener,
		IModelEventFactory
{

	/**
	 * the root report design of outline tree
	 */
	private ModuleHandle reportHandle;

	private NonGEFSynchronizerWithTreeView synchronizer;

	// private ListenerElementVisitor visitor;

	/**
	 * Instantiates DesignerOutlinePage, and sets the IR Model's root report
	 * design object
	 */
	public DesignerOutlinePage( ModuleHandle reportHandle )
	{
		this.reportHandle = reportHandle;
	}

	/**
	 * Creates the SWT control for this page under the given parent control.
	 * <p>
	 * Clients should not call this method (the workbench calls this method when
	 * it needs to, which may be never).
	 * </p>
	 * 
	 * @param parent
	 *            the parent control
	 */
	public void createControl( Composite parent )
	{
		super.createControl( parent );
		// added by gao 2004.08.05
		createContextMenu( );
		ViewsTreeProvider provider = new ViewsTreeProvider( );

		getTreeViewer( ).setContentProvider( provider );

		getTreeViewer( ).setLabelProvider( provider );

		getSelectionSynchronizer( ).setTreeViewer( getTreeViewer( ) );

		// add inline renaming support
		new RenameListener( getTreeViewer( ) ).apply( );

		getTreeViewer( ).setSorter( new ItemSorter( ) );

		addDragAndDropListener( );

		init( reportHandle );

		getTreeViewer( ).expandToLevel( 2 );

		final Tree tree = getTreeViewer( ).getTree( );
		//184790
		tree.addListener(SWT.PaintItem, new Listener() {

			public void handleEvent(Event event)
			{
				// Fix bug 192094
				TreeItem item = (TreeItem)event.item;
				if(event.item.getData( ) instanceof CssStyleSheetHandle || event.item.getData( ) instanceof CssSharedStyleHandle){					
					Color gray = Display.getCurrent( ).getSystemColor(SWT.COLOR_DARK_GRAY);
					item.setForeground( gray );
				}else
				{					
					Color black = Display.getCurrent( ).getSystemColor(SWT.COLOR_BLACK);
					item.setForeground( black );
				}
			}} );
		// Adds mouse listener to disable Cell multi-selection
		tree.addMouseListener( new MouseAdapter( ) {

			public void mouseDown( MouseEvent e )
			{
				if ( ( e.stateMask & SWT.CTRL ) != 0
						|| ( e.stateMask & SWT.SHIFT ) != 0 )
				{
					setSingleSelection( e );
				}
{'fraction_non_alphanumeric': 0.12939015429831008, 'fraction_numerical': 0.00426157237325496, 'mean_word_length': 5.076339285714286, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4338748', 'n_tokens_mistral': 4363, 'n_tokens_neox': 4052, 'n_words': 735}