package Common.Visual.Trees;
import Common.Utils.Utils_;
import Common.Visual.DataControl_OLD;
import _VisualDVM.Global;

import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
public class DataTree extends StyledTree implements DataControl_OLD {
    public DataTree(DefaultMutableTreeNode root_in) {
        super(root_in);
    }
    public void ChangeCurrentObject(DefaultMutableTreeNode node) {
        if (getCurrent() != null)
            Global.mainModule.set(getCurrent(), node.getUserObject());
    }
    @Override
    public void ShowCurrentObject() throws Exception {
    }
    @Override
    public void ShowNoCurrentObject() throws Exception {
    }
    @Override
    public void SelectionAction(TreePath path) {
        ChangeCurrentObject((DefaultMutableTreeNode) path.getLastPathComponent());
        try {
            ShowCurrentObject();
        } catch (Exception ex) {
            Utils_.MainLog.PrintException(ex);
        }
    }
    public void SelectNodeByCriteria(Object criteria) {
        EventsOff();
        TreePath res = ShowNodeByCriteria(criteria);
        setSelectionPath(res);
        ChangeCurrentObject((DefaultMutableTreeNode) res.getLastPathComponent());
        EventsOn();
    }
}

