| /******************************************************************************* |
| * Copyright (c) 2002-2006 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.buttonkit; |
| |
| import java.io.IOException; |
| import junit.framework.TestCase; |
| import org.eclipse.swt.RWTFixture; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.events.*; |
| import org.eclipse.swt.internal.lifecycle.RWTLifeCycle; |
| import org.eclipse.swt.internal.widgets.IShellAdapter; |
| import org.eclipse.swt.internal.widgets.Props; |
| import org.eclipse.swt.lifecycle.*; |
| import org.eclipse.swt.widgets.*; |
| import com.w4t.Fixture; |
| import com.w4t.engine.lifecycle.PhaseId; |
| import com.w4t.engine.requests.RequestParams; |
| |
| public class ButtonLCA_Test extends TestCase { |
| |
| public void testPreserveValues() { |
| Display display = new Display(); |
| Composite shell = new Shell( display , SWT.NONE ); |
| Button button = new Button( shell, SWT.PUSH ); |
| RWTFixture.markInitialized( display ); |
| RWTFixture.preserveWidgets(); |
| IWidgetAdapter adapter = WidgetUtil.getAdapter( button ); |
| Boolean hasListeners; |
| hasListeners = ( Boolean )adapter.getPreserved( Props.SELECTION_LISTENERS ); |
| assertEquals( Boolean.FALSE, hasListeners ); |
| RWTFixture.clearPreserved(); |
| SelectionListener selectionListener = new SelectionAdapter() {}; |
| button.addSelectionListener( selectionListener ); |
| RWTFixture.preserveWidgets(); |
| adapter = WidgetUtil.getAdapter( button ); |
| hasListeners = ( Boolean )adapter.getPreserved( Props.SELECTION_LISTENERS ); |
| assertEquals( Boolean.TRUE, hasListeners ); |
| display.dispose(); |
| } |
| |
| public void testDisabledButtonSelection() { |
| final StringBuffer log = new StringBuffer(); |
| RWTFixture.fakePhase( PhaseId.PROCESS_ACTION ); |
| Display display = new Display(); |
| Shell shell = new Shell( display, SWT.NONE ); |
| final Button button = new Button( shell, SWT.NONE ); |
| Label label = new Label( shell, SWT.NONE ); |
| ActivateEvent.addListener( button, new ActivateAdapter() { |
| public void activated( final ActivateEvent event ) { |
| log.append( "widgetActivated|" ); |
| button.setEnabled( false ); |
| } |
| } ); |
| button.addSelectionListener( new SelectionAdapter() { |
| public void widgetSelected( final SelectionEvent event ) { |
| log.append( "widgetSelected|" ); |
| } |
| } ); |
| Object adapter = shell.getAdapter( IShellAdapter.class ); |
| IShellAdapter shellAdapter = ( IShellAdapter )adapter; |
| shellAdapter.setActiveControl( label ); |
| |
| String displayId = DisplayUtil.getId( display ); |
| String buttonId = WidgetUtil.getId( button ); |
| Fixture.fakeRequestParam( RequestParams.UIROOT, displayId ); |
| Fixture.fakeRequestParam( JSConst.EVENT_WIDGET_SELECTED, buttonId ); |
| Fixture.fakeRequestParam( JSConst.EVENT_WIDGET_ACTIVATED, buttonId ); |
| |
| RWTFixture.readDataAndProcessAction( display ); |
| assertEquals( "widgetActivated|", log.toString() ); |
| } |
| |
| public void testSelectionEvent() throws IOException { |
| final StringBuffer log = new StringBuffer(); |
| Display display = new Display(); |
| Shell shell = new Shell( display ); |
| final Button button = new Button( shell, SWT.PUSH ); |
| button.addSelectionListener( new SelectionAdapter() { |
| public void widgetSelected( final SelectionEvent event ) { |
| assertEquals( 0, event.x ); |
| assertEquals( 0, event.y ); |
| assertEquals( 0, event.width ); |
| assertEquals( 0, event.height ); |
| assertSame( button, event.getSource() ); |
| assertEquals( 0, event.detail ); |
| log.append( "widgetSelected" ); |
| } |
| } ); |
| String displayId = DisplayUtil.getId( display ); |
| String buttonId = WidgetUtil.getId( button ); |
| |
| RWTFixture.fakeNewRequest(); |
| Fixture.fakeRequestParam( RequestParams.UIROOT, displayId ); |
| Fixture.fakeRequestParam( "org.eclipse.swt.events.widgetSelected", |
| buttonId ); |
| new RWTLifeCycle().execute(); |
| assertEquals( "widgetSelected", log.toString() ); |
| } |
| |
| protected void setUp() throws Exception { |
| RWTFixture.setUp(); |
| } |
| |
| protected void tearDown() throws Exception { |
| RWTFixture.tearDown(); |
| } |
| } |