Project

General

Profile

Download (4.26 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.hibernate.HibernateProxyHelper;
16
import eu.etaxonomy.cdm.model.name.TaxonName;
17
import eu.etaxonomy.cdm.model.taxon.Taxon;
18
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
19
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
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 MisapplicationContainerE4 extends AbstractGroupedContainerE4<Taxon> {
34
	TaxonRelationship misapplication;
35

    
36
	public MisapplicationContainerE4(AbstractGroupE4 group, Taxon misappliedName) {
37
		super(group, misappliedName);
38

    
39
	}
40

    
41
	/** {@inheritDoc} */
42
	@Override
43
	protected void initializeComposite() {
44
		setIsDraggable(true);
45
		setFont(getViewerFont());
46
		TaxonNameEditorE4 editor = getEditor();
47
		Taxon taxon = editor.getTaxon();
48
		for (TaxonRelationship rel: taxon.getTaxonRelations(getMisappliedName())){
49
			if (rel.getType().isAnyMisappliedName()){
50
				misapplication = rel;
51
				break;
52
			}
53
		}
54
		showSec();
55

    
56
		initTextViewer();
57
	}
58

    
59
	@Override
60
	protected void updateIcon() {
61
		setIcon(MISAPPLIEDNAME_ICON);
62
	}
63

    
64
	private void showSec() {
65
		if (getMisappliedName() == null) {
66
			return;
67
		}
68
		String title = "";
69
		String author = "";
70
		TaxonName misappliedNameName = HibernateProxyHelper.deproxy(getMisappliedName().getName());
71
		if (StringUtils.isNotBlank(misappliedNameName.getAuthorshipCache())){
72
			author = ", non " + misappliedNameName.getAuthorshipCache();
73
		}
74
		if (getMisappliedName().getSec() == null) {
75
		    if (getMisappliedName().getAppendedPhrase() != null ){
76
		        title = getMisappliedName().getAppendedPhrase();
77
		    }else{
78
		        title = "auct.";
79

    
80
		    }
81

    
82
		} else {
83
			String sec = " sensu ";
84
			if (getMisappliedName().getAppendedPhrase() != null ){
85
			    sec = getMisappliedName().getAppendedPhrase() + " " + sec;
86
			}
87

    
88
			title += sec + getMisappliedName().getSec().getCacheStrategy().getCitation(getMisappliedName().getSec());
89
		}
90
		if (misapplication.getType().equals(TaxonRelationshipType.PRO_PARTE_MISAPPLIED_NAME_FOR()) ){
91
		    title += " p.p. ";
92
        }
93
		title += author;
94
		title = title.replace("&", "&&");
95
		setNonEditableInfo(title, false);
96
	}
97

    
98
	public Taxon getMisappliedName() {
99
		return getTaxonBase();
100
	}
101

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

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

    
117

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

    
124
	@Override
125
	protected void updateIndent() {
126
		setIndent(MISAPPLIEDNAME_INDENT);
127
	}
128

    
129
	@Override
130
	protected void initTextViewer() {
131

    
132
		// showNameRelations();
133

    
134
		updateIndent();
135

    
136
		updateIcon();
137

    
138
		String text = NameHelper.getDisplayNameCache(getData());
139

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

    
149
	@Override
150
    public void refresh() {
151
		// showNameRelations();
152

    
153
		String text = NameHelper.getDisplayNameCache(getData());
154

    
155
		if (getNameViewer().getTextWidget() == null) {
156
			// we might get here via dnd. Look slike it can be ignored
157
			return;
158
		}
159

    
160
		if (text.length() == 0) {
161
			initEmptyText();
162
		} else if (!getNameViewer().getTextWidget().getText().equals(text)) {
163
			removeListener();
164
			getNameViewer().getTextWidget().setText(text);
165
			addListener();
166
		}
167

    
168
		updateNonEditableInfo();
169

    
170
		updateIcon();
171
		// placeCursor();
172
		updateIndent();
173

    
174
		enableFreeText();
175
	}
176

    
177
}
(8-8/11)