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 java
.util
.ArrayList
;
14 import java
.util
.List
;
17 import org
.apache
.commons
.lang
.StringUtils
;
18 import org
.eclipse
.jface
.action
.IStatusLineManager
;
19 import org
.eclipse
.swt
.graphics
.Font
;
20 import org
.eclipse
.swt
.graphics
.Image
;
21 import org
.eclipse
.swt
.widgets
.Display
;
23 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
24 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
25 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
26 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
27 import eu
.etaxonomy
.cdm
.model
.common
.IAnnotatableEntity
;
28 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
29 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
30 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
31 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
32 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
33 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.EntityListener
;
34 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.ILineDisplayStrategy
;
35 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.AbstractBulkEditorInput
;
36 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
39 * <p>BulkEditorLineDisplay class.</p>
45 public class BulkEditorLineDisplay
implements ILineDisplayStrategy
{
47 private BulkEditor editor
;
50 * <p>Constructor for BulkEditorLineDisplay.</p>
52 * @param editor a {@link org.eclipse.ui.IEditorPart} object.
54 public BulkEditorLineDisplay(BulkEditor editor
) {
59 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getIcon(java.lang.Object)
62 public Image
getIcon(Object entity
) {
67 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getIndent(java.lang.Object)
70 public int getIndent(Object entity
) {
75 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getText(java.lang.Object)
78 public String
getText(Object entity
) {
81 if(entity
instanceof IdentifiableEntity
){
82 IdentifiableEntity identifiableEntity
= (IdentifiableEntity
) HibernateProxyHelper
.deproxy(entity
);
83 if(identifiableEntity
instanceof TaxonNameBase
){
84 // TODO it is not very nice to do this here. Please refactor
85 text
= ((TaxonNameBase
) identifiableEntity
).getFullTitleCache();
87 text
= identifiableEntity
.getTitleCache();
91 return text
== null ?
"" : text
;
96 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getSupplementalText(java.lang.Object)
99 public String
getSupplementalText(Object entity
) {
101 String supplementalText
= "";
103 AbstractBulkEditorInput input
= editor
.getEditorInput();
104 String typeText
= input
.getTypeText(entity
);
106 supplementalText
+= CdmUtils
.isEmpty(typeText
) ?
"" : String
.format(" [%s]", typeText
);
108 if (entity
instanceof IAnnotatableEntity
) {
109 IAnnotatableEntity annotatableEntity
= (IAnnotatableEntity
) HibernateProxyHelper
.deproxy(entity
);
111 Map
<MarkerType
, Boolean
> editMarkerTypePreferences
= PreferencesUtil
.getEditMarkerTypePreferences();
113 String markerText
= "";
114 List
<String
> markers
= new ArrayList
<String
>();
115 for (Marker marker
: annotatableEntity
.getMarkers()) {
116 markers
.add(String
.format("%1s = %2s", marker
.getMarkerType().getLabel(), marker
.getFlag() ?
"yes" : "no"));
118 if (! markers
.isEmpty()) {
119 markerText
= StringUtils
.join(markers
, ", ");
122 supplementalText
+= CdmUtils
.isEmpty(markerText
) ?
"" : String
.format(" [%s]", markerText
);
125 return supplementalText
;
129 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#setText(java.lang.String, java.lang.Object)
132 public void setText(String text
, Object entity
) {
133 if (entity
instanceof Reference
) {
134 ((Reference
) entity
).setTitleCache(text
);
139 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getHoverText(java.lang.Object)
142 public String
getHoverText(Object entity
) {
147 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#setStatusMessage(java.lang.String, java.lang.Object)
150 public void setStatusMessage(final String text
, Object entity
) {
152 // Calling from the synchronized method ListEditorReconcilingStrategy#doReconcile
153 // without its own thread causes an invalid thread access exception
154 // see http://wiki.eclipse.org/FAQ_Why_do_I_get_an_invalid_thread_access_exception%3F
155 new Thread(new Runnable() {
157 Display
.getDefault().asyncExec(new Runnable() {
159 IStatusLineManager statusLineManager
= editor
.getEditorSite().getActionBars().getStatusLineManager();
160 statusLineManager
.setMessage(text
);
168 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getEmptyText(java.lang.Object)
171 public String
getEmptyCacheMessage(Object entity
) {
172 if (entity
instanceof Reference
) {
173 return "No reference title cache";
175 if (entity
instanceof TaxonNameBase
) {
176 return "No name title cache";
178 if (entity
instanceof AgentBase
) {
179 return "No title cache";
185 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#isEntityCacheEmpty(java.lang.Object)
188 public boolean isEntityCacheEmpty(Object entity
) {
189 if (entity
instanceof Reference
) {
190 String text
= ((Reference
) entity
).getTitleCache();
191 return (text
== null || text
.equals(""));
193 if (entity
instanceof TaxonNameBase
) {
194 String text
= ((TaxonNameBase
) entity
).getTitleCache();
195 return (text
== null || text
.equals(""));
197 if (entity
instanceof AgentBase
) {
198 String text
= ((AgentBase
) entity
).getTitleCache();
199 return (text
== null || text
.equals(""));
205 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#addDisplayListener(java.lang.Object)
208 public void addDisplayListener(Object entity
, EntityListener listener
) {
209 /* Note: all non-field specific listeners require that corresponding property sheets
210 * contain the following:
213 * public void setPropertyValue(Object id, Object value) {
215 * reference.firePropertyChange(new PropertyChangeEvent(reference, "", null, null));
219 if (entity
instanceof CdmBase
) {
220 ((CdmBase
) entity
).addPropertyChangeListener(listener
);
225 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getFont(java.lang.Object)
228 public Font
getFont(Object entity
) {