Project

General

Profile

Download (4.69 KB) Statistics
| Branch: | Tag: | Revision:
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.Font;
16

    
17
import eu.etaxonomy.cdm.format.taxon.TaxonRelationshipFormatter;
18
import eu.etaxonomy.cdm.model.common.Language;
19
import eu.etaxonomy.cdm.model.taxon.Taxon;
20
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
21
import eu.etaxonomy.cdm.strategy.cache.TaggedCacheHelper;
22
import eu.etaxonomy.cdm.strategy.cache.TaggedText;
23
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
24
import eu.etaxonomy.taxeditor.editor.name.container.EditorAnnotation;
25
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
26
import eu.etaxonomy.taxeditor.model.AbstractUtility;
27
import eu.etaxonomy.taxeditor.model.NameHelper;
28
import eu.etaxonomy.taxeditor.preference.Resources;
29
import eu.etaxonomy.taxeditor.store.CdmStore;
30

    
31
/**
32
 *
33
 * @author pplitzner
34
 * @date Aug 24, 2017
35
 *
36
 */
37
public class ConceptContainerE4 extends AbstractGroupedContainerE4<Taxon> {
38
	TaxonRelationship relationship;
39
	TaxonRelationshipFormatter misappliedFormatter;
40

    
41
	private boolean isMisapplication;
42

    
43
	public ConceptContainerE4(AbstractGroupE4 group, Taxon misappliedName, boolean isMisapplication) {
44
		super(group, misappliedName);
45
		this.isMisapplication = isMisapplication;
46
		misappliedFormatter = new TaxonRelationshipFormatter();
47

    
48
	}
49

    
50
	/** {@inheritDoc} */
51
	@Override
52
	protected void initializeComposite() {
53
		setIsDraggable(true);
54
		setFont(getViewerFont());
55
		TaxonNameEditorE4 editor = getEditor();
56
		Taxon taxon = editor.getTaxon();
57
		for (TaxonRelationship rel: taxon.getTaxonRelations(getMisappliedName())){
58
			if (rel.getType().isAnyMisappliedName() && isMisapplication){
59
			    relationship = rel;
60
				break;
61
			}else if (rel.getType().isAnySynonym() && !isMisapplication){
62
			    relationship = rel;
63
                break;
64
			}
65
		}
66
		showSec();
67

    
68
		initTextViewer();
69
	}
70

    
71
	@Override
72
	protected void updateIcon() {
73
	    if (relationship.getType().isAnyMisappliedName()){
74
	        setIcon(MISAPPLIEDNAME_ICON);
75
	    }else if (relationship.getType().isProParte()){
76
	        setIcon(PRO_PARTE_SYNONYM_ICON);
77
	    }else {
78
            setIcon(PARTIAL_SYNONYM_ICON);
79
        }
80
	}
81

    
82
	private void showSec() {
83
		if (getMisappliedName() == null) {
84
			return;
85
		}
86
		List<Language> languages = new ArrayList<>();
87
		languages.add(CdmStore.getDefaultLanguage());
88
		List<TaggedText> taggedText = misappliedFormatter.getTaggedText(relationship, true, languages, true);
89
		if (taggedText != null){
90
    		String title = TaggedCacheHelper.createString(taggedText);
91
    		title = title.replace("&", "&&");
92
    		setNonEditableInfo(title, false);
93
		}
94
	}
95

    
96
	public Taxon getMisappliedName() {
97
		return getTaxonBase();
98
	}
99

    
100
	/** {@inheritDoc} */
101
	@Override
102
	protected Font getViewerFont() {
103
		return AbstractUtility.getFont(Resources.MISAPPLIEDNAME_FONT);
104
	}
105

    
106
	@Override
107
	public void showAnnotations() {
108
		if(getData().getSec() == null){
109
			getNameViewer().addAnnotation(
110
					new EditorAnnotation(0, Messages.MisapplicationContainer_SEC_REF_REQUIRED));
111
		}
112
		super.showAnnotations();
113
	}
114

    
115

    
116
	/** {@inheritDoc} */
117
	@Override
118
	protected void updateNonEditableInfo() {
119
		showSec();
120
	}
121

    
122
	@Override
123
	protected void updateIndent() {
124
		setIndent(MISAPPLIEDNAME_INDENT);
125
	}
126

    
127
	@Override
128
	protected void initTextViewer() {
129

    
130
		// showNameRelations();
131

    
132
		updateIndent();
133

    
134
		updateIcon();
135
		String text;
136
		if (isMisapplication){
137
		    text = NameHelper.getDisplayNameCache(getData());
138
		}else{
139
		    text = NameHelper.getDisplayName(getData());
140
		}
141

    
142
		if (text.length() == 0) {
143
			initEmptyText();
144
		} else {
145
			getNameViewer().setText(text);
146
			placeCursor();
147
		}
148
		calculateAnnotations();
149
	}
150

    
151
	@Override
152
    public void refresh() {
153
		// showNameRelations();
154
	    if (relationship.getType().isAnyMisappliedName()){
155
	        isMisapplication = true;
156
	    }else{
157
	        isMisapplication = false;
158
	    }
159
		String text;
160
		if (isMisapplication){
161
            text = NameHelper.getDisplayNameCache(getData());
162
        }else{
163
            text = NameHelper.getDisplayName(getData());
164
        }
165

    
166

    
167
		if (getNameViewer().getTextWidget() == null) {
168
			// we might get here via dnd. Look slike it can be ignored
169
			return;
170
		}
171

    
172
		if (text.length() == 0) {
173
			initEmptyText();
174
		} else if (!getNameViewer().getTextWidget().getText().equals(text)) {
175
			removeListener();
176
			getNameViewer().getTextWidget().setText(text);
177
			addListener();
178
		}
179

    
180
		updateNonEditableInfo();
181

    
182
		updateIcon();
183
		// placeCursor();
184
		updateIndent();
185
		setDelayedSelection();
186

    
187
		enableFreeText();
188
	}
189

    
190
}
(6-6/11)