Example usage for com.google.gwt.user.client.ui Label setText

List of usage examples for com.google.gwt.user.client.ui Label setText

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui Label setText.

Prototype

public void setText(String text) 

Source Link

Document

Sets the label's content to the given text.

Usage

From source file:org.mobicents.slee.container.management.console.client.sleestate.SleeStatePanel.java

License:Open Source License

public SleeStatePanel() {
    super();//www .  j  a v  a 2s.c  om

    startButton.setTitle("Start");
    stopButton.setTitle("Stop");
    shutdownButton.setTitle("Shutdown");
    final Label header = new Label("Mobicents JAIN SLEE is");
    ServerCallback callback = new ServerCallback(this) {
        public void onSuccess(Object result) {
            header.setText((String) result + " is");
        }
    };
    service.getVersion(callback);
    HorizontalPanel buttonsPanel = new HorizontalPanel();
    buttonsPanel.setSpacing(5);
    buttonsPanel.add(startButton);
    buttonsPanel.add(stopButton);
    buttonsPanel.add(shutdownButton);

    startButton.setEnabled(false);
    stopButton.setEnabled(false);
    shutdownButton.setEnabled(false);

    startButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            onStartButton();
        }
    });

    stopButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            onStopButton();
        }
    });

    shutdownButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            onShutdownButton();
        }
    });

    timer = new Timer() {
        public void run() {
            updateState();
        }
    };

    add(header);
    add(state);
    add(buttonsPanel);

    setStyleName("sleestate-SleeStatePanel");
    setSpacing(5);
    state.setStyleName("sleestate-SleeStatePanel-state");

    setCellHorizontalAlignment(header, HasHorizontalAlignment.ALIGN_CENTER);
    setCellHorizontalAlignment(state, HasHorizontalAlignment.ALIGN_CENTER);
    setCellHorizontalAlignment(buttonsPanel, HasHorizontalAlignment.ALIGN_CENTER);
}

From source file:org.ned.server.nedadminconsole.client.widgets.NedStatisticsWidget.java

License:Open Source License

public NedStatisticsWidget() {

    VerticalPanel verticalPanel = new VerticalPanel();
    verticalPanel.setSpacing(15);//from  w  w w .  j  a  va 2s .  c om
    verticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    initWidget(verticalPanel);
    verticalPanel.setSize("100%", "50px");

    buttonDownload = new Button();
    buttonDownload.setText(NedRes.instance().statisticsDownload());

    Grid grid = new Grid(4, 1);
    verticalPanel.add(grid);

    Label lblChooseMethod = new Label();
    lblChooseMethod.setText(NedRes.instance().statisticsChooseMethod());
    grid.setWidget(0, 0, lblChooseMethod);

    rdbtnAllStatistics = new RadioButton("statFilter");
    rdbtnAllStatistics.setText(NedRes.instance().downloadAllStats());
    grid.setWidget(1, 0, rdbtnAllStatistics);

    rdbtnFilterDate = new RadioButton("statFilter");
    rdbtnFilterDate.setText(NedRes.instance().downloadSelectDate());
    grid.setWidget(2, 0, rdbtnFilterDate);

    HorizontalPanel horizontalPanel = new HorizontalPanel();
    grid.setWidget(3, 0, horizontalPanel);

    Label lblFrom = new Label();
    lblFrom.setText(NedRes.instance().statisticsFrom());
    horizontalPanel.add(lblFrom);

    dateBoxFrom = new DateBox();
    dateBoxFrom.setFormat(
            new DefaultFormat(DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_MEDIUM)));
    horizontalPanel.add(dateBoxFrom);

    Label lblTo = new Label();
    lblTo.setText(NedRes.instance().statisticsTo());
    horizontalPanel.add(lblTo);

    dateBoxTo = new DateBox();
    dateBoxTo.setFormat(
            new DefaultFormat(DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_MEDIUM)));
    horizontalPanel.add(dateBoxTo);
    verticalPanel.add(buttonDownload);
    buttonDownload.setSize("30%", "");

    buttonDownload.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            String queryString = "NedStatisticsFileServlet";
            if (rdbtnFilterDate.getValue().booleanValue()) {
                if (dateBoxFrom.getValue() == null || dateBoxTo.getValue() == null) {
                    NedAlert.showAlert(NedRes.instance().statisticsWrongDate());
                    return;
                }
                queryString = queryString + "?from=" + String.valueOf(dateBoxFrom.getValue().getTime()) + "&to="
                        + String.valueOf(dateBoxTo.getValue().getTime());
            }
            com.google.gwt.user.client.Window.Location.assign(GWT.getHostPageBaseURL() + queryString);
        }
    });
}

