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:
Fabian Becker 2014-10-23 17:50:12 +02:00
parent 2593ec2a70
commit 468aa7b2a0
5 changed files with 32 additions and 12 deletions

View File

@ -10,6 +10,7 @@ import eva2.util.annotation.Description;
import eva2.util.annotation.Parameter; import eva2.util.annotation.Parameter;
import java.beans.*; import java.beans.*;
import java.lang.annotation.Annotation;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; 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 * This method simply looks for an appropriate tiptext
* *
@ -998,11 +1023,9 @@ public class BeanInspector {
// Find by annotation // Find by annotation
Parameter[] parameters= target.getClass().getAnnotationsByType(Parameter.class); Parameter[] parameters= target.getClass().getAnnotationsByType(Parameter.class);
for (Field field : target.getClass().getDeclaredFields()) { Parameter parameter = BeanInspector.getAnnotationFromField(name, target.getClass(), Parameter.class);
if (field.isAnnotationPresent(Parameter.class) && field.getName().equals(name)) { if (parameter != null) {
Parameter parameter = field.getAnnotation(Parameter.class); return parameter.description();
return parameter.description();
}
} }
// Find by deprecated TipText method // Find by deprecated TipText method

View File

@ -292,7 +292,7 @@ public class PropertySheetPanel extends JPanel implements PropertyChangeListener
itemIndex++; itemIndex++;
newView = getView(propertyEditors[i]); newView = getView(propertyEditors[i]);
if (newView == null) { 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; continue;
} }
} catch (Exception ex) { } catch (Exception ex) {
@ -424,7 +424,6 @@ public class PropertySheetPanel extends JPanel implements PropertyChangeListener
* @return * @return
*/ */
private PropertyDescriptor[] reorderProperties(Method meth) { private PropertyDescriptor[] reorderProperties(Method meth) {
// Mathematics.revertArray(oldProps, newProps);
Object[] args = {}; Object[] args = {};
Object retV = null; Object retV = null;
PropertyDescriptor[] newProps = null; PropertyDescriptor[] newProps = null;

View File

@ -14,7 +14,6 @@ public interface InterfaceAdditionalPopulationInformer {
/** /**
* This method returns the header for additional statistical data. * This method returns the header for additional statistical data.
* *
* @param pop The population of the optimization run.
* @return String * @return String
*/ */
public String[] getAdditionalDataHeader(); public String[] getAdditionalDataHeader();
@ -22,7 +21,6 @@ public interface InterfaceAdditionalPopulationInformer {
/** /**
* Optionally return informative descriptions of the data fields. * Optionally return informative descriptions of the data fields.
* *
* @param pop
* @return * @return
*/ */
public String[] getAdditionalDataInfo(); public String[] getAdditionalDataInfo();

View File

@ -19,7 +19,7 @@ public interface InterfaceOptimizationProblem extends InterfaceAdditionalPopulat
public Object clone(); public Object clone();
/** /**
* This method inits the Problem to log multiruns * This method initializes the Problem to log multiruns
*/ */
public void initializeProblem(); public void initializeProblem();

View File

@ -1,9 +1,9 @@
package eva2.util.annotation; package eva2.util.annotation;
import java.lang.annotation.Retention; import java.lang.annotation.*;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Parameter { public @interface Parameter {
String name(); String name();