package Visual_DVM_2021.Passes.All;
import Common.Current;
import ProjectData.Files.FileState;
import ProjectData.Files.ProjectFile;
import ProjectData.Project.db_project_info;
import TestingSystem.Common.Group.Group;
//из текущего проекта.
public class CreateTestFromProject extends CreateTestFromDirectory {
    db_project_info project;
    @Override
    public String getIconPath() {
        return "/icons/RedAdd.png";
    }
    @Override
    protected boolean canStart(Object... args) throws Exception {
        if (args.length == 0) {
            if (Current.Check(Log, Current.Group, Current.Project)) {
                project = Current.getProject();
                if (super.canStart(Current.getProject().Home, Current.getGroup())){
                    from_directory_chooser = true; //чтобы опубликовал.
                    return true;
                }
            }
        } else {
            project = (db_project_info) args[0];
            group = (Group) args[1];
            //если проект не текущий, освежить его бд.
            if (!Current.HasProject() || !Current.getProject().Home.equals(project.Home)) {
                project.Open();
                project.Close();
            }
            return super.canStart(project.Home, group);
        }
        return false;
    }
    @Override
    public boolean isNotExcluded(ProjectFile projectFile) {
        return project.db.files.containsKey(projectFile.file.getName()) &&
                !project.db.files.get(projectFile.file.getName()).state.equals(FileState.Excluded);
    }
}
