package _VisualDVM.Passes.All;
import Common.Passes.Pass;
import _VisualDVM.Current;
import _VisualDVM.Global;
import _VisualDVM.GlobalData.SapforProfile.SapforProfile;
import _VisualDVM.GlobalData.SapforProfileSetting.SapforProfileSetting;
import _VisualDVM.Passes.PassCode;

import java.util.Vector;
public class ApplyProfile extends Pass<SapforProfile> {
    @Override
    public String getIconPath() {
        return "/icons/Apply.png";
    }
    @Override
    public String getButtonText() {
        return "";
    }
    @Override
    public boolean needsConfirmations() {
        return true;
    }
    @Override
    protected boolean canStart(Object... args) throws Exception {
        if (Global.mainModule.Check(Log, Current.SapforProfile)) {
            target = (SapforProfile) Global.mainModule.get(Current.SapforProfile);
            return true;
        }
        return false;
    }
    @Override
    protected void body() throws Exception {
        Vector<SapforProfileSetting> settings = new Vector<>();
        for (SapforProfileSetting sapforProfileSetting : Global.mainModule.getDb().sapforProfilesSettings.Data.values())
            if (sapforProfileSetting.sapforprofile_id == target.id)
                settings.add(sapforProfileSetting);
        //--
        for (SapforProfileSetting setting : settings)
            if (Global.mainModule.getDb().settings.containsKey(setting.name))
                Global.mainModule.getPass(PassCode.UpdateSetting).Do(setting.name, setting.value);
        //--
    }
}
