Search in sources :

Example 1 with DisclosurePanel

use of com.google.gwt.user.client.ui.DisclosurePanel in project opentsdb by OpenTSDB.

the class QueryUi method asyncGetJson.

private void asyncGetJson(final String url, final GotJsonCallback callback) {
    final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    try {
        builder.sendRequest(null, new RequestCallback() {

            public void onError(final Request request, final Throwable e) {
                displayError("Failed to get " + url + ": " + e.getMessage());
                // Since we don't call the callback we've been given, reset this
                // bit of state as we're not going to retry anything right now.
                pending_requests = 0;
            }

            public void onResponseReceived(final Request request, final Response response) {
                final int code = response.getStatusCode();
                if (code == Response.SC_OK) {
                    clearError();
                    callback.got(JSONParser.parse(response.getText()));
                    return;
                } else if (code >= Response.SC_BAD_REQUEST) {
                    // 400+ => Oops.
                    // Since we don't call the callback we've been given, reset this
                    // bit of state as we're not going to retry anything right now.
                    pending_requests = 0;
                    String err = response.getText();
                    // an error message.
                    if (!err.isEmpty() && err.charAt(0) == '{') {
                        final JSONValue json = JSONParser.parse(err);
                        final JSONObject result = json == null ? null : json.isObject();
                        final JSONValue jerr = result == null ? null : result.get("err");
                        final JSONString serr = jerr == null ? null : jerr.isString();
                        err = serr.stringValue();
                        // If the error message has multiple lines (which is common if
                        // it contains a stack trace), show only the first line and
                        // hide the rest in a panel users can expand.
                        final int newline = err.indexOf('\n', 1);
                        final String msg = "Request failed: " + response.getStatusText();
                        if (newline < 0) {
                            displayError(msg + ": " + err);
                        } else {
                            displayError(msg);
                            final DisclosurePanel dp = new DisclosurePanel(err.substring(0, newline));
                            // Attach the widget.
                            RootPanel.get("queryuimain").add(dp);
                            final InlineLabel content = new InlineLabel(err.substring(newline, err.length()));
                            // For readable stack traces.
                            content.addStyleName("fwf");
                            dp.setContent(content);
                            current_error.getElement().appendChild(dp.getElement());
                        }
                    } else {
                        displayError("Request failed while getting " + url + ": " + response.getStatusText());
                        // Since we don't call the callback we've been given, reset this
                        // bit of state as we're not going to retry anything right now.
                        pending_requests = 0;
                    }
                    graphstatus.setText("");
                }
            }
        });
    } catch (RequestException e) {
        displayError("Failed to get " + url + ": " + e.getMessage());
    }
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) Request(com.google.gwt.http.client.Request) DisclosurePanel(com.google.gwt.user.client.ui.DisclosurePanel) JSONString(com.google.gwt.json.client.JSONString) RequestException(com.google.gwt.http.client.RequestException) EntryPoint(com.google.gwt.core.client.EntryPoint) Response(com.google.gwt.http.client.Response) JSONValue(com.google.gwt.json.client.JSONValue) RequestCallback(com.google.gwt.http.client.RequestCallback) JSONObject(com.google.gwt.json.client.JSONObject) InlineLabel(com.google.gwt.user.client.ui.InlineLabel) JSONString(com.google.gwt.json.client.JSONString)

Example 2 with DisclosurePanel

use of com.google.gwt.user.client.ui.DisclosurePanel in project gwt-test-utils by gwt-test-utils.

the class DisclosurePanelTest method style.

@Test
public void style() {
    // Given
    DisclosurePanel dp = new DisclosurePanel();
    // Preconditions
    assertThat(dp.getStyleName()).isEqualTo("gwt-DisclosurePanel gwt-DisclosurePanel-closed");
    // When
    dp.setOpen(true);
    // Then
    assertThat(dp.getStyleName()).isEqualTo("gwt-DisclosurePanel gwt-DisclosurePanel-open");
}
Also used : DisclosurePanel(com.google.gwt.user.client.ui.DisclosurePanel) Test(org.junit.Test)

Example 3 with DisclosurePanel

use of com.google.gwt.user.client.ui.DisclosurePanel in project gwt-test-utils by gwt-test-utils.

the class DisclosurePanelTest method visible.

@Test
public void visible() {
    // Given
    DisclosurePanel dp = new DisclosurePanel();
    // Preconditions
    assertThat(dp.isVisible()).isEqualTo(true);
    // When
    dp.setVisible(false);
    // Then
    assertThat(dp.isVisible()).isEqualTo(false);
}
Also used : DisclosurePanel(com.google.gwt.user.client.ui.DisclosurePanel) Test(org.junit.Test)

Example 4 with DisclosurePanel

use of com.google.gwt.user.client.ui.DisclosurePanel in project gwt-test-utils by gwt-test-utils.

the class DisclosurePanelTest method title.

@Test
public void title() {
    // Given
    DisclosurePanel dp = new DisclosurePanel();
    // When
    dp.setTitle("title");
    // Then
    assertThat(dp.getTitle()).isEqualTo("title");
}
Also used : DisclosurePanel(com.google.gwt.user.client.ui.DisclosurePanel) Test(org.junit.Test)

Aggregations

DisclosurePanel (com.google.gwt.user.client.ui.DisclosurePanel)4 Test (org.junit.Test)3 EntryPoint (com.google.gwt.core.client.EntryPoint)1 Request (com.google.gwt.http.client.Request)1 RequestBuilder (com.google.gwt.http.client.RequestBuilder)1 RequestCallback (com.google.gwt.http.client.RequestCallback)1 RequestException (com.google.gwt.http.client.RequestException)1 Response (com.google.gwt.http.client.Response)1 JSONObject (com.google.gwt.json.client.JSONObject)1 JSONString (com.google.gwt.json.client.JSONString)1 JSONValue (com.google.gwt.json.client.JSONValue)1 InlineLabel (com.google.gwt.user.client.ui.InlineLabel)1