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

import java.util.Vector;
public class ApplyProfile extends Pass<SapforProfile> {
    @Override
    public String getIconPath() {
        return "/Common/icons/Apply.png";
    }
    @Override
    public String getButtonText() {
        return "";
    }
    @Override
    public boolean needsConfirmations() {
        return true;
    }
    @Override
    protected boolean canStart(Object... args) throws Exception {
        if (MainModule_.instance.getDb().getTable(SapforProfile.class).getUI().CheckCurrent(Log)) {
            target = MainModule_.instance.getDb().getTable(SapforProfile.class).getUI().getCurrent();
            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);
        //--
        Global.mainModule.getProject().sapforProperties.applyProfile(settings);
    }
}
