|
|
|
|
|
|
|
|
*/ |
|
|
*/ |
|
|
package com.vaadin.client.ui.ui; |
|
|
package com.vaadin.client.ui.ui; |
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
import java.util.Arrays; |
|
|
|
|
|
import java.util.Collections; |
|
|
|
|
|
import java.util.Comparator; |
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
import java.util.HashSet; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
import java.util.logging.Logger; |
|
|
|
|
|
|
|
|
|
|
|
import com.google.gwt.core.client.Scheduler; |
|
|
import com.google.gwt.core.client.Scheduler; |
|
|
import com.google.gwt.dom.client.Document; |
|
|
import com.google.gwt.dom.client.Document; |
|
|
import com.google.gwt.dom.client.Element; |
|
|
import com.google.gwt.dom.client.Element; |
|
|
|
|
|
|
|
|
import com.vaadin.shared.ui.ui.UIState; |
|
|
import com.vaadin.shared.ui.ui.UIState; |
|
|
import com.vaadin.shared.util.SharedUtil; |
|
|
import com.vaadin.shared.util.SharedUtil; |
|
|
import com.vaadin.ui.UI; |
|
|
import com.vaadin.ui.UI; |
|
|
|
|
|
|
|
|
import elemental.client.Browser; |
|
|
import elemental.client.Browser; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
import java.util.Arrays; |
|
|
|
|
|
import java.util.Collections; |
|
|
|
|
|
import java.util.Comparator; |
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
import java.util.HashSet; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
import java.util.logging.Logger; |
|
|
|
|
|
|
|
|
@Connect(value = UI.class, loadStyle = LoadStyle.EAGER) |
|
|
@Connect(value = UI.class, loadStyle = LoadStyle.EAGER) |
|
|
public class UIConnector extends AbstractSingleComponentContainerConnector |
|
|
public class UIConnector extends AbstractSingleComponentContainerConnector |
|
|
implements Paintable, MayScrollChildren { |
|
|
implements Paintable, MayScrollChildren { |
|
|
|
|
|
|
|
|
if (uidl.hasAttribute("focused")) { |
|
|
if (uidl.hasAttribute("focused")) { |
|
|
// set focused component when render phase is finished |
|
|
// set focused component when render phase is finished |
|
|
Scheduler.get().scheduleDeferred(() -> { |
|
|
Scheduler.get().scheduleDeferred(() -> { |
|
|
ComponentConnector connector = (ComponentConnector) uidl |
|
|
|
|
|
.getPaintableAttribute("focused", getConnection()); |
|
|
|
|
|
|
|
|
Timer timer = new Timer() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void run() { |
|
|
|
|
|
ComponentConnector connector = (ComponentConnector) uidl |
|
|
|
|
|
.getPaintableAttribute("focused", |
|
|
|
|
|
getConnection()); |
|
|
|
|
|
|
|
|
if (connector == null) { |
|
|
|
|
|
// Do not try to focus invisible components which not |
|
|
|
|
|
// present in UIDL |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
focus(connector); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
final Widget toBeFocused = connector.getWidget(); |
|
|
|
|
|
/* |
|
|
|
|
|
* Two types of Widgets can be focused, either implementing GWT |
|
|
|
|
|
* Focusable of a thinner Vaadin specific Focusable interface. |
|
|
|
|
|
*/ |
|
|
|
|
|
if (toBeFocused instanceof com.google.gwt.user.client.ui.Focusable) { |
|
|
|
|
|
final com.google.gwt.user.client.ui.Focusable toBeFocusedWidget = (com.google.gwt.user.client.ui.Focusable) toBeFocused; |
|
|
|
|
|
toBeFocusedWidget.setFocus(true); |
|
|
|
|
|
} else if (toBeFocused instanceof Focusable) { |
|
|
|
|
|
((Focusable) toBeFocused).focus(); |
|
|
|
|
|
} else { |
|
|
|
|
|
getLogger().severe( |
|
|
|
|
|
"Server is trying to set focus to the widget of connector " |
|
|
|
|
|
+ Util.getConnectorString(connector) |
|
|
|
|
|
+ " but it is not focusable. The widget should implement either " |
|
|
|
|
|
+ com.google.gwt.user.client.ui.Focusable.class |
|
|
|
|
|
.getName() |
|
|
|
|
|
+ " or " + Focusable.class.getName()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
timer.schedule(0); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void focus(ComponentConnector connector) { |
|
|
|
|
|
if (connector == null) { |
|
|
|
|
|
// Do not try to focus invisible components which not |
|
|
|
|
|
// present in UIDL |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final Widget toBeFocused = connector.getWidget(); |
|
|
|
|
|
/* |
|
|
|
|
|
* Two types of Widgets can be focused, either implementing GWT |
|
|
|
|
|
* Focusable of a thinner Vaadin specific Focusable interface. |
|
|
|
|
|
*/ |
|
|
|
|
|
if (toBeFocused instanceof com.google.gwt.user.client.ui.Focusable) { |
|
|
|
|
|
final com.google.gwt.user.client.ui.Focusable toBeFocusedWidget = (com.google.gwt.user.client.ui.Focusable) toBeFocused; |
|
|
|
|
|
toBeFocusedWidget.setFocus(true); |
|
|
|
|
|
} else if (toBeFocused instanceof Focusable) { |
|
|
|
|
|
((Focusable) toBeFocused).focus(); |
|
|
|
|
|
} else { |
|
|
|
|
|
getLogger().severe( |
|
|
|
|
|
"Server is trying to set focus to the widget of connector " |
|
|
|
|
|
+ Util.getConnectorString(connector) |
|
|
|
|
|
+ " but it is not focusable. The widget should implement either " |
|
|
|
|
|
+ com.google.gwt.user.client.ui.Focusable.class |
|
|
|
|
|
.getName() |
|
|
|
|
|
+ " or " + Focusable.class.getName()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Reads CSS strings and resources injected by {@link Styles#inject} from |
|
|
* Reads CSS strings and resources injected by {@link Styles#inject} from |
|
|
* the UIDL stream. |
|
|
* the UIDL stream. |