List of usage examples for com.google.gwt.json.client JSONValue isString
public JSONString isString()
From source file:org.pentaho.ui.database.event.DataHandler.java
License:Open Source License
private void gatherErrors(Response response) { if (response.getStatusCode() == Response.SC_OK && !response.getText().equalsIgnoreCase("null")) { //$NON-NLS-1$ String message = ""; //$NON-NLS-1$ final JSONValue jsonValue = JSONParser.parseStrict(response.getText()); final String keyItems = "items"; //$NON-NLS-1$ final String starter = "* "; //$NON-NLS-1$ if (jsonValue.isObject() != null && jsonValue.isObject().containsKey(keyItems)) { final JSONValue items = jsonValue.isObject().get(keyItems); if (items.isArray() != null) { for (int i = 0; i < items.isArray().size(); i++) { message = message.concat(starter).concat(items.isArray().get(i).isString().stringValue()) .concat(LINE_SEPARATOR); }/*from w w w .jav a2 s . c om*/ } else if (items.isString() != null) { message = message.concat(starter).concat(items.isString().stringValue()).concat(LINE_SEPARATOR); } else { message = message.concat(starter).concat(items.toString()).concat(LINE_SEPARATOR); } } else { message = message.concat(starter).concat(jsonValue.toString()).concat(LINE_SEPARATOR); } showMessage(messages.getString("DataHandler.CHECK_PARAMS_TITLE"), message, false); //$NON-NLS-1$ } else { showMessage(messages.getString("DataHandler.ERROR_MESSAGE_TITLE"), response.getStatusText(), //$NON-NLS-1$ response.getStatusText().length() > 300); } }
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);//w w w.j av a2 s.c o m 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(); } });*/ }
From source file:org.roda.wui.client.common.utils.FormUtilities.java
private static String getFieldLabel(MetadataValue mv) { String result = mv.getId();/*w w w . java 2s.c o m*/ String rawLabel = mv.get("label"); if (rawLabel != null && rawLabel.length() > 0) { String loc = LocaleInfo.getCurrentLocale().getLocaleName(); try { JSONObject jsonObject = JSONParser.parseLenient(rawLabel).isObject(); JSONValue jsonValue = jsonObject.get(loc); if (jsonValue != null) { JSONString jsonString = jsonValue.isString(); if (jsonString != null) { result = jsonString.stringValue(); } } else { if (loc.contains("_")) { jsonValue = jsonObject.get(loc.split("_")[0]); if (jsonValue != null) { JSONString jsonString = jsonValue.isString(); if (jsonString != null) { result = jsonString.stringValue(); } } } // label for the desired language doesn't exist // do nothing } } catch (JSONException e) { // The JSON was malformed // do nothing } } mv.set("l", result); return result; }
From source file:org.roda.wui.client.common.utils.FormUtilities.java
private static void addList(FlowPanel panel, final FlowPanel layout, final MetadataValue mv, final boolean mandatory) { // Top Label/* ww w. ja v a 2 s . co m*/ Label mvLabel = new Label(getFieldLabel(mv)); mvLabel.addStyleName("form-label"); if (mandatory) { mvLabel.addStyleName("form-label-mandatory"); } // Field final ListBox mvList = new ListBox(); mvList.setTitle(mvLabel.getText()); mvList.addStyleName("form-textbox"); String options = mv.get("options"); JSONArray optionsArray = null; if (options != null) { optionsArray = JSONParser.parseLenient(options).isArray(); } String list = mv.get("optionsLabels"); mvList.addItem(""); if (list != null) { JSONArray jsonArray = JSONParser.parseLenient(list).isArray(); if (jsonArray != null) { for (int i = 0; i < jsonArray.size(); i++) { String value = jsonArray.get(i).isString().stringValue(); mvList.addItem(value); if (value.equals(mv.get("value"))) { mvList.setSelectedIndex(i + 1); } } } else { JSONObject jsonObject = JSONParser.parseLenient(list).isObject(); if (jsonObject != null) { String loc = LocaleInfo.getCurrentLocale().getLocaleName(); int i = 0; if (optionsArray != null) { for (int pos = 0; pos < optionsArray.size(); pos++) { String key = optionsArray.get(pos).isString().stringValue(); JSONValue entry = jsonObject.get(key); if (entry.isObject() != null) { JSONValue jsonValue = entry.isObject().get(loc); String value; if (jsonValue != null) { value = jsonValue.isString().stringValue(); } else { value = entry.isObject().get(entry.isObject().keySet().iterator().next()) .isString().stringValue(); } if (value != null) { mvList.addItem(value, key); if (key.equals(mv.get("value"))) { mvList.setSelectedIndex(i + 1); } } } i++; } } else { for (String key : jsonObject.keySet()) { JSONValue entry = jsonObject.get(key); if (entry.isObject() != null) { JSONValue jsonValue = entry.isObject().get(loc); String value; if (jsonValue != null) { value = jsonValue.isString().stringValue(); } else { value = entry.isObject().get(entry.isObject().keySet().iterator().next()) .isString().stringValue(); } if (value != null) { mvList.addItem(value, key); if (key.equals(mv.get("value"))) { mvList.setSelectedIndex(i + 1); } } } i++; } } } } } else { if (optionsArray != null) { int i = 0; for (int pos = 0; pos < optionsArray.size(); pos++) { String key = optionsArray.get(pos).isString().stringValue(); if (key != null) { mvList.addItem(key, key); if (key.equals(mv.get("value"))) { mvList.setSelectedIndex(i + 1); } } i++; } } } mvList.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent changeEvent) { mv.set("value", mvList.getSelectedValue()); if (mandatory && (mvList.getSelectedValue() != null && !"".equals(mvList.getSelectedValue().trim()))) { mvList.removeStyleName("isWrong"); } if (mandatory && (mvList.getSelectedValue() == null || "".equalsIgnoreCase(mvList.getSelectedValue().trim()))) { mvList.removeStyleName("isWrong"); } } }); if (mv.get("value") == null || mv.get("value").isEmpty()) { mvList.setSelectedIndex(0); mv.set("value", mvList.getSelectedValue()); } layout.add(mvLabel); layout.add(mvList); // Description String description = mv.get("description"); if (description != null && description.length() > 0) { Label mvDescription = new Label(description); mvDescription.addStyleName("form-help"); layout.add(mvDescription); } if (mv.get("error") != null && !"".equals(mv.get("error").trim())) { Label errorLabel = new Label(mv.get("error")); errorLabel.addStyleName("form-label-error"); layout.add(errorLabel); mvList.addStyleName("isWrong"); } panel.add(layout); }
From source file:org.rstudio.studio.client.common.SimpleRequestCallback.java
License:Open Source License
@Override public void onError(ServerError error) { Debug.logError(error);/*ww w. ja v a2s .c o m*/ String message = error.getUserMessage(); // see if a special message was provided if (useClientInfoMsg_) { JSONValue errValue = error.getClientInfo(); if (errValue != null) { JSONString errMsg = errValue.isString(); if (errMsg != null) message = errMsg.stringValue(); } } RStudioGinjector.INSTANCE.getGlobalDisplay().showErrorMessage(caption_, message); }
From source file:org.rstudio.studio.client.workbench.views.source.Source.java
License:Open Source License
private void openFile(final FileSystemItem file, final TextFileType fileType, final CommandWithArg<EditingTarget> executeOnSuccess) { openFile(file, fileType, new ResultCallback<EditingTarget, ServerError>() { @Override//from ww w . j a v a 2s . c o m public void onSuccess(EditingTarget target) { if (executeOnSuccess != null) executeOnSuccess.execute(target); } @Override public void onFailure(ServerError error) { String message = error.getUserMessage(); // see if a special message was provided JSONValue errValue = error.getClientInfo(); if (errValue != null) { JSONString errMsg = errValue.isString(); if (errMsg != null) message = errMsg.stringValue(); } globalDisplay_.showMessage(GlobalDisplay.MSG_ERROR, "Error while opening file", message); } }); }
From source file:org.sonar.api.web.gwt.client.webservices.JsonUtils.java
License:Open Source License
public static String getString(JSONObject json, String field) { JSONValue jsonValue; JSONString jsonString;// w w w.j a v a 2 s .c om if ((jsonValue = json.get(field)) == null) { return null; } if ((jsonString = jsonValue.isString()) == null) { JSONNumber jsonNumber = jsonValue.isNumber(); return jsonNumber != null ? jsonNumber.toString() : null; } return jsonString.stringValue(); }
From source file:org.sonar.api.web.gwt.client.webservices.SourcesQuery.java
License:Open Source License
private FileSource parseLines(JavaScriptObject obj) { Map<Integer, String> sourceLines = new TreeMap<Integer, String>(); FileSource src = new FileSource(sourceLines); JSONArray jsonArray = new JSONArray(obj); if (jsonArray.size() == 0) return src; JSONObject sources = jsonArray.get(0).isObject(); if (sources.size() == 0) return src; int maxSize = new Double(Math.pow(2, 16)).intValue(); int currentLine = from == 0 ? 1 : from; while (currentLine < maxSize) { JSONValue line = sources.get(Integer.toString(currentLine)); if (line == null) { break; }/*from ww w .j ava2s . c o m*/ sourceLines.put(currentLine++, line.isString().stringValue()); } return src; }
From source file:org.sonar.gwt.JsonUtils.java
License:Open Source License
public static String getAsString(JSONValue jsonValue) { if (jsonValue == null) { return null; }/* w w w. j a va 2s . c o m*/ JSONString jsonString; if ((jsonString = jsonValue.isString()) == null) { JSONNumber jsonNumber = jsonValue.isNumber(); return jsonNumber != null ? jsonNumber.toString() : null; } return jsonString.stringValue(); }
From source file:org.sonar.gwt.JsonUtils.java
License:Open Source License
public static Double getAsDouble(JSONValue jsonValue) { if (jsonValue == null) { return null; }// ww w. ja v a 2 s. c o m JSONNumber jsonNumber; if ((jsonNumber = jsonValue.isNumber()) == null) { JSONString jsonString = jsonValue.isString(); return jsonString != null ? Double.parseDouble(jsonString.toString()) : null; } return jsonNumber.doubleValue(); }