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.appinventor.client.explorer.youngandroid.GalleryPage.java

License:Open Source License

/**
 * Helper method called by constructor to initialize the feature section
 * @param container   The container that feature label reside
 *///from  w ww  . j  a va2  s  .  c o m
private void initFeatureSection(Panel container) { //TODO: Update the location of this button
    final User currentUser = Ode.getInstance().getUser();
    if (currentUser.getType() != User.MODERATOR) { //not admin
        return;
    }

    final Label featurePrompt = new Label(MESSAGES.galleryEmptyText());
    featurePrompt.addStyleName("primary-link");
    container.add(featurePrompt);

    final OdeAsyncCallback<Boolean> isFeaturedCallback = new OdeAsyncCallback<Boolean>(
            // failure message
            MESSAGES.galleryError()) {
        @Override
        public void onSuccess(Boolean bool) {
            if (bool) { // If the app is already featured before, the prompt should show as unfeatured
                featurePrompt.setText(MESSAGES.galleryUnfeaturedText());
            } else { // otherwise show as featured
                featurePrompt.setText(MESSAGES.galleryFeaturedText());
            }
        }
    };
    Ode.getInstance().getGalleryService().isFeatured(app.getGalleryAppId(), isFeaturedCallback); // This happens when user click on like, we need to check if it's already liked

    featurePrompt.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            final OdeAsyncCallback<Boolean> markFeaturedCallback = new OdeAsyncCallback<Boolean>(
                    // failure message
                    MESSAGES.galleryError()) {
                @Override
                public void onSuccess(Boolean bool) {
                    if (bool) { // If the app is already featured, the prompt should show as unfeatured
                        featurePrompt.setText(MESSAGES.galleryUnfeaturedText());
                    } else { // otherwise show as featured
                        featurePrompt.setText(MESSAGES.galleryFeaturedText());
                    }
                    //update gallery list
                    gallery.appWasChanged();
                }
            };
            Ode.getInstance().getGalleryService().markAppAsFeatured(app.getGalleryAppId(),
                    markFeaturedCallback);
        }
    });
}

From source file:com.google.appinventor.client.explorer.youngandroid.GalleryPage.java

License:Open Source License

/**
 * Helper method called by constructor to initialize the tutorial section
 * @param container   The container that feature label reside
 *//*  w w  w.  ja v a  2 s  .  co m*/
private void initTutorialSection(Panel container) { //TODO: Update the location of this button
    final User currentUser = Ode.getInstance().getUser();
    if (currentUser.getType() != User.MODERATOR) { //not admin
        return;
    }

    final Label tutorialPrompt = new Label(MESSAGES.galleryEmptyText());
    tutorialPrompt.addStyleName("primary-link");
    container.add(tutorialPrompt);

    final OdeAsyncCallback<Boolean> isTutorialCallback = new OdeAsyncCallback<Boolean>(
            // failure message
            MESSAGES.galleryError()) {
        @Override
        public void onSuccess(Boolean bool) {
            if (bool) { // If the app is already featured before, the prompt should show as unfeatured
                tutorialPrompt.setText(MESSAGES.galleryUntutorialText());
            } else { // otherwise show as featured
                tutorialPrompt.setText(MESSAGES.galleryTutorialText());
            }
        }
    };
    Ode.getInstance().getGalleryService().isTutorial(app.getGalleryAppId(), isTutorialCallback); // This happens when user click on like, we need to check if it's already liked

    tutorialPrompt.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            final OdeAsyncCallback<Boolean> markTutorialCallback = new OdeAsyncCallback<Boolean>(
                    // failure message
                    MESSAGES.galleryError()) {
                @Override
                public void onSuccess(Boolean bool) {
                    if (bool) { // If the app is already featured, the prompt should show as unfeatured
                        tutorialPrompt.setText(MESSAGES.galleryUntutorialText());
                    } else { // otherwise show as featured
                        tutorialPrompt.setText(MESSAGES.galleryTutorialText());
                    }
                    //update gallery list
                    gallery.appWasChanged();
                }
            };
            Ode.getInstance().getGalleryService().markAppAsTutorial(app.getGalleryAppId(),
                    markTutorialCallback);
        }
    });
}

From source file:com.google.appinventor.client.explorer.youngandroid.ReportList.java

License:Open Source License

/**
 * Helper method of creating a sending email popup
 * @param report/*from w ww. j av  a  2 s  .  c  om*/
 */
