* @param composite
* @return
*/
private Composite createRegionTabContents(SashForm sashForm) {
ISelection sel = fTextEditor.getSelectionProvider().getSelection();
final ITextSelection textSelection = (ITextSelection) sel;
final List documentRegions = new ArrayList();
if (fDocument instanceof IStructuredDocument) {
IStructuredDocument structuredDocument = (IStructuredDocument) fDocument;
int pos = textSelection.getOffset();
int end = textSelection.getOffset() + textSelection.getLength();
IStructuredDocumentRegion docRegion = structuredDocument.getRegionAtCharacterOffset(pos);
IStructuredDocumentRegion endRegion = structuredDocument.getRegionAtCharacterOffset(end);
if (pos < end) {
while (docRegion != endRegion) {
documentRegions.add(docRegion);
docRegion = docRegion.getNext();
}
}
documentRegions.add(docRegion);
}
final TreeViewer tree = new TreeViewer(sashForm, SWT.V_SCROLL | SWT.H_SCROLL);
final String START = SSEUIMessages.OffsetStatusLineContributionItem_15; //$NON-NLS-1$
final String LENGTH = SSEUIMessages.OffsetStatusLineContributionItem_16; //$NON-NLS-1$
final String TEXTLENGTH = SSEUIMessages.OffsetStatusLineContributionItem_17; //$NON-NLS-1$
final String CONTEXT = SSEUIMessages.OffsetStatusLineContributionItem_18; //$NON-NLS-1$
tree.setContentProvider(new ITreeContentProvider() {
public void dispose() {
}
public Object[] getChildren(Object parentElement) {
List children = new ArrayList(0);
if (parentElement instanceof ITextSelection) {
children.addAll(documentRegions);
}
if (parentElement instanceof ITextRegionCollection) {
children.add(((ITextRegionCollection) parentElement).getRegions().toArray());
}
if (parentElement instanceof ITextRegion) {
children.add(new KeyValuePair(CONTEXT, ((ITextRegion) parentElement).getType()));
children.add(new KeyValuePair(START, Integer.toString(((ITextRegion) parentElement).getStart())));
children.add(new KeyValuePair(TEXTLENGTH, Integer.toString(((ITextRegion) parentElement).getTextLength())));
children.add(new KeyValuePair(LENGTH, Integer.toString(((ITextRegion) parentElement).getLength())));
}
if (parentElement instanceof ITextRegionList) {
children.add(Arrays.asList(((ITextRegionList) parentElement).toArray()));
}
if (parentElement instanceof Collection) {
children.addAll((Collection) parentElement);
}
if (parentElement instanceof Object[]) {
children.addAll(Arrays.asList((Object[]) parentElement));
}
return children.toArray();
}
public Object[] getElements(Object inputElement) {
return documentRegions.toArray();
}
public Object getParent(Object element) {
if (element instanceof IStructuredDocumentRegion)
return ((IStructuredDocumentRegion) element).getParentDocument();
if (element instanceof ITextRegionContainer) {
return ((ITextRegionContainer) element).getParent();
}
return fDocument;
}
public boolean hasChildren(Object element) {
return !(element instanceof KeyValuePair);
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
});
tree.setLabelProvider(new LabelProvider() {
public String getText(Object element) {
if (element instanceof KeyValuePair)
return ((KeyValuePair) element).fKey.toString().toLowerCase() + ": " + ((KeyValuePair) element).fValue; //$NON-NLS-1$
if (element instanceof IStructuredDocumentRegion) {
IStructuredDocumentRegion documentRegion = (IStructuredDocumentRegion) element;
int packageNameLength = documentRegion.getClass().getPackage().getName().length();
if (packageNameLength > 0)
packageNameLength++;
String name = documentRegion.getClass().getName().substring(packageNameLength);
String text = "[" + documentRegion.getStartOffset() + "-" + documentRegion.getEndOffset() + "] " + name + "@" + element.hashCode() + " " + documentRegion.getType(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
return text;
}
if (element instanceof ITextRegion) {
ITextRegion textRegion = (ITextRegion) element;
int packageNameLength = textRegion.getClass().getPackage().getName().length();
if (packageNameLength > 0)
packageNameLength++;
String name = textRegion.getClass().getName().substring(packageNameLength);
String text = "[" + textRegion.getStart() + "-" + textRegion.getEnd() + "] " + name + "@" + element.hashCode() + " " + textRegion.getType(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
return text;
}
return super.getText(element);
}
});
tree.setInput(fDocument);
final Text displayText = new Text(sashForm, SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY | SWT.BORDER);
displayText.setBackground(sashForm.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
tree.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
if (event.getSelection() instanceof IStructuredSelection) {
Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
if (o instanceof KeyValuePair)
displayText.setText(((KeyValuePair) o).fValue.toString());
else if (o instanceof ITextSelection) {
ITextSelection text = (ITextSelection) o;
try {
displayText.setText(fDocument.get(text.getOffset(), text.getLength()));
}
catch (BadLocationException e) {
displayText.setText(""); //$NON-NLS-1$
}
}