Programmatically expanding subgraphs

Article ID: 2399
Last updated: 29 May, 2018
Article ID: 2399
Last updated: 29 May, 2018
Revision: 3
Views: 491
Posted: 07 Apr, 2011
by Dean J.
Updated: 29 May, 2018
by Gargani A.

Question

How to programmatically expand subgraphs?

Answer

The SDM engine delegates the rendering of the data model objects to specialized renderers. In the case of subgraphs, the renderer in charge of applying the style sheet settings for sub graphs is the IlvSubGraphRenderer class.

If you directly apply the expand or collapse state to the graphic object, you will effectively make the graphic object appear expanded or collapsed. However, problems may arise with styles as there is no chance for the style sheet to be applied; this is because the SDM engine is not being involved in the loop.

The correct way to directly style the SDM model node in a fully styled expanded or collapsed state is to ask the subgraph renderer to do it. The subgraph renderer can be retrieved from one of the renderers nested in the SDM engine base renderer by successive calls to IlvFilterSDMRenderer.getFilteredRenderer().

Here is one way to programmatically handle the expansion and collapsing of subgraph nodes:

expandAllButton = new JButton("Expand All");

final IlvDiagrammer someDiagram = ...;

expandAllButton.addActionListener(new ActionListener() {

  public void actionPerformed(ActionEvent arg0) {

    IlvSDMEngine engine = someDiagram.getEngine();

    Enumeration objectsEnum = engine.getAllObjects();

    while (objectsEnum.hasMoreElements()) {

      Object object = objectsEnum.nextElement();

      if (object instanceof IlvDefaultSDMNode) {

        IlvDefaultSDMNode node = (IlvDefaultSDMNode) object;

        IlvGraphic graphic = engine.getGraphic(node, false);

        if (graphic instanceof IlvGrapher) {

          IlvSDMRenderer baseRenderer = engine.getRenderer();

          if(baseRenderer instanceof IlvFilterSDMRenderer) {

            IlvFilterSDMRenderer sub = (IlvFilterSDMRenderer) baseRenderer;

            while(sub.getFilteredRenderer() instanceof IlvFilterSDMRenderer) {

              sub = (IlvFilterSDMRenderer) sub.getFilteredRenderer();

              if(sub instanceof IlvSubGraphRenderer) {

                IlvSubGraphRenderer sgRenderer = (IlvSubGraphRenderer)sub;

                sgRenderer.setExpanded(engine, node,

                                       !sgRenderer.isExpanded(engine, node), true);

              }

            }

          }

        }

      }

    }

  }

);

This article was:   Helpful | Not helpful
Report an issue
Article ID: 2399
Last updated: 29 May, 2018
Revision: 3
Views: 491
Posted: 07 Apr, 2011 by Dean J.
Updated: 29 May, 2018 by Gargani A.
Also listed in


Others in this category