/** Returns the first "default" TaskType, null. */ public Project findDefaultProject() { for (Project proj : P_PROJS.getList(this)) { if (proj.get(Project.P_DEFAULT) && !proj.get(Project.P_FINISHED)) { return proj; } } return null; }
/** Returns all open Projects. */ public ArrayList<Project> getOpenProjects() { ArrayList<Project> result = new ArrayList<Project>(P_PROJS.getItemCount(this)); for (Project task : P_PROJS.getList(this)) { if (!task.get(Project.P_FINISHED)) { result.add(task); } } return result; }
/** Sync projects with other WorkSpace. */ public void syncProjects(WorkSpace otherSpace) { ArrayList<Project> newProjects = new ArrayList<Project>(); for (Project otherProject : P_PROJS.getList(otherSpace)) { boolean found = false; for (Project thisProject : P_PROJS.getList(this)) { if (Project.P_ID.equals(otherProject, thisProject.get(Project.P_ID))) { if (Project.P_DESCR.equals(otherProject, thisProject.get(Project.P_DESCR))) { // only update projects with same description, otherwise // old non-synced projects may change description thisProject.copyFrom(otherProject); thisProject.syncTasks(otherProject); } found = true; break; } } if (!found) { newProjects.add(otherProject); } } for (Project thisProject : P_PROJS.getList(this)) { boolean found = false; for (Project otherProject : P_PROJS.getList(otherSpace)) { if (Project.P_ID.equals(otherProject, thisProject.get(Project.P_ID))) { found = true; break; } } if (!found) { thisProject.set(Project.P_FINISHED, true); } } for (Project otherProject : newProjects) { Project project = new Project(); project.copyFrom(otherProject); project.syncTasks(otherProject); WorkSpace.P_PROJS.addItem(this, project); } }