List of usage examples for com.google.gwt.core.client JsonUtils safeEval
public static native <T extends JavaScriptObject> T safeEval(String json) ;
From source file:org.cruxframework.crux.tools.codeserver.client.CodeServerNotifier.java
License:Apache License
private void addHandlers(final WebSocket socket) { socket.addCloseHandler(new SocketCloseHandler() { @Override/*from www. ja va 2 s. c om*/ public void onClose(SocketCloseEvent event) { logger.info("Compilation Notifier Socket was closed. Trying to reconnect..."); socket.reconnect(); } }); socket.addOpenHandler(new SocketOpenHandler() { @Override public void onOpen(SocketOpenEvent event) { if (LogConfiguration.loggingIsEnabled()) { logger.log(Level.INFO, "Connected to Compilation Notifier service."); } } }); socket.addErrorHandler(new SocketErrorHandler() { @Override public void onError(SocketErrorEvent event) { if (LogConfiguration.loggingIsEnabled()) { logger.log(Level.INFO, "Unexpected error on Compilation Notifier service socket."); } } }); socket.addMessageHandler(new SocketMessageHandler() { @Override public void onMessage(SocketMessageEvent event) { try { String message = event.getMessage(); CompilationMessage compilationMessage = JsonUtils.safeEval(message); switch (compilationMessage.getOperation()) { case START: Screen.blockToUser(); logger.log(Level.INFO, "Module: " + compilationMessage.getModule()); dialogBox.show(); break; case END: Screen.unblockToUser(); dialogBox.hide(); if (compilationMessage.getStatus()) { Window.Location.reload(); } else { Crux.getErrorHandler() .handleError("Error compiling module " + compilationMessage.getModule() + "."); } break; } } catch (Exception e) { Crux.getErrorHandler().handleError("Error parsing message from Compilation Notifier service", e); } } }); }
From source file:org.eclipse.che.ide.examples.CheFluxLiveEditExtension.java
License:Open Source License
protected void connectToFlux(final String url) { final SocketIOOverlay io = getSocketIO(); Log.info(getClass(), "connecting to " + url); socket = io.connect(url);// w ww . j av a 2s. c o m socket.on("error", new Runnable() { @Override public void run() { Log.info(getClass(), "error connecting to " + url); } }); socket.on("liveResourceChanged", new Consumer<FluxResourceChangedEventDataOverlay>() { @Override public void accept(FluxResourceChangedEventDataOverlay event) { Document document = liveDocuments.get("/" + event.getProject() + "/" + event.getResource()); if (document == null) { return; } String addedCharacters = event.getAddedCharacters(); isUpdatingModel = true; document.replace(event.getOffset(), event.getRemovedCharCount(), addedCharacters); // public void replace(int offset, int length, String text) { // this.editorOverlay.setText(text, offset, offset + length); isUpdatingModel = false; } }); socket.emit("connectToChannel", JsonUtils.safeEval("{\"channel\" : \"USER\"}")); }
From source file:org.eclipse.che.ide.flux.liveedit.CheFluxLiveEditExtension.java
License:Open Source License
protected void connectToFlux(final String url) { final SocketIOOverlay io = getSocketIO(); Log.info(getClass(), "connecting to " + url); socket = io.connect(url);//w w w . j a va 2 s . com socket.on("error", new Runnable() { @Override public void run() { Log.info(getClass(), "error connecting to " + url); } }); socket.on("liveResourceChanged", new Consumer<FluxResourceChangedEventDataOverlay>() { @Override public void accept(FluxResourceChangedEventDataOverlay event) { Document document = liveDocuments.get("/" + event.getProject() + "/" + event.getResource()); if (document == null) { return; } isUpdatingModel = true; path = document.getFile().getLocation(); openedEditor = editorAgent.getOpenedEditor(path); if (openedEditor instanceof TextEditor) { textEditor = (TextEditor) openedEditor; } String annotationStyle; String username = event.getChannelName(); updateCursorHandler(username); cursorHandlerForPairProgramming = cursorHandlers.get(username); annotationStyle = "pairProgramminigUser" + cursorHandlerForPairProgramming.getUserId(); int offset = event.getOffset(); if (openedEditor == null) { StatusNotification statusNotification = new StatusNotification( document.getFile().getLocation().toString() + " is being edited", SUCCESS, FLOAT_MODE); statusNotification.setState(READ); notificationManager.notify(statusNotification); return; } if (event.getRemovedCharCount() == 0) { offset++; } String addedCharacters = event.getAddedCharacters(); TextPosition cursorPosition = document.getCursorPosition(); document.replace(event.getOffset(), event.getRemovedCharCount(), addedCharacters); document.setCursorPosition(cursorPosition); TextPosition markerPosition = textEditor.getDocument().getPositionFromIndex(offset); TextRange textRange = new TextRange(markerPosition, markerPosition); if (cursorHandlerForPairProgramming.getMarkerRegistration() != null) { cursorHandlerForPairProgramming.clearMark(); } cursorHandlerForPairProgramming .setMarkerRegistration(textEditor.getEditorWidget().addMarker(textRange, annotationStyle)); cursorHandlers.remove(username); cursorHandlers.put(username, cursorHandlerForPairProgramming); isUpdatingModel = false; } }); socket.on("liveCursorOffsetChanged", new Consumer<FluxResourceChangedEventDataOverlay>() { @Override public void accept(FluxResourceChangedEventDataOverlay event) { Document document = liveDocuments.get("/" + event.getProject() + "/" + event.getResource()); if (document == null) { return; } isUpdatingModel = true; path = document.getFile().getLocation(); openedEditor = editorAgent.getOpenedEditor(path); if (openedEditor instanceof TextEditor) { textEditor = (TextEditor) openedEditor; } String annotationStyle; String username = event.getChannelName(); updateCursorHandler(username); cursorHandlerForPairProgramming = cursorHandlers.get(username); annotationStyle = "pairProgramminigUser" + cursorHandlerForPairProgramming.getUserId(); int offset = event.getOffset(); /*if removed count equals to -100 that means there is only a cursor change */ TextPosition markerPosition = textEditor.getDocument().getPositionFromIndex(offset); TextRange textRange = new TextRange(markerPosition, markerPosition); if (cursorHandlerForPairProgramming.getMarkerRegistration() != null) { cursorHandlerForPairProgramming.clearMark(); } cursorHandlerForPairProgramming .setMarkerRegistration(textEditor.getEditorWidget().addMarker(textRange, annotationStyle)); cursorHandlers.remove(username); cursorHandlers.put(username, cursorHandlerForPairProgramming); isUpdatingModel = false; } }); socket.emit("connectToChannel", JsonUtils.safeEval("{\"channel\" : \"" + channelName + "\"}")); }
From source file:org.geomajas.gwt2.client.service.JsonService.java
License:Open Source License
/** * Takes in a trusted JSON String and evals it. * /*from w w w . j av a 2 s . c o m*/ * @param jsonString JSON string that you trust. * @return JavaScriptObject that you can cast to an Overlay Type */ public static JavaScriptObject eval(String jsonString) { return JsonUtils.safeEval(jsonString); }
From source file:org.gwtbootstrap3.extras.slider.client.ui.base.SliderBase.java
License:Apache License
private List<Double> getNumberArrayAttribute(SliderOption option, List<Double> defaultValue) { // Get array attribute JsArrayNumber array = null;//from ww w .j av a 2s.c o m if (isAttached()) { array = getNumberArrayAttribute(getElement(), option.getName()); } else { String value = attributeMixin.getAttribute(option.getDataAttribute()); if (value != null && !value.isEmpty()) { array = JsonUtils.safeEval(value); } } // Attribute not set if (array == null) { return defaultValue; } // Put array to list List<Double> list = new ArrayList<Double>(array.length()); for (int i = 0; i < array.length(); i++) { list.add(array.get(i)); } return list; }
From source file:org.gwtbootstrap3.extras.slider.client.ui.base.SliderBase.java
License:Apache License
private List<String> getStringArrayAttribute(SliderOption option, List<String> defaultValue) { // Get array attribute JsArrayString array = null;//from w ww . j a v a 2 s . c o m if (isAttached()) { array = getStringArrayAttribute(getElement(), option.getName()); } else { String value = attributeMixin.getAttribute(option.getDataAttribute()); if (value != null && !value.isEmpty()) { array = JsonUtils.safeEval(value); } } // Attribute not set if (array == null) { return defaultValue; } // Put array to list List<String> list = new ArrayList<String>(array.length()); for (int i = 0; i < array.length(); i++) { list.add(array.get(i)); } return list; }
From source file:org.gwtbootstrap3.extras.slider.client.ui.Range.java
License:Apache License
/** * Converts the given string to a range instance.<br> * <br>//from ww w .ja v a 2 s .c o m * Useful when using UiBinder. * * @param value * @return */ public static Range fromString(String value) { if (value == null || value.isEmpty()) return null; JsArrayNumber array = JsonUtils.safeEval(value); return new Range(array); }
From source file:org.iplantc.phyloviewer.client.tree.viewer.OverviewView.java
License:Creative Commons License
public OverviewView(int width, int height) { this.width = width; this.height = height; canvas = new Canvas(width, height); this.add(canvas); this.addMouseMoveHandler(new MouseMoveHandler() { @Override// www . jav a 2s.com public void onMouseMove(MouseMoveEvent arg0) { int x = arg0.getX(); int y = arg0.getY(); // Project the point in screen space to object space. Vector2 position = new Vector2((double) x / OverviewView.this.width, (double) y / OverviewView.this.height); ITree tree = getTree(); if (tree != null) { String layoutID = OverviewView.this.getLayoutType().toString(); treeIntersectService.intersectTree(tree.getRootNode().getId(), layoutID, position.getX(), position.getY(), new AsyncCallback<String>() { @Override public void onFailure(Throwable arg0) { hit = null; OverviewView.this.requestRender(); } @Override public void onSuccess(String arg0) { JsHitResult result = (JsHitResult) JsonUtils.safeEval(arg0); hit = result.getHit(); OverviewView.this.requestRender(); } }); } } }); this.addMouseDownHandler(new MouseDownHandler() { @Override public void onMouseDown(MouseDownEvent arg0) { if (hit != null) { Box2D bbox = ConvertMathTypes.convertToBox2(hit.boundingBox()); zoomToBoundingBox(bbox); } } }); }
From source file:org.jboss.as.quickstarts.gwthelloworld.client.local.HelloWorldClient.java
License:Apache License
/** * Handles a click of the button by sending an AJAX request to the HelloWorldResource and then updating the {@code result} * label in response.//w ww .j ava2 s. c om * * @param e Details of the click event. Ignored by this handler. */ @UiHandler("sayHelloButton") public void onButtonClick(ClickEvent e) { try { new RequestBuilder(RequestBuilder.GET, "hello/json/" + URL.encodePathSegment(name.getValue())) .sendRequest(null, new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == Response.SC_OK) { HelloResponse r = (HelloResponse) JsonUtils.safeEval(response.getText()); result.setText(r.getResult()); } else { handleError("Server responded with status code " + response.getStatusCode()); } } @Override public void onError(Request request, Throwable exception) { handleError(exception.getMessage()); } }); } catch (RequestException exception) { handleError(exception.getMessage()); } }
From source file:org.jbpm.console.ng.ht.forms.client.display.displayers.process.AbstractStartProcessFormDisplayer.java
License:Apache License
protected void eventListener(String origin, String request) { if (origin == null || !origin.endsWith("//" + opener)) { return;// ww w . j av a 2 s . c o m } ActionRequest actionRequest = JsonUtils.safeEval(request); if (ACTION_START_PROCESS.equals(actionRequest.getAction())) { startProcessFromDisplayer(); } }