performed javacscript:fix and worked on documentation
[taxeditor.git] / taxeditor-bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / BulkEditorLineDisplay.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.bulkeditor;
12
13 import org.eclipse.jface.action.IStatusLineManager;
14 import org.eclipse.swt.graphics.Font;
15 import org.eclipse.swt.graphics.Image;
16 import org.eclipse.swt.widgets.Display;
17 import org.eclipse.ui.IEditorPart;
18
19 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
20 import eu.etaxonomy.cdm.model.agent.AgentBase;
21 import eu.etaxonomy.cdm.model.common.CdmBase;
22 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
23 import eu.etaxonomy.cdm.model.common.Marker;
24 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
25 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
26 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
27 import eu.etaxonomy.taxeditor.annotatedlineeditor.EntityListener;
28 import eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy;
29 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
30
31 /**
32 * <p>BulkEditorLineDisplay class.</p>
33 *
34 * @author p.ciardelli
35 * @created 07.07.2009
36 * @version 1.0
37 */
38 public class BulkEditorLineDisplay implements ILineDisplayStrategy {
39
40 private IEditorPart editor;
41
42 /**
43 * <p>Constructor for BulkEditorLineDisplay.</p>
44 *
45 * @param editor a {@link org.eclipse.ui.IEditorPart} object.
46 */
47 public BulkEditorLineDisplay(IEditorPart editor) {
48 this.editor = editor;
49 }
50
51 /* (non-Javadoc)
52 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getIcon(java.lang.Object)
53 */
54 /** {@inheritDoc} */
55 public Image getIcon(Object entity) {
56 return null;
57 }
58
59 /* (non-Javadoc)
60 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getIndent(java.lang.Object)
61 */
62 /** {@inheritDoc} */
63 public int getIndent(Object entity) {
64 return 0;
65 }
66
67 /* (non-Javadoc)
68 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getText(java.lang.Object)
69 */
70 /** {@inheritDoc} */
71 public String getText(Object entity) {
72 String text = null;
73
74 if(entity instanceof IdentifiableEntity){
75 IdentifiableEntity identifiableEntity = (IdentifiableEntity) HibernateProxyHelper.deproxy(entity);
76 if(identifiableEntity instanceof TaxonNameBase){
77 // TODO it is not very nice to do this here. Please refactor
78 text = ((TaxonNameBase) identifiableEntity).getFullTitleCache();
79 }else{
80 text = identifiableEntity.getTitleCache();
81 }
82 }
83
84 return text == null ? "" : text;
85 }
86
87
88 /* (non-Javadoc)
89 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getSupplementalText(java.lang.Object)
90 */
91 /** {@inheritDoc} */
92 public String getSupplementalText(Object entity) {
93 if (entity instanceof ReferenceBase) {
94 ReferenceBase reference = (ReferenceBase) HibernateProxyHelper.deproxy(entity);
95 // Nobody seems to like displaying the date
96 // TimePeriod datePublished = ((StrictReferenceBase) reference).getDatePublished();
97 //
98 // String date = datePublished == null ? null : datePublished.toString();
99 // if (date != null) {
100 // text += " [" + date + "]";
101 // }
102 String markerText = null;
103 for (Marker marker : reference.getMarkers()) {
104 if (PreferencesUtil.getEditMarkerTypePreference(editor.getEditorInput(), marker.getMarkerType())) {
105 if (markerText == null) {
106 markerText = " [";
107 } else {
108 markerText += ", ";
109 }
110 markerText += marker.getMarkerType().getLabel() + " = " + marker.getFlag();
111 }
112 }
113 if (markerText != null) {
114 markerText += "]";
115 } else {
116 markerText = "";
117 }
118 return markerText;
119 }
120 if (entity instanceof TaxonNameBase) {
121 return "";
122 }
123 if (entity instanceof AgentBase) {
124 return "[" + entity.getClass().getSimpleName() + "]";
125 }
126 if (entity instanceof SpecimenOrObservationBase) {
127 return "[" + entity.getClass().getSimpleName() + "]";
128 }
129 return "";
130 }
131
132 /* (non-Javadoc)
133 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#setText(java.lang.String, java.lang.Object)
134 */
135 /** {@inheritDoc} */
136 public void setText(String text, Object entity) {
137 if (entity instanceof ReferenceBase) {
138 ((ReferenceBase) entity).setTitleCache(text);
139 }
140 }
141
142 /* (non-Javadoc)
143 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getHoverText(java.lang.Object)
144 */
145 /** {@inheritDoc} */
146 public String getHoverText(Object entity) {
147 return null;
148 }
149
150 /* (non-Javadoc)
151 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#setStatusMessage(java.lang.String, java.lang.Object)
152 */
153 /** {@inheritDoc} */
154 public void setStatusMessage(final String text, Object entity) {
155
156 // Calling from the synchronized method ListEditorReconcilingStrategy#doReconcile
157 // without its own thread causes an invalid thread access exception
158 // see http://wiki.eclipse.org/FAQ_Why_do_I_get_an_invalid_thread_access_exception%3F
159 new Thread(new Runnable() {
160 public void run() {
161 Display.getDefault().asyncExec(new Runnable() {
162 public void run() {
163 IStatusLineManager statusLineManager = editor.getEditorSite().getActionBars().getStatusLineManager();
164 statusLineManager.setMessage(text);
165 }
166 });
167 }
168 }).start();
169 }
170
171 /* (non-Javadoc)
172 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getEmptyText(java.lang.Object)
173 */
174 /** {@inheritDoc} */
175 public String getEmptyCacheMessage(Object entity) {
176 if (entity instanceof ReferenceBase) {
177 return "No reference title cache";
178 }
179 if (entity instanceof TaxonNameBase) {
180 return "No name title cache";
181 }
182 if (entity instanceof AgentBase) {
183 return "No title cache";
184 }
185 return "";
186 }
187
188 /* (non-Javadoc)
189 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#isEntityCacheEmpty(java.lang.Object)
190 */
191 /** {@inheritDoc} */
192 public boolean isEntityCacheEmpty(Object entity) {
193 if (entity instanceof ReferenceBase) {
194 String text = ((ReferenceBase) entity).getTitleCache();
195 return (text == null || text.equals(""));
196 }
197 if (entity instanceof TaxonNameBase) {
198 String text = ((TaxonNameBase) entity).getTitleCache();
199 return (text == null || text.equals(""));
200 }
201 if (entity instanceof AgentBase) {
202 String text = ((AgentBase) entity).getTitleCache();
203 return (text == null || text.equals(""));
204 }
205 return false;
206 }
207
208 /* (non-Javadoc)
209 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#addDisplayListener(java.lang.Object)
210 */
211 /** {@inheritDoc} */
212 public void addDisplayListener(Object entity, EntityListener listener) {
213 /* Note: all non-field specific listeners require that corresponding property sheets
214 * contain the following:
215 *
216 *
217 * public void setPropertyValue(Object id, Object value) {
218 * ...
219 * reference.firePropertyChange(new PropertyChangeEvent(reference, "", null, null));
220 * }
221 *
222 */
223 if (entity instanceof CdmBase) {
224 ((CdmBase) entity).addPropertyChangeListener(listener);
225 }
226 }
227
228 /* (non-Javadoc)
229 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getFont(java.lang.Object)
230 */
231 /** {@inheritDoc} */
232 public Font getFont(Object entity) {
233 return null;
234 }
235 }