Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Buschtöns2013-07-24 14:39:11 +0000
committerTim Buschtöns2013-07-24 14:39:11 +0000
commitb394ff30dafe3c565ce760be4826f59a4744f8d3 (patch)
treeb664fe8b84b3b99ad2c4b929aca1ff41f97f4da5
parent83b68e593c86ab827e16ac6c3952c22c72da5faf (diff)
downloadorg.eclipse.rap.incubator.dropdown-b394ff30dafe3c565ce760be4826f59a4744f8d3.tar.gz
org.eclipse.rap.incubator.dropdown-b394ff30dafe3c565ce760be4826f59a4744f8d3.tar.xz
org.eclipse.rap.incubator.dropdown-b394ff30dafe3c565ce760be4826f59a4744f8d3.zip
Remove deprecated property elementSelection in AutoSuggest client model
Fires suggestionSelected instead
-rw-r--r--bundles/org.eclipse.rap.addons.autosuggest/src/org/eclipse/rap/addons/autosuggest/AutoSuggest.java2
-rw-r--r--bundles/org.eclipse.rap.addons.autosuggest/src/org/eclipse/rap/addons/autosuggest/internal/resources/AutoSuggest.js10
-rw-r--r--tests/org.eclipse.rap.addons.autosuggest.test/jasmine/jasmine/specs/AutoSuggestSpec.js42
-rw-r--r--tests/org.eclipse.rap.addons.autosuggest.test/src/org/eclipse/rap/addons/autosuggest/AutoSuggest_Test.java11
4 files changed, 20 insertions, 45 deletions
diff --git a/bundles/org.eclipse.rap.addons.autosuggest/src/org/eclipse/rap/addons/autosuggest/AutoSuggest.java b/bundles/org.eclipse.rap.addons.autosuggest/src/org/eclipse/rap/addons/autosuggest/AutoSuggest.java
index cdde05d..506ce13 100644
--- a/bundles/org.eclipse.rap.addons.autosuggest/src/org/eclipse/rap/addons/autosuggest/AutoSuggest.java
+++ b/bundles/org.eclipse.rap.addons.autosuggest/src/org/eclipse/rap/addons/autosuggest/AutoSuggest.java
@@ -31,7 +31,7 @@ import org.eclipse.swt.widgets.Text;
public class AutoSuggest {
- private static final String EVENT_TYPE_SELECTION = "change:elementSelection";
+ private static final String EVENT_TYPE_SELECTION = "suggestionSelected";
private final static String LISTENER_PREFIX
= "org/eclipse/rap/addons/autosuggest/internal/resources/";
private static final String MODEL_ID_KEY
diff --git a/bundles/org.eclipse.rap.addons.autosuggest/src/org/eclipse/rap/addons/autosuggest/internal/resources/AutoSuggest.js b/bundles/org.eclipse.rap.addons.autosuggest/src/org/eclipse/rap/addons/autosuggest/internal/resources/AutoSuggest.js
index cf8be3b..1b60f8b 100644
--- a/bundles/org.eclipse.rap.addons.autosuggest/src/org/eclipse/rap/addons/autosuggest/internal/resources/AutoSuggest.js
+++ b/bundles/org.eclipse.rap.addons.autosuggest/src/org/eclipse/rap/addons/autosuggest/internal/resources/AutoSuggest.js
@@ -49,7 +49,6 @@ function onChangeDataSourceId( event ) {
}
function onChangeSuggestions( event ) {
- this.set( "elementSelection", -1, { "nosync" : true } );
// NOTE: Nothing else to do if not visible, but would need to update when it becomes visible.
// Currently only onChangeUserText can set resultsVisible to true, which updates implicitly.
if( this.get( "suggestionsVisible" ) ) {
@@ -102,11 +101,10 @@ function onAcceptSuggestion( event ) {
var results = this.get( "currentSuggestions" );
if( results ) {
var index = this.get( "selectedSuggestionIndex" );
- if( typeof index === "number" && index > -1 ) {
- this.set( "elementSelection", results.indicies[ index ] );
- this.set( "suggestionsVisible", false );
- } else if( this.get( "autoComplete" ) && results.indicies.length === 1 ) {
- this.set( "elementSelection", results.indicies[ 0 ] );
+ var suggestionSelected = typeof index === "number" && index > -1;
+ var autoCompleteAccepted = this.get( "autoComplete" ) && results.indicies.length === 1;
+ if( suggestionSelected || autoCompleteAccepted ) {
+ this.notify( "suggestionSelected" );
this.set( "suggestionsVisible", false );
}
}
diff --git a/tests/org.eclipse.rap.addons.autosuggest.test/jasmine/jasmine/specs/AutoSuggestSpec.js b/tests/org.eclipse.rap.addons.autosuggest.test/jasmine/jasmine/specs/AutoSuggestSpec.js
index c388590..f8059b9 100644
--- a/tests/org.eclipse.rap.addons.autosuggest.test/jasmine/jasmine/specs/AutoSuggestSpec.js
+++ b/tests/org.eclipse.rap.addons.autosuggest.test/jasmine/jasmine/specs/AutoSuggestSpec.js
@@ -288,17 +288,6 @@
expect( model.get( "replacementText" ) ).toBeNull();
} );
- it( "clears elementSelection with nosync", function() {
- model.addListener( "change:suggestions", createClientListener( "AutoSuggest" ) );
- model.set( "elementSelection", 1 );
- model.addListener( "change:elementSelection", logger );
-
- model.set( "suggestions", [ "foo" ] );
-
- expect( model.get( "elementSelection" ) ).toBe( -1 );
- expect( log[ 0 ][ 0 ].options.nosync ).toBe( true );
- } );
-
it( "updates suggestions", function() {
model.addListener( "change:suggestions", createClientListener( "AutoSuggest" ) );
model.set( "userText", "ba" );
@@ -493,54 +482,41 @@
describe( "accept", function() {
- it( "sets elementSelection for selectedSuggestionIndex", function() {
+ it( "fires suggestionSelected for selectedSuggestionIndex", function() {
model.addListener( "accept", createClientListener( "AutoSuggest" ) );
model.set( "currentSuggestions", { "items" : [ "bar", "banana" ], "indicies" : [ 1, 3 ] } );
model.set( "selectedSuggestionIndex", 1 );
+ model.addListener( "suggestionSelected", logger );
model.notify( "accept", { source : model, type : "accept" } );
- expect( model.get( "elementSelection" ) ).toBe( 3 );
+ expect( log.length ).toBe( 1 );
expect( model.get( "suggestionsVisible" ) ).toBe( false );
} );
- it( "sets elementSelection for single currentSuggestion and autoComplete", function() {
+ it( "fires suggestionSelected when full auto complete is accepted", function() {
model.addListener( "accept", createClientListener( "AutoSuggest" ) );
model.set( "currentSuggestions", { "items" : [ "banana" ], "indicies" : [ 3 ] } );
model.set( "selectedSuggestionIndex", -1 );
model.set( "autoComplete", true );
+ model.addListener( "suggestionSelected", logger );
model.notify( "accept", { source : model, type : "accept" } );
- expect( model.get( "elementSelection" ) ).toBe( 3 );
+ expect( log.length ).toBe( 1 );
expect( model.get( "suggestionsVisible" ) ).toBe( false );
} );
- it( "does nothing for single currentSuggestion without autoComplete", function() {
+ it( "does nothing when attempting accepting without selected suggestion or auto complete", function() {
model.addListener( "accept", createClientListener( "AutoSuggest" ) );
model.set( "currentSuggestions", { "items" : [ "banana" ], "indicies" : [ 3 ] } );
model.set( "selectedSuggestionIndex", -1 );
- model.set( "elementSelection", 0 );
model.set( "suggestionsVisible", true );
-
+ model.addListener( "suggestionSelected", logger );
model.notify( "accept", { source : model, type : "accept" } );
- expect( model.get( "elementSelection" ) ).toBe( 0 );
- expect( model.get( "suggestionsVisible" ) ).toBe( true );
- } );
-
- it( "does nothing for multiple result without selectedSuggestionIndex", function() {
- model.addListener( "accept", createClientListener( "AutoSuggest" ) );
- model.set( "currentSuggestions", { "items" : [ "banana", "banu" ], "indicies" : [ 3 ] } );
- model.set( "selectedSuggestionIndex", -1 );
- model.set( "elementSelection", 0 );
- model.set( "suggestionsVisible", true );
-
-
- model.notify( "accept", { source : model, type : "accept" } );
-
- expect( model.get( "elementSelection" ) ).toBe( 0 );
+ expect( log.length ).toBe( 0 );
expect( model.get( "suggestionsVisible" ) ).toBe( true );
} );
diff --git a/tests/org.eclipse.rap.addons.autosuggest.test/src/org/eclipse/rap/addons/autosuggest/AutoSuggest_Test.java b/tests/org.eclipse.rap.addons.autosuggest.test/src/org/eclipse/rap/addons/autosuggest/AutoSuggest_Test.java
index 961ce26..5bc3c92 100644
--- a/tests/org.eclipse.rap.addons.autosuggest.test/src/org/eclipse/rap/addons/autosuggest/AutoSuggest_Test.java
+++ b/tests/org.eclipse.rap.addons.autosuggest.test/src/org/eclipse/rap/addons/autosuggest/AutoSuggest_Test.java
@@ -54,6 +54,7 @@ import org.mockito.stubbing.Answer;
@SuppressWarnings( "restriction" )
public class AutoSuggest_Test {
+ private static final String REMOTE_SELECTION_EVENT = "suggestionSelected";
private static final String REMOTE_TYPE = "rwt.remote.Model";
private static final String MODEL_ID_KEY = "org.eclipse.rap.addons.autosuggest#Model";
@@ -377,7 +378,7 @@ public class AutoSuggest_Test {
autoSuggest.addSelectionListener( mock( SuggestionSelectedListener.class ) );
- verify( remoteObject ).listen( "change:elementSelection", true );
+ verify( remoteObject ).listen( REMOTE_SELECTION_EVENT, true );
}
@Test
@@ -387,7 +388,7 @@ public class AutoSuggest_Test {
autoSuggest.addSelectionListener( mock( SuggestionSelectedListener.class ) );
autoSuggest.addSelectionListener( mock( SuggestionSelectedListener.class ) );
- verify( remoteObject, times( 1 ) ).listen( "change:elementSelection", true );
+ verify( remoteObject, times( 1 ) ).listen( REMOTE_SELECTION_EVENT, true );
}
@Test
@@ -433,7 +434,7 @@ public class AutoSuggest_Test {
autoSuggest.removeSelectionListener( listener );
- verify( remoteObject ).listen( "change:elementSelection", false );
+ verify( remoteObject ).listen( REMOTE_SELECTION_EVENT, false );
}
@Test
@@ -445,7 +446,7 @@ public class AutoSuggest_Test {
autoSuggest.removeSelectionListener( listener );
- verify( remoteObject, never() ).listen( "change:elementSelection", false );
+ verify( remoteObject, never() ).listen( REMOTE_SELECTION_EVENT, false );
}
@Test
@@ -480,7 +481,7 @@ public class AutoSuggest_Test {
SuggestionSelectedListener listener = mock( SuggestionSelectedListener.class );
autoSuggest.addSelectionListener( listener );
- operationHandlerCaptor.get().handleNotify( "change:elementSelection", null );
+ operationHandlerCaptor.get().handleNotify( REMOTE_SELECTION_EVENT, null );
verify( listener ).suggestionSelected();
}

Back to the top