Ejemplo n.º 1
0
 private void logout() {
   if (!sb.isRssAlreadyLoggedOn()) {
     sb.doLogout();
   } else {
     sb.setRssAlreadyLoggedOn(false);
   }
 }
Ejemplo n.º 2
0
  public String btnView_action() {
    String itemID = (String) hdnSelectedItemID.getValue();
    if (itemID == null) {
      msgPanel.error("No work item selected. Please select a work item to view.");
      return null;
    }

    WorkItemRecord selectedWIR = getSelectedWIR(itemID);

    // maybe the wir isn't started or was part of a cancellation set and now it's gone
    if (selectedWIR == null) {
      msgPanel.error(
          "Cannot view item contents - it appears that the "
              + "selected item may have been removed or cancelled. "
              + "Please see the log files for details.");
      return null;
    }

    _sb.setDynFormType(ApplicationBean.DynFormType.tasklevel);
    DynamicForm df = (DynamicForm) getBean("DynFormFactory");
    String title = "YAWL 3.0 - Edit Work Item";
    String header = "Edit Work Item: " + selectedWIR.getCaseID();
    if (df.makeForm(title, header, _sb.getTaskSchema(selectedWIR), selectedWIR)) {
      _sb.setVisualiserReferred(true);
      _sb.setVisualiserEditedWIR(selectedWIR);
      return "showDynForm";
    } else {
      msgPanel.error(
          "Cannot view item contents - problem initialising "
              + "dynamic form from task specification. "
              + "Please see the log files for details.");
      return null;
    }
  }
Ejemplo n.º 3
0
 public void clearAllFieldsAndLists() {
   clearTextFields();
   clearCombos();
   _sb.setNhResourcesCategoryItems(null);
   _sb.setNhResourcesSubcategoryItems(null); // resource tab combo box
   _sb.setNhResourcesSubcategoryList(null); // category tab list box
   lblMembers.setText("Members (0)");
 }
Ejemplo n.º 4
0
 /**
  * Initialise session data in the session bean
  *
  * @param userid the userid
  * @param handle the session handle supplied by the service
  */
 private void initSession(Participant p, String userid, String handle) {
   sb.setSessionhandle(handle);
   sb.setUserid(userid);
   if (!userid.equals("admin")) {
     sb.setParticipant(p);
     getApplicationBean().addLiveUser(userid);
   }
 }
