*/
package eu.etaxonomy.taxeditor.editor.view.derivate;
-import java.util.Arrays;
-
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.jface.viewers.IStructuredSelection;
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
-import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
/**
* Property tester used by the DerivateView tree menu.
*/
public class DerivateMenuPropertyTester extends PropertyTester {
- private static final String IS_FIELD_UNIT = "isFieldUnit";
- private static final String IS_SPECIMEN = "isSpecimen";
+ private static final String IS_SPECIMEN_OR_OBSERVATION = "isSpecimenOrObservation";
/* (non-Javadoc)
* @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
/** {@inheritDoc} */
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
- System.out.println(receiver.toString() + receiver.getClass().toString());
- System.out.println(property);
- System.out.println(Arrays.asList(args));
- System.out.println(expectedValue);
+ //TODO: these simple instanceof-checks can be unified in one class because there are several
+ // PropertyTesters that do the same, that is just checking which class the selection is of
- Object[] selectedElements = ((IStructuredSelection) receiver).toArray();
+ Object[] selectedElements = ((IStructuredSelection) receiver).toArray();
if(selectedElements.length == 0){
// nothing selected so all tests should fail
return false;
}
- if(IS_FIELD_UNIT.equals(property)){
- return isFieldUnit(selectedElements);
- }
- else if(IS_SPECIMEN.equals(property)){
- return isSpecimen(selectedElements);
+ if(IS_SPECIMEN_OR_OBSERVATION.equals(property)){
+ return isSpecimenOrObservation(selectedElements);
}
else{
return false;
}
}
- private boolean isFieldUnit(Object[] selectedElements) {
- for (Object object : selectedElements){
- if(!(object instanceof FieldUnit)){
- return false;
- }
- }
- return true;
- }
-
- private boolean isSpecimen(Object[] selectedElements) {
+ private boolean isSpecimenOrObservation(Object[] selectedElements) {
for (Object object : selectedElements){
- if(!(object instanceof DerivedUnit)){
+ if(!(object instanceof SpecimenOrObservationBase)){
return false;
}
}
return true;
}
+
}