com.vaadin.ui.UI.getCurrent()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(267)

本文整理了Java中com.vaadin.ui.UI.getCurrent()方法的一些代码示例,展示了UI.getCurrent()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。UI.getCurrent()方法的具体详情如下:
包路径:com.vaadin.ui.UI
类名称:UI
方法名:getCurrent

UI.getCurrent介绍

[英]Gets the currently used UI. The current UI is automatically defined when processing requests to the server. In other cases, (e.g. from background threads), the current UI is not automatically defined.

The UI is stored using a weak reference to avoid leaking memory in case it is not explicitly cleared.
[中]获取当前使用的UI。当前UI在处理对服务器的请求时自动定义。在其他情况下(例如,来自后台线程),当前UI不会自动定义。
UI使用弱引用进行存储,以避免在未明确清除时泄漏内存。

代码示例

代码示例来源:origin: com.vaadin/vaadin-server

protected Class<?> getAssociatedClass() {
  if (associatedClass == null) {
    UI current = UI.getCurrent();
    if (current instanceof LegacyWindow) {
      LegacyWindow legacyWindow = (LegacyWindow) current;
      return legacyWindow.getApplication().getClass();
    } else {
      return current.getClass();
    }
  }
  return associatedClass;
}

代码示例来源:origin: com.vaadin/vaadin-server

private Locale findLocale() {
  Locale l = null;
  if (component != null) {
    l = component.getLocale();
  }
  if (l == null && UI.getCurrent() != null) {
    l = UI.getCurrent().getLocale();
  }
  if (l == null) {
    l = Locale.getDefault();
  }
  return l;
}

代码示例来源:origin: com.vaadin/vaadin-server

/**
 * Gets the Page to which the current uI belongs. This is automatically
 * defined when processing requests to the server. In other cases, (e.g.
 * from background threads), the current uI is not automatically defined.
 *
 * @see UI#getCurrent()
 *
 * @return the current page instance if available, otherwise
 *         <code>null</code>
 */
public static Page getCurrent() {
  UI currentUI = UI.getCurrent();
  if (currentUI == null) {
    return null;
  }
  return currentUI.getPage();
}

代码示例来源:origin: com.vaadin/vaadin-server

/**
 * Finds an appropriate locale to be used in conversion and validation.
 *
 * @return the found locale, not null
 */
protected Locale findLocale() {
  Locale l = null;
  if (getField() instanceof Component) {
    l = ((Component) getField()).getLocale();
  }
  if (l == null && UI.getCurrent() != null) {
    l = UI.getCurrent().getLocale();
  }
  if (l == null) {
    l = Locale.getDefault();
  }
  return l;
}

代码示例来源:origin: com.vaadin/vaadin-server

/**
 * Shows a notification message on the middle of the current page. The
 * message automatically disappears ("humanized message").
 *
 * The caption is rendered as plain text with HTML automatically escaped.
 *
 * @see #Notification(String)
 * @see #show(Page)
 *
 * @param caption
 *            The message
 * @return The Notification
 */
public static Notification show(String caption) {
  Notification notification = new Notification(caption);
  notification.extend(UI.getCurrent());
  return notification;
}

代码示例来源:origin: com.vaadin/vaadin-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) {
  assert hasLock() : "Session is locked";
  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";
  Integer id = Integer.valueOf(ui.getUIId());
  ui.setSession(null);
  uIs.remove(id);
  String embedId = ui.getEmbedId();
  if (embedId != null && id.equals(embedIdMap.get(embedId))) {
    embedIdMap.remove(embedId);
  }
}

代码示例来源:origin: com.vaadin/vaadin-server

/**
 * Sets the main window of this application. Setting window as a main window
 * of this application also adds the window to this application.
 *
 * @param mainWindow
 *            the UI to set as the default window
 */
public void setMainWindow(LegacyWindow mainWindow) {
  if (this.mainWindow != null) {
    throw new IllegalStateException("mainWindow has already been set");
  }
  if (mainWindow.isAttached()) {
    throw new IllegalStateException(
        "mainWindow is attached to another application");
  }
  if (UI.getCurrent() == null) {
    // Assume setting a main window from Application.init if there's
    // no current UI -> set the main window as the current UI
    UI.setCurrent(mainWindow);
  }
  addWindow(mainWindow);
  this.mainWindow = mainWindow;
}

代码示例来源:origin: com.vaadin/vaadin-server

