2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.bulkeditor
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
15 import org
.apache
.commons
.lang
.StringUtils
;
16 import org
.eclipse
.jface
.action
.IStatusLineManager
;
17 import org
.eclipse
.swt
.graphics
.Font
;
18 import org
.eclipse
.swt
.graphics
.Image
;
19 import org
.eclipse
.swt
.widgets
.Display
;
21 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
22 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
23 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
24 import eu
.etaxonomy
.cdm
.model
.common
.IAnnotatableEntity
;
25 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
26 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
27 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
28 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.EntityListener
;
29 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.ILineDisplayStrategy
;
30 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.AbstractBulkEditorInput
;
33 * <p>BulkEditorLineDisplay class.</p>
38 public class BulkEditorLineDisplay
implements ILineDisplayStrategy
{
40 private BulkEditor editor
;
43 * <p>Constructor for BulkEditorLineDisplay.</p>
45 * @param editor a {@link org.eclipse.ui.IEditorPart} object.
47 public BulkEditorLineDisplay(BulkEditor editor
) {
53 public Image
getIcon(Object entity
) {
59 public int getIndent(Object entity
) {
65 public String
getText(Object entity
) {
66 return editor
.getEditorInput().getText((CdmBase
) entity
);
71 public String
getSupplementalText(Object entity
) {
73 String supplementalText
= "";
75 AbstractBulkEditorInput input
= editor
.getEditorInput();
76 String typeText
= input
.getTypeText(entity
);
78 supplementalText
+= StringUtils
.isBlank(typeText
) ?
"" : String
.format(" [%s]", typeText
);
80 if (entity
instanceof IAnnotatableEntity
) {
81 IAnnotatableEntity annotatableEntity
= (IAnnotatableEntity
) HibernateProxyHelper
.deproxy(entity
);
83 String markerText
= "";
84 List
<String
> markers
= new ArrayList
<String
>();
85 for (Marker marker
: annotatableEntity
.getMarkers()) {
86 String markerLabel
= marker
.getMarkerType() == null?
" unknown marker " : marker
.getMarkerType().getLabel();
87 markers
.add(String
.format("%1s = %2s", markerLabel
, marker
.getFlag() ?
"yes" : "no"));
89 if (! markers
.isEmpty()) {
90 markerText
= StringUtils
.join(markers
, ", ");
93 supplementalText
+= StringUtils
.isBlank(markerText
) ?
"" : String
.format(" [%s]", markerText
);
96 return supplementalText
;
101 public void setText(String text
, Object entity
) {
102 if (entity
instanceof Reference
) {
103 ((Reference
) entity
).setTitleCache(text
);
109 public String
getHoverText(Object entity
) {
114 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#setStatusMessage(java.lang.String, java.lang.Object)
118 public void setStatusMessage(final String text
, Object entity
) {
120 // Calling from the synchronized method ListEditorReconcilingStrategy#doReconcile
121 // without its own thread causes an invalid thread access exception
122 // see http://wiki.eclipse.org/FAQ_Why_do_I_get_an_invalid_thread_access_exception%3F
123 new Thread(new Runnable() {
126 Display
.getDefault().asyncExec(new Runnable() {
129 IStatusLineManager statusLineManager
= editor
.getEditorSite().getActionBars().getStatusLineManager();
130 statusLineManager
.setMessage(text
);
139 public String
getEmptyCacheMessage(Object entity
) {
140 return entity
.toString();
145 public boolean isEntityCacheEmpty(Object entity
) {
146 if (entity
instanceof Reference
) {
147 String text
= ((Reference
) entity
).getTitleCache();
148 return (text
== null || text
.equals(""));
150 if (entity
instanceof TaxonName
) {
151 String text
= ((TaxonName
) entity
).getTitleCache();
152 return (text
== null || text
.equals(""));
154 if (entity
instanceof AgentBase
) {
155 String text
= ((AgentBase
) entity
).getTitleCache();
156 return (text
== null || text
.equals(""));
163 public void addDisplayListener(Object entity
, EntityListener listener
) {
164 /* Note: all non-field specific listeners require that corresponding property sheets
165 * contain the following:
168 * public void setPropertyValue(Object id, Object value) {
170 * reference.firePropertyChange(new PropertyChangeEvent(reference, "", null, null));
174 if (entity
instanceof CdmBase
) {
175 ((CdmBase
) entity
).addPropertyChangeListener(listener
);
180 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getFont(java.lang.Object)
184 public Font
getFont(Object entity
) {