From source file:org.olanto.TranslationText.client.MainEntryPoint.java

License:Open Source License

public static void download(String fileDownloadURL, final Label msg) {
    Frame fileDownloadFrame = new Frame(fileDownloadURL);
    fileDownloadFrame.setSize("0px", "0px");
    fileDownloadFrame.setVisible(false);
    RootPanel panel = RootPanel.get("__gwt_downloadFrame");
    while (panel.getWidgetCount() > 0) {
        panel.remove(0);//from   w  ww  . j  a  va2s  .  c o m
    }
    panel.add(fileDownloadFrame);
    msg.setText(GuiMessageConst.MSG_32);
}

From source file:org.olanto.TranslationText.client.MyCatDownload.java

License:Open Source License

public static void downloadFileFromServer(String FileName, String Content, final Label msg) {
    rpcD.createTempFile(FileName, Content, new AsyncCallback<String>() {

        @Override/*ww  w.ja  v  a2  s . c o  m*/
        public void onFailure(Throwable caught) {
            Window.alert(GuiMessageConst.MSG_29);
            msg.setText(GuiMessageConst.MSG_30);
        }

        @Override
        public void onSuccess(String result) {
            if (result != null) {
                String fileDownloadURL = fileDownloadURLBase
                        + result.replace("", "$$$$$$").replace("+", "|||") + "&mode=file";
                MainEntryPoint.download(fileDownloadURL, msg);
            } else {
                Window.alert(GuiMessageConst.MSG_29);
            }
        }
    });

}

From source file:org.opencms.gwt.client.ui.input.form.A_CmsFormFieldPanel.java

License:Open Source License

/**
 * Adds a new row with a given label and input widget to the form.<p>
 * /*  www.j  a  v  a2s.  c o m*/
 * @param labelText the label text for the form field
 * @param description the description of the form field 
 * @param widget the widget for the form field 
 * @param infoText the text to display on the info icon (may be null)
 *  
 * @return the newly added form row 
 */
protected CmsFormRow createRow(String labelText, String description, Widget widget, String infoText) {

    CmsFormRow row = new CmsFormRow();
    Label label = row.getLabel();
    label.setText(labelText);
    label.setTitle(description);
    row.setInfo(infoText);
    row.getWidgetContainer().add(widget);

    //getPanel(panelId).add(row);

    return row;
}

From source file:org.opendatakit.aggregate.client.PreferencesSubTab.java

License:Apache License

