mirror of https://github.com/apache/jmeter.git
Bug 59105 - TableEditor : Add ability to paste rows from clipboard and delete multiple selection
#resolve #153
https://github.com/apache/jmeter/pull/153
Bugzilla Id: 59105
git-svn-id: https://svn.apache.org/repos/asf/jmeter/trunk@1734311 13f79535-47bb-0310-9956-ffa450edef68
Former-commit-id: e00e16d4a9
This commit is contained in:
parent
a9b03d0cfd
commit
e86c0ee9cf
|
|
@ -46,6 +46,7 @@ import javax.swing.event.TableModelListener;
|
|||
import org.apache.jmeter.gui.ClearGui;
|
||||
import org.apache.jmeter.testelement.property.TestElementProperty;
|
||||
import org.apache.jmeter.util.JMeterUtils;
|
||||
import org.apache.jorphan.gui.GuiUtils;
|
||||
import org.apache.jorphan.gui.ObjectTableModel;
|
||||
import org.apache.jorphan.logging.LoggingManager;
|
||||
import org.apache.jorphan.reflect.Functor;
|
||||
|
|
@ -59,7 +60,7 @@ import org.apache.log.Logger;
|
|||
* </ul>
|
||||
*/
|
||||
public class TableEditor extends PropertyEditorSupport implements FocusListener,TestBeanPropertyEditor,TableModelListener, ClearGui {
|
||||
private static final Logger log = LoggingManager.getLoggerForClass();
|
||||
private static final Logger LOG = LoggingManager.getLoggerForClass();
|
||||
|
||||
/**
|
||||
* attribute name for class name of a table row;
|
||||
|
|
@ -80,11 +81,16 @@ public class TableEditor extends PropertyEditorSupport implements FocusListener,
|
|||
private ObjectTableModel model;
|
||||
private Class<?> clazz;
|
||||
private PropertyDescriptor descriptor;
|
||||
private final JButton addButton,removeButton,clearButton;
|
||||
private final JButton addButton;
|
||||
private final JButton clipButton;
|
||||
private final JButton removeButton;
|
||||
private final JButton clearButton;
|
||||
|
||||
public TableEditor() {
|
||||
addButton = new JButton(JMeterUtils.getResString("add")); // $NON-NLS-1$
|
||||
addButton.addActionListener(new AddListener());
|
||||
clipButton = new JButton(JMeterUtils.getResString("add_from_clipboard")); // $NON-NLS-1$
|
||||
clipButton.addActionListener(new ClipListener());
|
||||
removeButton = new JButton(JMeterUtils.getResString("remove")); // $NON-NLS-1$
|
||||
removeButton.addActionListener(new RemoveListener());
|
||||
clearButton = new JButton(JMeterUtils.getResString("clear")); // $NON-NLS-1$
|
||||
|
|
@ -104,15 +110,16 @@ public class TableEditor extends PropertyEditorSupport implements FocusListener,
|
|||
return pane;
|
||||
}
|
||||
|
||||
private JComponent makePanel()
|
||||
{
|
||||
private JComponent makePanel() {
|
||||
JPanel p = new JPanel(new BorderLayout());
|
||||
JScrollPane scroller = new JScrollPane(table);
|
||||
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
||||
scroller.setMinimumSize(new Dimension(100, 70));
|
||||
scroller.setPreferredSize(scroller.getMinimumSize());
|
||||
p.add(scroller,BorderLayout.CENTER);
|
||||
JPanel south = new JPanel();
|
||||
south.add(addButton);
|
||||
south.add(clipButton);
|
||||
south.add(removeButton);
|
||||
south.add(clearButton);
|
||||
p.add(south,BorderLayout.SOUTH);
|
||||
|
|
@ -131,27 +138,20 @@ public class TableEditor extends PropertyEditorSupport implements FocusListener,
|
|||
|
||||
@Override
|
||||
public void setValue(Object value) {
|
||||
if(value != null)
|
||||
{
|
||||
if(value != null) {
|
||||
model.setRows(convertCollection((Collection<?>)value));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
model.clearData();
|
||||
}
|
||||
this.firePropertyChange();
|
||||
}
|
||||
|
||||
private Collection<Object> convertCollection(Collection<?> values)
|
||||
{
|
||||
private Collection<Object> convertCollection(Collection<?> values) {
|
||||
List<Object> l = new LinkedList<>();
|
||||
for(Object obj : values)
|
||||
{
|
||||
if(obj instanceof TestElementProperty)
|
||||
{
|
||||
for(Object obj : values) {
|
||||
if(obj instanceof TestElementProperty) {
|
||||
l.add(((TestElementProperty)obj).getElement());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
l.add(obj);
|
||||
}
|
||||
}
|
||||
|
|
@ -185,15 +185,12 @@ public class TableEditor extends PropertyEditorSupport implements FocusListener,
|
|||
void initializeModel()
|
||||
{
|
||||
Object hdrs = descriptor.getValue(HEADERS);
|
||||
if (!(hdrs instanceof String[])){
|
||||
if (!(hdrs instanceof String[])) {
|
||||
throw new RuntimeException("attribute HEADERS must be a String array");
|
||||
}
|
||||
if(clazz == String.class)
|
||||
{
|
||||
if(clazz == String.class) {
|
||||
model = new ObjectTableModel((String[])hdrs,new Functor[0],new Functor[0],new Class[]{String.class});
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Object value = descriptor.getValue(OBJECT_PROPERTIES);
|
||||
if (!(value instanceof String[])) {
|
||||
throw new RuntimeException("attribute OBJECT_PROPERTIES must be a String array");
|
||||
|
|
@ -203,8 +200,7 @@ public class TableEditor extends PropertyEditorSupport implements FocusListener,
|
|||
Functor[] readers = new Functor[props.length];
|
||||
Class<?>[] editors = new Class[props.length];
|
||||
int count = 0;
|
||||
for(String propName : props)
|
||||
{
|
||||
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);
|
||||
|
|
@ -220,30 +216,25 @@ public class TableEditor extends PropertyEditorSupport implements FocusListener,
|
|||
table.addFocusListener(this);
|
||||
}
|
||||
|
||||
Functor createWriter(Class<?> c,String propName)
|
||||
{
|
||||
Functor createWriter(Class<?> c,String propName) {
|
||||
String setter = "set" + propName; // $NON-NLS-1$
|
||||
return new Functor(setter);
|
||||
}
|
||||
|
||||
Functor createReader(Class<?> c,String propName)
|
||||
{
|
||||
Functor createReader(Class<?> c,String propName) {
|
||||
String getter = "get" + propName; // $NON-NLS-1$
|
||||
try
|
||||
{
|
||||
try {
|
||||
c.getMethod(getter,new Class[0]);
|
||||
return new Functor(getter);
|
||||
} catch(Exception e) {
|
||||
return new Functor("is" + propName);
|
||||
}
|
||||
catch(Exception e) { return new Functor("is" + propName); }
|
||||
}
|
||||
|
||||
Class<?> getArgForWriter(Class<?> c,String propName)
|
||||
{
|
||||
Class<?> getArgForWriter(Class<?> c,String propName) {
|
||||
String setter = "set" + propName; // $NON-NLS-1$
|
||||
for(Method m : c.getMethods())
|
||||
{
|
||||
if(m.getName().equals(setter))
|
||||
{
|
||||
for(Method m : c.getMethods()) {
|
||||
if(m.getName().equals(setter)) {
|
||||
return m.getParameterTypes()[0];
|
||||
}
|
||||
}
|
||||
|
|
@ -265,53 +256,67 @@ public class TableEditor extends PropertyEditorSupport implements FocusListener,
|
|||
final int editingRow = table.getEditingRow();
|
||||
final int editingColumn = table.getEditingColumn();
|
||||
CellEditor ce = null;
|
||||
if (editingRow != -1 && editingColumn != -1){
|
||||
if (editingRow != -1 && editingColumn != -1) {
|
||||
ce = table.getCellEditor(editingRow,editingColumn);
|
||||
}
|
||||
Component editor = table.getEditorComponent();
|
||||
if(ce != null && (editor == null || editor != e.getOppositeComponent()))
|
||||
{
|
||||
if(ce != null && (editor == null || editor != e.getOppositeComponent())) {
|
||||
ce.stopCellEditing();
|
||||
}
|
||||
else if(editor != null)
|
||||
{
|
||||
} else if(editor != null) {
|
||||
editor.addFocusListener(this);
|
||||
}
|
||||
this.firePropertyChange();
|
||||
}
|
||||
|
||||
private class AddListener implements ActionListener
|
||||
{
|
||||
private class AddListener implements ActionListener {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
try
|
||||
{
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
model.addRow(clazz.newInstance());
|
||||
}catch(Exception err)
|
||||
{
|
||||
log.error("The class type given to TableEditor was not instantiable. ",err);
|
||||
} catch(Exception err) {
|
||||
LOG.error("The class type given to TableEditor was not instantiable. ", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ClipListener implements ActionListener {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
String clipboardContent = GuiUtils.getPastedText();
|
||||
if(clipboardContent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String[] clipboardLines = clipboardContent.split("\n"); // $NON-NLS-1$
|
||||
for (String clipboardLine : clipboardLines) {
|
||||
String[] columns = clipboardLine.split("\t"); // $NON-NLS-1$
|
||||
|
||||
model.addRow(clazz.newInstance());
|
||||
|
||||
for (int i=0; i < columns.length; i++) {
|
||||
model.setValueAt(columns[i], model.getRowCount() - 1, i);
|
||||
}
|
||||
}
|
||||
} catch (Exception err) {
|
||||
LOG.error("The class type given to TableEditor was not instantiable. ", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class RemoveListener implements ActionListener
|
||||
{
|
||||
private class RemoveListener implements ActionListener {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
int row = table.getSelectedRow();
|
||||
if (row >= 0) {
|
||||
model.removeRow(row);
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
int[] rows = table.getSelectedRows();
|
||||
for(int i=0;i<rows.length;i++){
|
||||
model.removeRow(rows[i]-i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ClearListener implements ActionListener
|
||||
{
|
||||
private class ClearListener implements ActionListener {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
model.clearData();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -257,6 +257,7 @@ Summary
|
|||
<li><bug>58715</bug>Feature request: Bundle groovy-all with JMeter</li>
|
||||
<li><bug>59095</bug>Remove UserParameterXMLParser that was deprecated 8 years ago. Contributed by Benoit Wiart (benoit dot wiart at gmail.com)</li>
|
||||
<li><bug>58426</bug>Use DPI scaling of interface for high resolution devices (HiDPI support for Windows/Linux) - <i>BETA</i> see hidpi properties in bin/jmeter.properties</li>
|
||||
<li><bug>59105</bug>TableEditor : Add ability to paste rows from clipboard and delete multiple selection. Contributed by Vincent Herilier (vherilier at gmail.com)</li>
|
||||
</ul>
|
||||
<ch_section>Non-functional changes</ch_section>
|
||||
<ul>
|
||||
|
|
@ -404,7 +405,6 @@ Summary
|
|||
<li>Florent Sabbe (f dot sabbe at ubik-ingenierie.com)</li>
|
||||
<li>Antonio Gomes Rodrigues (ra0077 at gmail.com)</li>
|
||||
<li>Harrison Termotto (harrison dot termotto at stonybrook.edu</li>
|
||||
<li>Vincent Herilier (vherilier at gmail.com)</li>
|
||||
<li>Denis Kirpichenkov (denis.kirpichenkov at gmail.com)</li>
|
||||
<li>Gary Gregory (ggregory at apache.org)</li>
|
||||
</ul>
|
||||
|
|
|
|||
Loading…
Reference in New Issue