use of org.apache.jorphan.reflect.Functor in project jmeter by apache.
the class TableEditor method initializeModel.
void initializeModel() {
Object hdrs = descriptor.getValue(HEADERS);
if (!(hdrs instanceof String[])) {
throw new RuntimeException("attribute HEADERS must be a String array");
}
if (clazz == String.class) {
model = new ObjectTableModel((String[]) hdrs, new Functor[0], new Functor[0], new Class[] { String.class });
} else {
Object value = descriptor.getValue(OBJECT_PROPERTIES);
if (!(value instanceof String[])) {
throw new RuntimeException("attribute OBJECT_PROPERTIES must be a String array");
}
String[] props = (String[]) value;
Functor[] writers = new Functor[props.length];
Functor[] readers = new Functor[props.length];
Class<?>[] editors = new Class[props.length];
int count = 0;
for (String propName : props) {
propName = propName.substring(0, 1).toUpperCase(Locale.ENGLISH) + propName.substring(1);
writers[count] = createWriter(clazz, propName);
readers[count] = createReader(clazz, propName);
editors[count] = getArgForWriter(clazz, propName);
count++;
}
model = new ObjectTableModel((String[]) hdrs, readers, writers, editors);
}
model.addTableModelListener(this);
table = new JTable(model);
JMeterUtils.applyHiDPI(table);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.addFocusListener(this);
}
use of org.apache.jorphan.reflect.Functor in project jmeter by apache.
the class SavePropertyDialog method initDialog.
private void initDialog() {
this.getContentPane().setLayout(new BorderLayout());
final int configCount = (SampleSaveConfiguration.SAVE_CONFIG_NAMES.size() / 3) + 1;
log.debug("grid panel is {} by {}", 3, configCount);
JPanel checkPanel = new JPanel(new GridLayout(configCount, 3));
for (final String name : SampleSaveConfiguration.SAVE_CONFIG_NAMES) {
try {
JCheckBox check = new JCheckBox(JMeterUtils.getResString(RESOURCE_PREFIX + name), getSaveState(SampleSaveConfiguration.getterName(name)));
check.addActionListener(this);
// $NON-NLS-1$
final String actionCommand = SampleSaveConfiguration.setterName(name);
check.setActionCommand(actionCommand);
if (!functors.containsKey(actionCommand)) {
functors.put(actionCommand, new Functor(actionCommand));
}
checkPanel.add(check, BorderLayout.NORTH);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
log.warn("Problem creating save config dialog", e);
}
}
getContentPane().add(checkPanel, BorderLayout.NORTH);
// $NON-NLS-1$
JButton exit = new JButton(JMeterUtils.getResString("done"));
this.getContentPane().add(exit, BorderLayout.SOUTH);
exit.addActionListener(e -> dispose());
}
use of org.apache.jorphan.reflect.Functor in project jmeter by apache.
the class SavePropertyDialog method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
String action = e.getActionCommand();
Functor f = functors.get(action);
f.invoke(saveConfig, new Object[] { Boolean.valueOf(((JCheckBox) e.getSource()).isSelected()) });
}
Aggregations