Search in sources :

Example 6 with Functor

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);
}
Also used : JTable(javax.swing.JTable) ObjectTableModel(org.apache.jorphan.gui.ObjectTableModel) Functor(org.apache.jorphan.reflect.Functor)

Example 7 with Functor

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());
}
Also used : JCheckBox(javax.swing.JCheckBox) JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) JButton(javax.swing.JButton) Functor(org.apache.jorphan.reflect.Functor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 8 with Functor

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()) });
}
Also used : JCheckBox(javax.swing.JCheckBox) Functor(org.apache.jorphan.reflect.Functor)

Aggregations

Functor (org.apache.jorphan.reflect.Functor)8 JCheckBox (javax.swing.JCheckBox)2 BorderLayout (java.awt.BorderLayout)1 GridLayout (java.awt.GridLayout)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)1 Entry (java.util.Map.Entry)1 JButton (javax.swing.JButton)1 JPanel (javax.swing.JPanel)1 JTable (javax.swing.JTable)1 SampleSaveConfiguration (org.apache.jmeter.samplers.SampleSaveConfiguration)1 ObjectTableModel (org.apache.jorphan.gui.ObjectTableModel)1 Pattern (org.apache.oro.text.regex.Pattern)1 PatternMatcherInput (org.apache.oro.text.regex.PatternMatcherInput)1 Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)1 Before (org.junit.Before)1