當前位置: 首頁>>代碼示例>>Java>>正文


Java VaadinSession類代碼示例

本文整理匯總了Java中com.vaadin.server.VaadinSession的典型用法代碼示例。如果您正苦於以下問題:Java VaadinSession類的具體用法?Java VaadinSession怎麽用?Java VaadinSession使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


VaadinSession類屬於com.vaadin.server包,在下文中一共展示了VaadinSession類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createVaadinSession

import com.vaadin.server.VaadinSession; //導入依賴的package包/類
/**
 * Create a VaadinSession
 * @param locale Client locale
 * @return VaadinSession instance
 * @throws Exception Failed to create session
 */
protected VaadinSession createVaadinSession(Locale locale) throws Exception {
	WrappedSession wrappedSession = mock(WrappedSession.class);
	VaadinServletService vaadinService = mock(VaadinServletService.class);
	when(vaadinService.getDeploymentConfiguration())
			.thenReturn(new DefaultDeploymentConfiguration(VaadinServletService.class, getDeploymentProperties()));

	VaadinSession session = mock(VaadinSession.class);
	when(session.getState()).thenReturn(VaadinSession.State.OPEN);
	when(session.getSession()).thenReturn(wrappedSession);
	when(session.getService()).thenReturn(vaadinService);
	when(session.getSession().getId()).thenReturn(TEST_SESSION_ID);
	when(session.hasLock()).thenReturn(true);
	when(session.getLocale()).thenReturn(locale != null ? locale : Locale.US);
	return session;
}
 
開發者ID:holon-platform,項目名稱:holon-vaadin,代碼行數:22,代碼來源:AbstractVaadinTest.java

示例2: get

import com.vaadin.server.VaadinSession; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public <T> Optional<T> get(String resourceKey, Class<T> resourceType) throws TypeMismatchException {
	ObjectUtils.argumentNotNull(resourceKey, "Resource key must be not null");
	ObjectUtils.argumentNotNull(resourceType, "Resource type must be not null");

	final VaadinSession session = VaadinSession.getCurrent();

	if (session != null) {

		Object value = session.getAttribute(resourceKey);
		if (value != null) {

			// check type
			if (!TypeUtils.isAssignable(value.getClass(), resourceType)) {
				throw new TypeMismatchException("<" + NAME + "> Actual resource type [" + value.getClass().getName()
						+ "] and required resource type [" + resourceType.getName() + "] mismatch");
			}

			return Optional.of((T) value);

		}
	}

	return Optional.empty();
}
 
開發者ID:holon-platform,項目名稱:holon-vaadin7,代碼行數:27,代碼來源:VaadinSessionScope.java

示例3: put

import com.vaadin.server.VaadinSession; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public <T> Optional<T> put(String resourceKey, T value) throws UnsupportedOperationException {
	ObjectUtils.argumentNotNull(resourceKey, "Resource key must be not null");

	final VaadinSession session = VaadinSession.getCurrent();
	if (session == null) {
		throw new IllegalStateException("Current VaadinSession not available");
	}

	Object exist = session.getAttribute(resourceKey);

	session.setAttribute(resourceKey, value);

	try {
		T previous = (T) exist;
		return Optional.ofNullable(previous);
	} catch (@SuppressWarnings("unused") Exception e) {
		// ignore
		return Optional.empty();
	}
}
 
開發者ID:holon-platform,項目名稱:holon-vaadin7,代碼行數:23,代碼來源:VaadinSessionScope.java

示例4: putIfAbsent

import com.vaadin.server.VaadinSession; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public <T> Optional<T> putIfAbsent(String resourceKey, T value) throws UnsupportedOperationException {
	ObjectUtils.argumentNotNull(resourceKey, "Resource key must be not null");

	final VaadinSession session = VaadinSession.getCurrent();
	if (session == null) {
		throw new IllegalStateException("Current VaadinSession not available");
	}

	if (value != null) {
		synchronized (session) {
			Object exist = session.getAttribute(resourceKey);
			if (exist == null) {
				session.setAttribute(resourceKey, value);
			} else {
				return Optional.of((T) exist);
			}
		}
	}

	return Optional.empty();
}
 
開發者ID:holon-platform,項目名稱:holon-vaadin7,代碼行數:24,代碼來源:VaadinSessionScope.java

示例5: testFromRequest

import com.vaadin.server.VaadinSession; //導入依賴的package包/類
@Test
public void testFromRequest() {

	final DeviceInfo di = DeviceInfo.create(VaadinService.getCurrentRequest());
	assertNotNull(di);

	VaadinSession session = mock(VaadinSession.class);
	when(session.getState()).thenReturn(VaadinSession.State.OPEN);
	when(session.getSession()).thenReturn(mock(WrappedSession.class));
	when(session.getService()).thenReturn(mock(VaadinServletService.class));
	when(session.getSession().getId()).thenReturn(TEST_SESSION_ID);
	when(session.hasLock()).thenReturn(true);
	when(session.getLocale()).thenReturn(Locale.US);
	when(session.getAttribute(DeviceInfo.SESSION_ATTRIBUTE_NAME)).thenReturn(di);
	CurrentInstance.set(VaadinSession.class, session);

	Optional<DeviceInfo> odi = DeviceInfo.get();

	assertTrue(odi.isPresent());

}
 
