package _VisualDVM.ProjectData.Files.UI;
import Common.Visual.Trees.DataTree;
import _VisualDVM.Current;
import _VisualDVM.Global;
import _VisualDVM.ProjectData.SapforData.FileObject;
import _VisualDVM.ProjectData.SapforData.FileObjectWithMessages;
import _VisualDVM.Visual.Trees.GraphTreeCellRenderer;

import javax.swing.tree.DefaultMutableTreeNode;
public class FileGraphTree extends DataTree {
    public FileGraphTree(DefaultMutableTreeNode root) {
        super(root);
        //  ExpandAll();
    }
    @Override
    public Class getRendererClass() {
        return GraphTreeCellRenderer.class;
    }
    @Override
    public Current currentName() {
        return Current.FileGraphElement;
    }
    @Override
    public void ShowCurrentObject() throws Exception {
        Global.mainModule.getFile().form.EventsOff();
        Object o = Global.mainModule.get(currentName());
        if (o instanceof FileObjectWithMessages) {
            FileObjectWithMessages f = (FileObjectWithMessages) o;
            Global.mainModule.getFile().form.getEditor().gotoLine(f.line);
            Global.mainModule.getFile().form.ShowMessages(f);
        } else {
            Global.mainModule.getFile().form.getEditor().gotoLine(1);
            Global.mainModule.getFile().form.ShowMessages();
        }
        Global.mainModule.getFile().form.EventsOn();
    }
    @Override
    protected boolean findNode(Object userObject, Object criteria) {
        return (userObject instanceof FileObject) && (
                ((FileObject) (userObject)).line == (Integer) criteria);
    }
    @Override
    protected int getStartLine() {
        return 1;
    }
}