in application/org.openjdk.jmc.rjmx.ui/src/main/java/org/openjdk/jmc/rjmx/ui/internal/AttributeConfiguratorTableFactory.java [185:265]
private static TypedEditingSupport<MRI> createTypeEditingSupport(
final AttributeSelectionViewModel viewModel, final AttributeSelectionContentModel selectorModel,
final Map<KindOfQuantity<?>, List<IUnit>> types, final TableViewer table, final Runnable listener) {
return new TypedEditingSupport<MRI>(table, MRI.class) {
@Override
public boolean canEdit(Object element) {
if (viewModel.getContentType() != null) {
return false;
}
if (element instanceof MRI) {
MRI mri = (MRI) element;
IMRIMetadata metadata = selectorModel.getMetadataService().getMetadata(mri);
if (!MRIMetadataToolkit.isNumerical(metadata)) {
return false;
}
return true;
}
return false;
}
@Override
protected CellEditor getCellEditorTyped(MRI attribute) {
return new AttributeComboBoxCellEditor(table.getTable(), getTypeDisplayNames());
}
private String[] getTypeDisplayNames() {
if (viewModel.getContentType() != null) {
return new String[] {viewModel.getContentType().getName()};
}
List<String> typeNames = new ArrayList<>(types.size());
for (KindOfQuantity<?> type : types.keySet()) {
typeNames.add(type.getName());
}
return typeNames.toArray(new String[typeNames.size()]);
}
@Override
protected Object getValueTyped(MRI attribute) {
IUnit unit = selectorModel.getAttributeUnit(attribute);
if (unit == null) {
return 0;
}
int index = 0;
for (KindOfQuantity<?> type : types.keySet()) {
if (type.equals(unit.getContentType())) {
return index;
}
index++;
}
return 0;
}
@Override
protected void setValueTyped(MRI attribute, Object value) {
if (!(value instanceof Number)) {
return;
}
ContentType<?> contentType = viewModel.getContentType();
if (contentType != null) {
if (contentType instanceof KindOfQuantity) {
selectorModel.setAttributeUnit(attribute, ((KindOfQuantity<?>) contentType).getDefaultUnit());
table.refresh();
}
return;
}
IUnit unit = null;
int index = ((Number) value).intValue();
int pos = 0;
for (KindOfQuantity<?> type : types.keySet()) {
if (pos == index) {
unit = type.getDefaultUnit();
break;
}
pos += 1;
}
selectorModel.setAttributeUnit(attribute, unit);
table.refresh();
listener.run();
}
};
}