<commit_before>/*******************************************************************************
 * Copyright (c) 2007 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.chart.reportitem.ui.dialogs;

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

import org.eclipse.birt.chart.reportitem.ChartReportItemUtil;
import org.eclipse.birt.chart.reportitem.ui.i18n.Messages;
import org.eclipse.birt.chart.ui.swt.wizard.ChartWizard;
import org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBase;
import org.eclipse.birt.report.designer.internal.ui.dialogs.DataColumnBindingDialog;
import org.eclipse.birt.report.designer.internal.ui.util.DataUtil;
import org.eclipse.birt.report.designer.ui.dialogs.ColumnBindingDialog;
import org.eclipse.birt.report.designer.util.DEUtil;
import org.eclipse.birt.report.model.api.DataSetHandle;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.ReportItemHandle;
import org.eclipse.birt.report.model.api.ResultSetColumnHandle;
import org.eclipse.birt.report.model.api.StructureFactory;
import org.eclipse.birt.report.model.api.activity.SemanticException;
import org.eclipse.birt.report.model.api.elements.structures.ComputedColumn;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;

/**
 * Data binding dialog for Charts
 */

public class ChartColumnBindingDialog extends ColumnBindingDialog
{

	private Button btnAddAgg;
	private Button btnRefresh;
	
	/** The field indicates if all bindings are read-only in chart. */
	private boolean fIsReadOnly;

	public ChartColumnBindingDialog( Shell parent )
	{
		super( parent, false, false );
	}
	
	/**
	 * Disable/enable button to make all items in the dialog read-only.
	 * @since 2.3
	 */
	private void updateButtonStatusForReadOnly( )
	{
		if ( fIsReadOnly )
		{
			btnAdd.setEnabled( false );
			btnEdit.setEnabled( false );
			btnDel.setEnabled( false );
			btnAddAgg.setEnabled( false );
		}
	}

	protected int addButtons( Composite cmp, final Table table )
	{
		btnAddAgg = new Button( cmp, SWT.PUSH );
		btnAddAgg.setText( Messages.getString( "ChartColumnBindingDialog.Button.AddAggregation" ) ); //$NON-NLS-1$
		GridData data = new GridData( GridData.VERTICAL_ALIGN_BEGINNING );
		data.widthHint = Math.max( 60, btnAddAgg.computeSize( SWT.DEFAULT,
				SWT.DEFAULT,
				true ).x );
		btnAddAgg.setLayoutData( data );
		btnAddAgg.addListener( SWT.Selection, new Listener( ) {

			public void handleEvent( Event event )
			{
				DataColumnBindingDialog dialog = new DataColumnBindingDialog( true );
				dialog.setInput( inputElement );
				dialog.setExpressionProvider( expressionProvider );
				dialog.setAggreate( true );
				if ( dialog.open( ) == Dialog.OK )
				{
					if ( bindingTable != null )
					{
						refreshBindingTable( );
						bindingTable.getTable( )
								.setSelection( bindingTable.getTable( )
										.getItemCount( ) - 1 );
					}
				}

				refreshBindingTable( );
				if ( table.getItemCount( ) > 0 )
					setSelectionInTable( table.getItemCount( ) - 1 );
				updateButtons( );
			}

		} );

		btnRefresh = new Button( cmp, SWT.PUSH );
		btnRefresh.setText( Messages.getString( "ChartColumnBindingDialog.Button.Refresh" ) ); //$NON-NLS-1$
		btnRefresh.setLayoutData( data );
		btnRefresh.addListener( SWT.Selection, new Listener( ) {

			public void handleEvent( Event event )
			{
				try
				{
					List columnList = new ArrayList( );
					DataSetHandle dataSetHandle = inputElement.getDataSet( );
					if ( dataSetHandle == null )
					{
						dataSetHandle = DEUtil.getBindingHolder( inputElement )
								.getDataSet( );
					}
					if ( dataSetHandle != null )
					{
						List resultSetColumnList = DataUtil.getColumnList( dataSetHandle );
						for ( Iterator iterator = resultSetColumnList.iterator( ); iterator.hasNext( ); )
						{
							ResultSetColumnHandle resultSetColumn = (ResultSetColumnHandle) iterator.next( );
							ComputedColumn column = StructureFactory.newComputedColumn( inputElement,
									resultSetColumn.getColumnName( ) );
							column.setDataType( resultSetColumn.getDataType( ) );
							column.setExpression( DEUtil.getExpression( resultSetColumn ) );
							columnList.add( column );
						}
					}
					if ( columnList.size( ) > 0 )
					{
						for ( Iterator iter = columnList.iterator( ); iter.hasNext( ); )
						{
							DEUtil.addColumn( inputElement,
									(ComputedColumn) iter.next( ),
									false );
						}
					}<commit_msg>Check in #217389 and 217415 on behalf of <NAME><commit_after>/*******************************************************************************
 * Copyright (c) 2007 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.chart.reportitem.ui.dialogs;

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

import org.eclipse.birt.chart.reportitem.ChartReportItemUtil;
import org.eclipse.birt.chart.reportitem.ui.i18n.Messages;
import org.eclipse.birt.chart.ui.swt.wizard.ChartWizard;
import org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBase;
import org.eclipse.birt.report.designer.internal.ui.dialogs.DataColumnBindingDialog;
import org.eclipse.birt.report.designer.internal.ui.util.DataUtil;
import org.eclipse.birt.report.designer.ui.dialogs.ColumnBindingDialog;
import org.eclipse.birt.report.designer.util.DEUtil;
import org.eclipse.birt.report.model.api.DataSetHandle;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.ReportItemHandle;
import org.eclipse.birt.report.model.api.ResultSetColumnHandle;
import org.eclipse.birt.report.model.api.StructureFactory;
import org.eclipse.birt.report.model.api.activity.SemanticException;
import org.eclipse.birt.report.model.api.elements.structures.ComputedColumn;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;

/**
 * Data binding dialog for Charts
 */

public class ChartColumnBindingDialog extends ColumnBindingDialog
{

	private Button btnAddAgg;
	private Button btnRefresh;
	
	/** The field indicates if all bindings are read-only in chart. */
	private boolean fIsReadOnly;

	public ChartColumnBindingDialog( Shell parent )
	{
		super( parent, false, false );
	}
	
	/**
	 * Disable/enable button to make all items in the dialog read-only.
	 * @since 2.3
	 */
	private void updateButtonStatusForReadOnly( )
	{
		if ( fIsReadOnly )
		{
			btnAdd.setEnabled( false );
			btnEdit.setEnabled( false );
			btnDel.setEnabled( false );
			btnAddAgg.setEnabled( false );
		}
	}

	protected int addButtons( Composite cmp, final Table table )
	{
		btnAddAgg = new Button( cmp, SWT.PUSH );
		btnAddAgg.setText( Messages.getString( "ChartColumnBindingDialog.Button.AddAggregation" ) ); //$NON-NLS-1$
		GridData data = new GridData( GridData.VERTICAL_ALIGN_BEGINNING );
		data.widthHint = Math.max( 60, btnAddAgg.computeSize( SWT.DEFAULT,
				SWT.DEFAULT,
				true ).x );
		btnAddAgg.setLayoutData( data );
		btnAddAgg.addListener( SWT.Selection, new Listener( ) {

			public void handleEvent( Event event )
			{
				DataColumnBindingDialog dialog = new DataColumnBindingDialog( true );
				dialog.setInput( inputElement );
				dialog.setExpressionProvider( expressionProvider );
				dialog.setAggreate( true );
				if ( dialog.open( ) == Dialog.OK )
				{
					if ( bindingTable != null )
					{
						refreshBindingTable( );
						bindingTable.getTable( )
								.setSelection( bindingTable.getTable( )
										.getItemCount( ) - 1 );
					}
				}

				refreshBindingTable( );
				if ( table.getItemCount( ) > 0 )
					setSelectionInTable( table.getItemCount( ) - 1 );
				updateButtons( );
			}

		} );

		btnRefresh = new Button( cmp, SWT.PUSH );
		btnRefresh.setText( Messages.getString( "ChartColumnBindingDialog.Button.Refresh" ) ); //$NON-NLS-1$
		btnRefresh.setLayoutData( data );
		btnRefresh.addListener( SWT.Selection, new Listener( ) {

			public void handleEvent( Event event )
			{
				try
				{
					inputElement.getPropertyHandle( ReportItemHandle.BOUND_DATA_COLUMNS_PROP ).clearValue( );
					List columnList = new ArrayList( );
					DataSetHandle dataSetHandle = inputElement.getDataSet( );
					if ( dataSetHandle == null )
					{
						dataSetHandle = DEUtil.getBindingHolder( inputElement )
								.getDataSet( );
					}
					if ( dataSetHandle != null )
					{
						List resultSetColumnList = DataUtil.getColumnList( dataSetHandle );
						for ( Iterator iterator = resultSetColumnList.iterator( ); iterator.hasNext( ); )
						{
							ResultSetColumnHandle resultSetColumn = (ResultSetColumnHandle) iterator.next( );
							ComputedColumn column = StructureFactory.newComputedColumn( inputElement,
									resultSetColumn.getColumnName( ) );
							column.setDataType( resultSetColumn.getDataType( ) );
							column.setExpression( DEUtil.getExpression( resultSetColumn ) );
							columnList.add( column );
						}
					}
					if ( columnList.size( ) > 0 )
					{
						for ( Iterator iter = columnList.iterator( ); iter.hasNext( ); )
						{
							DEUtil.addColumn( inputElement,
									(ComputedColumn) iter.next( ),
									false );
						}
					}
{'fraction_non_alphanumeric': 0.13636797404332474, 'fraction_numerical': 0.004962305563507968, 'mean_word_length': 3.7832040164308536, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, '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': '6822544', 'n_tokens_mistral': 3745, 'n_tokens_neox': 3118, 'n_words': 629}