public Image getColumnImage(Object element, int columnIndex) {
return null;
}
public String getColumnText(Object element, int columnIndex) {
ITypedRegion partition = (ITypedRegion) element;
String text = null;
switch (columnIndex) {
case 0 :
text = Integer.toString(partition.getOffset());
break;
case 1 :
text = Integer.toString(partition.getLength());
break;
case 2 :
text = partition.getType();
break;
}
if (text == null)
text = ""; //$NON-NLS-1$
return text;
}
public boolean isLabelProperty(Object element, String property) {
return false;
}
public void removeListener(ILabelProviderListener listener) {
}
});
TableLayout tlayout = new TableLayout();
CellEditor[] cellEditors = new CellEditor[columns.length];
int columnWidths[] = new int[]{Display.getCurrent().getBounds().width / 14, Display.getCurrent().getBounds().width / 14, Display.getCurrent().getBounds().width / 5};
for (int i = 0; i < columns.length; i++) {
tlayout.addColumnData(new ColumnWeightData(1));
TableColumn tc = new TableColumn(fPartitionTable.getTable(), SWT.NONE);
tc.setText(columns[i]);
tc.setResizable(true);
tc.setWidth(columnWidths[i]);
}
fPartitionTable.setCellEditors(cellEditors);
fPartitionTable.setColumnProperties(columns);
final String[] partitionings = (fDocument instanceof IDocumentExtension3) ? ((IDocumentExtension3) fDocument).getPartitionings() : new String[]{IDocumentExtension3.DEFAULT_PARTITIONING};
partitioningCombo.setItems(partitionings);
partitioningCombo.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
ISelection sel = fTextEditor.getSelectionProvider().getSelection();
ITextSelection textSelection = (ITextSelection) sel;
try {
String partitionerText = fDocument instanceof IDocumentExtension3 ? ((IDocumentExtension3) fDocument).getDocumentPartitioner(partitioningCombo.getItem(partitioningCombo.getSelectionIndex())).toString() : ("" + fDocument.getDocumentPartitioner()); //$NON-NLS-1$
partitionerInstanceLabel.setText(SSEUIMessages.OffsetStatusLineContributionItem_13 + partitionerText); //$NON-NLS-1$
fPartitionTable.setInput(TextUtilities.computePartitioning(fDocument, partitioningCombo.getItem(partitioningCombo.getSelectionIndex()), textSelection.getOffset(), textSelection.getLength(), true));
}
catch (BadLocationException e1) {
fPartitionTable.setInput(new ITypedRegion[0]);
}
}
});
try {
if (partitionings.length > 0) {
String selectedPartitioning = partitioningCombo.getItem(0);
if (Utilities.contains(partitionings, IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING)) {
selectedPartitioning = IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING;
for (int i = 0; i < partitionings.length; i++) {
if (partitionings[i].equals(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING)) {
partitioningCombo.select(i);
}
}
}
else {
partitioningCombo.select(0);
}
ISelection sel = fTextEditor.getSelectionProvider().getSelection();
ITextSelection textSelection = (ITextSelection) sel;
ITypedRegion[] partitions = TextUtilities.computePartitioning(fDocument, selectedPartitioning, textSelection.getOffset(), textSelection.getLength(), true);
fPartitionTable.setInput(partitions);
String partitionerText = fDocument instanceof IDocumentExtension3 ? ((IDocumentExtension3) fDocument).getDocumentPartitioner(partitioningCombo.getItem(partitioningCombo.getSelectionIndex())).toString() : ("" + fDocument.getDocumentPartitioner()); //$NON-NLS-1$
partitionerInstanceLabel.setText(SSEUIMessages.OffsetStatusLineContributionItem_13 + partitionerText); //$NON-NLS-1$
}
else {
ISelection sel = fTextEditor.getSelectionProvider().getSelection();
ITextSelection textSelection = (ITextSelection) sel;
fPartitionTable.setInput(fDocument.computePartitioning(textSelection.getOffset(), textSelection.getLength()));
}
}
catch (BadLocationException e1) {
fPartitionTable.setInput(new ITypedRegion[0]);
}
partitioningCombo.setFocus();
final StyledText text = new StyledText(sash, SWT.MULTI | SWT.READ_ONLY);
fPartitionTable.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
if (event.getSelection() instanceof IStructuredSelection) {
IRegion partition = (IRegion) ((IStructuredSelection) event.getSelection()).getFirstElement();
IDocument document = fTextEditor.getDocumentProvider().getDocument(fTextEditor.getEditorInput());
String source;
try {
source = document.get(partition.getOffset(), partition.getLength());
text.setEnabled(true);
text.setText(source);
}
catch (BadLocationException e) {
e.printStackTrace();