jsalvata 2004/01/04 12:51:27
Modified: src/core/org/apache/jmeter/testbeans/gui Tag:
testbeans_experimental_branch TestBeanGUI.java
BeanInfoSupport.java
Log:
Add basic support for grouping & ordering (groups not yet
visible in the GUI).
Revision Changes Path
No revision
No revision
1.1.2.6 +97 -1
jakarta-jmeter/src/core/org/apache/jmeter/testbeans/gui/Attic/TestBeanGUI.java
Index: TestBeanGUI.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/testbeans/gui/Attic/TestBeanGUI.java,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -u -r1.1.2.5 -r1.1.2.6
--- TestBeanGUI.java 4 Jan 2004 12:08:47 -0000 1.1.2.5
+++ TestBeanGUI.java 4 Jan 2004 20:51:27 -0000 1.1.2.6
@@ -67,7 +67,9 @@
import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
@@ -100,6 +102,27 @@
* It allows editing each of the public exposed properties of the
* edited type 'a la JavaBeans': as far as the types of those properties
* have an associated editor, there's no GUI development required.
+ * <p>
+ * TestBeanGUI understands the following PropertyDescriptor attributes:
+ * <dl>
+ * <dt>group: String</dt>
+ * <dd>Group under which the property should be shown in the GUI. The string is
+ * also used as a group title. The default group is "".</dd>
+ * <dt>order: Integer</dt>
+ * <dd>Order in which the property will be shown in its group. A smaller
+ * integer means higher up in the GUI. The default order is 0. Properties
+ * of equal order are sorted alphabetically.</dd>
+ * </dl>
+ * <p>
+ * The following BeanDescriptor attributes are also understood:
+ * <dl>
+ * <dt>group.<i>group</i>.order: Integer</dt>
+ * <dd>where <b><i>group</i></b> is a group name used in a <b>group</b>
+ * attribute in one or more PropertyDescriptors. Defines the order in which
+ * the group will be shown in the GUI. A smaller integer means higher up
+ * in the GUI. The default order is 0. Groups of equal order are sorted
+ * alphabetically.</dd>
+ * </dl>
*/
public class TestBeanGUI extends AbstractJMeterGuiComponent
{
@@ -158,6 +181,9 @@
throw new Error(e); // Programming error. Don't continue.
}
+ // Sort the property descriptors:
+ Arrays.sort(descriptors, new PropertyComparator());
+
// Obtain the propertyEditors:
editors= new PropertyEditor[descriptors.length];
for (int i=0; i<descriptors.length; i++)
@@ -400,4 +426,74 @@
return panel;
}
+ /**
+ * Comparator used to sort properties for presentation in the GUI.
+ */
+ private class PropertyComparator implements Comparator
+ {
+ public int compare(Object o1, Object o2)
+ {
+ return compare((PropertyDescriptor)o1, (PropertyDescriptor)o2);
+ }
+
+ private int compare(PropertyDescriptor d1, PropertyDescriptor d2)
+ {
+ int result;
+
+ String g1= group(d1), g2= group(d2);
+ Integer go1= groupOrder(g1), go2= groupOrder(g2);
+
+ result= go1.compareTo(go2);
+ if (result != 0) return result;
+
+ result= g1.compareTo(g2);
+ if (result != 0) return result;
+
+ Integer po1= propertyOrder(d1), po2= propertyOrder(d2);
+ result= po1.compareTo(po2);
+ if (result != 0) return result;
+
+ return d1.getName().compareTo(d2.getName());
+ }
+
+ /**
+ * Obtain a property descriptor's group.
+ *
+ * @param descriptor
+ * @return the group String.
+ */
+ private String group(PropertyDescriptor d)
+ {
+ String group= (String)d.getValue("group");
+ if (group == null) group= "";
+ return group;
+ }
+
+ /**
+ * Obtain a group's order.
+ *
+ * @param group group name
+ * @return the group's order (zero by default)
+ */
+ private Integer groupOrder(String group)
+ {
+ Integer order= (Integer)beanInfo.getBeanDescriptor()
+ .getValue("group."+group+".order");
+ if (order == null) order= new Integer(0);
+ return order;
+ }
+
+ /**
+ * Obtain a property's order.
+ *
+ * @param d
+ * @return the property's order attribute (zero by default)
+ */
+ private Integer propertyOrder(PropertyDescriptor d)
+ {
+ Integer order= (Integer)d.getValue("order");
+ if (order == null) order= new Integer(0);
+ return order;
+ }
+ }
}
1.1.2.2 +34 -1
jakarta-jmeter/src/core/org/apache/jmeter/testbeans/gui/Attic/BeanInfoSupport.java
Index: BeanInfoSupport.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/testbeans/gui/Attic/BeanInfoSupport.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- BeanInfoSupport.java 2 Jan 2004 18:39:35 -0000 1.1.2.1
+++ BeanInfoSupport.java 4 Jan 2004 20:51:27 -0000 1.1.2.2
@@ -105,6 +105,12 @@
properties= rootBeanInfo.getPropertyDescriptors();
}
+ /**
+ * Get the property descriptor for the property of the given name.
+ *
+ * @param name property name
+ * @return descriptor for a property of that name, or null if there's none
+ */
protected PropertyDescriptor property(String name) {
for (int i=0; i<properties.length; i++)
{
@@ -113,6 +119,33 @@
}
}
return null;
+ }
+
+ private int numCreatedGroups= 0;
+
+ /**
+ * Utility method to group and order properties.
+ * <p>
+ * It will assing the given group name to each of the named properties,
+ * and set their order attribute so that they are shown in the given order.
+ * <p>
+ * The created groups will get order 1, 2, 3,... in the order in which they
+ * are created.
+ *
+ * @param group name of the group
+ * @param names property names in the desired order
+ */
+ protected void createPropertyGroup(String group, String[] names)
+ {
+ for (int i=0; i<names.length; i++)
+ {
+ PropertyDescriptor p= property(names[i]);
+ p.setValue("group", group);
+ p.setValue("order", new Integer(i));
+ }
+ numCreatedGroups++;
+ getBeanDescriptor().setValue("group."+group+".order",
+ new Integer(numCreatedGroups));
}
public BeanInfo[] getAdditionalBeanInfo() {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]