private void sendEmailPopup(final GalleryAppReport report) {
    // Create a PopUpPanel with a button to close it
    final PopupPanel popup = new PopupPanel(true);
    popup.setStyleName("ode-InboxContainer");
    final FlowPanel content = new FlowPanel();
    content.addStyleName("ode-Inbox");
    Label title = new Label(MESSAGES.emailSendTitle());
    title.addStyleName("InboxTitle");
    content.add(title);

    Button closeButton = new Button(MESSAGES.symbolX());
    closeButton.addStyleName("CloseButton");
    closeButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            popup.hide();
        }
    });
    content.add(closeButton);

    final FlowPanel emailPanel = new FlowPanel();
    emailPanel.addStyleName("app-actions");
    final Label sentFrom = new Label(MESSAGES.emailSentFrom());
    final Label sentTo = new Label(MESSAGES.emailSentTo() + report.getOffender().getUserName());
    final TextArea emailBodyText = new TextArea();
    emailBodyText.addStyleName("action-textarea");
    final Button sendEmail = new Button(MESSAGES.buttonSendEmail());
    sendEmail.addStyleName("action-button");

    // Account Drop Down Button
    List<DropDownItem> templateItems = Lists.newArrayList();
    // Email Template 1
    templateItems.add(
            new DropDownItem("template1", MESSAGES.inappropriateAppContentRemoveTitle(), new TemplateAction(
                    emailBodyText, EMAIL_INAPPROPRIATE_APP_CONTENT_REMOVE, report.getApp().getTitle())));
    templateItems.add(new DropDownItem("template2", MESSAGES.inappropriateAppContentTitle(),
            new TemplateAction(emailBodyText, EMAIL_INAPPROPRIATE_APP_CONTENT, report.getApp().getTitle())));
    templateItems.add(new DropDownItem("template3", MESSAGES.inappropriateUserProfileContentTitle(),
            new TemplateAction(emailBodyText, EMAIL_INAPPROPRIATE_USER_PROFILE_CONTENT, null)));

    templateButton = new DropDownButton("template", MESSAGES.labelChooseTemplate(), templateItems, true);
    templateButton.setStyleName("ode-TopPanelButton");

    new TemplateAction(emailBodyText, EMAIL_INAPPROPRIATE_APP_CONTENT, report.getApp().getTitle()).execute();

    emailPanel.add(templateButton);
    emailPanel.add(sentFrom);
    emailPanel.add(sentTo);
    emailPanel.add(emailBodyText);
    emailPanel.add(sendEmail);

    content.add(emailPanel);
    popup.setWidget(content);
    // Center and show the popup
    popup.center();

    final User currentUser = Ode.getInstance().getUser();
    sentFrom.setText(MESSAGES.emailSentFrom() + currentUser.getUserName());
    sendEmail.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            final OdeAsyncCallback<Long> emailCallBack = new OdeAsyncCallback<Long>(MESSAGES.galleryError()) {
                @Override
                public void onSuccess(final Long emailId) {
                    if (emailId == Email.NOTRECORDED) {
                        Window.alert(MESSAGES.moderationErrorFailToSendEmail());
                        popup.hide();
                    } else {
                        popup.hide();
                        storeModerationAction(report.getReportId(), report.getApp().getGalleryAppId(), emailId,
                                GalleryModerationAction.SENDEMAIL, getEmailPreview(emailBodyText.getText()));
                    }
                }
            };
            String emailBody = emailBodyText.getText() + MESSAGES.galleryVisitGalleryAppLinkLabel(
                    Window.Location.getHost(), report.getApp().getGalleryAppId());
            Ode.getInstance().getGalleryService().sendEmail(currentUser.getUserId(),
                    report.getOffender().getUserId(), report.getOffender().getUserEmail(),
                    MESSAGES.moderationSendEmailTitle(), emailBody, emailCallBack);
        }
    });
}

From source file:com.google.appinventor.client.explorer.youngandroid.ReportList.java

License:Open Source License

/**
 * Helper method for deactivating App Popup
 * @param report GalleryAppReport Gallery App Report
 * @param rw ReportWidgets Report Widgets
 *//*from   w  w  w  .  j a  va 2s  .  c o  m*/
