/**
   * Sets the supplied data in the model.
   *
   * @param sample The sample to administrate in this model.
   * @return true if the data != null and the type of the data equals the type of this model.
   * @todo TODO: Compare data types.
   */
  public boolean setData(Sample sample) {
    UserData data;
    boolean result = false;

    if (sample != null) {
      data = sample.getMessage().getUserData();
      int rowCount = this.getRowCount();

      for (int i = 0; i < rowCount; i++) {
        String fieldName = (String) this.getValueAt(i, 1);
        String fieldValue = data.getFieldValue(fieldName);
        this.setValueAt(fieldValue, i, 2);
      }
      ud = data;
      result = true;
    }
    return result;
  }
Пример #2
0
  /**
   * Administrates the Sample info oof the supplied Sample. It replaces the possible previous info.
   *
   * @param data The Sample, which info must be administrated.
   * @return true if the supplied Sample and its Message are not null, false otherwise.
   */
  public boolean setData(Sample data) {
    currentValue = data;
    boolean success = false;

    if (enabled) {
      Message msg = data.getMessage();
      int row = 0;

      if (msg != null) {
        State state = data.getState();

        this.setValueAt(this.getSampleState(state), row++, 1);
        this.setValueAt(this.getViewState(state), row++, 1);
        this.setValueAt(this.getInstanceState(state), row++, 1);
        this.setValueAt(this.getValidDataState(state), row++, 1);
        this.setValueAt(Long.toString(data.getDisposeCount()), row++, 1);
        this.setValueAt(Long.toString(data.getNoWritersCount()), row++, 1);

        String date = "(" + new Date(data.getInsertTimeSec() * 1000) + ")";
        this.setValueAt(
            Long.toString(data.getInsertTimeSec())
                + "s. "
                + Long.toString(data.getInsertTimeNanoSec())
                + "ns. "
                + date,
            row++,
            1);

        date = "(" + new Date(msg.getWriteTimeSec() * 1000) + ")";
        this.setValueAt(
            Long.toString(msg.getWriteTimeSec())
                + "s. "
                + Long.toString(msg.getWriteTimeNanoSec())
                + "ns. "
                + date,
            row++,
            1);

        long sec = data.getInsertTimeSec() - msg.getWriteTimeSec();
        long nsec = data.getInsertTimeNanoSec() - msg.getWriteTimeNanoSec();

        if (nsec < 0) {
          sec--;

          String strNsec = Long.toString(nsec);
          StringBuffer buf = new StringBuffer();
          buf.append("1");
          for (int i = 0; i < (strNsec.length() - 1); i++) {
            buf.append("0");
          }
          String strOne = buf.toString();

          long one = Long.parseLong(strOne);

          /*Add up, because nsec is negative.*/
          nsec = one + nsec;
        }

        this.setValueAt(Long.toString(sec) + "s. " + Long.toString(nsec) + "ns.", row++, 1);

        GID gid = msg.getWriterGid();

        if (gid != null) {
          this.setValueAt(Long.toString(gid.getLocalId()), row++, 1);
          this.setValueAt(Long.toString(gid.getSystemId()), row++, 1);
        } else {
          this.setValueAt("N/A", row++, 1);
          this.setValueAt("N/A", row++, 1);
          this.setValueAt("N/A", row++, 1);
        }
        gid = msg.getInstanceGid();

        if (gid != null) {
          this.setValueAt(Long.toString(gid.getLocalId()), row++, 1);
          this.setValueAt(Long.toString(gid.getSystemId()), row++, 1);
        } else {
          this.setValueAt("N/A", row++, 1);
          this.setValueAt("N/A", row++, 1);
          this.setValueAt("N/A", row++, 1);
        }
        this.setValueAt(Long.toString(msg.getSampleSequenceNumber()), row++, 1);

        if (msg.getQos() != null) {
          this.setValueAt(msg.getQos().getReliabilityKind().toString(), row++, 1);
        } else {
          this.setValueAt("N/A", row++, 1);
        }

        success = true;
      }
    } else {
      success = true;
    }
    return success;
  }
  public boolean setData(Sample sample, String colName, int index) {
    UserData data;
    boolean result = true;
    if (sample != null) {
      data = sample.getMessage().getUserData();
      int rowCount = this.getRowCount();
      if (data == null) {
        return false;
      }
      HashMap<String, ArrayList<String>> tableData = CollectSingleTableData(data, colName);
      for (int i = 0; i < rowCount; i++) {
        String fName = (String) this.getValueAt(i, 1);
        if (index >= 0) {
          if (fName.startsWith(colName)) {
            String tmp = fName.substring(colName.length());
            fName = colName + "[" + index + "]" + tmp;
          }
        }

        if (tableData.containsKey(fName)) {
          ArrayList<String> colVals = tableData.get(fName);
          if (index >= 0) {
            this.setValueAt(colVals.get(index), i, 2);
          } else {
            this.setValueAt(colVals.toString(), i, 2);
          }
        } else if (tableData.containsKey(colName)) {
          ArrayList<String> colVals = tableData.get(colName);
          if (index >= 0) {
            this.setValueAt(colVals.get(index), i, 2);
          } else {
            this.setValueAt(colVals.toString(), i, 2);
          }
        } else {
          LinkedHashSet<String> s = new LinkedHashSet<String>(data.getUserData().keySet());
          String value = null;
          for (String key : s) {
            if (key.startsWith(fName)) {
              if (value != null) {
                value = value + "," + data.getUserData().get(key);
              } else {
                value = data.getUserData().get(key);
              }
            }
          }
          if (value == null) {
            LinkedHashSet<String> td = new LinkedHashSet<String>(tableData.keySet());
            for (String key : td) {
              if (key.startsWith(fName)) {
                if (value != null) {
                  value = value + "," + tableData.get(key).toString();
                } else {
                  value = tableData.get(key).toString();
                }
              }
            }
          }
          this.setValueAt(value, i, 2);
        }
      }
      ud = data;
    }

    return result;
  }