Project

General

Profile

Download (4.16 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().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
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
		title += author;
91
		title = title.replace("&", "&&");
92
		setNonEditableInfo(title, false);
93
	}
94

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

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

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

    
114

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

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

    
126
	@Override
127
	protected void initTextViewer() {
128

    
129
		// showNameRelations();
130

    
131
		updateIndent();
132

    
133
		updateIcon();
134

    
135
		String text = NameHelper.getDisplayNameCache(getData());
136

    
137
		if (text.length() == 0) {
138
			initEmptyText();
139
		} else {
140
			getNameViewer().setText(text);
141
			placeCursor();
142
		}
143
		calculateAnnotations();
144
	}
145

    
146
	@Override
147
    public void refresh() {
148
		// showNameRelations();
149

    
150
		String text = NameHelper.getDisplayNameCache(getData());
151

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

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

    
165
		updateNonEditableInfo();
166

    
167
		updateIcon();
168
		// placeCursor();
169
		updateIndent();
170

    
171
		enableFreeText();
172
	}
173

    
174
}
(8-8/11)