Lior Vernia has uploaded a new change for review.

Change subject: webadmin: Modified EntityModelCellTable for input columns
......................................................................

webadmin: Modified EntityModelCellTable for input columns

Added support in the event handling mechanism of EntityModelCellTable
for CellTable columns that prefer to handle their own browser
event. Such columns' cells should implement EventHandlingCell, and
then implement the method handlesEvent() to decide whether they'd like
to handle a given event themselves.

For now, made ListModelListBoxCell and CheckBoxColumn handle their own
click events.

Also, changed EntityModelCellTable to only treat the selection column
checkbox as a selection switch, and let other checkboxes do their own
thing.

Change-Id: If46c72cea581d331fea030ea9f2ae2f42129f44f
Signed-off-by: Lior Vernia <lver...@redhat.com>
---
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelCellTable.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/CheckboxColumn.java
A 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/EventHandlingCell.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/ListModelListBoxCell.java
4 files changed, 46 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/65/16465/1

diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelCellTable.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelCellTable.java
index dbae649..acd43be 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelCellTable.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelCellTable.java
@@ -7,6 +7,7 @@
 import org.ovirt.engine.ui.common.PopupTableResources;
 import org.ovirt.engine.ui.common.widget.HasEditorDriver;
 import org.ovirt.engine.ui.common.widget.table.ElementIdCellTable;
+import org.ovirt.engine.ui.common.widget.table.column.EventHandlingCell;
 import org.ovirt.engine.ui.common.widget.table.column.RadioboxCell;
 import org.ovirt.engine.ui.common.widget.table.header.SelectAllCheckBoxHeader;
 import org.ovirt.engine.ui.uicommonweb.models.EntityModel;
@@ -15,6 +16,7 @@
 import org.ovirt.engine.ui.uicompat.EventArgs;
 import org.ovirt.engine.ui.uicompat.IEventListener;
 
+import com.google.gwt.cell.client.Cell;
 import com.google.gwt.cell.client.CheckboxCell;
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.dom.client.Style.Unit;
@@ -171,7 +173,7 @@
         switch (selectionMode) {
         case MULTIPLE:
             setSelectionModel(new MultiSelectionModel<EntityModel>(),
-                    DefaultSelectionEventManager.<EntityModel> 
createCheckboxManager());
+                    DefaultSelectionEventManager.<EntityModel> 
createCheckboxManager(0));
             break;
         case NONE:
             setSelectionModel(new NoSelectionModel<EntityModel>());
@@ -268,6 +270,13 @@
             addCellPreviewHandler(new CellPreviewEvent.Handler<EntityModel>() {
                 @Override
                 public void onCellPreview(CellPreviewEvent<EntityModel> event) 
{
+                    int columnIndex = event.getColumn();
+                    Cell<?> cell = getColumn(columnIndex).getCell();
+                    if (cell instanceof EventHandlingCell
+                            && ((EventHandlingCell<EntityModel>) 
cell).handlesEvent(event)) {
+                        return;
+                    }
+
                     if ("click".equals(event.getNativeEvent().getType()) 
//$NON-NLS-1$
                             && !(getSelectionModel() instanceof 
NoSelectionModel)) {
                         // Let the selection column deal with this
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/CheckboxColumn.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/CheckboxColumn.java
index 0a842d0..7491d75 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/CheckboxColumn.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/CheckboxColumn.java
@@ -4,16 +4,19 @@
 import com.google.gwt.cell.client.Cell.Context;
 import com.google.gwt.cell.client.CheckboxCell;
 import com.google.gwt.cell.client.FieldUpdater;
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.NativeEvent;
 import com.google.gwt.safehtml.shared.SafeHtml;
 import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
 import com.google.gwt.safehtml.shared.SafeHtmlUtils;
 import com.google.gwt.user.cellview.client.Column;
+import com.google.gwt.view.client.CellPreviewEvent;
 
 public abstract class CheckboxColumn<T> extends Column<T, Boolean> {
 
     private boolean isCentralized = false;
 
-    static class EnabledDisabledCheckboxCell extends CheckboxCell {
+    static class EnabledDisabledCheckboxCell extends CheckboxCell implements 
EventHandlingCell<Boolean> {
 
         public EnabledDisabledCheckboxCell() {
             super(true, false);
@@ -40,6 +43,16 @@
             }
         }
 
+        @Override
+        public boolean handlesEvent(CellPreviewEvent<Boolean> event) {
+            NativeEvent nativeEvent = event.getNativeEvent();
+            if (!"click".equals(nativeEvent.getType().toLowerCase())) { 
//$NON-NLS-1$
+                return false;
+            }
+            Element target = nativeEvent.getEventTarget().cast();
+            return "input".equals(target.getTagName().toLowerCase()); 
//$NON-NLS-1$
+        }
+
     }
 
     private static final SafeHtml INPUT_CHECKBOX_DISABLED_PREFIX =
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/EventHandlingCell.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/EventHandlingCell.java
new file mode 100644
index 0000000..5460eef
--- /dev/null
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/EventHandlingCell.java
@@ -0,0 +1,9 @@
+package org.ovirt.engine.ui.common.widget.table.column;
+
+import com.google.gwt.view.client.CellPreviewEvent;
+
+public interface EventHandlingCell<T> {
+
+    boolean handlesEvent(CellPreviewEvent<T> event);
+
+}
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/ListModelListBoxCell.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/ListModelListBoxCell.java
index b2da821..c2a7db2 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/ListModelListBoxCell.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/ListModelListBoxCell.java
@@ -17,6 +17,7 @@
 import com.google.gwt.dom.client.NativeEvent;
 import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
 import com.google.gwt.text.shared.Renderer;
+import com.google.gwt.view.client.CellPreviewEvent;
 
 /**
  * This class may be used to display a ListBox, backed by a ListModel, in cell 
widgets. It mimics the behaviour of a
@@ -27,7 +28,7 @@
  * @param <T>
  *            the ListModel item type.
  */
-public class ListModelListBoxCell<T> extends AbstractInputCell<ListModel, 
String> {
+public class ListModelListBoxCell<T> extends AbstractInputCell<ListModel, 
String> implements EventHandlingCell<T> {
 
     private static final String PATTERN_SELECT = "<select"; //$NON-NLS-1$
     private static final String REPLACEMENT_SELECT = "<select disabled"; 
//$NON-NLS-1$
@@ -113,4 +114,15 @@
                 });
     }
 
+    @Override
+    public boolean handlesEvent(CellPreviewEvent<T> event) {
+        NativeEvent nativeEvent = event.getNativeEvent();
+        if (!"click".equals(nativeEvent.getType().toLowerCase())) { 
//$NON-NLS-1$
+            return false;
+        }
+        Element target = nativeEvent.getEventTarget().cast();
+        String tagName = target.getTagName().toLowerCase();
+        return "select".equals(tagName) || "option".equals(tagName); 
//$NON-NLS-1$ $NON-NLS-2$
+    }
+
 }


-- 
To view, visit http://gerrit.ovirt.org/16465
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If46c72cea581d331fea030ea9f2ae2f42129f44f
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Lior Vernia <lver...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to