package _VisualDVM.Passes.All;
import Common.Passes.Pass;
import _VisualDVM.ComponentsServer.Component.Component;
import _VisualDVM.Global;
import _VisualDVM.Passes.PassCode;

import java.util.Vector;
public class UpdateSelectedComponents extends Pass<Vector<Component>> {
    @Override
    public String getIconPath() {
        return "/icons/Update.png";
    }
    @Override
    public String getButtonText() {
        return "";
    }
    @Override
    public boolean needsConfirmations() {
        return true;
    }
    @Override
    protected boolean canStart(Object... args) throws Exception {
        target = new Vector<>();
        //------------------------
        if (Global.components.getUI().getSelectedCount() == 0) {
            Log.Writeln_("Не отмечено ни одного компонента!");
            return false;
        }
        target = Global.components.getUI().getSelectedItems();
        return true;
    }
    @Override
    public String getStartDescription() {
        Vector<String> question = new Vector<>();
        question.add("Обновить компоненты");
        for (Component component : Global.components.getUI().getSelectedItems()) {
            question.add(component.getComponentType().getDescription());
        }
        return String.join("\n", question);
    }
    @Override
    protected void body() throws Exception {
        for (Component component : target) {
            Global.components.getUI().SetCurrentByPK(component.getPK());
            Global.mainModule.getPass(PassCode.UpdateComponent).Do();
        }
    }
}
