commit 2fe68f382e1e7da510d531d414f96a8a4393bbb2
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Fri Mar 1 16:16:44 2019 +0100

    ref #6794 Adapt taxeditor to model changes (feature tree/node generics)

diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/DescriptiveDataSetComposite.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/DescriptiveDataSetComposite.java
index f10451d50..f72166ed2 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/DescriptiveDataSetComposite.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/DescriptiveDataSetComposite.java
@@ -23,6 +23,7 @@ import org.eclipse.swt.widgets.Text;
 import org.eclipse.swt.widgets.Tree;
 
 import eu.etaxonomy.cdm.model.common.TermType;
+import eu.etaxonomy.cdm.model.description.Character;
 import eu.etaxonomy.cdm.model.description.FeatureTree;
 import eu.etaxonomy.cdm.model.name.Rank;
 import eu.etaxonomy.cdm.persistence.dto.TermDto;
@@ -43,7 +44,7 @@ public class DescriptiveDataSetComposite extends Composite {
     private Text txtDescriptiveDataSet;
     private TermUuidComboViewer comboRankMin;
     private TermUuidComboViewer comboRankMax;
-    private FeatureTreeEditorComposite featureTreeEditorComposite;
+    private FeatureTreeEditorComposite<Character> featureTreeEditorComposite;
     private TreeViewer taxonNodeTree;
     private List<TermDto> areas = new ArrayList<>();
     private Text textAreaText;
@@ -134,7 +135,7 @@ public class DescriptiveDataSetComposite extends Composite {
         btnChooseArea = new Button(composite, SWT.NONE);
         btnChooseArea.setImage(ImageResources.getImage(ImageResources.BROWSE_ICON));
 
-        featureTreeEditorComposite = new FeatureTreeEditorComposite(this, SWT.NONE);
+        featureTreeEditorComposite = new FeatureTreeEditorComposite<Character>(this, SWT.NONE);
         featureTreeEditorComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
     }
 
@@ -160,14 +161,14 @@ public class DescriptiveDataSetComposite extends Composite {
         comboRankMax.setElement(max);
     }
 
-    public FeatureTreeEditorComposite getFeatureTreeEditorComposite() {
+    public FeatureTreeEditorComposite<Character> getFeatureTreeEditorComposite() {
         return featureTreeEditorComposite;
     }
 
-    public FeatureTree getCharacters(){
+    public FeatureTree<Character> getCharacters(){
         return featureTreeEditorComposite.getFeatureTree();
     }
-    public void setCharacters(FeatureTree characters) {
+    public void setCharacters(FeatureTree<Character> characters) {
         featureTreeEditorComposite.setSelectedTree(characters);
     }
 
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/DescriptiveDataSetEditor.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/DescriptiveDataSetEditor.java
index abde54554..06e1a6cbd 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/DescriptiveDataSetEditor.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/DescriptiveDataSetEditor.java
@@ -59,6 +59,7 @@ import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
 import eu.etaxonomy.cdm.api.service.ITermService;
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
 import eu.etaxonomy.cdm.model.common.TermType;
+import eu.etaxonomy.cdm.model.description.Character;
 import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
 import eu.etaxonomy.cdm.model.description.FeatureTree;
 import eu.etaxonomy.cdm.model.location.NamedArea;
@@ -288,7 +289,7 @@ IPartContentHasDetails, IPartContentHasSupplementalData, IDirtyMarkable {
                 }
             }
         }
-        FeatureTree characters = composite.getCharacters();
+        FeatureTree<Character> characters = composite.getCharacters();
         if(characters!=null){
             //save characters because they can be modified in this editor
             characters.getDistinctFeatures().forEach(character->CdmStore.getService(ITermService.class).merge(character,true));
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/character/CharacterEditor.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/character/CharacterEditor.java
index 888d988d6..bf1c06aaa 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/character/CharacterEditor.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/character/CharacterEditor.java
@@ -58,6 +58,7 @@ import eu.etaxonomy.cdm.api.service.IFeatureNodeService;
 import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
 import eu.etaxonomy.cdm.api.service.ITermService;
 import eu.etaxonomy.cdm.api.service.IVocabularyService;
+import eu.etaxonomy.cdm.model.common.DefinedTermBase;
 import eu.etaxonomy.cdm.model.common.Representation;
 import eu.etaxonomy.cdm.model.common.TermType;
 import eu.etaxonomy.cdm.model.common.TermVocabulary;
@@ -95,9 +96,9 @@ import eu.etaxonomy.taxeditor.workbench.part.IE4ViewerPart;
 public class CharacterEditor implements IFeatureTreeEditor,IConversationEnabled, ISelectionChangedListener,
         ModifyListener, IE4ViewerPart, IPartContentHasDetails, IPartContentHasSupplementalData, IDirtyMarkable {
 
-    private FeatureTreeEditorComposite characterTreeEditorComposite;
-    private FeatureTreeEditorComposite propertiesTreeEditorComposite;
-    private FeatureTreeEditorComposite structuresTreeEditorComposite;
+    private FeatureTreeEditorComposite<Character> characterTreeEditorComposite;
+    private FeatureTreeEditorComposite<DefinedTermBase> propertiesTreeEditorComposite;
+    private FeatureTreeEditorComposite<DefinedTermBase> structuresTreeEditorComposite;
     private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
 
     @Inject
@@ -228,7 +229,7 @@ public class CharacterEditor implements IFeatureTreeEditor,IConversationEnabled,
                 Collection<Character> characters = createCharacters((TreeSelection)structureTreeSelection, (TreeSelection)propertyTreeSelection);
                 for (Character character : characters) {
                     //add new Character to feature tree
-                    FeatureNode parent = ((FeatureTree) characterTreeEditorComposite.getViewer().getInput()).getRoot();
+                    FeatureNode<Character> parent = ((FeatureTree<Character>) characterTreeEditorComposite.getViewer().getInput()).getRoot();
                     vocabulary.addTerm(character);
                     CdmStore.getService(IFeatureNodeService.class).createChildFeatureNode(parent, character);
                 }
@@ -252,8 +253,8 @@ public class CharacterEditor implements IFeatureTreeEditor,IConversationEnabled,
 
     }
 
-    private FeatureTreeEditorComposite addFeatureTreeEditor(Composite composite_3) {
-        FeatureTreeEditorComposite featureTreeEditorComposite = new FeatureTreeEditorComposite(composite_3, SWT.NONE);
+    private <T extends DefinedTermBase> FeatureTreeEditorComposite<T> addFeatureTreeEditor(Composite composite_3) {
+        FeatureTreeEditorComposite<T> featureTreeEditorComposite = new FeatureTreeEditorComposite<>(composite_3, SWT.NONE);
         featureTreeEditorComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
         return featureTreeEditorComposite;
     }
@@ -292,14 +293,14 @@ public class CharacterEditor implements IFeatureTreeEditor,IConversationEnabled,
     public static Collection<Character> createCharacters(TreeSelection structureTreeSelection, TreeSelection propertyTreeSelection){
         Set<Character> characters = new HashSet<>();
         //get selected structures and properties
-        Iterator<FeatureNode> structureIterator = structureTreeSelection.iterator();
+        Iterator<FeatureNode<DefinedTermBase>> structureIterator = structureTreeSelection.iterator();
 
         //create all combinations of structures and properties
         while(structureIterator.hasNext()){
-            FeatureNode structureNode = structureIterator.next();
-            Iterator<FeatureNode> propertiesIterator = propertyTreeSelection.iterator();
+            FeatureNode<DefinedTermBase> structureNode = structureIterator.next();
+            Iterator<FeatureNode<DefinedTermBase>> propertiesIterator = propertyTreeSelection.iterator();
             while(propertiesIterator.hasNext()){
-                FeatureNode propertyNode = propertiesIterator.next();
+                FeatureNode<DefinedTermBase> propertyNode = propertiesIterator.next();
                 Representation structureRepresentation = structureNode.getTerm().getRepresentation(PreferencesUtil.getGlobalLanguage());
                 Representation propertyRepresentation = propertyNode.getTerm().getRepresentation(PreferencesUtil.getGlobalLanguage());
                 String label = null;
@@ -328,7 +329,7 @@ public class CharacterEditor implements IFeatureTreeEditor,IConversationEnabled,
         // commit the conversation and start a new transaction immediately
         conversation.commit(true);
 
-        FeatureTree featureTree = characterTreeEditorComposite.getFeatureTree();
+        FeatureTree<Character> featureTree = characterTreeEditorComposite.getFeatureTree();
         if(featureTree!=null){
             //save characters because they can be modified in this editor
             featureTree.getDistinctFeatures().forEach(character->CdmStore.getService(ITermService.class).merge(character,true));
@@ -382,8 +383,8 @@ public class CharacterEditor implements IFeatureTreeEditor,IConversationEnabled,
     }
 
     @Override
-    public List<FeatureTree> getRootEntities() {
-        List<FeatureTree> root = new ArrayList<>();
+    public List<FeatureTree<Character>> getRootEntities() {
+        List<FeatureTree<Character>> root = new ArrayList<>();
         root.add(characterTreeEditorComposite.getFeatureTree());
         return root;
     }
@@ -423,7 +424,7 @@ public class CharacterEditor implements IFeatureTreeEditor,IConversationEnabled,
         return (IStructuredSelection) characterTreeEditorComposite.getViewer().getSelection();
     }
 
-    public FeatureTree getCharacterTree(){
+    public FeatureTree<Character> getCharacterTree(){
         return characterTreeEditorComposite.getFeatureTree();
     }
 
@@ -435,10 +436,10 @@ public class CharacterEditor implements IFeatureTreeEditor,IConversationEnabled,
     }
 
     private class FeatureTreeChooserListener extends SelectionAdapter{
-        private FeatureTreeEditorComposite featureTreeEditorComposite;
+        private FeatureTreeEditorComposite<?> featureTreeEditorComposite;
         private TermType termType;
 
-        public FeatureTreeChooserListener(FeatureTreeEditorComposite featureTreeEditorComposite, TermType termType) {
+        public FeatureTreeChooserListener(FeatureTreeEditorComposite<?> featureTreeEditorComposite, TermType termType) {
             super();
             this.featureTreeEditorComposite = featureTreeEditorComposite;
             this.termType = termType;
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
index 343536d25..a016708d5 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
@@ -98,8 +98,6 @@ import eu.etaxonomy.cdm.api.application.CdmApplicationState;
 import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
 import eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO;
 import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
-import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
-import eu.etaxonomy.cdm.model.common.DefinedTermBase;
 import eu.etaxonomy.cdm.model.description.Character;
 import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
@@ -271,17 +269,11 @@ public class CharacterMatrix extends Composite {
         natTable.doCommand(new ClientAreaResizeCommand(natTable));
     }
 
-    private List<Character> initCharacterList(FeatureNode node){
+    private List<Character> initCharacterList(FeatureNode<Character> node){
         List<Character> characters = new ArrayList<>();
         node.getChildNodes().forEach(childNode->
                 {
-                    DefinedTermBase term = childNode.getTerm();
-                    // FIXME #8146 this is currently checked via the termType of the tree
-                    // in the init() method. This may be solved by adding generics to FeatureNode
-                    // so that getTerm is typified. This would make this check obsolete
-                    if(term.isInstanceOf(Character.class)){
-                        characters.add(HibernateProxyHelper.deproxy(term, Character.class));
-                    }
+                    characters.add(childNode.getTerm());
                     characters.addAll(initCharacterList(childNode));
                 });
         return characters;
@@ -290,7 +282,7 @@ public class CharacterMatrix extends Composite {
     public void initDescriptiveDataSet(DescriptiveDataSet descriptiveDataSet){
         this.descriptiveDataSet = descriptiveDataSet;
         //get features/columns stored in descriptive data set
-        FeatureTree tree = descriptiveDataSet.getDescriptiveSystem();
+        FeatureTree<Character> tree = descriptiveDataSet.getDescriptiveSystem();
         characters = initCharacterList(tree.getRoot());
 
         //init state data for categorical features
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/DynamicFeatureMenuE4.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/DynamicFeatureMenuE4.java
index 839143370..158b982d2 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/DynamicFeatureMenuE4.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/DynamicFeatureMenuE4.java
@@ -60,20 +60,20 @@ public class DynamicFeatureMenuE4 {
         Object selectedElement = selection.getFirstElement();
 
         if (selectedElement instanceof DescriptionBase<?>) {
-            FeatureTree featureTree = getFeatureTree((DescriptionBase<?>) selectedElement);
+            FeatureTree<?> featureTree = getFeatureTree((DescriptionBase<?>) selectedElement);
 
-            for (FeatureNode childNode : featureTree.getRootChildren()) {
+            for (FeatureNode<?> childNode : featureTree.getRootChildren()) {
                 createMenuItem(menu, childNode.getTerm(), globalLanguage);
             }
         } else if (selectedElement instanceof FeatureNodeContainer) {
-            FeatureNode featureNode = ((FeatureNodeContainer) selectedElement)
+            FeatureNode<?> featureNode = ((FeatureNodeContainer) selectedElement)
                     .getFeatureNode();
 
             // add the feature to the menu
             createMenuItem(menu, featureNode.getTerm(), globalLanguage);
 
             // add possible children to the menu
-            for (FeatureNode childNode : featureNode.getChildNodes()) {
+            for (FeatureNode<?> childNode : featureNode.getChildNodes()) {
                 createMenuItem(menu, childNode.getTerm(), globalLanguage);
             }
         } else if (selectedElement instanceof DescriptionElementBase) {
@@ -122,8 +122,8 @@ public class DynamicFeatureMenuE4 {
 	 * @param description
 	 * @return
 	 */
-	private FeatureTree getFeatureTree(DescriptionBase description) {
-		FeatureTree featureTree = null;
+	private FeatureTree<?> getFeatureTree(DescriptionBase description) {
+		FeatureTree<?> featureTree = null;
 
 		// TODO change this to the feature tree associated with this taxon
 		// description
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureTreeEditorComposite.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureTreeEditorComposite.java
index b3ce573e2..507550778 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureTreeEditorComposite.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureTreeEditorComposite.java
@@ -28,6 +28,7 @@ import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.swt.widgets.Tree;
 
+import eu.etaxonomy.cdm.model.common.DefinedTermBase;
 import eu.etaxonomy.cdm.model.common.TermType;
 import eu.etaxonomy.cdm.model.description.FeatureTree;
 import eu.etaxonomy.taxeditor.editor.definedterm.TermTransfer;
@@ -44,9 +45,9 @@ import eu.etaxonomy.taxeditor.ui.dialog.selection.FeatureTreeSelectionDialog;
  * @since Jun 19, 2017
  *
  */
-public class FeatureTreeEditorComposite extends Composite{
+public class FeatureTreeEditorComposite <T extends DefinedTermBase> extends Composite{
 
-    private FeatureTree featureTree;
+    private FeatureTree<T> featureTree;
 
     private Label label_title;
     private Text text_title;
@@ -180,7 +181,7 @@ public class FeatureTreeEditorComposite extends Composite{
             btnOpenFeatureTree.addSelectionListener(new SelectionAdapter(){
                 @Override
                 public void widgetSelected(SelectionEvent e) {
-                    FeatureTree tree = FeatureTreeSelectionDialog.select(getDisplay().getActiveShell(),
+                    FeatureTree<T> tree = FeatureTreeSelectionDialog.select(getDisplay().getActiveShell(),
                             null, termType);
                     if(tree!=null){
                         setSelectedTree(tree);
@@ -193,7 +194,7 @@ public class FeatureTreeEditorComposite extends Composite{
         }
     }
 
-    public void setSelectedTree(FeatureTree featureTree) {
+    public void setSelectedTree(FeatureTree<T> featureTree) {
         this.featureTree = featureTree;
 
         viewer.setInput(featureTree);
@@ -208,7 +209,7 @@ public class FeatureTreeEditorComposite extends Composite{
         }
     }
 
-    public FeatureTree getFeatureTree() {
+    public FeatureTree<T> getFeatureTree() {
         return featureTree;
     }
 
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/FeatureNodeContainer.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/FeatureNodeContainer.java
index a38ddd7fb..ba6eb3e10 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/FeatureNodeContainer.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/FeatureNodeContainer.java
@@ -41,7 +41,7 @@ public class FeatureNodeContainer{
 
 
 
-	private FeatureNode featureNode;
+	private FeatureNode<Feature> featureNode;
 	private List<FeatureNodeContainer> children = new ArrayList<FeatureNodeContainer>();
 	private List<DescriptionElementBase> descriptionElements = new ArrayList<DescriptionElementBase>();
 
@@ -64,11 +64,11 @@ public class FeatureNodeContainer{
 	 * @param description
 	 * @return
 	 */
-	protected void findLeaves(FeatureNode featureNode) {
+	protected void findLeaves(FeatureNode<Feature> featureNode) {
 		if(featureNode.isLeaf()){
 			buildLeaf(featureNode);
 		}else{
-			for(FeatureNode childNode : featureNode.getChildNodes()){
+			for(FeatureNode<Feature> childNode : featureNode.getChildNodes()){
 				findLeaves(childNode);
 			}
 		}
@@ -80,12 +80,12 @@ public class FeatureNodeContainer{
 	 * @param description
 	 * @return
 	 */
-	private void buildLeaf(FeatureNode featureNode){
-		if(featureNode.getFeature() == null){
+	private void buildLeaf(FeatureNode<Feature> featureNode){
+		if(featureNode.getTerm() == null){
 			throw new IllegalArgumentException("The given feature node does not have a feature.");
 		}
 
-		Feature feature = (Feature) HibernateProxyHelper.deproxy(featureNode.getFeature());
+		Feature feature = HibernateProxyHelper.deproxy(featureNode.getTerm());
 
 		// get feature node container for the given feature
 		FeatureNodeContainer container = containerTree.getFeatureNodeContainer(feature);
@@ -140,7 +140,7 @@ public class FeatureNodeContainer{
 	 */
 	private void buildBranch(){
 		if(getParent() == null){
-			FeatureNode parentFeatureNode = getFeatureNode().getParent();
+			FeatureNode<Feature> parentFeatureNode = getFeatureNode().getParent();
 
 			if(parentFeatureNode.isRoot()){
 				containerTree.getRoot().addChild(this);
@@ -277,7 +277,7 @@ public class FeatureNodeContainer{
 	 *
 	 * @param featureNode a {@link eu.etaxonomy.cdm.model.description.FeatureNode} object.
 	 */
-	public void setFeatureNode(FeatureNode featureNode) {
+	public void setFeatureNode(FeatureNode<Feature> featureNode) {
 		this.featureNode = featureNode;
 	}
 
@@ -286,7 +286,7 @@ public class FeatureNodeContainer{
 	 *
 	 * @return a {@link eu.etaxonomy.cdm.model.description.FeatureNode} object.
 	 */
-	public FeatureNode getFeatureNode() {
+	public FeatureNode<Feature> getFeatureNode() {
 		return featureNode;
 	}
 
@@ -297,7 +297,7 @@ public class FeatureNodeContainer{
 	 */
 	public Feature getFeature(){
 		if(featureNode != null){
-			return featureNode.getFeature();
+			return featureNode.getTerm();
 		}
 		return null;
 	}
