Project

General

Profile

Download (4.6 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.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.EditorUtil;
21
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
22
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
23
import eu.etaxonomy.taxeditor.model.NameHelper;
24
import eu.etaxonomy.taxeditor.preference.Resources;
25

    
26
/**
27
 * <p>MisapplicationContainer class.</p>
28
 *
29
 * @author p.ciardelli
30
 * @created 13.01.2009
31
 */
32
public class MisapplicationContainer extends AbstractGroupedContainer<Taxon> {
33
	TaxonRelationship misapplication;
34

    
35
	/**
36
	 * <p>Constructor for MisapplicationContainer.</p>
37
	 *
38
	 * @param editor a {@link eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor} object.
39
	 * @param group a {@link eu.etaxonomy.taxeditor.editor.name.container.AbstractGroup} object.
40
	 * @param misappliedName a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
41
	 */
42
	public MisapplicationContainer(AbstractGroup group, Taxon misappliedName) {
43
		super(misappliedName);
44
		
45
	}
46

    
47
	/** {@inheritDoc} */
48
	@Override
49
	protected void initializeComposite() {
50
		setIsDraggable(true);
51
		setFont(getViewerFont());
52
		TaxonNameEditor editor = getEditor();
53
		Taxon taxon = editor.getTaxon();
54
		for (TaxonRelationship rel: taxon.getTaxonRelations(getMisappliedName())){
55
			if (rel.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
56
				misapplication = rel;
57
				break;
58
			}
59
		}
60
		showSec();
61

    
62
		initTextViewer();
63
	}
64

    
65
	@Override
66
	protected void updateIcon() {
67
		setIcon(MISAPPLIEDNAME_ICON);
68
	}
69

    
70
	private void showSec() {
71
		if (getMisappliedName() == null) {
72
			return;
73
		}
74
		String title = "";
75
		String author = "";
76
		TaxonName misappliedNameName = HibernateProxyHelper.deproxy(getMisappliedName().getName());
77
		if (StringUtils.isNotBlank(misappliedNameName.getAuthorshipCache())){
78
			author = ", non " + misappliedNameName.getAuthorshipCache();
79
		}
80
		if (misapplication.getCitation() == null) {
81
		    if (getMisappliedName().getAppendedPhrase() != null ){
82
		        title = getMisappliedName().getAppendedPhrase();
83
		    }else{
84
		        title = "auct."; //$NON-NLS-1$
85
		        
86
		    }
87
		  
88
		} else {
89
			String sec = " sensu "; //$NON-NLS-1$
90
			if (getMisappliedName().getAppendedPhrase() != null ){
91
			    sec = getMisappliedName().getAppendedPhrase() + " "+sec; //$NON-NLS-1$
92
			}
93
			title += sec + getMisappliedName().getSec().getTitleCache();
94
		}
95
		title += author;
96
		title = title.replace("&", "&&"); //$NON-NLS-1$ //$NON-NLS-2$
97
		setNonEditableInfo(title, false);
98
	}
99

    
100
	/**
101
	 * <p>getMisappliedName</p>
102
	 *
103
	 * @return a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
104
	 */
105
	public Taxon getMisappliedName() {
106
		return getTaxonBase();
107
	}
108

    
109
	/** {@inheritDoc} */
110
	@Override
111
	protected Font getViewerFont() {
112
		return EditorUtil.getFont(Resources.MISAPPLIEDNAME_FONT);
113
	}
114

    
115
	@Override
116
	public void showAnnotations() {
117
		if(getData().getSec() == null){
118
			getNameViewer().addAnnotation(
119
					new EditorAnnotation(0, Messages.MisapplicationContainer_SEC_REF_REQUIRED));
120
		}
121
		super.showAnnotations();
122
	}
123

    
124

    
125
	/** {@inheritDoc} */
126
	@Override
127
	protected void updateNonEditableInfo() {
128
		showSec();
129
	}
130

    
131
	@Override
132
	protected void updateIndent() {
133
		setIndent(MISAPPLIEDNAME_INDENT);
134
	}
135
	
136
	/**
137
	 * <p>
138
	 * initTextViewer
139
	 * </p>
140
	 */
141
	@Override
142
	protected void initTextViewer() {
143

    
144
		// showNameRelations();
145

    
146
		updateIndent();
147

    
148
		updateIcon();
149

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

    
152
		if (text.length() == 0) {
153
			initEmptyText();
154
		} else {
155
			getNameViewer().setText(text);
156
			placeCursor();
157
		}
158
		calculateAnnotations();
159
	}
160
	
161
	@Override
162
    public void refresh() {
163
		// showNameRelations();
164

    
165
		String text = NameHelper.getDisplayNameCache(getData());
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

    
186
		enableFreeText();
187
	}
188

    
189
}
(15-15/19)