開發者ID:holon-platform,項目名稱:holon-vaadin7,代碼行數:22,代碼來源:TestDeviceInfo.java

示例6: confirmKillSession

import com.vaadin.server.VaadinSession; //導入依賴的package包/類
/**
 * Confirme la fermeture d'une session
 * @param session la session a kill
 */
public void confirmKillSession(SessionPresentation session) {
	SessionPresentation user = (SessionPresentation) uisContainer.getParent(session);		
	String userName = applicationContext.getMessage("user.notconnected", null, UI.getCurrent().getLocale());
	if (user != null){
		userName = user.getId();
	}
	
	ConfirmWindow confirmWindow = new ConfirmWindow(applicationContext.getMessage("admin.uiList.confirmKillSession", new Object[]{session.getId(), userName}, UI.getCurrent().getLocale()));
	confirmWindow.addBtnOuiListener(e -> {
		VaadinSession vaadinSession = uiController.getSession(session);			
		Collection<SessionPresentation> listeUI = null;
		if (uisContainer.getChildren(session) != null){
			listeUI = (Collection<SessionPresentation>) uisContainer.getChildren(session);
		}			
		if (vaadinSession != null){
			uiController.killSession(vaadinSession, listeUI);
		}else{
			Notification.show(applicationContext.getMessage("admin.uiList.confirmKillSession.error", null, UI.getCurrent().getLocale()), Type.WARNING_MESSAGE);
		}
		removeElement(session);
	});
	UI.getCurrent().addWindow(confirmWindow);
}
 
開發者ID:EsupPortail,項目名稱:esup-ecandidat,代碼行數:28,代碼來源:AdminView.java

示例7: getUser

import com.vaadin.server.VaadinSession; //導入依賴的package包/類
/**
 * @param user
 * @return un user
 */
public UserDetails getUser(SessionPresentation user){
	for (MainUI ui : getUis()){
		try{
			VaadinSession session = ui.getSession();
			if (session == null || session.getSession()==null){
				return null;
			}
			SecurityContext securityContext = (SecurityContext) session.getSession().getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
					
			if (securityContext==null || securityContext.getAuthentication()==null){
				return null;
			}else{
				UserDetails details = (UserDetails) securityContext.getAuthentication().getPrincipal();
				if (details!=null && details.getUsername().equals(user.getId())){
					return details;
				}
			}				
		}catch (Exception e){}	
	}
	return null;
}
 
開發者ID:EsupPortail,項目名稱:esup-ecandidat,代碼行數:26,代碼來源:UiController.java

示例8: closeUserVaadinSessions

