/**
   * Constructor.
   *
   * @param inSettings the system settings
   * @param inSupportGroup the support domain group
   */
  public SupportStreamHelpPanel(
      final SystemSettings inSettings, final DomainGroupModelView inSupportGroup) {
    Label headerLabel = new Label("Support Stream");
    headerPanel.add(headerLabel);
    headerPanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().header());
    contentPanel.add(descriptionPanel);
    add(headerPanel);
    add(contentPanel);

    logoPanel.add(
        new AvatarWidget(
            inSupportGroup.getId(), inSupportGroup.getAvatarId(), EntityType.GROUP, Size.Normal));
    logoPanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().supportGroupLogoPanel());

    contentPanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().contentPanel());
    contentPanel.add(logoPanel);
    descriptionPanel.add(new Label(inSupportGroup.getDescription()));

    Hyperlink gotoStreamLink =
        new Hyperlink(
            "Go to Stream",
            Session.getInstance()
                .generateUrl(
                    new CreateUrlRequest(
                        Page.GROUPS, inSettings.getSupportStreamGroupShortName())));
    descriptionPanel.add(gotoStreamLink);
    gotoStreamLink.addStyleName(
        StaticResourceBundle.INSTANCE.coreCss().goToSupportGroupStreamLink());

    contentPanel.add(descriptionPanel);
    descriptionPanel.addStyleName(
        StaticResourceBundle.INSTANCE.coreCss().supportGroupDescriptionPanel());
  }
  /** {@inheritDoc} */
  public void render(
      final Panel renderContainer,
      final ItemRenderer itemRenderer,
      final PagedSet<? extends Serializable> items,
      final String noItemsMessage) {
    Panel left = new FlowPanel();
    left.addStyleName(StaticResourceBundle.INSTANCE.coreCss().connectionColLeft());
    left.addStyleName(StaticResourceBundle.INSTANCE.coreCss().connectionCol());
    Panel right = new FlowPanel();
    right.addStyleName(StaticResourceBundle.INSTANCE.coreCss().connectionColRight());
    right.addStyleName(StaticResourceBundle.INSTANCE.coreCss().connectionCol());

    int count = 0;

    if (items.getTotal() == 0) {
      Label noItemsMessageLabel = new Label(noItemsMessage);
      noItemsMessageLabel.addStyleName(
          StaticResourceBundle.INSTANCE.coreCss().connectionItemEmpty());
      renderContainer.add(noItemsMessageLabel);
    } else {
      renderContainer.add(left);
      renderContainer.add(right);
    }
    double halfwayPoint = items.getPagedSet().size() / 2.0;

    for (Serializable item : items.getPagedSet()) {
      if (count >= halfwayPoint) {
        right.add(itemRenderer.render(item));
      } else {
        left.add(itemRenderer.render(item));
      }

      count++;
    }
  }
  /**
   * Constructor specifiying the key, or the history token key associated with this tab container.
   *
   * @param inKey the history token key.
   */
  public TabContainerPanel(final String inKey) {
    key = inKey;
    tabBoundaryPanel.setWidth("100%");
    tabBoundaryPanel.add(tabDropZone);
    tabBoundaryPanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().tabContainer());
    this.addStyleName(StaticResourceBundle.INSTANCE.coreCss().tabContainerParent());

    this.add(tabBoundaryPanel);
    this.add(tabContents);
  }
 /** Gets triggered whenever the comment changes. */
 private void onCommentChanges() {
   Integer charsRemaining = MAXLENGTH - commentBox.getText().length();
   countDown.setText(charsRemaining.toString());
   if (charsRemaining >= 0 && charsRemaining != MAXLENGTH) {
     countDown.removeStyleName(StaticResourceBundle.INSTANCE.coreCss().overCharacterLimit());
     post.removeStyleName(StaticResourceBundle.INSTANCE.coreCss().inactive());
     inactive = false;
   } else {
     if (charsRemaining != MAXLENGTH) {
       countDown.addStyleName(StaticResourceBundle.INSTANCE.coreCss().overCharacterLimit());
     }
     post.addStyleName(StaticResourceBundle.INSTANCE.coreCss().inactive());
     inactive = true;
   }
 }
