summaryrefslogtreecommitdiffstats
path: root/client/src
diff options
context:
space:
mode:
authorSauli Tähkäpää <sauli@vaadin.com>2015-08-26 21:43:17 +0300
committerVaadin Code Review <review@vaadin.com>2016-05-13 12:21:46 +0000
commit7f3481b7a69d9edc31c7e70b305ece6816eee36f (patch)
treea96219d0ff50c4531625886c0af271ed97e7384a /client/src
parentc6f185a1c420af5ca67a5dc9200db15dcc8e2365 (diff)
downloadvaadin-framework-7f3481b7a69d9edc31c7e70b305ece6816eee36f.tar.gz
vaadin-framework-7f3481b7a69d9edc31c7e70b305ece6816eee36f.zip
Disable multiselect checkboxes when Grid is disabled. (#18560)
Change-Id: Ief0531fe90b9bc8bcf0a60132211a0633b9401d4
Diffstat (limited to 'client/src')
-rw-r--r--client/src/main/java/com/vaadin/client/widget/grid/events/GridEnabledEvent.java46
-rw-r--r--client/src/main/java/com/vaadin/client/widget/grid/events/GridEnabledHandler.java36
-rw-r--r--client/src/main/java/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java25
-rw-r--r--client/src/main/java/com/vaadin/client/widgets/Grid.java40
4 files changed, 141 insertions, 6 deletions
diff --git a/client/src/main/java/com/vaadin/client/widget/grid/events/GridEnabledEvent.java b/client/src/main/java/com/vaadin/client/widget/grid/events/GridEnabledEvent.java
new file mode 100644
index 0000000000..2e4be88671
--- /dev/null
+++ b/client/src/main/java/com/vaadin/client/widget/grid/events/GridEnabledEvent.java
@@ -0,0 +1,46 @@
+/*
+ * 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.widget.grid.events;
+
+import com.google.gwt.event.shared.GwtEvent;
+
+/**
+ * An enabled/disabled event, fired by the Grid when it is disabled or enabled.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class GridEnabledEvent extends GwtEvent<GridEnabledHandler> {
+ /**
+ * The type of this event
+ */
+ public static final Type<GridEnabledHandler> TYPE = new Type<GridEnabledHandler>();
+ private final boolean enabled;
+
+ public GridEnabledEvent(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ @Override
+ public Type<GridEnabledHandler> getAssociatedType() {
+ return TYPE;
+ }
+
+ @Override
+ protected void dispatch(final GridEnabledHandler handler) {
+ handler.onEnabled(enabled);
+ }
+}
diff --git a/client/src/main/java/com/vaadin/client/widget/grid/events/GridEnabledHandler.java b/client/src/main/java/com/vaadin/client/widget/grid/events/GridEnabledHandler.java
new file mode 100644
index 0000000000..26ac498bcc
--- /dev/null
+++ b/client/src/main/java/com/vaadin/client/widget/grid/events/GridEnabledHandler.java
@@ -0,0 +1,36 @@
+/*
+ * 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.widget.grid.events;
+
+import com.google.gwt.event.shared.EventHandler;
+
+/**
+ * Handler for a Grid enabled/disabled event, called when the Grid is enabled
+ * or disabled.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public interface GridEnabledHandler extends EventHandler {
+
+ /**
+ * Called when Grid is enabled or disabled.
+ *
+ * @param enabled
+ * true if status changes from disabled to enabled, otherwise false.
+ */
+ public void onEnabled(boolean enabled);
+}
diff --git a/client/src/main/java/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java b/client/src/main/java/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java
index c64908f24c..f244682b49 100644
--- a/client/src/main/java/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java
+++ b/client/src/main/java/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java
@@ -42,6 +42,8 @@ import com.vaadin.client.WidgetUtil;
import com.vaadin.client.renderers.ClickableRenderer;
import com.vaadin.client.widget.grid.CellReference;
import com.vaadin.client.widget.grid.RendererCellReference;
+import com.vaadin.client.widget.grid.events.GridEnabledEvent;
+import com.vaadin.client.widget.grid.events.GridEnabledHandler;
import com.vaadin.client.widget.grid.selection.SelectionModel.Multi.Batched;
import com.vaadin.client.widgets.Grid;
@@ -76,7 +78,7 @@ public class MultiSelectionRenderer<T> extends
* @since 7.5
*/
private final class CheckBoxEventHandler implements MouseDownHandler,
- TouchStartHandler, ClickHandler {
+ TouchStartHandler, ClickHandler, GridEnabledHandler {
private final CheckBox checkBox;
/**
@@ -89,14 +91,18 @@ public class MultiSelectionRenderer<T> extends
@Override
public void onMouseDown(MouseDownEvent event) {
- if (event.getNativeButton() == NativeEvent.BUTTON_LEFT) {
- startDragSelect(event.getNativeEvent(), checkBox.getElement());
+ if(checkBox.isEnabled()) {
+ if (event.getNativeButton() == NativeEvent.BUTTON_LEFT) {
+ startDragSelect(event.getNativeEvent(), checkBox.getElement());
+ }
}
}
@Override
public void onTouchStart(TouchStartEvent event) {
- startDragSelect(event.getNativeEvent(), checkBox.getElement());
+ if(checkBox.isEnabled()) {
+ startDragSelect(event.getNativeEvent(), checkBox.getElement());
+ }
}
@Override
@@ -105,6 +111,11 @@ public class MultiSelectionRenderer<T> extends
event.preventDefault();
event.stopPropagation();
}
+
+ @Override
+ public void onEnabled(boolean enabled) {
+ checkBox.setEnabled(enabled);
+ }
}
/**
@@ -595,6 +606,7 @@ public class MultiSelectionRenderer<T> extends
final CheckBox checkBox = GWT.create(CheckBox.class);
checkBox.setStylePrimaryName(grid.getStylePrimaryName()
+ SELECTION_CHECKBOX_CLASSNAME);
+
CheckBoxEventHandler handler = new CheckBoxEventHandler(checkBox);
// Sink events
@@ -606,6 +618,9 @@ public class MultiSelectionRenderer<T> extends
checkBox.addMouseDownHandler(handler);
checkBox.addTouchStartHandler(handler);
checkBox.addClickHandler(handler);
+ grid.addHandler(handler, GridEnabledEvent.TYPE);
+
+ checkBox.setEnabled(grid.isEnabled());
return checkBox;
}
@@ -614,7 +629,7 @@ public class MultiSelectionRenderer<T> extends
public void render(final RendererCellReference cell, final Boolean data,
CheckBox checkBox) {
checkBox.setValue(data, false);
- checkBox.setEnabled(!grid.isEditorActive());
+ checkBox.setEnabled(grid.isEnabled() && !grid.isEditorActive());
checkBox.getElement().setPropertyInt(LOGICAL_ROW_PROPERTY_INT,
cell.getRowIndex());
}
diff --git a/client/src/main/java/com/vaadin/client/widgets/Grid.java b/client/src/main/java/com/vaadin/client/widgets/Grid.java
index c388dbc951..a022db58a4 100644
--- a/client/src/main/java/com/vaadin/client/widgets/Grid.java
+++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java
@@ -140,6 +140,8 @@ import com.vaadin.client.widget.grid.events.FooterKeyPressHandler;
import com.vaadin.client.widget.grid.events.FooterKeyUpHandler;
import com.vaadin.client.widget.grid.events.GridClickEvent;
import com.vaadin.client.widget.grid.events.GridDoubleClickEvent;
+import com.vaadin.client.widget.grid.events.GridEnabledEvent;
+import com.vaadin.client.widget.grid.events.GridEnabledHandler;
import com.vaadin.client.widget.grid.events.GridKeyDownEvent;
import com.vaadin.client.widget.grid.events.GridKeyPressEvent;
import com.vaadin.client.widget.grid.events.GridKeyUpEvent;
@@ -2845,7 +2847,8 @@ public class Grid<T> extends ResizeComposite implements
}
}
- public final class SelectionColumn extends Column<Boolean, T> {
+ public final class SelectionColumn extends Column<Boolean, T>
+ implements GridEnabledHandler {
private boolean initDone = false;
private boolean selected = false;
@@ -2853,6 +2856,8 @@ public class Grid<T> extends ResizeComposite implements
SelectionColumn(final Renderer<Boolean> selectColumnRenderer) {
super(selectColumnRenderer);
+
+ addEnabledHandler(this);
}
void initDone() {
@@ -3002,6 +3007,24 @@ public class Grid<T> extends ResizeComposite implements
super.setEditable(editable);
return this;
}
+
+ /**
+ * Sets whether the selection column is enabled.
+ *
+ * @since
+ * @param enabled <code>true</code> to enable the column,
+ * <code>false</code> to disable it.
+ */
+ public void setEnabled(boolean enabled) {
+ if(selectAllCheckBox != null) {
+ selectAllCheckBox.setEnabled(enabled);
+ }
+ }
+
+ @Override
+ public void onEnabled(boolean enabled) {
+ setEnabled(enabled);
+ }
}
/**
@@ -5971,6 +5994,8 @@ public class Grid<T> extends ResizeComposite implements
getEscalator().setScrollLocked(Direction.VERTICAL,
!enabled || editorOpen);
getEscalator().setScrollLocked(Direction.HORIZONTAL, !enabled);
+
+ fireEvent(new GridEnabledEvent(enabled));
}
@Override
@@ -7538,6 +7563,8 @@ public class Grid<T> extends ResizeComposite implements
selectionColumn = new SelectionColumn(selectColumnRenderer);
addColumnSkipSelectionColumnCheck(selectionColumn, 0);
+
+ selectionColumn.setEnabled(isEnabled());
selectionColumn.initDone();
} else {
selectionColumn = null;
@@ -8100,6 +8127,17 @@ public class Grid<T> extends ResizeComposite implements
}
/**
+ * Register a enabled status change handler to this Grid.
+ * The event for this handler is fired when the Grid changes from disabled
+ * to enabled and vice-versa.
+ * @param handler the handler for the event
+ * @return the registration for the event
+ */
+ public HandlerRegistration addEnabledHandler(GridEnabledHandler handler) {
+ return addHandler(handler, GridEnabledEvent.TYPE);
+ }
+
+ /**
* Apply sorting to data source.
*/
private void sort(boolean userOriginated) {