Ejemplo n.º 5
0
 /* fills ui with the selected category's values */
 private void populateGUI(NonHumanCategory category) {
   if (category != null) {
     populateSimpleFields(category);
     _sb.setNhResourcesSubcategoryList(getSubCategoryList(category));
     int membership = _sb.setCategoryMembers(category);
     lblMembers.setText("Members (" + membership + ")");
   }
   _sb.setNhResourcesSubcategoryItems(null); // empty the resource tab combo box
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 7
0
 private void showForm(WorkItemRecord wir) {
   FormViewer form = new FormViewer(sb);
   String formURI = form.display(wir);
   if (formURI.startsWith("<failure>")) {
     showMessage(unwrap(formURI));
   } else {
     sb.setFormViewerInstance(form);
     sb.setRssFormWIR(wir);
     sb.setRssFormDisplay(true);
     if (formURI.equals("showDynForm")) formURI = "dynForm.jsp";
     redirect(formURI);
   }
 }
Ejemplo n.º 8
0
  private String validateCredentials(String userid, String password) {
    if (userid == null) {
      return "No userid was specified.";
    }
    if (password == null) {
      return "No password was specified.";
    }

    String loggedOnUserID = sb.getUserid();
    if (loggedOnUserID != null) {
      if (!loggedOnUserID.equals(userid)) {
        return "User '"
            + loggedOnUserID
            + "' is already logged on in this"
            + " browser instance (in another tab or window)."
            + " Only one user logon per browser "
            + " instance is possible. If you wish to view you work"
            + " queued items via your iGoogle Gadget, please "
            + " logout the currently logged on user first.";
      } else sb.setRssAlreadyLoggedOn(true);
    } else {
      if (rm == null) {
        return "Could not connect to work queue, service unavailable.";
      }
      Participant p = rm.getParticipantFromUserID(userid);
      if (p == null) {
        return "Unknown userid: " + userid;
      }
      if (!p.getPassword().equals(password)) {
        return "Incorrect password.";
      }
      if (!rm.hasOrgDataSource()) {
        msgPanel.error(
            "Missing or invalid organisational data source. The resource"
                + " service requires a connection to a valid data source"
                + " that contains organisational data. Please check the"
                + " settings of the 'OrgDataSource' parameter in the service's"
                + " web.xml to ensure a valid data source is set, and/or check"
                + " the configuration properties set for the data source.");
      }
      String handle = rm.login(userid, password, sb.getExternalSessionID());
      if (!rm.successful(handle)) {
        return (msgPanel.format(handle));
      }

      initSession(p, userid, handle);
    }
    return success; // successful login
  }
Ejemplo n.º 9
0
  /* saves updates to the values of the selected resource or category */
  public boolean saveChanges(String id) {
    String activeTab = _sb.getActiveTab();
    if (activeTab.equals("tabResources")) return saveResourceChanges(id);
    else if (activeTab.equals("tabCategories")) return saveCategoryChanges(id);

    return false;
  }
Ejemplo n.º 10
0
 protected void updateSelectedResource(NonHumanResource resource, boolean editing) {
   try {
     _sb.setSelectedNonHumanResource(resource, editing);
   } catch (CloneNotSupportedException cnse) {
     _msgPanel.error("Could not update form: cloning Exception");
   }
 }
Ejemplo n.º 11
0
  /* saves updates to the values of the currently selected resource */
  public boolean saveResourceChanges(String id) {
    NonHumanResource cloned = _sb.getSelectedNonHumanResource();
    if (cloned == null) {
      _msgPanel.error("Could not retrieve changes from session");
      return false;
    }
    NonHumanResource resource = _orgDataSet.getNonHumanResource(id);
    if (resource == null) {
      _msgPanel.error("Invalid resource id: " + id);
      return false;
    }

    // check that any name change is valid
    String name = (String) txtName.getText();
    if ((!name.equals(resource.getName())) && _orgDataSet.isKnownNonHumanResourceName(name)) {
      addDuplicationError("Resource");
      return false;
    }
    storeSimpleFieldValues(cloned);
    resource.merge(cloned); // update resource with clone's values
    cloned.clearCategory(); // remove cloned from its category
    _orgDataSet.updateNonHumanResource(resource);
    updateSelectedResource(resource);
    return true;
  }
Ejemplo n.º 12
0
 /* triggered by resources tab only */
 public void cbbSubCategory_processValueChange(ValueChangeEvent event) {
   NonHumanResource resource = _sb.getSelectedNonHumanResource();
   if (resource != null) {
     storeSimpleFieldValues(resource);
     resource.setSubCategory((String) event.getNewValue());
   }
 }
Ejemplo n.º 13
0
  // it was necessary to do it this way rather than using 'jsp:plugin' in the
  // jsf because the 'codebase' parameter does not support dynamic value setting
  public String getAppletHtml() {
    String baseURI = getApplicationBean().getResServiceBaseURI();
    Participant p = _sb.getParticipant();
    Dimension view = getViewSize();
    StringBuilder result = new StringBuilder("<applet width=\"");
    result
        .append(view.width)
        .append("\" height=\"")
        .append(view.height)
        .append("\"")
        .append(" archive=\"visualiser.jar,javax.servlet.jar,jdom-2.0.5.jar,")
        .append(" resourceService.jar,saxon9.jar,log4j-1.2.16.jar,commons-codec-1.9.jar\"")
        .append(" codebase=\"../../visualiserApplet\"")
        .append(" code=\"worklist.WRKLApplet.class\" MAYSCRIPT>")
        .append(" <param name=\"user\" value=\"")
        .append(p.getUserID())
        .append("\"/>")
        .append(" <param name=\"pass\" value=\"")
        .append(p.getPassword())
        .append("\"/>")
        .append(" <param name=\"urYAWL\" value=\"")
        .append(baseURI)
        .append("\"/>")
        .append("</applet>");

    return result.toString();
  }
Ejemplo n.º 14
0
 /* returns the value of the first listed category, sorted */
 private NonHumanCategory getFirstListedCategory() {
   Option[] catItems = _sb.getNhResourcesCategoryList();
   if ((catItems != null) && (catItems.length > 0)) {
     String catID = (String) catItems[0].getValue();
     return _orgDataSet.getNonHumanCategory(catID);
   }
   return null;
 }
Ejemplo n.º 15
0
 protected void populateGUI(String id, nonHumanMgt.SelType type) {
   switch (type) {
     case resource:
       populateGUI(_sb.getSelectedNonHumanResource(), id);
       break;
     case category:
       populateGUI(_orgDataSet.getNonHumanCategory(id));
       break;
   }
   lbxItems.setSelected(id);
 }
Ejemplo n.º 16
0
 /* triggered by resources tab only */
 public void cbbCategory_processValueChange(ValueChangeEvent event) {
   NonHumanResource resource = _sb.getSelectedNonHumanResource();
   if (resource != null) {
     storeSimpleFieldValues(resource);
     NonHumanCategory category = _orgDataSet.getNonHumanCategory((String) event.getNewValue());
     if (category != null) {
       resource.setCategory(category);
       resource.setSubCategory("None");
     }
   }
 }
Ejemplo n.º 17
0
 private WorkItemRecord getSelectedWIR(String itemID) {
   Set<WorkItemRecord> wirSet = _sb.getQueue(WorkQueue.STARTED);
   WorkItemRecord selectedWIR = null;
   for (WorkItemRecord wir : wirSet) {
     if (wir.getID().equals(itemID)) {
       selectedWIR = wir;
       break;
     }
   }
   return selectedWIR;
 }
Ejemplo n.º 18
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
  }
