Java Code Examples for com.vaadin.ui.UI#getCurrent()

The following examples show how to use com.vaadin.ui.UI#getCurrent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainLayout.java    From designer-tutorials with Apache License 2.0 6 votes vote down vote up
public MainLayout() {
    Navigator navigator = new Navigator(UI.getCurrent(), contentPanel);
    navigator.addView(StatsView.VIEW_NAME, StatsView.class);
    navigator.addView(PluginsView.VIEW_NAME, PluginsView.class);
    navigator.addView(PermissionsView.VIEW_NAME, PermissionsView.class);

    menuButton1.addClickListener(event -> doNavigate(StatsView.VIEW_NAME));
    menuButton2
            .addClickListener(event -> doNavigate(PluginsView.VIEW_NAME));
    menuButton3.addClickListener(
            event -> doNavigate(PermissionsView.VIEW_NAME));

    if (navigator.getState().isEmpty()) {
        navigator.navigateTo(StatsView.VIEW_NAME);
    } else {
        navigator.navigateTo(navigator.getState());
    }
}
 
Example 2
Source File: VaadinScope.java    From jdal with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public String getConversationId() {
	Integer uiId = null;
	
	UI ui =  UI.getCurrent();
	if (ui == null) {
		UIid id = CurrentInstance.get(UIid.class);
		if (id != null) {
			uiId = id.getUiId();
		}
	}
	else if (ui != null) {
		if (!sessions.containsKey(ui)) {
			ui.addDetachListener(this);
			sessions.put(ui, VaadinSession.getCurrent().getSession().getId());
		}

		uiId = ui.getUIId();
	}
	
	return uiId != null ? getConversationId(uiId) : null;
}
 
Example 3
Source File: WebTreeImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void queue(@Nonnull WebTreeNodeImpl<E> parent, TreeState.TreeChangeType type) {
  UI ui = UI.getCurrent();
  myUpdater.execute(() -> {
    WebUIThreadLocal.setUI(ui);

    try {
      List<WebTreeNodeImpl<E>> children = parent.getChildren();
      if (children == null) {
        children = fetchChildren(parent, true);
      }

      mapChanges(parent, children, type);

      ui.access(this::markAsDirty);
    }
    finally {
      WebUIThreadLocal.setUI(null);
    }
  });
}
 
Example 4
Source File: UploadProgressInfoWindow.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
UploadProgressInfoWindow(final UIEventBus eventBus, final ArtifactUploadState artifactUploadState,
        final VaadinMessageSource i18n) {
    this.artifactUploadState = artifactUploadState;
    this.i18n = i18n;

    setPopupProperties();
    createStatusPopupHeaderComponents();

    mainLayout = new VerticalLayout();
    mainLayout.setSpacing(Boolean.TRUE);
    mainLayout.setSizeUndefined();
    setPopupSizeInMinMode();

    uploads = getGridContainer();
    grid = createGrid();
    setGridColumnProperties();

    mainLayout.addComponents(getCaptionLayout(), grid);
    mainLayout.setExpandRatio(grid, 1.0F);
    setContent(mainLayout);
    eventBus.subscribe(this);
    ui = UI.getCurrent();
}
 
Example 5
Source File: DefineGroupsLayout.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
private void validateRemainingTargets() {
    resetErrors();
    if (targetFilter == null) {
        return;
    }

    if (runningValidationsCounter.incrementAndGet() == 1) {
        final ListenableFuture<RolloutGroupsValidation> validateTargetsInGroups = rolloutManagement
                .validateTargetsInGroups(savedRolloutGroups, targetFilter, System.currentTimeMillis());
        final UI ui = UI.getCurrent();
        validateTargetsInGroups.addCallback(validation -> ui.access(() -> setGroupsValidation(validation)),
                throwable -> ui.access(() -> setGroupsValidation(null)));
        return;
    }

    runningValidationsCounter.incrementAndGet();

}
 
Example 6
Source File: TableDataContainer.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected void fireItemSetChanged() {
    if (ignoreListeners) {
        return;
    }

    ignoreListeners = true;

    UI ui = UI.getCurrent();
    if (ui != null && ui.getConnectorTracker().isWritingResponse()) {
        // Suppress containerItemSetChange listeners during painting, undefined behavior may be occurred
        return;
    }

    StaticItemSetChangeEvent event = new StaticItemSetChangeEvent(this);
    for (ItemSetChangeListener listener : itemSetChangeListeners) {
        listener.containerItemSetChange(event);
    }
}
 
Example 7
Source File: UploadProgressButtonLayout.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a new {@link UploadProgressButtonLayout} instance.
 * 
 * @param i18n
 *            the {@link VaadinMessageSource}
 * @param eventBus
 *            the {@link UIEventBus} for listening to ui events
 * @param artifactUploadState
 *            the {@link ArtifactUploadState} for state information
 * @param multipartConfigElement
 *            the {@link MultipartConfigElement}
 * @param softwareManagement
 *            the {@link SoftwareModuleManagement} for retrieving the
 *            {@link SoftwareModule}
 * @param artifactManagement
 *            the {@link ArtifactManagement} for storing the uploaded
 *            artifacts
 * @param uploadLock
 *            A common upload lock that enforced sequential upload within an UI instance
 */
