本文整理了Java中com.vaadin.flow.component.UI
类的一些代码示例,展示了UI
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。UI
类的具体详情如下:
包路径:com.vaadin.flow.component.UI
类名称:UI
[英]The topmost component in any component hierarchy. There is one UI for every Vaadin instance in a browser window. A UI may either represent an entire browser window (or tab) or some part of a html page where a Vaadin application is embedded.
The UI is the server side entry point for various client side features that are not represented as components added to a layout, e.g notifications, sub windows, and executing javascript in the browser.
When a new UI instance is needed, typically because the user opens a URL in a browser window which points to e.g. VaadinServlet, the UI mapped to that servlet is opened. The selection is based on the UI
init parameter.
After a UI has been created by the application, it is initialized using #init(VaadinRequest).
[中]任何组件层次结构中最顶层的组件。浏览器窗口中的每个Vaadin实例都有一个UI。UI可以代表整个浏览器窗口(或选项卡),也可以代表嵌入Vaadin应用程序的html页面的某个部分。
UI是各种客户端功能的服务器端入口点,这些功能不表示为添加到布局中的组件,例如通知、子窗口和在浏览器中执行javascript。
当需要一个新的UI实例时,通常是因为用户在浏览器窗口中打开一个指向例如VaadinServlet的URL,映射到该servlet的UI就会打开。选择基于UI
init参数。
应用程序创建UI后,将使用#init(VaadinRequest)对其进行初始化。
代码示例来源:origin: com.vaadin/flow-server
/**
* Navigates forward. This has the same effect as if the user would press
* the forward button in the browser. This causes a
* {@link HistoryStateChangeEvent} to be fired asynchronously if the
* conditions described in the <a href=
* "https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onpopstate">
* onpopstate documentation</a> are met.
*/
public void forward() {
ui.getPage().executeJavaScript("history.forward()");
}
代码示例来源:origin: com.vaadin/flow-data
private Locale findLocale() {
Locale locale = null;
if (UI.getCurrent() != null) {
locale = UI.getCurrent().getLocale();
}
if (locale == null) {
locale = Locale.getDefault();
}
return locale;
}
代码示例来源:origin: com.vaadin/flow-server
/**
* Called by the framework to remove an UI instance from the session because
* it has been closed.
*
* @param ui
* the UI to remove
*/
public void removeUI(UI ui) {
checkHasLock();
assert UI.getCurrent() != null : "Current UI cannot be null";
assert ui != null : "Removed UI cannot be null";
assert UI.getCurrent().getUIId() == ui.getUIId() : "UIs don't match";
ui.getInternals().setSession(null);
uIs.remove(ui.getUIId());
}
代码示例来源:origin: com.vaadin/vaadin-spring
BeanStore getBeanStore(UI ui) {
BeanStore beanStore = uiStores.get(ui.getUIId());
if (beanStore == null) {
beanStore = new BeanStore(session);
uiStores.put(ui.getUIId(), beanStore);
ui.addDetachListener(this);
}
return beanStore;
}
代码示例来源:origin: org.rapidpm.vaadin/rapidpm-vaadin-cdi-m-impl
@Override
protected ContextualStorage newContextualStorage(Integer uiId) {
UI.getCurrent().addDetachListener(this::destroy);
return super.newContextualStorage(uiId);
}
代码示例来源:origin: com.vaadin/vaadin-context-menu-flow
private UI getCurrentUI() {
UI ui = UI.getCurrent();
if (ui == null) {
throw new IllegalStateException("UI instance is not available. "
+ "It means that you are calling this method "
+ "out of a normal workflow where it's always implicitly set. "
+ "That may happen if you call the method from the custom thread without "
+ "'UI::access' or from tests without proper initialization.");
}
return ui;
}
}
代码示例来源:origin: com.vaadin/vaadin-tabs-flow
@Override
protected void onAttach(AttachEvent attachEvent) {
getElement().getNode().runWhenAttached(ui -> ui.beforeClientResponse(
this,
context -> ui.getPage().executeJavaScript(
"$0.addEventListener('items-changed', "
+ "function(){ this.$server.updateSelectedTab(true); });",
getElement())));
}
代码示例来源:origin: com.vaadin/vaadin-cdi
public ContextualStorage getContextualStorage(boolean createIfNotExist) {
final Integer uiId = UI.getCurrent().getUIId();
return super.getContextualStorage(uiId, createIfNotExist);
}
代码示例来源:origin: com.vaadin/flow-server
private void queueBeforeExecutionCallback() {
if (lifecycleOwner == null || !lifecycleOwner.getUI().isPresent()) {
return;
}
if (executionRegistration != null) {
executionRegistration.remove();
}
executionRegistration = lifecycleOwner.getUI().get()
.beforeClientResponse(lifecycleOwner,
beforeClientResponseConsumer);
}
代码示例来源:origin: com.vaadin/vaadin-context-menu-flow
ui -> ui.beforeClientResponse(this, context -> ui.getPage()
.executeJavaScript("$0.listenOn=$1", this, target)));
ui -> ui.beforeClientResponse(target, context -> {
ui.getInternals()
.addComponentDependencies(ContextMenuBase.class);
ui.getPage().executeJavaScript(
"window.Vaadin.Flow.contextMenuConnector.init($0)",
target.getElement());
代码示例来源:origin: com.vaadin/vaadin-notification-flow
/**
* Opens or closes the notification.
* <p>
* Note: You don't need to add the component anywhere before opening it.
* Since {@code <vaadin-notification>}'s location in the DOM doesn't really
* matter, opening a notification will automatically add it to the
* {@code <body>} if it's not yet attached anywhere.
*
* @param opened
* {@code true} to open the notification, {@code false} to close
* it
*/
@Override
public void setOpened(boolean opened) {
UI ui = UI.getCurrent();
if (ui == null) {
throw new IllegalStateException("UI instance is not available. "
+ "It means that you are calling this method "
+ "out of a normal workflow where it's always implicitely set. "
+ "That may happen if you call the method from the custom thread without "
+ "'UI::access' or from tests without proper initialization.");
}
if (opened && getElement().getNode().getParent() == null) {
ui.beforeClientResponse(ui, context -> {
ui.add(this);
autoAddedToTheUi = true;
});
}
super.setOpened(opened);
}
代码示例来源:origin: com.vaadin/vaadin-text-field-flow
private static void execJS(Component component, String js) {
StateNode node = component.getElement().getNode();
node.runWhenAttached(ui -> ui.getInternals().getStateTree()
.beforeClientResponse(node, context -> ui.getPage()
.executeJavaScript(js, component.getElement())));
}
代码示例来源:origin: appreciated/vaadin-app-layout
public String getRoute() {
if (className != null) {
return UI.getCurrent().getRouter().getUrl(className);
} else if (view != null) {
return UI.getCurrent().getRouter().getUrl(view.getClass());
} else {
return getCaption();
}
}
代码示例来源:origin: com.vaadin/flow-server
private static AtmospherePushConnection getConnectionForUI(UI ui) {
PushConnection pushConnection = ui.getInternals().getPushConnection();
if (pushConnection instanceof AtmospherePushConnection) {
return (AtmospherePushConnection) pushConnection;
} else {
return null;
}
}
代码示例来源:origin: com.vaadin/vaadin-cdi
private void destroy(DetachEvent event) {
final int uiId = event.getUI().getUIId();
super.destroy(uiId);
}
}
代码示例来源:origin: com.vaadin/vaadin-confirm-dialog-flow
private void ensureAttached() {
if (getElement().getNode().getParent() == null) {
UI ui = getCurrentUI();
ui.beforeClientResponse(ui, context -> {
ui.add(this);
autoAddedToTheUi = true;
});
}
}
}
代码示例来源:origin: com.vaadin/flow-server
JsonObject response = Json.createObject();
UIInternals uiInternals = ui.getInternals();
VaadinSession session = ui.getSession();
VaadinService service = session.getService();
nextClientToServerMessageId);
SystemMessages messages = ui.getSession().getService()
.getSystemMessages(ui.getLocale(), null);
encodeExecuteJavaScriptList(executeJavaScriptList));
if (ui.getSession().getService().getDeploymentConfiguration()
.isRequestTiming()) {
response.put("timings", createPerformanceData(ui));
代码示例来源:origin: com.vaadin/flow-server
/**
* Closes those UIs in the given session for which {@link #isUIActive}
* yields false.
*/
private void closeInactiveUIs(VaadinSession session) {
final String sessionId = session.getSession().getId();
for (final UI ui : session.getUIs()) {
if (!isUIActive(ui) && !ui.isClosing()) {
ui.accessSynchronously(() -> {
getLogger().debug("Closing inactive UI #{} in session {}",
ui.getUIId(), sessionId);
ui.close();
});
}
}
}
代码示例来源:origin: com.vaadin/flow-server
/**
* Removes those UIs from the given session for which {@link UI#isClosing()
* isClosing} yields true.
*
* @param session
*/
private void removeClosedUIs(final VaadinSession session) {
List<UI> uis = new ArrayList<>(session.getUIs());
for (final UI ui : uis) {
if (ui.isClosing()) {
ui.accessSynchronously(() -> {
getLogger().debug("Removing closed UI {}", ui.getUIId());
session.removeUI(ui);
});
}
}
}
代码示例来源:origin: vaadin/spring
@Override
public void run() {
// We can acquire the lock after the request started this thread is processed
// Needed to make sure that this is sent as a push message
Lock lockInstance = ui.getSession().getLockInstance();
lockInstance.lock();
lockInstance.unlock();
ui.access(() -> execute(ui));
}
内容来源于网络,如有侵权,请联系作者删除!