import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.FlowPanel;
-import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RootPanel;
-import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.UIObject;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
private final TableFooter tFoot = new TableFooter();
- private final ScrollPanel bodyContainer = new ScrollPanel();
- private final FocusPanel bodyContainerFocus = new FocusPanel(bodyContainer);
+ private final FocusableScrollPanel scrollBodyPanel = new FocusableScrollPanel();
private int totalRows;
private int multiselectmode;
public VScrollTable() {
- bodyContainerFocus.setStyleName(CLASSNAME + "-body-wrapper");
+ scrollBodyPanel.setStyleName(CLASSNAME + "-body-wrapper");
/*
* Firefox auto-repeat works correctly only if we use a key press
* handler
*/
if (BrowserInfo.get().isGecko()) {
- bodyContainerFocus.addKeyPressHandler(this);
+ scrollBodyPanel.addKeyPressHandler(this);
} else {
- bodyContainerFocus.addKeyDownHandler(this);
+ scrollBodyPanel.addKeyDownHandler(this);
}
- bodyContainerFocus.addFocusHandler(this);
- bodyContainerFocus.addBlurHandler(this);
+ scrollBodyPanel.addFocusHandler(this);
+ scrollBodyPanel.addBlurHandler(this);
- bodyContainer.addScrollHandler(this);
- bodyContainer.setStyleName(CLASSNAME + "-body");
+ scrollBodyPanel.addScrollHandler(this);
+ scrollBodyPanel.setStyleName(CLASSNAME + "-body");
setStyleName(CLASSNAME);
add(tHead);
- add(bodyContainerFocus);
+ add(scrollBodyPanel);
add(tFoot);
rowRequestHandler = new RowRequestHandler();
if (firstvisible != lastRequestedFirstvisible && scrollBody != null) {
// received 'surprising' firstvisible from server: scroll there
firstRowInViewPort = firstvisible;
- bodyContainer.setScrollPosition((int) (firstvisible * scrollBody
+ scrollBodyPanel.setScrollPosition((int) (firstvisible * scrollBody
.getRowHeight()));
}
// run overflow fix for scrollable area
DeferredCommand.addCommand(new Command() {
public void execute() {
- Util.runWebkitOverflowAutoFix(bodyContainer
+ Util.runWebkitOverflowAutoFix(scrollBodyPanel
.getElement());
}
});
scrollBody.renderInitialRows(rowData, uidl
.getIntAttribute("firstrow"), uidl.getIntAttribute("rows"));
- bodyContainer.add(scrollBody);
+ scrollBodyPanel.add(scrollBody);
initialContentReceived = true;
if (isAttached()) {
sizeInit();
if (needsSpaceForHorizontalSrollbar) {
bodyHeight += Util.getNativeScrollbarSize();
}
- bodyContainer.setHeight(bodyHeight + "px");
- Util.runWebkitOverflowAutoFix(bodyContainer.getElement());
+ scrollBodyPanel.setHeight(bodyHeight + "px");
+ Util.runWebkitOverflowAutoFix(scrollBodyPanel.getElement());
}
isNewBody = false;
// without
DeferredCommand.addCommand(new Command() {
public void execute() {
- bodyContainer
+ scrollBodyPanel
.setScrollPosition((int) (firstvisible * scrollBody
.getRowHeight()));
firstRowInViewPort = firstvisible;
} else {
int fakeheight = (int) Math.round(scrollBody.getRowHeight()
* totalRows);
- int availableHeight = bodyContainer.getElement().getPropertyInt(
+ int availableHeight = scrollBodyPanel.getElement().getPropertyInt(
"clientHeight");
if (fakeheight > availableHeight) {
return true;
Style style = scrollPositionElement.getStyle();
style.setMarginLeft(getElement().getOffsetWidth() / 2 - 80, Unit.PX);
- style.setMarginTop(-bodyContainer.getOffsetHeight(), Unit.PX);
+ style.setMarginTop(-scrollBodyPanel.getOffsetHeight(), Unit.PX);
// indexes go from 1-totalRows, as rowheaders in index-mode indicate
int last = (firstRowInViewPort + pageLength);
cid, false);
}
// get also cache columns at the same request
- bodyContainer.setScrollPosition(0);
+ scrollBodyPanel.setScrollPosition(0);
firstvisible = 0;
rowRequestHandler.setReqFirstRow(0);
rowRequestHandler.setReqRows((int) (2 * pageLength
}
public int getAvailableWidth() {
- int availW = bodyContainer.getOffsetWidth() - getBorderWidth();
+ int availW = scrollBodyPanel.getOffsetWidth() - getBorderWidth();
return availW;
}
}
int rowHeight = (int) scrollBody.getRowHeight();
- int bodyH = bodyContainer.getOffsetHeight();
+ int bodyH = scrollBodyPanel.getOffsetHeight();
int rowsAtOnce = bodyH / rowHeight;
boolean anotherPartlyVisible = ((bodyH % rowHeight) != 0);
if (anotherPartlyVisible) {
if (currentlyVisible < pageLength
&& currentlyVisible < totalRows) {
// shake scrollpanel to fill empty space
- bodyContainer.setScrollPosition(scrollTop + 1);
- bodyContainer.setScrollPosition(scrollTop - 1);
+ scrollBodyPanel.setScrollPosition(scrollTop + 1);
+ scrollBodyPanel.setScrollPosition(scrollTop - 1);
}
}
}
bodyHeight += Util.getNativeScrollbarSize();
}
int heightBefore = getOffsetHeight();
- bodyContainer.setHeight(bodyHeight + "px");
+ scrollBodyPanel.setHeight(bodyHeight + "px");
if (heightBefore != getOffsetHeight()) {
Util.notifyParentOfSizeChange(VScrollTable.this, false);
}
scrollBody.reLayoutComponents();
DeferredCommand.addCommand(new Command() {
public void execute() {
- Util.runWebkitOverflowAutoFix(bodyContainer.getElement());
+ Util.runWebkitOverflowAutoFix(scrollBodyPanel.getElement());
}
});
}
*/
private void setContentWidth(int pixels) {
tHead.setWidth(pixels + "px");
- bodyContainer.setWidth(pixels + "px");
+ scrollBodyPanel.setWidth(pixels + "px");
tFoot.setWidth(pixels + "px");
}
*/
private int getBorderWidth() {
if (borderWidth < 0) {
- borderWidth = Util.measureHorizontalPaddingAndBorder(bodyContainer
- .getElement(), 2);
+ borderWidth = Util.measureHorizontalPaddingAndBorder(
+ scrollBodyPanel.getElement(), 2);
if (borderWidth < 0) {
borderWidth = 0;
}
if (contentH < 0) {
contentH = 0;
}
- bodyContainer.setHeight(contentH + "px");
+ scrollBodyPanel.setHeight(contentH + "px");
}
}
if (contentAreaBorderHeight < 0) {
if (BrowserInfo.get().isIE7() || BrowserInfo.get().isIE6()) {
contentAreaBorderHeight = Util
- .measureVerticalBorder(bodyContainer.getElement());
+ .measureVerticalBorder(scrollBodyPanel.getElement());
} else {
- DOM.setStyleAttribute(bodyContainer.getElement(), "overflow",
+ DOM.setStyleAttribute(scrollBodyPanel.getElement(), "overflow",
"hidden");
- int oh = bodyContainer.getOffsetHeight();
- int ch = bodyContainer.getElement().getPropertyInt(
+ int oh = scrollBodyPanel.getOffsetHeight();
+ int ch = scrollBodyPanel.getElement().getPropertyInt(
"clientHeight");
contentAreaBorderHeight = oh - ch;
- DOM.setStyleAttribute(bodyContainer.getElement(), "overflow",
+ DOM.setStyleAttribute(scrollBodyPanel.getElement(), "overflow",
"auto");
}
}
// Webkit may sometimes get an odd rendering bug (white space
// between header and body), see bug #3875. Running
// overflow hack here to shake body element a bit.
- Util.runWebkitOverflowAutoFix(bodyContainer.getElement());
+ Util.runWebkitOverflowAutoFix(scrollBodyPanel.getElement());
}
}
if (visible) {
DeferredCommand.addCommand(new Command() {
public void execute() {
- bodyContainer
+ scrollBodyPanel
.setScrollPosition((int) (firstRowInViewPort * scrollBody
.getRowHeight()));
}
* user scrolls
*/
public void onScroll(ScrollEvent event) {
- scrollLeft = bodyContainer.getElement().getScrollLeft();
- scrollTop = bodyContainer.getScrollPosition();
+ scrollLeft = scrollBodyPanel.getElement().getScrollLeft();
+ scrollTop = scrollBodyPanel.getScrollPosition();
if (!initializedAndAttached) {
return;
}
if (!enabled) {
- bodyContainer
+ scrollBodyPanel
.setScrollPosition((int) (firstRowInViewPort * scrollBody
.getRowHeight()));
return;
// Scroll up or down if needed
int rowTop = focusedRow.getElement().getAbsoluteTop();
- int scrollTop = bodyContainer.getElement().getAbsoluteTop();
+ int scrollTop = scrollBodyPanel.getElement().getAbsoluteTop();
int scrollBottom = scrollTop
- + bodyContainer.getElement().getOffsetHeight();
+ + scrollBodyPanel.getElement().getOffsetHeight();
if (rowTop > scrollBottom - focusedRow.getOffsetHeight()) {
- bodyContainer.setScrollPosition(bodyContainer
+ scrollBodyPanel.setScrollPosition(scrollBodyPanel
.getScrollPosition()
+ focusedRow.getOffsetHeight());
} else if (rowTop < scrollTop) {
- bodyContainer.setScrollPosition(bodyContainer
+ scrollBodyPanel.setScrollPosition(scrollBodyPanel
.getScrollPosition()
- focusedRow.getOffsetHeight());
}
// Down navigation
if (selectMode == SELECT_MODE_NONE && keycode == getNavigationDownKey()) {
- bodyContainer.setScrollPosition(bodyContainer.getScrollPosition()
+ scrollBodyPanel.setScrollPosition(scrollBodyPanel
+ .getScrollPosition()
+ scrollingVelocity);
return true;
} else if (keycode == getNavigationDownKey()) {
// Up navigation
if (selectMode == SELECT_MODE_NONE && keycode == getNavigationUpKey()) {
- bodyContainer.setScrollPosition(bodyContainer.getScrollPosition()
+ scrollBodyPanel.setScrollPosition(scrollBodyPanel
+ .getScrollPosition()
- scrollingVelocity);
return true;
} else if (keycode == getNavigationUpKey()) {
if (keycode == getNavigationLeftKey()) {
// Left navigation
- bodyContainer.setHorizontalScrollPosition(bodyContainer
+ scrollBodyPanel.setHorizontalScrollPosition(scrollBodyPanel
.getHorizontalScrollPosition()
- scrollingVelocity);
return true;
} else if (keycode == getNavigationRightKey()) {
// Right navigation
- bodyContainer.setHorizontalScrollPosition(bodyContainer
+ scrollBodyPanel.setHorizontalScrollPosition(scrollBodyPanel
.getHorizontalScrollPosition()
+ scrollingVelocity);
}
if (keycode == getNavigationPageDownKey()) {
int rowHeight = (int) scrollBody.getRowHeight();
int offset = pageLength * rowHeight - rowHeight;
- bodyContainer.setScrollPosition(bodyContainer.getScrollPosition()
+ scrollBodyPanel.setScrollPosition(scrollBodyPanel
+ .getScrollPosition()
+ offset);
if (selectMode > SELECT_MODE_NONE) {
if (!moveFocusDown(pageLength - 2)) {
if (keycode == getNavigationPageUpKey()) {
int rowHeight = (int) scrollBody.getRowHeight();
int offset = pageLength * rowHeight - rowHeight;
- bodyContainer.setScrollPosition(bodyContainer.getScrollPosition()
+ scrollBodyPanel.setScrollPosition(scrollBodyPanel
+ .getScrollPosition()
- offset);
if (selectMode > SELECT_MODE_NONE) {
if (!moveFocusUp(pageLength - 2)) {
selectFirstItemInNextRender = true;
}
}
- bodyContainer.setScrollPosition(0);
+ scrollBodyPanel.setScrollPosition(0);
return true;
}
selectLastItemInNextRender = true;
}
}
- bodyContainer.setScrollPosition(scrollBody.getOffsetHeight());
+ scrollBodyPanel.setScrollPosition(scrollBody.getOffsetHeight());
return true;
}
* .dom.client.FocusEvent)
*/
public void onFocus(FocusEvent event) {
- bodyContainer.addStyleName("focused");
+ scrollBodyPanel.addStyleName("focused");
// Focus a row if no row is in focus
if (focusedRow == null) {
* .dom.client.BlurEvent)
*/
public void onBlur(BlurEvent event) {
- bodyContainer.removeStyleName("focused");
+ scrollBodyPanel.removeStyleName("focused");
// Unfocus any row
setRowFocus(null);
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.FlowPanel;
-import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.UIObject;
import com.google.gwt.user.client.ui.Widget;
+import com.google.gwt.user.client.ui.impl.FocusImpl;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.BrowserInfo;
import com.vaadin.terminal.gwt.client.MouseEventDetails;
/**
*
*/
-public class VTree extends FocusPanel implements Paintable, VHasDropHandler,
- FocusHandler, BlurHandler, KeyPressHandler, KeyDownHandler {
+public class VTree extends SimpleFocusablePanel implements Paintable,
+ VHasDropHandler, FocusHandler, BlurHandler, KeyPressHandler,
+ KeyDownHandler {
public static final String CLASSNAME = "v-tree";
super();
setStyleName(CLASSNAME);
add(body);
-
+
addFocusHandler(this);
addBlurHandler(this);
"onselectstart", null);
}
} else if (event.getTypeInt() == Event.ONKEYUP) {
- if (selectionHasChanged) {
- if(event.getKeyCode() == getNavigationDownKey() && !event.getShiftKey()){
+ if (selectionHasChanged) {
+ if (event.getKeyCode() == getNavigationDownKey()
+ && !event.getShiftKey()) {
sendSelectionToServer();
event.preventDefault();
} else if (event.getKeyCode() == getNavigationUpKey()
}
}
+ private void setFocus(boolean focus) {
+ if (focus) {
+ FocusImpl.getFocusImplForPanel().focus(getElement());
+ } else {
+ FocusImpl.getFocusImplForPanel().blur(getElement());
+ }
+ }
+
private void updateActionMap(UIDL c) {
final Iterator it = c.getChildIterator();
while (it.hasNext()) {
* @param endNodeKey
* The end node key
*/
- private void selectNodeRange(String startNodeKey, String endNodeKey){
-
+ private void selectNodeRange(String startNodeKey, String endNodeKey) {
+
TreeNode startNode = keyToNode.get(startNodeKey);
TreeNode endNode = keyToNode.get(endNodeKey);
// The nodes have the same parent
- if(startNode.getParent() == endNode.getParent()){
+ if (startNode.getParent() == endNode.getParent()) {
doSiblingSelection(startNode, endNode);
// The start node is a grandparent of the end node
TreeNode commonParent = getCommonGrandParent(startNode, endNode);
TreeNode startBranch = null, endBranch = null;
-
+
// Find the children of the common parent
List<TreeNode> children;
- if(commonParent != null){
- children = commonParent.getChildren();
- }else{
+ if (commonParent != null) {
+ children = commonParent.getChildren();
+ } else {
children = new LinkedList<TreeNode>();
for (int w = 0; w < body.getWidgetCount(); w++) {
children.add((TreeNode) body.getWidget(w));
}
}
-
+
// Find the start and end branches
for (TreeNode node : children) {
if (nodeIsInBranch(startNode, node)) {
return true;
}
-
// Navigate left (close branch)
if (keycode == getNavigationLeftKey()) {
if (!focusedNode.isLeaf() && focusedNode.getState()) {
if (keycode == getNavigationSelectKey()) {
if (!focusedNode.isSelected()) {
selectNode(focusedNode, !isMultiselect
- || multiSelectMode == MULTISELECT_MODE_SIMPLE);
+ || multiSelectMode == MULTISELECT_MODE_SIMPLE);
} else {
deselectNode(focusedNode);
}
return KeyCodes.KEY_END;
}
-
-
}