* 1: <a></a> (2 matches)</p>
*
* @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider#getStyledText(java.lang.Object)
*/
public StyledString getStyledText(Object obj) {
StyledString styledText = new StyledString();
BasicSearchMatchElement element = null;
if (obj instanceof Match) {
Match match = (Match) obj;
if(match.getElement() instanceof BasicSearchMatchElement) {
element = (BasicSearchMatchElement) match.getElement();
}
} else if(obj instanceof BasicSearchMatchElement) {
element = (BasicSearchMatchElement)obj;
}
//get the match count if possible
int matchCount = 0;
Match[] matches = new Match[0];
if(fPage != null) {
matches = fPage.getInput().getMatches(obj);
matchCount = matches.length;
}
//if everything was of the right type create our formated message,
//else use the toString of the given object for the message
if(element != null) {
String message = element.getLine().trim(); //$NON-NLS-1$
int trimedAmount = element.getLine().indexOf(message);
String lineNum = element.getLineNum() + 1 + ": "; //$NON-NLS-1$
styledText.append(lineNum, StyledString.QUALIFIER_STYLER);
styledText.append(message);
//get the match count if possible
for(int i = 0; i < matchCount; ++i) {
int offset = matches[i].getOffset() - element.geLineOffset() + lineNum.length() - trimedAmount;
styledText.setStyle(offset, matches[i].getLength(), HIGHLIGHT_WRITE_STYLE);
}
} else {
styledText.append(obj.toString());
}
//append the match count if its worth appending
if (matchCount > 1) {
String matchesMsg = " " + MessageFormat.format(
SSEUIMessages.TextSearchLabelProvider_matchCountFormat,
new Object[] { new Integer(matchCount) });
styledText.append(matchesMsg, StyledString.COUNTER_STYLER);
}
return styledText;
}