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

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

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

UI.setCurrent介绍

[英]Sets the thread local for the current UI. This method is used by the framework to set the current application whenever a new request is processed and it is cleared when the request has been processed.

The application developer can also use this method to define the current UI outside the normal request handling, e.g. when initiating custom background threads.

The UI is stored using a weak reference to avoid leaking memory in case it is not explicitly cleared.
[中]为当前UI设置线程本地。框架使用此方法在处理新请求时设置当前应用程序,并在处理请求时清除。
应用程序开发人员还可以使用此方法在正常请求处理之外定义当前UI,例如在启动自定义后台线程时。
UI使用弱引用进行存储,以避免在未明确清除时泄漏内存。

代码示例

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

/**
 * Updates a UI that has already been initialized but is now loaded again,
 * e.g. because of {@link PreserveOnRefresh}.
 *
 * @param ui
 * @param request
 */
private void reinitUI(UI ui, VaadinRequest request) {
  UI.setCurrent(ui);
  ui.doRefresh(request);
}

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

/**
 * Hack used to return existing LegacyWindow instances without regard for
 * out-of-sync problems.
 *
 * @param event
 * @return
 */
public UI getExistingUI(UIClassSelectionEvent event) {
  UI uiInstance = getUIInstance(event);
  if (uiInstance == null || uiInstance.getUIId() == -1) {
    // Not initialized -> Let go through createUIInstance to make it
    // initialized
    return null;
  } else {
    UI.setCurrent(uiInstance);
    return uiInstance;
  }
}

代码示例来源: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

/**
 * Finds the {@link UI} that belongs to the provided request. This is
 * generally only supported for UIDL requests as other request types are not
 * related to any particular UI or have the UI information encoded in a
 * non-standard way. The returned UI is also set as the current UI (
 * {@link UI#setCurrent(UI)}).
 *
 * @param request
 *            the request for which a UI is desired
 * @return the UI belonging to the request or null if no UI is found
 *
 */
public UI findUI(VaadinRequest request) {
  // getForSession asserts that the lock is held
  VaadinSession session = loadSession(request.getWrappedSession());
  // Get UI id from the request
  String uiIdString = request.getParameter(UIConstants.UI_ID_PARAMETER);
  UI ui = null;
  if (uiIdString != null && session != null) {
    int uiId = Integer.parseInt(uiIdString);
    ui = session.getUIById(uiId);
  }
  UI.setCurrent(ui);
  return ui;
}

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

try {
  UI uI = session.getUIById(Integer.parseInt(uiId));
  UI.setCurrent(uI);

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

UI.setCurrent(ui);

代码示例来源:origin: eclipse/hawkbit

@Override
  public void run() {
    UI.setCurrent(current);
    eventBus.publish(this, CustomFilterUIEvent.FILTER_TARGET_BY_QUERY);
  }
}

代码示例来源:origin: org.eclipse.hawkbit/hawkbit-ui

@Override
  public void run() {
    UI.setCurrent(current);
    eventBus.publish(this, CustomFilterUIEvent.FILTER_TARGET_BY_QUERY);
  }
}

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

@Override
public void tearDown() {
  UI.setCurrent(null);
}

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

private void initializeVaadinUI(final URI returnURI) {
  UI.setCurrent(new UI() {
    @Override
    protected void init(VaadinRequest request) {
    }
    @Override
    public Locale getLocale() {
      return Locale.ENGLISH;
    }
    @Override
    public Page getPage() {
      Page page = mock(Page.class);
      doReturn(returnURI).when(page).getLocation();
      return page;
    }
  });
}

代码示例来源:origin: uk.q3c.krail/krail

public final void setScopeKey(int index) {
    UI.setCurrent(null); // overcomes the inheritable check in CurrentInstance.set
    //flush last test if there was one
    UIScope oldScope = UIScope.getCurrent();
    if (oldScope != null) {
      oldScope.flush();
    }
    UIKey uiKey = new UIKey(index);
    BasicUI ui = mock(BasicUI.class);
    when(ui.getInstanceKey()).thenReturn(uiKey);
    UI.setCurrent(ui);
    CurrentInstance.set(UIKey.class, uiKey);
    getUiScope().startScope(uiKey);
  }
}

代码示例来源:origin: KrailOrg/krail

