List of usage examples for com.google.gwt.user.client Cookies getCookie
public static String getCookie(String name)
From source file:org.rebioma.client.ListView.java
License:Apache License
/** * Deletes a set of {@link Occurrence} objects via {@link DataSwitch}. * /*from w w w . jav a 2s. c o m*/ * @param toDelete occurrence set to delete */ private void deleteOccurrences(final Set<Occurrence> occurrences) { if (occurrences.isEmpty()) { Window.alert(constants.NoActionCantDeleteOthers()); return; } else { if (!Window.confirm(constants.DeleteConfirm())) { return; } } String sessionId = Cookies.getCookie(ApplicationView.SESSION_ID_NAME); DataSwitch.get().delete(sessionId, occurrences, new AsyncCallback<String>() { public void onFailure(Throwable caught) { try { throw caught; } catch (OccurrenceServiceException e) { Window.confirm(e.toString()); } catch (Throwable t) { Window.confirm(t.toString()); } } public void onSuccess(String result) { pagerWidget.init(pagerWidget.getCurrentPageNumber()); //tax setCheckedAll(false); } }); }
From source file:org.rebioma.client.ListView.java
License:Apache License
@Override public void reviewAllRecords(final Boolean reviewed, String comment, boolean notified) { String sessionId = Cookies.getCookie(ApplicationView.SESSION_ID_NAME); DataSwitch.get().reviewRecords(sessionId, reviewed, pagerWidget.getQuery(), comment, notified, new AsyncCallback<Integer>() { public void onFailure(Throwable caught) { Window.alert(caught.getMessage()); DisplayPopup.getDefaultDisplayPopup().hide(); }//from w w w. j a v a 2 s .c o m public void onSuccess(Integer result) { pagerWidget.init(pagerWidget.getCurrentPageNumber()); showMsg(result + " records was " + (reviewed ? "positively" : "negatively") + " reviewed"); DisplayPopup.getDefaultDisplayPopup().hide(); } }); }
From source file:org.rebioma.client.ListView.java
License:Apache License
@Override public void reviewRecords(Set<Integer> occurrenceIds, final Boolean reviewed, String comment, boolean notified) { String sessionId = Cookies.getCookie(ApplicationView.SESSION_ID_NAME); DataSwitch.get().reviewRecords(sessionId, reviewed, occurrenceIds, comment, notified, new AsyncCallback<Integer>() { public void onFailure(Throwable caught) { Window.alert(caught.getMessage()); DisplayPopup.getDefaultDisplayPopup().hide(); }/*from w w w. java 2s .c o m*/ public void onSuccess(Integer result) { pagerWidget.init(pagerWidget.getCurrentPageNumber()); showMsg(result + " records was " + (reviewed ? "positively" : "negatively") + " reviewed"); DisplayPopup.getDefaultDisplayPopup().hide(); //tax setCheckedAll(false); } }); }
From source file:org.rebioma.client.ListView.java
License:Apache License
@Override public void commentRecords(Set<Integer> occurrenceIds, String comment, boolean notified) { String sessionId = Cookies.getCookie(ApplicationView.SESSION_ID_NAME); DataSwitch.get().commentRecords(sessionId, occurrenceIds, comment, notified, new AsyncCallback<Integer>() { public void onFailure(Throwable caught) { Window.alert(caught.getMessage()); DisplayPopup.getDefaultDisplayPopup().hide(); }//from www. ja v a 2s. c om public void onSuccess(Integer result) { pagerWidget.init(pagerWidget.getCurrentPageNumber()); showMsg(result + " records was commented successfully"); DisplayPopup.getDefaultDisplayPopup().hide(); //tax setCheckedAll(false); } }); }
From source file:org.rebioma.client.ListView.java
License:Apache License
private void updateAll(String updateFilter, final String hint) { OccurrenceQuery query = pagerWidget.getQuery(); query.clearsUpdate();//from w ww .j av a 2 s .com query.addUpdate(updateFilter); String sessionId = Cookies.getCookie(ApplicationView.SESSION_ID_NAME); if (!Window.confirm(constants.Update() + " " + pagerWidget.getTotalRow() + " " + constants.Occurrences() + "?\n Note: " + hint)) { return; } DataSwitch.get().update(sessionId, query, new AsyncCallback<Integer>() { public void onFailure(Throwable caught) { Window.alert(caught.getMessage()); GWT.log(caught.getMessage(), caught); } public void onSuccess(Integer result) { if (result != null) { if (result.intValue() == 0) { showMsg("No records was updated. Hint: " + hint); } else { showMsg(result + " records was updated."); pagerWidget.init(pagerWidget.getCurrentPageNumber()); } } } }); }
From source file:org.rebioma.client.ListView.java
License:Apache License
/** * Handles {@link Occurrence} updates by submitting a request to * {@link DataSwitch}./* w w w. ja va 2 s . c om*/ * * @param warningMsg a warning message when is updated occurrences is empty. * @param ids list of occurrence ids to vet * @param vetted true to vet ids, false to unvet ids */ private void updateOccurrences(Set<Occurrence> updatedOccurrences, String warningMsg) { if (updatedOccurrences.isEmpty()) { Window.alert(warningMsg); return; } String sessionId = Cookies.getCookie(ApplicationView.SESSION_ID_NAME); DataSwitch.get().update(sessionId, updatedOccurrences, new AsyncCallback<String>() { public void onFailure(Throwable caught) { try { throw caught; } catch (OccurrenceServiceException e) { Window.confirm(e.toString()); } catch (Throwable t) { Window.confirm(t.toString()); } } public void onSuccess(String result) { pagerWidget.init(pagerWidget.getCurrentPageNumber()); //tax setCheckedAll(false); } }); }
From source file:org.rebioma.client.OccurrenceView.java
License:Apache License
public void onClick(ClickEvent event) { Object sender = event.getSource(); if (sender == mapLink) { switchView(MAP, false);/*from ww w .j a v a 2 s . com*/ addHistoryItem(false); searchForm.restoreStatesFromHistory(History.getToken()); } else if (sender == listLink) { switchView(LIST, false); addHistoryItem(false); searchForm.restoreStatesFromHistory(History.getToken()); } else if (sender == uploadLink) { switchView(UPLOAD, false); activeViewInfo.getView().resetToDefaultState(); addHistoryItem(false); } else if (sender == searchForm.advanceLink) { switchView(ADVANCE, false); helpLink.setStyleName("helplink"); switchViewPanel.add(helpLink); addHistoryItem(false); } else if (sender == searchForm.shapeDialogLink) { ShapeFileWindow window = new ShapeFileWindow(constants); window.setWidth(400); window.setHeight(300); window.show(); window.addTreeSelectHandler(this); } else if (sender == revalidateLink) { addHistoryItem(false); String sessionId = Cookies.getCookie(ApplicationView.SESSION_ID_NAME); if (revalidateLink.getText().equals(constants.Revalidating())) { /*RevalidationService.Proxy.get().cancelRevalidation(sessionId, new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { revalidateLink.setHTML(constants.Revalidate()); } @Override public void onSuccess(Void result) { revalidateLink.setHTML(constants.Revalidate()); } });*/ } else { revalidateLink.setStyleName("revalidating", true);//add loading image final ServerPingServiceAsync pingService = ServerPingService.Proxy.get(); final Timer sessionAliveTimer = new Timer() { public void run() { pingService.ping(new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { GWT.log("Error while pinging the server", caught); } @Override public void onSuccess(Void result) { GWT.log("Ping success"); } }); } }; sessionAliveTimer.scheduleRepeating(REVALIDATION_SERVER_PING_INTERVAL); RevalidationService.Proxy.get().revalidate(sessionId, new AsyncCallback<RevalidationResult>() { @Override public void onSuccess(RevalidationResult result) { GWT.log("Revalidation success"); revalidateLink.setHTML(constants.Revalidate()); new RevalidationResultPopup(result).show(); revalidateLink.setStyleName("revalidatelink"); revalidateLink.setStyleName("revalidatelink_success", true); //Window.alert(constants.RevalidationSuccess()); sessionAliveTimer.cancel(); } @Override public void onFailure(Throwable caught) { GWT.log("Error while revalidating", caught); revalidateLink.setHTML(constants.Revalidate()); revalidateLink.setStyleName("revalidatelink"); revalidateLink.setStyleName("revalidatelink_error", true); Window.alert(caught.getLocalizedMessage()); sessionAliveTimer.cancel(); } }); revalidateLink.setHTML(constants.Revalidating()); } } else if (sender == ativityLink) { new ActivityLogDialog(constants).show(); } }
From source file:org.rebioma.client.Portal.java
License:Apache License
/** * Checks the current session via RPC. Updates application state. Updates all * tab widgets with new application state. *///w w w.j av a 2 s.c om private void checkCurrentSession() { final String dev = Window.Location.getParameter("gwt.codesvr") == null ? "" : "Portal.html?gwt.codesvr=" + Window.Location.getParameter("gwt.codesvr"); String from = Window.Location.getParameter("from"); String sign = Window.Location.getParameter("signinc"); if (from != null) { String family = Window.Location.getParameter("family"); family = (family == null || family.isEmpty()) ? "" : "&asearch=AcceptedFamily like " + family.trim(); String genus = Window.Location.getParameter("genus"); String m_search = genus == null ? "" : genus; genus = (genus == null || genus.isEmpty()) ? "" : "&asearch=AcceptedGenus like " + genus.trim(); String species = Window.Location.getParameter("species"); m_search = (species == null || species.trim().isEmpty()) ? m_search : species; species = (species == null || species.isEmpty()) ? "" : "&asearch=AcceptedSpecies like " + species.trim(); String year = Window.Location.getParameter("year"); year = (year == null || year.isEmpty()) ? "" : "&asearch=YearCollected = " + year.trim(); Window.Location.replace(GWT.getHostPageBaseURL() + dev + "#tab=occ&view=Map&zoom=5¢er=-19,47&map_type=terrain&left_tab=1&m_search=" + m_search + "&asearch=AcceptedOrder = PRIMATES&m_page=1&page=1" + family + genus + species + "&error_type=all&type=all occurrences"); } else if (sign != null) { String email = Window.Location.getParameter("emailc"); final String id = Window.Location.getParameter("id"); Cookies.removeCookie(ApplicationView.SESSION_ID_NAME); DataSwitch.get().signInC(email, sign, new AsyncCallback<User>() { @Override public void onFailure(Throwable caught) { // TODO Auto-generated method stub } @Override public void onSuccess(User result) { // TODO Auto-generated method stub if (result.getSessionId() == null) initApplication(null); else { Cookies.setCookie(ApplicationView.SESSION_ID_NAME, result.getSessionId(), new Date(System.currentTimeMillis() + 86400000)); Window.Location.replace(GWT.getHostPageBaseURL() + dev + "#tab=occ&view=Detail&id=" + id + "&p=false&page=1&asearch=Id = " + id + "&type=all occurrences"); } } }); } else if (!isSessionIdInBrowser()) { // links.showLinks(HOME_UNAUTHENTICATED_LINKS); initApplication(null); return; } else { String sid = Cookies.getCookie(ApplicationView.SESSION_ID_NAME); DataSwitch.get().isSessionIdValid(sid, new AsyncCallback<User>() { public void onFailure(Throwable caught) { GWT.log(caught.getMessage(), caught); initApplication(null); } public void onSuccess(User result) { if (result != null) { ApplicationView.setSessionId(result.getSessionId()); ApplicationView.refreshSession(); } initApplication(result); } }); } }
From source file:org.rebioma.client.Portal.java
License:Apache License
/** * Returns true if there is a sessionId in the browser * /*from w ww . j av a 2 s.c om*/ * @return true if the browser contains a sessionId */ private boolean isSessionIdInBrowser() { String sessionId = Cookies.getCookie(ApplicationView.SESSION_ID_NAME); return sessionId != null && !sessionId.equals(""); }
From source file:org.rebioma.client.UploadView.java
License:Apache License
private UploadView(View parent, UploadListener uListener) { super(parent, false); this.uploadListener = uListener; modelingBox.setName("modeling"); final VerticalPanel uploadPanel = new VerticalPanel(); uploadPanel.setStyleName("pupload"); HorizontalPanel privateModelField = new HorizontalPanel(); privateModelField.add(privateRadioButton); privateModelField.add(new HTML(" (")); privateModelField.add(modelingBox);/*from w w w. jav a2 s . c om*/ privateModelField.add(new HTML(")")); HorizontalPanel delimiterPanel = new HorizontalPanel(); delimiterBox.addItem(constants.Comma(), ","); delimiterBox.addItem(constants.Semicolon(), ";"); delimiterBox.setName("delimiter"); delimiterPanel.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE); delimiterPanel.add(delimiterBox); delimiterPanel.add(new HTML(" " + constants.CSVDelimiter())); fileUpload.setName("file_upload"); //uploadForm.setAction(GWT.getModuleBaseURL() + "upload"); //uploadForm.setEncoding(FormPanel.ENCODING_MULTIPART); //uploadForm.setMethod(FormPanel.METHOD_POST); //uploadPanel.add(fileUpload); uploadPanel.add(delimiterPanel); showEmailBox.setName("show_email"); clearReviewCheckBox.setName("clear_review"); clearReviewCheckBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() { @Override public void onValueChange(ValueChangeEvent<Boolean> event) { if (event.getValue()) { MessageBox boxWarning = new MessageBox("Reset review state?", ""); boxWarning.setPredefinedButtons(PredefinedButton.YES, PredefinedButton.CANCEL); boxWarning.setIcon(MessageBox.ICONS.warning()); boxWarning.setWidth("415px"); boxWarning.setMessage( "You are resetting all the TRB's review on all occurrences. Would you like to continue?"); boxWarning.addHideHandler(new HideHandler() { @Override public void onHide(HideEvent eventW) { Dialog btnW = (Dialog) eventW.getSource(); if (!btnW.getHideButton().getText().equalsIgnoreCase("yes")) { clearReviewCheckBox.setChecked(false); } } }); boxWarning.show(); } } }); uploadPanel.add(clearReviewCheckBox); uploadPanel.add(showEmailBox); uploadPanel.add(privateModelField); uploadPanel.add(publicRadioButton); setClearReview(ApplicationView.getCurrentState() == ViewState.SUPERADMIN); UserQuery query = friendsTable.getQuery(); query.setUsersCollaboratorsOnly(true); friendsTable.addCheckedListener(this); // TODO: fix resize // friendsTable.setSize("500px", "300px"); friendsTable.resetTable(); HorizontalPanel hp = new HorizontalPanel(); hp.setSpacing(10); uploadPanel.add(hp); //HorizontalPanel buttonPanel = new HorizontalPanel(); // buttonPanel.add(uploadButton); // buttonPanel.add(cancelButton); // buttonPanel.setSpacing(2); //uploadPanel.add(dataSharingAgreementLink); // uploadPanel.add(buttonPanel); hiddenSessionId.setValue(Cookies.getCookie(ApplicationView.SESSION_ID_NAME)); uploadPanel.add(hiddenSessionId); uploadPanel.add(collaboratorsSharing); final VerticalPanel friendsPanel = new VerticalPanel(); Label collaborator = new Label(constants.CollaboratorsOnUpload()); collaborator.setStyleName("title1"); friendsPanel.add(collaborator); friendsPanel.add(friendsTable); //HorizontalPanel friendUplodaHp = new HorizontalPanel(); //friendUplodaHp.add(uploadPanel); //friendUplodaHp.add(friendsPanel); //friendUplodaHp.setSpacing(5); //uploadForm.setWidget(friendUplodaHp); /*mainSp.setWidget(uploadForm); initWidget(mainSp);*/ final FlexTable grid = new FlexTable(); grid.setStyleName("GWTUpld"); final FormPanel form = new FormPanel() { public void add(Widget w) { grid.setWidget(grid.getRowCount(), 1, uploadPanel); grid.getFlexCellFormatter().setRowSpan(0, 2, 20); grid.setWidget(0, 2, new Label(" ")); grid.getFlexCellFormatter().setStyleName(0, 2, "sep"); grid.getFlexCellFormatter().setRowSpan(0, 3, 20); grid.setWidget(0, 3, friendsPanel); grid.setWidget(grid.getRowCount(), 1, dataSharingAgreementLink); grid.setWidget(grid.getRowCount(), 1, w); //grid.getFlexCellFormatter().setColSpan(grid.getRowCount()+1, 1, 2); } { super.add(grid); } }; class MyFancyLookingSubmitButton extends Composite implements HasClickHandlers { DecoratorPanel widget = new DecoratorPanel(); public MyFancyLookingSubmitButton() { Button widget = new Button(constants.AcceptDsaUpload()); initWidget(widget); } public HandlerRegistration addClickHandler(ClickHandler handler) { return addDomHandler(handler, ClickEvent.getType()); } } SingleUploader uploader = new SingleUploader(FileInputType.LABEL, new ModalUploadStatus(), new MyFancyLookingSubmitButton(), form); uploader.setServletPath("send.file"); //mainSp.add(uploader); //grid.setText(5, 0, "Attachment:"); mainSp.setWidget(uploader); uploader.getFileInput().setText(constants.chooseFileLabel()); initWidget(mainSp); uploader.addOnFinishUploadHandler(new OnFinishUploaderHandler() { public void onFinish(IUploader uploader) { if (uploader.getStatus() == Status.SUCCESS) { Document doc = null; String displayMsg = null; try { doc = XMLParser.parse(uploader.getServerResponse()); displayMsg = Utils.getXmlNodeValue(doc, "message"); } catch (Exception e) { } //Window.alert("Server response: \n" + displayMsg); setUploadEnable(true); if (displayMsg != null) { if (displayMsg.matches("<.+>.+<.+>")) { displayMsg = displayMsg.substring(displayMsg.indexOf('>') + 1, displayMsg.lastIndexOf('<')); } JSONObject serverMsg = JSONParser.parse(displayMsg).isObject(); if (serverMsg.get("onSuccess") != null) { JSONValue successValue = serverMsg.get("onSuccess"); popupStatusMessage.showMessage(successValue); popupStatusMessage.setWidth("300px"); //uploadForm.reset(); } else { JSONObject error = serverMsg.get("onFailure").isObject(); String errorKey = error.keySet().iterator().next(); JSONValue jValue = error.get(errorKey); if (errorKey.equals("No File")) { Window.alert(constants.UploadFailedNoFile()); } else if (errorKey.equals("Invalid File")) { Window.alert(constants.UploadFailedInvalidFile()); } else if (errorKey.equals("Missing Required Headers")) { Window.alert(constants.MissingRequiredHeader() + jValue.isArray()); } else { Window.alert(constants.UploadFailedException() + jValue.isString()); } } } DataSwitch.get().clearCache(DataSwitch.OCCURRENCE_KEY); uploadListener.onUploadComplete(); popupStatusMessage.checkAndResize(); uploader.getFileInput().setText(constants.chooseFileLabel()); uploader.getFileInput().setSize("200px", "auto"); uploader.reset(); form.reset(); } } }); initListeners(); cancelButton.setEnabled(false); publicRadioButton.setValue(true); showEmailBox.setValue(true); // Adds upload form handlers //uploadForm.addSubmitHandler(new SubmitHandler() { /** * If the uploading file is empty display an error message and cancels the * submit event. * * @see com.google.gwt.user.client.ui.FormPanel.SubmitHandler#onSubmit(com.google.gwt.user.client.ui.FormPanel.SubmitEvent) */ /*public void onSubmit(SubmitEvent event) { if (fileUpload.getFilename().equals("")) { Window.alert(constants.FileCantBeEmpty()); event.cancel(); } else { uploadListener.onUploadStart(); setUploadEnable(false); } } });*/ //uploadForm.addSubmitCompleteHandler(new SubmitCompleteHandler() { /** * Notifies the user whether the upload was successful. Also clears the * DataSwitch cache since new records were uploaded. * * @see com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler#onSubmitComplete(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent) */ /*public void onSubmitComplete(SubmitCompleteEvent event) { setUploadEnable(true); String displayMsg = event.getResults(); // displayMsg = // "<something>{\"onFailure\": \"No file uploaded\"}</something>"; if (displayMsg.matches("<.+>.+<.+>")) { displayMsg = displayMsg.substring(displayMsg.indexOf('>') + 1, displayMsg.lastIndexOf('<')); } JSONObject serverMsg = JSONParser.parse(displayMsg).isObject(); if (serverMsg.get("onSuccess") != null) { JSONValue successValue = serverMsg.get("onSuccess"); popupStatusMessage.showMessage(successValue); uploadForm.reset(); } else { JSONObject error = serverMsg.get("onFailure").isObject(); String errorKey = error.keySet().iterator().next(); JSONValue jValue = error.get(errorKey); if (errorKey.equals("No File")) { Window.alert(constants.UploadFailedNoFile()); } else if (errorKey.equals("Invalid File")) { Window.alert(constants.UploadFailedInvalidFile()); } else if (errorKey.equals("Missing Required Headers")) { Window.alert(constants.MissingRequiredHeader() + jValue.isArray()); } else { Window.alert(constants.UploadFailedException() + jValue.isString()); } } DataSwitch.get().clearCache(DataSwitch.OCCURRENCE_KEY); uploadListener.onUploadComplete(); popupStatusMessage.checkAndResize(); } });*/ }