package _VisualDVM.Passes.All;
import Common.CommonConstants;
import _VisualDVM.Global;
import _VisualDVM.TestingSystem.DVM.DVMPackage.DVMPackage;

import java.io.File;
import java.util.Vector;
public class DownloadDVMPackage extends DownloadDVMPackages {
    DVMPackage dvmPackage;
    @Override
    public String getIconPath() {
        return "/icons/DownloadBugReport.png";
    }
    protected boolean canStart(Object... args) throws Exception {
        if (Global.testingServer.db.dvmPackages.getUI().CheckCurrent(Log)) {
            //--
            dvmPackage = Global.testingServer.db.dvmPackages.getUI().getCurrent();
            //--
            if (!dvmPackage.state.isDone()
            ) {
                Log.Writeln_("Возможно скачать и отобразить задачи только завершённого пакета!");
                return false;
            }
            if (new File(dvmPackage.getLocalWorkspace(), CommonConstants.LOADED).exists()) {
                Global.mainModule.getUI().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 {
        Global.mainModule.getUI().getMainWindow().getTestingWindow().ShowDVMPackage(dvmPackage);
        Global.testingServer.db.dvmRunTasks.ShowDVMPackage(dvmPackage);
    }
}