public UploadProgressButtonLayout(final VaadinMessageSource i18n, final UIEventBus eventBus,
        final ArtifactUploadState artifactUploadState, final MultipartConfigElement multipartConfigElement,
        final ArtifactManagement artifactManagement, final SoftwareModuleManagement softwareManagement, final Lock uploadLock) {
    this.artifactUploadState = artifactUploadState;
    this.artifactManagement = artifactManagement;
    this.uploadInfoWindow = new UploadProgressInfoWindow(eventBus, artifactUploadState, i18n);
    this.uploadInfoWindow.addCloseListener(event -> {
        // ensure that the progress button is hidden when the progress
        // window is closed and no more uploads running
        if (artifactUploadState.areAllUploadsFinished()) {
            hideUploadProgressButton();
        }
    });
    this.i18n = i18n;
    this.multipartConfigElement = multipartConfigElement;
    this.softwareModuleManagement = softwareManagement;
    this.upload = new UploadFixed();
    this.uploadLock = uploadLock;

    createComponents();
    buildLayout();
    restoreState();
    ui = UI.getCurrent();

    eventBus.subscribe(this);
}
 
Example 8
Source File: TargetBulkUpdateWindowLayout.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
private BulkUploadHandler getBulkUploadHandler() {
    final BulkUploadHandler bulkUploadHandler = new BulkUploadHandler(this, targetManagement, tagManagement,
            entityFactory, distributionSetManagement, managementUIState, deploymentManagement, i18n,
            UI.getCurrent(), uiExecutor);
    bulkUploadHandler.buildLayout();
    bulkUploadHandler.addStyleName(SPUIStyleDefinitions.BULK_UPLOAD_BUTTON);
    return bulkUploadHandler;
}
 
Example 9
Source File: MainLayout.java    From designer-tutorials with Apache License 2.0 5 votes vote down vote up
public MainLayout() {
    navigator = new Navigator(UI.getCurrent(), (ViewDisplay) this);
    addNavigatorView(DashboardView.VIEW_NAME, DashboardView.class,
            menuButton1);
    addNavigatorView(OrderView.VIEW_NAME, OrderView.class, menuButton2);
    addNavigatorView(AboutView.VIEW_NAME, AboutView.class, menuButton3);
    if (navigator.getState().isEmpty()) {
        navigator.navigateTo(DashboardView.VIEW_NAME);
    }
}
 
Example 10
Source File: MultiFileUpload.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void ensurePushOrPollingIsEnabled() {
    UI current = UI.getCurrent();
    PushConfiguration pushConfiguration = current.getPushConfiguration();
    PushMode pushMode = pushConfiguration.getPushMode();
    if (pushMode != PushMode.AUTOMATIC) {
        int currentPollInterval = current.getPollInterval();
        if (currentPollInterval == -1 || currentPollInterval > 1000) {
            savedPollInterval = currentPollInterval;
            current.setPollInterval(getPollInterval());
        }
    }
}
 
Example 11
Source File: MultiFileUpload.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void resetPollIntervalIfNecessary() {
    if (savedPollInterval != null
            && getprogressBarsLayout().getComponentCount() == 0) {
        UI current = UI.getCurrent();
        current.setPollInterval(savedPollInterval);
        savedPollInterval = null;
    }
}
 
Example 12
Source File: UpgradeConfirmWindow.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
public UpgradeConfirmWindow(final String version, String manualDownloadLink, final String installerFilePath) {
    super(UserUIContext.getMessage(ShellI18nEnum.OPT_NEW_UPGRADE_IS_READY));
    this.withModal(true).withResizable(false).withCenter().withWidth("600px");
    this.installerFilePath = installerFilePath;

    currentUI = UI.getCurrent();

    MVerticalLayout content = new MVerticalLayout();
    this.setContent(content);

    Div titleDiv = new Div().appendText(UserUIContext.getMessage(ShellI18nEnum.OPT_REQUEST_UPGRADE, version)).setStyle("font-weight:bold");
    content.with(ELabel.html(titleDiv.write()));

    Div manualInstallLink = new Div().appendText("&nbsp;&nbsp;&nbsp;&nbsp;" + UserUIContext.getMessage(ShellI18nEnum.OPT_MANUAL_INSTALL) + ": ")
            .appendChild(new A(manualDownloadLink, "_blank")
                    .appendText(UserUIContext.getMessage(ShellI18nEnum.OPT_DOWNLOAD_LINK)));
    content.with(ELabel.html(manualInstallLink.write()));

    Div manualUpgradeHowtoLink = new Div().appendText("&nbsp;&nbsp;&nbsp;&nbsp;" + UserUIContext.getMessage(ShellI18nEnum.OPT_MANUAL_UPGRADE) + ": ")
            .appendChild(new A("https://docs.mycollab.com/administration/upgrade-mycollab-automatically/", "_blank").appendText("Link"));
    content.with(ELabel.html(manualUpgradeHowtoLink.write()));

    Div releaseNoteLink = new Div().appendText("&nbsp;&nbsp;&nbsp;&nbsp;" + UserUIContext.getMessage(ShellI18nEnum.OPT_RELEASE_NOTES) + ": ")
            .appendChild(new A("https://docs.mycollab.com/administration/hosting-mycollab-on-your-own-server/releases/", "_blank").appendText("Link"));
    content.with(ELabel.html(releaseNoteLink.write()));

    MButton skipBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.ACTION_SKIP), clickEvent -> close())
            .withStyleName(WebThemes.BUTTON_OPTION);

    MButton autoUpgradeBtn = new MButton(UserUIContext.getMessage(ShellI18nEnum.ACTION_AUTO_UPGRADE), clickEvent -> {
        close();
        navigateToWaitingUpgradePage();
    }).withStyleName(WebThemes.BUTTON_ACTION);
    if (installerFilePath == null) {
        autoUpgradeBtn.setEnabled(false);
    }

    MHorizontalLayout buttonControls = new MHorizontalLayout(skipBtn, autoUpgradeBtn).withMargin(true);
    content.with(buttonControls).withAlign(buttonControls, Alignment.MIDDLE_RIGHT);
}
 
