Fix ToolTip not appearing on front sheet panel.
We now traverse the superclass hierarchy and search for a field with the matching annotation.
This commit is contained in:
parent
2593ec2a70
commit
468aa7b2a0
@ -10,6 +10,7 @@ import eva2.util.annotation.Description;
|
||||
import eva2.util.annotation.Parameter;
|
||||
|
||||
import java.beans.*;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
@ -984,6 +985,30 @@ public class BeanInspector {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotations on Fields are not retained when inherited. This method traverses the
|
||||
* superclass hierarchy and looks for an annotation on a given field name.
|
||||
*
|
||||
* @param name Name of the field in the class
|
||||
* @param c Class to start searching for the field with the annotation
|
||||
* @param annotation The annotation to look for
|
||||
* @param <T>
|
||||
* @return Returns the annotation of the field if found, null otherwise
|
||||
*/
|
||||
public static <T extends Annotation> T getAnnotationFromField(final String name, final Class c, final Class<T> annotation) {
|
||||
for (Field field : c.getDeclaredFields()) {
|
||||
if (field.isAnnotationPresent(annotation) && field.getName().equals(name)) {
|
||||
return field.getAnnotation(annotation);
|
||||
}
|
||||
}
|
||||
|
||||
if (!c.getSuperclass().equals(Object.class)) {
|
||||
return getAnnotationFromField(name, c.getSuperclass(), annotation);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method simply looks for an appropriate tiptext
|
||||
*
|
||||
@ -998,11 +1023,9 @@ public class BeanInspector {
|
||||
|
||||
// Find by annotation
|
||||
Parameter[] parameters= target.getClass().getAnnotationsByType(Parameter.class);
|
||||
for (Field field : target.getClass().getDeclaredFields()) {
|
||||
if (field.isAnnotationPresent(Parameter.class) && field.getName().equals(name)) {
|
||||
Parameter parameter = field.getAnnotation(Parameter.class);
|
||||
return parameter.description();
|
||||
}
|
||||
Parameter parameter = BeanInspector.getAnnotationFromField(name, target.getClass(), Parameter.class);
|
||||
if (parameter != null) {
|
||||
return parameter.description();
|
||||
}
|
||||
|
||||
// Find by deprecated TipText method
|
||||
|
@ -292,7 +292,7 @@ public class PropertySheetPanel extends JPanel implements PropertyChangeListener
|
||||
itemIndex++;
|
||||
newView = getView(propertyEditors[i]);
|
||||
if (newView == null) {
|
||||
System.err.println("Warning: Property \"" + name + "\" has non-displayabale editor. Skipping.");
|
||||
System.err.println("Warning: Property \"" + name + "\" has non-displayable editor. Skipping.");
|
||||
continue;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
@ -424,7 +424,6 @@ public class PropertySheetPanel extends JPanel implements PropertyChangeListener
|
||||
* @return
|
||||
*/
|
||||
private PropertyDescriptor[] reorderProperties(Method meth) {
|
||||
// Mathematics.revertArray(oldProps, newProps);
|
||||
Object[] args = {};
|
||||
Object retV = null;
|
||||
PropertyDescriptor[] newProps = null;
|
||||
|
@ -14,7 +14,6 @@ public interface InterfaceAdditionalPopulationInformer {
|
||||
/**
|
||||
* This method returns the header for additional statistical data.
|
||||
*
|
||||
* @param pop The population of the optimization run.
|
||||
* @return String
|
||||
*/
|
||||
public String[] getAdditionalDataHeader();
|
||||
@ -22,7 +21,6 @@ public interface InterfaceAdditionalPopulationInformer {
|
||||
/**
|
||||
* Optionally return informative descriptions of the data fields.
|
||||
*
|
||||
* @param pop
|
||||
* @return
|
||||
*/
|
||||
public String[] getAdditionalDataInfo();
|
||||
|
@ -19,7 +19,7 @@ public interface InterfaceOptimizationProblem extends InterfaceAdditionalPopulat
|
||||
public Object clone();
|
||||
|
||||
/**
|
||||
* This method inits the Problem to log multiruns
|
||||
* This method initializes the Problem to log multiruns
|
||||
*/
|
||||
public void initializeProblem();
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
package eva2.util.annotation;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface Parameter {
|
||||
String name();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user