public PreferencesSubTab() {
    // vertical/*from   www  .j  av a  2  s.c o  m*/
    setStylePrimaryName(UIConsts.VERTICAL_FLOW_PANEL_STYLENAME);

    HTML labelVersion = new HTML(VERSION_LABEL);
    add(labelVersion);
    Label version = new Label();
    version.setStylePrimaryName(VERSION_STRING_STYLE);
    version.setText(UIConsts.VERSION_STRING);
    add(version);

    HTML labelCredentialsSection = new HTML(GOOGLE_API_CREDENTIALS_LABEL);
    add(labelCredentialsSection);

    HTML labelCredentialsInfo = new HTML(GOOGLE_API_CREDENTIALS_INFO);
    labelCredentialsInfo.setStylePrimaryName(INDENTED_STYLE);
    add(labelCredentialsInfo);

    HTML labelApiKeyHeading = new HTML(GOOGLE_API_KEY_LABEL);
    labelApiKeyHeading.setStylePrimaryName(INDENTED_STYLE);
    add(labelApiKeyHeading);

    simpleApiKey = new Label();
    simpleApiKey.setStylePrimaryName(INDENTED_ENTRY_STYLE);
    add(simpleApiKey);

    HTML labelApiKeyInfo = new HTML(GOOGLE_API_KEY_INFO);
    labelApiKeyInfo.setStylePrimaryName(INDENTED_STYLE);
    add(labelApiKeyInfo);

    HTML labelApiClientIdHeading = new HTML(GOOGLE_API_CLIENT_ID_LABEL);
    labelApiClientIdHeading.setStylePrimaryName(INDENTED_STYLE);
    add(labelApiClientIdHeading);

    googleApiClientId = new Label();
    googleApiClientId.setStylePrimaryName(INDENTED_ENTRY_STYLE);
    add(googleApiClientId);

    HTML labelApiClientIdInfo = new HTML(GOOGLE_API_CLIENT_ID_INFO);
    labelApiClientIdInfo.setStylePrimaryName(INDENTED_STYLE);
    add(labelApiClientIdInfo);

    ServletPopupButton newCredential = new ServletPopupButton(NEW_SERVICE_ACCOUNT_BUTTON_TEXT,
            NEW_SERVICE_ACCOUNT_TXT, UIConsts.SERVICE_ACCOUNT_PRIVATE_KEY_UPLOAD_ADDR, this,
            NEW_SERVICE_ACCOUNT_TOOLTIP_TXT, NEW_SERVICE_ACCOUNT_BALLOON_TXT);
    newCredential.setStylePrimaryName(INDENTED_STYLE);
    add(newCredential);

    HTML labelCredentialsSectionEnketo = new HTML(ENKETO_API_CREDENTIALS_LABEL);
    add(labelCredentialsSectionEnketo);

    HTML labelCredentialsInfoEnketo = new HTML(ENKETO_API_CREDENTIALS_INFO);
    labelCredentialsInfoEnketo.setStylePrimaryName(INDENTED_STYLE);
    add(labelCredentialsInfoEnketo);

    HTML labelApiKeyHeadingEnketo = new HTML(ENKETO_API_URL_LABEL);
    labelApiKeyHeadingEnketo.setStylePrimaryName(INDENTED_STYLE);
    add(labelApiKeyHeadingEnketo);

    enketoApiUrl = new Label();
    enketoApiUrl.setStylePrimaryName(INDENTED_ENTRY_STYLE);
    add(enketoApiUrl);

    HTML labelApiKeyInfoEnketo = new HTML(ENKETO_API_URL_INFO);
    labelApiKeyInfoEnketo.setStylePrimaryName(INDENTED_STYLE);
    add(labelApiKeyInfoEnketo);

    HTML labelApiClientIdHeadingEnketo = new HTML(ENKETO_API_TOKEN);
    labelApiClientIdHeadingEnketo.setStylePrimaryName(INDENTED_STYLE);
    add(labelApiClientIdHeadingEnketo);

    enketoApiToken = new Label();
    enketoApiToken.setStylePrimaryName(INDENTED_ENTRY_STYLE);
    add(enketoApiToken);

    HTML labelApiClientIdInfoEnketo = new HTML(ENKETO_API_TOKEN_INFO);
    labelApiClientIdInfoEnketo.setStylePrimaryName(INDENTED_STYLE);
    add(labelApiClientIdInfoEnketo);

    ServletPopupButton newEnketoCredential = new ServletPopupButton(NEW_ENKETO_SERVICE_ACCOUNT_BUTTON_TEXT,
            NEW_ENKETO_SERVICE_ACCOUNT_TXT, UIConsts.ENKETO_SERVICE_ACCOUNT_PRIVATE_KEY_UPLOAD_ADDR, this,
            NEW_ENKETO_SERVICE_ACCOUNT_TOOLTIP_TXT, NEW_ENKETO_SERVICE_ACCOUNT_BALLOON_TXT);
    newEnketoCredential.setStylePrimaryName(INDENTED_STYLE);
    add(newEnketoCredential);

    setCredentialValues();
    // add(new UpdateGMapsKeyButton(mapsApiKey));
    // add(new
    // UpdateGoogleClientCredentialsButton(googleApiClientId.getText()));

    HTML tablesFeatures = new HTML(ODK_TABLES_FEATURES_LABEL);
    add(tablesFeatures);

    odkTablesEnable = new EnableOdkTablesCheckbox(Preferences.getOdkTablesEnabled(), settingsChange);
    add(odkTablesEnable);

    HTML br = new HTML("<br>");
    add(br);

    HTML labelAppName = new HTML(ODK_TABLES_APP_NAME_LABEL);
    labelAppName.setStylePrimaryName(INDENTED_STYLE);
    add(labelAppName);

    appName = new Label();
    appName.setStylePrimaryName(INDENTED_ENTRY_STYLE);
    add(appName);

    HTML labelAppNameInfo = new HTML(ODK_TABLES_APP_NAME_INFO);
    labelAppNameInfo.setStylePrimaryName(INDENTED_STYLE);
    add(labelAppNameInfo);

    changeAppNameButton = new ChangeAppNameButton(settingsChange);
    changeAppNameButton.setStylePrimaryName(INDENTED_STYLE);
    add(changeAppNameButton);

    HTML features = new HTML(FEATURES_LABEL);
    add(features);

    disableFasterBackgroundActions = new DisableFasterBackgroundActionsCheckbox(
            Preferences.getFasterBackgroundActionsDisabled(), settingsChange);
    add(disableFasterBackgroundActions);

    HTML linebreak = new HTML("<br>");
    add(linebreak);

    skipMalformedSubmissions = new SkipMalformedSubmissionsCheckbox(Preferences.getSkipMalformedSubmissions(),
            settingsChange);
    add(skipMalformedSubmissions);
}

