/** Provides the empty String if attribute doesn't exist. */ @Override public Object getValueAt(int row, int col) { // get roster entry for row RosterEntry re = Roster.getDefault().getGroupEntry(rosterGroup, row); if (re == null) { log.debug("roster entry is null!"); return null; } switch (col) { case IDCOL: return re.getId(); case ADDRESSCOL: return re.getDccLocoAddress().getNumber(); case DECODERCOL: return re.getDecoderModel(); case MODELCOL: return re.getModel(); case ROADNAMECOL: return re.getRoadName(); case ROADNUMBERCOL: return re.getRoadNumber(); case MFGCOL: return re.getMfg(); case ICONCOL: return getIcon(re); case OWNERCOL: return re.getOwner(); case DATEUPDATECOL: return re.getDateUpdated(); case PROTOCOL: return re.getProtocolAsString(); default: break; } String value = re.getAttribute(getColumnName(col).replaceAll("\\s", "")); // NOI18N if (value != null) { return value; } return ""; }
@Override public void setValueAt(Object value, int row, int col) { // get roster entry for row RosterEntry re = Roster.getDefault().getGroupEntry(rosterGroup, row); if (re == null) { log.warn("roster entry is null!"); return; } if (re.isOpen()) { log.warn("Entry is already open"); return; } String valueToSet = (String) value; switch (col) { case IDCOL: if (re.getId().equals(valueToSet)) { return; } re.setId(valueToSet); break; case ROADNAMECOL: if (re.getRoadName().equals(valueToSet)) { return; } re.setRoadName(valueToSet); break; case ROADNUMBERCOL: if (re.getRoadNumber().equals(valueToSet)) { return; } re.setRoadNumber(valueToSet); break; case MFGCOL: if (re.getMfg().equals(valueToSet)) { return; } re.setMfg(valueToSet); break; case MODELCOL: if (re.getModel().equals(valueToSet)) { return; } re.setModel(valueToSet); break; case OWNERCOL: if (re.getOwner().equals(valueToSet)) { return; } re.setOwner(valueToSet); break; default: String attributeName = (getColumnName(col)).replaceAll("\\s", ""); if (re.getAttribute(attributeName) != null && re.getAttribute(attributeName).equals(valueToSet)) { return; } if ((valueToSet == null) || valueToSet.isEmpty()) { re.deleteAttribute(attributeName); } else { re.putAttribute(attributeName, valueToSet); } break; } // need to mark as updated re.changeDateUpdated(); re.updateFile(); }