public void addLineStyleListener( LineStyleListener lineStyler ) {
styledText.addLineStyleListener( lineStyler );
}
private void buildPreview(Composite container) {
GridData gridData = new GridData();
gridData.horizontalAlignment = SWT.RIGHT;
gridData.verticalAlignment = SWT.TOP;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalSpan = 1;
gridData.verticalSpan = 5;
Composite composite = new Composite(container, SWT.NONE);
composite.setLayout(new GridLayout(1, false));
composite.setLayoutData(gridData);
// create overview
Table table = new Table(composite, SWT.BORDER);
table.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, true, 1, 1));
TableColumn intersection = new TableColumn(table, SWT.CENTER);
TableColumn mergeConflicts = new TableColumn(table, SWT.CENTER);
TableColumn unionWithoutConflicts = new TableColumn(table, SWT.CENTER);
intersection.setText("Intersection");
mergeConflicts.setText("Merge conflicts");
unionWithoutConflicts.setText("Union without conflicts");
intersection.setWidth(80);
mergeConflicts.setWidth(100);
unionWithoutConflicts.setWidth(140);
table.setHeaderVisible(true);
previewStats = new TableItem(table, SWT.NONE);
Label label = new Label(composite, SWT.NONE);
label.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, true, 1, 1));
label.setText("Preview: ");
preview = new StyledText(composite, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
preview.setLayoutData(new GridData(GridData.FILL_BOTH));
preview.setEditable(false);
preview.setEnabled(false);
preview.setBlockSelection(true);
// highlight current conflict
initializeConflictIterator();
preview.addLineStyleListener(new LineStyleListener() {
public void lineGetStyle(LineStyleEvent event) {
if (currentConflictedField == null
|| currentConflictedResource.getConflictForField(currentConflictedField) == null)
return;
String currentConflict = currentConflictedResource.getConflictForField(currentConflictedField);
StyleRange styleRange = new StyleRange();
styleRange.start = preview.getText().indexOf(currentConflict);
styleRange.length = currentConflict.length();
styleRange.background = getParentShell().getDisplay().getSystemColor(SWT.COLOR_YELLOW);
event.styles = new StyleRange[] { styleRange };
}
});
GridData textGrid = new GridData(500, 500);
textGrid.horizontalSpan = 2;
preview.setLayoutData(textGrid);
updatePreview();
}
public void addLineStyleListener( LineStyleListener lineStyler ) {
styledText.addLineStyleListener( lineStyler );
}