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

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

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

UI.access介绍

[英]Provides exclusive access to this UI from outside a request handling thread.

The given command is executed while holding the session lock to ensure exclusive access to this UI. If the session is not locked, the lock will be acquired and the command is run right away. If the session is currently locked, the command will be run before that lock is released.

RPC handlers for components inside this UI do not need to use this method as the session is automatically locked by the framework during RPC handling.

Please note that the command might be invoked on a different thread or later on the current thread, which means that custom thread locals might not have the expected values when the command is executed. Inheritable values in CurrentInstance will have the same values as when this method was invoked. UI#getCurrent(), VaadinSession#getCurrent() and VaadinService#getCurrent()are set according to this UI before executing the command. Non-inheritable CurrentInstance values including VaadinService#getCurrentRequest() and VaadinService#getCurrentResponse() will not be defined.

The returned future can be used to check for task completion and to cancel the task.
[中]提供从请求处理线程外部对此UI的独占访问。
在保持会话锁的同时执行给定的命令,以确保以独占方式访问此UI。如果会话未锁定,将获取锁并立即运行命令。如果会话当前已锁定,则在释放该锁定之前将运行该命令。
此UI内组件的RPC处理程序不需要使用此方法,因为在RPC处理期间,会话会被框架自动锁定。
请注意,该命令可能会在其他线程上调用,或者稍后在当前线程上调用,这意味着在执行该命令时,自定义线程局部变量可能没有预期的值。CurrentInstance中的可继承值将与调用此方法时的值相同。UI#getCurrent()、VaadinSession#getCurrent()和VaadinService#getCurrent()在执行命令之前根据此UI进行设置。将不定义不可继承的CurrentInstance值,包括VaadinService#getCurrentRequest()和VaadinService#getCurrentResponse()。
返回的future可用于检查任务完成情况和取消任务。

代码示例

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

private void attachDataProviderListener() {
  dataProviderUpdateRegistration = getDataProvider()
      .addDataProviderListener(event -> {
        if (event instanceof DataRefreshEvent) {
          T item = ((DataRefreshEvent<T>) event).getItem();
          getKeyMapper().refresh(item);
          generators.forEach(g -> g.refreshData(item));
          getUI().access(() -> refresh(item));
        } else {
          reset = true;
          getUI().access(() -> markAsDirty());
        }
      });
}

代码示例来源:origin: viritin/viritin

/**
 * A hook for extension to do something after the response has been sent to
 * the client.
 */
protected void afterResponseWritten() {
  if (downloadCompletedListeners != null) {
    getUI().access(() -> {
      downloadCompletedListeners.forEach(DownloadCompletedListener::onCompleted);
    });
  }
}

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

private void handleError(final UI ui, final Exception ex) {
 ui.access(() -> {
   LOG.error("Unknown Error occurred", ex);
   UIHelper.showNotification("Unknown Error", ex.getMessage(), Notification.Type.ERROR_MESSAGE);
   taskToRun.onError();
 });
}

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

@EventBusListenerMethod(scope = EventScope.UI)
void onEvent(final CustomFilterUIEvent custFUIEvent) {
  if (custFUIEvent == CustomFilterUIEvent.TARGET_DETAILS_VIEW
      || custFUIEvent == CustomFilterUIEvent.CREATE_NEW_FILTER_CLICK) {
    UI.getCurrent().access(this::populateTableData);
  } else if (custFUIEvent == CustomFilterUIEvent.FILTER_TARGET_BY_QUERY) {
    UI.getCurrent().access(this::onQuery);
  }
}

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

@EventBusListenerMethod(scope = EventScope.UI)
void onEvent(final ManagementUIEvent mgmtUIEvent) {
  if (mgmtUIEvent == ManagementUIEvent.MAX_ACTION_HISTORY) {
    UI.getCurrent().access(this::maximizeActionHistory);
  }
  if (mgmtUIEvent == ManagementUIEvent.MIN_ACTION_HISTORY) {
    UI.getCurrent().access(this::minimizeActionHistory);
  }
}

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

@EventBusListenerMethod(scope = EventScope.UI)
void onEvent(final ManagementUIEvent mgmtUIEvent) {
  if (mgmtUIEvent == ManagementUIEvent.MAX_ACTION_HISTORY) {
    UI.getCurrent().access(this::createMaximizedContent);
  }
  if (mgmtUIEvent == ManagementUIEvent.MIN_ACTION_HISTORY) {
    UI.getCurrent().access(this::createMinimizedContent);
  }
}

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

@EventBusListenerMethod(scope = EventScope.UI)
void onEvent(final UploadArtifactUIEvent event) {
  if (event == UploadArtifactUIEvent.DELETED_ALL_SOFTWARE) {
    UI.getCurrent().access(this::refreshFilter);
  }
}

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

@EventBusListenerMethod(scope = EventScope.UI)
void onEvent(final SaveActionWindowEvent event) {
  if (event == SaveActionWindowEvent.DELETED_DISTRIBUTIONS || event == SaveActionWindowEvent.SAVED_ASSIGNMENTS) {
    UI.getCurrent().access(this::refreshFilter);
  }
}

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

