public Component getListCellRendererComponent(
      JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {

    if (value instanceof WSIBox) {
      value = ((WSIBox) value).getTitle();
    }

    if (value instanceof TridasMeasurementSeries) {
      TridasMeasurementSeries ms = (TridasMeasurementSeries) value;
      TridasGenericField f = GenericFieldUtils.findField(ms, "tellervo.internal.labcodeText");

      value = (f != null) ? f.getValue() : ms.getTitle();
    }

    if (value instanceof TridasRadius) {
      TridasRadius r = (TridasRadius) value;
      TridasGenericField f = GenericFieldUtils.findField(r, "tellervo.internal.labcodeText");

      value = (f != null) ? f.getValue() : r.getTitle();
    }

    if (value instanceof TridasSample) {
      TridasSample s = (TridasSample) value;

      LabCode labcode = new LabCode();
      boolean set = false;
      if (GenericFieldUtils.findField(s, "tellervo.objectLabCode") != null) {
        labcode.appendSiteCode(GenericFieldUtils.findField(s, "tellervo.objectLabCode").getValue());
        if (GenericFieldUtils.findField(s, "tellervo.elementLabCode") != null) {
          labcode.setElementCode(
              GenericFieldUtils.findField(s, "tellervo.elementLabCode").getValue());
          labcode.setSampleCode(s.getTitle());
          set = true;
        }
      }

      if (set) {
        value = LabCodeFormatter.getRadiusPrefixFormatter().format(labcode);
      } else {
        TridasGenericField f = GenericFieldUtils.findField(s, "tellervo.internal.labcodeText");
        value = (f != null) ? f.getValue() : s.getTitle();
      }
    }

    if (value instanceof TridasElement) {
      TridasElement e = (TridasElement) value;
      TridasGenericField f = GenericFieldUtils.findField(e, "tellervo.internal.labcodeText");

      value = (f != null) ? f.getValue() : e.getTitle();
    }

    /*else
    {
    	System.out.println("The object type "+ value.getClass().toString()+" is unsupported in TridasListCellRenderer");
    }*/

    return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
  }
Exemplo n.º 2
0
 @Override
 public String getBoxID() {
   if (have(sample)) {
     TridasGenericField field = GenericFieldUtils.findField(sample, "tellervo.boxID");
     if (field != null) return field.getValue();
   }
   return null;
 }