private void deactivateAppPopup(final GalleryAppReport report, final ReportWidgets rw) {
    // Create a PopUpPanel with a button to close it
    final PopupPanel popup = new PopupPanel(true);
    popup.setStyleName("ode-InboxContainer");
    final FlowPanel content = new FlowPanel();
    content.addStyleName("ode-Inbox");
    Label title = new Label(MESSAGES.emailSendTitle());
    title.addStyleName("InboxTitle");
    content.add(title);

    Button closeButton = new Button(MESSAGES.symbolX());
    closeButton.addStyleName("CloseButton");
    closeButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            popup.hide();
        }
    });
    content.add(closeButton);

    final FlowPanel emailPanel = new FlowPanel();
    emailPanel.addStyleName("app-actions");
    final Label sentFrom = new Label(MESSAGES.emailSentFrom());
    final Label sentTo = new Label(MESSAGES.emailSentTo() + report.getOffender().getUserName());
    final TextArea emailBodyText = new TextArea();
    emailBodyText.addStyleName("action-textarea");
    final Button sendEmailAndDeactivateApp = new Button(MESSAGES.labelDeactivateAppAndSendEmail());
    sendEmailAndDeactivateApp.addStyleName("action-button");
    final Button cancel = new Button(MESSAGES.labelCancel());
    cancel.addStyleName("action-button");

    // Account Drop Down Button
    List<DropDownItem> templateItems = Lists.newArrayList();
    // Email Template 1
    templateItems.add(
            new DropDownItem("template1", MESSAGES.inappropriateAppContentRemoveTitle(), new TemplateAction(
                    emailBodyText, EMAIL_INAPPROPRIATE_APP_CONTENT_REMOVE, report.getApp().getTitle())));
    templateItems.add(new DropDownItem("template2", MESSAGES.inappropriateAppContentTitle(),
            new TemplateAction(emailBodyText, EMAIL_INAPPROPRIATE_APP_CONTENT, report.getApp().getTitle())));
    templateItems.add(new DropDownItem("template3", MESSAGES.inappropriateUserProfileContentTitle(),
            new TemplateAction(emailBodyText, EMAIL_INAPPROPRIATE_USER_PROFILE_CONTENT, null)));
    templateButton = new DropDownButton("template", MESSAGES.labelChooseTemplate(), templateItems, true);
    templateButton.setStyleName("ode-TopPanelButton");

    // automatically choose first template
    new TemplateAction(emailBodyText, EMAIL_INAPPROPRIATE_APP_CONTENT_REMOVE, report.getApp().getTitle())
            .execute();

    emailPanel.add(templateButton);
    emailPanel.add(sentFrom);
    emailPanel.add(sentTo);
    emailPanel.add(emailBodyText);
    emailPanel.add(sendEmailAndDeactivateApp);
    emailPanel.add(cancel);

    content.add(emailPanel);
    popup.setWidget(content);
    // Center and show the popup
    popup.center();

    cancel.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            popup.hide();
        }
    });

    final User currentUser = Ode.getInstance().getUser();
    sentFrom.setText(MESSAGES.emailSentFrom() + currentUser.getUserName());
    sendEmailAndDeactivateApp.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            final OdeAsyncCallback<Long> emailCallback = new OdeAsyncCallback<Long>(MESSAGES.galleryError()) {
                @Override
                public void onSuccess(final Long emailId) {
                    if (emailId == Email.NOTRECORDED) {
                        Window.alert(MESSAGES.moderationErrorFailToSendEmail());
                        popup.hide();
                    } else {
                        popup.hide();
                        final OdeAsyncCallback<Boolean> callback = new OdeAsyncCallback<Boolean>(
                                // failure message
                                MESSAGES.galleryError()) {
                            @Override
                            public void onSuccess(Boolean success) {
                                if (!success)
                                    return;
                                if (rw.appActive == true) { //app was active, now is deactive
                                    rw.deactiveAppButton.setText(MESSAGES.labelReactivateApp());//revert button
                                    rw.appActive = false;
                                    storeModerationAction(report.getReportId(),
                                            report.getApp().getGalleryAppId(), emailId,
                                            GalleryModerationAction.DEACTIVATEAPP,
                                            getEmailPreview(emailBodyText.getText()));
                                } else { //app was deactive, now is active
                                    /*This should not be reached, just in case*/
                                    rw.deactiveAppButton.setText(MESSAGES.labelDeactivateApp());//revert button
                                    rw.appActive = true;
                                    storeModerationAction(report.getReportId(),
                                            report.getApp().getGalleryAppId(), emailId,
                                            GalleryModerationAction.REACTIVATEAPP,
                                            getEmailPreview(emailBodyText.getText()));
                                }
                                //update gallery list
                                galleryClient.appWasChanged();
                            }
                        };
                        Ode.getInstance().getGalleryService()
                                .deactivateGalleryApp(report.getApp().getGalleryAppId(), callback);
                    }
                }
            };
            String emailBody = emailBodyText.getText() + MESSAGES.galleryVisitGalleryAppLinkLabel(
                    Window.Location.getHost(), report.getApp().getGalleryAppId());
            Ode.getInstance().getGalleryService().sendEmail(currentUser.getUserId(),
                    report.getOffender().getUserId(), report.getOffender().getUserEmail(),
                    MESSAGES.moderationAppDeactivatedTitle(), emailBody, emailCallback);
        }
    });
}

