- added startNumber to PolytomousKey DetailsView (fixes #3563)
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / BulkEditorLineDisplay.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10
11 package eu.etaxonomy.taxeditor.bulkeditor;
12
13 import java.util.ArrayList;
14 import java.util.List;
15 import java.util.Map;
16
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;
22
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;
36
37 /**
38 * <p>BulkEditorLineDisplay class.</p>
39 *
40 * @author p.ciardelli
41 * @created 07.07.2009
42 * @version 1.0
43 */
44 public class BulkEditorLineDisplay implements ILineDisplayStrategy {
45
46 private BulkEditor editor;
47
48 /**
49 * <p>Constructor for BulkEditorLineDisplay.</p>
50 *
51 * @param editor a {@link org.eclipse.ui.IEditorPart} object.
52 */
53 public BulkEditorLineDisplay(BulkEditor editor) {
54 this.editor = editor;
55 }
56
57 /* (non-Javadoc)
58 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getIcon(java.lang.Object)
59 */
60 /** {@inheritDoc} */
61 public Image getIcon(Object entity) {
62 return null;
63 }
64
65 /* (non-Javadoc)
66 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getIndent(java.lang.Object)
67 */
68 /** {@inheritDoc} */
69 public int getIndent(Object entity) {
70 return 0;
71 }
72
73 /* (non-Javadoc)
74 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getText(java.lang.Object)
75 */
76 /** {@inheritDoc} */
77 public String getText(Object entity) {
78 return editor.getEditorInput().getText((ICdmBase) entity);
79 }
80
81
82 /* (non-Javadoc)
83 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getSupplementalText(java.lang.Object)
84 */
85 /** {@inheritDoc} */
86 public String getSupplementalText(Object entity) {
87
88 String supplementalText = "";
89
90 AbstractBulkEditorInput input = editor.getEditorInput();
91 String typeText = input.getTypeText(entity);
92
93 supplementalText += StringUtils.isBlank(typeText) ? "" : String.format(" [%s]", typeText);
94
95 if (entity instanceof IAnnotatableEntity) {
96 IAnnotatableEntity annotatableEntity = (IAnnotatableEntity) HibernateProxyHelper.deproxy(entity);
97
98 Map<MarkerType, Boolean> editMarkerTypePreferences = PreferencesUtil.getEditMarkerTypePreferences();
99
100 String markerText = "";
101 List<String> markers = new ArrayList<String>();
102 for (Marker marker : annotatableEntity.getMarkers()) {
103 String markerLabel = marker.getMarkerType() == null? " unknown marker " : marker.getMarkerType().getLabel();
104 markers.add(String.format("%1s = %2s", markerLabel, marker.getFlag() ? "yes" : "no"));
105 }
106 if (! markers.isEmpty()) {
107 markerText = StringUtils.join(markers, ", ");
108 }
109
110 supplementalText += StringUtils.isBlank(markerText) ? "" : String.format(" [%s]", markerText);
111 }
112
113 return supplementalText;
114 }
115
116 /* (non-Javadoc)
117 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#setText(java.lang.String, java.lang.Object)
118 */
119 /** {@inheritDoc} */
120 public void setText(String text, Object entity) {
121 if (entity instanceof Reference) {
122 ((Reference) entity).setTitleCache(text);
123 }
124 }
125
126 /* (non-Javadoc)
127 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getHoverText(java.lang.Object)
128 */
129 /** {@inheritDoc} */
130 public String getHoverText(Object entity) {
131 return null;
132 }
133
134 /* (non-Javadoc)
135 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#setStatusMessage(java.lang.String, java.lang.Object)
136 */
137 /** {@inheritDoc} */
138 public void setStatusMessage(final String text, Object entity) {
139
140 // Calling from the synchronized method ListEditorReconcilingStrategy#doReconcile
141 // without its own thread causes an invalid thread access exception
142 // see http://wiki.eclipse.org/FAQ_Why_do_I_get_an_invalid_thread_access_exception%3F
143 new Thread(new Runnable() {
144 public void run() {
145 Display.getDefault().asyncExec(new Runnable() {
146 public void run() {
147 IStatusLineManager statusLineManager = editor.getEditorSite().getActionBars().getStatusLineManager();
148 statusLineManager.setMessage(text);
149 }
150 });
151 }
152 }).start();
153 }
154
155 /* (non-Javadoc)
156 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getEmptyText(java.lang.Object)
157 */
158 /** {@inheritDoc} */
159 public String getEmptyCacheMessage(Object entity) {
160 if (entity instanceof Reference) {
161 return "No reference title cache";
162 }
163 if (entity instanceof TaxonNameBase) {
164 return "No name title cache";
165 }
166 if (entity instanceof AgentBase) {
167 return "No title cache";
168 }
169 return "";
170 }
171
172 /* (non-Javadoc)
173 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#isEntityCacheEmpty(java.lang.Object)
174 */
175 /** {@inheritDoc} */
176 public boolean isEntityCacheEmpty(Object entity) {
177 if (entity instanceof Reference) {
178 String text = ((Reference) entity).getTitleCache();
179 return (text == null || text.equals(""));
180 }
181 if (entity instanceof TaxonNameBase) {
182 String text = ((TaxonNameBase) entity).getTitleCache();
183 return (text == null || text.equals(""));
184 }
185 if (entity instanceof AgentBase) {
186 String text = ((AgentBase) entity).getTitleCache();
187 return (text == null || text.equals(""));
188 }
189 return false;
190 }
191
192 /* (non-Javadoc)
193 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#addDisplayListener(java.lang.Object)
194 */
195 /** {@inheritDoc} */
196 public void addDisplayListener(Object entity, EntityListener listener) {
197 /* Note: all non-field specific listeners require that corresponding property sheets
198 * contain the following:
199 *
200 *
201 * public void setPropertyValue(Object id, Object value) {
202 * ...
203 * reference.firePropertyChange(new PropertyChangeEvent(reference, "", null, null));
204 * }
205 *
206 */
207 if (entity instanceof CdmBase) {
208 ((CdmBase) entity).addPropertyChangeListener(listener);
209 }
210 }
211
212 /* (non-Javadoc)
213 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getFont(java.lang.Object)
214 */
215 /** {@inheritDoc} */
216 public Font getFont(Object entity) {
217 return null;
218 }
219 }