/** * 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; }
/** * 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; }
/** * Select and reveal the given outline item, based on its offset and length. * * @param item * the item, must not be null */ public void selectAndReveal(OutlineItem item) { selectAndReveal(item.getOffset(), item.getLength()); } }
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); } } }
public void selectAndReveal(OutlineItem item) { selectAndReveal(item.getOffset(), item.getLength()); if (isShowingPreview()) { // scroll preview to the selected item. revealInBrowser(item); } }
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(); insertLocation = children.get(0).getOffset();
public boolean show(ShowInContext context) { ISelection selection = context.getSelection(); if (selection instanceof IStructuredSelection) { for (Object element : ((IStructuredSelection) selection).toArray()) { if (element instanceof OutlineItem) { OutlineItem item = (OutlineItem) element; viewer.setSelection(new TextSelection(item.getOffset(), item.getLength()), true); return true; } } } else if (selection instanceof ITextSelection) { viewer.setSelection(selection, true); return true; } return false; }