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.EventId;
import com.vaadin.terminal.gwt.client.Focusable;
import com.vaadin.terminal.gwt.client.Paintable;
import com.vaadin.terminal.gwt.client.RenderInformation;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.VCaption;
-import com.vaadin.terminal.gwt.client.VConsole;
public class VTabsheet extends VTabsheetBase implements Focusable,
FocusHandler, BlurHandler, KeyDownHandler {
this.tabBar = tabBar;
setStyleName(td, TD_CLASSNAME);
- div = focusImpl.createFocusable();
- focusImpl.setTabIndex(div, -1);
+ div = DOM.createDiv();
+ focusImpl.setTabIndex(td, -1);
setStyleName(div, DIV_CLASSNAME);
DOM.appendChild(td, div);
public void setEnabledOnServer(boolean enabled) {
enabledOnServer = enabled;
setStyleName(td, TD_DISABLED_CLASSNAME, !enabled);
+ if (!enabled) {
+ focusImpl.setTabIndex(td, -1);
+ }
}
public void addClickHandler(ClickHandler handler) {
*/
public void setStyleNames(boolean selected, boolean first) {
// TODO #5100 doesn't belong here
- focusImpl.setTabIndex(div, selected ? 0 : -1);
+ focusImpl.setTabIndex(td, selected ? getTabsheet().tabulatorIndex
+ : -1);
setStyleName(td, TD_FIRST_CLASSNAME, first);
setStyleName(td, TD_SELECTED_CLASSNAME, selected);
setStyleName(div, DIV_SELECTED_CLASSNAME, selected);
}
- public void onClose() {
- VConsole.log("OnClose");
+ public boolean isClosable() {
+ return tabCaption.isClosable();
+ }
+ public void onClose() {
closeHandler.onClose(new VCloseEvent(this));
- VConsole.log("End OnClose");
}
public VTabsheet getTabsheet() {
}
public void focus() {
- focusImpl.focus(div);
+ focusImpl.focus(td);
}
public void blur() {
- focusImpl.blur(div);
+ focusImpl.blur(td);
}
}
}
}
+ public boolean isClosable() {
+ return closable;
+ }
+
@Override
public int getRequiredWidth() {
int width = super.getRequiredWidth();
Widget caption = (Widget) event.getSource();
int index = getWidgetIndex(caption.getParent());
getTabsheet().onTabSelected(index);
- getTabsheet().focus();
}
public VTabsheet getTabsheet() {
private Tab focusedTab;
+ private int tabulatorIndex = 0;
+
/**
* The index of the first visible tab (when scrolled)
*/
private String currentStyle;
- private void onTabSelected(final int tabIndex) {
+ /**
+ * @return Whether the tab could be selected or not.
+ */
+ private boolean onTabSelected(final int tabIndex) {
if (disabled || waitingForResponse) {
- return;
+ return false;
}
final Object tabKey = tabKeys.get(tabIndex);
if (disabledTabKeys.contains(tabKey)) {
- return;
+ return false;
}
if (client != null && activeTabIndex != tabIndex) {
tb.selectTab(tabIndex);
if (focusedTab != null) {
- focusedTab.blur();
- tb.getTab(tabIndex).focus();
+ focusedTab = tb.getTab(tabIndex);
}
addStyleDependentName("loading");
}
});
waitingForResponse = true;
+
+ return true;
}
+ return false;
}
public ApplicationConnection getApplicationConnection() {
updateOpenTabSize();
}
+ if (uidl.hasAttribute("tabindex")) {
+ tabulatorIndex = uidl.getIntAttribute("tabindex");
+ if (tabulatorIndex == -1) {
+ blur();
+ }
+ }
+
// If a tab was focused before, focus the new active tab
- if (focusedTab != null && tb.getTabCount() > 0) {
- focusedTab = tb.getTab(activeTabIndex);
- focusedTab.focus();
+ if (focusedTab != null && tb.getTabCount() > 0 && tabulatorIndex != -1) {
+ focus();
}
iLayout();
updateOpenTabSize();
VTabsheet.this.removeStyleDependentName("loading");
if (previousVisibleWidget != null) {
- // DOM.setStyleAttribute(
- // DOM.getParent(previousVisibleWidget.getElement()),
- // "visibility", "");
+ DOM.setStyleAttribute(
+ DOM.getParent(previousVisibleWidget.getElement()),
+ "visibility", "");
previousVisibleWidget = null;
}
}
}
public void onBlur(BlurEvent event) {
- focusedTab = null;
- // TODO Auto-generated method stub
- VConsole.log("BLUR " + event);
+ if (focusedTab != null && event.getSource() instanceof Tab) {
+ focusedTab = null;
+ if (client.hasEventListeners(this, EventId.BLUR)) {
+ client.updateVariable(id, EventId.BLUR, "", true);
+ }
+ }
}
public void onFocus(FocusEvent event) {
- // TODO Auto-generated method stub
- VConsole.log("FOCUS " + event);
- if (event.getSource() instanceof Tab) {
+ if (focusedTab == null && event.getSource() instanceof Tab) {
focusedTab = (Tab) event.getSource();
+ if (client.hasEventListeners(this, EventId.FOCUS)) {
+ client.updateVariable(id, EventId.FOCUS, "", true);
+ }
}
}
public void focus() {
- if (focusedTab == null) {
- focusedTab = tb.getTab(activeTabIndex);
- focusedTab.focus();
- }
+ tb.getTab(activeTabIndex).focus();
}
public void blur() {
- if (focusedTab != null) {
- focusedTab.blur();
- focusedTab = null;
- }
+ tb.getTab(activeTabIndex).blur();
}
public void onKeyDown(KeyDownEvent event) {
if (event.getSource() instanceof Tab) {
- VConsole.log("KEYDOWN");
int keycode = event.getNativeEvent().getKeyCode();
+
if (keycode == getPreviousTabKey()) {
- int newTabIndex = activeTabIndex == 0 ? tb.getTabCount() - 1
- : activeTabIndex - 1;
- onTabSelected(newTabIndex);
+ int newTabIndex = activeTabIndex;
+ // Find the previous non-disabled tab with wraparound.
+ do {
+ newTabIndex = (newTabIndex != 0) ? newTabIndex - 1 : tb
+ .getTabCount() - 1;
+ } while (newTabIndex != activeTabIndex
+ && !onTabSelected(newTabIndex));
activeTabIndex = newTabIndex;
+
+ // Tab scrolling
+ if (isScrolledTabs()) {
+ int newFirstIndex = tb.scrollLeft(scrollerIndex);
+ if (newFirstIndex != -1) {
+ scrollerIndex = newFirstIndex;
+ updateTabScroller();
+ }
+ }
+
} else if (keycode == getNextTabKey()) {
- int newTabIndex = (activeTabIndex + 1) % tb.getTabCount();
- onTabSelected(newTabIndex);
+ int newTabIndex = activeTabIndex;
+ // Find the next non-disabled tab with wraparound.
+ do {
+ newTabIndex = (newTabIndex + 1) % tb.getTabCount();
+ } while (newTabIndex != activeTabIndex
+ && !onTabSelected(newTabIndex));
activeTabIndex = newTabIndex;
+
+ if (isClippedTabs()) {
+ int newFirstIndex = tb.scrollRight(scrollerIndex);
+ if (newFirstIndex != -1) {
+ scrollerIndex = newFirstIndex;
+ updateTabScroller();
+ }
+ }
+
} else if (keycode == getCloseTabKey()) {
- VConsole.log("INDEX=" + activeTabIndex);
- focusedTab.onClose();
- removeTab(activeTabIndex);
+ Tab tab = tb.getTab(activeTabIndex);
+ if (tab.isClosable()) {
+ tab.onClose();
+ removeTab(activeTabIndex);
+ }
}
- VConsole.log("tabindex -> " + activeTabIndex);
}
}
import com.vaadin.event.FieldEvents.BlurEvent;
import com.vaadin.event.FieldEvents.BlurListener;
+import com.vaadin.event.FieldEvents.BlurNotifier;
import com.vaadin.event.FieldEvents.FocusEvent;
import com.vaadin.event.FieldEvents.FocusListener;
+import com.vaadin.event.FieldEvents.FocusNotifier;
import com.vaadin.terminal.ErrorMessage;
import com.vaadin.terminal.KeyMapper;
import com.vaadin.terminal.PaintException;
@SuppressWarnings("serial")
@ClientWidget(VTabsheet.class)
public class TabSheet extends AbstractComponentContainer implements Focusable,
- FocusListener, BlurListener {
+ FocusNotifier, BlurNotifier {
/**
* List of component tabs (tab contents). In addition to being on this list,
closeHandler.onTabClose(this, tab);
}
}
+ if (variables.containsKey(FocusEvent.EVENT_ID)) {
+ fireEvent(new FocusEvent(this));
+ }
+ if (variables.containsKey(BlurEvent.EVENT_ID)) {
+ fireEvent(new BlurEvent(this));
+ }
}
/**
return components.indexOf(tab.getComponent());
}
- public void blur(BlurEvent event) {
- // TODO Auto-generated method stub
-
- }
-
- public void focus(FocusEvent event) {
- // TODO Auto-generated method stub
- }
-
@Override
public void focus() {
super.focus();
requestRepaint();
}
+ public void addListener(BlurListener listener) {
+ addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener,
+ BlurListener.blurMethod);
+ }
+
+ public void removeListener(BlurListener listener) {
+ removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener);
+ }
+
+ public void addListener(FocusListener listener) {
+ addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener,
+ FocusListener.focusMethod);
+ }
+
+ public void removeListener(FocusListener listener) {
+ removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener);
+
+ }
}