Example #1
0
 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;
 }
Example #2
0
 public Set<NonHumanSubCategory> getNonHumanSubCategories() {
   Set<NonHumanSubCategory> set = new HashSet<NonHumanSubCategory>();
   for (NonHumanCategory c : nonHumanCategoryMap.values()) {
     set.addAll(c.getSubCategories());
   }
   return set;
 }
Example #3
0
 public String getNonHumanCategoryNames() {
   XNode node = new XNode("nonHumanCategoryNames");
   for (NonHumanCategory r : nonHumanCategoryMap.values()) {
     node.addChild("name", r.getName());
   }
   return node.toString();
 }
Example #4
0
  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();
  }
Example #5
0
 /* 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;
 }
Example #6
0
 /* 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;
 }
Example #7
0
 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();
 }
Example #8
0
 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();
 }
Example #9
0
  /* 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;
  }
Example #10
0
 /* 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;
 }
Example #11
0
 public Set<NonHumanResource> getNonHumanResources(NonHumanCategory category, String subcategory) {
   Set<NonHumanResource> resources = new HashSet<NonHumanResource>();
   if (category != null) {
     resources = category.getSubCategoryResources(subcategory);
   }
   return resources;
 }
Example #12
0
 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");
 }
Example #13
0
  /* 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;
  }
Example #14
0
  /* 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
  }
Example #15
0
 private void populateSimpleFields(NonHumanCategory category) {
   populateSimpleFields(category.getName(), category.getDescription(), category.getNotes());
 }
Example #16
0
 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());
 }
Example #17
0
 public int compareTo(NonHumanCategory other) {
   if (other == null) return 1;
   return this.getName().compareTo(other.getName());
 }
Example #18
0
 public boolean isKnownNonHumanCategory(NonHumanCategory c) {
   return isKnownNonHumanCategory(c.getID());
 }
Example #19
0
 public void putNonHumanCategory(NonHumanCategory r) {
   nonHumanCategoryMap.put(r.getID(), r);
   setChangeStamp(ResUnit.NonHumanCategory);
 }
Example #20
0
 public NonHumanCategory getNonHumanCategoryByName(String name) {
   for (NonHumanCategory r : nonHumanCategoryMap.values()) {
     if (r.getName().equalsIgnoreCase(name)) return r;
   }
   return null; // no match
 }
Example #21
0
 public void delNonHumanCategory(NonHumanCategory r) {
   nonHumanCategoryMap.remove(r.getID());
   setChangeStamp(ResUnit.NonHumanCategory);
 }