@EventBusListenerMethod(scope = EventScope.UI)
void onEvent(final CustomFilterUIEvent custFUIEvent) {
  if (custFUIEvent == CustomFilterUIEvent.TARGET_DETAILS_VIEW
      || custFUIEvent == CustomFilterUIEvent.CREATE_NEW_FILTER_CLICK
      || custFUIEvent == CustomFilterUIEvent.EXIT_CREATE_OR_UPDATE_FILTRER_VIEW
      || custFUIEvent == CustomFilterUIEvent.UPDATE_TARGET_FILTER_SEARCH_ICON) {
    UI.getCurrent().access(this::displayTargetFilterMessage);
  }
}

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

@EventBusListenerMethod(scope = EventScope.UI)
void onEvent(final ManagementUIEvent event) {
  if (event == ManagementUIEvent.HIDE_TARGET_TAG_LAYOUT) {
    setFilterButtonsIconVisible(true);
  } else if (event == ManagementUIEvent.SHOW_TARGET_TAG_LAYOUT) {
    setFilterButtonsIconVisible(false);
  } else if (event == ManagementUIEvent.RESET_SIMPLE_FILTERS) {
    UI.getCurrent().access(this::onSimpleFilterReset);
  } else if (event == ManagementUIEvent.RESET_TARGET_FILTER_QUERY) {
    UI.getCurrent().access(this::onCustomFilterReset);
  }
}

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

@EventBusListenerMethod(scope = EventScope.UI)
void onEvent(final ManagementUIEvent managementUIEvent) {
  UI.getCurrent().access(() -> {
    if (managementUIEvent == ManagementUIEvent.UNASSIGN_DISTRIBUTION_TAG
        || managementUIEvent == ManagementUIEvent.ASSIGN_DISTRIBUTION_TAG) {
      refreshFilter();
    }
  });
}

代码示例来源:origin: viritin/viritin

@Override
  public void run() {
    try {
      getWriter().write(out);
      out.close();
    } catch (Exception e) {
      getUI().access(() -> {
        handleErrorInFileGeneration(e);
      });
    }
  }
}.start();

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

@Override
public void messageCleared(final Message message) {
  if (ui.isAttached()) {
    ui.access(() -> eventBus.fireEvent(new MessageEvent(message, true)));
  }
}

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

protected void onBaseEntityEvent(final BaseUIEntityEvent<T> baseEntityEvent) {
  if (BaseEntityEventType.SELECTED_ENTITY != baseEntityEvent.getEventType()) {
    return;
  }
  UI.getCurrent().access(() -> {
    final T entity = baseEntityEvent.getEntity();
    if (entity != null) {
      selectedEntity = entity;
      repopulateToken();
    }
  });
}

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

@EventBusListenerMethod(scope = EventScope.UI)
void onEvent(final DistributionsUIEvent event) {
  UI.getCurrent().access(() -> {
    if (event == DistributionsUIEvent.ORDER_BY_DISTRIBUTION) {
      refreshFilter();
      styleTableOnDistSelection();
    }
  });
}

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

@EventBusListenerMethod(scope = EventScope.UI)
void onEvent(final BulkUploadPopupEvent event) {
  if (BulkUploadPopupEvent.MAXIMIMIZED == event) {
    targetBulkUpdateWindow.restoreComponentsValue();
    openBulkUploadWindow();
  } else if (BulkUploadPopupEvent.CLOSED == event) {
    UI.getCurrent().access(this::enableBulkUpload);
  }
}

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

@EventBusListenerMethod(scope = EventScope.UI)
void onEvent(final TargetTableEvent targetUIEvent) {
  final Optional<Long> targetId = managementUIState.getLastSelectedTargetId();
  if (BaseEntityEventType.SELECTED_ENTITY == targetUIEvent.getEventType()) {
    setData(getI18n().getMessage(UIMessageIdProvider.MESSAGE_DATA_AVAILABLE));
    UI.getCurrent().access(() -> populateActionHistoryDetails(targetUIEvent.getEntity()));
  } else if (BaseEntityEventType.REMOVE_ENTITY == targetUIEvent.getEventType() && targetId.isPresent()
      && targetUIEvent.getEntityIds().contains(targetId.get())) {
    setData(getI18n().getMessage(UIMessageIdProvider.MESSAGE_NO_DATA));
    UI.getCurrent().access(this::populateActionHistoryDetails);
  }
}

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

@EventBusListenerMethod(scope = EventScope.UI)
void addOrEditEvent(final TargetAddUpdateWindowEvent targetUIEvent) {
  if (BaseEntityEventType.UPDATED_ENTITY != targetUIEvent.getEventType()) {
    return;
  }
  UI.getCurrent().access(() -> updateTarget(targetUIEvent.getEntity()));
}

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

@EventBusListenerMethod(scope = EventScope.UI)
void onEvent(final SoftwareModuleEvent event) {
  if (event.getSoftwareModuleEventType() == SoftwareModuleEventType.ASSIGN_SOFTWARE_MODULE) {
    UI.getCurrent().access(() -> updateSoftwareModule(event.getEntity()));
  }
}

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

@EventBusListenerMethod(scope = EventScope.UI)
void onEvent(final DistributionTableEvent event) {
  onBaseEntityEvent(event);
  if (BaseEntityEventType.UPDATED_ENTITY != event.getEventType()) {
    return;
  }
  UI.getCurrent().access(() -> updateDistributionInTable(event.getEntity()));
}

相关文章