public void updateCaret() {
if (_trackFigure != null) {
_trackFigure.removeFigureListener(this);
_trackFigure = null;
}
Caret caret = _viewer.getCaret();
if (caret == null) {
return;
}
if (caret.isDisposed()) {
return;
}
Rectangle rect = null;
// try get the caret bounds.
if (_viewer.isInRangeMode()) {
DesignRange range = _viewer.getRangeSelection();
if (range != null) {
DesignPosition endPosition = range.getEndPosition();
if (endPosition != null && endPosition.isValid()) {
rect = EditPartPositionHelper
.convertToAbsoluteCaretRect(endPosition);
_trackFigure = ((GraphicalEditPart) endPosition
.getContainerPart()).getFigure();
_trackFigure.addFigureListener(this);
}
}
}
// set visible effect
if (rect == null) {
caret.setVisible(false);
} else {
caret.setVisible(false); // make sure it get removed from the
// screen.
// the caret width doesn't need to be calculated, the x pos should
// be adjusted more acurately.
caret.setBounds(rect.x, rect.y, CARET_WIDTH, rect.height);
caret.setVisible(true);
}
}