import com.vaadin.server.VaadinSession; //導入依賴的package包/類
private void closeUserVaadinSessions(String loginName) {
    // CopyOnWriteArrayList is thread safe for iteration under update
    for (HttpSession session : this.sessions) {
        for (VaadinSession vaadinSession : VaadinSession.getAllSessions(session)) {
            Object userName = vaadinSession.getAttribute("user");
            if (loginName == null || loginName.equals(userName)) {
            	vaadinSession.close();

            	// Redirect all UIs to force the close
            	for (UI ui : vaadinSession.getUIs()) {
            		ui.access(() -> {
            			ui.getPage().setLocation("/");
            		});
	}
            }
        }
    }
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:19,代碼來源:UiListenerDelegate.java

示例9: createVaadinRequest

import com.vaadin.server.VaadinSession; //導入依賴的package包/類
/**
 * Every incoming request should set the current user context
 */
@Override
protected VaadinServletRequest createVaadinRequest(HttpServletRequest request) {
    VaadinServletRequest vaadinRequest = super.createVaadinRequest(request);

    VaadinSession vaadinSession;
    try {
        vaadinSession = getService().findVaadinSession(vaadinRequest);
    } catch (Exception e) {
        // This exception will be handled later when we try to service
        // the request
        vaadinSession = null;
    }

    if(vaadinSession != null) {
        this.userContext.setUser((String) vaadinSession.getAttribute("user"));
    } else {
        this.userContext.setUser(null);
    }

    return vaadinRequest;
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:25,代碼來源:UiServlet.java

示例10: init

import com.vaadin.server.VaadinSession; //導入依賴的package包/類
@Override
protected void init(VaadinRequest vaadinRequest) {
  VaadinSession.getCurrent().getSession().setMaxInactiveInterval(-1);
  Page.getCurrent().setTitle("Tiny Pounder (" + VERSION + ")");

  setupLayout();
  addKitControls();
  updateKitControls();
  initVoltronConfigLayout();
  initVoltronControlLayout();
  initRuntimeLayout();
  addExitCloseTab();
  updateServerGrid();

  // refresh consoles if any
  consoleRefresher = scheduledExecutorService.scheduleWithFixedDelay(
      () -> access(() -> runningServers.values().forEach(RunningServer::refreshConsole)),
      2, 2, TimeUnit.SECONDS);
}
 
開發者ID:Terracotta-OSS,項目名稱:tinypounder,代碼行數:20,代碼來源:TinyPounderMainUI.java

示例11: dashboardNameEdited

import com.vaadin.server.VaadinSession; //導入依賴的package包/類
@Override
    public void dashboardNameEdited(final Imot imot) throws Exception {
//        titleLabel.setValue(name);
        User user = (User) VaadinSession.getCurrent().getAttribute(User.class.getName());

        if (user.role().equals("guest")) {
            return;
        }

        GoogleMapMarker marker = imot.getLocation().marker().googleMarker();
        googleMap.addMarker(marker);
        googleMap.setCenter(centerSofia);

        user.addImot(imot);
        new UserVertex(user).saveOrUpdateInNewTX();
    }
 
開發者ID:imotSpot,項目名稱:imotSpot,代碼行數:17,代碼來源:DashboardView.java

示例12: updateContent

import com.vaadin.server.VaadinSession; //導入依賴的package包/類
/**
     * Updates the correct content for this UI based on the current user status.
     * If the user is logged in with appropriate privileges, main view is shown.
     * Otherwise login view is shown.
     */
    private void updateContent() {
        User user = (User) VaadinSession.getCurrent().getAttribute(
                User.class.getName());
        if (user == null) {
            user = UserBean.builder()
                    .oauthIdentifier("")
                    .firstName("guest")
                    .lastName("")
                    .role("guest")
                    .build();
            VaadinSession.getCurrent().setAttribute(User.class.getName(), user);
        }
            setContent(new MainView());
            removeStyleName("loginview");
            getNavigator().navigateTo(getNavigator().getState());
//        } else {
//            setContent(new LoginView());
//            addStyleName("loginview");
//        }
    }
 
開發者ID:imotSpot,項目名稱:imotSpot,代碼行數:26,代碼來源:DashboardUI.java

示例13: getMainDivId

import com.vaadin.server.VaadinSession; //導入依賴的package包/類
@Override
public String getMainDivId(VaadinSession session, VaadinRequest request, Class<? extends UI> uiClass) {
    String appId = request.getPathInfo();
    if (appId == null || "".equals(appId) || "/".equals(appId)) {
        appId = "ROOT";
    }
    appId = appId.replaceAll("[^a-zA-Z0-9]", "");
    // Add hashCode to the end, so that it is still (sort of)
    // predictable, but indicates that it should not be used in CSS
    // and
    // such:
    int hashCode = appId.hashCode();
    if (hashCode < 0) {
        hashCode = -hashCode;
    }
    appId = appId + "-" + hashCode;
    return appId;
}
 
開發者ID:mcollovati,項目名稱:vaadin-vertx-samples,代碼行數:19,代碼來源:VertxVaadinService.java

示例14: handleAdditionalDependencies

import com.vaadin.server.VaadinSession; //導入依賴的package包/類
@SuppressWarnings("deprecation")
@Override
protected void handleAdditionalDependencies(List<Class<? extends ClientConnector>> newConnectorTypes,
                                            List<String> scriptDependencies, List<String> styleDependencies) {
    LegacyCommunicationManager manager = VaadinSession.getCurrent().getCommunicationManager();

    for (Class<? extends ClientConnector> connector : newConnectorTypes) {
        WebJarResource webJarResource = connector.getAnnotation(WebJarResource.class);
        if (webJarResource == null)
            continue;

        for (String uri : webJarResource.value()) {
            uri = processResourceUri(uri);

            if (uri.endsWith(JAVASCRIPT_EXTENSION)) {
                scriptDependencies.add(manager.registerDependency(uri, connector));
            }

            if (uri.endsWith(CSS_EXTENSION)) {
                styleDependencies.add(manager.registerDependency(uri, connector));
            }
        }
    }
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:25,代碼來源:CubaUidlWriter.java

示例15: convertToModel

import com.vaadin.server.VaadinSession; //導入依賴的package包/類
@Override
public Enum convertToModel(String value, Class<? extends Enum> targetType, Locale locale)
        throws ConversionException {
    if (value == null) {
        return null;
    }

    if (locale == null) {
        locale = VaadinSession.getCurrent().getLocale();
    }

    if (isTrimming()) {
        value = StringUtils.trimToEmpty(value);
    }

    Object[] enumConstants = enumClass.getEnumConstants();
    if (enumConstants != null) {
        for (Object enumValue : enumConstants) {
            if (Objects.equals(value, messages.getMessage((Enum) enumValue, locale))) {
                return (Enum) enumValue;
            }
        }
    }

    return null;
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:27,代碼來源:StringToEnumConverter.java


注:本文中的com.vaadin.server.VaadinSession類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。