package _VisualDVM.ProjectData.SapforData.Arrays.UI;
import Common.Visual.Menus.GraphMenu;
import Common.Visual.Trees.StyledTree;
import _VisualDVM.Global;
import _VisualDVM.ProjectData.SapforData.Regions.ParallelRegion;

import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
public class RulesTree extends StyledTree {
    public RulesTree() {
        super(Global.mainModule.getProject().align_rules_root);
        setRootVisible(false);
        expandRow(0);
        ExpandAll();
        Global.mainModule.getProject().parallelRegions.getUI().dropCurrent();
    }
    @Override
    protected GraphMenu createMenu() {
        return new DistributionMenu(this);
    }
    @Override
    public Class getRendererClass() {
        return RendererTreeRule.class;
    }
    @Override
    public void SelectionAction(TreePath e) {
        ParallelRegion region = null;
        if (e != null) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getLastPathComponent();
            Object o = node.getUserObject();
            if (o instanceof String) {
                region = (ParallelRegion) ((DefaultMutableTreeNode) node.getParent()).getUserObject();
            }
            if (o instanceof ParallelRegion) {
                region = (ParallelRegion) o;
            }
        }
        //todo(?)
        Global.mainModule.getProject().parallelRegions.getUI().SetCurrentByPK(region.getPK());
    }
}