Example 13
Source File: WebUIThreadLocal.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static UI getUI() {
  UI ui = ourUI.get();
  if (ui != null) {
    return ui;
  }
  UI current = UI.getCurrent();
  if (current != null) {
    return current;
  }
  throw new UnsupportedOperationException();
}
 
Example 14
Source File: AuthorizationFailureEventListener.java    From cia with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(final AuthorizationFailureEvent authorizationFailureEvent) {

	final String sessionId = RequestContextHolder.currentRequestAttributes().getSessionId();

	final CreateApplicationEventRequest serviceRequest = new CreateApplicationEventRequest();
	serviceRequest.setSessionId(sessionId);

	serviceRequest.setEventGroup(ApplicationEventGroup.APPLICATION);
	serviceRequest.setApplicationOperation(ApplicationOperationType.AUTHORIZATION);

	serviceRequest.setUserId(UserContextUtil.getUserIdFromSecurityContext());

	final Page currentPageIfAny = Page.getCurrent();
	final String requestUrl = UserContextUtil.getRequestUrl(currentPageIfAny);
	final UI currentUiIfAny = UI.getCurrent();
	String methodInfo = "";

	if (currentPageIfAny != null && currentUiIfAny != null && currentUiIfAny.getNavigator() != null
			&& currentUiIfAny.getNavigator().getCurrentView() != null) {
		serviceRequest.setPage(currentUiIfAny.getNavigator().getCurrentView().getClass().getSimpleName());
		serviceRequest.setPageMode(currentPageIfAny.getUriFragment());
	}

	if (authorizationFailureEvent.getSource() instanceof ReflectiveMethodInvocation) {
		final ReflectiveMethodInvocation methodInvocation = (ReflectiveMethodInvocation) authorizationFailureEvent
				.getSource();
		if (methodInvocation != null && methodInvocation.getThis() != null) {
			methodInfo = new StringBuilder().append(methodInvocation.getThis().getClass().getSimpleName())
					.append('.').append(methodInvocation.getMethod().getName()).toString();
		}
	}

	final Collection<? extends GrantedAuthority> authorities = authorizationFailureEvent.getAuthentication()
			.getAuthorities();
	final Collection<ConfigAttribute> configAttributes = authorizationFailureEvent.getConfigAttributes();

	serviceRequest.setErrorMessage(MessageFormat.format(ERROR_MESSAGE_FORMAT, requestUrl, methodInfo, AUTHORITIES,
			authorities, REQUIRED_AUTHORITIES, configAttributes, authorizationFailureEvent.getSource()));
	serviceRequest.setApplicationMessage(ACCESS_DENIED);

	applicationManager.service(serviceRequest);

	LOGGER.info(LOG_MSG_AUTHORIZATION_FAILURE_SESSION_ID_AUTHORITIES_REQUIRED_AUTHORITIES,
			requestUrl.replaceAll(CRLF, CRLF_REPLACEMENT), methodInfo.replaceAll(CRLF, CRLF_REPLACEMENT),
			sessionId.replaceAll(CRLF, CRLF_REPLACEMENT), authorities, configAttributes);
}
 
Example 15
Source File: WebBackgroundWorker.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public UIAccessor getUIAccessor() {
    checkUIAccess();

    return new WebUIAccessor(UI.getCurrent());
}
 
Example 16
Source File: WebUIInternalImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean _UIAccess_isUIThread() {
  return UI.getCurrent() != null;
}
 
Example 17
Source File: HawkbitCommonUtil.java    From hawkbit with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Gets the locale of the current Vaadin UI. If the locale can not be
 * determined, the default locale is returned instead.
 *
 * @return the current locale, never {@code null}.
 * @see com.vaadin.ui.UI#getLocale()
 * @see java.util.Locale#getDefault()
 */
public static Locale getCurrentLocale() {
    final UI currentUI = UI.getCurrent();
    return currentUI == null ? Locale.getDefault() : currentUI.getLocale();
}