当前位置: 首页>>代码示例>>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;未经允许,请勿转载。