-/*
+/*
@ITMillApache2LicenseForJavaFiles@
*/
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.BrowserInfo;
import com.vaadin.terminal.gwt.client.Container;
+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.RenderSpace;
import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.ShortcutActionHandlerOwner;
public class VPanel extends SimplePanel implements Container,
- ShortcutActionHandlerOwner {
+ ShortcutActionHandlerOwner, Focusable {
public static final String CLICK_EVENT_IDENTIFIER = "click";
public static final String CLASSNAME = "v-panel";
bottomDecoration.setClassName(CLASSNAME + "-deco");
getElement().appendChild(captionWrap);
+
+ /*
+ * Make contentNode focusable only by using the setFocus() method. This
+ * behaviour can be changed by invoking setTabIndex() in the serverside
+ * implementation
+ */
+ contentNode.setTabIndex(-1);
+
getElement().appendChild(contentNode);
+
getElement().appendChild(bottomDecoration);
setStyleName(CLASSNAME);
DOM.sinkEvents(getElement(), Event.ONKEYDOWN);
}
+ /**
+ * Sets the keyboard focus on the Panel
+ *
+ * @param focus
+ * Should the panel have focus or not.
+ */
+ public void setFocus(boolean focus) {
+ if (focus) {
+ getContainerElement().focus();
+ } else {
+ getContainerElement().blur();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.terminal.gwt.client.Focusable#focus()
+ */
+ public void focus() {
+ setFocus(true);
+
+ }
+
@Override
protected Element getContainerElement() {
return contentNode;
// scrollTop
runHacks(false);
+ // And apply tab index
+ if (uidl.hasVariable("tabindex")) {
+ contentNode.setTabIndex(uidl.getIntVariable("tabindex"));
+ }
+
rendering = false;
}
*
*/
public class VView extends SimplePanel implements Container, ResizeHandler,
- Window.ClosingHandler, ShortcutActionHandlerOwner {
+ Window.ClosingHandler, ShortcutActionHandlerOwner, Focusable {
private static final String CLASSNAME = "v-view";
public VView() {
super();
setStyleName(CLASSNAME);
+
+ // Allow focusing the view by using the focus() method, the view
+ // should not be in the document focus flow
+ getElement().setTabIndex(-1);
}
/**
DOM.setStyleAttribute(fElem, "position", "absolute");
DOM.setStyleAttribute(fElem, "opacity", "0.1");
DOM.appendChild(getElement(), fElem);
- Util.focus(fElem);
+ fElem.focus();
} else {
- Util.focus(getElement());
+ getElement().focus();
}
parentFrame = getParentFrame();
return actionHandler;
}
+ public void focus() {
+ getElement().focus();
+ }
+
}
-/*
+/*
@ITMillApache2LicenseForJavaFiles@
*/
import com.vaadin.terminal.gwt.client.BrowserInfo;
import com.vaadin.terminal.gwt.client.Container;
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.RenderSpace;
import com.vaadin.terminal.gwt.client.UIDL;
*/
public class VWindow extends VOverlay implements Container,
ShortcutActionHandlerOwner, ScrollHandler, KeyDownHandler,
- FocusHandler, BlurHandler, BeforeShortcutActionListener {
+ FocusHandler, BlurHandler, BeforeShortcutActionListener, Focusable {
/**
* Minimum allowed height of a window. This refers to the content area, not
// blur/focus )
}
+ public void focus() {
+ contentPanel.focus();
+ }
+
}
-/*
+/*
@ITMillApache2LicenseForJavaFiles@
*/
import com.vaadin.terminal.Scrollable;
import com.vaadin.terminal.gwt.client.MouseEventDetails;
import com.vaadin.terminal.gwt.client.ui.VPanel;
+import com.vaadin.ui.Component.Focusable;
import com.vaadin.ui.themes.Reindeer;
import com.vaadin.ui.themes.Runo;
@ClientWidget(VPanel.class)
public class Panel extends AbstractComponentContainer implements Scrollable,
ComponentContainer.ComponentAttachListener,
- ComponentContainer.ComponentDetachListener, Action.Notifier {
+ ComponentContainer.ComponentDetachListener, Action.Notifier, Focusable {
private static final String CLICK_EVENT = VPanel.CLICK_EVENT_IDENTIFIER;
*/
protected ActionManager actionManager;
+ /**
+ * By default the Panel is not in the normal document focus flow and can
+ * only be focused by using the focus()-method. Change this to 0 if you want
+ * to have the Panel in the normal focus flow.
+ */
+ private int tabIndex = -1;
+
/**
* Creates a new empty panel. A VerticalLayout is used as content.
*/
public void paintContent(PaintTarget target) throws PaintException {
content.paint(target);
+ target.addVariable(this, "tabindex", getTabIndex());
+
if (isScrollable()) {
target.addVariable(this, "scrollLeft", getScrollLeft());
target.addVariable(this, "scrollTop", getScrollTop());
fireEvent(new ClickEvent(this, mouseDetails));
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getTabIndex() {
+ return tabIndex;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setTabIndex(int tabIndex) {
+ this.tabIndex = tabIndex;
+ requestRepaint();
+ }
+
+ /**
+ * Moves keyboard focus to the component. {@see Focusable#focus()}
+ *
+ */
+ @Override
+ public void focus() {
+ super.focus();
+ }
+
}
-/*
+/*
@ITMillApache2LicenseForJavaFiles@
*/
if (parent == null) {
fireClose();
} else {
+
+ // focus is restored to the parent window
+ parent.focus();
+
// subwindow is removed from parent
parent.removeWindow(this);
}
* <code>
* // within the window using helper
* subWindow.setCloseShortcut(KeyCode.ESCAPE, null);
- *
+ *
* // or globally
* getWindow().addAction(new Window.CloseShortcut(subWindow, KeyCode.ESCAPE));
* </code>
removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener);
}
+ /**
+ * {@inheritDoc}
+ *
+ * If the window is a sub-window focusing will cause the sub-window to be
+ * brought on top of other sub-windows on gain keyboard focus.
+ */
+ @Override
+ public void focus() {
+ if (getParent() != null) {
+ /*
+ * When focusing a sub-window it basically means it should be
+ * brought to the front. Instead of just moving the keyboard focus
+ * we focus the window and bring it top-most.
+ */
+ bringToFront();
+ } else {
+ super.focus();
+ }
+ }
+
}