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
;
16 import org
.apache
.commons
.lang
.StringUtils
;
17 import org
.eclipse
.jface
.action
.IStatusLineManager
;
18 import org
.eclipse
.swt
.graphics
.Font
;
19 import org
.eclipse
.swt
.graphics
.Image
;
20 import org
.eclipse
.swt
.widgets
.Display
;
22 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
23 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
24 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
25 import eu
.etaxonomy
.cdm
.model
.common
.IAnnotatableEntity
;
26 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
27 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
28 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
29 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
30 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.EntityListener
;
31 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.ILineDisplayStrategy
;
32 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.AbstractBulkEditorInput
;
35 * <p>BulkEditorLineDisplay class.</p>
41 public class BulkEditorLineDisplay
implements ILineDisplayStrategy
{
43 private BulkEditor editor
;
46 * <p>Constructor for BulkEditorLineDisplay.</p>
48 * @param editor a {@link org.eclipse.ui.IEditorPart} object.
50 public BulkEditorLineDisplay(BulkEditor editor
) {
55 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getIcon(java.lang.Object)
59 public Image
getIcon(Object entity
) {
64 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getIndent(java.lang.Object)
68 public int getIndent(Object entity
) {
73 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getText(java.lang.Object)
77 public String
getText(Object entity
) {
78 return editor
.getEditorInput().getText((ICdmBase
) entity
);
83 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getSupplementalText(java.lang.Object)
87 public String
getSupplementalText(Object entity
) {
89 String supplementalText
= "";
91 AbstractBulkEditorInput input
= editor
.getEditorInput();
92 String typeText
= input
.getTypeText(entity
);
94 supplementalText
+= StringUtils
.isBlank(typeText
) ?
"" : String
.format(" [%s]", typeText
);
96 if (entity
instanceof IAnnotatableEntity
) {
97 IAnnotatableEntity annotatableEntity
= (IAnnotatableEntity
) HibernateProxyHelper
.deproxy(entity
);
99 String markerText
= "";
100 List
<String
> markers
= new ArrayList
<String
>();
101 for (Marker marker
: annotatableEntity
.getMarkers()) {
102 String markerLabel
= marker
.getMarkerType() == null?
" unknown marker " : marker
.getMarkerType().getLabel();
103 markers
.add(String
.format("%1s = %2s", markerLabel
, marker
.getFlag() ?
"yes" : "no"));
105 if (! markers
.isEmpty()) {
106 markerText
= StringUtils
.join(markers
, ", ");
109 supplementalText
+= StringUtils
.isBlank(markerText
) ?
"" : String
.format(" [%s]", markerText
);
112 return supplementalText
;
116 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#setText(java.lang.String, java.lang.Object)
120 public void setText(String text
, Object entity
) {
121 if (entity
instanceof Reference
) {
122 ((Reference
) entity
).setTitleCache(text
);
127 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getHoverText(java.lang.Object)
131 public String
getHoverText(Object entity
) {
136 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#setStatusMessage(java.lang.String, java.lang.Object)
140 public void setStatusMessage(final String text
, Object entity
) {
142 // Calling from the synchronized method ListEditorReconcilingStrategy#doReconcile
143 // without its own thread causes an invalid thread access exception
144 // see http://wiki.eclipse.org/FAQ_Why_do_I_get_an_invalid_thread_access_exception%3F
145 new Thread(new Runnable() {
148 Display
.getDefault().asyncExec(new Runnable() {
151 IStatusLineManager statusLineManager
= editor
.getEditorSite().getActionBars().getStatusLineManager();
152 statusLineManager
.setMessage(text
);
160 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getEmptyText(java.lang.Object)
164 public String
getEmptyCacheMessage(Object entity
) {
165 if (entity
instanceof Reference
) {
166 return "No reference title cache";
168 if (entity
instanceof TaxonNameBase
) {
169 return "No name title cache";
171 if (entity
instanceof AgentBase
) {
172 return "No title cache";
178 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#isEntityCacheEmpty(java.lang.Object)
182 public boolean isEntityCacheEmpty(Object entity
) {
183 if (entity
instanceof Reference
) {
184 String text
= ((Reference
) entity
).getTitleCache();
185 return (text
== null || text
.equals(""));
187 if (entity
instanceof TaxonNameBase
) {
188 String text
= ((TaxonNameBase
) entity
).getTitleCache();
189 return (text
== null || text
.equals(""));
191 if (entity
instanceof AgentBase
) {
192 String text
= ((AgentBase
) entity
).getTitleCache();
193 return (text
== null || text
.equals(""));
199 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#addDisplayListener(java.lang.Object)
203 public void addDisplayListener(Object entity
, EntityListener listener
) {
204 /* Note: all non-field specific listeners require that corresponding property sheets
205 * contain the following:
208 * public void setPropertyValue(Object id, Object value) {
210 * reference.firePropertyChange(new PropertyChangeEvent(reference, "", null, null));
214 if (entity
instanceof CdmBase
) {
215 ((CdmBase
) entity
).addPropertyChangeListener(listener
);
220 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getFont(java.lang.Object)
224 public Font
getFont(Object entity
) {