List of usage examples for com.google.gwt.user.client.ui Label addClickHandler
public HandlerRegistration addClickHandler(ClickHandler handler)
From source file:org.eurekastreams.web.client.ui.common.pagedlist.RemovableGroupMemberPersonRenderer.java
License:Apache License
/** * {@inheritDoc}//from www .j a v a 2 s .c om */ public Panel render(final PersonModelView item) { PersonPanel panel = new PersonPanel(item, false, false, false); boolean currentUserIsAdmin = Session.getInstance().getCurrentPersonRoles().contains(Role.SYSTEM_ADMIN); boolean currentUserIsGroupCoordinator = isGroupCoordinator(Session.getInstance().getCurrentPerson()); // conditions by which a person should show up as 'Remove'-able: // cannot delete himself AND private group AND (current user is ADMIN or GROUP COORD) if ((Session.getInstance().getCurrentPerson().getId() != item.getEntityId()) && (currentUserIsAdmin || currentUserIsGroupCoordinator) && (!group.isPublic())) { boolean toBeRemovedFollowerIsGroupCoordinator = isGroupCoordinator(item); int numberOfGroupCoordinators = group.getCoordinators().size(); // Cannot remove Group Coordinator if he/she is the last Group Coordinator. if (toBeRemovedFollowerIsGroupCoordinator && (numberOfGroupCoordinators == 1)) { // short-circuit as this Person is non-removable return panel; } panel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().removablePerson()); Label deleteLink = new Label("Remove"); deleteLink.addStyleName(StaticResourceBundle.INSTANCE.coreCss().linkedLabel()); deleteLink.addStyleName(StaticResourceBundle.INSTANCE.coreCss().delete()); panel.add(deleteLink); deleteLink.addClickHandler(new ClickHandler() { public void onClick(final ClickEvent inArg0) { if (new WidgetJSNIFacadeImpl().confirm( "Are you sure you want to remove " + item.getDisplayName() + " from this group?")) { GroupMembersModel.getInstance() .delete(new SetFollowingStatusRequest(item.getAccountId(), groupUniqueId, EntityType.GROUP, false, FollowerStatus.NOTFOLLOWING, group.getShortName())); } } }); } return panel; }
From source file:org.eurekastreams.web.client.ui.common.stream.comments.CommentPanel.java
License:Apache License
/** * Default constructor.// w w w.j a v a 2 s .c om * * @param comment * the comment. * @param truncate * If long comments should be truncated. */ public CommentPanel(final CommentDTO comment, final boolean truncate) { final FlowPanel commentContainer = new FlowPanel(); commentContainer.addStyleName(StaticResourceBundle.INSTANCE.coreCss().messageComment()); StreamEntityDTO author = new StreamEntityDTO(EntityType.PERSON, comment.getAuthorAccountId()); author.setAvatarId(comment.getAuthorAvatarId()); author.setActive(comment.isAuthorActive()); author.setDisplayName(comment.getAuthorDisplayName()); commentContainer.add(AvatarLinkPanel.create(author, Size.VerySmall)); FlowPanel body = new FlowPanel(); body.addStyleName(StaticResourceBundle.INSTANCE.coreCss().body()); commentContainer.add(body); Widget authorName = RenderUtilities.renderEntityName(author, ""); authorName.addStyleName(StaticResourceBundle.INSTANCE.coreCss().messageCommentAuthor()); body.add(authorName); // parse the comment content ContentSegment segments = new ContentParser().split(comment.getBody().trim()); boolean oversize = truncate && isTooLong(segments); // build/display the comment content, truncating if too long final ComplexPanel textContainer = new FlowPanel(); textContainer.addStyleName(StaticResourceBundle.INSTANCE.coreCss().messageCommentText()); body.add(textContainer); // render only up to the limit Widget shortTextWidget = null; int size = 0; ContentSegment segment = segments; for (; segment != null; segment = segment.getNext()) { // check for when to stop if (oversize && !segment.isTag()) { int spaceLeft = TRUNCATE_LENGTH - size; int contentLength = segment.getContent().length(); if (contentLength > spaceLeft) { if (segment.isText()) { String shortText = getTruncatedText(segment.getContent(), spaceLeft); if (shortText != null) { shortTextWidget = new InlineLabel(shortText); textContainer.add(shortTextWidget); } } break; } size += contentLength; } contentRenderer.renderSegment(segment, textContainer, searchLinkBuilder); } final ContentSegment remainingSegments = segment; final Widget shortTextToReplace = shortTextWidget; // if too long, add a ... and "show more" link if (oversize) { final InlineLabel ellipsis = new InlineLabel("..."); body.add(ellipsis); final InlineLabel more = new InlineLabel("show more"); more.addStyleName(StaticResourceBundle.INSTANCE.coreCss().showMoreCommentLink()); more.addStyleName(StaticResourceBundle.INSTANCE.coreCss().linkedLabel()); more.addClickHandler(new ClickHandler() { public void onClick(final ClickEvent inEvent) { // remove the truncated segment, ... and "show more" if (shortTextToReplace != null) { shortTextToReplace.removeFromParent(); } more.removeFromParent(); ellipsis.removeFromParent(); // render the rest of the content contentRenderer.renderList(remainingSegments, textContainer, searchLinkBuilder); } }); body.add(more); } // timestamp and actions Panel timestampActions = new FlowPanel(); timestampActions.addStyleName(StaticResourceBundle.INSTANCE.coreCss().commentTimestamp()); body.add(timestampActions); DateFormatter dateFormatter = new DateFormatter(new Date()); Label dateLink = new InlineLabel(dateFormatter.timeAgo(comment.getTimeSent())); dateLink.addStyleName(StaticResourceBundle.INSTANCE.coreCss().commentTimestamp()); timestampActions.add(dateLink); Panel actionsPanel = new FlowPanel(); timestampActions.add(actionsPanel); if (comment.isDeletable()) { Label sep = new InlineLabel("\u2219"); sep.addStyleName(StaticResourceBundle.INSTANCE.coreCss().actionLinkSeparator()); actionsPanel.add(sep); Label deleteLink = new InlineLabel("Delete"); deleteLink.addStyleName(StaticResourceBundle.INSTANCE.coreCss().delete()); deleteLink.addStyleName(StaticResourceBundle.INSTANCE.coreCss().linkedLabel()); actionsPanel.add(deleteLink); deleteLink.addClickHandler(new ClickHandler() { public void onClick(final ClickEvent event) { if (jsniFacade.confirm("Are you sure you want to delete this comment?")) { Session.getInstance().getActionProcessor().makeRequest("deleteComment", comment.getId(), new AsyncCallback<Boolean>() { /* * implement the async call back methods */ public void onFailure(final Throwable caught) { // No failure state. } public void onSuccess(final Boolean result) { effects.fadeOut(commentContainer.getElement(), true); Session.getInstance().getEventBus() .notifyObservers(new CommentDeletedEvent(comment.getActivityId())); } }); } } }); } initWidget(commentContainer); }
From source file:org.eurekastreams.web.client.ui.common.stream.comments.PostCommentPanel.java
License:Apache License
/** * Unactivate the control./* w w w. j a v a 2s. c o m*/ */ private void unActivate() { if (!fullCollapse) { clear(); Label postAComment = new Label("post a comment"); postAComment.addStyleName(StaticResourceBundle.INSTANCE.coreCss().unactive()); postAComment.addStyleName(StaticResourceBundle.INSTANCE.coreCss().simulatedTextBox()); postAComment.addClickHandler(new ClickHandler() { public void onClick(final ClickEvent event) { activate(); } }); add(postAComment); } else { this.setVisible(false); } }
From source file:org.eurekastreams.web.client.ui.common.stream.FeatureDialogContent.java
License:Apache License
/** * Default constructor.//from ww w . j av a 2s . c om * * @param featuredStreamDTO * the featured stream. */ public FeatureDialogContent(final FeaturedStreamDTO featuredStreamDTO) { Label saveButton = new Label(""); saveButton.addStyleName(StaticResourceBundle.INSTANCE.coreCss().saveChangesButton()); body.add(new Label("Stream Name: " + featuredStreamDTO.getDisplayName())); final BasicTextAreaFormElement textArea = new BasicTextAreaFormElement(Person.MAX_JOB_DESCRIPTION_LENGTH, "Description", "description", featuredStreamDTO.getDescription(), "", true); body.add(textArea); body.add(saveButton); saveButton.addClickHandler(new ClickHandler() { public void onClick(final ClickEvent event) { featuredStreamDTO.setDescription(textArea.getValue()); FeaturedStreamModel.getInstance().insert(featuredStreamDTO); } }); EventBus.getInstance().addObserver(AddedFeaturedStreamResponseEvent.class, new Observer<AddedFeaturedStreamResponseEvent>() { public void update(final AddedFeaturedStreamResponseEvent event) { close(); } }); container.add(body); }
From source file:org.eurekastreams.web.client.ui.common.stream.FollowDialogContent.java
License:Apache License
/** * Default constructor./*from w w w . j ava2 s .c om*/ * * @param inStreamName * the stream name. * @param streamRequest * the stream request. * @param inStreamId * the stream id. * @param inSubscribeModel * Model for subscribing to activity on the stream. * @param inEntityUniqueId * Unique ID of entity owning the stream. * @param streamType * Type of entity of the stream. */ public FollowDialogContent(final String inStreamName, final String streamRequest, final Long inStreamId, final EntityType streamType, final BaseActivitySubscriptionModel inSubscribeModel, final String inEntityUniqueId) { Label saveButton = new Label(""); Label closeButton = new Label("No Thanks"); closeButton.addClickHandler(new ClickHandler() { public void onClick(final ClickEvent event) { close(); } }); body.add(new Label("You are now following the:")); Label streamTitle = new Label(inStreamName + " Stream"); streamTitle.addStyleName(StaticResourceBundle.INSTANCE.coreCss().title()); body.add(streamTitle); body.add(new Label("Below are additional ways to subscribe:")); FlowPanel options = new FlowPanel(); options.addStyleName(StaticResourceBundle.INSTANCE.coreCss().followDialogOptions()); final CheckBox addToStartPage = new CheckBox("Add this Stream to my Start Page"); final CheckBox bookmarkStream = new CheckBox("Bookmark this stream"); final CheckBox notifyViaEmail = new CheckBox("Notify me via Email"); saveButton.addClickHandler(new ClickHandler() { public void onClick(final ClickEvent event) { if (addToStartPage.getValue()) { // For the app's location, use the current URL minus a few parameters we know we don't want. (They // are used by other lists, but get left in the URL when switching tabs.) // We don't build the URL from the stream id, since that doesn't take search terms into account. HashMap<String, String> params = new HashMap<String, String>(); params.put("listId", null); params.put("listFilter", null); params.put("listSort", null); params.put("startIndex", null); params.put("endIndex", null); String url = Session.getInstance().generateUrl(new CreateUrlRequest(params)); String prefs = "{\"streamQuery\":" + WidgetJSNIFacadeImpl .makeJsonString(STREAM_URL_TRANSFORMER.getUrl(null, streamRequest)) + ",\"gadgetTitle\":" + WidgetJSNIFacadeImpl.makeJsonString(inStreamName) + ",\"streamLocation\":" + WidgetJSNIFacadeImpl.makeJsonString(url) + "}"; GadgetModel.getInstance() .insert(new AddGadgetToStartPageRequest("{d7a58391-5375-4c76-b5fc-a431c42a7555}", null, STREAM_URL_TRANSFORMER.getUrl(null, prefs))); } if (bookmarkStream.getValue()) { StreamBookmarksModel.getInstance().insert(inStreamId); } if (notifyViaEmail.getValue()) { inSubscribeModel.update(inEntityUniqueId, true, EntityType.GROUP == streamType ? subscribeCoordButton.getValue() : false); } close(); } }); options.add(addToStartPage); options.add(bookmarkStream); if (EntityType.GROUP == streamType) { Panel panel = new FlowPanel(); panel.add(notifyViaEmail); subscribeAllButton = new RadioButton("whichPosts", "All posts to this stream"); subscribeAllButton.setValue(true); subscribeAllButton.setEnabled(false); subscribeCoordButton = new RadioButton("whichPosts", "Only posts from coordinators of this stream"); subscribeCoordButton.setEnabled(false); panel.add(subscribeAllButton); panel.add(subscribeCoordButton); options.add(panel); notifyViaEmail.addClickHandler(new ClickHandler() { public void onClick(final ClickEvent inEvent) { boolean checked = notifyViaEmail.getValue(); subscribeAllButton.setEnabled(checked); subscribeCoordButton.setEnabled(checked); } }); } else { options.add(notifyViaEmail); } body.add(options); FlowPanel buttonPanel = new FlowPanel(); buttonPanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().followDialogButtonPanel()); saveButton.addStyleName(StaticResourceBundle.INSTANCE.coreCss().saveChangesButton()); buttonPanel.add(saveButton); buttonPanel.add(closeButton); body.add(buttonPanel); container.add(body); Label tipsTitle = new Label("Tips"); tips.add(tipsTitle); tips.add(new Label( "These options allow you to have control over how to access the activity of this stream.")); tips.add(new Label( "Don't worry, these selections are not permanent. You can always change them in the future.")); container.add(tips); body.addStyleName(StaticResourceBundle.INSTANCE.coreCss().followDialogBody()); tips.addStyleName(StaticResourceBundle.INSTANCE.coreCss().followDialogTips()); }
From source file:org.eurekastreams.web.client.ui.common.stream.renderers.StickyActivityRenderer.java
License:Apache License
/** * Builds the action links line./*from w ww .j av a2 s . com*/ * * @param msg * The message. * @param verbRenderer * Renderer for the message's verb. * @return The actions panel. */ private Widget buildActionsLine(final ActivityDTO msg, final VerbRenderer verbRenderer) { StreamEntityDTO destinationStream = msg.getDestinationStream(); // timestamp and actions Panel timestampActions = new FlowPanel(); timestampActions.addStyleName(StaticResourceBundle.INSTANCE.coreCss().messageTimestampActionsArea()); // Hijack this property and use to show lock icon for private activity. if (!msg.isShareable()) { Label lockIcon = new Label(""); lockIcon.addStyleName(StaticResourceBundle.INSTANCE.coreCss().privateIcon()); timestampActions.add(lockIcon); } // create timestamp as permalink String date = new DateFormatter(new Date()).timeAgo(msg.getPostedTime()); Widget dateLink; String permalinkUrl = activityLinkBuilder.buildActivityPermalink(msg.getId(), destinationStream.getType(), destinationStream.getUniqueIdentifier()); dateLink = new InlineHyperlink(date, permalinkUrl); dateLink.addStyleName(StaticResourceBundle.INSTANCE.coreCss().messageTimestampLink()); timestampActions.add(dateLink); if (msg.getAppName() != null) { String appSource = msg.getAppSource(); if (appSource != null) { FlowPanel viaPanel = new FlowPanel(); viaPanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().viaMetadata()); viaPanel.add(new InlineLabel("via ")); viaPanel.add(new Anchor(msg.getAppName(), appSource)); timestampActions.add(viaPanel); } else { InlineLabel viaLine = new InlineLabel("via " + msg.getAppName()); viaLine.addStyleName(StaticResourceBundle.INSTANCE.coreCss().viaMetadata()); timestampActions.add(viaLine); } // TODO: If appSource is not supplied, the link should go to the respective galleries for apps and plugins. // However, the app galery requires knowing the start page tab id, and the worthwhile plugin gallery is only // available to coordinators. } ComplexPanel actionsPanel = new FlowPanel(); actionsPanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().messageActionsArea()); // Show comments InlineHyperlink showCommentsLink = new InlineHyperlink("Show Comments", permalinkUrl); actionsPanel.add(showCommentsLink); // Share if (verbRenderer.getAllowShare() && msg.isShareable()) { insertActionSeparator(actionsPanel, null); Label shareLink = new InlineLabel("Share"); shareLink.addStyleName(StaticResourceBundle.INSTANCE.coreCss().linkedLabel()); actionsPanel.add(shareLink); shareLink.addClickHandler(new ClickHandler() { public void onClick(final ClickEvent event) { Dialog.showCentered(new ShareMessageDialogContent(msg)); } }); } // Unstick // Note: using the cheating way: always create the link, let CSS hide it unless the user is actually a // coordinator insertActionSeparator(actionsPanel, StaticResourceBundle.INSTANCE.coreCss().ownerOnlyInline()); Label link = new InlineLabel("Unstick"); link.addStyleName(StaticResourceBundle.INSTANCE.coreCss().linkedLabel()); link.addStyleName(StaticResourceBundle.INSTANCE.coreCss().ownerOnlyInline()); actionsPanel.add(link); link.addClickHandler(new ClickHandler() { public void onClick(final ClickEvent event) { GroupStickyActivityModel.getInstance().delete(msg.getDestinationStream().getDestinationEntityId()); } }); timestampActions.add(actionsPanel); return timestampActions; }
From source file:org.eurekastreams.web.client.ui.common.stream.renderers.StreamMessageItemRenderer.java
License:Apache License
/** * Builds the action links panel./*from ww w . ja v a 2 s. c om*/ * * @param msg * The message. * @param mainPanel * The overall panel for the message. * @param commentsPanel * The comments panel. * @param verbRenderer * Renderer for the message's verb. * @return The actions panel. */ private Widget buildActions(final ActivityDTO msg, final Panel mainPanel, final CommentsListPanel commentsPanel, final VerbRenderer verbRenderer) { final EventBus eventBus = Session.getInstance().getEventBus(); Panel actionsPanel = new FlowPanel(); actionsPanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().messageActionsArea()); // Comment // The verb is used for activities that are always now commentable. The msg.isCOmmentable is used for activities // that that normally are commentable but the user has turned off. if (commentsPanel != null && verbRenderer.getAllowComment() && msg.isCommentable()) { Label commentLink = new InlineLabel("Comment"); commentLink.addStyleName(StaticResourceBundle.INSTANCE.coreCss().linkedLabel()); actionsPanel.add(commentLink); commentLink.addClickHandler(new ClickHandler() { public void onClick(final ClickEvent event) { commentsPanel.activatePostComment(); } }); } // Like if (verbRenderer.getAllowLike()) { insertActionSeparator(actionsPanel); Widget like = new LikeWidget(msg.isLiked(), msg.getEntityId()); actionsPanel.add(like); } // Share if (verbRenderer.getAllowShare() && msg.isShareable()) { insertActionSeparator(actionsPanel); Label shareLink = new InlineLabel("Share"); shareLink.addStyleName(StaticResourceBundle.INSTANCE.coreCss().linkedLabel()); actionsPanel.add(shareLink); shareLink.addClickHandler(new ClickHandler() { public void onClick(final ClickEvent event) { onShare(msg); } }); } // Save/Unsave if (verbRenderer.getAllowStar() && msg.isStarred() != null) { insertActionSeparator(actionsPanel); Widget star = new StarLinkWidget(msg.isStarred(), msg.getEntityId()); actionsPanel.add(star); } // Stick (for group coordinators only) if (showStickActivity) { // Note: using the cheating way: always create the link, let CSS hide it unless the user is actually a // coordinator insertActionSeparator(actionsPanel) .addStyleName(StaticResourceBundle.INSTANCE.coreCss().ownerOnlyInline()); Label link = new InlineLabel("Stick"); link.addStyleName(StaticResourceBundle.INSTANCE.coreCss().linkedLabel()); link.addStyleName(StaticResourceBundle.INSTANCE.coreCss().ownerOnlyInline()); actionsPanel.add(link); link.addClickHandler(new ClickHandler() { public void onClick(final ClickEvent inEvent) { // Note: for now we assume the destination entity is a group (because that's all we've implemented // sticky activities for). Update here if that if sticky activities are allowed on other kinds of // streams. GroupStickyActivityModel.getInstance().insert(msg); } }); } // Flag as Inappropriate if (!state.equals(State.READONLY) && !showManageFlagged) { insertActionSeparator(actionsPanel); Label flagLink = new InlineLabel("Flag as Inappropriate"); flagLink.addStyleName(StaticResourceBundle.INSTANCE.coreCss().linkedLabel()); actionsPanel.add(flagLink); flagLink.addClickHandler(new ClickHandler() { public void onClick(final ClickEvent event) { if (new WidgetJSNIFacadeImpl() .confirm("Flagged activities will be sent to the system administrators for review. " + "Are you sure you want to flag this activity as inappropriate?")) { EventBus.getInstance().addObserver(UpdatedActivityFlagResponseEvent.class, new Observer<UpdatedActivityFlagResponseEvent>() { public void update(final UpdatedActivityFlagResponseEvent ev) { if (ev.getResponse() == msg.getId()) { EventBus.getInstance().removeObserver(ev, this); EventBus.getInstance().notifyObservers(new ShowNotificationEvent( new Notification("Activity has been flagged"))); } } }); FlaggedActivityModel.getInstance().update(new UpdateActivityFlagRequest(msg.getId(), true)); } } }); } return actionsPanel; }
From source file:org.eurekastreams.web.client.ui.common.stream.renderers.StreamMessageItemRenderer.java
License:Apache License
/** * Sets up the buttons to manage flagged content. * * @param msg/* ww w .j a v a 2 s .c om*/ * The activity. * @param mainPanel * The main activity panel. * @return Panel with the controls. */ private Widget buildManageFlaggedControls(final ActivityDTO msg, final Panel mainPanel) { final Panel buttonsPanel = new FlowPanel(); buttonsPanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().flagControls()); Label ignoreButton = new Label("Ignore"); ignoreButton.addStyleName(StaticResourceBundle.INSTANCE.coreCss().flagIgnoreButton()); buttonsPanel.add(ignoreButton); ignoreButton.addClickHandler(new ClickHandler() { public void onClick(final ClickEvent ev) { buttonsPanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().waitActive()); if (singleView) { Session.getInstance().getEventBus().addObserver(UpdatedActivityFlagResponseEvent.class, new Observer<UpdatedActivityFlagResponseEvent>() { public void update(final UpdatedActivityFlagResponseEvent ev) { if (ev.getResponse().equals(msg.getId())) { Session.getInstance().getEventBus().removeObserver(ev, this); buttonsPanel.removeFromParent(); } } }); } FlaggedActivityModel.getInstance().update(new UpdateActivityFlagRequest(msg.getId(), false)); } }); Label deleteButton = new Label("Delete"); deleteButton.addStyleName(StaticResourceBundle.INSTANCE.coreCss().flagDeleteButton()); buttonsPanel.add(deleteButton); deleteButton.addClickHandler(new ClickHandler() { public void onClick(final ClickEvent event) { if (new WidgetJSNIFacadeImpl().confirm("Are you sure you want to delete this activity?")) { // buttonsPanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().waitActive()); setupDeleteFadeout(msg, mainPanel); ActivityModel.getInstance().delete(msg.getId()); } } }); return buttonsPanel; }
From source file:org.eurekastreams.web.client.ui.common.widgets.activity.PostBoxComposite.java
License:Apache License
/** * Build page./*from ww w. jav a2 s . c o m*/ */ private void buildPage() { posterAvatar.add(avatarRenderer.render(Session.getInstance().getCurrentPerson().getEntityId(), Session.getInstance().getCurrentPerson().getAvatarId(), EntityType.PERSON, Size.Small)); postCharCount.setInnerText(POST_MAX.toString()); checkPostBox(); postBox.setLabel("Post to your stream..."); postBox.reset(); addEvents(); postBox.addKeyUpHandler(new KeyUpHandler() { public void onKeyUp(final KeyUpEvent event) { checkPostBox(); } }); postBox.addFocusHandler(new FocusHandler() { public void onFocus(final FocusEvent event) { postOptions.addClassName(style.visiblePostBox()); } }); postBox.addBlurHandler(new BlurHandler() { public void onBlur(final BlurEvent event) { timerFactory.runTimer(BLUR_DELAY, new TimerHandler() { public void run() { if (postBox.getText().trim().length() == 0 && !addLinkComposite.inAddMode() && attachment == null) { postOptions.removeClassName(style.visiblePostBox()); postBox.getElement().getStyle().clearHeight(); postBox.reset(); } } }); } }); setupPostButtonClickHandler(); postBox.addKeyDownHandler(new KeyDownHandler() { public void onKeyDown(final KeyDownEvent event) { if ((event.getNativeKeyCode() == KeyCodes.KEY_TAB || event.getNativeKeyCode() == KeyCodes.KEY_ENTER) && !event.isAnyModifierKeyDown() && activeItemIndex != null) { hashTags.getWidget(activeItemIndex).getElement().dispatchEvent( Document.get().createClickEvent(1, 0, 0, 0, 0, false, false, false, false)); event.preventDefault(); event.stopPropagation(); // clearSearch(); } else if (event.getNativeKeyCode() == KeyCodes.KEY_DOWN && activeItemIndex != null) { if (activeItemIndex + 1 < hashTags.getWidgetCount()) { selectItem((Label) hashTags.getWidget(activeItemIndex + 1)); } event.preventDefault(); event.stopPropagation(); } else if (event.getNativeKeyCode() == KeyCodes.KEY_UP && activeItemIndex != null) { if (activeItemIndex - 1 >= 0) { selectItem((Label) hashTags.getWidget(activeItemIndex - 1)); } event.preventDefault(); event.stopPropagation(); } else if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER && event.isControlKeyDown()) { postButton.getElement().dispatchEvent( Document.get().createClickEvent(1, 0, 0, 0, 0, false, false, false, false)); event.preventDefault(); event.stopPropagation(); } } }); postBox.addKeyUpHandler(new KeyUpHandler() { public void onKeyUp(final KeyUpEvent event) { int tagsAdded = 0; String postText = postBox.getText(); if (!postText.endsWith(" ")) { String[] words = postText.split("\\s"); if (words.length >= 1) { final String lastWord = words[words.length - 1]; if (lastWord.startsWith("#")) { boolean activeItemSet = false; Label firstItem = null; for (String hashTag : allHashTags) { if (hashTag.startsWith(lastWord)) { // get list ready on first tag added if (tagsAdded == 0) { hashTags.clear(); String boxHeight = postBox.getElement().getStyle().getHeight().replace("px", ""); if (boxHeight.isEmpty()) { boxHeight = "44"; } hashTags.getElement().getStyle().setTop( Integer.parseInt(boxHeight) + HASH_TAG_DROP_DOWN_PADDING, Unit.PX); hashTags.setVisible(true); } final String hashTagFinal = hashTag; final Label tagLbl = new Label(hashTagFinal); tagLbl.addClickHandler(new ClickHandler() { public void onClick(final ClickEvent event) { String postText = postBox.getText(); postText = postText.substring(0, postText.length() - lastWord.length()) + hashTagFinal + " "; postBox.setText(postText); hashTags.setVisible(false); hashTags.clear(); activeItemIndex = null; } }); tagLbl.addMouseOverHandler(new MouseOverHandler() { public void onMouseOver(final MouseOverEvent arg0) { selectItem(tagLbl); } }); hashTags.add(tagLbl); if (firstItem == null) { firstItem = tagLbl; } if (activeItemIndex != null && activeItemIndex.equals(hashTags.getWidgetCount() - 1)) { activeItemIndex = null; activeItemSet = true; selectItem(tagLbl); } tagsAdded++; if (tagsAdded >= MAX_HASH_TAG_AUTOCOMPLETE_ENTRIES) { break; } } } if (!activeItemSet && firstItem != null) { activeItemIndex = null; selectItem(firstItem); } } } } if (tagsAdded == 0) { hashTags.setVisible(false); activeItemIndex = null; } } }); AllPopularHashTagsModel.getInstance().fetch(null, true); SystemSettingsModel.getInstance().fetch(null, true); hashTags.setVisible(false); }
From source file:org.eurekastreams.web.client.ui.pages.activity.ActivityContent.java
License:Apache License
/** * Create LI Element for stream lists.//from w w w . j a va 2s . c om * * @param name * the name of the item. * @param view * the history token to load. * @param modifyClickHandler * click handler for modify. * @param modifyClass * the class for the modify button. * @param modifyText * the text for the modify button. * @param imgUrl * the img url. * @param isAvatar * if the image is an avatar. * @return the LI. */ private StreamNamePanel createPanel(final String name, final String view, final String imgUrl, final ClickHandler modifyClickHandler, final String modifyClass, final String modifyText, final boolean isAvatar) { StreamNamePanel panel = new StreamNamePanel(name); panel.addStyleName(style.streamOptionChild()); panel.addClickHandler(new ClickHandler() { public void onClick(final ClickEvent event) { History.newItem(Session.getInstance().generateUrl(new CreateUrlRequest(Page.ACTIVITY, view))); } }); FlowPanel innerPanel = new FlowPanel(); Image streamImage = new Image(imgUrl); if (isAvatar) { streamImage.addStyleName(style.smallAvatar()); } innerPanel.add(streamImage); Label streamName = new Label(name); streamName.setTitle(name); streamName.addStyleName(style.streamName()); streamName.addStyleName(StaticResourceBundle.INSTANCE.coreCss().ellipsis()); innerPanel.add(streamName); if (modifyClickHandler != null) { Label modifyLink = new Label(modifyText); modifyLink.addStyleName(modifyClass); modifyLink.addClickHandler(modifyClickHandler); innerPanel.add(modifyLink); } panel.add(innerPanel); return panel; }