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:com.google.gwt.sample.showcase.client.content.widgets.CwDatePicker.java

License:Apache License

/**
 * Initialize this example./*from www  .  j  a  v  a 2s.  co  m*/
 */
@SuppressWarnings("deprecation")
@ShowcaseSource
@Override
public Widget onInitialize() {
    // Create a basic date picker
    DatePicker datePicker = new DatePicker();
    final Label text = new Label();

    // Set the value in the text box when the user selects a date
    datePicker.addValueChangeHandler(new ValueChangeHandler<Date>() {
        public void onValueChange(ValueChangeEvent<Date> event) {
            Date date = event.getValue();
            String dateString = DateTimeFormat.getMediumDateFormat().format(date);
            text.setText(dateString);
        }
    });

    // Set the default value
    datePicker.setValue(new Date(), true);

    // Create a DateBox
    DateTimeFormat dateFormat = DateTimeFormat.getLongDateFormat();
    DateBox dateBox = new DateBox();
    dateBox.setFormat(new DateBox.DefaultFormat(dateFormat));

    // Combine the widgets into a panel and return them
    VerticalPanel vPanel = new VerticalPanel();
    vPanel.add(new HTML(constants.cwDatePickerLabel()));
    vPanel.add(text);
    vPanel.add(datePicker);
    vPanel.add(new HTML(constants.cwDatePickerBoxLabel()));
    vPanel.add(dateBox);
    return vPanel;
}

From source file:com.google.gwt.sample.simplexml.client.SimpleXML.java

License:Apache License

/**
 * Creates the xml representation of xmlText. xmlText is assumed to have been
 * validated for structure on the server.
 * /*  w w w. ja  v  a  2  s. co  m*/
 * @param xmlText xml text
 * @param xmlParsed panel to display customer record
 */
private void customerPane(String xmlText, FlowPanel xmlParsed) {
    Document customerDom = XMLParser.parse(xmlText);
    Element customerElement = customerDom.getDocumentElement();
    // Must do this if you ever use a raw node list that you expect to be
    // all elements.
    XMLParser.removeWhitespace(customerElement);

    // Customer Name
    String nameValue = getElementTextValue(customerElement, "name");
    String title = "<h1>" + nameValue + "</h1>";
    HTML titleHTML = new HTML(title);
    xmlParsed.add(titleHTML);

    // Customer Notes
    String notesValue = getElementTextValue(customerElement, "notes");
    Label notesText = new Label();
    notesText.setStyleName(NOTES_STYLE);
    notesText.setText(notesValue);
    xmlParsed.add(notesText);

    // Pending orders UI setup
    FlexTable pendingTable = createOrderTable(xmlParsed, "Pending Orders");
    FlexTable completedTable = createOrderTable(xmlParsed, "Completed");
    completedTable.setText(0, 7, "Shipped by");

    // Fill Orders Table
    NodeList orders = customerElement.getElementsByTagName("order");
    int pendingRowPos = 0;
    int completedRowPos = 0;
    for (int i = 0; i < orders.getLength(); i++) {
        Element order = (Element) orders.item(i);
        HTMLTable table;
        int rowPos;
        if (order.getAttribute("status").equals("pending")) {
            table = pendingTable;
            rowPos = ++pendingRowPos;
        } else {
            table = completedTable;
            rowPos = ++completedRowPos;
        }
        int columnPos = 0;
        fillInOrderTableRow(customerElement, order, table, rowPos, columnPos);
    }
}

From source file:com.google.gwt.sample.starter.client.Starter.java

/**
 * This is the entry point method.//from ww  w  .j a v a2  s.c o  m
 */
public void onModuleLoad() {
    final Button sendButton = new Button("Send");
    final TextBox nameField = new TextBox();
    nameField.setText("GWT User");
    final Label errorLabel = new Label();

    // 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);
    RootPanel.get("errorLabelContainer").add(errorLabel);

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

    // 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.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
    dialogVPanel.add(closeButton);
    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("");
            greetingService.greetServer(textToServer, 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(SERVER_ERROR);
                    dialogBox.center();
                    closeButton.setFocus(true);
                }

                public void onSuccess(String result) {
                    dialogBox.setText("Remote Procedure Call");
                    serverResponseLabel.removeStyleName("serverResponseLabelError");
                    serverResponseLabel.setHTML(result);
                    dialogBox.center();
                    closeButton.setFocus(true);
                }
            });
        }
    }

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