Example #5
0
  /**
   * Constructor.
   *
   * @param entityType Type of entity the avatar belongs to.
   * @param entityUniqueId Short name / account id of entity the avatar belongs to.
   * @param avatar Avatar image widget.
   */
  public AvatarLinkPanel(
      final EntityType entityType, final String entityUniqueId, final AvatarWidget avatar) {
    Panel main = new FlowPanel();
    main.addStyleName(StaticResourceBundle.INSTANCE.coreCss().avatar());
    initWidget(main);

    Page page;
    switch (entityType) {
      case PERSON:
        page = Page.PEOPLE;
        break;
      case GROUP:
        page = Page.GROUPS;
        break;
      default:
        // this should never happen
        return;
    }
    HashMap<String, String> params = new HashMap<String, String>();
    params.put("tab", "Stream");

    String linkUrl =
        Session.getInstance().generateUrl(new CreateUrlRequest(page, entityUniqueId, params));

    Hyperlink link = new InlineHyperlink("", linkUrl);
    main.add(link);
    link.getElement().appendChild(avatar.getElement());
  }
  /**
   * Gets the image.
   *
   * @param imageId the image id.
   * @return the image.
   */
  public FlowPanel getImage(final String imageId) {
    AvatarUrlGenerator urlGenerator = new AvatarUrlGenerator(entityType);
    FlowPanel imageContainer = new FlowPanel();
    imageContainer.addStyleName(StaticResourceBundle.INSTANCE.coreCss().banner());
    imageContainer.add(new Image(urlGenerator.getBannerUrl(imageId)));

    return imageContainer;
  }
  /** Sets the remaining number of characters. */
  private void onRemainingCharactersChanged() {
    final int textLength = messageText.length();

    charsRemaining.setText(Integer.toString(MAX_MESSAGE_LENGTH - textLength));

    if (textLength <= MAX_MESSAGE_LENGTH && (!messageText.isEmpty() || links.hasAttachment())) {
      showPostButton();
    } else {
      hidePostButton();
    }

    if (textLength > MAX_MESSAGE_LENGTH) {
      charsRemaining.addStyleName(StaticResourceBundle.INSTANCE.coreCss().overCharacterLimit());
    } else {
      charsRemaining.removeStyleName(StaticResourceBundle.INSTANCE.coreCss().overCharacterLimit());
    }
  }
  /** Unactivate the control. */
  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);
    }
  }
  /**
   * Set the stream scope to post to.
   *
   * @param streamScope the scope.
   * @param postingEnabled if posting is enabled.
   */
  public void setStreamScope(final StreamScope streamScope, final Boolean postingEnabled) {
    postingDisabled.setVisible(!postingEnabled);
    shadowPanel.setVisible(postingEnabled);

    if (postComposite == null && postingEnabled) {
      postComposite = new PostToStreamComposite(streamScope);
      setupPostComposite();
    } else if (postingEnabled) {
      postComposite.setScope(streamScope);
    } else {
      FlowPanel postingDisabledMessage = new FlowPanel();

      postingDisabledMessage
          .getElement()
          .setInnerHTML("Posting messages has been disabled for this stream.");
      postingDisabled.addStyleName(StaticResourceBundle.INSTANCE.coreCss().postingDisabledBox());
      postingDisabled.add(postingDisabledMessage);
      postContent.add(postingDisabled);
    }
  }
  /** Constructor. */
  public NotificationCountWidget() {
    addStyleName(StaticResourceBundle.INSTANCE.coreCss().notifCount());
    setTitle("View Notifications");

    addClickHandler(
        new ClickHandler() {
          public void onClick(final ClickEvent inEvent) {
            showDialog();
          }
        });

    Session.getInstance()
        .getEventBus()
        .addObserver(
            NotificationCountsAvailableEvent.class,
            new Observer<NotificationCountsAvailableEvent>() {
              public void update(final NotificationCountsAvailableEvent ev) {
                int total = ev.getNormalCount() + ev.getHighPriorityCount();
                setText(Integer.toString(total));
                if (total > 0) {
                  if (ev.getHighPriorityCount() > 0) {
                    addStyleName(StaticResourceBundle.INSTANCE.coreCss().notifCountHighPriority());
                    removeStyleName(
                        StaticResourceBundle.INSTANCE.coreCss().notifCountNormalPriority());
                  } else {
                    addStyleName(
                        StaticResourceBundle.INSTANCE.coreCss().notifCountNormalPriority());
                    removeStyleName(
                        StaticResourceBundle.INSTANCE.coreCss().notifCountHighPriority());
                  }
                } else {
                  removeStyleName(
                      StaticResourceBundle.INSTANCE.coreCss().notifCountNormalPriority());
                  removeStyleName(StaticResourceBundle.INSTANCE.coreCss().notifCountHighPriority());
                }
              }
            });
  }
 /** Displays the post button. */
 private void showPostButton() {
   postButton.removeStyleName(StaticResourceBundle.INSTANCE.coreCss().inactive());
 }
 /**
  * Gets called if this element has an error.
  *
  * @param errMessage the error Message.
  */
 public void onError(final String errMessage) {
   label.addStyleName(StaticResourceBundle.INSTANCE.coreCss().formError());
 }
 /**
  * Default constructor.
  *
  * @param inMessageId the message id.
  * @param inFullCollapse if the panel should fully collapse on unActivate.
  */
 public PostCommentPanel(final Long inMessageId, final boolean inFullCollapse) {
   messageId = inMessageId;
   addStyleName(StaticResourceBundle.INSTANCE.coreCss().messageComment());
   unActivate();
   fullCollapse = inFullCollapse;
 }
 /** Gets called if this element was successful. */
 public void onSuccess() {
   label.removeStyleName(StaticResourceBundle.INSTANCE.coreCss().formError());
 }
  /** Activate the control. */
  public void activate() {
    clear();
    this.setVisible(true);
    Widget avatar =
        new AvatarWidget(
            Session.getInstance().getCurrentPerson().getAvatarId(),
            EntityType.PERSON,
            Size.VerySmall);
    avatar.addStyleName(StaticResourceBundle.INSTANCE.coreCss().avatar());
    this.add(avatar);

    FlowPanel body = new FlowPanel();
    body.addStyleName(StaticResourceBundle.INSTANCE.coreCss().body());

    SimplePanel boxWrapper = new SimplePanel();
    boxWrapper.addStyleName(StaticResourceBundle.INSTANCE.coreCss().boxWrapper());
    commentBox = new ExtendedTextArea(true);
    boxWrapper.add(commentBox);
    body.add(boxWrapper);
    commentBox.setFocus(true);

    countDown = new Label(Integer.toString(MAXLENGTH));
    countDown.addStyleName(StaticResourceBundle.INSTANCE.coreCss().charactersRemaining());
    body.add(countDown);

    post = new PushButton("post");
    post.addStyleName(StaticResourceBundle.INSTANCE.coreCss().postButton());
    post.addStyleName(StaticResourceBundle.INSTANCE.coreCss().inactive());
    body.add(post);

    final Label warning = new Label();
    warning.addStyleName(StaticResourceBundle.INSTANCE.coreCss().warning());
    warning.addStyleName(StaticResourceBundle.INSTANCE.coreCss().hidden());
    body.add(warning);

    Session.getInstance()
        .getEventBus()
        .addObserver(
            GotSystemSettingsResponseEvent.class,
            new Observer<GotSystemSettingsResponseEvent>() {
              public void update(final GotSystemSettingsResponseEvent event) {
                String text = event.getResponse().getContentWarningText();
                if (text != null && !text.isEmpty()) {
                  warning.removeStyleName(StaticResourceBundle.INSTANCE.coreCss().hidden());
                  warning.setText(text);
                }
              }
            });

    SystemSettingsModel.getInstance().fetch(null, true);

    post.addClickHandler(
        new ClickHandler() {
          public void onClick(final ClickEvent event) {
            fullCollapse = false;
            if (!inactive) {
              unActivate();
              CommentDTO comment = new CommentDTO();
              comment.setBody(commentBox.getText());
              comment.setActivityId(messageId);
              Session.getInstance()
                  .getActionProcessor()
                  .makeRequest(
                      "postActivityCommentAction",
                      comment,
                      new AsyncCallback<CommentDTO>() {
                        /* implement the async call back methods */
                        public void onFailure(final Throwable caught) {}

                        public void onSuccess(final CommentDTO result) {
                          ActivityModel.getInstance().clearCache();
                          Session.getInstance()
                              .getEventBus()
                              .notifyObservers(new CommentAddedEvent(result, messageId));
                        }
                      });
            }
          }
        });

    this.add(body);
    commentBox.setFocus(true);
    nativeSetFocus(commentBox.getElement());

    commentBox.addBlurHandler(
        new BlurHandler() {
          public void onBlur(final BlurEvent arg0) {
            TimerFactory timerFactory = new TimerFactory();
            timerFactory.runTimer(
                BLUR_DELAY,
                new TimerHandler() {
                  public void run() {
                    if (commentBox.getText().length() == 0) {
                      unActivate();
                    }
                  }
                });
          }
        });

    commentBox.addKeyDownHandler(
        new KeyDownHandler() {
          public void onKeyDown(final KeyDownEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE) {
              unActivate();
            } else if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER && event.isControlKeyDown()) {
              post.getElement()
                  .dispatchEvent(
                      Document.get().createClickEvent(1, 0, 0, 0, 0, false, false, false, false));
              event.preventDefault();
              event.stopPropagation();
            }
          }
        });

    commentBox.addKeyUpHandler(
        new KeyUpHandler() {
          public void onKeyUp(final KeyUpEvent event) {
            onCommentChanges();
          }
        });

    commentBox.addValueChangeHandler(
        new ValueChangeHandler<String>() {
          public void onValueChange(final ValueChangeEvent<String> inArg0) {
            onCommentChanges();
          }
        });

    commentBox.addChangeHandler(
        new ChangeHandler() {
          public void onChange(final ChangeEvent event) {
            onCommentChanges();
          }
        });
  }
Example #16
0
 /**
  * Renders an avatar.
  *
  * @param id id of the user.
  * @param avatarId avatar id of the user.
  * @param type the type.
  * @param size the avatar size.
  * @return the avatar panel.
  */
 public Widget render(
     final Long id, final String avatarId, final EntityType type, final Size size) {
   AvatarWidget avatar = new AvatarWidget(avatarId, type, size);
   avatar.addStyleName(StaticResourceBundle.INSTANCE.coreCss().avatar());
   return avatar;
 }
 /** Hides the post button. */
 private void hidePostButton() {
   postButton.addStyleName(StaticResourceBundle.INSTANCE.coreCss().inactive());
 }
  /**
   * Builds the UI.
   *
   * @param inScope the scope.
   */
  private void setupWidgets(final StreamScope inScope) {
    this.getElement().setAttribute("id", "post-to-stream");
    this.addStyleName(StaticResourceBundle.INSTANCE.coreCss().small());

    charsRemaining = new Label();
    postButton = new Hyperlink("", History.getToken());
    postButton.getElement().setAttribute("tabindex", "2");
    message = new PostToStreamTextboxPanel();
    message.setText(postBoxDefaultText);
    message.setVisible(false); // Hide until post ready event.

    this.addStyleName(StaticResourceBundle.INSTANCE.coreCss().postToStream());
    errorMsg.addStyleName(StaticResourceBundle.INSTANCE.coreCss().formErrorBox());
    errorMsg.setVisible(false);
    this.add(errorMsg);

    FlowPanel postInfoContainer = new FlowPanel();
    postInfoContainer.addStyleName(StaticResourceBundle.INSTANCE.coreCss().postInfoContainer());

    postButton.addStyleName(StaticResourceBundle.INSTANCE.coreCss().postButton());
    postInfoContainer.add(postButton);

    charsRemaining.addStyleName(StaticResourceBundle.INSTANCE.coreCss().charactersRemaining());
    postInfoContainer.add(charsRemaining);

    AvatarWidget avatar =
        new AvatarWidget(
            Session.getInstance().getCurrentPerson(), EntityType.PERSON, Size.VerySmall);
    avatar.addStyleName(StaticResourceBundle.INSTANCE.coreCss().postEntryAvatar());

    Panel entryPanel = new FlowPanel();
    entryPanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().postEntryPanel());
    entryPanel.add(avatar);
    entryPanel.add(postInfoContainer);
    entryPanel.add(message);
    SimplePanel breakPanel = new SimplePanel();
    breakPanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().breakClass());
    entryPanel.add(breakPanel);
    add(entryPanel);

    // below text area: links and post to on one line, then content warning below

    expandedPanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().postExpandedPanel());

    postToPanel = new PostToPanel(inScope);
    expandedPanel.add(postToPanel);
    links = new AddLinkComposite();
    expandedPanel.add(links);

    contentWarning = new FlowPanel();
    contentWarningContainer.addStyleName(StaticResourceBundle.INSTANCE.coreCss().contentWarning());
    contentWarningContainer.add(new SimplePanel());
    contentWarningContainer.add(contentWarning);
    expandedPanel.add(contentWarningContainer);

    add(expandedPanel);

    setVisible(false);

    setVisible(Session.getInstance().getCurrentPerson() != null);
  }
  /**
   * Default constructor.
   *
   * @param json the id of the default view.
   */
  public StreamListFormElement(final JSONObject json) {
    scopes =
        new StreamScopeFormElement(
            "scopes",
            new LinkedList<StreamScope>(),
            "",
            "Enter the name of an employee or group.",
            false,
            true,
            "/resources/autocomplete/entities/",
            MAX_NAME,
            MAX_ITEMS);

    this.addStyleName(StaticResourceBundle.INSTANCE.coreCss().streamLists());
    label.addStyleName(StaticResourceBundle.INSTANCE.coreCss().formLabel());
    this.add(label);

    this.add(streamOptions);

    streamOptions.addItem("Everyone", "");
    streamOptions.addItem("Following", StreamJsonRequestFactory.FOLLOWED_BY_KEY);
    streamOptions.addItem("Saved", StreamJsonRequestFactory.SAVED_KEY);
    streamOptions.addItem("Groups I've Joined", StreamJsonRequestFactory.JOINED_GROUPS_KEY);
    streamOptions.addItem("Posted To", StreamJsonRequestFactory.RECIPIENT_KEY);
    streamOptions.addItem("Authored By", StreamJsonRequestFactory.AUTHOR_KEY);
    streamOptions.addItem("Liked By", StreamJsonRequestFactory.LIKER_KEY);

    streamOptions.addChangeHandler(
        new ChangeHandler() {
          public void onChange(final ChangeEvent event) {
            scopes.setVisible(hasStreamScopes(getSelected()));
          }
        });

    if (json == null) {
      streamOptions.setSelectedIndex(0);
      scopes.setVisible(false);
    } else {
      if (json.containsKey(StreamJsonRequestFactory.RECIPIENT_KEY)) {
        setSelectedByValue(StreamJsonRequestFactory.RECIPIENT_KEY);
      } else if (json.containsKey(StreamJsonRequestFactory.SAVED_KEY)) {
        setSelectedByValue(StreamJsonRequestFactory.SAVED_KEY);
      } else if (json.containsKey(StreamJsonRequestFactory.PARENT_ORG_KEY)) {
        setSelectedByValue(StreamJsonRequestFactory.PARENT_ORG_KEY);
      } else if (json.containsKey(StreamJsonRequestFactory.FOLLOWED_BY_KEY)) {
        setSelectedByValue(StreamJsonRequestFactory.FOLLOWED_BY_KEY);
      } else if (json.containsKey(StreamJsonRequestFactory.AUTHOR_KEY)) {
        setSelectedByValue(StreamJsonRequestFactory.AUTHOR_KEY);
      } else if (json.containsKey(StreamJsonRequestFactory.LIKER_KEY)) {
        setSelectedByValue(StreamJsonRequestFactory.LIKER_KEY);
      } else if (json.containsKey(StreamJsonRequestFactory.JOINED_GROUPS_KEY)) {
        setSelectedByValue(StreamJsonRequestFactory.JOINED_GROUPS_KEY);
      } else {
        setSelectedByValue("");
      }

      if (hasStreamScopes(getSelected())) {
        Session.getInstance()
            .getEventBus()
            .addObserver(
                GotBulkEntityResponseEvent.class,
                new Observer<GotBulkEntityResponseEvent>() {
                  public void update(final GotBulkEntityResponseEvent event) {
                    JSONArray recipientArray = json.get(getSelected()).isArray();

                    for (int i = 0; i < recipientArray.size(); i++) {
                      JSONObject recipient = (JSONObject) recipientArray.get(i);
                      String uniqueId =
                          recipient
                              .get(StreamJsonRequestFactory.ENTITY_UNIQUE_ID_KEY)
                              .isString()
                              .stringValue();
                      String displayName =
                          getEntityDisplayName(
                              EntityType.valueOf(
                                  recipient
                                      .get(StreamJsonRequestFactory.ENTITY_TYPE_KEY)
                                      .isString()
                                      .stringValue()),
                              uniqueId,
                              event.getResponse());

                      ScopeType scopeType =
                          ScopeType.valueOf(
                              recipient
                                  .get(StreamJsonRequestFactory.ENTITY_TYPE_KEY)
                                  .isString()
                                  .stringValue());

                      StreamScope scope = new StreamScope(scopeType, uniqueId);
                      scope.setDisplayName(displayName);

                      Session.getInstance()
                          .getEventBus()
                          .notifyObservers(new StreamScopeAddedEvent(scope));
                    }

                    Session.getInstance()
                        .getEventBus()
                        .removeObserver(GotBulkEntityResponseEvent.class, this);
                  }
                });

        ArrayList<StreamEntityDTO> entities = new ArrayList<StreamEntityDTO>();

        JSONArray recipientArray = json.get(getSelected()).isArray();
        for (int i = 0; i < recipientArray.size(); i++) {
          JSONObject recipient = (JSONObject) recipientArray.get(i);
          StreamEntityDTO entity = new StreamEntityDTO();
          entity.setType(
              EntityType.valueOf(
                  recipient
                      .get(StreamJsonRequestFactory.ENTITY_TYPE_KEY)
                      .isString()
                      .stringValue()));
          entity.setUniqueIdentifier(
              recipient
                  .get(StreamJsonRequestFactory.ENTITY_UNIQUE_ID_KEY)
                  .isString()
                  .stringValue());
          entities.add(entity);
        }
        BulkEntityModel.getInstance().fetch(entities, false);
      }
    }

    this.add(scopes);
  }
