/*
* 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
import com.google.gwt.dom.client.Touch;
import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.BlurHandler;
+import com.google.gwt.event.dom.client.ContextMenuEvent;
+import com.google.gwt.event.dom.client.ContextMenuHandler;
import com.google.gwt.event.dom.client.FocusEvent;
import com.google.gwt.event.dom.client.FocusHandler;
import com.google.gwt.event.dom.client.KeyCodes;
/**
* VScrollTable
- *
+ *
* VScrollTable is a FlowPanel having two widgets in it: * TableHead component *
* ScrollPanel
- *
+ *
* TableHead contains table's header and widgets + logic for resizing,
* reordering and hiding columns.
- *
+ *
* ScrollPanel contains VScrollTableBody object which handles content. To save
* some bandwidth and to improve clients responsiveness with loads of data, in
* VScrollTableBody all rows are not necessary rendered. There are "spacers" in
* VScrollTableBody to use the exact same space as non-rendered rows would use.
* This way we can use seamlessly traditional scrollbars and scrolling to fetch
* more rows instead of "paging".
- *
+ *
* In VScrollTable we listen to scroll events. On horizontal scrolling we also
* update TableHeads scroll position which has its scrollbars hidden. On
* vertical scroll events we will check if we are reaching the end of area where
* we have rows rendered and
- *
+ *
* TODO implement unregistering for child components in Cells
*/
public class VScrollTable extends FlowPanel implements HasWidgets,
ScrollHandler, VHasDropHandler, FocusHandler, BlurHandler, Focusable,
ActionOwner, SubPartAware {
- /**
- * Simple interface for parts of the table capable of owning a context menu.
- *
- * @author Vaadin Ltd
- */
- private interface ContextMenuOwner {
- public void showContextMenu(Event event);
- }
-
- /**
- * Handles showing context menu on "long press" from a touch screen.
- *
- * @author Vaadin Ltd
- */
- private class TouchContextProvider {
- private static final int TOUCH_CONTEXT_MENU_TIMEOUT = 500;
- private Timer contextTouchTimeout;
-
- private Event touchStart;
- private int touchStartY;
- private int touchStartX;
-
- private ContextMenuOwner target;
-
- /**
- * Initializes a handler for a certain context menu owner.
- *
- * @param target
- * the owner of the context menu
- */
- public TouchContextProvider(ContextMenuOwner target) {
- this.target = target;
- }
-
- /**
- * Cancels the current context touch timeout.
- */
- public void cancel() {
- if (contextTouchTimeout != null) {
- contextTouchTimeout.cancel();
- contextTouchTimeout = null;
- }
- touchStart = null;
- }
-
- /**
- * A function to handle touch context events in a table.
- *
- * @param event
- * browser event to handle
- */
- public void handleTouchEvent(final Event event) {
- int type = event.getTypeInt();
-
- switch (type) {
- case Event.ONCONTEXTMENU:
- target.showContextMenu(event);
- break;
- case Event.ONTOUCHSTART:
- // save position to fields, touches in events are same
- // instance during the operation.
- touchStart = event;
-
- Touch touch = event.getChangedTouches().get(0);
- touchStartX = touch.getClientX();
- touchStartY = touch.getClientY();
-
- if (contextTouchTimeout == null) {
- contextTouchTimeout = new Timer() {
-
- @Override
- public void run() {
- if (touchStart != null) {
- // Open the context menu if finger
- // is held in place long enough.
- target.showContextMenu(touchStart);
- event.preventDefault();
- touchStart = null;
- }
- }
- };
- }
- contextTouchTimeout.schedule(TOUCH_CONTEXT_MENU_TIMEOUT);
- break;
- case Event.ONTOUCHCANCEL:
- case Event.ONTOUCHEND:
- cancel();
- break;
- case Event.ONTOUCHMOVE:
- if (isSignificantMove(event)) {
- // Moved finger before the context menu timer
- // expired, so let the browser handle the event.
- cancel();
- }
- }
- }
-
- /**
- * Calculates how many pixels away the user's finger has traveled. This
- * reduces the chance of small non-intentional movements from canceling
- * the long press detection.
- *
- * @param event
- * the Event for which to check the move distance
- * @return true if this is considered an intentional move by the user
- */
- protected boolean isSignificantMove(Event event) {
- if (touchStart == null) {
- // no touch start
- return false;
- }
-
- // Calculate the distance between touch start and the current touch
- // position
- Touch touch = event.getChangedTouches().get(0);
- int deltaX = touch.getClientX() - touchStartX;
- int deltaY = touch.getClientY() - touchStartY;
- int delta = deltaX * deltaX + deltaY * deltaY;
-
- // Compare to the square of the significant move threshold to remove
- // the need for a square root
- if (delta > TouchScrollDelegate.SIGNIFICANT_MOVE_THRESHOLD
- * TouchScrollDelegate.SIGNIFICANT_MOVE_THRESHOLD) {
- return true;
- }
- return false;
- }
- }
-
public static final String STYLENAME = "v-table";
public enum SelectMode {
* The last known row height used to preserve the height of a table with
* custom row heights and a fixed page length after removing the last row
* from the table.
- *
+ *
* A new VScrollTableBody instance is created every time the number of rows
* changes causing {@link VScrollTableBody#rowHeight} to be discarded and
* the height recalculated by {@link VScrollTableBody#getRowHeight(boolean)}
/*
* (non-Javadoc)
- *
+ *
* @see java.lang.Object#toString()
*/
/** For internal use only. May be removed or replaced in the future. */
public final TableFooter tFoot = new TableFooter();
- /** Handles context menu for table body */
- private ContextMenuOwner contextMenuOwner = new ContextMenuOwner() {
-
- @Override
- public void showContextMenu(Event event) {
- int left = Util.getTouchOrMouseClientX(event);
- int top = Util.getTouchOrMouseClientY(event);
- boolean menuShown = handleBodyContextMenu(left, top);
- if (menuShown) {
- event.stopPropagation();
- event.preventDefault();
- }
- }
- };
-
- /** Handles touch events to display a context menu for table body */
- private TouchContextProvider touchContextProvider = new TouchContextProvider(
- contextMenuOwner);
-
/** For internal use only. May be removed or replaced in the future. */
public final FocusableScrollPanel scrollBodyPanel = new FocusableScrollPanel(
- true) {
- @Override
- public void onBrowserEvent(Event event) {
- super.onBrowserEvent(event);
- touchContextProvider.handleTouchEvent(event);
- };
- };
+ true);
private KeyPressHandler navKeyPressHandler = new KeyPressHandler() {
* Values (serverCacheFirst+serverCacheLast) sent by server that tells which
* rows (indexes) are in the server side cache (page buffer). -1 means
* unknown. The server side cache row MUST MATCH the client side cache rows.
- *
+ *
* If the client side cache contains additional rows with e.g. buttons, it
* will cause out of sync when such a button is pressed.
- *
+ *
* If the server side cache contains additional rows with e.g. buttons,
* scrolling in the client will cause empty buttons to be rendered
* (cached=true request for non-existing components)
- *
+ *
* For internal use only. May be removed or replaced in the future.
*/
public int serverCacheFirst = -1;
}
scrollBodyPanel.addKeyUpHandler(navKeyUpHandler);
- scrollBodyPanel.sinkEvents(Event.TOUCHEVENTS | Event.ONCONTEXTMENU);
+ scrollBodyPanel.sinkEvents(Event.TOUCHEVENTS);
+
+ scrollBodyPanel.sinkEvents(Event.ONCONTEXTMENU);
+ scrollBodyPanel.addDomHandler(new ContextMenuHandler() {
+
+ @Override
+ public void onContextMenu(ContextMenuEvent event) {
+ handleBodyContextMenu(event);
+ }
+ }, ContextMenuEvent.getType());
setStyleName(STYLENAME);
});
}
- /**
- * Handles a context menu event on table body.
- *
- * @param left
- * left position of the context menu
- * @param top
- * top position of the context menu
- * @return true if a context menu was shown, otherwise false
- */
- private boolean handleBodyContextMenu(int left, int top) {
+ private void handleBodyContextMenu(ContextMenuEvent event) {
if (enabled && bodyActionKeys != null) {
+ int left = Util.getTouchOrMouseClientX(event.getNativeEvent());
+ int top = Util.getTouchOrMouseClientY(event.getNativeEvent());
top += Window.getScrollTop();
left += Window.getScrollLeft();
client.getContextMenu().showAt(this, left, top);
- return true;
+
+ // Only prevent browser context menu if there are action handlers
+ // registered
+ event.stopPropagation();
+ event.preventDefault();
}
- return false;
}
/**
* Fires a column resize event which sends the resize information to the
* server.
- *
+ *
* @param columnId
* The columnId of the column which was resized
* @param originalWidth
/**
* Non-immediate variable update of column widths for a collection of
* columns.
- *
+ *
* @param columns
* the columns to trigger the events for.
*/
/**
* Moves the focus one step down
- *
+ *
* @return Returns true if succeeded
*/
private boolean moveFocusDown() {
/**
* Moves the focus down by 1+offset rows
- *
+ *
* @return Returns true if succeeded, else false if the selection could not
* be move downwards
*/
/**
* Moves the selection one step up
- *
+ *
* @return Returns true if succeeded
*/
private boolean moveFocusUp() {
/**
* Moves the focus row upwards
- *
+ *
* @return Returns true if succeeded, else false if the selection could not
* be move upwards
- *
+ *
*/
private boolean moveFocusUp(int offset) {
if (isSelectable()) {
/**
* Selects a row where the current selection head is
- *
+ *
* @param ctrlSelect
* Is the selection a ctrl+selection
* @param shiftSelect
/**
* Sends the selection to the server if it has been changed since the last
* update/visit.
- *
+ *
* @param immediately
* set to true to immediately send the rows
*/
* Get the key that moves the selection head upwards. By default it is the
* up arrow key but by overriding this you can change the key to whatever
* you want.
- *
+ *
* @return The keycode of the key
*/
protected int getNavigationUpKey() {
* Get the key that moves the selection head downwards. By default it is the
* down arrow key but by overriding this you can change the key to whatever
* you want.
- *
+ *
* @return The keycode of the key
*/
protected int getNavigationDownKey() {
* Get the key that scrolls to the left in the table. By default it is the
* left arrow key but by overriding this you can change the key to whatever
* you want.
- *
+ *
* @return The keycode of the key
*/
protected int getNavigationLeftKey() {
* Get the key that scroll to the right on the table. By default it is the
* right arrow key but by overriding this you can change the key to whatever
* you want.
- *
+ *
* @return The keycode of the key
*/
protected int getNavigationRightKey() {
* Get the key that selects an item in the table. By default it is the space
* bar key but by overriding this you can change the key to whatever you
* want.
- *
+ *
* @return
*/
protected int getNavigationSelectKey() {
* Get the key the moves the selection one page up in the table. By default
* this is the Page Up key but by overriding this you can change the key to
* whatever you want.
- *
+ *
* @return
*/
protected int getNavigationPageUpKey() {
* Get the key the moves the selection one page down in the table. By
* default this is the Page Down key but by overriding this you can change
* the key to whatever you want.
- *
+ *
* @return
*/
protected int getNavigationPageDownKey() {
* Get the key the moves the selection to the beginning of the table. By
* default this is the Home key but by overriding this you can change the
* key to whatever you want.
- *
+ *
* @return
*/
protected int getNavigationStartKey() {
* Get the key the moves the selection to the end of the table. By default
* this is the End key but by overriding this you can change the key to
* whatever you want.
- *
+ *
* @return
*/
protected int getNavigationEndKey() {
/*
* The focus is no longer on a selected row. Move
* focus to the selected row. (#10522)
- *
+ *
* Don't do this for multiselect (#13341).
- *
+ *
* Checking the selection mode here instead of in
* setRowFocus allows keyboard shift+downarrow
* selection to work as expected.
@Override
public void execute() {
- if (firstvisible >= 0) {
+ if (firstvisible > 0) {
firstRowInViewPort = firstvisible;
if (firstvisibleOnLastPage > -1) {
scrollBodyPanel
/**
* Returns the extra space that is given to the header column when column
* width is determined by header text.
- *
+ *
* @return extra space in pixels
*/
private int getHeaderPadding() {
* This method exists for the needs of {@link VTreeTable} only. Not part of
* the official API, <b>extend at your own risk</b>. May be removed or
* replaced in the future.
- *
+ *
* @return index of TreeTable's hierarchy column, or -1 if not applicable
*/
protected int getHierarchyColumnIndex() {
* Selects the last row visible in the table
* <p>
* For internal use only. May be removed or replaced in the future.
- *
+ *
* @param focusOnly
* Should the focus only be moved to the last row
*/
* Selects the first row visible in the table
* <p>
* For internal use only. May be removed or replaced in the future.
- *
+ *
* @param focusOnly
* Should the focus only be moved to the first row
*/
* <p>
* Update headers whould be called before this method is called!
* </p>
- *
+ *
* @param strings
*/
private void updateFooter(String[] strings) {
/**
* For internal use only. May be removed or replaced in the future.
- *
+ *
* @param uidl
* which contains row data
* @param firstRow
* on the commands in the UIDL.
* <p>
* For internal use only. May be removed or replaced in the future.
- *
+ *
* @param partialRowAdditions
* the UIDL containing row updates.
*/
/**
* Gives correct column index for given column key ("cid" in UIDL).
- *
+ *
* @param colKey
* @return column index of visible columns, -1 if column not visible
*/
/**
* Note: not part of the official API, extend at your own risk. May be
* removed or replaced in the future.
- *
+ *
* Sets the indicated column's width for headers and scrollBody alike.
- *
+ *
* @param colIndex
* index of the modified column
* @param w
/**
* Get a rendered row by its key
- *
+ *
* @param key
* The key to search with
* @return
/**
* Returns the next row to the given row
- *
+ *
* @param row
* The row to calculate from
- *
+ *
* @return The next row or null if no row exists
*/
private VScrollTableRow getNextRow(VScrollTableRow row, int offset) {
/**
* Returns the previous row from the given row
- *
+ *
* @param row
* The row to calculate from
* @return The previous row or null if no row exists
/**
* Run only once when component is attached and received its initial
* content. This function:
- *
+ *
* * Syncs headers and bodys "natural widths and saves the values.
- *
+ *
* * Sets proper width and height
- *
+ *
* * Makes deferred request to get some cache rows
- *
+ *
* For internal use only. May be removed or replaced in the future.
*/
public void sizeInit() {
* We will use browsers table rendering algorithm to find proper column
* widths. If content and header take less space than available, we will
* divide extra space relatively to each column which has not width set.
- *
+ *
* Overflow pixels are added to last column.
*/
/**
* Note: this method is not part of official API although declared as
* protected. Extend at your own risk.
- *
+ *
* @return true if content area will have scrollbars visible.
*/
protected boolean willHaveScrollbars() {
* Sets width to the header cell. This width should not include any
* possible indent modifications that are present in
* {@link VScrollTableBody#getMaxIndent()}.
- *
+ *
* @param w
* required width of the cell sans indentations
* @param ensureDefinedWidth
/**
* Detects if width is fixed by developer on server side or resized to
* current width by user.
- *
+ *
* @return true if defined, false if "natural" width
*/
public boolean isDefinedWidth() {
/**
* This method exists for the needs of {@link VTreeTable} only.
- *
+ *
* Returns the pixels width of the header cell. This includes the
* indent, if applicable.
- *
+ *
* @return The width in pixels
*/
protected int getWidthWithIndent() {
/**
* Returns the pixels width of the header cell.
- *
+ *
* @return The width in pixels
*/
public int getWidth() {
/**
* This method exists for the needs of {@link VTreeTable} only.
- *
+ *
* @return <code>true</code> if this is hierarcyColumn's header cell,
* <code>false</code> otherwise
*/
/**
* Fires a header click event after the user has clicked a column header
* cell
- *
+ *
* @param event
* The click event
*/
/**
* Returns the smallest possible cell width in pixels.
- *
+ *
* @param includeIndent
* - width should include hierarchy column indent if
* applicable (VTreeTable only)
* Detects the natural minimum width for the column of this header cell.
* If column is resized by user or the width is defined by server the
* actual width is returned. Else the natural min width is returned.
- *
+ *
* @param columnIndex
* column index hint, if -1 (unknown) it will be detected
- *
+ *
* @return
*/
public int getNaturalColumnWidth(int columnIndex) {
/**
* HeaderCell that is header cell for row headers.
- *
+ *
* Reordering disabled and clicking on it resets sorting.
*/
public class RowHeadersHeaderCell extends HeaderCell {
/**
* Get's HeaderCell by it's column Key.
- *
+ *
* Note that this returns HeaderCell even if it is currently collapsed.
- *
+ *
* @param cid
* Column key of accessed HeaderCell
* @return HeaderCell
/**
* Sets the text of the footer
- *
+ *
* @param footerText
* The text in the footer
*/
/**
* Set alignment of the text in the cell
- *
+ *
* @param c
* The alignment which can be ALIGN_CENTER, ALIGN_LEFT,
* ALIGN_RIGHT
/**
* Get the alignment of the text int the cell
- *
+ *
* @return Returns either ALIGN_CENTER, ALIGN_LEFT or ALIGN_RIGHT
*/
public char getAlign() {
* Sets the width of the cell. This width should not include any
* possible indent modifications that are present in
* {@link VScrollTableBody#getMaxIndent()}.
- *
+ *
* @param w
* The width of the cell
* @param ensureDefinedWidth
/**
* Detects if width is fixed by developer on server side or resized to
* current width by user.
- *
+ *
* @return true if defined, false if "natural" width
*/
public boolean isDefinedWidth() {
/**
* Returns the pixels width of the footer cell.
- *
+ *
* @return The width in pixels
*/
public int getWidth() {
/**
* Sets the expand ratio of the cell
- *
+ *
* @param floatAttribute
* The expand ratio
*/
/**
* Returns the expand ration of the cell
- *
+ *
* @return The expand ratio
*/
public float getExpandRatio() {
/**
* Is the cell enabled?
- *
+ *
* @return True if enabled else False
*/
public boolean isEnabled() {
/**
* Handles a event on the captions
- *
+ *
* @param event
* The event to handle
*/
/**
* Fires a footer click event after the user has clicked a column footer
* cell
- *
+ *
* @param event
* The click event
*/
/**
* Returns the column key of the column
- *
+ *
* @return The column key
*/
public String getColKey() {
* Detects the natural minimum width for the column of this header cell.
* If column is resized by user or the width is defined by server the
* actual width is returned. Else the natural min width is returned.
- *
+ *
* @param columnIndex
* column index hint, if -1 (unknown) it will be detected
- *
+ *
* @return
*/
public int getNaturalColumnWidth(int columnIndex) {
/**
* HeaderCell that is header cell for row headers.
- *
+ *
* Reordering disabled and clicking on it resets sorting.
*/
public class RowHeadersFooterCell extends FooterCell {
/*
* (non-Javadoc)
- *
+ *
* @see
* com.google.gwt.user.client.ui.Panel#remove(com.google.gwt.user.client
* .ui.Widget)
/*
* (non-Javadoc)
- *
+ *
* @see com.google.gwt.user.client.ui.HasWidgets#iterator()
*/
/**
* Gets a footer cell which represents the given columnId
- *
+ *
* @param cid
* The columnId
- *
+ *
* @return The cell
*/
public FooterCell getFooterCell(String cid) {
/**
* Gets a footer cell by using a column index
- *
+ *
* @param index
* The index of the column
* @return The Cell
/**
* Updates the cells contents when updateUIDL request is received
- *
+ *
* @param uidl
* The UIDL
*/
/**
* Set a footer cell for a specified column index
- *
+ *
* @param index
* The index
* @param cell
/**
* Remove a cell by using the columnId
- *
+ *
* @param colKey
* The columnId to remove
*/
/**
* Enable a column (Sets the footer cell)
- *
+ *
* @param cid
* The columnId
* @param index
/**
* Set the horizontal position in the cell in the footer. This is done
* when a horizontal scrollbar is present.
- *
+ *
* @param scrollLeft
* The value of the leftScroll
*/
/**
* Swap cells when the column are dragged
- *
+ *
* @param oldIndex
* The old index of the cell
* @param newIndex
* This Panel can only contain VScrollTableRow type of widgets. This
* "simulates" very large table, keeping spacers which take room of
* unrendered rows.
- *
+ *
*/
public class VScrollTableBody extends Panel {
/*
* #8040 - scroll position is completely changed since the
* latest request, so request a new set of rows.
- *
+ *
* TODO: We should probably check whether the fetched rows match
* the current scroll position right when they arrive, so as to
* not waste time rendering a set of rows that will never be
} else if (firstRendered > reactFirstRow) {
/*
* Branch for fetching cache above visible area.
- *
+ *
* If cache needed for both before and after visible area, this
* will be rendered after-cache is received and rendered. So in
* some rare situations the table may make two cache visits to
/**
* Inserts rows as provided in the rowData starting at firstIndex.
- *
+ *
* @param rowData
* @param firstIndex
* @param rows
* This method is used to instantiate new rows for this table. It
* automatically sets correct widths to rows cells and assigns correct
* client reference for child widgets.
- *
+ *
* This method can be called only after table has been initialized
- *
+ *
* @param uidl
*/
private VScrollTableRow prepareRow(UIDL uidl) {
/**
* Returns the width available for column content.
- *
+ *
* @param columnIndex
* @return
*/
/**
* Sets the content width of a column.
- *
+ *
* Due IE limitation, we must set the width to a wrapper elements inside
* table cells (with overflow hidden, which does not work on td
* elements).
- *
+ *
* To get this work properly crossplatform, we will also set the width
* of td.
- *
+ *
* @param colIndex
* @param w
*/
* This method exists for the needs of {@link VTreeTable} only. May be
* removed or replaced in the future.</br> </br> Returns the maximum
* indent of the hierarcyColumn, if applicable.
- *
+ *
* @see {@link VScrollTable#getHierarchyColumnIndex()}
- *
+ *
* @return maximum indent in pixels
*/
protected int getMaxIndent() {
return -1;
}
- public class VScrollTableRow extends Panel implements ActionOwner,
- ContextMenuOwner {
+ public class VScrollTableRow extends Panel implements ActionOwner {
private static final int TOUCHSCROLL_TIMEOUT = 100;
private static final int DRAGMODE_MULTIROW = 2;
private String[] actionKeys = null;
private final TableRowElement rowElement;
private int index;
-
private Event touchStart;
+
+ private static final int TOUCH_CONTEXT_MENU_TIMEOUT = 500;
+ private Timer contextTouchTimeout;
private Timer dragTouchTimeout;
private int touchStartY;
private int touchStartX;
-
- private TouchContextProvider touchContextProvider = new TouchContextProvider(
- this);
-
private TooltipInfo tooltipInfo = null;
private Map<TableCellElement, TooltipInfo> cellToolTips = new HashMap<TableCellElement, TooltipInfo>();
private boolean isDragging = false;
/**
* Overriding this and returning true causes all text cells to be
* rendered as HTML.
- *
+ *
* @return always returns false in the default implementation
*/
protected boolean isRenderHtmlInCells() {
/**
* Detects whether row is visible in tables viewport.
- *
+ *
* @return
*/
public boolean isInViewPort() {
/**
* Makes a check based on indexes whether the row is before the
* compared row.
- *
+ *
* @param row1
* @return true if this rows index is smaller than in the row1
*/
/**
* Sets the index of the row in the whole table. Currently used just
* to set even/odd classname
- *
+ *
* @param indexInWholeTable
*/
private void setIndex(int indexInWholeTable) {
/**
* If there are registered click listeners, sends a click event and
* returns true. Otherwise, does nothing and returns false.
- *
+ *
* @param event
* @param targetTdOrTr
* @param immediate
/**
* Special handler for touch devices that support native scrolling
- *
+ *
* @return Whether the event was handled by this method.
*/
private boolean handleTouchEvent(final Event event) {
boolean touchEventHandled = false;
if (enabled && hasNativeTouchScrolling) {
- touchContextProvider.handleTouchEvent(event);
-
final Element targetTdOrTr = getEventTargetTdOrTr(event);
final int type = event.getTypeInt();
}
dragTouchTimeout.schedule(TOUCHSCROLL_TIMEOUT);
}
+
+ if (actionKeys != null) {
+ if (contextTouchTimeout == null) {
+ contextTouchTimeout = new Timer() {
+
+ @Override
+ public void run() {
+ if (touchStart != null) {
+ // Open the context menu if finger
+ // is held in place long enough.
+ showContextMenu(touchStart);
+ event.preventDefault();
+ touchStart = null;
+ }
+ }
+ };
+ }
+ contextTouchTimeout
+ .schedule(TOUCH_CONTEXT_MENU_TIMEOUT);
+ }
break;
case Event.ONTOUCHMOVE:
touchEventHandled = true;
if (isSignificantMove(event)) {
+ if (contextTouchTimeout != null) {
+ // Moved finger before the context menu timer
+ // expired, so let the browser handle this as a
+ // scroll.
+ contextTouchTimeout.cancel();
+ contextTouchTimeout = null;
+ }
if (!isDragging && dragTouchTimeout != null) {
// Moved finger before the drag timer expired,
// so let the browser handle this as a scroll.
case Event.ONTOUCHEND:
case Event.ONTOUCHCANCEL:
touchEventHandled = true;
+ if (contextTouchTimeout != null) {
+ contextTouchTimeout.cancel();
+ }
if (dragTouchTimeout != null) {
dragTouchTimeout.cancel();
}
Util.simulateClickFromTouchEvent(touchStart, this);
touchStart = null;
}
- touchContextProvider.cancel();
+ if (contextTouchTimeout != null) {
+ contextTouchTimeout.cancel();
+ }
break;
case Event.ONTOUCHMOVE:
if (isSignificantMove(event)) {
.getActiveScrollDelegate() == null)) {
startRowDrag(touchStart, type, targetTdOrTr);
}
- touchContextProvider.cancel();
+ if (contextTouchTimeout != null) {
+ contextTouchTimeout.cancel();
+ }
/*
* Avoid clicks and drags by clearing touch start
* flag.
}
}
}.schedule(TOUCHSCROLL_TIMEOUT);
+
+ if (contextTouchTimeout == null
+ && actionKeys != null) {
+ contextTouchTimeout = new Timer() {
+
+ @Override
+ public void run() {
+ if (touchStart != null) {
+ showContextMenu(touchStart);
+ touchStart = null;
+ }
+ }
+ };
+ }
+ if (contextTouchTimeout != null) {
+ contextTouchTimeout.cancel();
+ contextTouchTimeout
+ .schedule(TOUCH_CONTEXT_MENU_TIMEOUT);
+ }
}
break;
case Event.ONMOUSEDOWN:
/**
* Checks if the row represented by the row key has been selected
- *
+ *
* @param key
* The generated row key
*/
* target of the event should not be handled. If the event target is
* the row directly this method returns the TR element instead of
* the TD.
- *
+ *
* @param event
* @return TD or TR element that the event targets (the actual event
* target is this element or a child of it)
return getTdOrTr(eventTarget);
}
- @Override
public void showContextMenu(Event event) {
if (enabled && actionKeys != null) {
// Show context menu if there are registered action handlers
/**
* Has the row been selected?
- *
+ *
* @return Returns true if selected, else false
*/
public boolean isSelected() {
/**
* Is called when a user clicks an item when holding SHIFT key down.
* This will select a new range from the last focused row
- *
+ *
* @param deselectPrevious
* Should the previous selected range be deselected
*/
/*
* (non-Javadoc)
- *
+ *
* @see com.vaadin.client.ui.IActionOwner#getActions ()
*/
/**
* Ensure the component has a focus.
- *
+ *
* TODO the current implementation simply always calls focus for the
* component. In case the Table at some point implements focus/blur
* listeners, this method needs to be evolved to conditionally call
if (getTotalRows() == 0) {
/*
* Too wide header combined with no rows in the table.
- *
+ *
* No horizontal scrollbars would be displayed because
* there's no rows that grows too wide causing the
* scrollBody container div to overflow. Must explicitely
/**
* helper to set pixel size of head and body part
- *
+ *
* @param pixels
*/
private void setContentWidth(int pixels) {
/**
* Helper function to build html snippet for column or row headers
- *
+ *
* @param uidl
* possibly with values caption and icon
* @return html snippet containing possibly an icon + caption text
scrollTop = scrollBodyPanel.getScrollPosition();
/*
* #6970 - IE sometimes fires scroll events for a detached table.
- *
+ *
* FIXME initializedAndAttached should probably be renamed - its name
* doesn't seem to reflect its semantics. onDetach() doesn't set it to
* false, and changing that might break something else, so we need to
/**
* Moves the selection head to a specific row
- *
+ *
* @param row
* The row to where the selection head should move
* @return Returns true if focus was moved successfully, else false
/**
* Ensures that the row is visible
- *
+ *
* @param row
* The row to ensure is visible
*/
/**
* Handles the keyboard events handled by the table
- *
+ *
* @param event
* The keyboard event received
* @return true iff the navigation event was handled
/*
* (non-Javadoc)
- *
+ *
* @see
* com.google.gwt.event.dom.client.FocusHandler#onFocus(com.google.gwt.event
* .dom.client.FocusEvent)
/*
* (non-Javadoc)
- *
+ *
* @see
* com.google.gwt.event.dom.client.BlurHandler#onBlur(com.google.gwt.event
* .dom.client.BlurEvent)
/**
* Removes a key from a range if the key is found in a selected range
- *
+ *
* @param key
* The key to remove
*/
/**
* Can the Table be focused?
- *
+ *
* @return True if the table can be focused, else false
*/
public boolean isFocusable() {
/*
* (non-Javadoc)
- *
+ *
* @see com.vaadin.client.Focusable#focus()
*/
}
/**
- *
+ *
* @param keyCode
* @return true if the given keyCode is used by the table for navigation
*/
* Add this to the element mouse down event by using element.setPropertyJSO
* ("onselectstart",applyDisableTextSelectionIEHack()); Remove it then again
* when the mouse is depressed in the mouse up event.
- *
+ *
* @return Returns the JSO preventing text selection
*/
private static native JavaScriptObject getPreventTextSelectionIEHack()
addCloseHandler.removeHandler();
}
}
-
- public void totalRowsHaveChanged() {
- firstvisibleOnLastPage = -1;
- }
}