Package com.google.livingstories.client

Examples of com.google.livingstories.client.BaseContentItem


          @Override
          public void onSuccess(List<BaseContentItem> result) {
            // Put result on loadedAContentItemsMap in reverse order. Can't use useful
            // Google Collections stuff for it, so:
            for (int i = result.size() - 1; i >= 0; i--) {
              BaseContentItem contentItem = result.get(i);
              loadedContentItemsMap.put(contentItem.getId(), contentItem);
            }
            refresh();
          }
        });
  }
View Full Code Here


  }
 
  public void addContentItems(List<BaseContentItem> contentItems) {
    // Add to loadedContentItemsMap in reverse order to how the items were specified.
    for (int i = contentItems.size() - 1; i >= 0; i--) {
      BaseContentItem contentItem = contentItems.get(i);
      loadedContentItemsMap.put(contentItem.getId(), contentItem);
    }
    itemList.refresh();
  }
View Full Code Here

        location = new Location(latitude, longitude, locationDescriptionTextArea.getText());
      }
     
      Set<Long> currentContributorIds = new HashSet<Long>(currentContributorIdsToNamesMap.keySet());

      BaseContentItem contentItem;
      switch (contentItemType) {
        case EVENT:
          Date startDate = getStartDateTime();
          Date endDate = getEndDateTime();
          if (startDate.equals(endDate)) {
            // actually, a null end-date is what we want
            endDate = null;
          }
         
          String update = updateEditor.getText().trim();
          if (update.isEmpty()) {
            showInputError("Event update cannot be empty.");
            return;
          }
          contentItem = new EventContentItem(contentItemId, creationDate, currentContributorIds,
              importance, livingStoryId, startDate, endDate, update, summaryEditor.getContent(),
              content);
          break;
        case PLAYER:
          if (livingStoryId == null) {
            String nameString = nameTextBox.getText();
            if (nameString.isEmpty()) {
              showInputError("Player name cannot be empty.");
              return;
            }
            List<String> aliasList = new ArrayList<String>();
            for (String alias : aliasesTextBox.getText().split(",")) {
              String trimmed = alias.trim();
              if (!trimmed.isEmpty()) {
                aliasList.add(trimmed);
              }
            }
            BaseContentItem photoContentItem = photoSelector.getSelection();
            if (photoContentItem != null
                && (photoContentItem.getContentItemType() != ContentItemType.ASSET
                || ((AssetContentItem) photoContentItem).getAssetType() != AssetType.IMAGE)) {
              showInputError("Player photo must be an image");
              return;
            }
            contentItem = new PlayerContentItem(contentItemId, creationDate, currentContributorIds,
View Full Code Here

            new SingleContentItemSelectionPanel();
        contentPanel.add(selectionPanel);
        contentPanel.add(createButtonPanel(popup, new ContentItemSelectionHandler() {
          @Override
          public void onSelect() {
            BaseContentItem contentItem = selectionPanel.getSelection();
            String headline = null;
            if (contentItem.getContentItemType() == ContentItemType.EVENT) {
              headline = ((EventContentItem) contentItem).getEventUpdate();
            } else if (contentItem.getContentItemType() == ContentItemType.NARRATIVE) {
              headline = ((NarrativeContentItem) contentItem).getHeadline();
            } else {
              Window.alert("You must link to an event or top level narrative!");
              contentItem = null;
            }
            if (contentItem != null && contentItem.displayTopLevel()) {
              richTextUtil.createJavascriptLink(richText.getElement(),
                  "goToContentItem(" + contentItem.getId() + ")",
                  "Jump to: " + headline.replace("\"", "'"));
            }
          }
        }));
        popup.add(contentPanel);
        popup.showRelativeTo(insertContentItem);
      } else if (sender == insertContentItem) {
        PopupPanel popup = new PopupPanel();
        FlowPanel contentPanel = new FlowPanel();
        final SingleContentItemSelectionPanel selectionPanel =
            new SingleContentItemSelectionPanel();
        contentPanel.add(selectionPanel);
        contentPanel.add(createButtonPanel(popup, new ContentItemSelectionHandler() {
          @Override
          public void onSelect() {
            BaseContentItem contentItem = selectionPanel.getSelection();
            if (contentItem != null) {
              richTextUtil.createJavascriptLink(richText.getElement(),
                  "showContentItemPopup(" + contentItem.getId() + ", this)");
            }
          }
        }));
        popup.add(contentPanel);
        popup.showRelativeTo(insertContentItem);
      } else if (sender == insertSource) {
        PopupPanel popup = new PopupPanel();
        FlowPanel contentPanel = new FlowPanel();
        final TextBox descriptionBox = new TextBox();
        HorizontalPanel descriptionPanel = new HorizontalPanel();
        descriptionPanel.add(new Label("Source description:"));
        descriptionPanel.add(descriptionBox);
        contentPanel.add(descriptionPanel);
        final SingleContentItemSelectionPanel selectionPanel =
            new SingleContentItemSelectionPanel();
        contentPanel.add(selectionPanel);
        contentPanel.add(createButtonPanel(popup, new ContentItemSelectionHandler() {
          @Override
          public void onSelect() {
            String description = descriptionBox.getText();
            BaseContentItem contentItem = selectionPanel.getSelection();
            if (!description.isEmpty() || contentItem != null) {
              String selectedText = richTextUtil.getSelection(richText.getElement());
              richTextUtil.insertHTML(richText.getElement(), selectedText + " " +
                  new SourceLink(description, contentItem == null ? -1
                      : contentItem.getId()).getOuterHTML());
            }
          }
        }));
        popup.add(contentPanel);
        popup.showRelativeTo(insertSource);
      } else if (sender == insertLightbox) {
        PopupPanel popup = new PopupPanel();
        FlowPanel contentPanel = new FlowPanel();
        final SingleContentItemSelectionPanel selectionPanel =
            new SingleContentItemSelectionPanel();
        contentPanel.add(selectionPanel);
        contentPanel.add(createButtonPanel(popup, new ContentItemSelectionHandler() {
          @Override
          public void onSelect() {
            BaseContentItem contentItem = selectionPanel.getSelection();
            if (contentItem != null) {
              richTextUtil.createJavascriptLink(richText.getElement(),
                  "showLightboxForContentItem('" + contentItem.getTypeString()
                  + "', " + contentItem.getId() + ")");
            }
          }
        }));
        popup.add(contentPanel);
        popup.showRelativeTo(insertLightbox);
View Full Code Here

  @Override
  public synchronized BaseContentItem retrieveById(Long id, boolean populateLinkedEntities) {
    PersistenceManager pm = PMF.get().getPersistenceManager();
   
    try {
      BaseContentItem content = pm.getObjectById(BaseContentEntity.class, id).toClientObject();
      if (populateLinkedEntities) {
        content.setLinkedContentItems(retrieveByIds(content.getLinkedContentItemIds()));
      }
      return content;
    } catch (JDOObjectNotFoundException e) {
      return null;
    } finally {
View Full Code Here

      @SuppressWarnings("unchecked")
      List<BaseContentEntity> contentEntities = (List<BaseContentEntity>) query.execute(afterDate,
          beforeDate);
      List<BaseContentItem> contentList = new ArrayList<BaseContentItem>();
      for (BaseContentEntity contentEntity : contentEntities) {
        BaseContentItem content = contentEntity.toClientObject();
        contentList.add(content);
      }
      return contentList;
    } finally {
      query.closeAll();
View Full Code Here

    // We pass suggested new linked content items back to the client by adding their ids to the
    // client object before returning it. It's the client's responsibility to check the linked
    // content item ids it passed in with those that came back, and to present appropriate
    // UI for processing the suggestions. Note that we shouldn't add the suggestions directly
    // to contentEntity! This will persist them to the datastore prematurely.
    BaseContentItem ret = contentEntity.toClientObject();
   
    if (newLinkedContentItemSuggestions != null) {
      ret.addAllLinkedContentItemIds(newLinkedContentItemSuggestions);
    }
   
    return ret;
  }
View Full Code Here

      return result;
    }
   
    FilterSpec localFilterSpec = new FilterSpec(filterSpec);
   
    BaseContentItem focusedContentItem = null;
    if (focusedContentItemId != null) {
      focusedContentItem = getContentItem(focusedContentItemId, false);
      if (focusedContentItem != null) {
        if (adjustFilterSpecForContentItem(localFilterSpec, focusedContentItem)) {
          // If we had to adjust the filter spec to accommodate the focused content item,
          // we'll be switching filter views, so we want to clear the start date
          // and reload the list from the beginning.
          cutoff = null;
        }
      }
    }
   
    // Some preliminaries. Note that the present implementation just filters all content items for
    // a story, which could be a bit expensive if there's a cache miss. By and large, though,
    // we'd expect a lot more cache hits than cache misses, unlike the case with, say,
    // a twitter "following" feed, which is more likely to be unique to that user.
    List<BaseContentItem> allContentItems = getContentItemsForLivingStory(livingStoryId, true);
   
    Map<Long, BaseContentItem> idToContentItemMap = Maps.newHashMap();
    List<BaseContentItem> relevantContentItems = Lists.newArrayList();
    for (BaseContentItem contentItem : allContentItems) {
      idToContentItemMap.put(contentItem.getId(), contentItem);
     
      Date sortKey = contentItem.getDateSortKey();
      boolean matchesStartDate = (cutoff == null) ||
          (localFilterSpec.oldestFirst ? !sortKey.before(cutoff) : !sortKey.after(cutoff));

      if (matchesStartDate && localFilterSpec.doesContentItemMatch(contentItem)) {
        relevantContentItems.add(contentItem);
      }
    }
    sortContentItemList(relevantContentItems, localFilterSpec);

    // Need to get the focused content item from the map instead of using the object directly.
    // This is because we use indexOf() to find the location of the focused content item in the
    // list and the original contentItem isn't the same object instance.
    List<BaseContentItem> coreContentItems = getSublist(relevantContentItems,
        focusedContentItem == null ? null : idToContentItemMap.get(focusedContentItemId), cutoff);
    Set<Long> linkedContentItemIds = Sets.newHashSet();
   
    for (BaseContentItem contentItem : coreContentItems) {
      if (contentItem.displayTopLevel()) {
        // If a content item isn't a top-level display content item, we can get away without
        // returning its linked content items.
        linkedContentItemIds.addAll(contentItem.getLinkedContentItemIds());
      }
    }

    Set<BaseContentItem> linkedContentItems = Sets.newHashSet();
    for (Long id : linkedContentItemIds) {
      BaseContentItem linkedContentItem = idToContentItemMap.get(id);
      if (linkedContentItem == null) {
        System.err.println("Linked content item with id " + id + " is not found.");
      } else {
        linkedContentItems.add(linkedContentItem);
        // For linked narratives, we want to get their own linked content items as well
        if (linkedContentItem.getContentItemType() == ContentItemType.NARRATIVE) {
          for (Long linkedToLinkedContentItemId : linkedContentItem.getLinkedContentItemIds()) {
            BaseContentItem linkedToLinkedContentItem =
                idToContentItemMap.get(linkedToLinkedContentItemId);
            if (linkedToLinkedContentItem != null) {
              linkedContentItems.add(linkedToLinkedContentItem);
            }
          }
View Full Code Here

  @Override
  public synchronized BaseContentItem getContentItem(Long id, boolean getLinkedContentItems) {
    PersistenceManager pm = PMF.get().getPersistenceManager();
   
    try {
      BaseContentItem contentItem = pm.getObjectById(BaseContentEntity.class, id).toClientObject();
      if (getLinkedContentItems) {
        contentItem.setLinkedContentItems(getContentItems(contentItem.getLinkedContentItemIds()));
      }
      return contentItem;
    } catch (JDOObjectNotFoundException e) {
      return null;
    } finally {
View Full Code Here

     
      @SuppressWarnings("unchecked")
      List<BaseContentEntity> contentEntities =
          (List<BaseContentEntity>) query.execute(contentItemId);
      for (BaseContentEntity contentEntity : contentEntities) {
        BaseContentItem contentItem = contentEntity.toClientObject();
        if (cutoff == null || !contentItem.getDateSortKey().after(cutoff)) {
          relevantContentItems.add(contentItem);
        }
      }
     
      // sort and put a window on the list, get the next date in the sequence
View Full Code Here

TOP

Related Classes of com.google.livingstories.client.BaseContentItem

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.