/** * get the length of the section, which is the length of the heading text plus the length of any following content * up to the next peer-leveled heading or the parent's following sibling. * * @see #getLength() */ public int getSectionLength() { if (parent == null) { return length; } List<OutlineItem> siblings = getParent().getChildren(); int index = siblings.indexOf(this); if (index < (siblings.size() - 1)) { return siblings.get(index + 1).getOffset() - getOffset(); } int parentRelativeOffset = getOffset() - parent.getOffset(); return parent.getSectionLength() - parentRelativeOffset; }
public String getLabel(Object o) { if (o instanceof OutlineItem) { OutlineItem item = (OutlineItem) o; // TODO: bug 260447 remove text prefix when icons become available if (item.getKind() == null) { return item.getLabel(); } else { return item.getKind() + ". " + item.getLabel(); //$NON-NLS-1$ } } return null; }
private OutlineItem computeRoot(OutlineItem item) { while (!item.isRootItem()) { item = item.getParent(); } return item; }
private void emitToc(OutlineItem item) { if (item.getChildren().isEmpty()) { return; } if ((item.getLevel() + 1) > maxLevel) { return; } Attributes nullAttributes = new Attributes(); builder.beginBlock(BlockType.NUMERIC_LIST, new Attributes(null, null, "list-style: " + style + ";", null)); //$NON-NLS-1$ //$NON-NLS-2$ for (OutlineItem child : item.getChildren()) { builder.beginBlock(BlockType.LIST_ITEM, nullAttributes); builder.link('#' + child.getId(), child.getLabel()); emitToc(child); builder.endBlock(); } builder.endBlock(); }
private void emitToc(XmlStreamWriter writer, List<OutlineItem> children) { for (OutlineItem item : children) { writer.writeStartElement("topic"); //$NON-NLS-1$ String file = computeFile(item); file = adjustForPrefix(file); String suffix = ""; //$NON-NLS-1$ // bug 260065: only append document anchor name if this is not the first item in the file. OutlineItem previous = item.getPrevious(); if (previous != null && previous.getParent() != null) { String fileOfPrevious = computeFile(previous); fileOfPrevious = adjustForPrefix(fileOfPrevious); if (file.equals(fileOfPrevious)) { suffix = "#" + item.getId(); //$NON-NLS-1$ } } writer.writeAttribute("href", file + suffix); //$NON-NLS-1$ writer.writeAttribute("label", item.getLabel()); //$NON-NLS-1$ if (!item.getChildren().isEmpty()) { emitToc(writer, item.getChildren()); } writer.writeEndElement(); // topic } }
private void emitToc(OutlineItem item) { if (item.getChildren().isEmpty()) { return; } Attributes nullAttributes = new Attributes(); builder.beginBlock(BlockType.NUMERIC_LIST, new Attributes()); for (OutlineItem child : item.getChildren()) { builder.beginBlock(BlockType.LIST_ITEM, nullAttributes); builder.link('#' + child.getId(), child.getLabel()); emitToc(child); builder.endBlock(); } builder.endBlock(); }
private void createProjectionAnnotations(List<Annotation> newProjectionAnnotations, Map<HeadingProjectionAnnotation, Position> annotationToPosition, List<OutlineItem> children, int endOffset) { final int size = children.size(); final int lastIndex = size - 1; for (int x = 0; x < size; ++x) { OutlineItem child = children.get(x); if (child.getId() == null || child.getId().length() == 0) { continue; } int offset = child.getOffset(); int end; if (x == lastIndex) { end = endOffset; } else { end = children.get(x + 1).getOffset(); } int length = end - offset; if (length > 0) { HeadingProjectionAnnotation annotation = new HeadingProjectionAnnotation(child.getId()); Position position = new Position(offset, length); newProjectionAnnotations.add(annotation); annotationToPosition.put(annotation, position); } if (!child.getChildren().isEmpty()) { createProjectionAnnotations(newProjectionAnnotations, annotationToPosition, child.getChildren(), end); } } }
if (previousItem.contains(item)) { items.remove(x); --x; break; } else if (item.contains(previousItem)) { items.remove(y); --x; for (int x = 0; x < items.size(); ++x) { OutlineItem item = items.get(x); sections[x] = new Section(item.getOffset(), item.getSectionLength()); int insertLocation = target.getOffset(); if (location == InsertLocation.WITHIN) { List<OutlineItem> children = target.getChildren(); if (children.isEmpty()) { insertLocation += target.getLength(); insertLocation = children.get(0).getOffset(); insertLocation += target.getSectionLength();
public Object[] getChildren(Object o) { if (o instanceof OutlineItem) { OutlineItem item = (OutlineItem) o; if (!item.getChildren().isEmpty()) { return item.getChildren().toArray(); } } return NO_CHILDREN; }
switch (topicStrategy) { case FIRST: if (!outline.getChildren().isEmpty()) { builder.setTopicBreakLevel(outline.getChildren().get(0).getLevel()); } else { builder.setTopicBreakLevel(1);
public void accept(Visitor visitor) { if (visitor.visit(this)) { for (OutlineItem item : getChildren()) { item.accept(visitor); } } }
/** * @since 1.1 */ @Override public String toString() { return "OutlineItem(" + calculatePositionKey() + "/" + getId() + "/" + System.identityHashCode(this) + ")"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ } }
while (level <= currentItem.getLevel()) { currentItem = currentItem.getParent(); currentItem.setTooltip(fullLabelText); currentItem.setKind(kind); } else { registerId(attributes.getId());
/** * Indicate if this outline item contains the given outline item. The computation uses outline item offsets (the * {@link #getOffset() offset} and {@link #getSectionLength() section length}. * * @return true if and only if the offsets of the provided item lie within the offsets of this outline item. */ public boolean contains(OutlineItem item) { if (item == this || isRootItem()) { return true; } if (getOffset() <= item.getOffset()) { int end = getOffset() + getSectionLength(); int itemEnd = item.getOffset() + item.getSectionLength(); if (end >= itemEnd) { return true; } } return false; }
public PreviewOutlineItemAction(MarkupEditor editor, OutlineItem outlineItem) { this.editor = editor; this.outlineItem = outlineItem; setText(NLS.bind(Messages.PreviewOutlineItemAction_label, outlineItem.getLabel())); }
private void updateOutline(int contentGeneration, OutlineItem rootItem) { if (getSourceViewer().getTextWidget().isDisposed()) { return; } synchronized (this) { if (contentGeneration != documentGeneration) { return; } } outlineDirty = false; outlineModel.clear(); outlineModel.moveChildren(rootItem); IFile file = (IFile) getAdapter(IFile.class); outlineModel.setResourcePath(file == null ? null : file.getFullPath().toString()); firePropertyChange(PROP_OUTLINE); }