*/
//TODO: needs refactoring
public static DesignPosition innerFindEditPartPosition(EditPart rootHost,
EditPart host, Point p, FlowBoxLine boxLine,
IPositionMediator validator) {
Target target = new Target(host);
LayoutPart lPart = new LayoutPart(host, p);
// text
if (host instanceof TextEditPart) {
if (lPart.contains(p)) {
DesignPosition position = null;
// see if the point is within string.
position = findTextEditPartPosition((TextEditPart) host, p);
if (position == null) {
addToCurrentLine(boxLine, host, p, validator);
}
// found?!!
return position;
}
addToCurrentLine(boxLine, host, p, validator);
return null;
}
// widget
else if (isWidget(host)) {
if (lPart.contains(p)
&& (validator.isValidPosition(new DOMRefPosition(target
.getNode(), true)) || //
validator.isValidPosition((new DOMRefPosition(target
.getNode(), false))))) {
if (IHTMLConstants.TAG_BR.equalsIgnoreCase(Target.resolveNode(
host).getNodeName())) {
return new DesignRefPosition(host, lPart.isBeforePoint(p));
}
return new DesignRefPosition(host, lPart.isBeforePoint(p)
|| !lPart.atLeftPart(p));
}
addToCurrentLine(boxLine, host, p, validator);
} else {
// root host. we always support it has editable area.
if (host == rootHost) {
if (host.getChildren().size() > 0) {
List children = host.getChildren();
for (int i = 0, size = children.size(); i < size; i++) {
GraphicalEditPart child = (GraphicalEditPart) children
.get(i);
DesignPosition position = innerFindEditPartPosition(
rootHost, child, p, boxLine, validator);
if (position != null) {
return position;
}
}
}
if (boxLine.getPartsList().size() == 0) {
if (lPart.contains(p)) {
// found!!!
return new DesignPosition(host, 0);
}
addToCurrentLine(boxLine, host, p, validator);
}
}
// container
else {
// can't edit it.
if (!validator.hasEditableArea(target)) {
if (lPart.contains(p) && //
(validator.isValidPosition(new DesignRefPosition(
target.getPart(), true)) || //
validator.isValidPosition(new DesignRefPosition(
target.getPart(), false)))) {
return new DesignRefPosition(host, lPart
.isBeforePoint(p)
|| !lPart.atLeftPart(p));
}
addToCurrentLine(boxLine, host, p, validator);
}
// can edit
else {
// contains p
if (lPart.contains(p) || //
(!validator.isValidPosition(new DesignRefPosition(
target.getPart(), true)) && //
!validator.isValidPosition(new DesignRefPosition(
target.getPart(), false)))) {
if (host.getChildren().size() > 0) {
List children = host.getChildren();
for (int i = 0, size = children.size(); i < size; i++) {
GraphicalEditPart child = (GraphicalEditPart) children
.get(i);