Project

General

Profile

Download (6.08 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 org.apache.commons.lang.StringUtils;
13
import org.eclipse.swt.graphics.Font;
14

    
15
import eu.etaxonomy.cdm.format.taxon.TaxonRelationshipFormatter;
16
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
17
import eu.etaxonomy.cdm.model.name.TaxonName;
18
import eu.etaxonomy.cdm.model.taxon.Taxon;
19
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
20
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
21
import eu.etaxonomy.taxeditor.editor.name.container.EditorAnnotation;
22
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
23
import eu.etaxonomy.taxeditor.model.AbstractUtility;
24
import eu.etaxonomy.taxeditor.model.NameHelper;
25
import eu.etaxonomy.taxeditor.preference.Resources;
26

    
27
/**
28
 *
29
 * @author pplitzner
30
 * @date Aug 24, 2017
31
 *
32
 */
33
public class ConceptContainerE4 extends AbstractGroupedContainerE4<Taxon> {
34
	TaxonRelationship relationship;
35
	TaxonRelationshipFormatter misappliedFormatter;
36

    
37
	private boolean isMisapplication;
38

    
39
	public ConceptContainerE4(AbstractGroupE4 group, Taxon misappliedName, boolean isMisapplication) {
40
		super(group, misappliedName);
41
		this.isMisapplication = isMisapplication;
42
		misappliedFormatter = new TaxonRelationshipFormatter();
43

    
44
	}
45

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

    
64
		initTextViewer();
65
	}
66

    
67
	@Override
68
	protected void updateIcon() {
69
	    if (relationship.getType().isAnyMisappliedName()){
70
	        setIcon(MISAPPLIEDNAME_ICON);
71
	    }else if (relationship.getType().isProParte()){
72
	        setIcon(PRO_PARTE_SYNONYM_ICON);
73
	    }else {
74
            setIcon(PARTIAL_SYNONYM_ICON);
75
        }
76
	}
77

    
78
	private void showSec() {
79
		if (getMisappliedName() == null) {
80
			return;
81
		}
82
		String title = "";
83
		String author = "";
84
		TaxonName conceptName = HibernateProxyHelper.deproxy(getMisappliedName().getName());
85

    
86
		  if (isMisapplication && StringUtils.isNotBlank(conceptName.getAuthorshipCache())){
87
	            author = ", non " + conceptName.getAuthorshipCache();
88
	        }
89
	        if ((isMisapplication &&getMisappliedName().getSec() == null) || (!isMisapplication && relationship.getCitation() == null)) {
90
	            if (getMisappliedName().getAppendedPhrase() != null ){
91
	                title = getMisappliedName().getAppendedPhrase();
92
	            }else if (isMisapplication){
93
	                title = "auct.";
94

    
95
	            }
96

    
97
	        } else {
98
	            String sec ;
99
	            if (isMisapplication){
100
	                sec = " sensu ";
101
	            }else{
102
	                sec = " syn. sec. ";
103
	            }
104
	            if (getMisappliedName().getAppendedPhrase() != null ){
105
	                sec = getMisappliedName().getAppendedPhrase() + " " + sec;
106
	            }
107
	            if (isMisapplication){
108
	                title += sec + getMisappliedName().getSec().getCacheStrategy().getCitation(getMisappliedName().getSec());
109
	            }else{
110
	                title += sec + relationship.getCitation().getCacheStrategy().getCitation(relationship.getCitation());
111
	            }
112
	        }
113
	        if (relationship.getType().isProParte() && isMisapplication){
114
	            title += " p.p. ";
115
	        }
116
	        title += author;
117
	        title = title.replace("&", "&&");
118
	        setNonEditableInfo(title, false);
119

    
120

    
121
//
122
//		List<Language> languages = new ArrayList<>();
123
//		languages.add(CdmStore.getDefaultLanguage());
124
//		List<TaggedText> taggedText = misappliedFormatter.getTaggedText(relationship, true, languages);
125
//
126
//		String title2 = TaggedCacheHelper.createString(taggedText.subList(5, taggedText.size()));
127
//
128
//
129
//		setNonEditableInfo(title2, false);
130
	}
131

    
132
	public Taxon getMisappliedName() {
133
		return getTaxonBase();
134
	}
135

    
136
	/** {@inheritDoc} */
137
	@Override
138
	protected Font getViewerFont() {
139
		return AbstractUtility.getFont(Resources.MISAPPLIEDNAME_FONT);
140
	}
141

    
142
	@Override
143
	public void showAnnotations() {
144
		if(getData().getSec() == null){
145
			getNameViewer().addAnnotation(
146
					new EditorAnnotation(0, Messages.MisapplicationContainer_SEC_REF_REQUIRED));
147
		}
148
		super.showAnnotations();
149
	}
150

    
151

    
152
	/** {@inheritDoc} */
153
	@Override
154
	protected void updateNonEditableInfo() {
155
		showSec();
156
	}
157

    
158
	@Override
159
	protected void updateIndent() {
160
		setIndent(MISAPPLIEDNAME_INDENT);
161
	}
162

    
163
	@Override
164
	protected void initTextViewer() {
165

    
166
		// showNameRelations();
167

    
168
		updateIndent();
169

    
170
		updateIcon();
171
		String text;
172
		if (isMisapplication){
173
		    text = NameHelper.getDisplayNameCache(getData());
174
		}else{
175
		    text = NameHelper.getDisplayName(getData());
176
		}
177

    
178
		if (text.length() == 0) {
179
			initEmptyText();
180
		} else {
181
			getNameViewer().setText(text);
182
			placeCursor();
183
		}
184
		calculateAnnotations();
185
	}
186

    
187
	@Override
188
    public void refresh() {
189
		// showNameRelations();
190
	    if (relationship.getType().isAnyMisappliedName()){
191
	        isMisapplication = true;
192
	    }else{
193
	        isMisapplication = false;
194
	    }
195
		String text;
196
		if (isMisapplication){
197
            text = NameHelper.getDisplayNameCache(getData());
198
        }else{
199
            text = NameHelper.getDisplayName(getData());
200
        }
201

    
202

    
203
		if (getNameViewer().getTextWidget() == null) {
204
			// we might get here via dnd. Look slike it can be ignored
205
			return;
206
		}
207

    
208
		if (text.length() == 0) {
209
			initEmptyText();
210
		} else if (!getNameViewer().getTextWidget().getText().equals(text)) {
211
			removeListener();
212
			getNameViewer().getTextWidget().setText(text);
213
			addListener();
214
		}
215

    
216
		updateNonEditableInfo();
217

    
218
		updateIcon();
219
		// placeCursor();
220
		updateIndent();
221
		setDelayedSelection();
222

    
223
		enableFreeText();
224
	}
225

    
226
}
(6-6/11)