From source file:com.google.appinventor.client.explorer.youngandroid.ReportList.java

License:Open Source License

/**
 * Helper method of creating popup window to show all associated moderation actions.
 * @param report GalleryAppReport gallery app report
 *//*from  w ww  . ja v a2  s  .  c o m*/
private void seeAllActionsPopup(GalleryAppReport report) {
    // Create a PopUpPanel with a button to close it
    final PopupPanel popup = new PopupPanel(true);
    popup.setStyleName("ode-InboxContainer");
    final FlowPanel content = new FlowPanel();
    content.addStyleName("ode-Inbox");
    Label title = new Label(MESSAGES.titleSeeAllActionsPopup());
    title.addStyleName("InboxTitle");
    content.add(title);

    Button closeButton = new Button(MESSAGES.symbolX());
    closeButton.addStyleName("CloseButton");
    closeButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            popup.hide();
        }
    });
    content.add(closeButton);

    final FlowPanel actionPanel = new FlowPanel();
    actionPanel.addStyleName("app-actions");

    final OdeAsyncCallback<List<GalleryModerationAction>> callback = new OdeAsyncCallback<List<GalleryModerationAction>>(
            // failure message
            MESSAGES.galleryError()) {
        @Override
        public void onSuccess(List<GalleryModerationAction> moderationActions) {
            for (final GalleryModerationAction moderationAction : moderationActions) {
                FlowPanel record = new FlowPanel();
                Label time = new Label();
                Date createdDate = new Date(moderationAction.getDate());
                DateTimeFormat dateFormat = DateTimeFormat.getFormat("yyyy/MM/dd HH:mm:ss");
                time.setText(dateFormat.format(createdDate));
                time.addStyleName("time-label");
                record.add(time);
                Label moderatorLabel = new Label();
                moderatorLabel.setText(moderationAction.getModeratorName());
                moderatorLabel.addStyleName("moderator-link");
                moderatorLabel.addClickHandler(new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        Ode.getInstance().switchToUserProfileView(moderationAction.getModeratorId(),
                                1 /* 1 for public view*/ );
                        popup.hide();
                    }
                });
                record.add(moderatorLabel);
                final Label actionLabel = new Label();
                actionLabel.addStyleName("inline-label");
                record.add(actionLabel);
                int actionType = moderationAction.getActonType();
                switch (actionType) {
                case GalleryModerationAction.SENDEMAIL:
                    actionLabel.setText(MESSAGES.moderationActionSendAnEmail());
                    createEmailCollapse(record, moderationAction.getMesaageId(),
                            moderationAction.getEmailPreview());
                    break;
                case GalleryModerationAction.DEACTIVATEAPP:
                    actionLabel.setText(MESSAGES.moderationActionDeactivateThisAppWithEmail());
                    createEmailCollapse(record, moderationAction.getMesaageId(),
                            moderationAction.getEmailPreview());
                    break;
                case GalleryModerationAction.REACTIVATEAPP:
                    actionLabel.setText(MESSAGES.moderationActionReactivateThisApp());
                    break;
                case GalleryModerationAction.MARKASRESOLVED:
                    actionLabel.setText(MESSAGES.moderationActionMarkThisReportAsResolved());
                    break;
                case GalleryModerationAction.MARKASUNRESOLVED:
                    actionLabel.setText(MESSAGES.moderationActionMarkThisReportAsUnresolved());
                    break;
                default:
                    break;
                }
                actionPanel.add(record);
            }
        }
    };
    Ode.getInstance().getGalleryService().getModerationActions(report.getReportId(), callback);

    content.add(actionPanel);
    popup.setWidget(content);
    // Center and show the popup
    popup.center();
}

