Package org.eurekastreams.web.client.events

Examples of org.eurekastreams.web.client.events.EventBus


    /**
     * Setup bookmarks and custom streams.
     */
    private void setupStreamsAndBookmarks()
    {
        final EventBus eventBus = EventBus.getInstance();

        eventBus.addObserver(GotCurrentUserStreamBookmarks.class, new Observer<GotCurrentUserStreamBookmarks>()
        {
            private final AvatarUrlGenerator groupUrlGen = new AvatarUrlGenerator(EntityType.GROUP);
            private final AvatarUrlGenerator personUrlGen = new AvatarUrlGenerator(EntityType.PERSON);

            public void update(final GotCurrentUserStreamBookmarks event)
            {
                bookmarkList.clear();
                bookmarksWidgetMap.clear();

                List<StreamFilter> sortedStreamFilters = event.getResponse();
                Collections.sort(sortedStreamFilters, new StreamFilterNameComparator());

                for (final StreamFilter filter : sortedStreamFilters)
                {
                    JSONObject req = StreamJsonRequestFactory.getJSONRequest(filter.getRequest());
                    String uniqueId = null;
                    String entityType = null;

                    String imgUrl = "";

                    if (req.containsKey("query"))
                    {
                        JSONObject query = req.get("query").isObject();
                        if (query.containsKey(StreamJsonRequestFactory.RECIPIENT_KEY))
                        {
                            JSONArray recipient = query.get(StreamJsonRequestFactory.RECIPIENT_KEY).isArray();
                            if (recipient.size() > 0)
                            {
                                JSONObject recipientObj = recipient.get(0).isObject();
                                uniqueId = recipientObj.get("name").isString().stringValue();
                                entityType = recipientObj.get("type").isString().stringValue().toLowerCase();

                                AvatarUrlGenerator urlGen = groupUrlGen;

                                if ("person".equals(entityType))
                                {
                                    urlGen = personUrlGen;
                                }

                                imgUrl = urlGen.getSmallAvatarUrl(filter.getOwnerAvatarId());

                            }
                        }

                    }

                    if (uniqueId != null && entityType != null)
                    {
                        String bookmarkUrl = entityType + "/" + uniqueId;
                        StreamNamePanel bookmarkFilter = createPanel(filter.getName(), bookmarkUrl, imgUrl,
                                new ClickHandler()
                                {
                                    public void onClick(final ClickEvent event)
                                    {
                                        if (new WidgetJSNIFacadeImpl()
                                                .confirm("Are you sure you want to delete this bookmark?"))
                                        {
                                            StreamBookmarksModel.getInstance().delete(filter.getId());
                                        }

                                        event.stopPropagation();
                                    }
                                }, style.deleteBookmark(), "", true);

                        bookmarkList.add(bookmarkFilter);
                        bookmarksWidgetMap.put(bookmarkUrl, bookmarkFilter);
                    }

                }
                if (sortedStreamFilters.size() == 0)
                {
                    Label defaultLabel = new Label("Bookmarks allow you to quickly jump to any stream in Eureka.");
                    defaultLabel.addStyleName(style.noBookmarksMessage());
                    bookmarkList.add(defaultLabel);
                }

                bookmarksLoaded = true;
                checkInit();
            }
        });

        eventBus.addObserver(StreamActivitySubscriptionChangedEvent.class,
                new Observer<StreamActivitySubscriptionChangedEvent>()
                {
                    public void update(final StreamActivitySubscriptionChangedEvent ev)
                    {
                        boolean newStatus = ev.getResponse().getReceiveNewActivityNotifications();
                        setSubscribeStatus(newStatus);

                        String msg = newStatus ? "You will now receive emails for new activities to this stream"
                                : "You will no longer receive emails for new activities to this stream";
                        eventBus.notifyObservers(new ShowNotificationEvent(new Notification(msg)));
                    }
                });
        eventBus.addObserver(GotStreamActivitySubscriptionResponseEvent.class,
                new Observer<GotStreamActivitySubscriptionResponseEvent>()
                {
                    public void update(final GotStreamActivitySubscriptionResponseEvent result)
                    {
                        setSubscribeStatus(result.isSubscribed());
                    }
                });

        eventBus.addObserver(GotCurrentUserCustomStreamsResponseEvent.class,
                new Observer<GotCurrentUserCustomStreamsResponseEvent>()
                {
                    public void update(final GotCurrentUserCustomStreamsResponseEvent event)
                    {
                        filterList.clear();
                        customStreamWidgetMap.clear();

                        StreamNamePanel savedBy = createPanel("My Saved Items", "custom/0/"
                                + "{\"query\":{\"savedBy\":\""
                                + Session.getInstance().getCurrentPerson().getAccountId() + "\"}}",
                                "style/images/customStream.png", null, "", "", false);

                        filterList.add(savedBy);
                        customStreamWidgetMap.put(0L, savedBy);

                        StreamNamePanel likedBy = createPanel("My Liked Items", "custom/1/"
                                + "{\"query\":{\"likedBy\":[{\"type\":\"PERSON\", \"name\":\""
                                + Session.getInstance().getCurrentPerson().getAccountId() + "\"}]}}/My Liked Items",
                                "style/images/customStream.png", null, "", "", false);

                        filterList.add(likedBy);
                        customStreamWidgetMap.put(1L, likedBy);

                        for (final StreamFilter filter : event.getResponse().getStreamFilters())
                        {
                            StreamNamePanel filterPanel = createPanel(
                                    filter.getName(),
                                    "custom/"
                                            + filter.getId()
                                            + "/"
                                            + URL.encodeComponent(filter.getRequest().
                                                        replace("%%CURRENT_USER_ACCOUNT_ID%%",
                                                            Session.getInstance().getCurrentPerson().getAccountId())),
                                    "style/images/customStream.png", new ClickHandler()
                                    {

                                        public void onClick(final ClickEvent event)
                                        {
                                            Dialog.showCentered(new CustomStreamDialogContent((Stream) filter));
                                            event.stopPropagation();
                                        }
                                    }, style.editCustomStream(), "edit", false);

                            filterList.add(filterPanel);
                            customStreamWidgetMap.put(filter.getId(), filterPanel);
                        }

                        customStreamsLoaded = true;
                        checkInit();
                    }
                });

        eventBus.addObserver(StreamSearchBeginEvent.class, new Observer<StreamSearchBeginEvent>()
        {
            public void update(final StreamSearchBeginEvent event)
            {
                if (null == event.getSearchText())
                {
                    eventBus.notifyObservers(new UpdateHistoryEvent(new CreateUrlRequest("search", "", false)));
                    searchBox.setText("");
                }
            }
        });
    }
