3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.bulkeditor
;
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
;
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
;
32 * <p>BulkEditorLineDisplay class.</p>
38 public class BulkEditorLineDisplay
implements ILineDisplayStrategy
{
40 private IEditorPart editor
;
43 * <p>Constructor for BulkEditorLineDisplay.</p>
45 * @param editor a {@link org.eclipse.ui.IEditorPart} object.
47 public BulkEditorLineDisplay(IEditorPart editor
) {
52 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getIcon(java.lang.Object)
55 public Image
getIcon(Object entity
) {
60 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getIndent(java.lang.Object)
63 public int getIndent(Object entity
) {
68 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getText(java.lang.Object)
71 public String
getText(Object entity
) {
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();
80 text
= identifiableEntity
.getTitleCache();
84 return text
== null ?
"" : text
;
89 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getSupplementalText(java.lang.Object)
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();
98 // String date = datePublished == null ? null : datePublished.toString();
99 // if (date != null) {
100 // text += " [" + date + "]";
102 String markerText
= null;
103 for (Marker marker
: reference
.getMarkers()) {
104 if (PreferencesUtil
.getEditMarkerTypePreference(editor
.getEditorInput(), marker
.getMarkerType())) {
105 if (markerText
== null) {
110 markerText
+= marker
.getMarkerType().getLabel() + " = " + marker
.getFlag();
113 if (markerText
!= null) {
120 if (entity
instanceof TaxonNameBase
) {
123 if (entity
instanceof AgentBase
) {
124 return "[" + entity
.getClass().getSimpleName() + "]";
126 if (entity
instanceof SpecimenOrObservationBase
) {
127 return "[" + entity
.getClass().getSimpleName() + "]";
133 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#setText(java.lang.String, java.lang.Object)
136 public void setText(String text
, Object entity
) {
137 if (entity
instanceof ReferenceBase
) {
138 ((ReferenceBase
) entity
).setTitleCache(text
);
143 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getHoverText(java.lang.Object)
146 public String
getHoverText(Object entity
) {
151 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#setStatusMessage(java.lang.String, java.lang.Object)
154 public void setStatusMessage(final String text
, Object entity
) {
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() {
161 Display
.getDefault().asyncExec(new Runnable() {
163 IStatusLineManager statusLineManager
= editor
.getEditorSite().getActionBars().getStatusLineManager();
164 statusLineManager
.setMessage(text
);
172 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getEmptyText(java.lang.Object)
175 public String
getEmptyCacheMessage(Object entity
) {
176 if (entity
instanceof ReferenceBase
) {
177 return "No reference title cache";
179 if (entity
instanceof TaxonNameBase
) {
180 return "No name title cache";
182 if (entity
instanceof AgentBase
) {
183 return "No title cache";
189 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#isEntityCacheEmpty(java.lang.Object)
192 public boolean isEntityCacheEmpty(Object entity
) {
193 if (entity
instanceof ReferenceBase
) {
194 String text
= ((ReferenceBase
) entity
).getTitleCache();
195 return (text
== null || text
.equals(""));
197 if (entity
instanceof TaxonNameBase
) {
198 String text
= ((TaxonNameBase
) entity
).getTitleCache();
199 return (text
== null || text
.equals(""));
201 if (entity
instanceof AgentBase
) {
202 String text
= ((AgentBase
) entity
).getTitleCache();
203 return (text
== null || text
.equals(""));
209 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#addDisplayListener(java.lang.Object)
212 public void addDisplayListener(Object entity
, EntityListener listener
) {
213 /* Note: all non-field specific listeners require that corresponding property sheets
214 * contain the following:
217 * public void setPropertyValue(Object id, Object value) {
219 * reference.firePropertyChange(new PropertyChangeEvent(reference, "", null, null));
223 if (entity
instanceof CdmBase
) {
224 ((CdmBase
) entity
).addPropertyChangeListener(listener
);
229 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getFont(java.lang.Object)
232 public Font
getFont(Object entity
) {