Revision 5d5c3c75
Added by Patrick Plitzner over 8 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/contextMenu/SingleReadSequenceContextMenu.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import org.eclipse.jface.action.ContributionItem; |
4 | 4 |
import org.eclipse.jface.action.IContributionItem; |
5 |
import org.eclipse.jface.action.Separator; |
|
5 | 6 |
import org.eclipse.jface.util.LocalSelectionTransfer; |
6 | 7 |
import org.eclipse.jface.viewers.ISelection; |
7 | 8 |
import org.eclipse.jface.viewers.TreeNode; |
... | ... | |
38 | 39 |
|
39 | 40 |
@Override |
40 | 41 |
protected IContributionItem[] getContributionItems() { |
41 |
IContributionItem[] contributionItems = new IContributionItem[] { |
|
42 |
new ContributionItem() { |
|
43 |
@Override |
|
44 |
public void fill(Menu menu, int index) { |
|
45 |
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
|
46 |
final IEditorPart activeEditor = window.getActivePage().getActiveEditor(); |
|
47 |
final ISelection selection = window.getActivePage().getSelection(); |
|
48 |
TreeNode selectedTreeNode = EditorUtil.getTreeNodeOfSelection(selection); |
|
49 |
TreeNode clipboardNode = EditorUtil.getTreeNodeOfSelection(LocalSelectionTransfer.getTransfer().getSelection()); |
|
50 |
if(selectedTreeNode!=null){ |
|
51 |
//context menu for Sequence |
|
52 |
if(selectedTreeNode.getValue() instanceof Sequence |
|
53 |
&& clipboardNode!=null && clipboardNode.getValue() instanceof SingleRead){ |
|
54 |
MenuItem item = new MenuItem(menu, SWT.NONE); |
|
55 |
item.setText(Messages.SingleReadSequenceContextMenu_REUSE_SINGLE_READ_HERE); |
|
56 |
item.addSelectionListener(new WidgetSelectionListener(CommandType.ADD_TO_SEQUENCE)); |
|
57 |
} |
|
58 |
else if(selectedTreeNode.getValue() instanceof SingleRead){ |
|
59 |
MenuItem item = new MenuItem(menu, SWT.NONE); |
|
60 |
item.setText(Messages.SingleReadSequenceContextMenu_REUSE_FOR_SEQUENCE); |
|
61 |
item.addSelectionListener(new WidgetSelectionListener(CommandType.COPY_TO_CLIPBOARD)); |
|
62 |
if(activeEditor instanceof DerivateView |
|
63 |
&& ((DerivateView) activeEditor).getMultiLinkSingleReads().contains(selectedTreeNode.getValue())){ |
|
64 |
MenuItem unlinkItem = new MenuItem(menu, SWT.NONE); |
|
65 |
unlinkItem.setText(Messages.SingleReadSequenceContextMenu_REMOVE_FROM_SEQUENCE); |
|
66 |
unlinkItem.addSelectionListener(new WidgetSelectionListener(CommandType.REMOVE_FROM_SEQUENCE)); |
|
42 |
boolean menuVisible = false; |
|
43 |
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
|
44 |
final ISelection selection = window.getActivePage().getSelection(); |
|
45 |
TreeNode selectedTreeNode = EditorUtil.getTreeNodeOfSelection(selection); |
|
46 |
TreeNode clipboardNode = EditorUtil.getTreeNodeOfSelection(LocalSelectionTransfer.getTransfer().getSelection()); |
|
47 |
if(selectedTreeNode!=null && |
|
48 |
(selectedTreeNode.getValue() instanceof Sequence && clipboardNode!=null && clipboardNode.getValue() instanceof SingleRead) |
|
49 |
|| (selectedTreeNode.getValue() instanceof SingleRead)){ |
|
50 |
menuVisible = true; |
|
51 |
} |
|
52 |
IContributionItem[] contributionItems = new IContributionItem[0]; |
|
53 |
if(menuVisible){ |
|
54 |
contributionItems = new IContributionItem[] { |
|
55 |
new Separator(), |
|
56 |
new ContributionItem() { |
|
57 |
@Override |
|
58 |
public void fill(Menu menu, int index) { |
|
59 |
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
|
60 |
final IEditorPart activeEditor = window.getActivePage().getActiveEditor(); |
|
61 |
final ISelection selection = window.getActivePage().getSelection(); |
|
62 |
TreeNode selectedTreeNode = EditorUtil.getTreeNodeOfSelection(selection); |
|
63 |
TreeNode clipboardNode = EditorUtil.getTreeNodeOfSelection(LocalSelectionTransfer.getTransfer().getSelection()); |
|
64 |
if(selectedTreeNode!=null){ |
|
65 |
//context menu for Sequence |
|
66 |
if(selectedTreeNode.getValue() instanceof Sequence |
|
67 |
&& clipboardNode!=null && clipboardNode.getValue() instanceof SingleRead){ |
|
68 |
MenuItem item = new MenuItem(menu, SWT.NONE); |
|
69 |
item.setText(Messages.SingleReadSequenceContextMenu_REUSE_SINGLE_READ_HERE); |
|
70 |
item.addSelectionListener(new WidgetSelectionListener(CommandType.ADD_TO_SEQUENCE)); |
|
71 |
} |
|
72 |
else if(selectedTreeNode.getValue() instanceof SingleRead){ |
|
73 |
MenuItem item = new MenuItem(menu, SWT.NONE); |
|
74 |
item.setText(Messages.SingleReadSequenceContextMenu_REUSE_FOR_SEQUENCE); |
|
75 |
item.addSelectionListener(new WidgetSelectionListener(CommandType.COPY_TO_CLIPBOARD)); |
|
76 |
if(activeEditor instanceof DerivateView |
|
77 |
&& ((DerivateView) activeEditor).getMultiLinkSingleReads().contains(selectedTreeNode.getValue())){ |
|
78 |
MenuItem unlinkItem = new MenuItem(menu, SWT.NONE); |
|
79 |
unlinkItem.setText(Messages.SingleReadSequenceContextMenu_REMOVE_FROM_SEQUENCE); |
|
80 |
unlinkItem.addSelectionListener(new WidgetSelectionListener(CommandType.REMOVE_FROM_SEQUENCE)); |
|
81 |
} |
|
67 | 82 |
} |
68 | 83 |
} |
69 | 84 |
} |
70 | 85 |
} |
71 |
}
|
|
72 |
};
|
|
86 |
};
|
|
87 |
} |
|
73 | 88 |
return contributionItems; |
74 | 89 |
} |
75 | 90 |
|
Also available in: Unified diff
Structure derivative editor context menu (#5406)