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
.ICdmBase
;
29 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
30 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
31 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
32 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
33 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
34 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.EntityListener
;
35 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.ILineDisplayStrategy
;
36 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.AbstractBulkEditorInput
;
37 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
40 * <p>BulkEditorLineDisplay class.</p>
46 public class BulkEditorLineDisplay
implements ILineDisplayStrategy
{
48 private BulkEditor editor
;
51 * <p>Constructor for BulkEditorLineDisplay.</p>
53 * @param editor a {@link org.eclipse.ui.IEditorPart} object.
55 public BulkEditorLineDisplay(BulkEditor editor
) {
60 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getIcon(java.lang.Object)
63 public Image
getIcon(Object entity
) {
68 * @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)
79 public String
getText(Object entity
) {
80 return editor
.getEditorInput().getText((ICdmBase
) entity
);
85 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getSupplementalText(java.lang.Object)
88 public String
getSupplementalText(Object entity
) {
90 String supplementalText
= "";
92 AbstractBulkEditorInput input
= editor
.getEditorInput();
93 String typeText
= input
.getTypeText(entity
);
95 supplementalText
+= CdmUtils
.isEmpty(typeText
) ?
"" : String
.format(" [%s]", typeText
);
97 if (entity
instanceof IAnnotatableEntity
) {
98 IAnnotatableEntity annotatableEntity
= (IAnnotatableEntity
) HibernateProxyHelper
.deproxy(entity
);
100 Map
<MarkerType
, Boolean
> editMarkerTypePreferences
= PreferencesUtil
.getEditMarkerTypePreferences();
102 String markerText
= "";
103 List
<String
> markers
= new ArrayList
<String
>();
104 for (Marker marker
: annotatableEntity
.getMarkers()) {
105 markers
.add(String
.format("%1s = %2s", marker
.getMarkerType().getLabel(), marker
.getFlag() ?
"yes" : "no"));
107 if (! markers
.isEmpty()) {
108 markerText
= StringUtils
.join(markers
, ", ");
111 supplementalText
+= CdmUtils
.isEmpty(markerText
) ?
"" : String
.format(" [%s]", markerText
);
114 return supplementalText
;
118 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#setText(java.lang.String, java.lang.Object)
121 public void setText(String text
, Object entity
) {
122 if (entity
instanceof Reference
) {
123 ((Reference
) entity
).setTitleCache(text
);
128 * @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)
139 public void setStatusMessage(final String text
, Object entity
) {
141 // Calling from the synchronized method ListEditorReconcilingStrategy#doReconcile
142 // without its own thread causes an invalid thread access exception
143 // see http://wiki.eclipse.org/FAQ_Why_do_I_get_an_invalid_thread_access_exception%3F
144 new Thread(new Runnable() {
146 Display
.getDefault().asyncExec(new Runnable() {
148 IStatusLineManager statusLineManager
= editor
.getEditorSite().getActionBars().getStatusLineManager();
149 statusLineManager
.setMessage(text
);
157 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getEmptyText(java.lang.Object)
160 public String
getEmptyCacheMessage(Object entity
) {
161 if (entity
instanceof Reference
) {
162 return "No reference title cache";
164 if (entity
instanceof TaxonNameBase
) {
165 return "No name title cache";
167 if (entity
instanceof AgentBase
) {
168 return "No title cache";
174 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#isEntityCacheEmpty(java.lang.Object)
177 public boolean isEntityCacheEmpty(Object entity
) {
178 if (entity
instanceof Reference
) {
179 String text
= ((Reference
) entity
).getTitleCache();
180 return (text
== null || text
.equals(""));
182 if (entity
instanceof TaxonNameBase
) {
183 String text
= ((TaxonNameBase
) entity
).getTitleCache();
184 return (text
== null || text
.equals(""));
186 if (entity
instanceof AgentBase
) {
187 String text
= ((AgentBase
) entity
).getTitleCache();
188 return (text
== null || text
.equals(""));
194 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#addDisplayListener(java.lang.Object)
197 public void addDisplayListener(Object entity
, EntityListener listener
) {
198 /* Note: all non-field specific listeners require that corresponding property sheets
199 * contain the following:
202 * public void setPropertyValue(Object id, Object value) {
204 * reference.firePropertyChange(new PropertyChangeEvent(reference, "", null, null));
208 if (entity
instanceof CdmBase
) {
209 ((CdmBase
) entity
).addPropertyChangeListener(listener
);
214 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getFont(java.lang.Object)
217 public Font
getFont(Object entity
) {