Merge branch 'release/4.6.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / command / BulkEditorSelectionPropertyTester.java
1 package eu.etaxonomy.taxeditor.bulkeditor.command;
2
3 import org.eclipse.core.expressions.PropertyTester;
4 import org.eclipse.jface.viewers.IStructuredSelection;
5 import org.eclipse.jface.viewers.TreeNode;
6
7 import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
8 import eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInputType;
9
10 public class BulkEditorSelectionPropertyTester extends PropertyTester {
11
12 public static final String IS_BULK_EDITOR_SUPPORTED = "isBulkEditorSupported";
13
14 @Override
15 public boolean test(Object receiver, String property, Object[] args,
16 Object expectedValue) {
17 if(IS_BULK_EDITOR_SUPPORTED.equals(property)){
18 if(receiver instanceof IStructuredSelection){
19 IStructuredSelection selection = (IStructuredSelection) receiver;
20 Object selectedElement = selection.getFirstElement();
21 if(selectedElement!=null){
22 if(selectedElement instanceof UuidAndTitleCache){
23 return BulkEditorInputType.getByType(((UuidAndTitleCache) selectedElement).getType())!=null;
24 }
25 else if(selectedElement instanceof TreeNode){
26 System.out.println(BulkEditorInputType.getByType(((TreeNode) selectedElement).getValue().getClass())!=null);
27 return BulkEditorInputType.getByType(((TreeNode) selectedElement).getValue().getClass())!=null;
28 }
29 return BulkEditorInputType.getByType(selectedElement.getClass())!=null;
30 }
31 }
32 }
33 return false;
34 }
35
36 }