Methods Summary |
---|
public void | activate()
super.activate();
getUiNode().addUpdateListener(this);
|
protected void | createEditPolicies()
/*
* This is no longer needed, as a selection edit policy is set by the parent layout.
* Leave this code commented out right now, I'll want to play with this later.
*
installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE,
new NonResizableSelectionEditPolicy(this));
*/
|
public void | deactivate()
super.deactivate();
getUiNode().removeUpdateListener(this);
|
protected final org.eclipse.draw2d.geometry.Rectangle | getBounds()
UiElementNode model = (UiElementNode)getModel();
Object editData = model.getEditData();
if (editData != null) {
// assert with fully qualified class name to prevent import changes to another
// Rectangle class.
assert (editData instanceof org.eclipse.draw2d.geometry.Rectangle);
return (Rectangle)editData;
}
// return a dummy rect
return new Rectangle(0, 0, 0, 0);
|
protected final com.android.ide.eclipse.editors.descriptors.ElementDescriptor | getDescriptor()
return getUiNode().getDescriptor();
|
public org.eclipse.gef.DragTracker | getDragTracker(org.eclipse.gef.Request request)
return new SelectEditPartTracker(this);
|
protected final com.android.ide.eclipse.editors.layout.parts.UiElementEditPart | getEditPartParent()
EditPart parent = getParent();
if (parent instanceof UiElementEditPart) {
return (UiElementEditPart)parent;
}
return null;
|
protected java.util.List | getModelChildren()
return getUiNode().getUiChildren();
|
protected final java.lang.String | getStringAttr(java.lang.String attrName)Returns a given XML attribute.
UiElementNode uiNode = getUiNode();
if (uiNode.getXmlNode() != null) {
Node xmlNode = uiNode.getXmlNode();
if (xmlNode != null) {
NamedNodeMap nodeAttributes = xmlNode.getAttributes();
if (nodeAttributes != null) {
Node attr = nodeAttributes.getNamedItemNS(
SdkConstants.NS_RESOURCES, attrName);
if (attr != null) {
return attr.getNodeValue();
}
}
}
}
return null;
|
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.
Reject being a target for elements which descriptor does not allow children.
{@inheritDoc}
if (request != null && request.getType() == RequestConstants.REQ_CREATE) {
// Reject being a target for elements which descriptor does not allow children.
if (!getUiNode().getDescriptor().hasChildren()) {
return null;
}
}
return super.getTargetEditPart(request);
|
public final com.android.ide.eclipse.editors.uimodel.UiElementNode | getUiNode()
return (UiElementNode) getModel();
|
protected abstract void | hideSelection()
|
protected void | installLayoutEditPolicy(com.android.ide.eclipse.editors.layout.parts.UiElementEditPart layoutEditPart)Used by derived classes {@link UiDocumentEditPart} and {@link UiLayoutEditPart}
to accept drag'n'drop of new items from the palette.
// This policy indicates how elements can be constrained by the layout.
// TODO Right now we use the XY layout policy since our constraints are
// handled by the android rendering engine rather than GEF. Tweak as
// appropriate.
installEditPolicy(EditPolicy.LAYOUT_ROLE, new LayoutEditPolicy() {
/**
* We don't allow layout children to be resized yet.
* <p/>
* Typical choices would be:
* <ul>
* <li> ResizableEditPolicy, to allow for selection, move and resize.
* <li> NonResizableEditPolicy, to allow for selection, move but not resize.
* <li> SelectionEditPolicy to allow for only selection.
* </ul>
* <p/>
* TODO: make this depend on the part layout. For an AbsoluteLayout we should
* probably use a NonResizableEditPolicy and SelectionEditPolicy for the rest.
* Whether to use ResizableEditPolicy or NonResizableEditPolicy should depend
* on the child in an AbsoluteLayout.
*/
@Override
protected EditPolicy createChildEditPolicy(EditPart child) {
if (child instanceof UiElementEditPart) {
return new NonResizableSelectionEditPolicy((UiElementEditPart) child);
}
return null;
}
@Override
protected Command getCreateCommand(CreateRequest request) {
// We store the ElementDescriptor in the request.factory.type
Object newType = request.getNewObjectType();
if (newType instanceof ElementDescriptor) {
Point where = request.getLocation().getCopy();
Point origin = getLayoutContainer().getClientArea().getLocation();
where.translate(origin.getNegated());
// The host is the EditPart where this policy is installed,
// e.g. this UiElementEditPart.
EditPart host = getHost();
if (host instanceof UiElementEditPart) {
return new ElementCreateCommand((ElementDescriptor) newType,
(UiElementEditPart) host,
where);
}
}
return null;
}
@Override
protected Command getMoveChildrenCommand(Request request) {
// TODO Auto-generated method stub
return null;
}
@Override
public void showLayoutTargetFeedback(Request request) {
super.showLayoutTargetFeedback(request);
// for debugging
// System.out.println("target: " + request.toString() + " -- " + layoutEditPart.getUiNode().getBreadcrumbTrailDescription(false));
if (layoutEditPart instanceof UiLayoutEditPart &&
request instanceof DropRequest) {
Point where = ((DropRequest) request).getLocation().getCopy();
Point origin = getLayoutContainer().getClientArea().getLocation();
where.translate(origin.getNegated());
((UiLayoutEditPart) layoutEditPart).showDropTarget(where);
}
}
@Override
protected void eraseLayoutTargetFeedback(Request request) {
super.eraseLayoutTargetFeedback(request);
if (layoutEditPart instanceof UiLayoutEditPart) {
((UiLayoutEditPart) layoutEditPart).hideDropTarget();
}
}
@Override
protected IFigure createSizeOnDropFeedback(CreateRequest createRequest) {
// TODO understand if this is useful for us or remove
return super.createSizeOnDropFeedback(createRequest);
}
});
|
protected void | refreshChildrenVisuals()
if (children != null) {
for (Object child : children) {
if (child instanceof UiElementEditPart) {
UiElementEditPart childPart = (UiElementEditPart)child;
childPart.refreshVisuals();
}
}
}
|
protected void | refreshVisuals()
if (getFigure().getParent() != null) {
((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), getBounds());
}
// update the visuals of the children as well
refreshChildrenVisuals();
|
protected abstract void | showSelection()
|
public void | uiElementNodeUpdated(com.android.ide.eclipse.editors.uimodel.UiElementNode ui_node, UiUpdateState state)
// TODO: optimize by refreshing only when needed
switch(state) {
case ATTR_UPDATED:
refreshVisuals();
break;
case CHILDREN_CHANGED:
refreshChildren();
// new children list, need to update the layout
refreshVisuals();
break;
case CREATED:
refreshVisuals();
break;
case DELETED:
// pass
break;
}
|