@Override public String toString() { return "WaveletBasedConversationBlip(id = " + manifestBlip.getId() + ")"; }
static WaveletBasedConversationBlip create(ObservableManifestBlip manifestBlip, Blip backingBlip, WaveletBasedConversationThread thread, ComponentHelper helper) { WaveletBasedConversationBlip blip = new WaveletBasedConversationBlip(manifestBlip, backingBlip, thread, helper); for (ObservableManifestThread reply : manifestBlip.getReplies()) { blip.adaptThread(reply); } manifestBlip.addListener(blip); helper.getWaveletEventSource().addListener(blip.waveletListener); return blip; }
/** * Invalidates this blip. It may no longer be accessed. */ void invalidate() { checkIsUsable(); manifestBlip.removeListener(this); isUsable = false; }
/** * Very basic test to see that we can create the object with a document and use it. */ public void testSimpleUsageWithDocument() { ObservableManifestBlip blip = buildBlipElement(ConversationTestUtils.createManifestDocument(), "b+1"); assertEquals("b+1", blip.getId()); ManifestThread reply = blip.appendReply("t1", false); assertNotNull(reply); assertEquals("t1", reply.getId()); }
@Override public WaveletBasedConversationThread addReplyThread() { checkIsUsable(); String id = helper.createThreadId(); manifestBlip.appendReply(id, false); return replies.get(id); }
verify(blip).detachListeners();
/** * Deletes a thread from this blip, deleting that thread's blips. */ void deleteThread(WaveletBasedConversationThread threadToDelete) { threadToDelete.deleteBlips(); manifestBlip.removeReply(threadToDelete.getManifestThread()); clearInlineReplyAnchor(threadToDelete.getId()); }
/** * {@inheritDoc} * * The 'history of appends' corresponds to the manifest order of replies. */ @Override public Iterable<WaveletBasedConversationThread> getReplyThreads() { final Iterable<? extends ObservableManifestThread> manifestBlips = manifestBlip.getReplies(); return new Iterable<WaveletBasedConversationThread>() { @Override public Iterator<WaveletBasedConversationThread> iterator() { return WrapperIterator.create(manifestBlips.iterator(), replies); } }; }
/** * Very basic test to see that we can create the object with a document and use it. */ public void testSimpleUsageWithDocument() { ObservableManifestBlip blip = buildBlipElement(ConversationTestUtils.createManifestDocument(), "b+1"); assertEquals("b+1", blip.getId()); ManifestThread reply = blip.appendReply("t1", false); assertNotNull(reply); assertEquals("t1", reply.getId()); }
@Override public WaveletBasedConversationThread addReplyThread(final int location) { checkIsUsable(); final String threadId = helper.createThreadId(); createInlineReplyAnchor(threadId, location); manifestBlip.appendReply(threadId, true); return replies.get(threadId); }
verify(blip).detachListeners();
/** * Deletes all threads from this blip. * * @see WaveletBasedConversationBlip#deleteThread(WaveletBasedConversationThread) */ void deleteThreads() { // deleteThread() equivalent is inline here so we can do only one // document traversal to remove inline reply anchors. List<WaveletBasedConversationThread> threads = CollectionUtils.newArrayList(getReplyThreads()); for (WaveletBasedConversationThread threadToDelete : threads) { threadToDelete.deleteBlips(); manifestBlip.removeReply(threadToDelete.getManifestThread()); } clearAllInlineReplyAnchors(); }
@Override public String getId() { return manifestBlip.getId(); }
@Override public void onBlipRemoved(ObservableManifestBlip blip) { WaveletBasedConversationBlip blipToRemove = blips.get(blip.getId()); if (blipToRemove != null) { forgetBlip(blipToRemove); } }
/** * Creates a conversation blip backed by a manifest blip and inserts it in * {@code blips}. */ private WaveletBasedConversationBlip adaptBlip(ObservableManifestBlip manifestBlip, Blip blip) { WaveletBasedConversationBlip convBlip = WaveletBasedConversationBlip.create(manifestBlip, blip, this, helper); blips.put(manifestBlip.getId(), convBlip); return convBlip; }
private WaveletBasedConversationBlip(ObservableManifestBlip manifestBlip, Blip blip, WaveletBasedConversationThread thread, ComponentHelper helper) { Preconditions.checkNotNull(manifestBlip, "WaveletBasedConversationBlip received null manifest blip"); if (blip == null) { Preconditions.nullPointer("WaveletBasedConversationBlip " + manifestBlip.getId() + " received null blip"); } this.manifestBlip = manifestBlip; this.blip = blip; this.helper = helper; this.parentThread = thread; }
@Override public void onBlipAdded(ObservableManifestBlip manifestBlip) { Blip blip = helper.getBlip(manifestBlip.getId()); if (blip != null) { // Note that this means the blip will be ignored if it doesn't exist in // the wavelet when the manifest entry is added. WaveletBasedConversationBlip convBlip = adaptBlip(manifestBlip, blip); triggerOnBlipAdded(convBlip); } }
@Override public WaveletBasedConversationBlip getFirstBlip() { WaveletBasedConversationBlip result = null; if (!blips.isEmpty()) { ObservableManifestBlip manifestBlip = manifestThread.getBlip(0); result = blips.get(manifestBlip.getId()); if (result == null) { // Very uncommon case: the first blip in the manifest doesn't have a // corresponding blip object. Fall back to iterating since iteration // handles this correctly. for (WaveletBasedConversationBlip firstBlip : getBlips()) { result = firstBlip; break; } } } return result; }
/** * Creates a new conversation thread. * * @param manifestThread data for the thread * @param parentBlip blip to which this thread is a reply (null for root) * @param helper provides conversation components */ static WaveletBasedConversationThread create(ObservableManifestThread manifestThread, WaveletBasedConversationBlip parentBlip, WaveletBasedConversation.ComponentHelper helper) { WaveletBasedConversationThread thread = new WaveletBasedConversationThread(manifestThread, parentBlip, helper); for (ObservableManifestBlip manifestBlip : manifestThread.getBlips()) { Blip blip = helper.getBlip(manifestBlip.getId()); if (blip != null) { thread.adaptBlip(manifestBlip, blip); } } manifestThread.addListener(thread); return thread; }