Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Furnadjiev2016-11-15 13:37:10 +0000
committerGerrit Code Review @ Eclipse.org2016-11-22 09:48:49 +0000
commite0dd8c88eaa7f18355904094b5ff801f19528f4e (patch)
tree816229de8b8452fc42754494d50dffd497d2e9bf /bundles
parent6cd512186de3fabc5d31b28cb1e0ce1f4e1a6fbe (diff)
downloadorg.eclipse.rap-e0dd8c88eaa7f18355904094b5ff801f19528f4e.tar.gz
org.eclipse.rap-e0dd8c88eaa7f18355904094b5ff801f19528f4e.tar.xz
org.eclipse.rap-e0dd8c88eaa7f18355904094b5ff801f19528f4e.zip
Add support for H_SCROLL to DropDown
Add DropDown (Java) constructor with style parameter. Use arguments object in DropDown (JS) constructor. Check if re-layout is needed whenever a new row was rendered. Respect horizontal scrollbar height when computing DropDown layout. Change-Id: I199affd87c341da99a39b4f7cb4fa17a8c672a3c Signed-off-by: Tim Buschtoens <tbuschto@eclipsesource.com>
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/DropDownHandler.js7
-rwxr-xr-xbundles/org.eclipse.rap.rwt/js/rwt/widgets/Combo.js2
-rw-r--r--bundles/org.eclipse.rap.rwt/js/rwt/widgets/DropDown.js54
-rw-r--r--bundles/org.eclipse.rap.rwt/js/rwt/widgets/base/GridRowContainer.js3
-rw-r--r--bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/widgets/DropDown.java51
5 files changed, 89 insertions, 28 deletions
diff --git a/bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/DropDownHandler.js b/bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/DropDownHandler.js
index 2b5a9db0a3..56dc9c594b 100644
--- a/bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/DropDownHandler.js
+++ b/bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/DropDownHandler.js
@@ -17,7 +17,12 @@
factory : function( properties ) {
var control = rwt.remote.ObjectRegistry.getObject( properties.parent );
- var dropdown = new rwt.widgets.DropDown( control, properties.markupEnabled, "dropdown" );
+ var dropdown = new rwt.widgets.DropDown( {
+ parent: control,
+ markupEnabled: properties.markupEnabled,
+ appearance: "dropdown",
+ hScroll: properties.style.indexOf("H_SCROLL") !== -1
+ } );
new rwt.widgets.util.DropDownSynchronizer( dropdown );
return dropdown;
},
diff --git a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/Combo.js b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/Combo.js
index 6c3cb90dc4..7b1c3b74cb 100755
--- a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/Combo.js
+++ b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/Combo.js
@@ -135,7 +135,7 @@ rwt.qx.Class.define( "rwt.widgets.Combo", {
// DropDown requires valid parent focus root when creating
if( !this._list ) {
var appearance = this.getAppearance() + "-list";
- this._list = new rwt.widgets.DropDown( this, false, appearance );
+ this._list = new rwt.widgets.DropDown( { parent: this, appearance: appearance } );
this._list.setSelectionWrapping( false );
this._list.setDirection( this.getDirection() );
var that = this;
diff --git a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/DropDown.js b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/DropDown.js
index 7f4316e9b1..23e2c9df91 100644
--- a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/DropDown.js
+++ b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/DropDown.js
@@ -34,16 +34,17 @@
/**
* @class Instances of DropDown represent the server-side counterpart of a DropDown widget
*/
- rwt.widgets.DropDown = function( parent, markupEnabled, appearance ) {
+ rwt.widgets.DropDown = function( args ) {
this._ = {};
+ this._.hScroll = !!args.hScroll;
this._.hideTimer = new rwt.client.Timer( 0 );
this._.hideTimer.addEventListener( "interval", checkFocus, this );
- this._.parent = parent;
- this._.appearance = appearance;
+ this._.parent = args.parent;
+ this._.appearance = args.appearance;
this._.customVariant = null;
this._.styleMap = null;
- this._.popup = createPopup( appearance ); // TODO: create on demand
- this._.grid = createGrid( this._.popup, markupEnabled, appearance );
+ this._.popup = createPopup( args.appearance ); // TODO: create on demand
+ this._.grid = createGrid( this._.popup, !!args.markupEnabled, args.appearance );
inheritParentStyling.call( this );
this._.visibleItemCount = 5;
this._.items = [];
@@ -56,7 +57,7 @@
addParentListeners.call( this );
addGridListeners.call( this );
this._.popup.addEventListener( "appear", onAppear, this );
- this._.parentFocusRoot = parent.getFocusRoot();
+ this._.parentFocusRoot = args.parent.getFocusRoot();
this._.parentFocusRoot.addEventListener( "changeFocusedChild", onFocusChange, this );
};
@@ -66,12 +67,12 @@
setItems : function( items ) {
this.setSelectionIndex( -1 );
+ delete this._.maxTextWidth;
this._.items = rwt.util.Arrays.copy( items );
renderGridItems.call( this );
if( this._.grid.isSeeable() ) {
renderLayout.call( this );
}
- updateScrollBars.call( this );
if( this._.visibility && items.length > 0 ) {
this.show();
} else if( this._.visibility && items.length === 0 ) {
@@ -96,7 +97,6 @@
renderLayout.call( this );
}
// TODO: hide dropdown completely if no items are visible
- updateScrollBars.call( this );
},
getVisibleItemCount : function() {
@@ -349,6 +349,9 @@
this._.grid.addEventListener( "keypress", onKeyEvent, this );
this._.grid.addEventListener( "mousedown", onMouseDown, this );
this._.grid.addEventListener( "mouseup", onMouseUp, this );
+ if ( this._.hScroll && !this._.columns ) {
+ this._.grid.getRowContainer().addEventListener( "rowRendered", onRowRendered, this );
+ }
}
function setPopUpVisible( visible ) {
@@ -367,13 +370,15 @@
var itemHeight = Math.floor( font.getSize() * 1.3 ) + padding[ 0 ] + padding[ 2 ];
var visibleItems = Math.min( this._.visibleItemCount, this.getItemCount() );
var gridWidth = calcGridWidth.apply( this );
- var gridHeight = visibleItems * itemHeight;
+ var gridHeight = calcGridHeight.apply( this, [ visibleItems, itemHeight ] );
+ var itemWidth = computeItemWidth.apply( this, [ gridWidth, padding ] );
renderPosition.call( this );
var frameWidth = getStyleMap.call( this ).border.getWidthLeft() * 2;
this._.popup.setWidth( gridWidth + frameWidth );
this._.popup.setHeight( gridHeight + frameWidth );
this._.grid.setDimension( gridWidth, gridHeight );
- renderItemMetrics.apply( this, [ itemHeight, gridWidth, padding ] );
+ renderItemMetrics.apply( this, [ itemHeight, itemWidth, padding ] );
+ updateScrollBars.apply( this, [ gridWidth, itemWidth ] );
}
function renderPosition() {
@@ -409,6 +414,14 @@
return result;
}
+ function calcGridHeight( visibleItems, itemHeight ) {
+ var result = visibleItems * itemHeight;
+ if ( this._.hScroll ) {
+ result += this._.grid.getHorizontalBar().getHeight();
+ }
+ return result;
+ }
+
function renderItemMetrics( itemHeight, itemWidth, padding ) {
this._.grid.setItemHeight( itemHeight );
if( this._.columns != null ) {
@@ -443,6 +456,11 @@
}
}
+ function computeItemWidth( gridWidth, padding ) {
+ var neededWidth = this._.hScroll ? ( this._.maxTextWidth || 0 ) + padding[ 1 ] + padding[ 3 ] : 0;
+ return Math.max( neededWidth, gridWidth );
+ }
+
function renderGridItems() {
var rootItem = this._.grid.getRootItem();
var items = this._.items;
@@ -580,6 +598,14 @@
this._.hideTimer.start();
}
+ function onRowRendered( row ) {
+ var textWidth = row._computeVisualTextWidth( 0 );
+ if ( textWidth > ( this._.maxTextWidth || 0 ) ) {
+ this._.maxTextWidth = textWidth;
+ renderLayout.call( this );
+ }
+ }
+
function fireEvent( type ) {
var event = {
"text" : "",
@@ -609,10 +635,10 @@
}
}
- function updateScrollBars() {
- var scrollable = this._.visibleItemCount < this.getItemCount();
- // TODO [tb] : Horizontal scrolling would require measuring all items preferred width
- this._.grid.setScrollBarsVisible( false, scrollable );
+ function updateScrollBars( gridWidth, itemWidth ) {
+ var vScrollable = this._.visibleItemCount < this.getItemCount();
+ var hScrollable = this._.hScroll && gridWidth < itemWidth;
+ this._.grid.setScrollBarsVisible( hScrollable, vScrollable );
}
function notify( type, event ) {
diff --git a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/base/GridRowContainer.js b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/base/GridRowContainer.js
index 55938e7bed..126f27065c 100644
--- a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/base/GridRowContainer.js
+++ b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/base/GridRowContainer.js
@@ -354,6 +354,9 @@ rwt.qx.Class.define( "rwt.widgets.base.GridRowContainer", {
this._isSelected( item ),
this._getHoverElement( item ),
contentOnly );
+ if( item ) {
+ this.dispatchSimpleEvent( "rowRendered", row );
+ }
},
_sortRows : function( newFirstRow, forwards ) {
diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/widgets/DropDown.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/widgets/DropDown.java
index cc5e32e658..089b174135 100644
--- a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/widgets/DropDown.java
+++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/widgets/DropDown.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013, 2015 EclipseSource and others.
+ * Copyright (c) 2013, 2016 EclipseSource 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
@@ -10,10 +10,12 @@
******************************************************************************/
package org.eclipse.rap.rwt.widgets;
+import static org.eclipse.rap.rwt.internal.lifecycle.WidgetLCAUtil.getStyles;
+import static org.eclipse.rap.rwt.internal.protocol.JsonUtil.createJsonArray;
+
import java.util.ArrayList;
import java.util.Arrays;
-import org.eclipse.rap.json.JsonArray;
import org.eclipse.rap.json.JsonObject;
import org.eclipse.rap.json.JsonValue;
import org.eclipse.rap.rwt.RWT;
@@ -66,6 +68,9 @@ public class DropDown extends Widget {
private static final String REMOTE_TYPE = "rwt.widgets.DropDown";
private static final String SELECTION = "Selection";
private static final String DEFAULT_SELECTION = "DefaultSelection";
+ private static final String[] ALLOWED_STYLES = {
+ "V_SCROLL", "H_SCROLL"
+ };
private final java.util.List<String> items;
private RemoteObject remoteObject;
@@ -77,10 +82,12 @@ public class DropDown extends Widget {
private int visibleItemCount = 5;
/**
- * Constructs a new instance of this class given its parent.
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior.
*
* @param parent a control, usually <code>Text</code>,
* which will be the parent of the new instance (cannot be null)
+ * @param style the style of widget to construct
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
@@ -92,12 +99,15 @@ public class DropDown extends Widget {
*
* @see Text
* @see Widget#checkSubclass
+ *
+ * @since 3.2
*/
- public DropDown( Control parent ) {
- super( parent, SWT.NONE );
+ public DropDown( Control parent, int style ) {
+ super( parent, checkStyle( style ) );
this.parent = parent;
items = new ArrayList<>();
getRemoteObject().set( "parent", WidgetUtil.getId( parent ) );
+ getRemoteObject().set( "style", createJsonArray( getStyles( this, ALLOWED_STYLES ) ) );
getRemoteObject().setHandler( new InternalOperationHandler() );
disposeListener = new Listener() {
@Override
@@ -109,6 +119,27 @@ public class DropDown extends Widget {
}
/**
+ * Constructs a new instance of this class given its parent.
+ *
+ * @param parent a control, usually <code>Text</code>,
+ * which will be the parent of the new instance (cannot be null)
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
+ * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
+ * </ul>
+ *
+ * @see Text
+ * @see Widget#checkSubclass
+ */
+ public DropDown( Control parent ) {
+ this( parent, SWT.V_SCROLL );
+ }
+
+ /**
* Sets the receiver's items to be the given array of items.
*
* @param items the array of items
@@ -134,7 +165,7 @@ public class DropDown extends Widget {
}
this.items.clear();
this.items.addAll( Arrays.asList( items ) );
- remoteObject.set( "items", JsonUtil.createJsonArray( items ) );
+ remoteObject.set( "items", createJsonArray( items ) );
setSelectionIndexImpl( -1 );
}
@@ -443,12 +474,8 @@ public class DropDown extends Widget {
return result;
}
- private static JsonArray createJsonArray( int[] arr ) {
- JsonArray array = new JsonArray();
- for( int i = 0; i < arr.length; i++ ) {
- array.add( arr[ i ] );
- }
- return array;
+ private static int checkStyle( int style ) {
+ return style | SWT.V_SCROLL;
}
}

Back to the top