From source file:org.opendatakit.dwc.client.DemoWebClient.java

License:Apache License

/**
 * This is the entry point method.//  ww  w . j a va 2s  . c o  m
 */
public void onModuleLoad() {
    final Label errorLabel = new Label();

    // shared error area
    RootPanel.get("errorLabelContainer").add(errorLabel);

    {
        clientWebsiteName.setText("--clientWebsiteName--");
        RootPanel.get("clientWebsiteNameContainer").add(clientWebsiteName);
        clientWebsitePort.setText("--clientWebsitePort--");
        RootPanel.get("clientWebsitePortContainer").add(clientWebsitePort);
        clientWebsiteCodesvrPort.setText("--clientWebsiteCodesvrPort--");
        RootPanel.get("clientWebsiteCodesvrPortContainer").add(clientWebsiteCodesvrPort);
        clientWebsiteClientId.setText("--clientWebsiteClientId--");
        RootPanel.get("clientWebsiteClientIdContainer").add(clientWebsiteClientId);
        clientWebsiteClientSecret.setText("--clientWebsiteClientSecret--");
        RootPanel.get("clientWebsiteClientSecretContainer").add(clientWebsiteClientSecret);

        final Button fetchButton = new Button("Get Configuration");
        final Button setButton = new Button("Set Configuration");
        RootPanel.get("fetchConfigurationButtonContainer").add(fetchButton);
        RootPanel.get("setConfigurationButtonContainer").add(setButton);

        fetchButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                greetingService.getConfiguration(new AsyncCallback<Configuration>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        errorLabel.setText(caught.toString());
                    }

                    @Override
                    public void onSuccess(Configuration result) {
                        {
                            String value = result.get(Configuration.CLIENT_WEBSITE_HOSTNAME_KEY);
                            clientWebsiteName.setText((value == null) ? "" : value);
                        }
                        {
                            String value = result.get(Configuration.CLIENT_WEBSITE_PORT_KEY);
                            clientWebsitePort.setText((value == null) ? "" : value);
                        }
                        {
                            String value = result.get(Configuration.CLIENT_WEBSITE_CODESVR_PORT_KEY);
                            clientWebsiteCodesvrPort.setText((value == null) ? "" : value);
                        }
                        {
                            String value = result.get(Configuration.CLIENT_ID_KEY);
                            clientWebsiteClientId.setText((value == null) ? "" : value);
                        }
                        {
                            String value = result.get(Configuration.CLIENT_SECRET_KEY);
                            clientWebsiteClientSecret.setText((value == null) ? "" : value);
                        }

                    }
                });

            }
        });

        setButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                Configuration config = new Configuration();
                config.put(Configuration.CLIENT_WEBSITE_HOSTNAME_KEY, clientWebsiteName.getText());
                config.put(Configuration.CLIENT_WEBSITE_PORT_KEY, clientWebsitePort.getText());
                config.put(Configuration.CLIENT_WEBSITE_CODESVR_PORT_KEY, clientWebsiteCodesvrPort.getText());
                config.put(Configuration.CLIENT_ID_KEY, clientWebsiteClientId.getText());
                config.put(Configuration.CLIENT_SECRET_KEY, clientWebsiteClientSecret.getText());

                greetingService.setConfiguration(config, new AsyncCallback<Void>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        errorLabel.setText(caught.toString());
                    }

                    @Override
                    public void onSuccess(Void result) {
                    }
                });
            }
        });
    }

    {
        final Button sendButton = new Button("Send");
        final TextBox nameField = new TextBox();
        nameField.setText("GWT User");
        // We can add style names to widgets
        sendButton.addStyleName("sendButton");

        // Add the nameField and sendButton to the RootPanel
        // Use RootPanel.get() to get the entire body element
        RootPanel.get("nameFieldContainer").add(nameField);
        RootPanel.get("sendButtonContainer").add(sendButton);

        // Focus the cursor on the name field when the app loads
        nameField.setFocus(true);
        nameField.selectAll();

        defineDialogIneractions(nameField, sendButton, errorLabel, BUTTON_FIELD_ACTION.GREETING);
    }

    {
        final Button getUserEmailTokenButton = new Button("Get OAuth1 Token");

        RootPanel.get("userEmailTokenButton").add(getUserEmailTokenButton);

        // Add a handler to close the DialogBox
        getUserEmailTokenButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                greetingService.obtainToken("passthrough", new AsyncCallback<String>() {
                    @Override
                    public void onFailure(Throwable caught) {
                        errorLabel.setText(caught.toString());
                    }

                    @Override
                    public void onSuccess(String result) {
                        goTo(result);
                    }
                });
            }
        });
    }

    {
        final Button getUserEmailOauth2TokenButton = new Button("Get OAuth2 Code");

        RootPanel.get("userEmailOauth2TokenButton").add(getUserEmailOauth2TokenButton);

        // Add a handler to close the DialogBox
        getUserEmailOauth2TokenButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                greetingService.obtainOauth2Code("passthrough", new AsyncCallback<String>() {
                    @Override
                    public void onFailure(Throwable caught) {
                        errorLabel.setText(caught.toString());
                    }

                    @Override
                    public void onSuccess(String result) {
                        goTo(result);
                    }
                });
            }
        });
    }

    {
        final Button getOauth2UserEmailButtonContainer = new Button("Use Oauth2 to access Google info.email");
        final TextBox userEmailFieldContainer = new TextBox();
        userEmailFieldContainer.setText("--confirm retrieval of Oauth2 info.email -- unknown--");

        RootPanel.get("getOauth2UserEmailButtonContainer").add(getOauth2UserEmailButtonContainer);
        RootPanel.get("userEmailFieldContainer").add(userEmailFieldContainer);

        // Add a handler to close the DialogBox
        getOauth2UserEmailButtonContainer.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                greetingService.getOauth2UserEmail(new AsyncCallback<String>() {
                    @Override
                    public void onFailure(Throwable caught) {
                        errorLabel.setText(caught.toString());
                    }

                    @Override
                    public void onSuccess(String result) {
                        userEmailFieldContainer.setText(result);
                    }
                });
            }
        });
    }
    {
        final Button getUserEmailOauth2ServiceAccountTokenButton = new Button("Get OAuth2 ServiceAccount Code");

        RootPanel.get("userEmailOauth2ServiceAccountTokenButton")
                .add(getUserEmailOauth2ServiceAccountTokenButton);

        // Add a handler to close the DialogBox
        getUserEmailOauth2ServiceAccountTokenButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                greetingService.obtainOauth2ServiceAccountCode("passthrough", new AsyncCallback<String>() {
                    @Override
                    public void onFailure(Throwable caught) {
                        errorLabel.setText(caught.toString());
                    }

                    @Override
                    public void onSuccess(String result) {
                        goTo(result);
                    }
                });
            }
        });
    }

    {
        final Button getOauth2ServiceAccountUserEmailButtonContainer = new Button(
                "Use Oauth2 ServiceAccount to access Google info.email");
        final TextBox userEmailServiceAccountFieldContainer = new TextBox();
        userEmailServiceAccountFieldContainer
                .setText("--confirm retrieval of Oauth2 ServiceAccount info.email -- unknown--");

        RootPanel.get("getOauth2ServiceAccountUserEmailButtonContainer")
                .add(getOauth2ServiceAccountUserEmailButtonContainer);
        RootPanel.get("userEmailServiceAccountFieldContainer").add(userEmailServiceAccountFieldContainer);

        // Add a handler to close the DialogBox
        getOauth2ServiceAccountUserEmailButtonContainer.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                greetingService.getOauth2ServiceAccountUserEmail(new AsyncCallback<String>() {
                    @Override
                    public void onFailure(Throwable caught) {
                        errorLabel.setText(caught.toString());
                    }

                    @Override
                    public void onSuccess(String result) {
                        userEmailServiceAccountFieldContainer.setText(result);
                    }
                });
            }
        });
    }

    {
        final Button urlSendButton = new Button("Access site using OAuth1");
        final TextBox urlField = new TextBox();
        urlField.setText("URL to access");

        // We can add style names to widgets
        urlSendButton.addStyleName("sendButton");

        // Add the nameField and sendButton to the RootPanel
        // Use RootPanel.get() to get the entire body element
        RootPanel.get("urlOauth1FieldContainer").add(urlField);
        RootPanel.get("urlOauth1SendButtonContainer").add(urlSendButton);

        defineDialogIneractions(urlField, urlSendButton, errorLabel, BUTTON_FIELD_ACTION.OAUTH1_FETCH);
    }

    {
        final Button urlSendButton = new Button("Access site using Oauth2");
        final TextBox urlField = new TextBox();
        urlField.setText("URL to access");

        // We can add style names to widgets
        urlSendButton.addStyleName("sendButton");

        // Add the nameField and sendButton to the RootPanel
        // Use RootPanel.get() to get the entire body element
        RootPanel.get("urlOauth2FieldContainer").add(urlField);
        RootPanel.get("urlOauth2SendButtonContainer").add(urlSendButton);

        defineDialogIneractions(urlField, urlSendButton, errorLabel, BUTTON_FIELD_ACTION.OAUTH2_FETCH);
    }
}