Ejemplo n.º 19
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;
 }
Ejemplo n.º 20
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;
  }
Ejemplo n.º 21
0
  /* saves a newly added resource to the org database */
  public boolean addResource(String name) {
    if (!_orgDataSet.isKnownNonHumanResourceName(name)) {
      String catID = (String) cbbCategory.getSelected();
      NonHumanCategory category = _orgDataSet.getNonHumanCategory(catID);
      String subCat = (String) cbbSubCategory.getSelected();

      NonHumanResource resource = _sb.getSelectedNonHumanResource();
      if (resource == null) resource = new NonHumanResource();
      resource.setName(name);
      resource.setCategory(category);
      resource.setSubCategory(subCat);
      resource.setDescription((String) txtDesc.getText());
      resource.setNotes((String) txtNotes.getText());
      String newID = _orgDataSet.addNonHumanResource(resource);
      if (_rm.successful(newID)) {
        updateSelectedResource(resource, false);
        _sb.setNhResourcesChoice(newID);
        return true;
      } else _msgPanel.error(_msgPanel.format(newID));
    } else addDuplicationError("Resource");

    return false;
  }
Ejemplo n.º 22
0
 /* enable or disable fields depending on whether we are in browse/edit or add mode */
 public void setAddMode(boolean adding, String selectedTab) {
   lbxItems.setDisabled(adding);
   if (selectedTab.equals("tabCategories")) {
     lbxSubCatItems.setDisabled(adding);
     btnAddSubCat.setDisabled(adding);
     btnRemoveSubCat.setDisabled(adding);
     disableInputFields(!adding);
     disableSubCatButtons(adding);
     _sb.setCategoryMembers(null);
   }
   if (adding) clearTextFields();
   txtName.setText("");
   lblMembers.setText("Members (0)");
 }