From source file:com.google.appinventor.client.explorer.youngandroid.ReportList.java

License:Open Source License

/**
 * Help method for Email Collapse Function
 * When the button(see more) is clicked, it will retrieve the whole email from database.
 * @param parent the parent container//from  w w w . ja va2s  .  c o  m
 * @param emailId email id
 * @param preview email preview
 */
void createEmailCollapse(final FlowPanel parent, final long emailId, final String preview) {
    final Label emailContent = new Label();
    emailContent.setText(preview);
    emailContent.addStyleName("inline-label");
    parent.add(emailContent);
    final Label actionButton = new Label();
    actionButton.setText(MESSAGES.seeMoreLink());
    actionButton.addStyleName("seemore-link");
    parent.add(actionButton);
    if (preview.length() <= MAX_EMAIL_PREVIEW_LENGTH) {
        actionButton.setVisible(false);
    }
    actionButton.addClickHandler(new ClickHandler() {
        boolean ifPreview = true;

        @Override
        public void onClick(ClickEvent event) {
            if (ifPreview == true) {
                OdeAsyncCallback<Email> callback = new OdeAsyncCallback<Email>(
                        // failure message
                        MESSAGES.serverUnavailable()) {
                    @Override
                    public void onSuccess(final Email email) {
                        emailContent.setText(email.getBody());
                        emailContent.addStyleName("inline");
                        actionButton.setText(MESSAGES.hideLink());
                        ifPreview = false;
                    }
                };
                Ode.getInstance().getGalleryService().getEmail(emailId, callback);
            } else {
                emailContent.setText(preview);
                actionButton.setText(MESSAGES.seeMoreLink());
                ifPreview = true;
            }
        }
    });
}

From source file:com.google.appinventor.client.wizards.youngandroid.RemixedYoungAndroidProjectWizard.java

License:Open Source License

/**
 * Creates a new YoungAndroid project wizard.
 *//* ww w.  j av  a 2 s.c  om*/
public RemixedYoungAndroidProjectWizard(final GalleryApp app, final Button actionButton) {
    super(MESSAGES.remixedYoungAndroidProjectWizardCaption());

    this.actionButton = actionButton;
    gallery = GalleryClient.getInstance();
    // Initialize the UI
    setStylePrimaryName("ode-DialogBox");

    projectNameTextBox = new LabeledTextBox(MESSAGES.projectNameLabel());
    projectNameTextBox.setText(replaceNonTextChar(app.getTitle()));
    projectNameTextBox.getTextBox().addKeyDownHandler(new KeyDownHandler() {
        @Override
        public void onKeyDown(KeyDownEvent event) {
            int keyCode = event.getNativeKeyCode();
            if (keyCode == KeyCodes.KEY_ENTER) {
                handleOkClick();
            } else if (keyCode == KeyCodes.KEY_ESCAPE) {
                handleCancelClick();
            }
        }
    });

    VerticalPanel page = new VerticalPanel();
    page.add(projectNameTextBox);
    addPage(page);
    // Create finish command (create a new Young Android project)
    initFinishCommand(new Command() {
        @Override
        public void execute() {
            String projectName = projectNameTextBox.getText();
            final PopupPanel popup = new PopupPanel(true);
            final FlowPanel content = new FlowPanel();
            popup.setWidget(content);
            Label loading = new Label();
            loading.setText(MESSAGES.loadingAppIndicatorText());
            // loading indicator will be hided or forced to be hided in gallery.loadSourceFile
            content.add(loading);
            popup.center();
            boolean success = gallery.loadSourceFile(app, projectNameTextBox.getText(), popup);
            if (success) {
                gallery.appWasDownloaded(app.getGalleryAppId(), app.getDeveloperId());
            } else {
                show();
                center();
                return;
            }
        }
    });
}

From source file:com.google.caliper.cloud.client.BenchmarkDataViewer.java

License:Apache License

