Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Implement getResourceLabel()
    1. This method should return the name of the resource that represents the title/name of the component. The resource will have to be entered into Jmeters messages.properties file (and possibly translations as well).
  2. Create your gui. Whatever style you like, layout your gui. Your class ultimately extends Jpanel, so your layout must be in your class's own ContentPane. Do not hook up gui elements to your TestElement class via actions and events. Let swing's internal model hang onto all the data as much as you possibly can.
    1. Some standard gui stuff should be added to all Jmeter gui components:
      1. call setBorder(makeBorder()) for your class. This will give it the standard Jmeter border
      2. add the title pane via makeTitlePanel(). Usually this is the first thing added to your gui, and should be done in a Box vertical layout scheme, or with Jmeter's VerticalLayout class. Here is an example init() method: {{{private void
        No Format
        
        private void init()

        {
        
        {
            setLayout(new BorderLayout());

        
            setBorder(makeBorder());

...

      1. 
                
            Box box = Box.createVerticalBox();

...

      1. 
            box.add(makeTitlePanel());

...

      1. 
            box.add(makeSourcePanel());

...

      1. 
            add(box,BorderLayout.NORTH);

...

      1. 
            add(makeParameterPanel(),BorderLayout.CENTER);

...

      1. 
        }
         

...

      1. 1.#3 Implement public void configure(TestElement el)
    1. Be sure to call super.configure(e). This will populate some of the data for you, like the name of the element.
    2. Use this method to set data into your gui elements. Example: {{{public void
      No Format
      
      public void configure(TestElement el)

      {
      
      {
          super.configure(el);

      
          useHeaders.setSelected(el.getPropertyAsBoolean(RegexExtractor.USEHEADERS));

      
          useBody.setSelected(!el.getPropertyAsBoolean(RegexExtractor.USEHEADERS));

      
          regexField.setText(el.getPropertyAsString(RegexExtractor.REGEX));

      
          templateField.setText(el.getPropertyAsString(RegexExtractor.TEMPLATE));

      
          defaultField.setText(el.getPropertyAsString(RegexExtractor.DEFAULT));

      
          matchNumberField.setText(el.getPropertyAsString(RegexExtractor.MATCH_NUM));

      
          refNameField.setText(el.getPropertyAsString(RegexExtractor.REFNAME));

      }
      }}}
      
      }
      
      1.#4 implement public void modifyTestElement(TestElement e). This is where you move the data from your gui elements to the TestElement. It is the logical reverse of the previous method.
    3. Call super.configureTestElement(e). This will take care of some default data for you.
    4. Example: {{{public void
      No Format
      
      public void modifyTestElement(TestElement e)

      {
      
      {
          super.configureTestElement(e);

      
          e.setProperty(new BooleanProperty(RegexExtractor.USEHEADERS,useHeaders.isSelected()));

      
          e.setProperty(RegexExtractor.MATCH_NUMBER,matchNumberField.getText());

      
          if(e instanceof RegexExtractor)

      {
      RegexExtractor regex =
      
          {
              RegexExtractor regex = (RegexExtractor)e;

      
              regex.setRefName(refNameField.getText());

      
              regex.setRegex(regexField.getText());

      
              regex.setTemplate(templateField.getText());

      
              regex.setDefaultValue(defaultField.getText());

      }
      }
      }}}
      
          }
      }
      
      1.#5 implement public TestElement createTestElement(). This method should create a new instance of your TestElement class, and then pass it to the modifyTestElement(TestElement) method you made above. {{{public TestElement
      No Format
      
      public TestElement createTestElement()

      {
      RegexExtractor extractor = new
      
      {
          RegexExtractor extractor = new RegexExtractor();

      
          modifyTestElement(extractor);

      
          return extractor;

      }
      }}}
      
      }
      

The reason you cannot hold onto a reference for your Test Element is because Jmeter reuses instance of gui class objects for multiple Test Elements. This saves a lot of memory. It also makes it incredibly easy to write the gui part of your new component. You still have to struggle with the layout in Swing, but you don't have to worry about creating the right events and actions for getting the data from the gui elements into the TestElement where it can do some good. Jmeter knows when to call your configure, and modifyTestElement methods where you can do it in a very straightforward way.