Ejemplo n.º 23
0
  public void prerender() {
    if (sb.isRssFormDisplay()) {
      String msg = "";
      FormViewer form = sb.getFormViewerInstance();
      if (form != null) {
        msg = form.postDisplay(sb.getRssFormWIR());
        sb.resetPostFormDisplay();
        if (successful(msg)) {
          msg = "Work Item successfully processed.";
        }
      } else {
        msg = "Unsuccessful form completion - could not finalise form.";
      }
      showMessage(msg + " Please click the button below to close this window/tab.");
    } else {
      HttpServletRequest request = getRequest();
      String userid = request.getParameter("userid");
      String password = request.getParameter("password");
      String itemid = request.getParameter("itemid");

      String msg = validateCredentials(userid, password);
      WorkItemRecord wir = null;
      if (successful(msg)) {
        wir = rm.getWorkItemRecord(itemid);
        if (wir == null) {
          msg =
              "Unknown Work Item ID - perhaps it has already been actioned"
                  + " and/or moved to another queue. Please refresh your worklist.";
        }
      }
      if (successful(msg)) {
        startAndShow(userid, wir);
      } else {
        showMessage(msg);
      }
    }
  }
Ejemplo n.º 24
0
  /** updates a workitem after editing on a dynamic form */
  private void postEditWIR() {
    if (_sb.isWirEdit()) {
      WorkItemRecord wir = _sb.getVisualiserEditedWIR();
      if (wir != null) {
        Element data =
            JDOMUtil.stringToElement(((DynFormFactory) getBean("DynFormFactory")).getDataList());
        wir.setUpdatedData(data);
        _rm.getWorkItemCache().update(wir);

        if (_sb.isCompleteAfterEdit()) {
          completeWorkItem(wir, _sb.getParticipant());
        }
      } else {
        msgPanel.error("Could not complete workitem. Check log for details.");
      }
    }
    _sb.setWirEdit(false);
    _sb.setCompleteAfterEdit(false);
    _sb.setVisualiserReferred(false);
    _sb.setVisualiserEditedWIR(null);
    if (msgPanel.hasMessage()) forceRefresh();
  }
Ejemplo n.º 25
0
 /* checks if currently selected subcat may be removed. pre: in 'edit' mode */
 private boolean subCatUnremovable() {
   String subCatStr = _sb.getNhResourcesSubcategoryChoice();
   return (subCatStr == null) || subCatStr.equals("None");
 }
Ejemplo n.º 26
0
 /* triggered by categories tab only */
 public void lbxSubCatItems_processValueChange(ValueChangeEvent event) {
   _sb.setSourceTabAfterListboxSelection();
 }
Ejemplo n.º 27
0
 /* set mode to add a new subcategory - triggered by categories tab only */
 public String btnAddSubCat_action() {
   _sb.setSubCatAddMode(true);
   setSubCatAddMode(true);
   return null;
 }
Ejemplo n.º 28
0
public class pfNHResources extends AbstractFragmentBean {
  private int __placeholder;

  private void _init() throws Exception {}

  private Listbox lbxItems = new Listbox();

  public Listbox getLbxItems() {
    return lbxItems;
  }

  public void setLbxItems(Listbox l) {
    this.lbxItems = l;
  }

  private Label lblItems = new Label();

  public Label getLblItems() {
    return lblItems;
  }

  public void setLblItems(Label l) {
    this.lblItems = l;
  }

  private Label lblName = new Label();

  public Label getLblName() {
    return lblName;
  }

  public void setLblName(Label l) {
    this.lblName = l;
  }

  private TextField txtName = new TextField();

  public TextField getTxtName() {
    return txtName;
  }

  public void setTxtName(TextField tf) {
    this.txtName = tf;
  }

  private Label lblCategory = new Label();

  public Label getLblCategory() {
    return lblCategory;
  }

  public void setLblCategory(Label l) {
    this.lblCategory = l;
  }

  private Label lblDesc = new Label();

  public Label getLblDesc() {
    return lblDesc;
  }

  public void setLblDesc(Label l) {
    this.lblDesc = l;
  }

  private Label lblNotes = new Label();

  public Label getLblNotes() {
    return lblNotes;
  }

  public void setLblNotes(Label l) {
    this.lblNotes = l;
  }

  private TextArea txtDesc = new TextArea();