public final void setScopeKey(int index) {
    UI.setCurrent(null); // overcomes the inheritable check in CurrentInstance.set
    //flush last test if there was one
    UIScope oldScope = UIScope.getCurrent();
    if (oldScope != null) {
      oldScope.flush();
    }
    UIKey uiKey = new UIKey(UUID.randomUUID());
    BasicUI ui = mock(BasicUI.class);
    when(ui.getInstanceKey()).thenReturn(uiKey);
    UI.setCurrent(ui);
    CurrentInstance.set(UIKey.class, uiKey);
    getUiScope().startScope(uiKey);
  }
}

代码示例来源:origin: eclipse/hawkbit

@Override
public void run() {
  try {
    UI.setCurrent(vaadinUi);
    streamToRepository();
  } catch (final RuntimeException e) {
    interruptUploadDueToUploadFailed();
    publishUploadFailedAndFinishedEvent(fileUploadId, e);
    LOG.error("Failed to transfer file to repository", e);
  } finally {
    tryToCloseIOStream(inputStream);
  }
}

代码示例来源:origin: org.eclipse.hawkbit/hawkbit-ui

@Override
public void run() {
  try {
    UI.setCurrent(vaadinUi);
    streamToRepository();
  } catch (final RuntimeException e) {
    publishUploadFailedEvent(fileUploadId, i18n.getMessage("message.upload.failed"), e);
    LOG.error("Failed to transfer file to repository", e);
  } finally {
    tryToCloseIOStream(inputStream);
  }
}

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

@After
public void tearDown() {
  UI.setCurrent(null);
}

代码示例来源:origin: KrailOrg/krail

private void setUIScope(UUID index) {
  UI.setCurrent(null); // overcomes the inheritable check in CurrentInstance.set
  //flush last test if there was one
  UIScope oldScope = UIScope.getCurrent();
  if (oldScope != null) {
    oldScope.flush();
  }
  UIKey uiKey = new UIKey(index);
  BasicUI ui = mock(BasicUI.class);
  when(ui.getInstanceKey()).thenReturn(uiKey);
  UI.setCurrent(ui);
  CurrentInstance.set(UIKey.class, uiKey);
}

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

@Override
protected void before() {
  VaadinService.setCurrent(this.vaadinService);
  VaadinSession.setCurrent(this.vaadinSession);
  UI.setCurrent(this.ui);
}

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

protected UI createAndInitUI(Class<? extends UI> uiClass,
    VaadinRequest request, VaadinSession session) {
  Integer uiId = Integer.valueOf(session.getNextUIid());
  UI ui = ReflectTools.createInstance(uiClass);
  // Initialize some fields for a newly created UI
  ui.getInternals().setSession(session);
  PushMode pushMode = AnnotationReader.getPushMode(uiClass).orElseGet(
      session.getService().getDeploymentConfiguration()::getPushMode);
  ui.getPushConfiguration().setPushMode(pushMode);
  AnnotationReader.getPushTransport(uiClass)
      .ifPresent(ui.getPushConfiguration()::setTransport);
  // Set thread local here so it is available in init
  UI.setCurrent(ui);
  ui.doInit(request, uiId.intValue());
  session.addUI(ui);
  return ui;
}

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

@After
public void tearDown() throws Exception {
  ComponentsTestUtil.clear();
  MgnlContext.setInstance(null);
  UI.setCurrent(null);
}

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

@Override
public void setUp() throws Exception {
  super.setUp();
  MockContext ctx = (MockContext) MgnlContext.getInstance();
  user = mock(User.class);
  ctx.setUser(user);
  ctx.setLocale(Locale.FRANCE);
  DateFieldDefinition definition = dateFieldDefinition("startDate");
  nodeAdapter = new JcrNewNodeAdapter(session.getRootNode(), ContentNode.NAME, "event");
  SimpleTranslator i18n = mock(SimpleTranslator.class);
  factory = new DateFieldFactory(definition, nodeAdapter, uiContext, i18nAuthoringSupport, i18n, ctx);
  factory.setComponentProvider(componentProvider);
  UI ui = mock(UI.class);
  Page page = mock(Page.class);
  browserInfo = mock(WebBrowser.class);
  when(page.getWebBrowser()).thenReturn(browserInfo);
  when(ui.getPage()).thenReturn(page);
  UI.setCurrent(ui);
}

相关文章