From source file:org.opendatakit.dwc.client.DemoWebClient.java

License:Apache License

private void defineDialogIneractions(final TextBox nameField, final Button sendButton, final Label errorLabel,
        final BUTTON_FIELD_ACTION api) {

    // Create the popup dialog box
    final DialogBox dialogBox = new DialogBox();
    dialogBox.setText("Remote Procedure Call");
    dialogBox.setAnimationEnabled(true);
    final Button closeButton = new Button("Close");
    // We can set the id of a widget by accessing its Element
    closeButton.getElement().setId("closeButton");
    final Label textToServerLabel = new Label();
    final HTML serverResponseLabel = new HTML();
    VerticalPanel dialogVPanel = new VerticalPanel();
    dialogVPanel.addStyleName("dialogVPanel");
    dialogVPanel.add(new HTML("<b>Sending name to the server:</b>"));
    dialogVPanel.add(textToServerLabel);
    dialogVPanel.add(new HTML("<br><b>Server replies:</b>"));
    dialogVPanel.add(serverResponseLabel);
    dialogVPanel.setWidth(Integer.toString(Window.getClientWidth() - 10) + "px");
    dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
    dialogVPanel.add(closeButton);//from  ww w.j  a  v  a  2s.  co  m
    dialogBox.setWidget(dialogVPanel);

    // Add a handler to close the DialogBox
    closeButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            dialogBox.hide();
            sendButton.setEnabled(true);
            sendButton.setFocus(true);
        }
    });

    // Create a handler for the sendButton and nameField
    class MyHandler implements ClickHandler, KeyUpHandler {
        /**
         * Fired when the user clicks on the sendButton.
         */
        public void onClick(ClickEvent event) {
            sendNameToServer();
        }

        /**
         * Fired when the user types in the nameField.
         */
        public void onKeyUp(KeyUpEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                sendNameToServer();
            }
        }

        /**
         * Send the name from the nameField to the server and wait for a response.
         */
        private void sendNameToServer() {
            // First, we validate the input.
            errorLabel.setText("");
            String textToServer = nameField.getText();
            if (!FieldVerifier.isValidName(textToServer)) {
                errorLabel.setText("Please enter at least four characters");
                return;
            }

            // Then, we send the input to the server.
            sendButton.setEnabled(false);
            textToServerLabel.setText(textToServer);
            serverResponseLabel.setText("");
            AsyncCallback<String> callback = new AsyncCallback<String>() {
                public void onFailure(Throwable caught) {
                    // Show the RPC error message to the user
                    dialogBox.setText("Remote Procedure Call - Failure");
                    serverResponseLabel.addStyleName("serverResponseLabelError");
                    serverResponseLabel
                            .setHTML("<verbatim>" + SafeHtmlUtils.htmlEscape(SERVER_ERROR) + "</verbatim>");
                    dialogBox.getWidget().setWidth("90%");
                    dialogBox.center();
                    closeButton.setFocus(true);
                }

                public void onSuccess(String result) {
                    dialogBox.setText("Remote Procedure Call");
                    serverResponseLabel.removeStyleName("serverResponseLabelError");
                    serverResponseLabel
                            .setHTML("<verbatim>" + SafeHtmlUtils.htmlEscape(result) + "</verbatim>");
                    dialogBox.getWidget().setWidth("90%");
                    dialogBox.center();
                    closeButton.setFocus(true);
                }
            };

            if (api == BUTTON_FIELD_ACTION.OAUTH2_FETCH) {
                greetingService.obtainOauth2Data(textToServer, callback);
            } else if (api == BUTTON_FIELD_ACTION.OAUTH1_FETCH) {
                greetingService.obtainOauth1Data(textToServer, callback);
            } else {
                greetingService.greetServer(textToServer, callback);
            }
        }
    }

    // Add a handler to send the name to the server
    MyHandler handler = new MyHandler();
    sendButton.addClickHandler(handler);
    nameField.addKeyUpHandler(handler);
}

