diff options
author | Ivan Furnadjiev | 2014-03-25 16:13:29 +0000 |
---|---|---|
committer | Ivan Furnadjiev | 2014-03-26 11:28:42 +0000 |
commit | 5ec2bd756a8eee3d83037f783bf6760099f6a91b (patch) | |
tree | 6fe35e890c4648132dfe73bc47a9e4621a14f222 | |
parent | bb29ecd6b70d39545e835704d798c2a853c076ea (diff) | |
download | org.eclipse.rap.incubator.dropdown-5ec2bd756a8eee3d83037f783bf6760099f6a91b.tar.gz org.eclipse.rap.incubator.dropdown-5ec2bd756a8eee3d83037f783bf6760099f6a91b.tar.xz org.eclipse.rap.incubator.dropdown-5ec2bd756a8eee3d83037f783bf6760099f6a91b.zip |
Move JavaScript DropDown implementation and tests to RAP core
Render "data" as property instead of "setData" call operation.
16 files changed, 16 insertions, 2130 deletions
diff --git a/bundles/org.eclipse.rap.addons.dropdown/.classpath b/bundles/org.eclipse.rap.addons.dropdown/.classpath index 7db29ef..64c5e31 100644 --- a/bundles/org.eclipse.rap.addons.dropdown/.classpath +++ b/bundles/org.eclipse.rap.addons.dropdown/.classpath @@ -3,6 +3,5 @@ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="src" path="src"/> - <classpathentry kind="src" path="js"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/bundles/org.eclipse.rap.addons.dropdown/META-INF/MANIFEST.MF b/bundles/org.eclipse.rap.addons.dropdown/META-INF/MANIFEST.MF index 69577c2..0592929 100644 --- a/bundles/org.eclipse.rap.addons.dropdown/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.rap.addons.dropdown/META-INF/MANIFEST.MF @@ -2,10 +2,9 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: DropDown Bundle-SymbolicName: org.eclipse.rap.addons.dropdown -Bundle-Version: 0.2.0.qualifier +Bundle-Version: 0.3.0.qualifier Bundle-Vendor: Eclipse.org - RAP Incubator Bundle-RequiredExecutionEnvironment: J2SE-1.5 Import-Package: org.osgi.framework;version="1.3.0" -Export-Package: org.eclipse.rap.addons.dropdown;version="0.2.0", - org.eclipse.rap.addons.dropdown.internal.resources;version="0.2.0";x-internal:=true -Require-Bundle: org.eclipse.rap.rwt;bundle-version="2.2.0" +Export-Package: org.eclipse.rap.addons.dropdown;version="0.2.0" +Require-Bundle: org.eclipse.rap.rwt;bundle-version="2.3.0" diff --git a/bundles/org.eclipse.rap.addons.dropdown/build.properties b/bundles/org.eclipse.rap.addons.dropdown/build.properties index 745ecd4..018ec84 100644 --- a/bundles/org.eclipse.rap.addons.dropdown/build.properties +++ b/bundles/org.eclipse.rap.addons.dropdown/build.properties @@ -1,5 +1,4 @@ -source.. = src/,\ - js/ +source.. = src/ output.. = bin/ bin.includes = META-INF/,\ . diff --git a/bundles/org.eclipse.rap.addons.dropdown/js/rwt/dropdown/DropDown.js b/bundles/org.eclipse.rap.addons.dropdown/js/rwt/dropdown/DropDown.js deleted file mode 100644 index 2e8c2f5..0000000 --- a/bundles/org.eclipse.rap.addons.dropdown/js/rwt/dropdown/DropDown.js +++ /dev/null @@ -1,631 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * EclipseSource - initial API and implementation - ******************************************************************************/ - -//@ sourceURL=DropDown.js - -(function(){ - - var TAB = String.fromCharCode( 9 ); - var getPadding = function() { - var manager = rwt.theme.AppearanceManager.getInstance(); - var stylemap = manager.styleFrom( "list-item", {} ); - return stylemap.padding || [ 5, 5, 5, 5 ]; - }; - var getShadow = function() { - var manager = rwt.theme.AppearanceManager.getInstance(); - var stylemap = manager.styleFrom( "combo-list", {} ); - return stylemap.shadow || null; - }; - var styleMap = null; - var getStyleMap = function() { - if( styleMap == null ) { - var manager = rwt.theme.AppearanceManager.getInstance(); - try { - styleMap = manager.styleFrom( "dropdown", {} ); - } catch( ex ) { - } - if( styleMap == null ) { - styleMap = {}; - styleMap.border = new rwt.html.Border( 1, "solid", "#000000" ); - } - styleMap.padding = getPadding(); - styleMap.shadow = getShadow(); - } - return styleMap; - }; - - var eventTypes = { - Selection : SWT.Selection, - DefaultSelection : SWT.DefaultSelection, - Show : SWT.Show, - Hide : SWT.Hide - }; - - var forwardedKeys = { - Enter : true, - Up : true, - Down : true, - PageUp : true, - PageDown : true, - Escape : true - }; - - /** - * @public - * @namespace - * @name rwt - */ - /** - * @public - * @namespace - */ - rwt.dropdown = {}; - - /** - * @class Instances of DropDown represent the server-side counterpart of a DropDown widget - */ - rwt.dropdown.DropDown = function( parent, markupEnabled ) { - this._ = {}; - this._.hideTimer = new rwt.client.Timer( 0 ); - this._.hideTimer.addEventListener( "interval", checkFocus, this ); - this._.popup = createPopup(); // TODO: create on demand - this._.grid = createGrid( this._.popup, markupEnabled ); - this._.visibleItemCount = 5; - this._.parent = parent; - this._.items = []; - this._.columns = null; - this._.inMouseSelection = false; - this._.events = createEventsMap(); - this._.parent.addEventListener( "keypress", onTextKeyEvent, this ); - this._.parent.addEventListener( "flush", onTextFlush, this ); - this._.grid._sendSelectionChange = bind( this, onSelection ); - this._.grid.addEventListener( "keypress", onKeyEvent, this ); - this._.grid.addEventListener( "mousedown", onMouseDown, this ); - this._.grid.addEventListener( "mouseup", onMouseUp, this ); - this._.popup.addEventListener( "appear", onAppear, this ); - this._.popup.getFocusRoot().addEventListener( "changeFocusedChild", onFocusChange, this ); - this._.parentFocusRoot = parent.getFocusRoot(); - this._.parentFocusRoot.addEventListener( "changeFocusedChild", onFocusChange, this ); - parent.addEventListener( "appear", onTextAppear, this ); - this._.visibility = false; - }; - - rwt.dropdown.DropDown.prototype = { - - classname : "rwt.dropdown.DropDown", - - setItems : function( items ) { - this.setSelectionIndex( -1 ); - 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 ) { - this._.popup.hide(); - } - }, - - getItemCount : function() { - return this._.grid.getRootItem().getChildrenLength(); - }, - - /** - * Not intended to be called by ClientScripting - */ - setVisibleItemCount : function( itemCount ) { - this._.visibleItemCount = itemCount; - if( this._.grid.isSeeable() ) { - renderLayout.call( this ); - } - // TODO: hide dropdown completely if no items are visible - updateScrollBars.call( this ); - }, - - setSelectionIndex : function( index ) { - if( index < -1 || index >= this.getItemCount() || isNaN( index ) ) { - throw new Error( "Can not select item: Index " + index + " not valid" ); - } - if( this.getSelectionIndex() === index ) { - return; - } - // This is more than optimization, it prevents too early rendering that can crash the client: - this._.grid._inServerResponse = rwt.util.Functions.returnTrue; - this._.grid.deselectAll(); - if( index > -1 ) { - var item = this._.grid.getRootItem().getChild( index ); - this._.grid.selectItem( item ); - this._.grid.setFocusItem( item ); - this._.grid._scrollIntoView( index, item ); - } else { - this._.grid.setFocusItem( null ); - this._.grid.setTopItemIndex( 0 ); - } - delete this._.grid._inServerResponse; - this._.grid._sendSelectionChange(); // Not called for selection changes by API/Server - }, - - getSelectionIndex : function() { - var selection = this._.grid._selection; - var result = -1; - if( selection[ 0 ] ) { - result = this._.grid.getRootItem().indexOf( selection[ 0 ] ); - } - return result; - }, - - setVisible : function( value ) { - if( value ) { - this.show(); - } else { - this.hide(); - } - }, - - getVisible : function() { - return this._.visibility; - }, - - show : function() { - checkDisposed( this ); - if( !this._.visibility ) { - this._.visibility = true; - fireEvent.call( this, "Show" ); - if( !rwt.remote.EventUtil.getSuspended() ) { - rap.getRemoteObject( this ).set( "visible", true ); - } - } - if( this._.items.length > 0 && this._.parent.isCreated() && !this._.popup.isSeeable() ) { - this._.grid.setFont( this._.parent.getFont() ); - renderLayout.call( this ); - this._.popup.show(); - if( !hasFocus( this._.parent ) ) { - this._.grid.getFocusRoot().setFocusedChild( this._.grid ); - } - } - }, - - hide : function() { - checkDisposed( this ); - if( this._.visibility ) { - this._.visibility = false; - fireEvent.call( this, "Hide" ); - if( !rwt.remote.EventUtil.getSuspended() ) { - rap.getRemoteObject( this ).set( "visible", false ); - } - } - this._.popup.setVisibility( false ); // makes it disappear immediately - this._.popup.setDisplay( false ); // forces the popup to appear after all parents are layouted - }, - - setData : function( key, value ) { - if( !this._.widgetData ) { - this._.widgetData = {}; - } - if( arguments.length === 1 && key instanceof Object ) { - rwt.util.Objects.mergeWith( this._.widgetData, key ); - } else { - this._.widgetData[ key ] = value; - } - }, - - getData : function( key ) { - if( !this._.widgetData ) { - return null; - } - var data = this._.widgetData[ key ]; - return data === undefined ? null : data; - }, - - addListener : function( type, listener ) { - if( this._.events[ type ] ) { - if( this._.events[ type ].indexOf( listener ) === -1 ) { - this._.events[ type ].push( listener ); - } - } else { - throw new Error( "Unkown type " + type ); - } - }, - - removeListener : function( type, listener ) { - if( this._ && this._.events[ type ] ) { - var index = this._.events[ type ].indexOf( listener ); - rwt.util.Arrays.removeAt( this._.events[ type ], index ); - } - }, - - /** - * Experimental! - */ - setColumns : function( columns ) { - this._.columns = columns; - this._.grid.setColumnCount( columns.length ); - if( this._.grid.isSeeable() ) { - renderLayout.call( this ); - } - }, - - /** - * Not intended to be called by ClientScripting - */ - destroy : function() { - if( !this.isDisposed() ) { - var parentFocusRoot = this._.parentFocusRoot; - if( parentFocusRoot && !parentFocusRoot.isDisposed() ) { - parentFocusRoot.removeEventListener( "changeFocusedChild", onFocusChange, this ); - } - var popupFocusRoot = this._.popup.getFocusRoot(); - if( popupFocusRoot && !popupFocusRoot.isDisposed() ) { - popupFocusRoot.removeEventListener( "changeFocusedChild", onFocusChange, this ); - } - this._.grid.getRootItem().setItemCount( 0 ); - if( !this._.parent.isDisposed() ) { - this._.parent.removeEventListener( "appear", onTextAppear, this ); - this._.parent.removeEventListener( "keydown", onTextKeyEvent, this ); - this._.parent.removeEventListener( "flush", onTextFlush, this ); - this._.parent.removeEventListener( "keypress", onTextKeyEvent, this ); - this._.popup.destroy(); - } - this._.hideTimer.dispose(); - if( this._.widgetData ) { - for( var key in this._.widgetData ) { - this._.widgetData[ key ] = null; - } - } - for( var key in this._ ) { - this._[ key ] = null; - } - this._ = null; - } - }, - - isDisposed : function() { - return this._ === null; - }, - - toString : function() { - return "DropDown"; - } - - }; - - //////////// - // "statics" - - rwt.dropdown.DropDown.searchItems = function( items, query, limit ) { - var resultIndicies = []; - var filter = function( item, index ) { - if( query.test( item ) ) { - resultIndicies.push( index ); - return true; - } else { - return false; - } - }; - var resultLimit = typeof limit === "number" ? limit : 0; - var resultItems = filterArray( items, filter, resultLimit ); - return { - "items" : resultItems, - "indicies" : resultIndicies, - "query" : query, - "limit" : resultLimit - }; - }; - - rwt.dropdown.DropDown.createQuery = function( str, caseSensitive, ignorePosition ) { - var escapedStr = rwt.dropdown.DropDown.escapeRegExp( str ); - return new RegExp( ( ignorePosition ? "" : "^" ) + escapedStr, caseSensitive ? "" : "i" ); - }; - - rwt.dropdown.DropDown.escapeRegExp = function( str ) { - return str.replace( /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&" ); - }; - - //////////// - // Internals - - var renderLayout = function() { - var font = this._.grid.getFont(); - // NOTE: Guessing the lineheight to be 1.3 - var padding = getStyleMap().padding; - 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; - renderPosition.call( this ); - var frameWidth = getStyleMap().border.getWidthLeft() * 2; - this._.popup.setWidth( gridWidth + frameWidth ); - this._.popup.setHeight( gridHeight + frameWidth ); - this._.grid.setDimension( gridWidth, gridHeight ); - renderItemMetrics.apply( this, [ itemHeight, gridWidth, padding ] ); - }; - - var renderPosition = function() { - this._.popup.positionRelativeTo( this._.parent, 0, this._.parent.getHeight() ); - var docHeight = rwt.widgets.base.ClientDocument.getInstance().getInnerHeight(); - if( this._.popup.getTop() + this._.popup.getHeight() > docHeight ) { - this._.popup.positionRelativeTo( this._.parent, 0, -1 * this._.popup.getHeight() ); - } - }; - - var calcGridWidth = function() { - var frameWidth = getStyleMap().border.getWidthLeft() * 2; - var result = this._.parent.getWidth() - frameWidth; - if( this._.columns ) { - var columnsSum = 0; - for( var i = 0; i < this._.columns.length; i++ ) { - columnsSum += this._.columns[ i ]; - } - if( columnsSum > result ) { - result = columnsSum; - } - } - return result; - }; - - var renderItemMetrics = function( itemHeight, itemWidth, padding ) { - this._.grid.setItemHeight( itemHeight ); - if( this._.columns != null ) { - var left = 0; - for( var i = 0; i < this._.columns.length; i++ ) { - var column = this._.columns[ i ]; - this._.grid.setItemMetrics( - i, // column - left, // left - column, // width - 0, // imageLeft - 0, // imageWidth - left + padding[ 3 ], // textLeft - column - padding[ 1 ] - padding[ 3 ], // textWidth - 0, // checkLeft - 0 // checkWith - ); - left += column; - } - } else { - this._.grid.setItemMetrics( - 0, // column - 0, // left - itemWidth, // width - 0, // imageLeft - 0, // imageWidth - padding[ 3 ], // textLeft - itemWidth - padding[ 1 ] - padding[ 3 ], // textWidth - 0, // checkLeft - 0 // checkWith - ); - } - }; - - var renderGridItems = function() { - var rootItem = this._.grid.getRootItem(); - var items = this._.items; - this._.grid._inServerResponse = rwt.util.Functions.returnTrue; - rootItem.setItemCount( 0 ); - rootItem.setItemCount( items.length ); - for( var i = 0; i < items.length; i++ ) { - var gridItem = new rwt.widgets.GridItem( rootItem, i, false ); - if( this._.columns ) { - gridItem.setTexts( items[ i ].split( TAB ) ); - } else { - gridItem.setTexts( [ items[ i ] ] ); - } - } - delete this._.grid._inServerResponse; - }; - - var onTextAppear = function() { - if( this._.visibility ) { - this.show(); - } - }; - - var onTextKeyEvent = function( event ) { - var key = event.getKeyIdentifier(); - if( this._.visibility && forwardedKeys[ key ] ) { - event.preventDefault(); - if( key === "Down" && this.getSelectionIndex() === -1 && this.getItemCount() > 0 ) { - this.setSelectionIndex( 0 ); - } else if( key === "Up" && this.getSelectionIndex() === 0 ) { - this.setSelectionIndex( -1 ); - } else if( key === "Down" && this.getSelectionIndex() === this.getItemCount() - 1 ) { - this.setSelectionIndex( -1 ); - } else if( key === "Up" && this.getSelectionIndex() === -1 && this.getItemCount() > 0 ) { - this.setSelectionIndex( this.getItemCount() - 1 ); - } else { - this._.grid.dispatchEvent( event ); - } - } - }; - - var onTextFlush = function( event ) { - var changes = event.getData(); - if( this._.visibility && ( changes.top || changes.left || changes.width || changes.height ) ) { - renderLayout.call( this ); - } - }; - - var onKeyEvent = function( event ) { - switch( event.getKeyIdentifier() ) { - case "Enter": - rwt.client.Timer.once( function() { - // NOTE : This async call ensures that the key events is processed before the - // DefaultSelection event. A better solution would be to do this for all forwarded - // key events, but this would be complicated since the event is disposed by the - // time dispatch would be called on the grid. - fireEvent.call( this, "DefaultSelection" ); - }, this, 0 ); - break; - case "Escape": - this.hide(); - break; - } - }; - - var onSelection = function( event ) { - if( !rwt.remote.EventUtil.getSuspended() ) { - rap.getRemoteObject( this ).set( "selectionIndex", this.getSelectionIndex() ); - } - fireEvent.call( this, "Selection" ); - }; - - var onMouseDown = function( event ) { - if( event.getOriginalTarget() instanceof rwt.widgets.base.GridRow ) { - this._.inMouseSelection = true; - } - }; - - var onMouseUp = function( event ) { - if( this._.inMouseSelection && event.getOriginalTarget() instanceof rwt.widgets.base.GridRow ) { - this._.inMouseSelection = false; - fireEvent.call( this, "DefaultSelection" ); - } - }; - - var onAppear = function( event ) { - // NOTE: widget absolute position can change without changing it's relative postion, therefore: - renderPosition.call( this ); - }; - - var onFocusChange = function( event ) { - // NOTE : There is no secure way to get the newly focused widget at this point because - // it may have another focus root. Therefore we use this timeout and check afterwards: - this._.hideTimer.start(); - }; - - var fireEvent = function( type ) { - var event = { - "text" : "", - "index" : -1 - }; - if( type === "Selection" || type === "DefaultSelection" ) { - var selection = this._.grid._selection; - if( selection.length > 0 ) { - event.index = this.getSelectionIndex(); - event.text = this._.items[ event.index ]; - } - notify.apply( this, [ type, event ] ); - if( !rwt.remote.EventUtil.getSuspended() ) { // TODO [tb] : ClientScripting must reset flag - // TODO : merge multiple changes? How long? - rap.getRemoteObject( this ).notify( type, event ); - if( type === "DefaultSelection" && selection.length > 0 ) { - this.hide(); - } - } - } else { - notify.apply( this, [ type, event ] ); - } - }; - - var checkFocus = function() { - this._.hideTimer.stop(); - if( !hasFocus( this._.parent ) && !hasFocus( this._.popup ) && this._.visibility ) { - this.hide(); - } - }; - - var updateScrollBars = function() { - var scrollable = this._.visibleItemCount < this.getItemCount(); - // TODO [tb] : Horizontal scrolling would require measuring all items preferred width - this._.grid.setScrollBarsVisible( false, scrollable ); - }; - - var notify = function( type, event ) { - var listeners = this._.events[ type ]; - var eventProxy = rwt.util.Objects.merge( { - "widget" : this, - "type" : eventTypes[ type ] - }, event ); - for( var i = 0; i < listeners.length; i++ ) { - listeners[ i ]( eventProxy ); - } - }; - - var createPopup = function() { - var result = new rwt.widgets.base.Popup(); - result.addToDocument(); - result.setBorder( getStyleMap().border ); - result.setBackgroundColor( "#ffffff" ); - result.setDisplay( false ); - result.setShadow( getStyleMap().shadow ); - result.setRestrictToPageOnOpen( false ); - result.setAutoHide( false ); - return result; - }; - - var createGrid = function( parent, markupEnabled ) { - var result = new rwt.widgets.Grid( { - "fullSelection" : true, - "appearance" : "table", - "markupEnabled" : markupEnabled - } ); - result.setLocation( 0, 0 ); - result.setParent( parent ); - result.setTreeColumn( -1 ); // TODO [tb] : should be default? - result.setScrollBarsVisible( false, false ); - result._sendItemFocusChange = rwt.util.Functions.returnTrue; - result._sendTopItemIndexChange = rwt.util.Functions.returnTrue; - result.getRenderConfig().focused = true; - result.addEventListener( "changeFocused", function() { - result.getRenderConfig().focused = true; - } ); - return result; - }; - - var checkDisposed = function( dropdown ) { - if( dropdown.isDisposed() ) { - throw new Error( "DropDown is disposed" ); - } - }; - - var createEventsMap = function() { - var result = {}; - for( var key in eventTypes ) { - result[ key ] = []; - } - return result; - }; - - var bind = function( context, method ) { - return function() { - return method.apply( context, arguments ); - }; - }; - - var hasFocus = function( control ) { - var root = control.getFocusRoot(); - var result = control.getFocused() - || ( control.contains && control.contains( root.getFocusedChild() ) ); - return result; - }; - - var filterArray = function( arr, func, limit ) { - var result = []; - if( typeof arr.filter === "function" && limit === 0 ) { - result = arr.filter( func ); - } else { - for( var i = 0; i < arr.length; i++ ) { - if( func( arr[ i ], i ) ) { - result.push( arr[ i ] ); - if( limit !== 0 && result.length === limit ) { - break; - } - } - } - } - return result; - }; - - -}()); diff --git a/bundles/org.eclipse.rap.addons.dropdown/js/rwt/dropdown/DropDownHandler.js b/bundles/org.eclipse.rap.addons.dropdown/js/rwt/dropdown/DropDownHandler.js deleted file mode 100644 index 064eb32..0000000 --- a/bundles/org.eclipse.rap.addons.dropdown/js/rwt/dropdown/DropDownHandler.js +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * EclipseSource - initial API and implementation - ******************************************************************************/ - -(function(){ - 'use strict'; - - rap.registerTypeHandler( "rwt.dropdown.DropDown", { - - factory : function( properties ) { - var control = rwt.remote.ObjectRegistry.getObject( properties.parent ); - return new rwt.dropdown.DropDown( control, properties.markupEnabled ); - }, - - properties : [ "items", "visible", "visibleItemCount", "columns" ], - - events : [ "Selection", "DefaultSelection" ], - - methods : [ "setData", "addListener", "removeListener" ], - - methodHandler: { - "addListener": function( widget, properties ) { - rwt.remote.HandlerUtil.callWithTarget( properties.listenerId, function( targetFunction ) { - widget.addListener( properties.eventType, targetFunction ); - } ); - }, - "removeListener": function( widget, properties ) { - rwt.remote.HandlerUtil.callWithTarget( properties.listenerId, function( targetFunction ) { - widget.removeListener( properties.eventType, targetFunction ); - } ); - } - }, - - destructor : "destroy" - - } ); - -}()); diff --git a/bundles/org.eclipse.rap.addons.dropdown/src/org/eclipse/rap/addons/dropdown/DropDown.java b/bundles/org.eclipse.rap.addons.dropdown/src/org/eclipse/rap/addons/dropdown/DropDown.java index fa87f9f..1790de9 100644 --- a/bundles/org.eclipse.rap.addons.dropdown/src/org/eclipse/rap/addons/dropdown/DropDown.java +++ b/bundles/org.eclipse.rap.addons.dropdown/src/org/eclipse/rap/addons/dropdown/DropDown.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 EclipseSource. + * Copyright (c) 2013, 2014 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,7 +10,6 @@ ******************************************************************************/ package org.eclipse.rap.addons.dropdown; -import org.eclipse.rap.addons.dropdown.internal.resources.DropDownResources; import org.eclipse.rap.json.JsonArray; import org.eclipse.rap.json.JsonObject; import org.eclipse.rap.json.JsonValue; @@ -61,7 +60,9 @@ import org.eclipse.swt.widgets.Widget; * </p> * */ -@SuppressWarnings("restriction") +@SuppressWarnings({ + "restriction", "deprecation" +}) public class DropDown extends Widget { private static final String COLUMNS = "columns"; @@ -97,7 +98,6 @@ public class DropDown extends Widget { public DropDown( Control parent ) { super( parent, 0 ); this.parent = parent; - DropDownResources.ensure(); getRemoteObject().set( "parent", WidgetUtil.getId( parent ) ); getRemoteObject().setHandler( new InternalOperationHandler() ); disposeListener = new Listener() { @@ -385,9 +385,8 @@ public class DropDown extends Widget { // This implementation assumes the client merges the new values with the existing // ones, which is the case in the WebClient if( WidgetDataUtil.getDataKeys().contains( key ) ) { - @SuppressWarnings( "deprecation" ) JsonObject data = new JsonObject().add( key, JsonUtil.createJsonValue( value ) ); - remoteObject.call( "setData", data ); + remoteObject.set( "data", data ); } } diff --git a/bundles/org.eclipse.rap.addons.dropdown/src/org/eclipse/rap/addons/dropdown/internal/resources/DropDownResources.java b/bundles/org.eclipse.rap.addons.dropdown/src/org/eclipse/rap/addons/dropdown/internal/resources/DropDownResources.java deleted file mode 100644 index 87b9b83..0000000 --- a/bundles/org.eclipse.rap.addons.dropdown/src/org/eclipse/rap/addons/dropdown/internal/resources/DropDownResources.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * EclipseSource - initial API and implementation - ******************************************************************************/ -package org.eclipse.rap.addons.dropdown.internal.resources; - -import java.io.IOException; -import java.io.InputStream; - -import org.eclipse.rap.rwt.RWT; -import org.eclipse.rap.rwt.client.service.JavaScriptLoader; - - -public final class DropDownResources { - - public static final String[] SCRIPTS = new String[] { - "rwt/dropdown/DropDown.js", - "rwt/dropdown/DropDownHandler.js" - }; - - private static final boolean DEBUG = true; - - public static void ensure() { - ensureRegistered(); - ensureLoaded(); - } - - private static void ensureRegistered() { - if( DEBUG && RWT.getResourceManager().isRegistered( SCRIPTS[ 0 ] ) ) { - deregister(); - } - if( !RWT.getResourceManager().isRegistered( SCRIPTS[ 0 ] ) ) { - try { - register(); - } catch( IOException exception ) { - throw new RuntimeException( "Failed to register resources", exception ); - } - } - } - - private static void ensureLoaded() { - for( String script : SCRIPTS ) { - JavaScriptLoader loader = RWT.getClient().getService( JavaScriptLoader.class ); - loader.require( RWT.getResourceManager().getLocation( script ) ); - } - } - - private static void register() throws IOException { - for( String script : SCRIPTS ) { - InputStream inputStream = getResourceAsStream( script ); - try { - RWT.getResourceManager().register( script, inputStream ); - } finally { - inputStream.close(); - } - } - } - - private static void deregister() { - for( String script : SCRIPTS ) { - RWT.getResourceManager().unregister( script ); - } - } - - public static InputStream getResourceAsStream( String resourceName ) { - ClassLoader classLoader = DropDownResources.class.getClassLoader(); - InputStream inputStream = classLoader.getResourceAsStream( resourceName ); - if( inputStream == null ) { - throw new RuntimeException( "Resource not found: " + resourceName ); - } - return inputStream; - } - - private DropDownResources() { - } - -} diff --git a/tests/org.eclipse.rap.addons.dropdown.test/.classpath b/tests/org.eclipse.rap.addons.dropdown.test/.classpath index 7db29ef..64c5e31 100644 --- a/tests/org.eclipse.rap.addons.dropdown.test/.classpath +++ b/tests/org.eclipse.rap.addons.dropdown.test/.classpath @@ -3,6 +3,5 @@ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="src" path="src"/> - <classpathentry kind="src" path="js"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/tests/org.eclipse.rap.addons.dropdown.test/DropDown JS Tests.launch b/tests/org.eclipse.rap.addons.dropdown.test/DropDown JS Tests.launch deleted file mode 100644 index bc00a50..0000000 --- a/tests/org.eclipse.rap.addons.dropdown.test/DropDown JS Tests.launch +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<launchConfiguration type="org.eclipse.pde.ui.EquinoxLauncher"> -<booleanAttribute key="append.args" value="true"/> -<booleanAttribute key="automaticAdd" value="false"/> -<booleanAttribute key="automaticValidate" value="true"/> -<stringAttribute key="bootstrap" value=""/> -<stringAttribute key="checked" value="[NONE]"/> -<booleanAttribute key="clearConfig" value="true"/> -<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/RAP Client Tests"/> -<booleanAttribute key="default" value="true"/> -<booleanAttribute key="default_auto_start" value="true"/> -<intAttribute key="default_start_level" value="4"/> -<booleanAttribute key="includeOptional" value="false"/> -<listAttribute key="org.eclipse.debug.ui.favoriteGroups"> -<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/> -</listAttribute> -<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> -<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consolelog -console -clean"/> -<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/> -<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Declipse.ignoreApp=true -Dosgi.noShutdown=true -Dorg.osgi.service.http.port=8081 -Dorg.eclipse.rap.rwt.developmentMode=true"/> -<stringAttribute key="pde.version" value="3.3"/> -<booleanAttribute key="show_selected_only" value="false"/> -<stringAttribute key="target_bundles" value="com.ibm.icu.base@default:default,javax.servlet@default:default,javax.xml@default:default,org.apache.felix.gogo.command@default:default,org.apache.felix.gogo.runtime@default:default,org.apache.felix.gogo.shell@default:default,org.eclipse.core.commands@default:default,org.eclipse.core.contenttype@default:default,org.eclipse.core.jobs@default:default,org.eclipse.core.runtime@default:true,org.eclipse.equinox.app@default:default,org.eclipse.equinox.common@2:true,org.eclipse.equinox.console@default:default,org.eclipse.equinox.ds@1:true,org.eclipse.equinox.http.jetty@default:default,org.eclipse.equinox.http.servlet@default:default,org.eclipse.equinox.preferences@default:default,org.eclipse.equinox.registry@default:default,org.eclipse.equinox.util@default:default,org.eclipse.jetty.continuation@default:default,org.eclipse.jetty.http@default:default,org.eclipse.jetty.io@default:default,org.eclipse.jetty.security@default:default,org.eclipse.jetty.server@default:default,org.eclipse.jetty.servlet@default:default,org.eclipse.jetty.util@default:default,org.eclipse.osgi.services@default:default,org.eclipse.osgi@-1:true,org.eclipse.rap.jface@default:default,org.eclipse.rap.rwt.osgi@default:default,org.hamcrest.core@default:default,org.junit@default:default,org.mockito.mockito-all@default:default,org.mozilla.javascript@default:default"/> -<booleanAttribute key="tracing" value="false"/> -<booleanAttribute key="useCustomFeatures" value="false"/> -<booleanAttribute key="useDefaultConfigArea" value="false"/> -<stringAttribute key="workspace_bundles" value="org.eclipse.rap.addons.dropdown.test@default:default,org.eclipse.rap.addons.dropdown@default:default,org.eclipse.rap.clientscripting@default:default,org.eclipse.rap.jstestrunner@default:default,org.eclipse.rap.rwt.jstest@default:default,org.eclipse.rap.rwt@default:default"/> -</launchConfiguration> diff --git a/tests/org.eclipse.rap.addons.dropdown.test/OSGI-INF/resourceContribution.xml b/tests/org.eclipse.rap.addons.dropdown.test/OSGI-INF/resourceContribution.xml deleted file mode 100644 index a084f30..0000000 --- a/tests/org.eclipse.rap.addons.dropdown.test/OSGI-INF/resourceContribution.xml +++ /dev/null @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.rap.addons.dropdown.test.resources"> - <implementation class="org.eclipse.rap.addons.dropdown.test.internal.DropDownResourcesContribution"/> - <service> - <provide interface="org.eclipse.rap.rwt.jstest.TestContribution"/> - </service> -</scr:component> diff --git a/tests/org.eclipse.rap.addons.dropdown.test/OSGI-INF/testContribution.xml b/tests/org.eclipse.rap.addons.dropdown.test/OSGI-INF/testContribution.xml deleted file mode 100644 index 8374fd0..0000000 --- a/tests/org.eclipse.rap.addons.dropdown.test/OSGI-INF/testContribution.xml +++ /dev/null @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.rap.addons.dropdown.testResources"> - <implementation class="org.eclipse.rap.addons.dropdown.test.internal.DropDownTestContribution"/> - <service> - <provide interface="org.eclipse.rap.rwt.jstest.TestContribution"/> - </service> -</scr:component> diff --git a/tests/org.eclipse.rap.addons.dropdown.test/build.properties b/tests/org.eclipse.rap.addons.dropdown.test/build.properties index 9bb83a0..018ec84 100644 --- a/tests/org.eclipse.rap.addons.dropdown.test/build.properties +++ b/tests/org.eclipse.rap.addons.dropdown.test/build.properties @@ -1,7 +1,5 @@ -source.. = src/,\ - js/ +source.. = src/ output.. = bin/ bin.includes = META-INF/,\ - .,\ - OSGI-INF/ + . javacDefaultEncoding.. = UTF-8 diff --git a/tests/org.eclipse.rap.addons.dropdown.test/js/rwt/dropdown/DropDown_Test.js b/tests/org.eclipse.rap.addons.dropdown.test/js/rwt/dropdown/DropDown_Test.js deleted file mode 100644 index 0010d58..0000000 --- a/tests/org.eclipse.rap.addons.dropdown.test/js/rwt/dropdown/DropDown_Test.js +++ /dev/null @@ -1,1233 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * EclipseSource - initial API and implementation - ******************************************************************************/ - -(function(){ -'use strict'; - -var TestUtil = org.eclipse.rwt.test.fixture.TestUtil; -var DropDown = rwt.dropdown.DropDown; - -var ITEM_HEIGHT = 25; // Depends on padding which is currently taken from list theming -var PADDING_LEFT = 10; -var PADDING_RIGHT = 10; - -var shell; -var widget; -var dropdown; -var popup; -var grid; -var hideTimer; - -rwt.qx.Class.define( "rwt.dropdown.DropDown_Test", { - - extend : rwt.qx.Object, - - members : { - - setUp : function() { - shell = TestUtil.createShellByProtocol( "w2" ); - shell.open(); - shell.setBorder( null ); - shell.setLocation( 10, 20 ); - this.createExample(); - TestUtil.flush(); - }, - - tearDown : function() { - shell.destroy(); - dropdown.destroy(); - }, - - testConstructor_AddsPopupToDocument : function() { - assertIdentical( rwt.widgets.base.ClientDocument.getInstance(), popup.getParent() ); - }, - - testConstructor_SetsDefaultPopUpStyling : function() { - assertEquals( "solid", popup.getBorder().getStyle() ); - assertEquals( "#000000", popup.getBorder().getColor() ); - assertEquals( [ 1, 1, 1, 1] , popup.getBorder().getWidths() ); - assertEquals( "#ffffff", popup.getBackgroundColor() ); - }, - - testConstructor_DoesNotMakePopUpVisible : function() { - TestUtil.flush(); - assertFalse( popup.isSeeable() ); - }, - - testConstructor_CreatesGridInPopup : function() { - assertTrue( grid instanceof rwt.widgets.Grid ); - assertIdentical( popup, grid.getParent() ); - }, - - testConstructor_PositionsGrid : function() { - assertEquals( 0, grid.getLeft() ); - assertEquals( 0, grid.getTop() ); - }, - - testConstructor_SetsMarkupEnabledFalse : function() { - assertTrue( !grid.getRenderConfig().markupEnabled ); - }, - - testConstructor_SetsMarkupEnabledTrue : function() { - widget = new rwt.widgets.Composite(); - widget.setParent( shell ); - dropdown = new rwt.dropdown.DropDown( widget, true ); - grid = dropdown._.grid; - - assertTrue( grid.getRenderConfig().markupEnabled ); - }, - - testConstructor_FakesGridFocus : function() { - assertTrue( grid.getRenderConfig().focused ); - }, - - testConstructor_FakesGridFocusAfterBlur : function() { - grid.setFocused( false ); - assertTrue( grid.getRenderConfig().focused ); - }, - - testConstructor_HideScrollbars : function() { - assertFalse( grid.getVerticalBar().getVisibility() ); - assertFalse( grid.getHorizontalBar().getVisibility() ); - }, - - testSetData_SetDataWithTwoParameters : function() { - dropdown.setData( "foo", "bar" ); - - assertEquals( "bar", dropdown.getData( "foo" ) ); - }, - - testSetData_SetDataWithMap : function() { - dropdown.setData( "x", "y" ); - dropdown.setData( { "foo" : "bar" } ); - - assertEquals( "y", dropdown.getData( "x" ) ); - assertEquals( "bar", dropdown.getData( "foo" ) ); - }, - - testShow_DoesNotMakePopUpSeeableIfNoItemsAreSet : function() { - showDropDown( [] ); - - assertFalse( popup.isSeeable() ); - }, - - testShow_MakesPopUpSeeable : function() { - showDropDown(); - - assertTrue( popup.isSeeable() ); - }, - - testSetItems_MakesPopUpSeeableIfVisibleIsTrueAndLengthIsGreaterZero : function() { - showDropDown( [] ); - - dropdown.setItems( [ "a" ] ); - TestUtil.flush(); - - assertTrue( popup.isSeeable() ); - }, - - testSetItems_MakesPopUpNotSeeableIfLengthIsZero : function() { - showDropDown(); - - dropdown.setItems( [] ); - TestUtil.flush(); - - assertFalse( popup.isSeeable() ); - assertTrue( dropdown.getVisible() ); - }, - - testShow_FocusesGrid : function() { - showDropDown(); - - assertTrue( grid.getFocused() ); - }, - - testShow_LeavesParentFocused : function() { - widget.setTabIndex( 1 ); - widget.focus(); - showDropDown(); - - assertFalse( grid.getFocused() ); - assertTrue( widget.getFocused() ); - }, - - testShow_LeavesSiblingFocused : function() { - var focusable = new rwt.widgets.Button( "push" ); - focusable.setParent( widget ); - TestUtil.flush(); - focusable.focus(); - showDropDown(); - - assertFalse( grid.getFocused() ); - assertTrue( focusable.getFocused() ); - }, - - testDoNotHideOnParentClick : function() { - var focusable = new rwt.widgets.Button( "push" ); - focusable.setParent( widget ); - showDropDown(); - - TestUtil.click( focusable ); - forceTimer(); - - assertTrue( popup.isSeeable() ); - }, - - testDoNotHideOnFocusableParentClick : function() { - widget.setTabIndex( 1 ); - widget.contains = rwt.util.Functions.returnFalse; - showDropDown(); - - TestUtil.click( widget ); - forceTimer(); - - assertTrue( popup.isSeeable() ); - }, - - testHideOnShellClick : function() { - showDropDown(); - - TestUtil.click( shell ); - forceTimer(); - - assertFalse( popup.isSeeable() ); - }, - - testHideOnEscape : function() { - showDropDown(); - - TestUtil.press( grid, "Escape" ); - - assertFalse( popup.isSeeable() ); - }, - - testHideOnEnter : function() { - showDropDown(); - dropdown.setItems( [ "a", "b" ] ); - dropdown.setSelectionIndex( 0 ); - - TestUtil.press( grid, "Enter" ); - TestUtil.forceTimerOnce(); - - assertFalse( popup.isSeeable() ); - }, - - testHideOnItemClick : function() { - dropdown.setItems( [ "a", "b" ] ); - showDropDown(); - - clickItem( 1 ); - - assertFalse( popup.isSeeable() ); - }, - - testDoNotHideOnScrollbarClick : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - dropdown.setVisibleItemCount( 2 ); - showDropDown(); - - TestUtil.click( grid.getVerticalBar() ); - - assertTrue( popup.isSeeable() ); - }, - - testShellClickAfterDropDownDisposeDoesNotCrash : function() { - showDropDown(); - dropdown.destroy(); - TestUtil.flush(); - - TestUtil.click( shell ); - forceTimer(); - - assertFalse( popup.isSeeable() ); - }, - - testShellClickAfterWidgetDisposeDoesNotCrash : function() { - widget.focus(); - widget.destroy(); - dropdown.destroy(); - TestUtil.flush(); - - TestUtil.click( shell ); - forceTimer(); - - assertFalse( popup.isSeeable() ); - }, - - testShow_CalledBeforeCreatedMakesPopUpVisible : function() { - dropdown.destroy(); - this.createExample(); - - showDropDown(); - - assertTrue( popup.isSeeable() ); - }, - - testHide_MakesPopUpInvisible : function() { - showDropDown(); - - dropdown.hide(); - TestUtil.flush(); - - assertFalse( popup.isSeeable() ); - }, - - testHide_SendsVisible : function() { - showDropDown(); - - dropdown.hide(); - rwt.remote.Connection.getInstance().send(); - - var message = TestUtil.getMessageObject(); - assertFalse( message.findSetProperty( "w3", "visible" ) ); - }, - - testHide_DoesNotSendVisibleInResponse : function() { - showDropDown(); - TestUtil.clearRequestLog(); - - TestUtil.fakeResponse( true ); - dropdown.hide(); - TestUtil.fakeResponse( false ); - rwt.remote.Connection.getInstance().send(); - - var message = TestUtil.getMessageObject(); - assertNull( message.findSetOperation( "w3", "visible" ) ); - }, - - testHide_DoesNotSendVisibleIfAlreadyInvisible : function() { - dropdown.hide(); - rwt.remote.Connection.getInstance().send(); - - var message = TestUtil.getMessageObject(); - assertNull( message.findSetOperation( "w3", "visible" ) ); - }, - - testShow_PositionsPopUp : function() { - showDropDown(); - - assertEquals( 20, popup.getLeft() ); - assertEquals( 70, popup.getTop() ); - }, - - testShow_PositionsPopUpWhileParentIsInLayoutQueueForTop : function() { - // NOTE: this won't be effective if the text changes position soley because it's parent - // changes position. For this case the popup will re-layout in the appear event (see below), - // but this assumes that it is not visible while the text parent changes position. - widget.setTop( 50 ); - showDropDown(); - - assertEquals( 20, popup.getLeft() ); - assertEquals( 100, popup.getTop() ); - }, - - testShow_PositionsPopUpWhileParentIsInLayoutQueueForLeft : function() { - widget.setLeft( 20 ); - showDropDown(); - - assertEquals( 30, popup.getLeft() ); - assertEquals( 70, popup.getTop() ); - }, - - testShow_PositionsPopUpWhileParentIsInLayoutQueueForHeight : function() { - widget.setHeight( 50 ); - showDropDown(); - - assertEquals( 20, popup.getLeft() ); - assertEquals( 90, popup.getTop() ); - }, - - testShow_LayoutsPopUpWhileParentIsInLayoutQueueForWidth : function() { - widget.setWidth( 150 ); - showDropDown(); - - assertEquals( 150, popup.getWidth() ); - }, - - testShow_LayoutsPopUpWhenParentAppearsAfterShellChangesPosition : function() { - showDropDown(); - dropdown.hide(); - - shell.setTop( 50 ); - dropdown.show(); - TestUtil.flush(); - - assertEquals( 100, popup.getTop() ); - }, - - testShow_LayoutsPopUpOnTopOfParentIfNotEnoughSpace : function() { - var doc = rwt.widgets.base.ClientDocument.getInstance(); - doc.getInnerHeight = function() { return 100; }; - - shell.setTop( 40 ); - showDropDown(); - - assertEquals( 33, popup.getTop() ); - delete doc.getInnerHeight; - }, - - testShow_SendsVisible : function() { - showDropDown(); - rwt.remote.Connection.getInstance().send(); - - var message = TestUtil.getMessageObject(); - assertTrue( message.findSetProperty( "w3", "visible" ) ); - }, - - testShow_DoesNotSendVisibleInResponse : function() { - TestUtil.fakeResponse( true ); - showDropDown(); - TestUtil.fakeResponse( false ); - rwt.remote.Connection.getInstance().send(); - - var message = TestUtil.getMessageObject(); - assertNull( message.findSetOperation( "w3", "visible" ) ); - }, - - testShow_DoesNotSendVisibleIfAlreadyVisible : function() { - showDropDown(); - TestUtil.clearRequestLog(); - - dropdown.show(); - rwt.remote.Connection.getInstance().send(); - - var message = TestUtil.getMessageObject(); - assertNull( message.findSetOperation( "w3", "visible" ) ); - }, - - testShow_SetsPopUpWidth : function() { - showDropDown(); - - assertEquals( 100, popup.getWidth() ); - }, - - testShow_PopUpInnerHeightOverVisibleItemCount : function() { - var items = [ "a", "b", "c", "d", "a", "b", "c", "d", "a", "b", "c", "d", "a", "b", "c" ]; - dropdown.setItems( items ); - dropdown.setVisibleItemCount( 7 ); - showDropDown(); - - assertEquals( 7 * ITEM_HEIGHT, popup.getInnerHeight() ); - }, - - testShow_PopUpInnerHeightUnderVisibleItemCount : function() { - var items = [ "a", "b" ]; - dropdown.setItems( items ); - dropdown.setVisibleItemCount( 7 ); - showDropDown(); - - assertEquals( 2 * ITEM_HEIGHT, popup.getInnerHeight() ); - }, - - testSetVisibleItemCount_UpdatesScrollbar : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - - dropdown.setVisibleItemCount( 2 ); - - assertTrue( grid.getVerticalBar().getDisplay() ); - }, - - testSetVisibleItemCount_RendersLayout : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - dropdown.setVisibleItemCount( 3 ); - showDropDown(); - - dropdown.setVisibleItemCount( 2 ); - TestUtil.flush(); - - assertEquals( 2 * ITEM_HEIGHT, popup.getInnerHeight() ); - assertEquals( 2 * ITEM_HEIGHT, grid.getHeight() ); - }, - - testSetItems_UpdatesScrollbar : function() { - dropdown.setVisibleItemCount( 2 ); - - dropdown.setItems( [ "a", "b", "c" ] ); - - assertTrue( grid.getVerticalBar().getDisplay() ); - }, - - testSetItems_RendersLayout : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - dropdown.setVisibleItemCount( 3 ); - showDropDown(); - - dropdown.setItems( [ "a", "b" ] ); - TestUtil.flush(); - - assertEquals( 2 * ITEM_HEIGHT, popup.getInnerHeight() ); - assertEquals( 2 * ITEM_HEIGHT, grid.getHeight() ); - }, - - testShow_LayoutsGrid : function() { - showDropDown(); - - assertEquals( popup.getInnerWidth(), grid.getWidth() ); - assertEquals( popup.getInnerHeight(), grid.getHeight() ); - }, - - testShow_setsItemMetrics: function() { - showDropDown(); - - var config = grid.getRenderConfig(); - assertEquals( 0, config.itemLeft[ 0 ] ); - assertEquals( grid.getWidth(), config.itemWidth[ 0 ] ); - assertEquals( PADDING_LEFT, config.itemTextLeft[ 0 ] ); - assertEquals( grid.getWidth() - PADDING_RIGHT - PADDING_LEFT, config.itemTextWidth[ 0 ] ); - }, - - testShow_SetsGridFont : function() { - var font = rwt.html.Font.fromString( "Arial 12px" ); - shell.setFont( font ); - widget.setFont( "inherit" ); - showDropDown(); - - assertIdentical( font, grid.getFont() ); - }, - - testShow_SetsItemHeightFor10pxFont : function() { - var font = rwt.html.Font.fromString( "Arial 10px" ); - widget.setFont( font ); - showDropDown(); - - assertEquals( 6 + 6 + 13, grid._itemHeight ); - }, - - testShow_SetsItemHeightFor12pxFont : function() { - var font = rwt.html.Font.fromString( "Arial 12px" ); - widget.setFont( font ); - showDropDown(); - - assertEquals( 6 + 6 + 15, grid._itemHeight ); - }, - - testSetItems_SetsItemsOnGrid : function() { - showDropDown(); - - dropdown.setItems( [ "a", "b", "c" ] ); - - assertEquals( [ "a", "b", "c" ], getGridItems() ); - }, - - testSetColumns_setsColumnCount : function() { - dropdown.setColumns( [ 30, 40 ] ); - - var config = grid.getRenderConfig(); - assertEquals( 2, config.columnCount ); - }, - - testSetColumns_setsItemMetrics : function() { - dropdown.setColumns( [ 30, 40 ] ); - showDropDown(); - - var config = grid.getRenderConfig(); - assertEquals( 0, config.itemLeft[ 0 ] ); - assertEquals( 30, config.itemWidth[ 0 ] ); - assertEquals( 30, config.itemLeft[ 1 ] ); - assertEquals( 40, config.itemWidth[ 1 ] ); - assertEquals( PADDING_LEFT, config.itemTextLeft[ 0 ] ); - assertEquals( 30 - PADDING_RIGHT - PADDING_LEFT, config.itemTextWidth[ 0 ] ); - assertEquals( 30 + PADDING_LEFT, config.itemTextLeft[ 1 ] ); - assertEquals( 40 - PADDING_RIGHT - PADDING_LEFT, config.itemTextWidth[ 1 ] ); - }, - - testSetColumns_setsPopUpWidth : function() { - dropdown.setColumns( [ 100, 200, 100 ] ); - showDropDown(); - - assertEquals( 400, popup.getInnerWidth() ); - }, - - testSetColumns_setsPopUpWidthAfterAppear : function() { - showDropDown(); - dropdown.setColumns( [ 100, 200, 100 ] ); - TestUtil.flush(); - - assertEquals( 400, popup.getInnerWidth() ); - }, - - testSetColumns_setsPopUpWidthAfterParentAppear : function() { - widget.destroy(); - dropdown.destroy(); - this.createExample(); - dropdown.show(); - dropdown.setColumns( [ 100, 200, 100 ] ); - TestUtil.flush(); - - assertEquals( 400, popup.getInnerWidth() ); - }, - - testSetColumns_setsDoesNotSetPopUpWidthIfSmaller : function() { - dropdown.setColumns( [ 30 ] ); - showDropDown(); - - assertEquals( 100, popup.getWidth() ); - }, - - testSetColumns_separatesItemsByTabulator : function() { - dropdown.setColumns( [ 30, 40 ] ); - var tab = String.fromCharCode( 9 ); - - dropdown.setItems( [ "foo" + tab + "bar" ] ); - showDropDown(); - - var gridItem = grid.getRootItem().getChild( 0 ); - assertEquals( "foo", gridItem.getText( 0 ) ); - assertEquals( "bar", gridItem.getText( 1 ) ); - }, - - testGetItemCount : function() { - showDropDown(); - - dropdown.setItems( [ "a", "b", "c" ] ); - - assertEquals( 3, dropdown.getItemCount() ); - }, - - testGetVisible_returnsFalse : function() { - assertFalse( dropdown.getVisible() ); - }, - - testGetVisible_returnsTrue : function() { - showDropDown(); - assertTrue( dropdown.getVisible() ); - }, - - testAddSelectionListener : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - showDropDown(); - var logger = TestUtil.getLogger(); - - dropdown.addListener( "Selection", logger.log ); - dropdown.setSelectionIndex( 1 ); - - assertEquals( 1, logger.getLog().length ); - }, - - testAddShowListener : function() { - var logger = TestUtil.getLogger(); - dropdown.addListener( "Show", logger.log ); - - showDropDown(); - - assertEquals( 1, logger.getLog().length ); - }, - - testAddShowListener_notifiesEventForEmptyItems : function() { - var logger = TestUtil.getLogger(); - dropdown.addListener( "Show", logger.log ); - - showDropDown( [] ); - - assertEquals( 1, logger.getLog().length ); - }, - - testRemoveShowListener : function() { - var logger = TestUtil.getLogger(); - dropdown.addListener( "Show", logger.log ); - dropdown.removeListener( "Show", logger.log ); - - showDropDown(); - - assertEquals( 0, logger.getLog().length ); - }, - - testAddHideListener : function() { - showDropDown(); - var logger = TestUtil.getLogger(); - dropdown.addListener( "Hide", logger.log ); - - dropdown.hide(); - - assertEquals( 1, logger.getLog().length ); - }, - - testAddHideListener_notifiesEventForEmptyItems : function() { - showDropDown( [] ); - var logger = TestUtil.getLogger(); - dropdown.addListener( "Hide", logger.log ); - - dropdown.hide(); - - assertEquals( 1, logger.getLog().length ); - }, - - testRemoveHideListener : function() { - showDropDown(); - var logger = TestUtil.getLogger(); - dropdown.addListener( "Hide", logger.log ); - dropdown.removeListener( "Hide", logger.log ); - - dropdown.hide(); - - assertEquals( 0, logger.getLog().length ); - }, - - testRemoveSelectionListener : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - showDropDown(); - var logger = TestUtil.getLogger(); - - dropdown.addListener( "Selection", logger.log ); - dropdown.removeListener( "Selection", logger.log ); - TestUtil.click( getItem( 0 ) ); - - assertEquals( 0, logger.getLog().length ); - }, - - testSelectionEventFields : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - showDropDown(); - var logger = TestUtil.getLogger(); - - dropdown.addListener( "Selection", logger.log ); - dropdown.setSelectionIndex( 1 ); - - var event = logger.getLog()[ 0 ]; - assertIdentical( dropdown, event.widget ); - assertIdentical( "b", event.text ); - assertIdentical( 1, event.index ); - assertIdentical( SWT.Selection, event.type ); - }, - - testSelectionEventFields_Unescaped : function() { - dropdown.setItems( [ "a", "&bb ", "c" ] ); // the *trailing* space is important - showDropDown(); - var logger = TestUtil.getLogger(); - - dropdown.addListener( "Selection", logger.log ); - clickItem( 1 ); - - var event = logger.getLog()[ 0 ]; - assertIdentical( "&bb ", event.text ); - }, - - testSelectionEventFields_NoItemSelected : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - showDropDown(); - dropdown.setSelectionIndex( 1 ); - var logger = TestUtil.getLogger(); - - dropdown.addListener( "Selection", logger.log ); - dropdown.setSelectionIndex( -1 ); - - var event = logger.getLog()[ 0 ]; - assertIdentical( dropdown, event.widget ); - assertEquals( "", event.text ); - }, - - testSelectionEventNotify_NoItemSelected : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - showDropDown(); - dropdown.setSelectionIndex( 1 ); - - TestUtil.protocolListen( "w3", { "Selection" : true } ); - dropdown.setSelectionIndex( -1 ); - - var message = TestUtil.getMessageObject(); - assertEquals( "", message.findNotifyProperty( "w3", "Selection", "text" ) ); - assertEquals( -1, message.findNotifyProperty( "w3", "Selection", "index" ) ); - }, - - testSelectionEventNotify : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - showDropDown(); - - TestUtil.protocolListen( "w3", { "Selection" : true } ); - dropdown.setSelectionIndex( 1 ); - - var message = TestUtil.getMessageObject(); - assertEquals( "b", message.findNotifyProperty( "w3", "Selection", "text" ) ); - assertEquals( 1, message.findNotifyProperty( "w3", "Selection", "index" ) ); - }, - - testAddDefaultSelectionListener_FiresOnEnter : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - showDropDown(); - var logger = TestUtil.getLogger(); - - dropdown.addListener( "DefaultSelection", logger.log ); - dropdown.setSelectionIndex( 1 ); - TestUtil.pressOnce( grid, "Enter" ); - TestUtil.forceTimerOnce(); - - assertEquals( 1, logger.getLog().length ); - }, - - testAddDefaultSelectionListener_FiresOnClick : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - showDropDown(); - var logger = TestUtil.getLogger(); - - dropdown.addListener( "DefaultSelection", logger.log ); - clickItem( 1 ); - TestUtil.forceTimerOnce(); - - assertEquals( 1, logger.getLog().length ); - }, - - testAddDefaultSelectionListener_FiresOnTextEnter : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - showDropDown(); - var logger = TestUtil.getLogger(); - - dropdown.addListener( "DefaultSelection", logger.log ); - dropdown.setSelectionIndex( 1 ); - widget.focus(); - TestUtil.pressOnce( widget, "Enter" ); - TestUtil.forceTimerOnce(); - - assertEquals( 1, logger.getLog().length ); - }, - - testAddDefaultSelectionListener_HidesNotOnTextEnterWithoutSelection : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - showDropDown(); - var logger = TestUtil.getLogger(); - - dropdown.addListener( "DefaultSelection", logger.log ); - widget.focus(); - TestUtil.pressOnce( widget, "Enter" ); - TestUtil.forceTimerOnce(); - - assertTrue( dropdown.getVisible() ); - }, - - testDefaultSelectionEventFields : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - showDropDown(); - var logger = TestUtil.getLogger(); - - dropdown.addListener( "DefaultSelection", logger.log ); - clickItem( 1 ); - TestUtil.pressOnce( grid, "Enter" ); - TestUtil.forceTimerOnce(); - - var event = logger.getLog()[ 0 ]; - assertIdentical( dropdown, event.widget ); - assertIdentical( "b", event.text ); - assertIdentical( 1, event.index ); - assertIdentical( SWT.DefaultSelection, event.type ); - }, - - testGetSelectionIndex_InitialValueIsMinusOne : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - - assertEquals( -1, dropdown.getSelectionIndex() ); - }, - - testGetSelectionIndex_ValueIsMinusOneForNoItems : function() { - assertEquals( -1, dropdown.getSelectionIndex() ); - }, - - testGetSelectionIndex_ValueAfterSelection : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - showDropDown(); - - clickItem( 1 ); - - assertEquals( 1, dropdown.getSelectionIndex() ); - }, - - testSetSelectionIndex : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - - dropdown.setSelectionIndex( 1 ); - - assertEquals( 1, dropdown.getSelectionIndex() ); - }, - - testSetSelectionIndex_ScrollToSelection : function() { - dropdown.setVisibleItemCount( 3 ); - showDropDown(); - dropdown.setItems( [ "a", "b", "c", "d", "e", "f" ] ); - - dropdown.setSelectionIndex( 5 ); - - assertEquals( 3, grid.getTopItemIndex() ); - }, - - - testSetSelectionIndex_DoesNotFireEventIfValueIsUnchanged : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - showDropDown(); - var logger = TestUtil.getLogger(); - - dropdown.addListener( "Selection", logger.log ); - dropdown.setSelectionIndex( 1 ); - dropdown.setSelectionIndex( 1 ); - - assertEquals( 1, logger.getLog().length ); - }, - - testResetSelectionIndex_ResetScrollPosition : function() { - dropdown.setVisibleItemCount( 3 ); - showDropDown(); - dropdown.setItems( [ "a", "b", "c", "d", "e", "f" ] ); - dropdown.setSelectionIndex( 5 ); - - dropdown.setSelectionIndex( -1 ); - - assertEquals( 0, grid.getTopItemIndex() ); - }, - - testSetItems_ResetsSelection : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - dropdown.setSelectionIndex( 1 ); - dropdown.setItems( [ "a", "b", "d" ] ); - - assertEquals( -1, dropdown.getSelectionIndex() ); - }, - - testSetSelectionIndex_RemoteSet : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - - dropdown.setSelectionIndex( 1 ); - rwt.remote.Connection.getInstance().send(); - - var message = TestUtil.getMessageObject(); - assertEquals( 1, message.findSetProperty( "w3", "selectionIndex" ) ); - }, - - testSetItemsFromServerDoesNotRemoteSetIndex : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - dropdown.setSelectionIndex( 1 ); - TestUtil.clearRequestLog(); - - TestUtil.fakeResponse( true ); - dropdown.setItems( [ "a", "b", "c" ] ); - TestUtil.fakeResponse( false ); - rwt.remote.Connection.getInstance().send(); - - var message = TestUtil.getMessageObject(); - assertNull( message.findSetOperation( "w3", "selectionIndex" ) ); - }, - - testSetSelectionIndex_ValueIsMinusOne : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - - dropdown.setSelectionIndex( -1 ); - - assertEquals( -1, dropdown.getSelectionIndex() ); - }, - - testSetSelectionIndex_ValueOutOfBoundsThrowsException : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - - try { - dropdown.setSelectionIndex( 4 ); - fail(); - } catch( ex ) { - // expected - } - }, - - testKeyEventForwarding_Escape : function() { - showDropDown(); - var logger = TestUtil.getLogger(); - - grid.addEventListener( "keypress", logger.log ); - widget.focus(); - TestUtil.pressOnce( widget, "Escape" ); - - assertEquals( 1, logger.getLog().length ); - assertTrue( logger.getLog()[ 0 ].getDefaultPrevented() ); - }, - - testKeyEventForwarding_Up : function() { - showDropDown( [ "a", "b" ] ); - dropdown.setSelectionIndex( 1 ); - var logger = TestUtil.getLogger(); - - grid.addEventListener( "keypress", logger.log ); - widget.focus(); - TestUtil.pressOnce( widget, "Up" ); - - assertEquals( 1, logger.getLog().length ); - assertTrue( logger.getLog()[ 0 ].getDefaultPrevented() ); - }, - - testKeyEventForwarding_UpNotVisible : function() { - var logger = TestUtil.getLogger(); - - grid.addEventListener( "keypress", logger.log ); - widget.focus(); - TestUtil.pressOnce( widget, "Up" ); - - assertEquals( 0, logger.getLog().length ); - }, - - testKeyEventForwarding_Down : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - dropdown.setSelectionIndex( 1 ); - showDropDown(); - var logger = TestUtil.getLogger(); - - grid.addEventListener( "keypress", logger.log ); - widget.focus(); - TestUtil.pressOnce( widget, "Down" ); - - assertEquals( 1, logger.getLog().length ); - assertTrue( logger.getLog()[ 0 ].getDefaultPrevented() ); - }, - - testKeyEventForwarding_PageUp : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - dropdown.setSelectionIndex( 1 ); - showDropDown(); - var logger = TestUtil.getLogger(); - - grid.addEventListener( "keypress", logger.log ); - widget.focus(); - TestUtil.pressOnce( widget, "PageUp" ); - - assertEquals( 1, logger.getLog().length ); - assertTrue( logger.getLog()[ 0 ].getDefaultPrevented() ); - }, - - testKeyEventForwarding_PageDown : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - dropdown.setSelectionIndex( 1 ); - showDropDown(); - var logger = TestUtil.getLogger(); - - grid.addEventListener( "keypress", logger.log ); - widget.focus(); - TestUtil.pressOnce( widget, "PageDown" ); - - assertEquals( 1, logger.getLog().length ); - assertTrue( logger.getLog()[ 0 ].getDefaultPrevented() ); - }, - - testPressDownAfterSelectionResetSelectsFirstItem : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - dropdown.setSelectionIndex( 1 ); - showDropDown(); - dropdown.setSelectionIndex( -1 ); - TestUtil.flush(); - - widget.focus(); - TestUtil.pressOnce( widget, "Down" ); - - assertEquals( 0, dropdown.getSelectionIndex() ); - }, - - testPressDownAfterSelectionResetFocusesFirstItem : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - dropdown.setSelectionIndex( 1 ); - showDropDown(); - dropdown.setSelectionIndex( -1 ); - TestUtil.flush(); - - widget.focus(); - TestUtil.pressOnce( widget, "Down" ); - - assertTrue( grid.isFocusItem( grid.getRootItem().getChild( 0 ) ) ); - }, - - testPressUpAfterSelectionResetsSelectsLastItem : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - showDropDown(); - dropdown.setSelectionIndex( -1 ); - TestUtil.flush(); - - widget.focus(); - TestUtil.pressOnce( widget, "Up" ); - - assertEquals( 2, dropdown.getSelectionIndex() ); - }, - - testPressUpAfterSelectionFirstItemResetsFocus : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - showDropDown(); - TestUtil.flush(); - - widget.focus(); - TestUtil.pressOnce( widget, "Down" ); - TestUtil.pressOnce( widget, "Up" ); - - assertFalse( grid.isFocusItem( grid.getRootItem().getChild( 0 ) ) ); - }, - - testPressUpOnFirstItemResetsSelection : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - dropdown.setSelectionIndex( 0 ); - showDropDown(); - TestUtil.flush(); - - widget.focus(); - TestUtil.pressOnce( widget, "Up" ); - - assertEquals( -1, dropdown.getSelectionIndex() ); - }, - - testPressDownOnLastItemResetsSelection : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - dropdown.setSelectionIndex( 2 ); - showDropDown(); - TestUtil.flush(); - - widget.focus(); - TestUtil.pressOnce( widget, "Down" ); - - assertEquals( -1, dropdown.getSelectionIndex() ); - }, - - testSelectionResetResetsLeadItem : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - showDropDown(); - widget.focus(); - TestUtil.pressOnce( widget, "Down" );// calling setSelectionIndex would not change lead item - - dropdown.setSelectionIndex( -1 ); - TestUtil.pressOnce( widget, "Down" ); - - assertEquals( 0, dropdown.getSelectionIndex() ); - }, - - testPressDownAfterItemResetSelectsFirstItem : function() { - dropdown.setItems( [ "a", "b", "c" ] ); - showDropDown(); - dropdown.setSelectionIndex( 2 ); - - dropdown.setItems( [ "x", "y" ] ); - TestUtil.flush(); - - widget.focus(); - TestUtil.pressOnce( widget, "Down" ); - - assertEquals( 0, dropdown.getSelectionIndex() ); - }, - - testDestroy_DisposesDropDown : function() { - dropdown.destroy(); - - assertTrue( dropdown.isDisposed() ); - }, - - testDestroy_AfterControlDispose : function() { - widget.destroy(); - dropdown.destroy(); - - assertTrue( dropdown.isDisposed() ); - }, - - testDestroy_DisposesPopup : function() { - dropdown.destroy(); - TestUtil.flush(); - - assertTrue( popup.isDisposed() ); - }, - - testDestroy_ClearsReferences : function() { - dropdown.setData( "foo", {} ); - var privateObj = dropdown._; - var props = privateObj.widgetData; - dropdown.destroy(); - - assertTrue( TestUtil.hasNoObjects( dropdown, true ) ); - assertTrue( TestUtil.hasNoObjects( privateObj ) ); - assertTrue( TestUtil.hasNoObjects( props ) ); - }, - - testDestroy_DeregistersAppearListener : function() { - widget.setVisibility( false ); - - dropdown.destroy(); - widget.setVisibility( true ); - // Succeeds by not crashing - }, - - testDestroy_DeregistersFlushListener : function() { - dropdown.destroy(); - widget.setTop( 45 ); - TestUtil.flush(); - // Succeeds by not crashing - }, - - testDestroy_RemoveListenerDoesNotCrash : function() { - var listener = function(){}; - dropdown.addListener( "Selection", listener ); - dropdown.destroy(); - - dropdown.removeListener( "Selection", listener ); - }, - - testDestroy_DocumentClick : function() { - showDropDown(); - dropdown.destroy(); - TestUtil.click( TestUtil.getDocument() ); - - assertFalse( popup.isSeeable() ); - }, - - /////////// - // Helper - - createExample : function() { - widget = new rwt.widgets.Composite(); - widget.setFont( rwt.html.Font.fromString( "Arial 10px" ) ); - widget.setParent( shell ); - widget.setLocation( 10, 20 ); - widget.setDimension( 100, 30 ); - dropdown = new rwt.dropdown.DropDown( widget ); - rwt.remote.ObjectRegistry.add( - "w3", - dropdown, - rwt.remote.HandlerRegistry.getHandler( "rwt.dropdown.DropDown" ) - ); - popup = dropdown._.popup; - grid = dropdown._.grid; - hideTimer = dropdown._.hideTimer; - } - - } - -} ); - -var showDropDown = function( items ) { - if( items ) { - dropdown.setItems( items ); - } else if( dropdown.getItemCount() === 0 ) { - dropdown.setItems( [ "a" ] ); - } - dropdown.show(); - TestUtil.flush(); - TestUtil.flush(); -}; - -var getGridItems = function() { - var result = []; - var items = grid.getRootItem()._children; - for( var i = 0; i < items.length; i++ ) { - result[ i ] = items[ i ].getText( 0 ); - } - return result; -}; - -var clickItem = function( index ) { - TestUtil.click( getItem( index ) ); -}; - -var doubleClickItem = function( index ) { - TestUtil.doubleClick( getItem( index ) ); -}; - -var getItem = function( index ) { - return grid.getRowContainer()._findRowByItem( grid.getRootItem().getChild( index ) ); -}; - -var forceTimer = function() { - TestUtil.forceInterval( hideTimer ); -}; - - -}()); diff --git a/tests/org.eclipse.rap.addons.dropdown.test/src/org/eclipse/rap/addons/dropdown/DropDown_Test.java b/tests/org.eclipse.rap.addons.dropdown.test/src/org/eclipse/rap/addons/dropdown/DropDown_Test.java index b7764e7..96e2af7 100644 --- a/tests/org.eclipse.rap.addons.dropdown.test/src/org/eclipse/rap/addons/dropdown/DropDown_Test.java +++ b/tests/org.eclipse.rap.addons.dropdown.test/src/org/eclipse/rap/addons/dropdown/DropDown_Test.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 EclipseSource. + * Copyright (c) 2013, 2014 EclipseSource. * 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 @@ -56,7 +56,9 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -@SuppressWarnings("restriction") +@SuppressWarnings({ + "restriction", "deprecation" +}) public class DropDown_Test { private Text text; @@ -359,7 +361,7 @@ public class DropDown_Test { WidgetUtil.registerDataKeys( "foo", "bar" ); dropdown.setData( "foo", "bar" ); - verify( remoteObject ).call( eq( "setData" ), eq( new JsonObject().add( "foo", "bar" ) ) ); + verify( remoteObject ).set( eq( "data" ), eq( new JsonObject().add( "foo", "bar" ) ) ); } @Test diff --git a/tests/org.eclipse.rap.addons.dropdown.test/src/org/eclipse/rap/addons/dropdown/test/internal/DropDownResourcesContribution.java b/tests/org.eclipse.rap.addons.dropdown.test/src/org/eclipse/rap/addons/dropdown/test/internal/DropDownResourcesContribution.java deleted file mode 100644 index 4f8c0a9..0000000 --- a/tests/org.eclipse.rap.addons.dropdown.test/src/org/eclipse/rap/addons/dropdown/test/internal/DropDownResourcesContribution.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * EclipseSource - initial API and implementation - ******************************************************************************/ -package org.eclipse.rap.addons.dropdown.test.internal; - -import java.io.IOException; -import java.io.InputStream; - -import org.eclipse.rap.addons.dropdown.internal.resources.DropDownResources; -import org.eclipse.rap.rwt.jstest.TestContribution; - - -@SuppressWarnings( "restriction" ) -public class DropDownResourcesContribution implements TestContribution { - - public String getName() { - return "dropdown-resources"; - } - - public String[] getResources() { - return DropDownResources.SCRIPTS; - } - - public InputStream getResourceAsStream( String resourceName ) throws IOException { - return DropDownResources.getResourceAsStream( resourceName ); - } - -} diff --git a/tests/org.eclipse.rap.addons.dropdown.test/src/org/eclipse/rap/addons/dropdown/test/internal/DropDownTestContribution.java b/tests/org.eclipse.rap.addons.dropdown.test/src/org/eclipse/rap/addons/dropdown/test/internal/DropDownTestContribution.java deleted file mode 100644 index 7e36e31..0000000 --- a/tests/org.eclipse.rap.addons.dropdown.test/src/org/eclipse/rap/addons/dropdown/test/internal/DropDownTestContribution.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * EclipseSource - initial API and implementation - ******************************************************************************/ - -package org.eclipse.rap.addons.dropdown.test.internal; - -import java.io.IOException; -import java.io.InputStream; - -import org.eclipse.rap.rwt.jstest.TestContribution; - - -public class DropDownTestContribution implements TestContribution { - - private static final ClassLoader CLASSLOADER = DropDownTestContribution.class.getClassLoader(); - - private static final String[] ALL_TEST_RESOURCES = new String[] { - "/rwt/dropdown/DropDown_Test.js" - }; - - public String getName() { - return "dropdown-tests"; - } - - public String[] getResources() { - return ALL_TEST_RESOURCES; - } - - public InputStream getResourceAsStream( String resourceName ) throws IOException { - return CLASSLOADER.getResourceAsStream( resourceName ); - } - -} |