Methods Summary |
---|
protected void | createEditPolicies()
super.createEditPolicies();
// This policy indicates this a root component that cannot be removed
installEditPolicy(EditPolicy.COMPONENT_ROLE, new RootComponentEditPolicy());
installLayoutEditPolicy(this);
|
protected org.eclipse.draw2d.IFigure | createFigure()
mLayer = new FreeformLayer();
mLayer.setLayoutManager(new FreeformLayout());
mLayer.setOpaque(true);
mLayer.setBackgroundColor(ColorConstants.lightGray);
return mLayer;
|
public org.eclipse.gef.EditPart | getTargetEditPart(org.eclipse.gef.Request request)Returns the EditPart that should be used as the target for the specified Request.
For instance this is called during drag'n'drop with a CreateRequest.
For the root document, we want the first child edit part to the be the target
since an XML document can have only one root element.
{@inheritDoc}
if (request != null && request.getType() == RequestConstants.REQ_CREATE) {
// We refuse the drop if it's not in the bounds of the document.
if (request instanceof DropRequest) {
Point where = ((DropRequest) request).getLocation().getCopy();
UiElementNode uiNode = getUiNode();
if (uiNode instanceof UiDocumentNode) {
// Take the bounds of the background image as the valid drop zone
Object editData = uiNode.getEditData();
if (editData instanceof BufferedImage) {
BufferedImage image = (BufferedImage)editData;
int w = image.getWidth();
int h = image.getHeight();
if (where.x > w || where.y > h) {
return null;
}
}
}
}
// For the root document, we want the first child edit part to the be the target
// since an XML document can have only one root element.
if (getChildren().size() > 0) {
Object o = getChildren().get(0);
if (o instanceof EditPart) {
return ((EditPart) o).getTargetEditPart(request);
}
}
}
return super.getTargetEditPart(request);
|
protected void | hideSelection()
// no selection at this level.
|
protected void | refreshVisuals()
UiElementNode model = (UiElementNode)getModel();
Object editData = model.getEditData();
if (editData instanceof BufferedImage) {
BufferedImage image = (BufferedImage)editData;
if (mImage == null || image != mImage.getBufferedImage()) {
mImage = new ImageBackground(image, mDisplay);
}
mLayer.setBorder(mImage);
if (mChild != null && mChild.getParent() == mLayer) {
mLayer.remove(mChild);
}
} else if (editData instanceof String) {
mLayer.setBorder(null);
if (mChild == null) {
mChild = new Label();
}
mChild.setText((String)editData);
if (mChild != null && mChild.getParent() != mLayer) {
mLayer.add(mChild);
}
Rectangle bounds = mChild.getTextBounds();
bounds.x = bounds.y = 0;
mLayer.setConstraint(mChild, bounds);
}
// refresh the children as well
refreshChildrenVisuals();
|
protected void | showSelection()
// no selection at this level.
|