List of usage examples for com.google.gwt.user.client.ui Label addClickHandler
public HandlerRegistration addClickHandler(ClickHandler handler)
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 w w . j a v a2 s.c om 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 *///from ww w. ja v a 2s. 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.ProfilePage.java
License:Open Source License
/** * Helper method called by constructor to initialize image upload components *//* w w w . ja v a2 s . c o m*/ private void initImageComponents(String userId) { imageUploadBox.addStyleName("app-image-uploadbox"); imageUploadBox.addStyleName("gallery-editbox"); imageUploadPrompt = new Label("Upload your profile image!"); imageUploadPrompt.addStyleName("gallery-editprompt"); if (gallery.getGallerySettings() != null) { updateUserImage(gallery.getUserImageURL(userId), imageUploadBoxInner); } imageUploadPrompt.addStyleName("app-image-uploadprompt"); //imageUploadBoxInner.add(imageUploadPrompt); // Set the correct handler for servlet side capture imageUpload.setName(ServerLayout.UPLOAD_FILE_FORM_ELEMENT); imageUpload.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { uploadImage(); } }); imageUploadBoxInner.add(imageUpload); imageUploadBox.add(imageUploadBoxInner); profileHeaderWrapper.add(imageUploadBox); profileHeaderWrapper.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { // The correct way to trigger click event on FileUpload //imageUpload.getElement().<InputElement>cast().click(); } }); profileHeader.add(profileHeaderWrapper); Label uploadPrompt = new Label("Upload your profile image"); uploadPrompt.addStyleName("primary-link-small"); uploadPrompt.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { // The correct way to trigger click event on FileUpload imageUpload.getElement().<InputElement>cast().click(); } }); profileHeader.add(uploadPrompt); }
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 www . j a 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// w ww . j ava2 s . 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.code.p.gwtcsample.client.GWTCSample.java
License:Apache License
void setupLanguageLinks() { final Label english = new Label("English"); final Label spanish = new Label("Spanish"); final Label japanese = new Label("Japanese"); final ClickHandler changeLocale = new ClickHandler() { public void onClick(ClickEvent event) { Widget sender = (Widget) event.getSource(); if (sender == english) { Window.Location.assign("?locale=en"); } else if (sender == spanish) { Window.Location.assign("?locale=es"); } else if (sender == japanese) { Window.Location.assign("?locale=ja"); }// w w w . j a v a2 s .c o m } }; HorizontalPanel langPanel = new HorizontalPanel() { { setStyleName("langPanel"); String loc = Window.Location.getParameter("locale"); if (loc != null && !"en".equals(loc)) add(english); if (!"es".equals(loc)) add(spanish); if (!"ja".equals(loc)) add(japanese); english.addClickHandler(changeLocale); spanish.addClickHandler(changeLocale); japanese.addClickHandler(changeLocale); if ("ja".equals(loc)) alert.alert("This application has not been translated into Japanese yet.\n" + "Nevertheless you can see how dates are displayed in japanese because DatePicker uses GWT DateTimeFormat"); } }; RootPanel.get().add(langPanel); }
From source file:com.google.gwt.gen2.demo.fasttree.client.FastTreeDemo.java
License:Apache License
protected Widget basicTree() { FastTree t = new FastTree(); FastTreeItem a = t.addItem("A root tree item"); a.addItem("A child with different style"); a.addItem("regular style"); FastTreeItem aXb = a.addItem("Another child"); aXb.addItem("a grand child"); FastTreeItem widgetBranch = a.addItem(new CheckBox("A checkbox child")); FastTreeItem textBoxParent = widgetBranch.addItem("A TextBox parent"); textBoxParent.addItem(new TextBox()); textBoxParent.addItem("and another one..."); textBoxParent.addItem(new TextArea()); // Add an item with basic elements inside of it {/*from w ww . j av a2 s. c o m*/ final TextBox textBox = new TextBox(); Hyperlink link = new Hyperlink("change focus", "blah"); link.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { textBox.setFocus(true); event.getNativeEvent().stopPropagation(); } }); VerticalPanel vPanel = new VerticalPanel(); vPanel.add(link); vPanel.add(textBox); a.addItem(vPanel); } // Add a large item FastTreeItem hugeParent = a.addItem("I contain a huge item"); SimplePanel hugePanel = new SimplePanel(); hugePanel.setPixelSize(1000, 1000); hugePanel.getElement().getStyle().setProperty("border", "2px solid blue"); hugePanel.getElement().getStyle().setPropertyPx("padding", 50); Label clickableLabel = new Label("Click Me"); clickableLabel.setWidth("70px"); clickableLabel.getElement().getStyle().setProperty("border", "1px solid blue"); clickableLabel.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { Window.alert("You clicked the label"); } }); hugePanel.setWidget(clickableLabel); hugeParent.addItem(hugePanel); ListBox lb = new ListBox(); for (int i = 0; i < 100; i++) { lb.addItem(i + ""); } widgetBranch.addItem("A ListBox parent").addItem(lb); return t; }
From source file:com.google.livingstories.client.ui.TimelineWidget.java
License:Apache License
private void loadImpl() { // put the background arrow on the widget int arrowTop = eventInsertionHeight - HASHMARK_HEIGHT / 2; absolutePanel.add(leftArrow, 0, arrowTop); absolutePanel.add(rightArrow, widthInPixels - ARROW_HEAD_WIDTH, arrowTop); SimplePanel arrowBody = new SimplePanel(); arrowBody.setStylePrimaryName("arrowBody"); arrowBody.setSize((widthInPixels - 2 * ARROW_HEAD_WIDTH) + "px", ARROW_BODY_HEIGHT + "px"); absolutePanel.add(arrowBody, ARROW_HEAD_WIDTH, arrowTop + (ARROW_HEAD_HEIGHT - ARROW_BODY_HEIGHT) / 2); // Now build up an alternate map of Intervals to event strings. Using a TreeMap gives us // increasing dates by key, which is convenient. Map<Interval, TimelineData<T>> events = new TreeMap<Interval, TimelineData<T>>(); for (Interval rangeKey : filteredRangeKeys) { events.put(rangeKey, rangeEvents.get(rangeKey)); }//from ww w. j a v a 2 s . c o m for (Date pointKey : pointEvents.keySet()) { events.put(new Interval(pointKey, pointKey), pointEvents.get(pointKey)); } // some sufficiently positive value here to start. Don't be tempted to use // Integer.MAX_VALUE here; the subtraction below may end up overflowing. int previousXPosMid = 500000; offscreenXLeft = 10000; offscreenXRight = -10000; // we process the events from most recent to least, rather than the other way around, so that, // when globalXOffset is 0, we're biased towards showing the most-recent events rather than // the least-recent. List<Interval> intervalsReversed = new ArrayList<Interval>(events.keySet()); Collections.reverse(intervalsReversed); for (Interval interval : intervalsReversed) { Date startDate = interval.getStartDateTime(); Date endDate = interval.getEndDateTime(); int xPosStart = globalXOffset + mapDateToPixelPosition(startDate); int xPosEnd = startDate.equals(endDate) ? xPosStart : (globalXOffset + mapDateToPixelPosition(endDate)); int xPosMid = (xPosStart + xPosEnd) / 2; int widthShortfall = xPosMid + PADDED_EVENT_WIDTH - previousXPosMid; if (widthShortfall > 0) { xPosStart -= widthShortfall; xPosMid -= widthShortfall; xPosEnd -= widthShortfall; } if (xPosMid > maxXPos) { offscreenXRight = xPosMid; continue; } if (xPosMid < HALF_EVENT_WIDTH) { offscreenXLeft = xPosMid; break; } // We enclose the date label in an extra-wide widget to ensure that it's centered // over the hash mark. String dateString = DateUtil.formatDate(startDate); if (!startDate.equals(endDate)) { dateString += " - " + DateUtil.formatDate(endDate); } Label dateLabel = new Label(dateString); dateLabel.setStylePrimaryName("timelineDate"); dateLabel.setWidth(DATE_LABEL_WIDTH + "px"); dateLabel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); SimplePanel hashMark = new SimplePanel(); hashMark.setStylePrimaryName("hashMark"); hashMark.setWidth((xPosEnd - xPosStart + 1) + "px"); TimelineData<T> timelineData = events.get(interval); Label eventLabel = new Label(timelineData.getLabel(), true); eventLabel.setStylePrimaryName("timelineEvent"); eventLabel.setWidth(EVENT_WIDTH + "px"); int eventBoxY = eventInsertionHeight + HASHMARK_HEIGHT / 2; eventLabel.getElement().getStyle().setPropertyPx("maxHeight", heightInPixels - eventBoxY); final T data = timelineData.getData(); if (onClickBehavior != null && data != null) { eventLabel.addStyleName("clickableTimelineEvent"); eventLabel.addStyleName("secondaryLink"); eventLabel.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { onClickBehavior.onClick(event, data); } }); } absolutePanel.add(dateLabel, xPosMid - DATE_LABEL_WIDTH / 2, eventInsertionHeight - DATE_LABEL_OFFSET); absolutePanel.add(hashMark, xPosStart, eventInsertionHeight - HASHMARK_HEIGHT / 2); absolutePanel.add(eventLabel, xPosMid - HALF_EVENT_WIDTH + EVENT_OFFSET, eventBoxY); previousXPosMid = xPosMid; } // offScreenXLeft will be < HALF_EVENT_WIDTH iff it was actually set. Similarly for // offScreenXRight. leftArrow.setStylePrimaryName(offscreenXLeft < HALF_EVENT_WIDTH ? "enabledArrowHead" : "disabledArrowHead"); rightArrow.setStylePrimaryName(offscreenXRight > maxXPos ? "enabledArrowHead" : "disabledArrowHead"); }
From source file:com.google.sampling.experiential.client.ExperimentRow.java
License:Open Source License
public ExperimentRow(Images resources, ExperimentDAO experiment, ExperimentListener listener, boolean joined, boolean findView) { this.images = resources; this.myConstants = GWT.create(MyConstants.class); this.experiment = experiment; this.joined = joined; this.findView = findView; this.listeners = new ArrayList<ExperimentListener>(); if (listener != null) { listeners.add(listener);/*from w w w.j a v a 2s .c om*/ } HorizontalPanel horizontalPanel = new HorizontalPanel(); horizontalPanel.setStyleName("paco-experimentRow"); horizontalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); horizontalPanel.setSpacing(1); horizontalPanel.setHeight("42px"); initWidget(horizontalPanel); Image experimentIcon = new Image(resources.question()); experimentIcon.setAltText(myConstants.experimentIcon()); horizontalPanel.add(experimentIcon); horizontalPanel.setCellHeight(experimentIcon, "42"); horizontalPanel.setCellWidth(experimentIcon, "42"); horizontalPanel.setCellHorizontalAlignment(experimentIcon, HasHorizontalAlignment.ALIGN_CENTER); horizontalPanel.setCellVerticalAlignment(experimentIcon, HasVerticalAlignment.ALIGN_BOTTOM); experimentIcon.setSize("42px", "42px"); VerticalPanel verticalPanel = new VerticalPanel(); verticalPanel.setHeight("39px"); horizontalPanel.add(verticalPanel); HorizontalPanel horizontalPanel_2 = new HorizontalPanel(); horizontalPanel_2.setHeight("19px"); verticalPanel.add(horizontalPanel_2); Label experimentTitleLabel = new Label(experiment.getTitle()); if (experiment.getDeleted() != null && experiment.getDeleted()) { experimentTitleLabel.setStyleName("gwt-Link-underline-strikethrough"); } else { experimentTitleLabel.setStyleName("gwt-Link-underline"); } horizontalPanel_2.add(experimentTitleLabel); horizontalPanel_2.setCellWidth(experimentTitleLabel, "22px"); horizontalPanel_2.setCellHeight(experimentTitleLabel, "18px"); experimentTitleLabel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); horizontalPanel.setCellVerticalAlignment(experimentTitleLabel, HasVerticalAlignment.ALIGN_MIDDLE); experimentTitleLabel.setWidth("180px"); ClickHandler titleHandler = new ClickHandler() { public void onClick(ClickEvent event) { showExperimentDetails(); } }; if (!isExperimentPurged()) { experimentTitleLabel.addClickHandler(titleHandler); experimentIcon.addClickHandler(titleHandler); } HorizontalPanel horizontalPanel_1 = new HorizontalPanel(); horizontalPanel_1.setSpacing(1); verticalPanel.add(horizontalPanel_1); createButtonPanel(experiment, joined, horizontalPanel, horizontalPanel_1, findView); }
From source file:com.google.sampling.experiential.client.StatsPanel.java
License:Open Source License
private void showJoinedStats(Grid grid) { Label joinedLabel = new Label("Participants Data (click for detail):"); joinedLabel.setStyleName("gwt-Label-Header"); joinedLabel.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { //showParticipantsPopup(); fireExperimentCode(ExperimentListener.INDIVIDUAL_STATS_CODE); }/* www. ja v a 2 s .c o m*/ }); grid.setWidget(0, 0, joinedLabel); joinedLabel.setWidth(""); Label label = new Label(Integer.toString(createMapofParticipantsAndJoinTimes().values().size())); grid.setWidget(0, 1, label); }