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

import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;

import static Common.Visual.Trees.TreeRenderers.RendererRule;
public class RulesTree extends StyledTree {
    public RulesTree() {
        super(Global.mainModule.getProject().align_rules_root);
        setRootVisible(false);
        expandRow(0);
        ExpandAll();
        Global.mainModule.set(Current.ParallelRegion, null);
    }
    @Override
    protected GraphMenu createMenu() {
        return new DistributionMenu(this);
    }
    @Override
    public TreeRenderers getRenderer() {
        return RendererRule;
    }
    @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;
            }
        }
        Global.mainModule.set(Current.ParallelRegion, region);
    }
}
