blob: d2649375cba50c926520772ffe54adfaa1bcccf0 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2007 Innoopract Informationssysteme GmbH.
* 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:
* Innoopract Informationssysteme GmbH - initial API and implementation
******************************************************************************/
package org.eclipse.swt.internal.widgets.tablecolumnkit;
import java.io.IOException;
import junit.framework.TestCase;
import org.eclipse.swt.RWTFixture;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.internal.lifecycle.PreserveWidgetsPhaseListener;
import org.eclipse.swt.internal.lifecycle.RWTLifeCycle;
import org.eclipse.swt.lifecycle.*;
import org.eclipse.swt.widgets.*;
import com.w4t.Fixture;
import com.w4t.engine.requests.RequestParams;
public class TableColumnLCA_Test extends TestCase {
protected void setUp() throws Exception {
RWTFixture.setUp();
}
protected void tearDown() throws Exception {
RWTFixture.tearDown();
}
public void testResizeEvent() throws IOException {
final StringBuffer log = new StringBuffer();
Display display = new Display();
Shell shell = new Shell( display );
Table table = new Table( shell, SWT.NONE );
final TableColumn column = new TableColumn( table, SWT.NONE );
column.setWidth( 20 );
column.addControlListener( new ControlListener() {
public void controlMoved( final ControlEvent e ) {
fail( "unexpected event: controlMoved" );
}
public void controlResized( final ControlEvent e ) {
assertSame( column, e.getSource() );
log.append( "controlResized" );
}
} );
String displayId = DisplayUtil.getId( display );
String columnId = WidgetUtil.getId( column );
RWTLifeCycle lifeCycle = new RWTLifeCycle();
lifeCycle.addPhaseListener( new PreserveWidgetsPhaseListener() );
//
RWTFixture.fakeNewRequest();
Fixture.fakeRequestParam( RequestParams.UIROOT, displayId );
lifeCycle.execute();
// Simulate request that changes column width
int newWidth = column.getWidth() + 2;
RWTFixture.fakeNewRequest();
Fixture.fakeRequestParam( RequestParams.UIROOT, displayId );
Fixture.fakeRequestParam( "org.eclipse.swt.events.controlResized",
columnId );
Fixture.fakeRequestParam( columnId + ".width", String.valueOf( newWidth ) );
lifeCycle.execute();
assertEquals( "controlResized", log.toString() );
assertEquals( newWidth, column.getWidth() );
IWidgetAdapter adapter = WidgetUtil.getAdapter( column );
assertTrue( adapter.isInitialized() );
String markup = Fixture.getAllMarkup();
assertTrue( markup.indexOf( "setWidth( " + newWidth + " )" ) != -1 );
}
}