From 7699a5ed893181555ca6c41dcf38a75a1919a2ee Mon Sep 17 00:00:00 2001 From: Gleb Gorelov Date: Thu, 26 Jan 2017 20:05:11 +0400 Subject: [PATCH] PL-8540 Some renderers prevent selection changes --- .../ui/client/grid/CubaGridWidget.java | 23 +++++++++++++ .../ui/client/grid/HasClickSettings.java | 24 +++++++++++++ .../client/renderers/CubaImageRenderer.java | 10 ++++++ .../renderers/CubaProgressBarRenderer.java | 32 +++++++++++++++++ .../CubaProgressBarRendererConnector.java | 29 ++++++++++++++++ .../widgets/image/CubaImageWidget.java | 34 +++++++++++++++++++ .../progressbar/CubaProgressBarWidget.java | 34 +++++++++++++++++++ .../renderers/WebProgressBarRenderer.java | 6 ++-- .../ui/renderers/CubaProgressBarRenderer.java | 22 ++++++++++++ 9 files changed, 211 insertions(+), 3 deletions(-) create mode 100644 modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/grid/HasClickSettings.java create mode 100644 modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/renderers/CubaProgressBarRenderer.java create mode 100644 modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/renderers/CubaProgressBarRendererConnector.java create mode 100644 modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/renderers/widgets/image/CubaImageWidget.java create mode 100644 modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/renderers/widgets/progressbar/CubaProgressBarWidget.java create mode 100644 modules/web/src/com/haulmont/cuba/web/toolkit/ui/renderers/CubaProgressBarRenderer.java diff --git a/modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/grid/CubaGridWidget.java b/modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/grid/CubaGridWidget.java index 5537faa873..b757ff9c05 100644 --- a/modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/grid/CubaGridWidget.java +++ b/modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/grid/CubaGridWidget.java @@ -16,6 +16,9 @@ package com.haulmont.cuba.web.toolkit.ui.client.grid; +import com.google.gwt.dom.client.Element; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.widgets.Grid; import elemental.json.JsonObject; @@ -32,4 +35,24 @@ public class CubaGridWidget extends Grid { // ignore shiftKeyDown until datasources don't support multi-sorting super.sortAfterDelayWithSorter(delay, false); } + + @Override + protected boolean isWidgetAllowsClickHandling(Element targetElement) { + // by default, clicking on widget renderer prevents row selection + // for some widget renderers we want to allow row selection + return isClickThroughEnabled(targetElement); + } + + @Override + protected boolean isEventHandlerShouldHandleEvent(Element targetElement) { + // by default, clicking on widget renderer prevents cell focus changing + // for some widget renderers we want to allow focus changing + return isClickThroughEnabled(targetElement); + } + + protected boolean isClickThroughEnabled(Element e) { + Widget widget = WidgetUtil.findWidget(e, null); + return widget instanceof HasClickSettings && + ((HasClickSettings) widget).isClickThroughEnabled(); + } } diff --git a/modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/grid/HasClickSettings.java b/modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/grid/HasClickSettings.java new file mode 100644 index 0000000000..406ae23502 --- /dev/null +++ b/modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/grid/HasClickSettings.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2008-2017 Haulmont. + * + * 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.haulmont.cuba.web.toolkit.ui.client.grid; + +public interface HasClickSettings { + boolean isClickThroughEnabled(); + void setClickThroughEnabled(boolean enabled); + + +} diff --git a/modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/renderers/CubaImageRenderer.java b/modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/renderers/CubaImageRenderer.java index 5e429d2c59..92f98feaa8 100644 --- a/modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/renderers/CubaImageRenderer.java +++ b/modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/renderers/CubaImageRenderer.java @@ -16,12 +16,22 @@ package com.haulmont.cuba.web.toolkit.ui.client.renderers; +import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Style; import com.google.gwt.user.client.ui.Image; +import com.haulmont.cuba.web.toolkit.ui.client.renderers.widgets.image.CubaImageWidget; import com.vaadin.client.renderers.ImageRenderer; import com.vaadin.client.widget.grid.RendererCellReference; public class CubaImageRenderer extends ImageRenderer { + @Override + public CubaImageWidget createWidget() { + CubaImageWidget image = GWT.create(CubaImageWidget.class); + image.addClickHandler(this); + image.setClickThroughEnabled(true); + return image; + } + @Override public void render(RendererCellReference cell, String url, Image image) { super.render(cell, url, image); diff --git a/modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/renderers/CubaProgressBarRenderer.java b/modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/renderers/CubaProgressBarRenderer.java new file mode 100644 index 0000000000..afa6eb6efb --- /dev/null +++ b/modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/renderers/CubaProgressBarRenderer.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2008-2017 Haulmont. + * + * 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.haulmont.cuba.web.toolkit.ui.client.renderers; + +import com.google.gwt.core.shared.GWT; +import com.haulmont.cuba.web.toolkit.ui.client.renderers.widgets.progressbar.CubaProgressBarWidget; +import com.vaadin.client.renderers.ProgressBarRenderer; + +public class CubaProgressBarRenderer extends ProgressBarRenderer { + + @Override + public CubaProgressBarWidget createWidget() { + CubaProgressBarWidget progressBar = GWT.create(CubaProgressBarWidget.class); + progressBar.addStyleDependentName("static"); + progressBar.setClickThroughEnabled(true); + return progressBar; + } +} diff --git a/modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/renderers/CubaProgressBarRendererConnector.java b/modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/renderers/CubaProgressBarRendererConnector.java new file mode 100644 index 0000000000..3b7a541e96 --- /dev/null +++ b/modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/renderers/CubaProgressBarRendererConnector.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2008-2017 Haulmont. + * + * 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.haulmont.cuba.web.toolkit.ui.client.renderers; + +import com.vaadin.client.connectors.ProgressBarRendererConnector; +import com.vaadin.shared.ui.Connect; + +@Connect(com.haulmont.cuba.web.toolkit.ui.renderers.CubaProgressBarRenderer.class) +public class CubaProgressBarRendererConnector extends ProgressBarRendererConnector { + + @Override + public CubaProgressBarRenderer getRenderer() { + return (CubaProgressBarRenderer) super.getRenderer(); + } +} diff --git a/modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/renderers/widgets/image/CubaImageWidget.java b/modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/renderers/widgets/image/CubaImageWidget.java new file mode 100644 index 0000000000..b5f4e4057d --- /dev/null +++ b/modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/renderers/widgets/image/CubaImageWidget.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2008-2017 Haulmont. + * + * 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.haulmont.cuba.web.toolkit.ui.client.renderers.widgets.image; + +import com.google.gwt.user.client.ui.Image; +import com.haulmont.cuba.web.toolkit.ui.client.grid.HasClickSettings; + +public class CubaImageWidget extends Image implements HasClickSettings { + protected boolean clickThroughEnabled = false; + + @Override + public boolean isClickThroughEnabled() { + return clickThroughEnabled; + } + + @Override + public void setClickThroughEnabled(boolean enabled) { + clickThroughEnabled = enabled; + } +} diff --git a/modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/renderers/widgets/progressbar/CubaProgressBarWidget.java b/modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/renderers/widgets/progressbar/CubaProgressBarWidget.java new file mode 100644 index 0000000000..007472d229 --- /dev/null +++ b/modules/web-toolkit/src/com/haulmont/cuba/web/toolkit/ui/client/renderers/widgets/progressbar/CubaProgressBarWidget.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2008-2017 Haulmont. + * + * 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.haulmont.cuba.web.toolkit.ui.client.renderers.widgets.progressbar; + +import com.haulmont.cuba.web.toolkit.ui.client.grid.HasClickSettings; +import com.vaadin.client.ui.VProgressBar; + +public class CubaProgressBarWidget extends VProgressBar implements HasClickSettings { + protected boolean clickThroughEnabled = false; + + @Override + public boolean isClickThroughEnabled() { + return clickThroughEnabled; + } + + @Override + public void setClickThroughEnabled(boolean enabled) { + clickThroughEnabled = enabled; + } +} diff --git a/modules/web/src/com/haulmont/cuba/web/gui/components/renderers/WebProgressBarRenderer.java b/modules/web/src/com/haulmont/cuba/web/gui/components/renderers/WebProgressBarRenderer.java index d7540ae40c..5ccbb7e3b7 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/components/renderers/WebProgressBarRenderer.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/components/renderers/WebProgressBarRenderer.java @@ -18,7 +18,7 @@ package com.haulmont.cuba.web.gui.components.renderers; import com.haulmont.cuba.gui.components.DataGrid; import com.haulmont.cuba.web.gui.components.WebDataGrid.AbstractRenderer; -import com.vaadin.ui.renderers.ProgressBarRenderer; +import com.haulmont.cuba.web.toolkit.ui.renderers.CubaProgressBarRenderer; /** * A renderer that represents a double values as a graphical progress bar. @@ -26,7 +26,7 @@ import com.vaadin.ui.renderers.ProgressBarRenderer; public class WebProgressBarRenderer extends AbstractRenderer implements DataGrid.ProgressBarRenderer { @Override - protected ProgressBarRenderer createImplementation() { - return new ProgressBarRenderer(); + protected CubaProgressBarRenderer createImplementation() { + return new CubaProgressBarRenderer(); } } diff --git a/modules/web/src/com/haulmont/cuba/web/toolkit/ui/renderers/CubaProgressBarRenderer.java b/modules/web/src/com/haulmont/cuba/web/toolkit/ui/renderers/CubaProgressBarRenderer.java new file mode 100644 index 0000000000..6989d4338b --- /dev/null +++ b/modules/web/src/com/haulmont/cuba/web/toolkit/ui/renderers/CubaProgressBarRenderer.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2008-2017 Haulmont. + * + * 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.haulmont.cuba.web.toolkit.ui.renderers; + +import com.vaadin.ui.renderers.ProgressBarRenderer; + +public class CubaProgressBarRenderer extends ProgressBarRenderer { +}