Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate ClickableRenderer and subclasses
Change-Id: I233250d9b68052825b73bed0288fffeaf5bdd04b
- Loading branch information
Showing
18 changed files
with
730 additions
and
39 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
client/src/main/java/com/vaadin/client/connectors/ButtonRendererConnector.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,45 @@ | ||
/* | ||
* Copyright 2000-2016 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.connectors; | ||
|
||
import com.google.web.bindery.event.shared.HandlerRegistration; | ||
import com.vaadin.client.renderers.ButtonRenderer; | ||
import com.vaadin.client.renderers.ClickableRenderer.RendererClickHandler; | ||
import com.vaadin.shared.ui.Connect; | ||
|
||
import elemental.json.JsonObject; | ||
|
||
/** | ||
* A connector for {@link ButtonRenderer}. | ||
* | ||
* @since 7.4 | ||
* @author Vaadin Ltd | ||
*/ | ||
@Connect(com.vaadin.ui.renderers.ButtonRenderer.class) | ||
public class ButtonRendererConnector | ||
extends ClickableRendererConnector<String> { | ||
|
||
@Override | ||
public ButtonRenderer getRenderer() { | ||
return (ButtonRenderer) super.getRenderer(); | ||
} | ||
|
||
@Override | ||
protected HandlerRegistration addClickHandler( | ||
RendererClickHandler<JsonObject> handler) { | ||
return getRenderer().addClickHandler(handler); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
client/src/main/java/com/vaadin/client/connectors/ClickableRendererConnector.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,63 @@ | ||
/* | ||
* Copyright 2000-2016 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.connectors; | ||
|
||
import com.google.web.bindery.event.shared.HandlerRegistration; | ||
import com.vaadin.client.MouseEventDetailsBuilder; | ||
import com.vaadin.client.connectors.grid.AbstractGridRendererConnector; | ||
import com.vaadin.client.renderers.ClickableRenderer.RendererClickEvent; | ||
import com.vaadin.client.renderers.ClickableRenderer.RendererClickHandler; | ||
import com.vaadin.shared.ui.grid.renderers.RendererClickRpc; | ||
|
||
import elemental.json.JsonObject; | ||
|
||
/** | ||
* An abstract base class for {@link ClickableRenderer} connectors. | ||
* | ||
* @param <T> | ||
* the presentation type of the renderer | ||
* | ||
* @since 7.4 | ||
* @author Vaadin Ltd | ||
*/ | ||
public abstract class ClickableRendererConnector<T> | ||
extends AbstractGridRendererConnector<T> { | ||
|
||
private HandlerRegistration clickRegistration; | ||
|
||
@Override | ||
protected void init() { | ||
clickRegistration = addClickHandler( | ||
new RendererClickHandler<JsonObject>() { | ||
@Override | ||
public void onClick(RendererClickEvent<JsonObject> event) { | ||
getRpcProxy(RendererClickRpc.class).click( | ||
getRowKey(event.getCell().getRow()), | ||
getColumnId(event.getCell().getColumn()), | ||
MouseEventDetailsBuilder.buildMouseEventDetails( | ||
event.getNativeEvent())); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onUnregister() { | ||
clickRegistration.removeHandler(); | ||
} | ||
|
||
protected abstract HandlerRegistration addClickHandler( | ||
RendererClickHandler<JsonObject> handler); | ||
} |
57 changes: 57 additions & 0 deletions
57
client/src/main/java/com/vaadin/client/connectors/ImageRendererConnector.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,57 @@ | ||
/* | ||
* Copyright 2000-2016 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.connectors; | ||
|
||
import com.google.web.bindery.event.shared.HandlerRegistration; | ||
import com.vaadin.client.communication.JsonDecoder; | ||
import com.vaadin.client.metadata.TypeDataStore; | ||
import com.vaadin.client.renderers.ClickableRenderer.RendererClickHandler; | ||
import com.vaadin.client.renderers.ImageRenderer; | ||
import com.vaadin.shared.communication.URLReference; | ||
import com.vaadin.shared.ui.Connect; | ||
|
||
import elemental.json.JsonObject; | ||
import elemental.json.JsonValue; | ||
|
||
/** | ||
* A connector for {@link ImageRenderer}. | ||
* | ||
* @since 7.4 | ||
* @author Vaadin Ltd | ||
*/ | ||
@Connect(com.vaadin.ui.renderers.ImageRenderer.class) | ||
public class ImageRendererConnector extends ClickableRendererConnector<String> { | ||
|
||
@Override | ||
public ImageRenderer getRenderer() { | ||
return (ImageRenderer) super.getRenderer(); | ||
} | ||
|
||
@Override | ||
public String decode(JsonValue value) { | ||
URLReference reference = (URLReference) JsonDecoder.decodeValue( | ||
TypeDataStore.getType(URLReference.class), value, null, | ||
getConnection()); | ||
|
||
return reference != null ? reference.getURL() : null; | ||
} | ||
|
||
@Override | ||
protected HandlerRegistration addClickHandler( | ||
RendererClickHandler<JsonObject> handler) { | ||
return getRenderer().addClickHandler(handler); | ||
} | ||
} |
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
Oops, something went wrong.