public void rebuildResultsTable() {
    if (plainText) {
        Label label = new Label();
        label.setStyleName("plaintext");
        label.setText(gridToString(toGrid()));

        resultsDiv.clear();/*from w ww  .  j  ava2 s  . c  o m*/
        resultsDiv.add(label);
        resultsDiv.add(new PlainTextEditor().getWidget());
        HTML dash = new HTML(" - ", false);
        dash.setStyleName("inline");
        resultsDiv.add(dash);
        resultsDiv.add(new SnapshotCreator().getWidget());
        return;
    }

    FlexTable table = new FlexTable();
    table.setStyleName("data");
    int r = 0;
    int c = 0;
    int evenRowMod = 0;

    // results header #1: cValue variables
    if (cVariable != null) {
        evenRowMod = 1;
        table.insertRow(r);
        table.getRowFormatter().setStyleName(r, "valueRow");
        table.getRowFormatter().addStyleName(r, "headerRow");

        table.addCell(r);
        table.getFlexCellFormatter().setColSpan(r, 0, rVariables.size());
        c++;
        for (Value cValue : cValues) {
            table.addCell(r);
            table.getFlexCellFormatter().setColSpan(r, c, 3);
            table.getCellFormatter().setStyleName(r, c, "parameterKey");

            Widget contents = newVariableLabel(cVariable, cValue.getLabel(), rVariables.size());
            contents.setStyleName("valueHeader");

            table.setWidget(r, c++, contents);
        }
        r++;
    }

    // results header 2: rValue variables, followed by "nanos/barchart" column pairs
    c = 0;
    table.insertRow(r);
    table.getRowFormatter().setStyleName(r, "evenRow");
    table.getRowFormatter().addStyleName(r, "headerRow");
    for (Variable variable : rVariables) {
        table.addCell(r);
        table.getCellFormatter().setStyleName(r, c, "parameterKey");
        table.setWidget(r, c, newVariableLabel(variable, variable.getName(), c));
        c++;
    }
    for (Value unused : cValues) {
        table.addCell(r);
        table.getCellFormatter().setStyleName(r, c, "parameterKey");
        table.setWidget(r, c++, newUnitLabel(unitMap.get(selectedType).trim()));

        table.addCell(r);
        table.getCellFormatter().setStyleName(r, c, "parameterKey");
        table.setWidget(r, c++, newRuntimeLabel());

        table.addCell(r);
        table.getCellFormatter().setStyleName(r, c, "parameterKey");
        table.setWidget(r, c++, new InlineLabel("%"));
    }
    r++;

    Key key = newDefaultKey();
    for (RowsIterator rows = new RowsIterator(rVariables); rows.nextRow();) {
        rows.updateKey(key);

        table.insertRow(r);
        table.getRowFormatter().setStyleName(r, r % 2 == evenRowMod ? "evenRow" : "oddRow");
        c = 0;
        for (int v = 0, size = rVariables.size(); v < size; v++) {
            table.addCell(r);
            table.setWidget(r, c++, new Label(rows.getRValue(v).getLabel()));
        }

        for (Value value : cValues) {
            table.addCell(r);
            table.addCell(r);

            if (cVariable != null) {
                key.set(cVariable, value);
            }

            final Datapoint datapoint = keysToDatapoints.get(key);
            table.getCellFormatter().setStyleName(r, c, "numericCell");
            table.getCellFormatter().setStyleName(r, c + 1, "bar");
            table.getCellFormatter().setStyleName(r, c + 2, "numericCell");
            MeasurementSet measurementSet;
            if (datapoint != null
                    && (measurementSet = datapoint.scenarioResults.getMeasurementSet(selectedType)) != null) {
                double rawMedian = getMedian(selectedType, measurementSet);
                String displayedValue = numberFormatMap.get(selectedType)
                        .format(rawMedian / divideByMap.get(selectedType));
                Anchor valueAnchor = new Anchor(displayedValue, false);
                valueAnchor.setStyleName("subtleLink");
                valueAnchor.setStyleName("nanos", true);

                final DialogBox eventLogPopup = new DialogBox(true);
                eventLogPopup.setText("");

                valueAnchor.addClickHandler(new ClickHandler() {
                    public void onClick(ClickEvent clickEvent) {
                        // Do this lazily since it takes quite a bit of time to render these popups for all
                        // the scenarios shown, and quite often they won't even be used.
                        if (eventLogPopup.getText().isEmpty()) {
                            eventLogPopup.setText("Event Log");
                            String eventLog = datapoint.scenarioResults.getEventLog(selectedType);
                            if (eventLog == null || eventLog.isEmpty()) {
                                eventLog = "No event log recorded.";
                            }
                            FlowPanel panel = new FlowPanel();
                            for (String line : eventLog.split("\n")) {
                                panel.add(new Label(line));
                            }
                            panel.setStyleName("eventLog");
                            eventLogPopup.add(panel);
                        }
                        eventLogPopup.center();
                        eventLogPopup.show();
                    }
                });

                table.setWidget(r, c, valueAnchor);
                table.setWidget(r, c + 1, newBar(datapoint.style, measurementSet, value));
                table.setWidget(r, c + 2, newPercentOfReferencePointLabel(rawMedian, value));
            } else {
                table.setWidget(r, c, new Label(""));
                table.setWidget(r, c + 1, new Label(""));
                table.setWidget(r, c + 2, new Label(""));
            }
            c += 3;
        }

        r++;
    }
    resultsDiv.clear();
    resultsDiv.add(table);
    resultsDiv.add(new PlainTextEditor().getWidget());
    HTML dash = new HTML(" - ", false);
    dash.setStyleName("inline");
    resultsDiv.add(dash);
    resultsDiv.add(new SnapshotCreator().getWidget());
}

