drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/editors/rete/ReteooLayoutFactory.java
public static RowList calculateReteRows(BaseVertex root) {
        RowList rowList = new RowList();

        rowList.add( 0,
                     root );

        int curRow = 0;

        final Set<BaseVertex> seenVertices = new HashSet<BaseVertex>();
        seenVertices.add( root );

        while ( curRow < rowList.getDepth() ) {
            final List<BaseVertex> rowVertices = rowList.get( curRow ).getVertices();

            for ( final Iterator<BaseVertex> rowNodeIter = rowVertices.iterator(); rowNodeIter.hasNext(); ) {
                final BaseVertex rowNode = rowNodeIter.next();

                final List<Connection> edges = rowNode.getSourceConnections();

                for ( final Iterator<Connection> edgeIter = edges.iterator(); edgeIter.hasNext(); ) {

                    final Connection edge = edgeIter.next();
                    final BaseVertex destNode = edge.getOpposite( rowNode );

                    if ( !seenVertices.contains( destNode ) ) {
                        rowList.add( curRow + 1,
                                     destNode );
                        seenVertices.add( destNode );
                    }
                }

                seenVertices.add( rowNode );
            }

            ++curRow;
        }

        rowList.optimize();

        return rowList;
    }
public static RowList calculateReteRows(BaseVertex root) {
        RowList rowList = new RowList();

        rowList.add( 0,
                     root );

        int curRow = 0;

        final Set<BaseVertex> seenVertices = new HashSet<BaseVertex>();
        seenVertices.add( root );

        while ( curRow < rowList.getDepth() ) {
            final List<BaseVertex> rowVertices = rowList.get( curRow ).getVertices();

            for ( final Iterator<BaseVertex> rowNodeIter = rowVertices.iterator(); rowNodeIter.hasNext(); ) {
                final BaseVertex rowNode = rowNodeIter.next();

                final List<Connection> edges = rowNode.getSourceConnections();

                for ( final Iterator<Connection> edgeIter = edges.iterator(); edgeIter.hasNext(); ) {

                    final Connection edge = edgeIter.next();
                    final BaseVertex destNode = edge.getOpposite( rowNode );

                    if ( !seenVertices.contains( destNode ) ) {
                        rowList.add( curRow + 1,
                                     destNode );
                        seenVertices.add( destNode );
                    }
                }

                seenVertices.add( rowNode );
            }

            ++curRow;
        }

        rowList.optimize();

        return rowList;
    }
public static RowList calculateReteRows ( BaseVertex root ) { RowList rowList = new RowList ( ) ; rowList . add ( 0 , root ) ; int curRow = 0 ; final Set < BaseVertex > seenVertices = new HashSet < BaseVertex > ( ) ; seenVertices . add ( root ) ; while ( curRow < rowList . getDepth ( ) ) { final List < BaseVertex > rowVertices = rowList . get ( curRow ) . getVertices ( ) ; for ( final Iterator < BaseVertex > rowNodeIter = rowVertices . iterator ( ) ; rowNodeIter . hasNext ( ) ; ) { final BaseVertex rowNode = rowNodeIter . next ( ) ; final List < Connection > edges = rowNode . getSourceConnections ( ) ; for ( final Iterator < Connection > edgeIter = edges . iterator ( ) ; edgeIter . hasNext ( ) ; ) { final Connection edge = edgeIter . next ( ) ; final BaseVertex destNode = edge . getOpposite ( rowNode ) ; if ( ! seenVertices . contains ( destNode ) ) { rowList . add ( curRow + 1 , destNode ) ; seenVertices . add ( destNode ) ; } } seenVertices . add ( rowNode ) ; } ++ curRow ; } rowList . optimize ( ) ; return rowList ; }
Calculates layouting for provided graph.

@param root graph root vertex

@return Optimally layouted rows from provided graph
Calculates layouting for provided graph .