Project

General

Profile

Download (4.11 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(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
			title += sec + getMisappliedName().getSec().getTitleCache();
88
		}
89
		title += author;
90
		title = title.replace("&", "&&");
91
		setNonEditableInfo(title, false);
92
	}
93

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

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

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

    
113

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

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

    
125
	@Override
126
	protected void initTextViewer() {
127

    
128
		// showNameRelations();
129

    
130
		updateIndent();
131

    
132
		updateIcon();
133

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

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

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

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

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

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

    
164
		updateNonEditableInfo();
165

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

    
170
		enableFreeText();
171
	}
172

    
173
}
(8-8/10)