/**
 * Shows a notification message the current page. The position and behavior
 * of the message depends on the type, which is one of the basic types
 * defined in {@link Notification}, for instance
 * {@link Type#WARNING_MESSAGE}.
 *
 * The caption is rendered as plain text with HTML automatically escaped.
 *
 * @see Notification(String, int)
 * @see #show(Page)
 *
 * @param caption
 *            The message
 * @param type
 *            The message type
 * @return The Notification
 */
public static Notification show(String caption, Type type) {
  Notification notification = new Notification(caption, type);
  notification.extend(UI.getCurrent());
  return notification;
}

代码示例来源:origin: com.vaadin/vaadin-server

/**
 * Shows a notification message the current page. The position and behavior
 * of the message depends on the type, which is one of the basic types
 * defined in {@link Notification}, for instance
 * Notification.TYPE_WARNING_MESSAGE.
 *
 * The caption is rendered as plain text with HTML automatically escaped.
 *
 * @see #Notification(String, Type)
 * @see #show(Page)
 *
 * @param caption
 *            The message
 * @param description
 *            The message description
 * @param type
 *            The message type
 * @return The Notification
 */
public static Notification show(String caption, String description,
    Type type) {
  Notification notification = new Notification(caption, description,
      type);
  notification.extend(UI.getCurrent());
  return notification;
}

代码示例来源:origin: com.vaadin/vaadin-server

VaadinRequest request) {
if (component == null) {
  component = UI.getCurrent();

代码示例来源:origin: com.haulmont.cuba/cuba-web

/**
 * @return current AppUI
 */
public static AppUI getCurrent() {
  return (AppUI) UI.getCurrent();
}

代码示例来源:origin: com.vaadin/vaadin-server

@Override
public boolean synchronizedHandleRequest(VaadinSession session,
    VaadinRequest request, VaadinResponse response) throws IOException {
  try {
    assert UI.getCurrent() == null;
    // Update browser information from the request
    session.getBrowser().updateRequestDetails(request);
    UI uI = getBrowserDetailsUI(request, session);
    session.getCommunicationManager().repaintAll(uI);
    JsonObject params = Json.createObject();
    params.put(UIConstants.UI_ID_PARAMETER, uI.getUIId());
    String initialUIDL = getInitialUidl(request, uI);
    params.put("uidl", initialUIDL);
    return commitJsonResponse(request, response,
        JsonUtil.stringify(params));
  } catch (JsonException e) {
    throw new IOException("Error producing initial UIDL", e);
  }
}

代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework

/**
 * @deprecated since 5.5.5 - use {@link #LocalMessageDispatcher(EventBus, UI)} instead.
 */
@Deprecated
public LocalMessageDispatcher(final EventBus eventBus, VaadinSession vaadinSession) {
  this(eventBus, UI.getCurrent());
}

代码示例来源:origin: OpenNMS/opennms

public void open() {
    if (UI.getCurrent() != null) {
      UI.getCurrent().addWindow(this);
    }
  }
}

代码示例来源:origin: OpenNMS/opennms

@Override
  public void refresh() {
    ((NodeMapsApplication)UI.getCurrent()).refresh();
  }
};

代码示例来源:origin: OpenNMS/opennms

public static <T extends UI> T getCurrent(Class<T> clazz) {
  final T ui = (T) UI.getCurrent();
  if (ui == null || !ui.isAttached()) {
    throw new IllegalStateException("UI is either null or not attached. Ensure it is invoked from within a VaadinRequest");
  }
  return ui;
}

代码示例来源:origin: com.vaadin/vaadin-server

try {
  ui = service.findUI(vaadinRequest);
  assert UI.getCurrent() == ui;

代码示例来源:origin: OpenNMS/opennms

private TopologyServiceClient getGraphProvider() {
  UI ui = UI.getCurrent();
  if (ui instanceof WidgetContext) {
    return ((WidgetContext) ui).getGraphContainer().getTopologyServiceClient();
  }
  return null;
}

代码示例来源:origin: OpenNMS/opennms

@Override
  public void buttonClick(Button.ClickEvent event) {
    UI.getCurrent().getNavigator().addViewChangeListener(HeaderLayout.this);
    UI.getCurrent().getNavigator().navigateTo("dashboard/" + m_nativeSelect.getContainerProperty(m_nativeSelect.getValue(), "title").getValue());
  }
});

代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework

public Window buildAndOpen() {
    Window window = new Window();
    window.setCaption(this.title);
    window.setContent(this.build());
    window.center();
    window.setModal(this.modal);
    UI.getCurrent().addWindow(window);
    return window;
  }
}

相关文章