From source file:com.google.gwt.sample.stockwatch.client.StockWatcher.java

private void updateTable(StockPrice price) {
    //Make sure the stock is still in the stock table.
    if (!stocks.contains(price.getSymbol())) {
        return;/*from  w w w . j  ava  2 s . com*/
    }

    int row = stocks.indexOf(price.getSymbol()) + 1;

    //Format the data in the Price and Change fields
    String priceText = NumberFormat.getFormat("#,##0.00").format(price.getPrice());
    NumberFormat changeFormat = NumberFormat.getFormat("+#,##0.00;-#,##0.00");
    String changeText = changeFormat.format(price.getChange());
    String changePercentText = changeFormat.format(price.getChangePercent());

    //Populate the Price and the Change fields with new data.
    stocksFlexTable.setText(row, 1, priceText);

    Label changeWidget = (Label) stocksFlexTable.getWidget(row, 2);
    changeWidget.setText(changeText + "(" + changePercentText + "%)");

    // Change the color of text in the Change field based on its value
    String changeStyleName = "noChange";
    if (price.getChangePercent() < -0.1f) {
        changeStyleName = "negativeChange";
    } else if (price.getChangePercent() > 0.1f) {
        changeStyleName = "positiveChange";
    }

    changeWidget.setStyleName(changeStyleName);
}

From source file:com.google.gwt.sample.stockwatcher.client.CopyOfStockWatcher.java

private void updateTable(StockPrice price) {
    // Make sure the stock is still in the stock table.
    if (!stocks.contains(price.getSymbol())) {
        return;//w  ww. j  a va 2s  .c  o m
    }

    int row = stocks.indexOf(price.getSymbol()) + 1;

    // Format the data in the Price and Change fields.
    String priceText = NumberFormat.getFormat("#,##0.00").format(price.getPrice());
    NumberFormat changeFormat = NumberFormat.getFormat("+#,##0.00;-#,##0.00");
    String changeText = changeFormat.format(price.getChange());
    String changePercentText = changeFormat.format(price.getChangePercent());

    // Populate the Price and Change fields with new data.
    // Populate the Price and Change fields with new data.
    stocksFlexTable.setText(row, 1, priceText);
    Label changeWidget = (Label) stocksFlexTable.getWidget(row, 2);
    changeWidget.setText(changeText + " (" + changePercentText + "%)");

    // Change the color of text in the Change field based on its value.
    String changeStyleName = "noChange";
    if (price.getChangePercent() < -0.1f) {
        changeStyleName = "negativeChange";
    } else if (price.getChangePercent() > 0.1f) {
        changeStyleName = "positiveChange";
    }

    changeWidget.setStyleName(changeStyleName);

}

From source file:com.google.gwt.sample.stockwatcher.client.FlexTableRowDropController.java

@Override
public void onDrop(DragContext context) {
    super.onDrop(context);
    AbsolutePanel target = (AbsolutePanel) getDropTarget();

    int factor = 6200000; // Thats the biggest amount / 100
    int table_size = 490;

    // Aqui se define lo que quieres que haga la el target widget cuando le
    // sueltes lo que sea
    target.setTitle(parent.currentCity.getCity() + " " + parent.currentCity.getAmmount());
    target.add(new Label(parent.currentCity.getCity() + parent.currentCity.getAmmount()));
    Label temp = new Label();
    temp.setWidth(String.valueOf((parent.currentCity.getAmmount() * table_size) / factor) + "px");
    temp.setStyleName("graphic_bars");
    temp.setText(" .");
    target.add(temp);/*w  w w.  ja  v a  2 s  . co  m*/

}

From source file:com.google.gwt.sample.stockwatcher.client.Footer.java

@SuppressWarnings("unused")
private void addLinkSeparator(HorizontalPanel _anchorPanel) {
    Label linkSeparator = new Label();

    linkSeparator.setText("|");
    linkSeparator.addStyleName("footer-link-separator");

    _anchorPanel.add(linkSeparator);//  w ww. ja  va 2 s. c o  m
    _anchorPanel.setCellVerticalAlignment(linkSeparator, HasVerticalAlignment.ALIGN_MIDDLE);
}

From source file:com.google.gwt.sample.stockwatcher.client.Gwt_Project_StockWatcher.java