  public TextArea getTxtDesc() {
    return txtDesc;
  }

  public void setTxtDesc(TextArea ta) {
    this.txtDesc = ta;
  }

  private TextArea txtNotes = new TextArea();

  public TextArea getTxtNotes() {
    return txtNotes;
  }

  public void setTxtNotes(TextArea ta) {
    this.txtNotes = ta;
  }

  private DropDown cbbCategory = new DropDown();

  public DropDown getCbbCategory() {
    return cbbCategory;
  }

  public void setCbbCategory(DropDown dd) {
    this.cbbCategory = dd;
  }

  private DropDown cbbSubCategory = new DropDown();

  public DropDown getCbbSubCategory() {
    return cbbSubCategory;
  }

  public void setCbbSubCategory(DropDown dd) {
    this.cbbSubCategory = dd;
  }

  private Label lblSubCategory = new Label();

  public Label getLblSubCategory() {
    return lblSubCategory;
  }

  public void setLblSubCategory(Label l) {
    this.lblSubCategory = l;
  }

  private DropDown cbbMembers = new DropDown();

  public DropDown getCbbMembers() {
    return cbbMembers;
  }

  public void setCbbMembers(DropDown dd) {
    this.cbbMembers = dd;
  }

  private Label lblMembers = new Label();

  public Label getLblMembers() {
    return lblMembers;
  }

  public void setLblMembers(Label l) {
    this.lblMembers = l;
  }

  private Listbox lbxSubCatItems = new Listbox();

  public Listbox getLbxSubCatItems() {
    return lbxSubCatItems;
  }

  public void setLbxSubCatItems(Listbox l) {
    this.lbxSubCatItems = l;
  }

  private TextField txtSubCat = new TextField();

  public TextField getTxtSubCat() {
    return txtSubCat;
  }

  public void setTxtSubCat(TextField tf) {
    this.txtSubCat = tf;
  }

  private Button btnRemoveSubCat = new Button();

  public Button getBtnRemoveSubCat() {
    return btnRemoveSubCat;
  }

  public void setBtnRemoveSubCat(Button b) {
    btnRemoveSubCat = b;
  }

  private Button btnAddSubCat = new Button();

  public Button getBtnAddSubCat() {
    return btnAddSubCat;
  }

  public void setBtnAddSubCat(Button b) {
    btnAddSubCat = b;
  }

  private Button btnConfirmAddSubCat = new Button();

  public Button getBtnConfirmAddSubCat() {
    return btnConfirmAddSubCat;
  }

  public void setBtnConfirmAddSubCat(Button b) {
    btnConfirmAddSubCat = b;
  }

  private Button btnCancelAddSubCat = new Button();

  public Button getBtnCancelAddSubCat() {
    return btnCancelAddSubCat;
  }

  public void setBtnCancelAddSubCat(Button b) {
    btnCancelAddSubCat = b;
  }

  /** ****************************************************** */
  public pfNHResources() {}

  /** Return a reference to the scoped data bean. */
  protected RequestBean getRequestBean() {
    return (RequestBean) getBean("RequestBean");
  }

  /** Return a reference to the scoped data bean. */
  protected SessionBean getSessionBean() {
    return (SessionBean) getBean("SessionBean");
  }

  /** Return a reference to the scoped data bean. */
  protected ApplicationBean getApplicationBean() {
    return (ApplicationBean) getBean("ApplicationBean");
  }

  public void init() {
    // Perform initializations inherited from our superclass
    super.init();

    // *Note* - this logic should NOT be modified
    try {
      _init();
    } catch (Exception e) {
      log("pfNHResources Initialization Failure", e);
      throw e instanceof FacesException ? (FacesException) e : new FacesException(e);
    }
  }

  public void destroy() {}

  private SessionBean _sb = getSessionBean();
  private MessagePanel _msgPanel = _sb.getMessagePanel();
  private ResourceManager _rm = getApplicationBean().getResourceManager();
  private ResourceDataSet _orgDataSet = _rm.getOrgDataSet();

