if (position == null || !position.isValid()) {
return null;
}
EditPart containerEditPart = position.getContainerPart();
if (containerEditPart instanceof TextEditPart) {
CSSTextFigure figure = (CSSTextFigure) ((TextEditPart) containerEditPart)
.getFigure();
ret = figure.calculateCaretPosition(position.getOffset());
figure.translateToAbsolute(ret);
ret.width = CaretUpdater.CARET_WIDTH;
} else {
int offset = position.getOffset();
// there is no child
if (containerEditPart.getChildren().isEmpty()
|| LayoutPart.getConcretePart(containerEditPart) == null) {
IFigure figure = ((GraphicalEditPart) containerEditPart)
.getFigure();
Rectangle bounds = figure.getBounds();
if (figure instanceof CSSFigure) {
List fragments = ((CSSFigure) figure)
.getFragmentsForRead();
if (fragments.size() > 0) {
FlowBox box = (FlowBox) fragments.get(fragments
.size() - 1);
bounds = LayoutPart.getBounds(box);
}
}
ret = new Rectangle(bounds.x + CARET_OFFSET, bounds.y,
CaretUpdater.CARET_WIDTH, bounds.height);
figure.translateToAbsolute(ret);
} else if (offset >= 0
&& offset <= containerEditPart.getChildren().size()) {
ret = getRefRect(position);
}
}