假如我们有两个模型:RouteMap和Homuncule,其中Homuncule是包含在RouteMap中。RouteMap上安装有用于Homuncule拖动和定大小的Policy:HomunculeLayoutPolicy.
要修改Homuncule默认的FeedBack,我们需要重写HomunculeLayoutPolicy的createChildEditPolicy(EditPart child)方法。例如:
protected EditPolicy createChildEditPolicy(EditPart child) {
if (child instanceof HomunculeEditPart) {
return new HomunculeFeedBackPolicy();
} else {
return super.createChildEditPolicy(child);
}
}
然后实现HomunculeFeedBackPolicy,这里HomunculeFeedBackPolicy需要继承:ResizableEditPolicy。最后HomunculeFeedBackPolicy重写方法:createDragSourceFeedbackFigure(),例如:
public class HomunculeFeedBackPolicy extends ResizableEditPolicy {
@Override
protected IFigure createDragSourceFeedbackFigure() {
HomunculeFigure r = new HomunculeFigure(ColorConstants.lightGray);
r.setBounds(getInitialFeedbackBounds());
addFeedback(r);
return r;
}
}
最后结果如下图: