package _VisualDVM.Visual.Menus;
import Common.Utils.Utils_;
import Common.Visual.Controls.StableMenuItem;
import Common.Visual.Menus.GraphMenu;
import Common.Visual.Menus.VisualiserMenuItem;
import Common.Visual.Trees.DataTree;
import _VisualDVM.Global;
import _VisualDVM.Passes.PassCode;
public class VersionsMenu extends GraphMenu<DataTree> {
    VisualiserMenuItem m_select_all;
    VisualiserMenuItem m_unselect_all;
    VisualiserMenuItem m_multiselection;
    public VersionsMenu(DataTree tree) {
        super(tree, "подверсии");
        add(Global.mainModule.getPass(PassCode.DeleteSubversions).createMenuItem());
        add(Global.mainModule.getPass(PassCode.DeleteLonelyM).createMenuItem());
        addSeparator();
        m_multiselection = new VisualiserMenuItem("Массовый режим работы с версиями");
        m_multiselection.setIcon(Utils_.getIcon(Global.versions_multiselection ? "/Common/icons/Pick.png" : "/Common/icons/NotPick.png"));
        m_multiselection.addActionListener(e -> {
            Global.versions_multiselection = !Global.versions_multiselection;
            m_multiselection.setIcon(Utils_.getIcon(Global.versions_multiselection ? "/Common/icons/Pick.png" : "/Common/icons/NotPick.png"));
            Global.mainModule.getRoot().SelectAllVersions(false);
            Global.mainModule.getUI().getVersionsWindow().getVersionsForm().getTree().updateUI();
        });
        add(m_multiselection);
        addSeparator();
        add(Global.mainModule.getPass(PassCode.DeleteVersion).createMenuItem());
        //-
        m_select_all = new StableMenuItem("Выбрать всё, кроме резервных копий", "/Common/icons/SelectAll.png");
        m_select_all.addActionListener(e -> {
            Global.mainModule.getRoot().SelectAllVersions(true);
            tree.updateUI();
        });
        add(m_select_all);
        m_unselect_all = new StableMenuItem("Отменить всё", "/Common/icons/UnselectAll.png");
        m_unselect_all.addActionListener(e -> {
            Global.mainModule.getRoot().SelectAllVersions(false);
            tree.updateUI();
        });
        add(m_unselect_all);
        add(Global.mainModule.getPass(PassCode.DeleteSelectedVersions).createMenuItem());
    }
    @Override
    public void CheckElementsVisibility() {
        Global.mainModule.getPass(PassCode.DeleteSelectedVersions).setControlsVisible(!Global.versions_multiselection);
        Global.mainModule.getPass(PassCode.DeleteSelectedVersions).setControlsVisible(Global.versions_multiselection);
        Global.mainModule.getPass(PassCode.DeleteVersion).setControlsVisible(!Global.versions_multiselection);
        m_select_all.setVisible(Global.versions_multiselection);
        m_unselect_all.setVisible(Global.versions_multiselection);
    }
}
