Introduce ScrollBars for ExpandBar in protocol
diff --git a/bundles/org.eclipse.rap.rwt/js/rwt/protocol/adapter/ExpandBarAdapter.js b/bundles/org.eclipse.rap.rwt/js/rwt/protocol/adapter/ExpandBarAdapter.js
index ebe0bf3..bfefc83 100644
--- a/bundles/org.eclipse.rap.rwt/js/rwt/protocol/adapter/ExpandBarAdapter.js
+++ b/bundles/org.eclipse.rap.rwt/js/rwt/protocol/adapter/ExpandBarAdapter.js
@@ -23,7 +23,6 @@
properties : rwt.protocol.AdapterUtil.extendControlProperties( [
"bottomSpacingBounds",
- "vScrollBarVisible",
"vScrollBarMax"
] ),
diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/internal/widgets/IExpandBarAdapter.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/internal/widgets/IExpandBarAdapter.java
index 33b1bfe..3b104f7 100644
--- a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/internal/widgets/IExpandBarAdapter.java
+++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/internal/widgets/IExpandBarAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 Innoopract Informationssysteme GmbH.
+ * Copyright (c) 2008, 2012 Innoopract Informationssysteme GmbH and others.
* 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
@@ -7,6 +7,7 @@
*
* Contributors:
* Innoopract Informationssysteme GmbH - initial API and implementation
+ * EclipseSource - ongoing development
******************************************************************************/
package org.eclipse.swt.internal.widgets;
@@ -17,7 +18,5 @@
Rectangle getBounds( ExpandItem item );
- boolean isVScrollbarVisible();
-
Rectangle getBottomSpacingBounds();
}
\ No newline at end of file
diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/ExpandBar.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/ExpandBar.java
index d5ff3cf..2089268 100644
--- a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/ExpandBar.java
+++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/ExpandBar.java
@@ -1,13 +1,13 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Innoopract Informationssysteme GmbH.
+ * Copyright (c) 2008, 2012 Innoopract Informationssysteme GmbH and others.
* 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
- * EclipseSource - ongoing development
+ * Innoopract Informationssysteme GmbH - initial API and implementation
+ * EclipseSource - ongoing development
******************************************************************************/
package org.eclipse.swt.widgets;
@@ -52,16 +52,13 @@
return ExpandBar.this.getItem( index ).getBounds();
}
- public boolean isVScrollbarVisible() {
- return ExpandBar.this.isVScrollbarVisible();
- }
-
public Rectangle getBottomSpacingBounds() {
return ExpandBar.this.getBottomSpacingBounds();
}
}
private final class ResizeListener extends ControlAdapter {
+ @Override
public void controlResized( ControlEvent event ) {
layoutItems( 0, true );
}
@@ -168,6 +165,7 @@
removeListener( SWT.Collapse, listener );
}
+ @Override
public Point computeSize( int wHint, int hHint, boolean changed ) {
checkWidget();
int height = 0, width = 0;
@@ -240,6 +238,7 @@
}
}
+ @Override
Control findBackgroundControl() {
Control control = super.findBackgroundControl();
if( !isAppThemed() ) {
@@ -385,13 +384,14 @@
ExpandItem lastItem = getItem( itemCount - 1 );
allItemsHeight = lastItem.y + lastItem.getBounds().height;
}
+ updateScrollBars();
// Set items width based on scrollbar visibility
Rectangle bounds = getBounds();
int border = getBorderWidth();
int scrollBarWidth = getVScrollBarWidth();
for( int i = 0; i < itemCount; i++ ) {
ExpandItem item = getItem( i );
- if( isVScrollbarVisible() ) {
+ if( isVScrollBarVisible() ) {
int width = bounds.width - scrollBarWidth - 2 * border - 2 * spacing;
item.setBounds( 0, 0, width, item.height, false, true );
} else {
@@ -416,6 +416,7 @@
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
+ @Override
public void setFont( Font font ) {
if( font != getFont() ) {
super.setFont( font );
@@ -453,6 +454,7 @@
layoutItems( index + 1, true );
}
+ @Override
protected void checkSubclass() {
if( !isValidSubclass() ) {
error( SWT.ERROR_INVALID_SUBCLASS );
@@ -468,16 +470,23 @@
return false;
}
- boolean isVScrollbarVisible() {
- int border = getBorderWidth();
- return ( getStyle() & SWT.V_SCROLL ) != 0
- && ( allItemsHeight > getBounds().height - 2 * border - spacing );
+ private void updateScrollBars() {
+ ScrollBar vScroll = getVerticalBar();
+ if( vScroll != null ) {
+ vScroll.setVisible( allItemsHeight > getBounds().height - 2 * getBorderWidth() - spacing );
+ }
+ }
+
+ private boolean isVScrollBarVisible() {
+ ScrollBar vScroll = getVerticalBar();
+ return vScroll != null && vScroll.getVisible();
}
Rectangle getBottomSpacingBounds() {
return new Rectangle( spacing, allItemsHeight, 10, spacing );
}
+ @Override
@SuppressWarnings("unchecked")
public <T> T getAdapter( Class<T> adapter ) {
T result;
@@ -497,6 +506,7 @@
/////////////////////
// Destroy expand bar
+ @Override
void releaseWidget() {
if( resizeListener != null ) {
removeControlListener( resizeListener );
@@ -504,6 +514,7 @@
super.releaseWidget();
}
+ @Override
void releaseChildren() {
Item[] expandItems = new ExpandItem[ getItemCount() ];
System.arraycopy( getItems(), 0, expandItems, 0, getItems().length );
@@ -517,6 +528,7 @@
////////////////////////////
// Helping methods - various
+ @Override
int getVScrollBarWidth() {
int result = 0;
if( ( style & SWT.V_SCROLL ) != 0 ) {
@@ -528,6 +540,7 @@
///////////////////
// Skinning support
+ @Override
void reskinChildren( int flags ) {
ExpandItem[] items = getItems();
if( items != null ) {
diff --git a/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/expandbarkit/ExpandBarLCA.java b/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/expandbarkit/ExpandBarLCA.java
index 9c071b0..0f50ab1 100644
--- a/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/expandbarkit/ExpandBarLCA.java
+++ b/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/expandbarkit/ExpandBarLCA.java
@@ -26,6 +26,7 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.internal.widgets.IExpandBarAdapter;
+import org.eclipse.swt.internal.widgets.ScrollBarLCAUtil;
import org.eclipse.swt.widgets.*;
@@ -35,7 +36,6 @@
private static final String[] ALLOWED_STYLES = new String[] { "NO_RADIO_GROUP", "BORDER" };
private static final String PROP_BOTTOM_SPACING_BOUNDS = "bottomSpacingBounds";
- private static final String PROP_VSCROLLBAR_VISIBLE = "vScrollBarVisible";
private static final String PROP_VSCROLLBAR_MAX = "vScrollBarMax";
private static final String PROP_EXPAND_LISTENER = "Expand";
private static final String PROP_COLLAPSE_LISTENER = "Collapse";
@@ -46,10 +46,10 @@
ControlLCAUtil.preserveValues( expandBar );
WidgetLCAUtil.preserveCustomVariant( expandBar );
preserveProperty( expandBar, PROP_BOTTOM_SPACING_BOUNDS, getBottomSpacingBounds( expandBar ) );
- preserveProperty( expandBar, PROP_VSCROLLBAR_VISIBLE, isVScrollBarVisible( expandBar ) );
preserveProperty( expandBar, PROP_VSCROLLBAR_MAX, getVScrollBarMax( expandBar ) );
preserveListener( expandBar, PROP_EXPAND_LISTENER, hasExpandListener( expandBar ) );
preserveListener( expandBar, PROP_COLLAPSE_LISTENER, hasCollapseListener( expandBar ) );
+ ScrollBarLCAUtil.preserveValues( expandBar );
}
public void readData( Widget widget ) {
@@ -59,6 +59,7 @@
WidgetLCAUtil.processHelp( expandBar );
processExpandEvent( expandBar, SWT.Expand, "Expand" );
processExpandEvent( expandBar, SWT.Collapse, "Collapse" );
+ ScrollBarLCAUtil.processSelectionEvent( expandBar );
}
@Override
@@ -68,6 +69,7 @@
clientObject.create( TYPE );
clientObject.set( "parent", WidgetUtil.getId( expandBar.getParent() ) );
clientObject.set( "style", WidgetLCAUtil.getStyles( expandBar, ALLOWED_STYLES ) );
+ ScrollBarLCAUtil.renderInitialization( expandBar );
}
@Override
@@ -79,10 +81,10 @@
PROP_BOTTOM_SPACING_BOUNDS,
getBottomSpacingBounds( expandBar ),
null );
- renderProperty( expandBar, PROP_VSCROLLBAR_VISIBLE, isVScrollBarVisible( expandBar ), false );
renderProperty( expandBar, PROP_VSCROLLBAR_MAX, getVScrollBarMax( expandBar ), 0 );
renderListener( expandBar, PROP_EXPAND_LISTENER, hasExpandListener( expandBar ), false );
renderListener( expandBar, PROP_COLLAPSE_LISTENER, hasCollapseListener( expandBar ), false );
+ ScrollBarLCAUtil.renderChanges( expandBar );
}
@Override
@@ -97,10 +99,6 @@
return getExpandBarAdapter( bar ).getBottomSpacingBounds();
}
- private static boolean isVScrollBarVisible( ExpandBar bar ) {
- return getExpandBarAdapter( bar ).isVScrollbarVisible();
- }
-
private static int getVScrollBarMax( ExpandBar bar ) {
int result = 0;
if( ( bar.getStyle() & SWT.V_SCROLL ) != 0 ) {
diff --git a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/ExpandBarTest.js b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/ExpandBarTest.js
index c7573a8..0530368 100644
--- a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/ExpandBarTest.js
+++ b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/ExpandBarTest.js
@@ -65,7 +65,9 @@
var TestUtil = org.eclipse.rwt.test.fixture.TestUtil;
var shell = TestUtil.createShellByProtocol( "w2" );
var widget = this._createExpandBarByProtocol( "w3", "w2", [ "NONE" ] );
- TestUtil.protocolSet( "w3", { "vScrollBarVisible" : true } );
+
+ TestUtil.protocolSet( "w3_vscroll", { "visibility" : true } );
+
assertTrue( widget._vertScrollBar.getDisplay() );
shell.destroy();
widget.destroy();
@@ -245,6 +247,26 @@
"parent" : parentId
}
} );
+ rwt.protocol.MessageProcessor.processOperation( {
+ "target" : id + "_vscroll",
+ "action" : "create",
+ "type" : "rwt.widgets.ScrollBar",
+ "properties" : {
+ "parent" : id,
+ "style" : [ "VERTICAL" ],
+ "visibility" : true
+ }
+ } );
+ rwt.protocol.MessageProcessor.processOperation( {
+ "target" : id + "_hscroll",
+ "action" : "create",
+ "type" : "rwt.widgets.ScrollBar",
+ "properties" : {
+ "parent" : id,
+ "style" : [ "HORIZONTAL" ],
+ "visibility" : true
+ }
+ } );
return rwt.protocol.ObjectRegistry.getObject( id );
},
diff --git a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/internal/widgets/expandbarkit/ExpandBarLCA_Test.java b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/internal/widgets/expandbarkit/ExpandBarLCA_Test.java
index 11fa01c..a442fed 100644
--- a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/internal/widgets/expandbarkit/ExpandBarLCA_Test.java
+++ b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/internal/widgets/expandbarkit/ExpandBarLCA_Test.java
@@ -26,6 +26,8 @@
import org.eclipse.rap.rwt.testfixture.Message.DestroyOperation;
import org.eclipse.rap.rwt.testfixture.Message.Operation;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.widgets.Props;
import org.eclipse.swt.internal.widgets.controlkit.ControlLCATestUtil;
@@ -134,7 +136,6 @@
assertEquals( "rwt.widgets.ExpandBar", operation.getType() );
List<Object> styles = Arrays.asList( operation.getStyles() );
assertFalse( styles.contains( "V_SCROLL" ) );
- assertEquals( Boolean.TRUE, message.findCreateProperty( expandBar, "vScrollBarVisible" ) );
}
public void testRenderParent() throws IOException {
@@ -185,18 +186,19 @@
public void testRenderInitialVScrollBarVisible() throws IOException {
expandBar = new ExpandBar( shell, SWT.V_SCROLL );
+ ScrollBar vScroll = expandBar.getVerticalBar();
expandBar.setSize( 100, 40 );
new ExpandItem( expandBar, SWT.NONE );
lca.render( expandBar );
Message message = Fixture.getProtocolMessage();
- CreateOperation operation = message.findCreateOperation( expandBar );
- assertTrue( operation.getPropertyNames().indexOf( "vScrollBarVisible" ) == -1 );
+ assertNull( message.findSetOperation( vScroll, "visibility" ) );
}
public void testRenderVScrollBarVisible() throws IOException {
expandBar = new ExpandBar( shell, SWT.V_SCROLL );
+ ScrollBar vScroll = expandBar.getVerticalBar();
expandBar.setSize( 100, 40 );
new ExpandItem( expandBar, SWT.NONE );
@@ -204,22 +206,24 @@
lca.renderChanges( expandBar );
Message message = Fixture.getProtocolMessage();
- assertEquals( Boolean.TRUE, message.findSetProperty( expandBar, "vScrollBarVisible" ) );
+ assertEquals( Boolean.TRUE, message.findSetProperty( vScroll, "visibility" ) );
}
public void testRenderVScrollBarVisibleUnchanged() throws IOException {
expandBar = new ExpandBar( shell, SWT.V_SCROLL );
+ ScrollBar vScroll = expandBar.getVerticalBar();
expandBar.setSize( 100, 40 );
new ExpandItem( expandBar, SWT.NONE );
Fixture.markInitialized( display );
Fixture.markInitialized( expandBar );
+ Fixture.markInitialized( vScroll );
new ExpandItem( expandBar, SWT.NONE );
Fixture.preserveWidgets();
lca.renderChanges( expandBar );
Message message = Fixture.getProtocolMessage();
- assertNull( message.findSetOperation( expandBar, "vScrollBarVisible" ) );
+ assertNull( message.findSetOperation( vScroll, "visibility" ) );
}
public void testRenderInitialVScrollBarMax() throws IOException {
@@ -274,4 +278,46 @@
Message message = Fixture.getProtocolMessage();
assertEquals( Boolean.TRUE, message.findListenProperty( expandBar, "Collapse" ) );
}
+
+ public void testRenderAddScrollBarsSelectionListener_Vertical() throws Exception {
+ expandBar = new ExpandBar( shell, SWT.V_SCROLL );
+ ScrollBar vScroll = expandBar.getVerticalBar();
+ Fixture.markInitialized( vScroll );
+ Fixture.preserveWidgets();
+
+ vScroll.addSelectionListener( new SelectionAdapter() { } );
+ lca.renderChanges( expandBar );
+
+ Message message = Fixture.getProtocolMessage();
+ assertEquals( Boolean.TRUE, message.findListenProperty( vScroll, "Selection" ) );
+ }
+
+ public void testRenderRemoveScrollBarsSelectionListener_Vertical() throws Exception {
+ expandBar = new ExpandBar( shell, SWT.V_SCROLL );
+ ScrollBar vScroll = expandBar.getVerticalBar();
+ SelectionListener listener = new SelectionAdapter() { };
+ vScroll.addSelectionListener( listener );
+ Fixture.markInitialized( vScroll );
+ Fixture.preserveWidgets();
+
+ vScroll.removeSelectionListener( listener );
+ lca.renderChanges( expandBar );
+
+ Message message = Fixture.getProtocolMessage();
+ assertEquals( Boolean.FALSE, message.findListenProperty( vScroll, "Selection" ) );
+ }
+
+ public void testRenderScrollBarsSelectionListenerUnchanged_Vertical() throws Exception {
+ expandBar = new ExpandBar( shell, SWT.V_SCROLL );
+ ScrollBar vScroll = expandBar.getVerticalBar();
+ Fixture.markInitialized( display );
+ Fixture.markInitialized( vScroll );
+
+ vScroll.addSelectionListener( new SelectionAdapter() { } );
+ Fixture.preserveWidgets();
+ lca.renderChanges( expandBar );
+
+ Message message = Fixture.getProtocolMessage();
+ assertNull( message.findListenOperation( vScroll, "Selection" ) );
+ }
}