private void updateTable(StockPrice price) {
    //Make sure the stock is still in the stock table.
    if (!stocks.contains(price.getSymbol())) {
        return;/*www.j a va 2  s .c om*/
    }

    int row = stocks.indexOf(price.getSymbol()) + 1;

    // Format the data in the Price and Change fields.
    String priceText = NumberFormat.getFormat("#,##0.00").format(price.getPrice());
    NumberFormat changeFormat = NumberFormat.getFormat("+#,##0.00;-#,##0.00");
    String changeText = changeFormat.format(price.getChange());
    String changePercentText = changeFormat.format(price.getChangePercent());

    // Populate the Price and Change fields with new data.
    stocksFlexTable.setText(row, 1, priceText);
    Label changeWidget = (Label) stocksFlexTable.getWidget(row, 2);
    changeWidget.setText(changeText + " (" + changePercentText + "%)");

    // Change the color of text in the Change field based on its value.
    String changeStyleName = "noChange";
    if (price.getChangePercent() < -0.1f) {
        changeStyleName = "negativeChange";
    } else if (price.getChangePercent() > 0.1f) {
        changeStyleName = "positiveChange";
    }

    changeWidget.setStyleName(changeStyleName);

}

From source file:com.google.gwt.sample.stockwatcher.client.OntologyBasedContentManagement.java

private void populateSuggestedTriples(List<String[]> action) {
    logger.log(Level.SEVERE, "Size of sugT" + action.size());
    Iterator<String[]> it = action.iterator();
    while (it.hasNext()) {
        String temp[] = new String[3];
        temp = it.next();/*from   ww  w.  j a v  a  2 s.co m*/
        logger.log(Level.SEVERE, temp[0] + " " + temp[1] + " " + temp[2]);

        ft.setText(0, 0, "Subject");
        ft.setText(0, 1, "Predicate");
        ft.setText(0, 2, "Object");
        ft.setText(0, 3, "Add");
        int rcount = ft.getRowCount();
        ft.setText(rcount, 0, temp[0]);
        ft.setText(rcount, 1, temp[1]);
        ft.setText(rcount, 2, temp[2]);

        cb = new CheckBox("Add");
        // cb.setChecked(true);
        cb.setValue(false);
        ft.setWidget(rcount, 3, cb);

        cb.addClickHandler(new ClickHandler() {

            @SuppressWarnings("deprecation")
            @Override
            public void onClick(ClickEvent event) {
                boolean checked = ((CheckBox) event.getSource()).isChecked();
            }

        });
        ft.addClickHandler(new ClickHandler() {
            int count = 0;

            @Override
            public void onClick(ClickEvent event) {
                // int count = 0;
                if (count < 1) {
                    com.google.gwt.user.client.ui.HTMLTable.Cell cell = ft.getCellForEvent(event);
                    int cellIndex = cell.getCellIndex();
                    int rowIndex = cell.getRowIndex();
                    logger.log(Level.SEVERE, "cell:" + cellIndex + "~ Row:" + (rowIndex));
                    if (cellIndex == 3 && cb.getValue()) {
                    }
                }
                count++;
            }

        });
    }
    Label lb = new Label();
    popupContents.add(popupHolder);
    popupContents.add(ft);
    lb.setText("* defines a Literal value");
    popupContents.add(lb);
    popup.center();

}

From source file:com.google.gwt.sample.stockwatcher.client.StockWatch.java

/**
 * Update a single row in the stock table.
 *
 * @param price//w  ww .  j  a v a2s . co  m
 *            Stock data for a single row.
 */
private void updateTable(StockPrice price) {
    // Make sure the stock is still in the stock table.
    if (!stocks.contains(price.getSymbol())) {
        return;
    }

    int row = stocks.indexOf(price.getSymbol()) + 1;

    // Format the data in the Price and Change fields.
    String priceText = NumberFormat.getFormat("#,##0.00").format(price.getPrice());
    NumberFormat changeFormat = NumberFormat.getFormat("+#,##0.00;-#,##0.00");
    String changeText = changeFormat.format(price.getChange());
    String changePercentText = changeFormat.format(price.getChangePercent());

    // Populate the Price and Change fields with new data.
    stockTable.setText(row, 1, priceText);
    Label changeWidget = (Label) stockTable.getWidget(row, 2);
    changeWidget.setText(changeText + " (" + changePercentText + "%)");

    // Change the color of text in the Change field based on its value.
    String changeStyleName = "noChange";
    if (price.getChangePercent() < -0.1f) {
        changeStyleName = "negativeChange";
    } else if (price.getChangePercent() > 0.1f) {
        changeStyleName = "positiveChange";
    }

    changeWidget.setStyleName(changeStyleName);
}