Revision e44f328b
Added by Patrick Plitzner over 10 years ago
- implemented context menu functionality (create specimen)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateMenuPropertyTester.java | ||
---|---|---|
3 | 3 |
*/ |
4 | 4 |
package eu.etaxonomy.taxeditor.editor.view.derivate; |
5 | 5 |
|
6 |
import java.util.Arrays; |
|
7 |
|
|
8 | 6 |
import org.eclipse.core.expressions.PropertyTester; |
9 | 7 |
import org.eclipse.jface.viewers.IStructuredSelection; |
10 | 8 |
|
11 |
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit; |
|
12 |
import eu.etaxonomy.cdm.model.occurrence.FieldUnit; |
|
9 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
|
13 | 10 |
|
14 | 11 |
/** |
15 | 12 |
* Property tester used by the DerivateView tree menu. |
... | ... | |
17 | 14 |
*/ |
18 | 15 |
public class DerivateMenuPropertyTester extends PropertyTester { |
19 | 16 |
|
20 |
private static final String IS_FIELD_UNIT = "isFieldUnit"; |
|
21 |
private static final String IS_SPECIMEN = "isSpecimen"; |
|
17 |
private static final String IS_SPECIMEN_OR_OBSERVATION = "isSpecimenOrObservation"; |
|
22 | 18 |
|
23 | 19 |
/* (non-Javadoc) |
24 | 20 |
* @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object) |
... | ... | |
26 | 22 |
/** {@inheritDoc} */ |
27 | 23 |
@Override |
28 | 24 |
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { |
29 |
System.out.println(receiver.toString() + receiver.getClass().toString()); |
|
30 |
System.out.println(property); |
|
31 |
System.out.println(Arrays.asList(args)); |
|
32 |
System.out.println(expectedValue); |
|
25 |
//TODO: these simple instanceof-checks can be unified in one class because there are several |
|
26 |
// PropertyTesters that do the same, that is just checking which class the selection is of |
|
33 | 27 |
|
34 |
Object[] selectedElements = ((IStructuredSelection) receiver).toArray();
|
|
28 |
Object[] selectedElements = ((IStructuredSelection) receiver).toArray();
|
|
35 | 29 |
|
36 | 30 |
if(selectedElements.length == 0){ |
37 | 31 |
// nothing selected so all tests should fail |
38 | 32 |
return false; |
39 | 33 |
} |
40 | 34 |
|
41 |
if(IS_FIELD_UNIT.equals(property)){ |
|
42 |
return isFieldUnit(selectedElements); |
|
43 |
} |
|
44 |
else if(IS_SPECIMEN.equals(property)){ |
|
45 |
return isSpecimen(selectedElements); |
|
35 |
if(IS_SPECIMEN_OR_OBSERVATION.equals(property)){ |
|
36 |
return isSpecimenOrObservation(selectedElements); |
|
46 | 37 |
} |
47 | 38 |
else{ |
48 | 39 |
return false; |
49 | 40 |
} |
50 | 41 |
} |
51 | 42 |
|
52 |
private boolean isFieldUnit(Object[] selectedElements) { |
|
53 |
for (Object object : selectedElements){ |
|
54 |
if(!(object instanceof FieldUnit)){ |
|
55 |
return false; |
|
56 |
} |
|
57 |
} |
|
58 |
return true; |
|
59 |
} |
|
60 |
|
|
61 |
private boolean isSpecimen(Object[] selectedElements) { |
|
43 |
private boolean isSpecimenOrObservation(Object[] selectedElements) { |
|
62 | 44 |
for (Object object : selectedElements){ |
63 |
if(!(object instanceof DerivedUnit)){
|
|
45 |
if(!(object instanceof SpecimenOrObservationBase)){
|
|
64 | 46 |
return false; |
65 | 47 |
} |
66 | 48 |
} |
67 | 49 |
return true; |
68 | 50 |
} |
51 |
|
|
69 | 52 |
} |
Also available in: Unified diff