private NumberValues createNumberValues() { NumberValues nv = new NumberValues(); nv.setColumnOneNumber(100); // the value which should be used as 100% nv.setColumnTwoNumber(20); // the value 1 for calculation nv.setColumnThreeNumber(30); // the value 2 for calculation // as column 4 and 5 should be calculated values, we don't set them to the NumberValues object return nv; }
/* (non-Javadoc) * @see org.eclipse.nebula.widgets.nattable.data.IColumnAccessor#getDataValue(java.lang.Object, int) */ @Override public Object getDataValue(NumberValues rowObject, int columnIndex) { switch (columnIndex) { case 0: return rowObject.getColumnOneNumber(); case 1: return rowObject.getColumnTwoNumber(); case 2: return rowObject.getColumnThreeNumber(); } return null; }
/* (non-Javadoc) * @see org.eclipse.nebula.widgets.nattable.data.IColumnAccessor#setDataValue(java.lang.Object, int, java.lang.Object) */ public void setDataValue(NumberValues rowObject, int columnIndex, Object newValue) { // because of the registered conversion, the new value has to be an Integer switch (columnIndex) { case 0: rowObject.setColumnOneNumber((Integer) newValue); break; case 1: rowObject.setColumnTwoNumber((Integer) newValue); break; case 2: rowObject.setColumnThreeNumber((Integer) newValue); break; } }
/* (non-Javadoc) * @see org.eclipse.nebula.widgets.nattable.data.IColumnAccessor#getDataValue(java.lang.Object, int) */ public Object getDataValue(NumberValues rowObject, int columnIndex) { switch (columnIndex) { case 0: return rowObject.getColumnOneNumber(); case 1: return rowObject.getColumnTwoNumber(); case 2: return rowObject.getColumnThreeNumber(); case 3: // calculate the sum return rowObject.getColumnTwoNumber() + rowObject.getColumnThreeNumber(); case 4: // calculate the percentage return new Double(rowObject.getColumnTwoNumber() + rowObject.getColumnThreeNumber()) / rowObject.getColumnOneNumber(); } return null; }