Project

General

Profile

Download (4.8 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 javax.persistence.GenerationType;
13

    
14
import org.eclipse.swt.graphics.Font;
15

    
16
import eu.etaxonomy.cdm.model.taxon.Taxon;
17
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
18
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
19
import eu.etaxonomy.taxeditor.editor.EditorUtil;
20
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
21
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
22
import eu.etaxonomy.taxeditor.model.NameHelper;
23
import eu.etaxonomy.taxeditor.preference.Resources;
24

    
25
/**
26
 * <p>MisapplicationContainer class.</p>
27
 *
28
 * @author p.ciardelli
29
 * @created 13.01.2009
30
 * @version 1.0
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

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

    
66
		initTextViewer();
67
	}
68

    
69
	@Override
70
	protected void updateIcon() {
71
		setIcon(MISAPPLIEDNAME_ICON);
72
	}
73

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

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

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

    
118
	/* (non-Javadoc)
119
	 * @see eu.etaxonomy.taxeditor.editor.name.container.AbstractGroupedContainer#showAnnotations()
120
	 */
121
	@Override
122
	public void showAnnotations() {
123
		if(getData().getSec() == null){
124
			getNameViewer().addAnnotation(
125
					new EditorAnnotation(0, Messages.MisapplicationContainer_SEC_REF_REQUIRED));
126
		}
127
		super.showAnnotations();
128
	}
129

    
130

    
131
	/** {@inheritDoc} */
132
	@Override
133
	protected void updateNonEditableInfo() {
134
		showSec();
135
	}
136

    
137

    
138
	/* (non-Javadoc)
139
	 * @see eu.etaxonomy.taxeditor.editor.name.AbstractGroupedContainer#updateIndent()
140
	 */
141
	@Override
142
	protected void updateIndent() {
143
		setIndent(MISAPPLIEDNAME_INDENT);
144
	}
145
	
146
	/**
147
	 * <p>
148
	 * initTextViewer
149
	 * </p>
150
	 */
151
	@Override
152
	protected void initTextViewer() {
153

    
154
		// showNameRelations();
155

    
156
		updateIndent();
157

    
158
		updateIcon();
159

    
160
		String text = NameHelper.getDisplayNameCache(getData());
161

    
162
		if (text.length() == 0) {
163
			initEmptyText();
164
		} else {
165
			getNameViewer().setText(text);
166
			placeCursor();
167
		}
168
		calculateAnnotations();
169
	}
170
	
171
	@Override
172
    public void refresh() {
173
		// showNameRelations();
174

    
175
		String text = NameHelper.getDisplayNameCache(getData());
176

    
177
		if (getNameViewer().getTextWidget() == null) {
178
			// we might get here via dnd. Look slike it can be ignored
179
			return;
180
		}
181

    
182
		if (text.length() == 0) {
183
			initEmptyText();
184
		} else if (!getNameViewer().getTextWidget().getText().equals(text)) {
185
			removeListener();
186
			getNameViewer().getTextWidget().setText(text);
187
			addListener();
188
		}
189

    
190
		updateNonEditableInfo();
191

    
192
		updateIcon();
193
		// placeCursor();
194
		updateIndent();
195

    
196
		enableFreeText();
197
	}
198

    
199
}
(15-15/19)