  /* triggered by both tabs */
  public void lbxItems_processValueChange(ValueChangeEvent event) {
    _sb.setSourceTabAfterListboxSelection();
    updateSelectedResource(null); // resets currently selected
  }

  /* triggered by categories tab only */
  public void lbxSubCatItems_processValueChange(ValueChangeEvent event) {
    _sb.setSourceTabAfterListboxSelection();
  }

  /* triggered by resources tab only */
  public void cbbCategory_processValueChange(ValueChangeEvent event) {
    NonHumanResource resource = _sb.getSelectedNonHumanResource();
    if (resource != null) {
      storeSimpleFieldValues(resource);
      NonHumanCategory category = _orgDataSet.getNonHumanCategory((String) event.getNewValue());
      if (category != null) {
        resource.setCategory(category);
        resource.setSubCategory("None");
      }
    }
  }

  /* triggered by resources tab only */
  public void cbbSubCategory_processValueChange(ValueChangeEvent event) {
    NonHumanResource resource = _sb.getSelectedNonHumanResource();
    if (resource != null) {
      storeSimpleFieldValues(resource);
      resource.setSubCategory((String) event.getNewValue());
    }
  }

  /* set mode to add a new subcategory - triggered by categories tab only */
  public String btnAddSubCat_action() {
    _sb.setSubCatAddMode(true);
    setSubCatAddMode(true);
    return null;
  }

  /* 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;
  }

  /* 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;
  }

  /* reset mode to browse/edit for subcategories - triggered by categories tab only */
  public String btnCancelAddSubCat_action() {
    _sb.setSubCatAddMode(false);
    return null;
  }

  protected void populateGUI(String id, nonHumanMgt.SelType type) {
    switch (type) {
      case resource:
        populateGUI(_sb.getSelectedNonHumanResource(), id);
        break;
      case category:
        populateGUI(_orgDataSet.getNonHumanCategory(id));
        break;
    }
    lbxItems.setSelected(id);
  }

  /* 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
  }

  /* fills ui with the selected category's values */
  private void populateGUI(NonHumanCategory category) {
    if (category != null) {
      populateSimpleFields(category);
      _sb.setNhResourcesSubcategoryList(getSubCategoryList(category));
      int membership = _sb.setCategoryMembers(category);
      lblMembers.setText("Members (" + membership + ")");
    }
    _sb.setNhResourcesSubcategoryItems(null); // empty the resource tab combo box
  }

  /* sets or hides fields depending on which tab is shown */
  public void setVisibleComponents(nonHumanMgt.SelType sType) {
    boolean catTab = (sType == nonHumanMgt.SelType.category);

    // these only appear on the resources tab
    cbbCategory.setVisible(!catTab);
    lblSubCategory.setVisible(!catTab);
    cbbSubCategory.setVisible(!catTab);

    // these only appear on the categories tab
    lblMembers.setVisible(catTab);
    cbbMembers.setVisible(catTab);
    lbxSubCatItems.setVisible(catTab);
    btnAddSubCat.setVisible(catTab);
    btnRemoveSubCat.setVisible(catTab);

    // nullify lists
    if (catTab) {
      cbbCategory.setItems(null);
      cbbSubCategory.setItems(null);
    } else lbxSubCatItems.setItems(null);
  }

  /* enable or disable fields depending on whether we are in browse/edit or add mode */
  public void setAddMode(boolean adding, String selectedTab) {
    lbxItems.setDisabled(adding);
    if (selectedTab.equals("tabCategories")) {
      lbxSubCatItems.setDisabled(adding);
      btnAddSubCat.setDisabled(adding);
      btnRemoveSubCat.setDisabled(adding);
      disableInputFields(!adding);
      disableSubCatButtons(adding);
      _sb.setCategoryMembers(null);
    }
    if (adding) clearTextFields();
    txtName.setText("");
    lblMembers.setText("Members (0)");
  }

  /* saves updates to the values of the selected resource or category */
  public boolean saveChanges(String id) {
    String activeTab = _sb.getActiveTab();
    if (activeTab.equals("tabResources")) return saveResourceChanges(id);
    else if (activeTab.equals("tabCategories")) return saveCategoryChanges(id);

    return false;
  }

