public ArrayList<Specialty> listSpecialties(Specialty filterLookup)
      throws DomainInterfaceException {
    if (filterLookup == null)
      throw new DomainInterfaceException("Can not search on null speciality filter");

    ArrayList<Specialty> specialtiesList = new ArrayList<Specialty>();

    ArrayList<String> searchWords = new ArrayList<String>();

    filterLookup.setText(filterLookup.getText().replaceAll(" ", "%"));
    String[] split = filterLookup.getText().split("%");

    for (int i = split.length - 1; i >= 0; i--) {
      if (!(split[i].equalsIgnoreCase(""))) searchWords.add(split[i]);
    }

    LookupService lookup = this.getLookupService();
    SpecialtyCollection collection =
        (SpecialtyCollection)
            lookup.getLookupCollection(
                Specialty.TYPE_ID, SpecialtyCollection.class, Specialty.class);

    for (int i = 0; i < collection.size(); i++) {
      Specialty specialty = collection.get(i);

      if (containsText(specialty, searchWords)) specialtiesList.add(specialty);
    }

    return specialtiesList;
  }
  protected final void oncmbSpecialtyValueSet(Object value) {
    java.util.ArrayList listOfValues =
        this.form.lyrMappings().tabExternal().cmbSpecialty().getValues();

    if (value == null) {
      if (listOfValues != null && listOfValues.size() > 0) {
        for (int x = 0; x < listOfValues.size(); x++) {
          ims.core.vo.lookups.Specialty existingInstance =
              (ims.core.vo.lookups.Specialty) listOfValues.get(x);
          if (!existingInstance.isActive()) {
            bindcmbSpecialtyLookup();
            return;
          }
        }
      }
    } else if (value instanceof ims.core.vo.lookups.Specialty) {
      ims.core.vo.lookups.Specialty instance = (ims.core.vo.lookups.Specialty) value;

      if (listOfValues != null) {
        if (listOfValues.size() == 0) bindcmbSpecialtyLookup();

        for (int x = 0; x < listOfValues.size(); x++) {
          ims.core.vo.lookups.Specialty existingInstance =
              (ims.core.vo.lookups.Specialty) listOfValues.get(x);
          if (existingInstance.equals(instance)) return;
        }
      }

      this.form
          .lyrMappings()
          .tabExternal()
          .cmbSpecialty()
          .newRow(instance, instance.getText(), instance.getImage(), instance.getTextColor());
    }
  }
  private boolean containsText(Specialty specialty, ArrayList<String> searchWords) {
    for (int i = 0; i < searchWords.size(); i++)
      if (specialty.getText().toUpperCase().indexOf(searchWords.get(i).toUpperCase()) == -1)
        return false;

    return true;
  }