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

import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.DesignVisitor;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.core.Listener;

/**
 * Applies visitor to the report element and the children element
 *  
 */

public class ListenerElementVisitor extends DesignVisitor
{

	/**
	 * The listener
	 */

	private Listener listener;

	private boolean install = true;

	/**
	 * the design
	 */

	private ReportDesignHandle designHandle = null;

	/**
	 * constructor. Sets the listener and design
	 * 
	 * @param lis
	 *            the listener value to be set
	 * @param designHandle
	 *            the handle of the report design
	 */

	public ListenerElementVisitor( Listener lis, ReportDesignHandle designHandle )
	{
		super( designHandle );
		this.listener = lis;
		this.designHandle = designHandle;
	}

	public void addListener( DesignElementHandle handle )
	{
		install = true;
		apply( handle );
	}

	public void removeListener( DesignElementHandle handle )
	{
		install = false;
		apply( handle );
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.birt.model.api.DesignVisitor#visitDesignElement(org.eclipse.birt.model.api.DesignElementHandle)
	 */
	public void visitDesignElement( DesignElementHandle obj )
	{
		if ( install )
		{
			obj.addListener( listener );
		}
		else
		{
			obj.removeListener( listener );
		}
		for ( int i = 0; i < obj.getDefn( ).getSlotCount( ); i++ )
		{
			visitContents( obj.getSlot( i ) );
		}
	}

	/**
	 * Sets the listener null.
	 */

	public void dispose( )
	{
		removeListener( designHandle );
		listener = null;
	}
}
@@ -715,69 +715,8 @@
 or;%0A
-import org.eclipse.birt.report.model.api.ReportDesignHandle;%0A
 impo
@@ -1000,84 +1000,8 @@
 e;%0A%0A
-%09/**%0A%09 * the design%0A%09 */%0A%0A%09private ReportDesignHandle designHandle = null;%0A%0A
 %09/**
@@ -1066,16 +1066,21 @@
 aram lis
+tener
 %0A%09 *    
@@ -1120,79 +1120,8 @@
 set%0A
-%09 * @param designHandle%0A%09 *            the handle of the report design%0A
 %09 */
@@ -1170,41 +1170,13 @@
  lis
-, ReportDesignHandle designHandle
+tener
  )%0A%09
@@ -1185,29 +1185,16 @@
 %09%09super(
- designHandle
  );%0A%09%09th
@@ -1214,44 +1214,13 @@
  lis
-;%0A%09%09this.designHandle = designHandle
+tener
 ;%0A%09%7D
@@ -1418,24 +1418,25 @@
 andle );%0A%09%7D%0A
+%09
 %0A%09/*%0A%09 * (no
@@ -1923,42 +1923,8 @@
 %0A%09%7B%0A
-%09%09removeListener( designHandle );%0A
 %09%09li

- SCR(s) Resolved: - Description: Change the constructor of ListenerElementVistor since the old constructor of the super class degenerated. Fix a minor problem which occurs after saving as - Regression ( Yes/No ):No - Code Owner: Yueqian Wang - Code Reviewers: Qiangsheng Wang - Tests: Manual test and JUnit test - Test Automated (Yes/No, if "No" then explain why):Yes - Case Entries Resolved: CVS/Home - Notes to Developers: - Notes to QA: - Notes to Documentation: - Notes to Configuration Management: - Notes to Support: - Notes to Product Marketing: