/*
 *************************************************************************
 * Copyright (c) 2004-2005 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.data.oda.sampledb.ui;

import java.util.Properties;

import org.eclipse.birt.report.data.oda.jdbc.OdaJdbcDriver;
import org.eclipse.birt.report.data.oda.sampledb.SampleDBConstants;
import org.eclipse.birt.report.data.oda.sampledb.ui.i18n.Messages;
import org.eclipse.datatools.connectivity.oda.OdaException;
import org.eclipse.datatools.connectivity.oda.design.DataSetDesign;
import org.eclipse.datatools.connectivity.oda.design.DataSourceDesign;
import org.eclipse.datatools.connectivity.oda.design.ui.designsession.DesignSessionUtil;
import org.eclipse.datatools.connectivity.oda.design.ui.wizards.DataSetWizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;

/**
 * Data Set Editor page for Sample DB Data sets created using builds prior to 2.0M3
 * It updates the data source to a regular JDBC data source 
 */
public class SampleDataSetEditor extends DataSetWizardPage
{

	private DataSetDesign datasetDesign;
	private DataSourceDesign dataSourceDesign;
	private Properties props;
	private static final String SAMPLE_DB_SCHEMA="ClassicModels";
	
	public SampleDataSetEditor( String pageName )
	{
		super( pageName );
		// TODO Auto-generated constructor stub
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.datatools.connectivity.oda.design.ui.wizards.DataSetWizardPage#createPageCustomControl(org.eclipse.swt.widgets.Composite)
	 */
	public void createPageCustomControl( Composite parent )
	{
		initializeControl( );
		setControl( createPageControl( parent ) );
	}

	
   private void initializeControl( )
	{
	   datasetDesign = this.getInitializationDesign( );
	   dataSourceDesign = datasetDesign.getDataSourceDesign( );
	}

	/*
	 * @see org.eclipse.birt.report.designer.ui.dialogs.properties.IPropertyPage#createPageControl(org.eclipse.swt.widgets.Composite)
	 */
	public Control createPageControl( Composite parent )
	{
		// create the composite to hold the widgets
		Composite content = new Composite( parent, SWT.NONE );

		GridLayout layout = new GridLayout( );
		content.setLayout( layout );
		content.setLayoutData( new GridData( GridData.FILL_BOTH ) );

		Label txt = new Label( content, SWT.LEFT );
		txt.setText( Messages.formatMessage( "datasource.upgrade.msg.firstLine", new Object[]{ //$NON-NLS-1$
					dataSourceDesign.getName( )
				} ) );

		Label nextLineLabel = new Label( content, SWT.LEFT );
		nextLineLabel.setText( Messages.formatMessage( "datasource.upgrade.msg.secondLine", new Object[]{ //$NON-NLS-1$
					dataSourceDesign.getName( )
				} ) );

		Label thirdLineLabel = new Label( content, SWT.LEFT );
		thirdLineLabel.setText( Messages.getMessage( "datasource.upgrade.msg.thirdLine" ) ); //$NON-NLS-1$
		return content;
	}

    /* (non-Javadoc)
	 * @see org.eclipse.datatools.connectivity.oda.design.internal.ui.DataSetWizardPageCore#collectDataSetDesign(org.eclipse.datatools.connectivity.oda.design.DataSetDesign)
	 */
	protected DataSetDesign collectDataSetDesign( DataSetDesign design )
	{
		// default implementation does nothing;
		// sub-class to override and update based on the given data set design
		// Update the data source to a regular JDBC data source
		// Note that since the data source extensionID is an intristic property
		// we cannot simply
		// update it; we will instead drop the original data source and
		// re-create one with
		// the same name
		if ( props == null )
			props = new Properties( );

		// set custom driver specific properties
		props.setProperty( org.eclipse.birt.report.data.oda.jdbc.Connection.Constants.ODADriverClass,
				SampleDBConstants.DRIVER_CLASS );
		props.setProperty( org.eclipse.birt.report.data.oda.jdbc.Connection.Constants.ODAURL, SampleDBConstants.DRIVER_URL );
		props.setProperty( org.eclipse.birt.report.data.oda.jdbc.Connection.Constants.ODAUser, SAMPLE_DB_SCHEMA );
		props.setProperty( org.eclipse.birt.report.data.oda.jdbc.Connection.Constants.ODAPassword, "" );

		design.getDataSourceDesign( )
				.setOdaExtensionId( OdaJdbcDriver.Constants.DATA_SOURCE_ID );
		
		try
		{
			design.getDataSourceDesign( )
					.setPublicProperties( DesignSessionUtil.createDataSourcePublicProperties( OdaJdbcDriver.Constants.DATA_SOURCE_ID,
							props ) );
		}
		catch ( OdaException e )
		{
			// TODO Auto-generated catch block
			e.printStackTrace( );
		}
		return design;
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.eclipse.datatools.connectivity.oda.design.ui.wizards.DataSetWizardPage#canLeave()
	 */
	protected boolean canLeave( )
	{
		return true;
	}
}

@@ -1402,21 +1402,20 @@
 widgets.
-Label
+Text
 ;%0A%0A/**%0A 
@@ -2817,21 +2817,20 @@
 ) );%0A%0A%09%09
-Label
+Text
  txt = n
@@ -2828,29 +2828,28 @@
 t txt = new 
-Label
+Text
 ( content, S
@@ -2851,25 +2851,87 @@
 nt, SWT.LEFT
- 
+%7CSWT.MULTI%7CSWT.H_SCROLL%7CSWT.V_SCROLL );%0A%09%09txt.setEditable(false
 );%0A%09%09txt.set
@@ -3072,88 +3072,20 @@
  );%0A
-%0A
 %09%09
-Label nextLineLabel = new Label( content, SWT.LEFT );%0A%09%09nextLineLabel.setText
+txt.append
 ( Me
@@ -3167,33 +3167,32 @@
 $NON-NLS-1$%0A%09%09%09%09
-%09
 dataSourceDesign
@@ -3210,98 +3210,27 @@
 %0A%09%09%09
-%09
 %7D ) );%0A
-%0A
 %09%09
-Label thirdLineLabel = new Label( content, SWT.LEFT );%0A%09%09thirdLineLabel.setText
+txt.append
 ( Me
@@ -3288,25 +3288,74 @@
 e%22 )
+ 
  );
- //$NON-NLS-1$
+%0A%09%09txt.setLayoutData( new GridData( GridData.FILL_BOTH ) );%0A%09%09
 %0A%09%09r

Fix issue Too long text for Japanese translation causes the text cut off : Data Set Editor (for upgrade Data Set definition message)[48449]