View Full Code Here


                checkMessageTextChanged();
                handlePostMessage();
            }
        });

        final EventBus eventBus = Session.getInstance().getEventBus();
        eventBus.addObserver(MessageStreamAppendEvent.class, new Observer<MessageStreamAppendEvent>()
        {
            public void update(final MessageStreamAppendEvent event)
            {
                errorMsg.setVisible(false);
                addStyleName(StaticResourceBundle.INSTANCE.coreCss().small());
                messageText = "";
                message.setText(postBoxDefaultText);
                onRemainingCharactersChanged();
                links.close();
            }
        });

        eventBus.addObserver(GotSystemSettingsResponseEvent.class, new Observer<GotSystemSettingsResponseEvent>()
        {
            public void update(final GotSystemSettingsResponseEvent event)
            {
                String warning = event.getResponse().getContentWarningText();
                if (warning != null && !warning.isEmpty())
                {
                    contentWarning.getElement().setInnerHTML(warning);
                }
                else
                {
                    contentWarning.setVisible(false);
                }
                message.setVisible(true);
            }
        });

        eventBus.addObserver(MessageTextAreaChangedEvent.getEvent(), new Observer<MessageTextAreaChangedEvent>()
        {
            public void update(final MessageTextAreaChangedEvent arg1)
            {
                // the value changed - make sure we're not stuck in the disabled, non-editable mode
                if ((" " + getStyleName() + " ").contains(StaticResourceBundle.INSTANCE.coreCss().small()))
                {
                    removeStyleName(StaticResourceBundle.INSTANCE.coreCss().small());
                }
                onRemainingCharactersChanged();
            }
        });

        eventBus.addObserver(MessageAttachmentChangedEvent.class, new Observer<MessageAttachmentChangedEvent>()
        {
            public void update(final MessageAttachmentChangedEvent evt)
            {
                errorMsg.setVisible(false);
                attachment = evt.getAttachment();
                if (attachment == null && messageText.isEmpty())
                {
                    hidePostButton();
                }
                else
                {
                    showPostButton();
                }
            }
        });

        eventBus.addObserver(new ErrorPostingMessageToNullScopeEvent(),
                new Observer<ErrorPostingMessageToNullScopeEvent>()
                {
                    public void update(final ErrorPostingMessageToNullScopeEvent event)
                    {
                        errorMsg.setText(event.getErrorMsg());
View Full Code Here

    /**
     * Wires up events.
     */
    private void setupEvents()
    {
        EventBus eventBus = Session.getInstance().getEventBus();

        // update the UI when group / attribute search is selected.
        group.addClickHandler(new ClickHandler()
        {
            public void onClick(final ClickEvent event)
            {
                description.setText(GROUP_DESC);
            }
        });
        attr.addClickHandler(new ClickHandler()
        {
            public void onClick(final ClickEvent event)
            {
                description.setText(ATTR_DESC);
            }
        });

        // make verification request to the server when user clicks verify button / presses enter
        verifyButton.addClickHandler(new ClickHandler()
        {
            public void onClick(final ClickEvent inArg0)
            {
                initiateVerification();
            }
        });
        membershipCriteria.addKeyUpHandler(new KeyUpHandler()
        {
            public void onKeyUp(final KeyUpEvent ev)
            {
                if (ev.getNativeKeyCode() == KeyCodes.KEY_ENTER)
                {
                    initiateVerification();
                }
            }
        });

        // got verification result: criterion matched some users
        eventBus.addObserver(MembershipCriteriaPersistedEvent.class, new Observer<MembershipCriteriaPersistedEvent>()
        {
            public void update(final MembershipCriteriaPersistedEvent ev)
            {
                membershipCriteria.setText("");
                tabDropDown.reset();
                themeDropDown.reset();
                results.setVisible(false);
                verifyingDone();

                addMembershipCriteria(ev.getResponse());
            }
        });

        // got verification result: criterion matched no users
        eventBus.addObserver(MembershipCriteriaVerificationNoUsersEvent.class,
                new Observer<MembershipCriteriaVerificationNoUsersEvent>()
                {
                    public void update(final MembershipCriteriaVerificationNoUsersEvent event)
                    {
                        results.setVisible(true);
                        results.addStyleName(StaticResourceBundle.INSTANCE.coreCss().formErrorBox());
                        results.setText(VERIFY_NO_USERS_MESSAGE);
                        verifyingDone();
                    }
                });

        // got verification result: query failed
        eventBus.addObserver(MembershipCriteriaVerificationFailureEvent.class,
                new Observer<MembershipCriteriaVerificationFailureEvent>()
                {
                    public void update(final MembershipCriteriaVerificationFailureEvent event)
                    {
                        results.setVisible(true);
View Full Code Here

TOP

Related Classes of org.eurekastreams.web.client.events.EventBus

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.