Refactor row ClickHandling into NavigationTable
Several users of NavigationTable handle single and double clicks on row, and the rest of the users should. Instead of implementing this handling in every subclass, setup a framework to handle them directly in NavigationTable and implement a sane default policy to handle them which can easily be overridden. Adapt the PatchContentTable classes to override this default behavior. Change-Id: I2a745f572f3c58117d471959caaee1fa2ed20f06
This commit is contained in:
@@ -45,7 +45,6 @@ import com.google.gwt.event.dom.client.KeyPressEvent;
|
||||
import com.google.gwt.event.shared.HandlerRegistration;
|
||||
import com.google.gwt.user.client.DOM;
|
||||
import com.google.gwt.user.client.Element;
|
||||
import com.google.gwt.user.client.Event;
|
||||
import com.google.gwt.user.client.History;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.google.gwt.user.client.ui.Focusable;
|
||||
@@ -212,11 +211,6 @@ public abstract class AbstractPatchContentTable extends NavigationTable<Object>
|
||||
|
||||
public abstract void display(CommentDetail comments, boolean expandComments);
|
||||
|
||||
@Override
|
||||
protected MyFlexTable createFlexTable() {
|
||||
return new DoubleClickFlexTable();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getRowItemKey(final Object item) {
|
||||
return null;
|
||||
@@ -366,12 +360,6 @@ public abstract class AbstractPatchContentTable extends NavigationTable<Object>
|
||||
return getRowItem(row) instanceof CommentList;
|
||||
}
|
||||
|
||||
/** Invoked when the user double clicks on a table cell. */
|
||||
protected abstract void onCellDoubleClick(int row, int column);
|
||||
|
||||
/** Invoked when the user clicks on a table cell. */
|
||||
protected abstract void onCellSingleClick(int row, int column);
|
||||
|
||||
/**
|
||||
* Invokes createCommentEditor() with an empty string as value for the comment
|
||||
* parent UUID. This method is invoked by callers that want to create an
|
||||
@@ -658,42 +646,6 @@ public abstract class AbstractPatchContentTable extends NavigationTable<Object>
|
||||
new ArrayList<PublishedCommentPanel>();
|
||||
}
|
||||
|
||||
protected class DoubleClickFlexTable extends MyFlexTable {
|
||||
public DoubleClickFlexTable() {
|
||||
sinkEvents(Event.ONDBLCLICK | Event.ONCLICK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBrowserEvent(final Event event) {
|
||||
switch (DOM.eventGetType(event)) {
|
||||
case Event.ONCLICK: {
|
||||
// Find out which cell was actually clicked.
|
||||
final Element td = getEventTargetCell(event);
|
||||
if (td == null) {
|
||||
break;
|
||||
}
|
||||
final int row = rowOf(td);
|
||||
if (getRowItem(row) != null) {
|
||||
movePointerTo(row);
|
||||
onCellSingleClick(rowOf(td), columnOf(td));
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Event.ONDBLCLICK: {
|
||||
// Find out which cell was actually clicked.
|
||||
Element td = getEventTargetCell(event);
|
||||
if (td == null) {
|
||||
return;
|
||||
}
|
||||
onCellDoubleClick(rowOf(td), columnOf(td));
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.onBrowserEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public static class NoOpKeyCommand extends NeedsSignInKeyCommand {
|
||||
public NoOpKeyCommand(int mask, int key, String help) {
|
||||
super(mask, key, help);
|
||||
|
@@ -63,6 +63,7 @@ public class SideBySideTable extends AbstractPatchContentTable {
|
||||
|
||||
@Override
|
||||
protected void onCellSingleClick(int row, int column) {
|
||||
super.onCellSingleClick(row, column);
|
||||
if (column == 1 || column == 4) {
|
||||
onCellDoubleClick(row, column);
|
||||
}
|
||||
|
@@ -66,6 +66,7 @@ public class UnifiedDiffTable extends AbstractPatchContentTable {
|
||||
|
||||
@Override
|
||||
protected void onCellSingleClick(int row, int column) {
|
||||
super.onCellSingleClick(row, column);
|
||||
if (column == 1 || column == 2) {
|
||||
if (!"".equals(table.getText(row, column))) {
|
||||
onCellDoubleClick(row, column);
|
||||
|
@@ -20,6 +20,7 @@ import com.google.gwt.event.dom.client.KeyPressEvent;
|
||||
import com.google.gwt.event.shared.HandlerRegistration;
|
||||
import com.google.gwt.user.client.DOM;
|
||||
import com.google.gwt.user.client.Element;
|
||||
import com.google.gwt.user.client.Event;
|
||||
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
import com.google.gwt.user.client.ui.ScrollPanel;
|
||||
@@ -34,6 +35,41 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public abstract class NavigationTable<RowItem> extends FancyFlexTable<RowItem> {
|
||||
protected class MyFlexTable extends FancyFlexTable.MyFlexTable {
|
||||
public MyFlexTable() {
|
||||
sinkEvents(Event.ONDBLCLICK | Event.ONCLICK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBrowserEvent(final Event event) {
|
||||
switch (DOM.eventGetType(event)) {
|
||||
case Event.ONCLICK: {
|
||||
// Find out which cell was actually clicked.
|
||||
final Element td = getEventTargetCell(event);
|
||||
if (td == null) {
|
||||
break;
|
||||
}
|
||||
final int row = rowOf(td);
|
||||
if (getRowItem(row) != null) {
|
||||
onCellSingleClick(rowOf(td), columnOf(td));
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Event.ONDBLCLICK: {
|
||||
// Find out which cell was actually clicked.
|
||||
Element td = getEventTargetCell(event);
|
||||
if (td == null) {
|
||||
return;
|
||||
}
|
||||
onCellDoubleClick(rowOf(td), columnOf(td));
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.onBrowserEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private static final LinkedHashMap<String, Object> savedPositions =
|
||||
new LinkedHashMap<String, Object>(10, 0.75f, true) {
|
||||
@@ -91,6 +127,16 @@ public abstract class NavigationTable<RowItem> extends FancyFlexTable<RowItem> {
|
||||
}
|
||||
}
|
||||
|
||||
/** Invoked when the user double clicks on a table cell. */
|
||||
protected void onCellDoubleClick(int row, int column) {
|
||||
movePointerTo(row);
|
||||
}
|
||||
|
||||
/** Invoked when the user clicks on a table cell. */
|
||||
protected void onCellSingleClick(int row, int column) {
|
||||
onOpenRow(row);
|
||||
}
|
||||
|
||||
protected int getCurrentRow() {
|
||||
return currentRow;
|
||||
}
|
||||
@@ -259,6 +305,11 @@ public abstract class NavigationTable<RowItem> extends FancyFlexTable<RowItem> {
|
||||
super.onUnload();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MyFlexTable createFlexTable() {
|
||||
return new MyFlexTable();
|
||||
}
|
||||
|
||||
public class PrevKeyCommand extends KeyCommand {
|
||||
public PrevKeyCommand(int mask, char key, String help) {
|
||||
super(mask, key, help);
|
||||
|
@@ -18,9 +18,6 @@ import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.projects.ProjectInfo;
|
||||
import com.google.gerrit.client.projects.ProjectMap;
|
||||
import com.google.gwt.event.dom.client.KeyCodes;
|
||||
import com.google.gwt.user.client.DOM;
|
||||
import com.google.gwt.user.client.Element;
|
||||
import com.google.gwt.user.client.Event;
|
||||
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -47,43 +44,6 @@ public class ProjectsTable extends NavigationTable<ProjectInfo> {
|
||||
fmt.addStyleName(0, 2, Gerrit.RESOURCES.css().dataHeader());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MyFlexTable createFlexTable() {
|
||||
MyFlexTable table = new MyFlexTable() {
|
||||
@Override
|
||||
public void onBrowserEvent(final Event event) {
|
||||
switch (DOM.eventGetType(event)) {
|
||||
case Event.ONCLICK: {
|
||||
// Find out which cell was actually clicked.
|
||||
final Element td = getEventTargetCell(event);
|
||||
if (td == null) {
|
||||
break;
|
||||
}
|
||||
final int row = rowOf(td);
|
||||
if (getRowItem(row) != null) {
|
||||
ProjectsTable.this.movePointerTo(row);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Event.ONDBLCLICK: {
|
||||
// Find out which cell was actually clicked.
|
||||
Element td = getEventTargetCell(event);
|
||||
if (td == null) {
|
||||
return;
|
||||
}
|
||||
onOpenRow(rowOf(td));
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.onBrowserEvent(event);
|
||||
}
|
||||
};
|
||||
|
||||
table.sinkEvents(Event.ONDBLCLICK | Event.ONCLICK);
|
||||
return table;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getRowItemKey(final ProjectInfo item) {
|
||||
return item.name();
|
||||
|
Reference in New Issue
Block a user