List of usage examples for com.google.gwt.user.client Cookies setCookie
public static void setCookie(String name, String value, Date expires)
From source file:bingo.client.Bingo.java
License:Open Source License
/** * This is the entry point method./*ww w. ja v a 2s .c om*/ */ public void onModuleLoad() { Label titleLabel = new Label(); titleLabel.setText(strings.title()); RootPanel.get("title").add(titleLabel); // This is the general notification text box RootPanel.get("message").add(message); // Cheking if the user has already an user id final String cookie = Cookies.getCookie(COOKIE_ID); // Validating the cookie bingoService.statusUserId(cookie, new AsyncCallback<Integer>() { @Override public void onFailure(Throwable caught) { message.setText(caught.getMessage()); Cookies.removeCookie(COOKIE_ID); } @Override public void onSuccess(Integer status) { // TODO: Control the logged status (I should not get a user if s/he is already logged) if (status.intValue() == BingoService.NO_LOGGED || status.intValue() == BingoService.LOGGED) { bingoService.getUserId(new AsyncCallback<String>() { @Override public void onFailure(Throwable caught) { message.setText(strings.errorUserCreation()); } @Override public void onSuccess(String result) { userId = result; } }); message.setHTML(""); // Showing image to enter ImageResource imageResource = BingoResources.INSTANCE.entry(); Image entryImage = new Image(imageResource.getSafeUri()); RootPanel.get("buttons").add(entryImage); // Selecting behavior (admin / voter) HorizontalPanel entryPoint = new HorizontalPanel(); entryPoint.setStyleName("mainSelectorPanel"); entryPoint.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); entryPoint.setSpacing(50); // // CREATING A BINGO // VerticalPanel leftPanel = new VerticalPanel(); leftPanel.setStyleName("selectorPanel"); Label leftPanelTitle = new Label(); leftPanelTitle.setStyleName("selectorPanelTitle"); leftPanelTitle.setText(strings.leftPanelTitle()); leftPanel.add(leftPanelTitle); leftPanel.setCellHorizontalAlignment(leftPanelTitle, HasHorizontalAlignment.ALIGN_CENTER); Grid leftSubPanel = new Grid(2, 2); leftSubPanel.setWidget(0, 0, new Label(strings.createBingoName())); final TextBox bingoNameBox = new TextBox(); leftSubPanel.setWidget(0, 1, bingoNameBox); leftSubPanel.setWidget(1, 0, new Label(strings.createBingoPassword())); final PasswordTextBox bingoPasswordBox = new PasswordTextBox(); leftSubPanel.setWidget(1, 1, bingoPasswordBox); leftPanel.add(leftSubPanel); final Button createButton = new Button("Create"); createButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { bingoService.createBingo(userId, bingoNameBox.getText(), bingoPasswordBox.getText(), new AsyncCallback<String>() { @Override public void onFailure(Throwable caught) { message.setText(caught.getMessage()); } @Override public void onSuccess(final String gameId) { final BingoGrid bingoGrid = new BingoGrid(); initAdminGrid(userId, bingoGrid, false); RootPanel.get("bingoTable").clear(); RootPanel.get("bingoTable").add(bingoGrid); message.setText(strings.welcomeMessageCreation()); // Setting the cookie Date expirationDate = new Date(); expirationDate.setHours(expirationDate.getHours() + EXPIRATION_VALUE); Cookies.setCookie(COOKIE_ID, userId, expirationDate); } }); } }); leftPanel.add(createButton); leftPanel.setCellHorizontalAlignment(createButton, HasHorizontalAlignment.ALIGN_CENTER); entryPoint.add(leftPanel); // // JOINING // VerticalPanel rightPanel = new VerticalPanel(); rightPanel.setStyleName("selectorPanel"); Label rightPanelTitle = new Label(); rightPanelTitle.setStyleName("selectorPanelTitle"); rightPanelTitle.setText(strings.rightPanelTitle()); rightPanel.add(rightPanelTitle); rightPanel.setCellHorizontalAlignment(rightPanelTitle, HasHorizontalAlignment.ALIGN_CENTER); Grid rightSubPanel = new Grid(2, 2); rightSubPanel.setWidget(0, 0, new Label(strings.joinToBingoName())); final ListBox joinExistingBingoBox = new ListBox(); bingoService.getBingos(new AsyncCallback<String[][]>() { @Override public void onFailure(Throwable caught) { joinExistingBingoBox.addItem(strings.noBingos()); } @Override public void onSuccess(String[][] result) { if (result == null) { joinExistingBingoBox.addItem(strings.noBingos()); } else { for (int i = 0; i < result.length; i++) { String gameName = result[i][0]; String gameId = result[i][1]; joinExistingBingoBox.addItem(gameName, gameId); } } } }); rightSubPanel.setWidget(0, 1, joinExistingBingoBox); rightSubPanel.setWidget(1, 0, new Label(strings.joinToBingoPassword())); final PasswordTextBox joinBingoPasswordBox = new PasswordTextBox(); rightSubPanel.setWidget(1, 1, joinBingoPasswordBox); rightPanel.add(rightSubPanel); final Button joinButton = new Button("Join"); joinButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { int index = joinExistingBingoBox.getSelectedIndex(); if (index < 0) message.setText(strings.noSelectedItem()); else { final String gameId = joinExistingBingoBox.getValue(index); if (gameId == null) message.setText(strings.noSelectedItem()); else { bingoService.joinBingo(userId, gameId, joinBingoPasswordBox.getText(), new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { message.setText(caught.getMessage()); } @Override public void onSuccess(Void result) { final BingoGrid bingoGrid = new BingoGrid(); initUserGrid(bingoGrid); RootPanel.get("bingoTable").clear(); RootPanel.get("bingoTable").add(bingoGrid); message.setText(strings.welcomeMessageJoin()); // Setting the cookie Date expirationDate = new Date(); expirationDate .setHours(expirationDate.getHours() + EXPIRATION_VALUE); Cookies.setCookie(COOKIE_ID, userId, expirationDate); } }); } } } }); rightPanel.add(joinButton); rightPanel.setCellHorizontalAlignment(joinButton, HasHorizontalAlignment.ALIGN_CENTER); entryPoint.add(rightPanel); RootPanel.get("bingoTable").add(entryPoint); } else if (status.intValue() == BingoService.ADMIN) { message.setText("Detected cookie: " + cookie + " as admin"); userId = cookie; bingoService.statusBingo(userId, new AsyncCallback<Integer>() { @Override public void onFailure(Throwable caught) { message.setText(caught.getMessage()); } @Override public void onSuccess(Integer result) { int status = result.intValue(); final BingoGrid bingoGrid = new BingoGrid(); if (status == BingoService.RUNNING) { initAdminGrid(userId, bingoGrid, false); message.setText(strings.welcomeMessageCreation()); } else if (status == BingoService.FINISHED) { initAdminGrid(userId, bingoGrid, true); message.setText(strings.finishMessage()); } RootPanel.get("bingoTable").clear(); RootPanel.get("bingoTable").add(bingoGrid); } }); } else if (status.intValue() == BingoService.PARTICIPANT) { message.setText("Detected cookie: " + cookie + " as participant"); userId = cookie; final BingoGrid bingoGrid = new BingoGrid(); initUserGrid(bingoGrid); updateUserGrid(bingoGrid, null); RootPanel.get("bingoTable").clear(); RootPanel.get("bingoTable").add(bingoGrid); } } }); }
From source file:ca.qc.cegepoutaouais.tge.pige.client.ui.dialog.LoginDialog.java
License:Open Source License
private void onSubmit() { if (!isLoginEnabled()) { return;/*w ww. j a va 2s . com*/ } // Interdir l'excution de nouvelle demande d'authentification pendant // qu'une autre est en train de se faire. setLoginEnabled(false); LoginServiceAsync rpcService = Registry.get(PIGE.LOGIN_SERVICE); // Envoyer la demande d'authentification au serveur. rpcService.logIn(identifierTF.getValue(), passwordTF.getValue(), new AsyncCallback<SessionObject>() { @Override public void onSuccess(SessionObject session) { // La demande d'authentification a russie! hide(); // Crer le cookie de session qui va permettre l'usager // d'accder ultrieurement PIGE sans devoir // s'authentifier de nouveau. La dure de vie du cookie // est dtermin par le serveur. Cookies.setCookie(PIGE.SESSION_COOKIE, session.getId(), new Date(System.currentTimeMillis() + session.getLifespan())); Registry.register(PIGE.SESSION_COOKIE, session.getId()); Registry.register(PIGE.USER_IDENTIFIER, identifierTF.getValue()); identifierTF.clear(); passwordTF.clear(); // Gnrer l'vnement permettant d'afficher la vue // principale. Dispatcher.get().dispatch(AppEvents.INIT_EVENT); } // onSuccess() @Override public void onFailure(Throwable caught) { // En cas d'chec, afficher le message d'erreur // indiquant la cause. passwordTF.clear(); setLoginEnabled(true); String errMsg = caught.getMessage(); if (caught instanceof LoginErrorException) { String errType = ((LoginErrorException) caught).getErrorType(); if (errType.equals(LoginErrorException.ERROR_INVALID_IDENTIFIER_PASSWORD)) { errMsg = messages.invalidIdentifierOrPassword(); } else if (errType.equals(LoginErrorException.ERROR_ACCOUNT_INACTIVE)) { errMsg = messages.accountInactive(); } else if (errType.equals(LoginErrorException.ERROR_ACCOUNT_LOCKED)) { errMsg = messages.accountLocked(); } MessageBox.alert(messages.error(), errMsg, null).setIcon(MessageBox.ERROR); } else { PIGE.handleException(caught); } } }); // logIn() }
From source file:cimav.visorglass.client.widgets.PanelesLayout.java
License:Apache License
@Override protected void onUnload() { super.onUnload(); // Guardar Cookies {//w w w .ja v a2s.co m String valor = "" + btnArbol.isActive(); Cookies.setCookie(SGC_COOKIE_ACTIVE_ARBOL_PANEL, valor, expira()); valor = "" + btnDocumentos.isActive(); Cookies.setCookie(SGC_COOKIE_ACTIVE_DOCUMENTOS_PANEL, valor, expira()); valor = "" + btnVisor.isActive(); Cookies.setCookie(SGC_COOKIE_ACTIVE_VISOR_PANEL, valor, expira()); Double widthArbol = splitLayoutPanel.getWidgetSize(flowPanelDecoratorArbol); Double widthVisor = splitLayoutPanel.getWidgetSize(flowPanelDecoratorVisor); Cookies.setCookie(SGC_COOKIE_WIDTH_ARBOL_PANEL, String.valueOf(Math.round(widthArbol)), expira()); Cookies.setCookie(SGC_COOKIE_WIDTH_VISOR_PANEL, String.valueOf(Math.round(widthVisor)), expira()); } }
From source file:cl.uai.client.MarkingInterface.java
License:Open Source License
/** /**//from ww w . j a va 2 s . c om * */ public MarkingInterface() { // The timer will check if no other resize events have been called in the last 200 ms resizeTimer = new Timer() { @Override public void run() { Date now = new Date(); long diff = now.getTime() - resizeTime.getTime(); // The last resize was in less than 200 ms if (diff < 200) { resizeTimer.schedule(200); } else { // More than 200 ms, we accept no more resize is being done resizeTimeout = false; Date oneyear = new Date(); CalendarUtil.addMonthsToDate(oneyear, 12); Cookies.setCookie("emarking_width", Integer.toString(Window.getClientWidth()), oneyear); EMarkingWeb.markingInterface.loadSubmissionData(); } } }; // Focus panel to catch key events focusPanel = new FocusPanel(); // Main panel has two rows: Toolbar and Marking panel mainPanel = new VerticalPanel(); mainPanel.addStyleName(Resources.INSTANCE.css().interfaceMainPanel()); focusPanel.setWidget(mainPanel); // Toolbar goes up toolbar = new MarkingToolBar(); mainPanel.add(toolbar); focusPanel.addKeyDownHandler(new MarkingInterfaceKeyDownHandler(toolbar)); // Marking panel containing the marking interface interfacePanel = new SplitLayoutPanel() { @Override public void onResize() { super.onResize(); markingPagesInterface.resizePage(this.getCenterWidth()); }; }; interfacePanel.animate(180); interfacePanel.addStyleName(Resources.INSTANCE.css().interfacepanel()); loadingMessage = new HTML(messages.Loading() + " " + EMarkingConfiguration.getMoodleUrl()); bubbleButtons = new ArrayList<BubbleButton>(); bubbleButtons.add(new ShowRubricButton(Window.getClientWidth() - 40, 0, 0)); bubbleButtons.add(new ShowChatButton(Window.getClientWidth() - 40, 45, NodeChat.SOURCE_CHAT)); bubbleButtons.add(new ShowWallButton(Window.getClientWidth() - 40, 90, NodeChat.SOURCE_WALL)); bubbleButtons.add(new ShowHelpButton(Window.getClientWidth() - 40, 135, NodeChat.SOURCE_SOS)); interfacePanel.add(loadingMessage); // interfacePanel.setCellHorizontalAlignment(loadingMessage, HasAlignment.ALIGN_CENTER); markingPanel = new AbsolutePanel(); markingPanel.add(interfacePanel); for (BubbleButton b : bubbleButtons) { markingPanel.add(b); } mainPanel.add(markingPanel); // Timer for pinging system timer = new Timer() { @Override public void run() { // If there are ticks to wait before trying again, update message and update ticks if (ticksUntilTrying > 0) { loadingMessage.setHTML(messages.CantReachServerRetrying(ticksUntilTrying)); ticksUntilTrying--; } else { // Updating next trial for one more second and trying onLoad again timerWaitingTurns++; ticksUntilTrying = Math.min(timerWaitingTurns, 60); loadingMessage.setHTML(messages.Loading() + " " + EMarkingConfiguration.getMoodleUrl()); onLoad(); } } }; heartBeatTimer = new Timer() { @Override public void run() { String extradata = ""; if (submissionData != null) extradata = "&marker=" + submissionData.getMarkerid() + "&draft=" + submissionData.getId(); final String requestUrl = extradata; AjaxRequest.ajaxRequest("action=heartbeat" + extradata, new AsyncCallback<AjaxData>() { @Override public void onSuccess(AjaxData result) { logger.info("Heartbeat! " + requestUrl); } @Override public void onFailure(Throwable caught) { logger.warning("Failure on heartbeat"); } }); } }; // Drag and Drop controller attached to marking panel dragController = new PickupDragController(markingPanel, false); waitDialog = new DialogBox(false, true); waitDialog.setGlassEnabled(true); waitDialog.addStyleName(Resources.INSTANCE.css().commentdialog()); waitDialog.setHTML(MarkingInterface.messages.Loading()); ProgressBar pbar = new ProgressBar(ProgressBarBase.Style.STRIPED); pbar.setActive(true); pbar.setPercent(100); waitDialog.setWidget(pbar); this.initWidget(focusPanel); }
From source file:cl.uai.client.MarkingInterface.java
License:Open Source License
public void setColoredRubric(boolean colored) { Date oneyear = new Date(); CalendarUtil.addMonthsToDate(oneyear, 12); Cookies.setCookie("emarking_showcolors", colored ? "1" : "0", oneyear); EMarkingConfiguration.setColoredRubric(colored); EMarkingWeb.markingInterface.loadInterface(); }
From source file:cl.uai.client.rubric.RubricInterface.java
License:Open Source License
@Override public void setVisible(boolean visible) { super.setVisible(visible); Date oneyear = new Date(); CalendarUtil.addMonthsToDate(oneyear, 12); Cookies.setCookie("emarking_showrubric", visible ? "1" : "0", oneyear); EMarkingConfiguration.setShowRubricOnLoad(visible); EMarkingWeb.markingInterface.getMarkingPagesInterface().loadInterface(); EMarkingWeb.markingInterface.setShowRubricButtonVisible(visible); }
From source file:com.chinarewards.gwt.license.client.support.impl.CookieSessionManager.java
protected void tokenObtained(UserSession rep) { if (rep != null && rep.getToken() != null) { session.setToken(rep.getToken()); session.setLoginName(rep.getLoginName()); session.setCorporationId(rep.getCorporationId()); session.setUserRoles(rep.getUserRoles()); session.setDepartmentId(rep.getDepartmentId()); session.setStaffId(rep.getStaffId()); session.setLastLoginRole(rep.getLastLoginRole()); session.setCorporationName(rep.getCorporationName()); session.setPhoto(rep.getPhoto()); Date expires = new Date((new Date()).getTime() + COOKIE_TIMEOUT); Cookies.setCookie("token", rep.getToken(), expires); } else {//from ww w . j a v a2s . c o m session.setToken(null); Cookies.removeCookie("token"); } }
From source file:com.chinarewards.gwt.license.client.support.impl.CookieSessionManager.java
protected void tokenObtaineds(LoginResponse rep) { if (rep != null && rep.getToken() != null) { session.setToken(rep.getToken()); session.setLoginName(rep.getLoginName()); session.setCorporationId(rep.getCorporationId()); session.setUserRoles(rep.getUserRoles()); session.setDepartmentId(rep.getDepartmentId()); session.setStaffId(rep.getStaffId()); session.setLastLoginRole(rep.getLastLoginRole()); session.setCorporationName(rep.getCorporationName()); session.setPhoto(rep.getPhoto()); Date expires = new Date((new Date()).getTime() + COOKIE_TIMEOUT); Cookies.setCookie("token", rep.getToken(), expires); } else {//w w w. j a v a2 s . c o m session.setToken(null); Cookies.removeCookie("token"); } }
From source file:com.chinarewards.gwt.license.client.support.impl.CookieSessionManager.java
protected void tokenObtainedToo(TokenValidResponse rep) { if (rep != null && rep.getToken() != null) { session.setToken(rep.getToken()); session.setLoginName(rep.getLoginName()); session.setCorporationId(rep.getCorporationId()); session.setUserRoles(rep.getUserRoles()); session.setDepartmentId(rep.getDepartmentId()); session.setStaffId(rep.getStaffId()); session.setLastLoginRole(rep.getLastLoginRole()); session.setCorporationName(rep.getCorporationName()); session.setPhoto(rep.getPhoto()); Date expires = new Date((new Date()).getTime() + COOKIE_TIMEOUT); Cookies.setCookie("token", rep.getToken(), expires); } else {/*from w w w.j a v a2 s. c o m*/ session.setToken(null); Cookies.removeCookie("token"); } }
From source file:com.data2semantics.yasgui.client.helpers.LocalStorageHelper.java
License:Open Source License
public static void setAsCookie(String key, String value, int expireDays) { key = Helper.getCurrentHost() + "_" + key; Cookies.removeCookie(key);//from w w w .j av a2s. c om Cookies.setCookie(key, value, getExpireDate(expireDays)); }