}
public ScrollTabBar(boolean decorated, boolean atBottom) {
super(new BoxLayout(atBottom?Alignment.START:Alignment.END));
final LayoutPanel layoutPanel = getLayoutPanel();
layoutPanel.setPadding(0);
layoutPanel.setWidgetSpacing(0);
if (decorated) {
if (atBottom) {
tabBar = new DecoratedBottomTabBar() {
@Override
protected void insertTabWidget(Widget widget, int beforeIndex) {
super.insertTabWidget(widget, beforeIndex);
tabs.add(beforeIndex, widget);
}
@Override
public void removeTab(int index) {
super.removeTab(index);
tabs.remove(index);
}
};
} else {
tabBar = new DecoratedTabBar() {
@Override
protected void insertTabWidget(Widget widget, int beforeIndex) {
super.insertTabWidget(widget, beforeIndex);
tabs.add(beforeIndex, widget);
}
@Override
public void removeTab(int index) {
super.removeTab(index);
tabs.remove(index);
}
};
}
} else {
tabBar = new TabBar() {
@Override
protected void insertTabWidget(Widget widget, int beforeIndex) {
super.insertTabWidget(widget, beforeIndex);
tabs.add(beforeIndex, widget);
}
@Override
public void removeTab(int index) {
super.removeTab(index);
tabs.remove(index);
}
};
}
tabBar.addSelectionHandler(new SelectionHandler<Integer>() {
public void onSelection(final SelectionEvent<Integer> event) {
DeferredCommand.addCommand(new Command() {
public void execute() {
invalidate();
scrollTabIntoView();
}
});
}
});
tabBarWrapper = createWrapper("tabBarWrapper");
tabBarWrapper.add(tabBar);
navBar = new HorizontalPanel();
navBar.addStyleName(DEFAULT_STYLENAME + "-NavBar");
navBar.setVisible(false);
scrollLeftBtn = new Button(Caption.IMAGES.toolArrowLeft().getHTML(),
new ClickHandler() {
public void onClick(ClickEvent event) {
createScrollAnimation();
scrollAnimation.scrollTabBar(ScrollTabBar.this, -1 * SCROLL_OFFSET,
isAnimationEnabled);
}
});
scrollLeftBtn.addMouseDownHandler(new MouseDownHandler() {
public void onMouseDown(MouseDownEvent event) {
scrollLeftBtnDown = true;
scrollLeftBtnTimer.scheduleRepeating(CoreConstants.DEFAULT_DELAY_MILLIS);
}
});
scrollLeftBtn.addMouseUpHandler(new MouseUpHandler() {
public void onMouseUp(MouseUpEvent event) {
scrollLeftBtnDown = false;
scrollLeftBtnTimer.cancel();
}
});
navBar.add(scrollLeftBtn);
scrollRightBtn = new Button(Caption.IMAGES.toolArrowRight().getHTML(),
new ClickHandler() {
public void onClick(ClickEvent event) {
createScrollAnimation();
scrollAnimation.scrollTabBar(ScrollTabBar.this, SCROLL_OFFSET,
isAnimationEnabled);
}
});
scrollRightBtn.addMouseDownHandler(new MouseDownHandler() {
public void onMouseDown(MouseDownEvent event) {
scrollRightBtnDown = true;
scrollRightBtnTimer.scheduleRepeating(CoreConstants.DEFAULT_DELAY_MILLIS);
}
});
scrollRightBtn.addMouseUpHandler(new MouseUpHandler() {
public void onMouseUp(MouseUpEvent event) {
scrollRightBtnDown = false;
scrollRightBtnTimer.cancel();
}
});
navBar.add(scrollRightBtn);
tabBarMenuBtn = new Button(Caption.IMAGES.toolArrowDown().getHTML(),
new ClickHandler() {
public void onClick(ClickEvent event) {
final PopupMenu menu = new PopupMenu();
menu.addItem(tabBar.getTabHTML(tabBar.getSelectedTab()), true,
new Command() {
public void execute() {
tabBar.selectTab(tabBar.getSelectedTab());
}
});
menu.addSeparator();
for (int i = 0, n = tabBar.getTabCount(); i < n; i++) {
final int index = i;
if (index != tabBar.getSelectedTab()) {
menu.addItem(tabBar.getTabHTML(i), true, new Command() {
public void execute() {
tabBar.selectTab(index);
}
});
}
}
menu.setPopupPositionAndShow(new PositionCallback() {
public void setPosition(int offsetWidth, int offsetHeight) {
final Dimension box = WidgetHelper.getOffsetSize(tabBarMenuBtn);
int left = DOM.getAbsoluteLeft(tabBarMenuBtn.getElement());
if (left + offsetWidth > Window.getClientWidth()) {
left += box.width - offsetWidth;
}
final int top = DOM.getAbsoluteTop(tabBarMenuBtn.getElement())
+ box.height;
menu.setPopupPosition(left, top);
}
});
}
});
navBar.add(tabBarMenuBtn);
layoutPanel.add(tabBarWrapper, new BoxLayoutData(FillStyle.HORIZONTAL));
layoutPanel.add(navBar);
DOM.setStyleAttribute(tabBarWrapper.getElement(), "overflow", "hidden");
addStyleName(DEFAULT_STYLENAME);
}