Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor handling of focus and blur RPC in Connectors (#17917)
Change-Id: I2e4fb3fb941fda2aa4cbc7154fa9a3f7e8e9ce02
- Loading branch information
1 parent
26b06bd
commit 8ba56b9
Showing
8 changed files
with
121 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
client/src/com/vaadin/client/ui/ConnectorFocusAndBlurHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright 2000-2014 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.client.ui; | ||
|
||
import com.google.gwt.event.dom.client.BlurEvent; | ||
import com.google.gwt.event.dom.client.BlurHandler; | ||
import com.google.gwt.event.dom.client.FocusEvent; | ||
import com.google.gwt.event.dom.client.FocusHandler; | ||
import com.google.gwt.event.shared.HandlerRegistration; | ||
import com.google.gwt.user.client.ui.Widget; | ||
import com.vaadin.client.EventHelper; | ||
import com.vaadin.client.communication.StateChangeEvent; | ||
import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler; | ||
import com.vaadin.shared.EventId; | ||
import com.vaadin.shared.communication.FieldRpc.FocusAndBlurServerRpc; | ||
|
||
/** | ||
* A handler for focus and blur events which uses {@link FocusAndBlurServerRpc} | ||
* to transmit received events to the server. Events are only handled if there | ||
* is a corresponding listener on the server side. | ||
* | ||
* @since | ||
* @author Vaadin Ltd | ||
*/ | ||
public class ConnectorFocusAndBlurHandler implements StateChangeHandler, | ||
FocusHandler, BlurHandler { | ||
|
||
private final AbstractComponentConnector connector; | ||
private final Widget widget; | ||
private HandlerRegistration focusRegistration = null; | ||
private HandlerRegistration blurRegistration = null; | ||
|
||
public static void addHandlers(AbstractComponentConnector connector) { | ||
addHandlers(connector, connector.getWidget()); | ||
} | ||
|
||
public static void addHandlers(AbstractComponentConnector connector, | ||
Widget widget) { | ||
connector.addStateChangeHandler("registeredEventListeners", | ||
new ConnectorFocusAndBlurHandler(connector, widget)); | ||
} | ||
|
||
private ConnectorFocusAndBlurHandler(AbstractComponentConnector connector, | ||
Widget widget) { | ||
this.connector = connector; | ||
this.widget = widget; | ||
} | ||
|
||
@Override | ||
public void onStateChanged(StateChangeEvent stateChangeEvent) { | ||
focusRegistration = EventHelper.updateHandler(connector, this, | ||
EventId.FOCUS, focusRegistration, FocusEvent.getType(), widget); | ||
blurRegistration = EventHelper.updateHandler(connector, this, | ||
EventId.BLUR, blurRegistration, BlurEvent.getType(), widget); | ||
} | ||
|
||
@Override | ||
public void onFocus(FocusEvent event) { | ||
// updateHandler ensures that this is called only when | ||
// there is a listener on the server side | ||
getRpc().focus(); | ||
} | ||
|
||
@Override | ||
public void onBlur(BlurEvent event) { | ||
// updateHandler ensures that this is called only when | ||
// there is a listener on the server side | ||
getRpc().blur(); | ||
} | ||
|
||
private FocusAndBlurServerRpc getRpc() { | ||
return connector.getRpcProxy(FocusAndBlurServerRpc.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.