Search in sources :

Example 1 with AbstractBorderItemEditPart

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);
            }
        });
    }
}
Also used : IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) ShapeNodeEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart) ILayoutNode(org.eclipse.gmf.runtime.diagram.ui.services.layout.ILayoutNode) AbstractBorderItemEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderItemEditPart) AbstractImageEditPart(org.eclipse.gmf.runtime.diagram.ui.render.editparts.AbstractImageEditPart)

Example 2 with AbstractBorderItemEditPart

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);
        }
    }
}
Also used : IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) ShapeNodeEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart) Maybe(org.eclipse.elk.core.util.Maybe) ResizableCompartmentFigure(org.eclipse.gmf.runtime.diagram.ui.figures.ResizableCompartmentFigure) ElkNode(org.eclipse.elk.graph.ElkNode) ResizableCompartmentEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.ResizableCompartmentEditPart) ResizableCompartmentEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.ResizableCompartmentEditPart) CompartmentEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart) AbstractBorderItemEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderItemEditPart) EObject(org.eclipse.emf.ecore.EObject) ElkPadding(org.eclipse.elk.core.math.ElkPadding) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

AbstractBorderItemEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderItemEditPart)2 IGraphicalEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart)2 ShapeNodeEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart)2 IFigure (org.eclipse.draw2d.IFigure)1 ElkPadding (org.eclipse.elk.core.math.ElkPadding)1 Maybe (org.eclipse.elk.core.util.Maybe)1 ElkNode (org.eclipse.elk.graph.ElkNode)1 EObject (org.eclipse.emf.ecore.EObject)1 CompartmentEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart)1 ResizableCompartmentEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.ResizableCompartmentEditPart)1 ResizableCompartmentFigure (org.eclipse.gmf.runtime.diagram.ui.figures.ResizableCompartmentFigure)1 AbstractImageEditPart (org.eclipse.gmf.runtime.diagram.ui.render.editparts.AbstractImageEditPart)1 ILayoutNode (org.eclipse.gmf.runtime.diagram.ui.services.layout.ILayoutNode)1