Merge branch 'develop' into nameEditorE4
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / e4 / container / AcceptedGroupE4.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.taxeditor.editor.name.e4.container;
11
12 import java.util.ArrayList;
13 import java.util.List;
14
15 import org.eclipse.swt.graphics.Color;
16
17 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
18 import eu.etaxonomy.cdm.model.taxon.Synonym;
19 import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
20 import eu.etaxonomy.taxeditor.model.AbstractUtility;
21 import eu.etaxonomy.taxeditor.preference.Resources;
22
23 /**
24 *
25 * @author pplitzner
26 * @date Aug 24, 2017
27 *
28 */
29 public class AcceptedGroupE4 extends AbstractHomotypicalGroupContainerE4 {
30
31 private AcceptedNameContainerE4 acceptedContainer;
32
33 public AcceptedGroupE4(TaxonNameEditorE4 editor, HomotypicalGroup group) {
34 super(editor, group);
35 }
36
37 @Override
38 public void dragEntered() {
39 Color color = AbstractUtility.getColor(Resources.COLOR_DRAG_ENTER);
40 acceptedContainer.setBackground(color);
41 super.dragEntered();
42 }
43
44 @Override
45 public void dragLeft() {
46 acceptedContainer.restoreColor();
47 super.dragLeft();
48 }
49
50 @Override
51 public List<AbstractGroupedContainerE4> getGroupedContainers() {
52 List<AbstractGroupedContainerE4> containers = new ArrayList<>();
53 containers.add(getAcceptedNameContainer());
54 containers.addAll(super.getGroupedContainers());
55 return containers;
56 }
57
58 @Override
59 protected void createContainers() {
60 this.acceptedContainer = new AcceptedNameContainerE4(getEditor().getTaxon());
61 acceptedContainer.setGroup(this);
62
63 acceptedContainer.createContent();
64
65 createSynonymContainer();
66 }
67
68 @Override
69 protected void createSynonymContainer(){
70 for(Synonym synonym : getSynonyms()){
71 SynonymContainerE4 container = new SynonymContainerE4(this, synonym);
72 this.add(container);
73 container.createContent();
74 }
75 }
76
77 public void setAcceptedNameContainer(AcceptedNameContainerE4 acceptedNameContainer) {
78 this.acceptedContainer = acceptedNameContainer;
79 acceptedContainer.setGroup(this);
80 }
81
82 public AcceptedNameContainerE4 getAcceptedNameContainer(){
83 return acceptedContainer;
84 }
85
86 @Override
87 protected void emptyGroup() {
88 acceptedContainer.dispose();
89 acceptedContainer = null;
90 super.emptyGroup();
91 }
92
93 @Override
94 protected boolean redrawNeeded(HomotypicalGroup homotypicalGroup) {
95 if(! acceptedContainer.getData().equals(getEditor().getTaxon())){
96 return true;
97 }
98 return super.redrawNeeded(homotypicalGroup);
99 }
100 }