Project

General

Profile

Download (4.66 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.cdm.strategy.cache.reference.DefaultReferenceCacheStrategy;
21
import eu.etaxonomy.taxeditor.editor.EditorUtil;
22
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
23
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
24
import eu.etaxonomy.taxeditor.model.NameHelper;
25
import eu.etaxonomy.taxeditor.preference.Resources;
26

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

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

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

    
63
		initTextViewer();
64
	}
65

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

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

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

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

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

    
126

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

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

    
146
		// showNameRelations();
147

    
148
		updateIndent();
149

    
150
		updateIcon();
151

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

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

    
167
		String text = NameHelper.getDisplayNameCache(getData());
168

    
169
		if (getNameViewer().getTextWidget() == null) {
170
			// we might get here via dnd. Look slike it can be ignored
171
			return;
172
		}
173

    
174
		if (text.length() == 0) {
175
			initEmptyText();
176
		} else if (!getNameViewer().getTextWidget().getText().equals(text)) {
177
			removeListener();
178
			getNameViewer().getTextWidget().setText(text);
179
			addListener();
180
		}
181

    
182
		updateNonEditableInfo();
183

    
184
		updateIcon();
185
		// placeCursor();
186
		updateIndent();
187

    
188
		enableFreeText();
189
	}
190

    
191
}
(15-15/19)