use of org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderItemEditPart in project elk by eclipse.
the class ElkLayoutProvider method canLayoutNodes.
/**
* {@inheritDoc}<br>
* <br>
* This method returns <code>true</code> only for {@link IGraphicalEditPart IGraphicalEditParts}
* whose figures are visible and that contain at least a {@link ShapeNodeEditPart}, which is not
* an {@link AbstractBorderItemEditPart} or an {@link AbstractImageEditPart}.<br>
* <br>
* In short, returns only true if the provided edit part contains children that can be layouted.
*/
@SuppressWarnings("rawtypes")
public boolean canLayoutNodes(final List layoutNodes, final boolean shouldOffsetFromBoundingBox, final IAdaptable layoutHint) {
Object o = layoutHint.getAdapter(IGraphicalEditPart.class);
if (!(o instanceof IGraphicalEditPart)) {
return false;
}
final IGraphicalEditPart parent = (IGraphicalEditPart) o;
// computing layout on the element wouldn't make sense otherwise
if (layoutNodes.isEmpty()) {
return Iterables.any((List<?>) parent.getChildren(), new Predicate<Object>() {
public boolean apply(final Object o) {
return o instanceof ShapeNodeEditPart && !(o instanceof AbstractBorderItemEditPart) && !(o instanceof AbstractImageEditPart);
}
});
} else {
return Iterables.any((List<?>) layoutNodes, new Predicate<Object>() {
public boolean apply(final Object o) {
ILayoutNode layoutNode = (ILayoutNode) o;
IGraphicalEditPart editPart = findEditPart(parent, layoutNode.getNode());
return editPart instanceof ShapeNodeEditPart && !(editPart instanceof AbstractBorderItemEditPart) && !(editPart instanceof AbstractImageEditPart);
}
});
}
}
use of org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderItemEditPart in project elk by eclipse.
the class GmfDiagramLayoutConnector method buildLayoutGraphRecursively.
/**
* Recursively builds a layout graph by analyzing the children of the given edit part.
*
* @param mapping
* the layout mapping
* @param parentEditPart
* the parent edit part of the current elements
* @param parentLayoutNode
* the corresponding KNode
* @param currentEditPart
* the currently analyzed edit part
*/
protected void buildLayoutGraphRecursively(final LayoutMapping mapping, final IGraphicalEditPart parentEditPart, final ElkNode parentLayoutNode, final IGraphicalEditPart currentEditPart) {
Maybe<ElkPadding> kinsets = new Maybe<ElkPadding>();
// iterate through the children of the element
for (Object obj : currentEditPart.getChildren()) {
// check visibility of the child
if (obj instanceof IGraphicalEditPart) {
IFigure figure = ((IGraphicalEditPart) obj).getFigure();
if (!figure.isVisible()) {
continue;
}
}
// process a port (border item)
if (obj instanceof AbstractBorderItemEditPart) {
AbstractBorderItemEditPart borderItem = (AbstractBorderItemEditPart) obj;
if (editPartFilter.filter(borderItem)) {
createPort(mapping, borderItem, parentEditPart, parentLayoutNode);
}
// process a compartment, which may contain other elements
} else if (obj instanceof ResizableCompartmentEditPart && ((CompartmentEditPart) obj).getChildren().size() > 0) {
CompartmentEditPart compartment = (CompartmentEditPart) obj;
if (editPartFilter.filter(compartment)) {
boolean compExp = true;
IFigure compartmentFigure = compartment.getFigure();
if (compartmentFigure instanceof ResizableCompartmentFigure) {
ResizableCompartmentFigure resizCompFigure = (ResizableCompartmentFigure) compartmentFigure;
// check whether the compartment is collapsed
compExp = resizCompFigure.isExpanded();
}
if (compExp) {
buildLayoutGraphRecursively(mapping, parentEditPart, parentLayoutNode, compartment);
}
}
// process a node, which may be a parent of ports, compartments, or other nodes
} else if (obj instanceof ShapeNodeEditPart) {
ShapeNodeEditPart childNodeEditPart = (ShapeNodeEditPart) obj;
if (editPartFilter.filter(childNodeEditPart)) {
ElkNode node = createNode(mapping, childNodeEditPart, parentEditPart, parentLayoutNode, kinsets);
// process the child as new current edit part
buildLayoutGraphRecursively(mapping, childNodeEditPart, node, childNodeEditPart);
}
// process a label of the current node
} else if (obj instanceof IGraphicalEditPart) {
createNodeLabel(mapping, (IGraphicalEditPart) obj, parentEditPart, parentLayoutNode);
}
}
}
Aggregations