Example #20
0
 /**
  * Renders an avatar.
  *
  * @param id id of the user.
  * @param avatarId avatar id of the user.
  * @return the avatar panel.
  */
 public Widget render(final Long id, final String avatarId) {
   AvatarWidget avatar = new AvatarWidget(avatarId, EntityType.PERSON, Size.Small);
   avatar.addStyleName(StaticResourceBundle.INSTANCE.coreCss().avatar());
   return avatar;
 }
  /**
   * Create an avatar upload form element.
   *
   * @param label the label of the element.
   * @param desc the description.
   * @param servletPath the path to hit to upload the image
   * @param inProcessor the processor.
   * @param inStrategy the strategy.
   */
  public AvatarUploadFormElement(
      final String label,
      final String desc,
      final String servletPath,
      final ActionProcessor inProcessor,
      final ImageUploadStrategy inStrategy) {
    description = desc;
    strategy = inStrategy;
    Boolean resizeable = strategy.isResizable();

    errorBox = new FlowPanel();
    errorBox.addStyleName(StaticResourceBundle.INSTANCE.coreCss().formErrorBox());
    errorBox.add(
        new Label(
            "There was an error uploading your image. Please be sure "
                + "that your photo is under 4MB and is a PNG, JPG, or GIF."));

    errorBox.setVisible(false);

    this.addStyleName(StaticResourceBundle.INSTANCE.coreCss().formAvatarUpload());
    this.addStyleName(StaticResourceBundle.INSTANCE.coreCss().formElement());

    processor = inProcessor;
    // AvatarEntity Entity = inEntity;

    uploadForm.setAction(servletPath);

    uploadForm.setEncoding(FormPanel.ENCODING_MULTIPART);
    uploadForm.setMethod(FormPanel.METHOD_POST);

    Label photoLabel = new Label(label);
    photoLabel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().formLabel());
    panel.add(photoLabel);

    FlowPanel avatarModificationPanel = new FlowPanel();
    avatarModificationPanel.addStyleName(
        StaticResourceBundle.INSTANCE.coreCss().avatarModificationPanel());

    avatarContainer.addStyleName(StaticResourceBundle.INSTANCE.coreCss().avatarContainer());
    avatarModificationPanel.add(avatarContainer);

    FlowPanel photoButtonPanel = new FlowPanel();
    photoButtonPanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().formPhotoButtonPanel());

    if (resizeable) {
      editButton = new Anchor("Resize");
      editButton.addStyleName(StaticResourceBundle.INSTANCE.coreCss().formResizeButton());
      editButton.addStyleName(StaticResourceBundle.INSTANCE.coreCss().formButton());
      photoButtonPanel.add(editButton);
    }

    deleteButton = new Anchor("Delete");
    deleteButton.addStyleName(StaticResourceBundle.INSTANCE.coreCss().formDeleteButton());
    deleteButton.addStyleName(StaticResourceBundle.INSTANCE.coreCss().formButton());
    photoButtonPanel.add(deleteButton);

    avatarModificationPanel.add(photoButtonPanel);
    panel.add(avatarModificationPanel);

    FlowPanel uploadPanel = new FlowPanel();
    uploadPanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().formUploadPanel());
    uploadPanel.add(errorBox);

    // Wrapping the FileUpload because otherwise IE7 shifts it way
    // to the right. I couldn't figure out why,
    // but for whatever reason, this works.
    FlowPanel fileUploadWrapper = new FlowPanel();
    FileUpload upload = new FileUpload();
    upload.setName("imageUploadFormElement");
    upload.addStyleName(StaticResourceBundle.INSTANCE.coreCss().formAvatarUpload());
    fileUploadWrapper.add(upload);
    uploadPanel.add(fileUploadWrapper);

    uploadPanel.add(new Label(description));
    Anchor submitButton = new Anchor("");
    submitButton.addStyleName(StaticResourceBundle.INSTANCE.coreCss().formUploadButton());
    submitButton.addStyleName(StaticResourceBundle.INSTANCE.coreCss().formButton());

    uploadPanel.add(submitButton);

    hiddenImage = new Image();
    hiddenImage.addStyleName(StaticResourceBundle.INSTANCE.coreCss().avatarHiddenOriginal());
    uploadPanel.add(hiddenImage);

    panel.add(uploadPanel);

    submitButton.addClickHandler(
        new ClickHandler() {
          public void onClick(final ClickEvent event) {
            uploadForm.submit();
          }
        });

    uploadForm.setWidget(panel);
    this.add(uploadForm);

    uploadForm.addSubmitCompleteHandler(
        new SubmitCompleteHandler() {
          public void onSubmitComplete(final SubmitCompleteEvent ev) {
            String result = ev.getResults().replaceAll("\\<.*?\\>", "");
            final boolean fail = "fail".equals(result);
            errorBox.setVisible(fail);
            if (!fail) {
              String[] results = result.split(",");
              if (results.length >= 4) {
                strategy.setX(Integer.parseInt(results[1]));
                strategy.setY(Integer.parseInt(results[2]));
                strategy.setCropSize(Integer.parseInt(results[3]));
              }
              onAvatarIdChanged(results[0], strategy.getEntityType() == EntityType.PERSON);
            }
          }
        });

    if (editButton != null) {
      editButton.addClickHandler(
          new ClickHandler() {
            public void onClick(final ClickEvent inArg0) {
              // Since the size of the image is required before we can correctly show the
              // resize dialog, this method determines the avatar url and sets image url.
              // The load event of that image being loaded will kick off the resize modal.
              AvatarUrlGenerator urlGenerator = new AvatarUrlGenerator(EntityType.PERSON);
              hiddenImage.setUrl(urlGenerator.getOriginalAvatarUrl(avatarId));
            }
          });
      hiddenImage.addLoadHandler(
          new LoadHandler() {
            public void onLoad(final LoadEvent inEvent) {
              imageCropDialog =
                  new ImageCropContent(
                      strategy,
                      processor,
                      avatarId,
                      new Command() {
                        public void execute() {
                          onAvatarIdChanged(
                              strategy.getImageId(), strategy.getEntityType() == EntityType.PERSON);
                        }
                      },
                      hiddenImage.getWidth() + "px",
                      hiddenImage.getHeight() + "px");

              Dialog dialog = new Dialog(imageCropDialog);
              dialog.showCentered();
            }
          });
    }

    if (strategy.getImageType().equals(ImageType.BANNER)) {
      onAvatarIdChanged(
          strategy.getImageId(),
          strategy.getId().equals(strategy.getImageEntityId()),
          true,
          strategy.getEntityType() == EntityType.PERSON);
    } else {
      onAvatarIdChanged(strategy.getImageId(), strategy.getEntityType() == EntityType.PERSON);
    }

    deleteButton.addClickHandler(
        new ClickHandler() {
          @SuppressWarnings("unchecked")
          public void onClick(final ClickEvent event) {
            if (new WidgetJSNIFacadeImpl()
                .confirm("Are you sure you want to delete your current photo?")) {
              strategy.getDeleteAction().delete(strategy.getDeleteParam());
            }
          }
        });

    Session.getInstance()
        .getEventBus()
        .addObserver(
            ClearUploadedImageEvent.class,
            new Observer<ClearUploadedImageEvent>() {
              public void update(final ClearUploadedImageEvent event) {
                if (event.getImageType().equals(strategy.getImageType())
                    && event.getEntityType().equals(strategy.getEntityType())) {
                  if (event.getImageType().equals(ImageType.BANNER)) {
                    onAvatarIdChanged(
                        event.getEntity().getBannerId(),
                        strategy.getId().equals(event.getEntity().getBannerEntityId()),
                        true,
                        strategy.getEntityType() == EntityType.PERSON);
                  } else {
                    onAvatarIdChanged(null, strategy.getEntityType() == EntityType.PERSON);
                  }
                }
              }
            });
  }
  /**
   * Constructor.
   *
   * @param accountId Unique ID of person to display.
   */
  public UserProfileBadgeWidget(final String accountId) {
    final FlowPanel widget = new FlowPanel();
    widget.addStyleName(StaticResourceBundle.INSTANCE.coreCss().eurekaConnectBadgeContainer());
    initWidget(widget);

    widget.addStyleName(StaticResourceBundle.INSTANCE.coreCss().eurekaConnectLoading());

    EventBus.getInstance()
        .addObserver(
            GotPersonalInformationResponseEvent.class,
            new Observer<GotPersonalInformationResponseEvent>() {
              public void update(final GotPersonalInformationResponseEvent event) {
                widget.removeStyleName(
                    StaticResourceBundle.INSTANCE.coreCss().eurekaConnectLoading());
                PersonModelView entity = event.getResponse();

                if (entity == null) {
                  final AvatarWidget blankAvatar = new AvatarWidget(EntityType.PERSON, Size.Normal);
                  blankAvatar.addStyleName(
                      StaticResourceBundle.INSTANCE.coreCss().eurekaConnectBadgeAvatar());

                  widget.add(blankAvatar);

                  final Label blankName = new Label(accountId);
                  blankName.addStyleName(
                      StaticResourceBundle.INSTANCE.coreCss().eurekaConnectBadgeName());

                  widget.add(blankName);
                } else {
                  AvatarLinkPanel linkPanel =
                      new AvatarLinkPanel(
                          EntityType.PERSON,
                          entity.getAccountId(),
                          entity.getAvatarId(),
                          Size.Normal,
                          false);
                  linkPanel.addStyleName(
                      StaticResourceBundle.INSTANCE.coreCss().eurekaConnectBadgeAvatar());

                  widget.add(linkPanel);

                  String linkUrl =
                      "/#"
                          + Session.getInstance()
                              .generateUrl(
                                  new CreateUrlRequest(Page.PEOPLE, entity.getAccountId()));

                  Anchor name = new Anchor(entity.getDisplayName(), linkUrl, "_BLANK");
                  name.addStyleName(
                      StaticResourceBundle.INSTANCE.coreCss().eurekaConnectBadgeName());

                  Label title = new Label(entity.getTitle());
                  title.addStyleName(
                      StaticResourceBundle.INSTANCE.coreCss().eurekaConnectBadgeTitle());

                  Label company = new Label(entity.getCompanyName());
                  company.addStyleName(
                      StaticResourceBundle.INSTANCE.coreCss().eurekaConnectBadgeCompany());

                  widget.add(name);
                  widget.add(title);
                  widget.add(company);
                }
              }
            });

    PersonalInformationModel.getInstance().fetch(accountId, false);
  }
  /**
   * Initialize page.
   *
   * @param inShowRecipients if recipients should be shown.
   * @param itemRenderer Renderer for activities.
   */
  public StreamPanel(
      final ShowRecipient inShowRecipients, final ItemRenderer<ActivityDTO> itemRenderer) {
    addStyleName(StaticResourceBundle.INSTANCE.coreCss().layoutContainer());

    stream = new StreamListPanel(itemRenderer);
    stream.addStyleName(StaticResourceBundle.INSTANCE.coreCss().stream());
    stream.setVisible(false);

    // @author cm325 need to expose id
    stream.getElement().setId("ym-expose-stream-panel-stream");

    shadowPanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().postToStreamContainer());
    shadowPanel.setVisible(false);

    searchBoxWidget = new StreamSearchBoxWidget();
    searchStatusWidget = new StreamSearchStatusWidget();

    lockedMessage.setVisible(false);
    error.setVisible(false);

    postContent.add(shadowPanel);

    titlePanel.addStyleName(StaticResourceBundle.INSTANCE.coreCss().streamTitlebar());
    streamTitleWidget = new StreamTitleWidget();
    titlePanel.add(streamTitleWidget);
    addGadgetWidget = new StreamAddAppWidget();
    titlePanel.add(addGadgetWidget);

    sortSearchRow.addStyleName(StaticResourceBundle.INSTANCE.coreCss().navpanel());
    sortSearchRow.add(sortPanel);
    sortSearchRow.add(feedLinkWidget);
    sortSearchRow.add(searchBoxWidget);

    // @author cm325 need to expose id
    sortSearchRow.getElement().setId("ym-expose-stream-panel-sort-search-row");

    this.add(postContent);
    this.add(titlePanel);
    this.add(searchStatusWidget);
    this.add(new UnseenActivityNotificationPanel());
    this.add(sortSearchRow);
    this.add(error);
    this.add(lockedMessage);
    this.add(stream);
    this.add(activityDetailPanel);

    stream.reinitialize();

    // ---- Wire up events ----
    final EventBus eventBus = Session.getInstance().getEventBus();

    eventBus.addObserver(
        UpdatedHistoryParametersEvent.class,
        new Observer<UpdatedHistoryParametersEvent>() {
          public void update(final UpdatedHistoryParametersEvent event) {
            checkHistory(event.getParameters());

            // Only process this once.
            eventBus.removeObserver(UpdatedHistoryParametersEvent.class, this);
          }
        },
        true);

    eventBus.addObserver(
        UpdatedHistoryParametersEvent.class,
        new Observer<UpdatedHistoryParametersEvent>() {
          public void update(final UpdatedHistoryParametersEvent event) {
            if (checkHistory(event.getParameters())) {
              eventBus.notifyObservers(StreamReinitializeRequestEvent.getEvent());
            }
          }
        });

    eventBus.addObserver(
        GotActivityResponseEvent.class,
        new Observer<GotActivityResponseEvent>() {
          public void update(final GotActivityResponseEvent event) {
            setSingleActivityMode();
            activityDetailPanel.clear();
            activityDetailPanel.add(new ActivityDetailPanel(event.getResponse(), inShowRecipients));
          }
        });

    eventBus.addObserver(
        StreamRequestMoreEvent.class,
        new Observer<StreamRequestMoreEvent>() {
          public void update(final StreamRequestMoreEvent arg1) {
            JSONObject jsonObj = StreamJsonRequestFactory.getJSONRequest(jsonQuery);
            jsonObj = StreamJsonRequestFactory.setMaxId(lastSeenId, jsonObj);

            // Must be sorted by date to request more.
            jsonObj = StreamJsonRequestFactory.setSort("date", jsonObj);

            if (!search.isEmpty()) {
              searchBoxWidget.setSearchTerm(search);
              searchStatusWidget.setSearchTerm(search);

              jsonObj = StreamJsonRequestFactory.setSearchTerm(search, jsonObj);
            }

            StreamModel.getInstance().fetch(jsonObj.toString(), false);
          }
        });

    eventBus.addObserver(
        GotStreamResponseEvent.class,
        new Observer<GotStreamResponseEvent>() {
          public void update(final GotStreamResponseEvent event) {
            PagedSet<ActivityDTO> activity = event.getStream();

            int numberOfActivities = activity.getPagedSet().size();
            if (numberOfActivities > 0) {
              lastSeenId = activity.getPagedSet().get(numberOfActivities - 1).getId();
            }

            MessageStreamUpdateEvent updateEvent = new MessageStreamUpdateEvent(activity);
            updateEvent.setMoreResults(activity.getTotal() > activity.getPagedSet().size());

            error.setText("");
            error.setVisible(false);
            eventBus.notifyObservers(updateEvent);
            stream.setVisible(true);
          }
        });

    eventBus.addObserver(
        StreamReinitializeRequestEvent.class,
        new Observer<StreamReinitializeRequestEvent>() {
          public void update(final StreamReinitializeRequestEvent event) {
            eventBus.notifyObservers(new StreamRequestEvent(streamName, jsonQuery, true));
          }
        });

    eventBus.addObserver(
        MessageStreamAppendEvent.class,
        new Observer<MessageStreamAppendEvent>() {
          public void update(final MessageStreamAppendEvent evt) {
            if ("date".equals(sortPanel.getSort())) {
              eventBus.notifyObservers(StreamReinitializeRequestEvent.getEvent());
            } else {
              sortPanel.updateSelected("date", true);
            }
          }
        });

    eventBus.addObserver(
        StreamRequestEvent.class,
        new Observer<StreamRequestEvent>() {
          public void update(final StreamRequestEvent event) {
            if (event.getForceReload() || !event.getJson().equals(jsonQuery)) {
              streamName = event.getStreamName();
              jsonQuery = event.getJson();
              if (activityId != 0L) {
                ActivityModel.getInstance().fetch(activityId, false);
              } else {
                setListMode();
                stream.reinitialize();

                String titleLinkUrl = null;
                String updatedJson = jsonQuery;
                JSONObject queryObject =
                    JSONParser.parse(updatedJson).isObject().get("query").isObject();

                // Only show cancel option if search is not part of the view.
                Boolean canChange = !queryObject.containsKey("keywords");

                if (queryObject.containsKey("keywords")) {
                  final String streamSearchText =
                      queryObject.get("keywords").isString().stringValue();

                  searchBoxWidget.setSearchTerm(streamSearchText);
                  searchStatusWidget.setSearchTerm(streamSearchText);

                  updatedJson =
                      StreamJsonRequestFactory.setSearchTerm(
                              streamSearchText,
                              StreamJsonRequestFactory.getJSONRequest(updatedJson))
                          .toString();
                } else if (!search.isEmpty()) {
                  searchBoxWidget.setSearchTerm(search);
                  searchStatusWidget.setSearchTerm(search);

                  updatedJson =
                      StreamJsonRequestFactory.setSearchTerm(
                              search, StreamJsonRequestFactory.getJSONRequest(updatedJson))
                          .toString();

                }
                // see if the stream belongs to a group and set up the stream title as a link
                else if (queryObject.containsKey("recipient")
                    && queryObject.get("recipient").isArray().size() == 1) {
                  JSONArray recipientArr = queryObject.get("recipient").isArray();
                  JSONObject recipientObj = recipientArr.get(0).isObject();

                  // only show the link if viewing a group stream on the activity page
                  if ("GROUP".equals(recipientObj.get("type").isString().stringValue())
                      && Session.getInstance().getUrlPage() == Page.ACTIVITY) {
                    String shortName = recipientObj.get("name").isString().stringValue();
                    titleLinkUrl =
                        Session.getInstance()
                            .generateUrl(new CreateUrlRequest(Page.GROUPS, shortName));
                  }
                  searchBoxWidget.onSearchCanceled();
                  searchStatusWidget.onSearchCanceled();
                } else {
                  searchBoxWidget.onSearchCanceled();
                  searchStatusWidget.onSearchCanceled();
                }

                sort = sortPanel.getSort();

                updatedJson =
                    StreamJsonRequestFactory.setSort(
                            sort, StreamJsonRequestFactory.getJSONRequest(updatedJson))
                        .toString();

                streamTitleWidget.setStreamTitle(streamName, titleLinkUrl);
                addGadgetWidget.setStreamTitle(streamName);
                searchBoxWidget.setCanChange(canChange);
                searchStatusWidget.setCanChange(canChange);

                StreamModel.getInstance().fetch(updatedJson, false);
              }
            }
          }
        });

    eventBus.addObserver(
        StreamSearchBeginEvent.class,
        new Observer<StreamSearchBeginEvent>() {
          public void update(final StreamSearchBeginEvent event) {
            eventBus.notifyObservers(
                new UpdateHistoryEvent(
                    new CreateUrlRequest("search", event.getSearchText(), false)));
          }
        });

    eventBus.addObserver(
        DeletedActivityResponseEvent.class,
        new Observer<DeletedActivityResponseEvent>() {
          public void update(final DeletedActivityResponseEvent ev) {
            eventBus.notifyObservers(
                new ShowNotificationEvent(new Notification("Activity has been deleted")));
          }
        });
  }