public Map<String, String> getNonHumanCategoryIdentifiers() { Map<String, String> idMap = new Hashtable<String, String>(); for (NonHumanCategory r : getNonHumanCategories()) { idMap.put(r.getID(), r.getName()); } return idMap; }
public Set<NonHumanSubCategory> getNonHumanSubCategories() { Set<NonHumanSubCategory> set = new HashSet<NonHumanSubCategory>(); for (NonHumanCategory c : nonHumanCategoryMap.values()) { set.addAll(c.getSubCategories()); } return set; }
public String getNonHumanCategoryNames() { XNode node = new XNode("nonHumanCategoryNames"); for (NonHumanCategory r : nonHumanCategoryMap.values()) { node.addChild("name", r.getName()); } return node.toString(); }
public String getNonHumanCategoriesAsXML() { Set<NonHumanCategory> rList = new TreeSet<NonHumanCategory>(nonHumanCategoryMap.values()); StringBuilder xml = new StringBuilder("<nonhumancategories>"); for (NonHumanCategory r : rList) xml.append(r.toXML()); xml.append("</nonhumancategories>"); return xml.toString(); }
/* gets the full list of subcategories for a given category as listbox items */ private Option[] getSubCategoryList(NonHumanCategory category) { Option[] subCatList = new Option[category.getSubCategoryCount()]; int i = 0; for (NonHumanSubCategory subCat : category.getSubCategories()) { subCatList[i++] = new Option(subCat.getName()); } Arrays.sort(subCatList, new OptionComparator()); return subCatList; }
/* removes a subcategory - triggered by categories tab only */ public String btnRemoveSubCat_action() { NonHumanCategory category = getCurrentlySelectedCategory(); if (category != null) { if (category.removeSubCategory(_sb.getNhResourcesSubcategoryChoice())) { _orgDataSet.updateNonHumanCategory(category); _sb.setNhResourcesSubcategoryChoice("None"); } else _msgPanel.error("Failed to remove subcategory."); } return null; }
public String getNonHumanCategorySet() { XNode node = new XNode("nonHumanCategorySet"); for (NonHumanCategory category : nonHumanCategoryMap.values()) { XNode categoryNode = node.addChild("category"); categoryNode.addAttribute("name", category.getName()); for (String subcategory : category.getSubCategoryNames()) { categoryNode.addChild("subcategory", subcategory); } } return node.toString(); }
public String getNonHumanSubCategoriesAsXML(String categoryID) { XNode node = new XNode("nonHumanSubCategories"); NonHumanCategory nhCategory = getNonHumanCategory(categoryID); if (nhCategory != null) { node.addAttribute("category", categoryID); for (String subcategory : nhCategory.getSubCategoryNames()) { node.addChild("subcategory", subcategory); } } return node.toString(); }
/* saves a newly added category to the org database */ public boolean addCategory(String name) { if (!_orgDataSet.isKnownNonHumanCategoryName(name)) { NonHumanCategory category = new NonHumanCategory(name); storeSimpleFieldValues(category); category.addSubCategory("None"); String newID = _orgDataSet.addNonHumanCategory(category); if (_rm.successful(newID)) { _sb.setNhResourcesChoice(newID); return true; } else _msgPanel.error(_msgPanel.format(newID)); } else addDuplicationError("Category"); return false; }
/* adds a new subcategory - triggered by categories tab only */ public String btnConfirmAddSubCat_action() { String name = (String) txtSubCat.getText(); if ((name != null) && (name.length() > 0)) { NonHumanCategory category = getCurrentlySelectedCategory(); if (category != null) { if (category.addSubCategory(name)) { // won't add if duplicate _orgDataSet.updateNonHumanCategory(category); _sb.setSubCatAddMode(false); txtSubCat.setText(null); } else _msgPanel.error("Subcategory already exists: " + name); } } else _msgPanel.error("Please enter a subcategory to add."); return null; }
public Set<NonHumanResource> getNonHumanResources(NonHumanCategory category, String subcategory) { Set<NonHumanResource> resources = new HashSet<NonHumanResource>(); if (category != null) { resources = category.getSubCategoryResources(subcategory); } return resources; }
public String addNonHumanCategory(NonHumanCategory c) { if (isDataEditable(ResUnit.NonHumanCategory)) { String newID = getDataSource(ResUnit.NonHumanCategory).insert(c); if (!hasDefaultDataSource(ResUnit.NonHumanCategory)) c.setID(newID); putNonHumanCategory(c); return newID; } else return fail("External NonHumanCategory dataset is read-only"); }
/* saves updates to the values of the currently selected category */ public boolean saveCategoryChanges(String id) { NonHumanCategory category = _orgDataSet.getNonHumanCategory(id); if (category == null) { _msgPanel.error("Invalid category id: " + id); return false; } // check that any name change is valid String name = (String) txtName.getText(); if ((!name.equals(category.getName())) && _orgDataSet.isKnownNonHumanCategoryName(name)) { addDuplicationError("Category"); return false; } storeSimpleFieldValues(category); _orgDataSet.updateNonHumanCategory(category); return true; }
/* fills ui with the selected resource's values */ private void populateGUI(NonHumanResource resource, String id) { // selected resource is null after a selection change if (resource == null) { resource = _orgDataSet.getNonHumanResource(id); updateSelectedResource(resource); } if (resource != null) { populateSimpleFields(resource); NonHumanCategory category = resource.getCategory(); String subCatName = resource.getSubCategoryName(); if (category == null) { category = getFirstListedCategory(); // default } if (subCatName == null) subCatName = "None"; if (category != null) { cbbCategory.setSelected(category.getID()); _sb.setNhResourcesSubcategoryItems(getSubCategoryList(category)); cbbSubCategory.setSelected(subCatName); } else _sb.setNhResourcesSubcategoryItems(null); // no categories defined } _sb.setNhResourcesSubcategoryList(null); // empty the category tab list box }
private void populateSimpleFields(NonHumanCategory category) { populateSimpleFields(category.getName(), category.getDescription(), category.getNotes()); }
private void storeSimpleFieldValues(NonHumanCategory category) { String name = (String) txtName.getText(); if (name.length() > 0) category.setName(name); category.setDescription((String) txtDesc.getText()); category.setNotes((String) txtNotes.getText()); }
public int compareTo(NonHumanCategory other) { if (other == null) return 1; return this.getName().compareTo(other.getName()); }
public boolean isKnownNonHumanCategory(NonHumanCategory c) { return isKnownNonHumanCategory(c.getID()); }
public void putNonHumanCategory(NonHumanCategory r) { nonHumanCategoryMap.put(r.getID(), r); setChangeStamp(ResUnit.NonHumanCategory); }
public NonHumanCategory getNonHumanCategoryByName(String name) { for (NonHumanCategory r : nonHumanCategoryMap.values()) { if (r.getName().equalsIgnoreCase(name)) return r; } return null; // no match }
public void delNonHumanCategory(NonHumanCategory r) { nonHumanCategoryMap.remove(r.getID()); setChangeStamp(ResUnit.NonHumanCategory); }