  /* saves updates to the values of the currently selected resource */
  public boolean saveResourceChanges(String id) {
    NonHumanResource cloned = _sb.getSelectedNonHumanResource();
    if (cloned == null) {
      _msgPanel.error("Could not retrieve changes from session");
      return false;
    }
    NonHumanResource resource = _orgDataSet.getNonHumanResource(id);
    if (resource == null) {
      _msgPanel.error("Invalid resource id: " + id);
      return false;
    }

    // check that any name change is valid
    String name = (String) txtName.getText();
    if ((!name.equals(resource.getName())) && _orgDataSet.isKnownNonHumanResourceName(name)) {
      addDuplicationError("Resource");
      return false;
    }
    storeSimpleFieldValues(cloned);
    resource.merge(cloned); // update resource with clone's values
    cloned.clearCategory(); // remove cloned from its category
    _orgDataSet.updateNonHumanResource(resource);
    updateSelectedResource(resource);
    return true;
  }

  /* 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;
  }

  /* saves a newly added resource or category to the org database */
  public boolean addNewItem(nonHumanMgt.SelType sType) {
    String newName = (String) txtName.getText();
    if ((newName == null) || (newName.length() == 0)) {
      _msgPanel.error("Please enter a name for the new Item.");
      return false;
    }
    switch (sType) {
      case resource:
        return addResource(newName);
      case category:
        return addCategory(newName);
    }
    return false;
  }

  /* saves a newly added resource to the org database */
  public boolean addResource(String name) {
    if (!_orgDataSet.isKnownNonHumanResourceName(name)) {
      String catID = (String) cbbCategory.getSelected();
      NonHumanCategory category = _orgDataSet.getNonHumanCategory(catID);
      String subCat = (String) cbbSubCategory.getSelected();

      NonHumanResource resource = _sb.getSelectedNonHumanResource();
      if (resource == null) resource = new NonHumanResource();
      resource.setName(name);
      resource.setCategory(category);
      resource.setSubCategory(subCat);
      resource.setDescription((String) txtDesc.getText());
      resource.setNotes((String) txtNotes.getText());
      String newID = _orgDataSet.addNonHumanResource(resource);
      if (_rm.successful(newID)) {
        updateSelectedResource(resource, false);
        _sb.setNhResourcesChoice(newID);
        return true;
      } else _msgPanel.error(_msgPanel.format(newID));
    } else addDuplicationError("Resource");

    return false;
  }

  /* 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;
  }

  private void addDuplicationError(String type) {
    String dupErrMsg = "There is already a %s by that name - please choose another.";
    _msgPanel.error(String.format(dupErrMsg, type));
  }

  public void clearTextFields() {
    txtDesc.setText("");
    txtNotes.setText("");
  }

  public void clearFieldsAfterRemove() {
    clearTextFields();
    lbxItems.setSelected(getFirstListboxItem());
  }

  public void clearAllFieldsAndLists() {
    clearTextFields();
    clearCombos();
    _sb.setNhResourcesCategoryItems(null);
    _sb.setNhResourcesSubcategoryItems(null); // resource tab combo box
    _sb.setNhResourcesSubcategoryList(null); // category tab list box
    lblMembers.setText("Members (0)");
  }

  protected void clearCombos() {
    cbbCategory.setSelected(null);
    cbbSubCategory.setSelected(null);
    cbbCategory.setItems(null);
    cbbSubCategory.setItems(null);
  }

  /* returns the value of the first item in the listbox, if any */
  private String getFirstListboxItem() {
    Option[] items = (Option[]) lbxItems.getItems();
    if ((items != null) && items.length > 0) {
      Option item = items[0];
      if (item != null) return (String) item.getValue();
    }
    return null;
  }

