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
.hibernate
.HibernateProxyHelper
;
24 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
25 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
26 import eu
.etaxonomy
.cdm
.model
.common
.IAnnotatableEntity
;
27 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
28 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
29 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
30 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
31 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
32 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.EntityListener
;
33 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.ILineDisplayStrategy
;
34 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.AbstractBulkEditorInput
;
35 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
38 * <p>BulkEditorLineDisplay class.</p>
44 public class BulkEditorLineDisplay
implements ILineDisplayStrategy
{
46 private BulkEditor editor
;
49 * <p>Constructor for BulkEditorLineDisplay.</p>
51 * @param editor a {@link org.eclipse.ui.IEditorPart} object.
53 public BulkEditorLineDisplay(BulkEditor editor
) {
58 * @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)
71 public int getIndent(Object entity
) {
76 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getText(java.lang.Object)
80 public String
getText(Object entity
) {
81 return editor
.getEditorInput().getText((ICdmBase
) entity
);
86 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getSupplementalText(java.lang.Object)
90 public String
getSupplementalText(Object entity
) {
92 String supplementalText
= "";
94 AbstractBulkEditorInput input
= editor
.getEditorInput();
95 String typeText
= input
.getTypeText(entity
);
97 supplementalText
+= StringUtils
.isBlank(typeText
) ?
"" : String
.format(" [%s]", typeText
);
99 if (entity
instanceof IAnnotatableEntity
) {
100 IAnnotatableEntity annotatableEntity
= (IAnnotatableEntity
) HibernateProxyHelper
.deproxy(entity
);
102 Map
<MarkerType
, Boolean
> editMarkerTypePreferences
= PreferencesUtil
.getEditMarkerTypePreferences();
104 String markerText
= "";
105 List
<String
> markers
= new ArrayList
<String
>();
106 for (Marker marker
: annotatableEntity
.getMarkers()) {
107 String markerLabel
= marker
.getMarkerType() == null?
" unknown marker " : marker
.getMarkerType().getLabel();
108 markers
.add(String
.format("%1s = %2s", markerLabel
, marker
.getFlag() ?
"yes" : "no"));
110 if (! markers
.isEmpty()) {
111 markerText
= StringUtils
.join(markers
, ", ");
114 supplementalText
+= StringUtils
.isBlank(markerText
) ?
"" : String
.format(" [%s]", markerText
);
117 return supplementalText
;
121 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#setText(java.lang.String, java.lang.Object)
125 public void setText(String text
, Object entity
) {
126 if (entity
instanceof Reference
) {
127 ((Reference
) entity
).setTitleCache(text
);
132 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getHoverText(java.lang.Object)
136 public String
getHoverText(Object entity
) {
141 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#setStatusMessage(java.lang.String, java.lang.Object)
145 public void setStatusMessage(final String text
, Object entity
) {
147 // Calling from the synchronized method ListEditorReconcilingStrategy#doReconcile
148 // without its own thread causes an invalid thread access exception
149 // see http://wiki.eclipse.org/FAQ_Why_do_I_get_an_invalid_thread_access_exception%3F
150 new Thread(new Runnable() {
153 Display
.getDefault().asyncExec(new Runnable() {
156 IStatusLineManager statusLineManager
= editor
.getEditorSite().getActionBars().getStatusLineManager();
157 statusLineManager
.setMessage(text
);
165 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getEmptyText(java.lang.Object)
169 public String
getEmptyCacheMessage(Object entity
) {
170 if (entity
instanceof Reference
) {
171 return "No reference title cache";
173 if (entity
instanceof TaxonNameBase
) {
174 return "No name title cache";
176 if (entity
instanceof AgentBase
) {
177 return "No title cache";
183 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#isEntityCacheEmpty(java.lang.Object)
187 public boolean isEntityCacheEmpty(Object entity
) {
188 if (entity
instanceof Reference
) {
189 String text
= ((Reference
) entity
).getTitleCache();
190 return (text
== null || text
.equals(""));
192 if (entity
instanceof TaxonNameBase
) {
193 String text
= ((TaxonNameBase
) entity
).getTitleCache();
194 return (text
== null || text
.equals(""));
196 if (entity
instanceof AgentBase
) {
197 String text
= ((AgentBase
) entity
).getTitleCache();
198 return (text
== null || text
.equals(""));
204 * @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)
229 public Font
getFont(Object entity
) {