package _VisualDVM.Passes.All;
import _VisualDVM.Constants;
import _VisualDVM.Current;
import _VisualDVM.Global;
import _VisualDVM.TestingSystem.DVM.DVMPackage.DVMPackage;
import _VisualDVM.Visual.UI;

import java.io.File;
import java.util.Vector;
public class DownloadDVMPackage extends DownloadDVMPackages {
    DVMPackage dvmPackage;
    @Override
    public String getIconPath() {
        return "/icons/Comparsion.png";
    }
    protected boolean canStart(Object... args) throws Exception {
        if (Global.mainModule.Check(Log, Current.DVMPackage)) {
            //--
            dvmPackage = Global.mainModule.getDVMPackage();
            //--
            if (!dvmPackage.state.isDone()
            ) {
                Log.Writeln_("Возможно скачать и отобразить задачи только завершённого пакета!");
                return false;
            }
            if (new File(dvmPackage.getLocalWorkspace(), Constants.LOADED).exists()) {
                UI.getMainWindow().getTestingWindow().ShowDVMPackage(dvmPackage);
                Global.testingServer.db.dvmRunTasks.ShowDVMPackage(dvmPackage);
                return false;
            }
            Vector<Integer> packages = new Vector<>();
            packages.add(dvmPackage.id);
            return super.canStart(packages);
        }
        return false;
    }
    @Override
    protected void showDone() throws Exception {
        UI.getMainWindow().getTestingWindow().ShowDVMPackage(dvmPackage);
        Global.testingServer.db.dvmRunTasks.ShowDVMPackage(dvmPackage);
    }
}
