Revision 167eefc2
Added by Patrick Plitzner almost 7 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/SpecimenPropertyTester.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
|
4 | 4 |
import org.eclipse.core.expressions.PropertyTester; |
5 |
import org.eclipse.jface.util.LocalSelectionTransfer; |
|
6 | 5 |
import org.eclipse.jface.viewers.IStructuredSelection; |
7 | 6 |
import org.eclipse.jface.viewers.TreeNode; |
8 |
import org.eclipse.ui.IEditorPart; |
|
9 |
import org.eclipse.ui.IWorkbenchWindow; |
|
10 |
import org.eclipse.ui.PlatformUI; |
|
11 | 7 |
|
12 | 8 |
import eu.etaxonomy.cdm.model.molecular.Sequence; |
13 |
import eu.etaxonomy.cdm.model.molecular.SingleRead; |
|
14 | 9 |
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen; |
15 | 10 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
16 | 11 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
17 |
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView; |
|
18 | 12 |
|
19 | 13 |
|
20 | 14 |
|
... | ... | |
26 | 20 |
*/ |
27 | 21 |
public class SpecimenPropertyTester extends PropertyTester { |
28 | 22 |
private static final String SEQUENCE = "isSequence"; //$NON-NLS-1$ |
29 |
private static final String SINGLE_READ = "isSingleRead"; //$NON-NLS-1$ |
|
30 |
private static final String IS_SINGLEREAD_REUSABLE_HERE = "isSingleReadReusableHere"; //$NON-NLS-1$ |
|
31 |
private static final String IS_SINGLEREAD_REUSED = "isSingleReadReused"; //$NON-NLS-1$ |
|
32 | 23 |
private static final String IS_SPECIMEN_OR_OBSERVATION_BASE = "isSpecimenOrObservationBase"; //$NON-NLS-1$ |
33 | 24 |
private static final String IS_ADD_DERIVATE_ALLOWED = "isAddDerivateAllowed"; //$NON-NLS-1$ |
34 | 25 |
private static final String IS_ADD_MEDIA_ALLOWED = "isAddMediaAllowed"; //$NON-NLS-1$ |
... | ... | |
46 | 37 |
if (SEQUENCE.equals(property)) { |
47 | 38 |
return isSequence(treeNodeOfSelection.getValue()); |
48 | 39 |
} |
49 |
else if (SINGLE_READ.equals(property)) { |
|
50 |
return isSingleReadAlignment(treeNodeOfSelection.getValue()); |
|
51 |
} |
|
52 |
else if (IS_SINGLEREAD_REUSABLE_HERE.equals(property)) { |
|
53 |
return isSingleReadReusableHere(treeNodeOfSelection.getValue()); |
|
54 |
} |
|
55 |
else if (IS_SINGLEREAD_REUSED.equals(property)) { |
|
56 |
return isSingleReadReused(treeNodeOfSelection.getValue()); |
|
57 |
} |
|
58 | 40 |
else if (IS_SPECIMEN_OR_OBSERVATION_BASE.equals(property)) { |
59 | 41 |
return isSpecimenOrObservationBase(treeNodeOfSelection.getValue()); |
60 | 42 |
} |
... | ... | |
69 | 51 |
return false; |
70 | 52 |
} |
71 | 53 |
|
72 |
private boolean isSingleReadReused(Object value) { |
|
73 |
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
|
74 |
final IEditorPart activeEditor = window.getActivePage().getActiveEditor(); |
|
75 |
if(value instanceof SingleRead){ |
|
76 |
if(activeEditor instanceof DerivateView |
|
77 |
&& ((DerivateView) activeEditor).getMultiLinkSingleReads().contains(value)){ |
|
78 |
return true; |
|
79 |
} |
|
80 |
} |
|
81 |
return false; |
|
82 |
} |
|
83 |
|
|
84 |
private boolean isSingleReadReusableHere(Object value) { |
|
85 |
TreeNode clipboardNode = EditorUtil.getTreeNodeOfSelection(LocalSelectionTransfer.getTransfer().getSelection()); |
|
86 |
if(value instanceof Sequence && clipboardNode!=null && clipboardNode.getValue() instanceof SingleRead |
|
87 |
&& !((Sequence) value).getSingleReads().contains(clipboardNode.getValue())){ |
|
88 |
return true; |
|
89 |
} |
|
90 |
return false; |
|
91 |
} |
|
92 | 54 |
|
93 | 55 |
private boolean isSpecimenOrObservationBase(Object object) { |
94 | 56 |
return (object instanceof SpecimenOrObservationBase); |
... | ... | |
108 | 70 |
return (object instanceof Sequence); |
109 | 71 |
} |
110 | 72 |
|
111 |
private boolean isSingleReadAlignment(Object object) { |
|
112 |
return (object instanceof SingleRead); |
|
113 |
} |
|
114 | 73 |
} |
Also available in: Unified diff
ref #6566 Migrate single read related context menu items Part 2