From source file:org.openelis.gwt.widget.CalendarWidget.java

License:Open Source License

public void setHandlers() {
    if (def.getName().equals("Calendar")) {
        ((Label) def.getWidget("MonthDisplay")).setText(form.monthDisplay);
        boolean displayMonth = false;
        Date currDate = new Date();
        if (form.month == currDate.getMonth() && (form.year - 1900) == currDate.getYear())
            displayMonth = true;/*w  w w.j  a  v a2 s .  c  o m*/
        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 7; j++) {
                Label date = (Label) def.getWidget("cell:" + i + ":" + j);
                date.setStyleName("DateText");
                if (i == 0 && form.cells[i][j] > 7) {
                    date.addStyleName("offMonth");
                    ((IconContainer) date.getParent()).enable(false);
                } else if (i >= 4 && form.cells[i][j] < 14) {
                    date.addStyleName("offMonth");
                    ((IconContainer) date.getParent()).enable(false);
                } else {
                    date.removeStyleName("offMonth");
                    ((IconContainer) date.getParent()).enable(true);
                    if (displayMonth && form.cells[i][j] == form.date.get(Datetime.DAY))
                        date.addStyleName("Current");
                    else
                        date.removeStyleName("Current");
                }
                date.setText(String.valueOf(form.cells[i][j]));
                if (prevMonth == null)
                    date.addClickHandler(this);
            }
        }
        if (prevMonth == null) {
            prevMonth = (org.openelis.gwt.widget.AppButton) def.getWidget("prevMonth");
            prevMonth.addClickHandler(this);
            prevMonth.enable(true);
        }
        if (nextMonth == null) {
            nextMonth = (AppButton) def.getWidget("nextMonth");
            nextMonth.addClickHandler(this);
            nextMonth.enable(true);
        }
        if (monthSelect == null) {
            monthSelect = (AppButton) def.getWidget("monthSelect");
            monthSelect.addClickHandler(this);
            monthSelect.enable(true);
        }
        if (today == null) {
            today = (AppButton) def.getWidget("today");
            today.addClickHandler(this);
            today.enable(true);
        }
        if (form.date.getEndCode() > Datetime.DAY) {
            if (time == null) {
                time = (TextBox<Datetime>) def.getWidget("time");
            }
            time.setFieldValue(Datetime.getInstance(Datetime.HOUR, Datetime.MINUTE, form.date.getDate()));
            def.getWidget("TimeBar").setVisible(true);
        } else
            def.getWidget("TimeBar").setVisible(false);
    } else {
        if (prevDecade == null) {
            prevDecade = (AppButton) def.getWidget("prevDecade");
            prevDecade.addClickHandler(this);
            prevDecade.enable(true);
        }
        if (nextDecade == null) {
            nextDecade = (AppButton) def.getWidget("nextDecade");
            nextDecade.addClickHandler(this);
            nextDecade.enable(true);
        }
        if (ok == null) {
            ok = (AppButton) def.getWidget("ok");
            ok.addClickHandler(this);
            ok.enable(true);
        }
        if (cancel == null) {
            cancel = (AppButton) def.getWidget("cancel");
            cancel.addClickHandler(this);
            cancel.enable(true);
        }
        if (months == null) {
            months = new ArrayList<AppButton>();
            for (int i = 0; i < 12; i++) {
                months.add((AppButton) def.getWidget("month" + i));
                ((AppButton) def.getWidget("month" + i)).addClickHandler(this);
            }
        }
        if (years == null) {
            years = new ArrayList<AppButton>();
            for (int i = 0; i < 10; i++) {
                years.add((AppButton) def.getWidget("year" + i));
                years.get(i).addClickHandler(this);

            }
        }
        int yr = form.year / 10 * 10;
        for (int i = 0; i < 10; i++) {
            Label year = (Label) def.getWidget("year" + i + "Text");
            year.setText(String.valueOf(yr + i));
            if (form.year == yr + i) {
                ((Widget) def.getWidget("year" + i)).addStyleName("Current");
            }
        }
        ((Widget) def.getWidget("month" + form.month)).addStyleName("Current");

    }
}