  /* returns the value of the first listed category, sorted */
  private NonHumanCategory getFirstListedCategory() {
    Option[] catItems = _sb.getNhResourcesCategoryList();
    if ((catItems != null) && (catItems.length > 0)) {
      String catID = (String) catItems[0].getValue();
      return _orgDataSet.getNonHumanCategory(catID);
    }
    return null;
  }

  private void storeSimpleFieldValues(NonHumanResource resource) {
    String name = (String) txtName.getText();
    if ((name != null) && (name.length() > 0)) resource.setName(name);
    String desc = (String) txtDesc.getText();
    if (desc != null) resource.setDescription(desc);
    String notes = (String) txtNotes.getText();
    if (notes != null) resource.setNotes(notes);
  }

  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());
  }

  private void populateSimpleFields(NonHumanResource resource) {
    populateSimpleFields(resource.getName(), resource.getDescription(), resource.getNotes());
  }

  private void populateSimpleFields(NonHumanCategory category) {
    populateSimpleFields(category.getName(), category.getDescription(), category.getNotes());
  }

  private void populateSimpleFields(String name, String desc, String notes) {
    txtName.setText(name);
    txtDesc.setText(desc);
    txtNotes.setText(notes);
  }

  /* 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;
  }

  /* checks if currently selected subcat may be removed. pre: in 'edit' mode */
  private boolean subCatUnremovable() {
    String subCatStr = _sb.getNhResourcesSubcategoryChoice();
    return (subCatStr == null) || subCatStr.equals("None");
  }

  /* enables or disables fields depending on whether a sub category is being added */
  protected void setSubCatAddMode(boolean adding) {
    showSubCatAddFields(adding);
    disableInputFields(adding);
    lbxItems.setDisabled(adding);
    lbxSubCatItems.setDisabled(adding);
    //        btnAddSubCat.setDisabled(adding);
    //        btnRemoveSubCat.setDisabled(adding || subCatUnremovable());
  }

  protected void disableInputFields(boolean disable) {
    txtName.setDisabled(disable);
    txtDesc.setDisabled(disable);
    txtNotes.setDisabled(disable);
    cbbMembers.setDisabled(disable);
    cbbCategory.setDisabled(disable);
    cbbSubCategory.setDisabled(disable);
    btnAddSubCat.setDisabled(disable);
    btnRemoveSubCat.setDisabled(disable || subCatUnremovable());
  }

  protected void disableSubCatButtons(boolean disable) {
    btnAddSubCat.setDisabled(disable);
    btnRemoveSubCat.setDisabled(disable || subCatUnremovable());
  }

  protected void showSubCatAddFields(boolean adding) {
    txtSubCat.setVisible(adding);
    btnConfirmAddSubCat.setVisible(adding);
    btnCancelAddSubCat.setVisible(adding);
  }

  protected void updateSelectedResource(NonHumanResource resource) {
    updateSelectedResource(resource, true);
  }

  protected void updateSelectedResource(NonHumanResource resource, boolean editing) {
    try {
      _sb.setSelectedNonHumanResource(resource, editing);
    } catch (CloneNotSupportedException cnse) {
      _msgPanel.error("Could not update form: cloning Exception");
    }
  }

  protected void createNewResource() {
    NonHumanResource resource = new NonHumanResource();
    resource.setID("_TEMP_");
    NonHumanCategory category = getFirstListedCategory();
    if (category != null) {
      resource.setCategory(category);
    }
    updateSelectedResource(resource);
  }

  private NonHumanCategory getCurrentlySelectedCategory() {
    String catID = _sb.getNhResourcesChoice(); // get selected category id
    return (catID != null) ? _orgDataSet.getNonHumanCategory(catID) : null;
  }
}
Ejemplo n.º 29
0
 private NonHumanCategory getCurrentlySelectedCategory() {
   String catID = _sb.getNhResourcesChoice(); // get selected category id
   return (catID != null) ? _orgDataSet.getNonHumanCategory(catID) : null;
 }
Ejemplo n.º 30
0
 /* reset mode to browse/edit for subcategories - triggered by categories tab only */
 public String btnCancelAddSubCat_action() {
   _sb.setSubCatAddMode(false);
   return null;
 }