From source file:com.google.code.gwt.geolocation.sample.hellogeolocation.client.HelloGeolocation.java

License:Apache License

/**
 * This is the entry point method.//ww  w  .  j  a  v a  2 s .c o  m
 */
public void onModuleLoad() {
    GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
        public void onUncaughtException(Throwable e) {
            RootPanel.get().add(new Label("Uncaught exception: " + e));
        }
    });
    final VerticalPanel main = new VerticalPanel();
    RootPanel.get().add(main);

    main.add(new Label("Geolocation provider: " + Geolocation.getProviderName()));
    //main.add(new Label("GWT strongname: " + GWT.getPermutationStrongName()));  // GWT2.0!

    Label l1 = new Label("Obtaining Geolocation...");
    main.add(l1);
    if (!Geolocation.isSupported()) {
        l1.setText("Obtaining Geolocation FAILED! Geolocation API is not supported.");
        return;
    }
    final Geolocation geo = Geolocation.getGeolocation();
    if (geo == null) {
        l1.setText("Obtaining Geolocation FAILED! Object is null.");
        return;
    }
    l1.setText("Obtaining Geolocation DONE!");

    main.add(new Button("Get Location", new ClickHandler() {
        public void onClick(ClickEvent event) {
            obtainPosition(main, geo);
        }
    }));

    obtainPosition(main, geo);
}

From source file:com.google.code.gwt.geolocation.sample.hellogeolocation.client.HelloGeolocation.java

License:Apache License

private void obtainPosition(final VerticalPanel main, Geolocation geo) {
    final Label l2 = new Label("Obtaining position (timeout: 15 sec)...");
    main.add(l2);// w ww  .  j  ava  2 s. c  o m

    geo.getCurrentPosition(new PositionCallback() {
        public void onFailure(PositionError error) {
            String message = "";
            switch (error.getCode()) {
            case PositionError.UNKNOWN_ERROR:
                message = "Unknown Error";
                break;
            case PositionError.PERMISSION_DENIED:
                message = "Permission Denied";
                break;
            case PositionError.POSITION_UNAVAILABLE:
                message = "Position Unavailable";
                break;
            case PositionError.TIMEOUT:
                message = "Time-out";
                break;
            default:
                message = "Unknown error code.";
            }
            l2.setText("Obtaining position FAILED! Message: '" + error.getMessage() + "', code: "
                    + error.getCode() + " (" + message + ")");
        }

        public void onSuccess(Position position) {
            l2.setText("Obtaining position DONE - acquired at " + position.getTimestamp());
            Coordinates c = position.getCoords();
            main.add(new Label("lat, lon: " + c.getLatitude() + ", " + c.getLongitude()));
            main.add(new Label("Accuracy (in meters): " + c.getAccuracy()));
            main.add(new Label("Altitude: " + (c.hasAltitude() ? c.getAltitude() : "[no value]")));
            main.add(new Label("Altitude accuracy (in meters): "
                    + (c.hasAltitudeAccuracy() ? c.getAltitudeAccuracy() : "[no value]")));
            main.add(new Label("Heading: " + (c.hasHeading() ? c.getHeading() : "[no value]")));
            main.add(new Label("Speed: " + (c.hasSpeed() ? c.getSpeed() : "[no value]")));
        }
    }, PositionOptions.getPositionOptions(false, 15000, 30000));
}