|
JMeter example source code file (TableEditor.java)
The JMeter TableEditor.java source code/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package org.apache.jmeter.testbeans.gui; import java.awt.BorderLayout; import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.beans.PropertyDescriptor; import java.beans.PropertyEditorSupport; import java.lang.reflect.Method; import java.util.Collection; import java.util.LinkedList; import java.util.List; import javax.swing.CellEditor; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelListener; import org.apache.jmeter.testelement.property.TestElementProperty; import org.apache.jmeter.util.JMeterUtils; import org.apache.jorphan.gui.ObjectTableModel; import org.apache.jorphan.logging.LoggingManager; import org.apache.jorphan.reflect.Functor; import org.apache.log.Logger; public class TableEditor extends PropertyEditorSupport implements FocusListener,TestBeanPropertyEditor,TableModelListener { private static final Logger log = LoggingManager.getLoggerForClass(); public static final String CLASSNAME = "tableObject.classname"; // $NON-NLS-1$ public static final String HEADERS = "table.headers"; // $NON-NLS-1$ public static final String OBJECT_PROPERTIES = "tableObject.properties"; // $NON-NLS-1$ private JTable table; private ObjectTableModel model; private Class<?> clazz; private PropertyDescriptor descriptor; private final JButton addButton,removeButton,clearButton; public TableEditor() { addButton = new JButton(JMeterUtils.getResString("add")); // $NON-NLS-1$ addButton.addActionListener(new AddListener()); removeButton = new JButton(JMeterUtils.getResString("remove")); // $NON-NLS-1$ removeButton.addActionListener(new RemoveListener()); clearButton = new JButton(JMeterUtils.getResString("clear")); // $NON-NLS-1$ clearButton.addActionListener(new ClearListener()); } @Override public String getAsText() { return null; } @Override public Component getCustomEditor() { JComponent pane = makePanel(); pane.doLayout(); pane.validate(); return pane; } private JComponent makePanel() { JPanel p = new JPanel(new BorderLayout()); JScrollPane scroller = new JScrollPane(table); scroller.setPreferredSize(scroller.getMinimumSize()); p.add(scroller,BorderLayout.CENTER); JPanel south = new JPanel(); south.add(addButton); south.add(removeButton); south.add(clearButton); p.add(south,BorderLayout.SOUTH); return p; } @Override public Object getValue() { return model.getObjectList(); } @Override public void setAsText(String text) throws IllegalArgumentException { //not interested in this method. } @Override public void setValue(Object value) { if(value != null) { model.setRows(convertCollection((Collection<?>)value)); } else model.clearData(); this.firePropertyChange(); } private Collection<Object> convertCollection(Collection> values) { List<Object> l = new LinkedList Other JMeter examples (source code examples)Here is a short list of links related to this JMeter TableEditor.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.