From source file:org.openelis.gwt.widget.table.TableColumn.java

License:Open Source License

public Widget getDisplayWidget(TableDataRow row) {
    TableDataCell cell = new TableDataCell(null);
    if (columnIndex < row.cells.size())
        cell = row.cells.get(columnIndex);
    Widget wid = null;/*from   w ww  .  jav  a 2  s . c o  m*/
    Object val = null;
    if (colWidget instanceof CheckBox) {
        wid = new CheckBoxContainer();
        IconContainer icon = new IconContainer();
        if (CheckBox.CHECKED.equals(cell.getValue()))
            icon.setStyleName(CheckBox.CHECKED_STYLE);
        else if (controller.queryMode && cell.getValue() == null)
            icon.setStyleName(CheckBox.UNKNOWN_STYLE);
        else
            icon.setStyleName(CheckBox.UNCHECKED_STYLE);
        setAlign(HasHorizontalAlignment.ALIGN_CENTER);
        ((AbsolutePanel) wid).add(icon);
        DOM.setStyleAttribute(wid.getElement(), "align", "center");
        wid.setWidth((currentWidth) + "px");
    } else if (colWidget instanceof PercentBar) {
        PercentBar newBar = new PercentBar();
        newBar.setColors(((PercentBar) colWidget).getColors());
        newBar.setWidth(currentWidth + "px");
        newBar.setBarWidth(((PercentBar) colWidget).getBarWidth());
        newBar.setPercent((Double) cell.getValue());
        return newBar;
    } else if (colWidget instanceof TableImage) {
        if (controller.queryMode)
            return new Label("");
        TableImage newImg = new TableImage();
        newImg.setStyleName((String) cell.getValue());
        setAlign(HasHorizontalAlignment.ALIGN_CENTER);
        return newImg;
    } else {
        if (colWidget instanceof AutoComplete) {
            if (controller.queryMode) {
                val = cell.getValue();
                if (val == null)
                    val = "";
            } else {
                TableDataRow vrow = (TableDataRow) cell.getValue();
                if (vrow != null)
                    ((AutoComplete) colWidget).setSelection(vrow);
                else
                    ((AutoComplete) colWidget).setSelection(null, "");
                val = ((AutoComplete) colWidget).getTextBoxDisplay();
            }
        } else if (colWidget instanceof Dropdown) {
            if (cell.getValue() instanceof ArrayList)
                ((Dropdown) colWidget).setSelectionKeys((ArrayList<Object>) cell.getValue());
            else
                ((Dropdown) colWidget).setSelection(cell.getValue());
            val = ((Dropdown) colWidget).getTextBoxDisplay();
        } else if (colWidget instanceof CalendarLookUp && ((CalendarLookUp) colWidget).getField().queryMode) {
            val = ((HasField) colWidget).getField().queryString;
        } else {
            if (cell.getValue() instanceof ArrayList) {
                if (((ArrayList) cell.getValue()).size() > 0)
                    ((HasField) colWidget).setFieldValue(((ArrayList) cell.getValue()).get(0).toString());
                else
                    ((HasField) colWidget).setFieldValue("");
            } else
                ((HasField) colWidget).setFieldValue(cell.getValue());
        }
        if (val == null) {
            if (((HasField) colWidget).getField().queryMode)
                val = ((HasField) colWidget).getField().queryString;
            else
                val = ((HasField) colWidget).getFieldValue();
        }
        Label label = new Label("");
        label.setStyleName("ScreenLabel");
        if (colWidget instanceof Label)
            label.setStyleName(colWidget.getStyleName());
        if (val != null) {
            if (colWidget instanceof CalendarLookUp) {
                if (((HasField) colWidget).getField().queryMode)
                    label.setText(((HasField) colWidget).getField().queryString);
                else
                    label.setText((((CalendarLookUp) colWidget).getField().format()));
            } else if (colWidget instanceof AutoComplete && controller.queryMode) {
                label.setText((String) val);
            } else if (colWidget instanceof DropdownWidget) {
                label.setText(((DropdownWidget) colWidget).getTextBoxDisplay());
            } else if (colWidget instanceof TextBoxBase) {
                if (((HasField) colWidget).getField().queryMode)
                    label.setText(((HasField) colWidget).getField().queryString);
                else
                    label.setText(((TextBoxBase) colWidget).getText());
            } else if (colWidget instanceof Label)
                label.setText(((Label) colWidget).getText());
        }
        label.setWordWrap(false);
        wid = label;
        wid.setWidth((currentWidth) + "px");
    }
    setExceptions(wid, cell.exceptions);
    wid.addStyleName("TableWidget");
    return wid;
}