#5849 Show class name + uuid for newly created empty entities in bulk
[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
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;
21
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;
33
34 /**
35 * <p>BulkEditorLineDisplay class.</p>
36 *
37 * @author p.ciardelli
38 * @created 07.07.2009
39 * @version 1.0
40 */
41 public class BulkEditorLineDisplay implements ILineDisplayStrategy {
42
43 private BulkEditor editor;
44
45 /**
46 * <p>Constructor for BulkEditorLineDisplay.</p>
47 *
48 * @param editor a {@link org.eclipse.ui.IEditorPart} object.
49 */
50 public BulkEditorLineDisplay(BulkEditor editor) {
51 this.editor = editor;
52 }
53
54 /* (non-Javadoc)
55 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getIcon(java.lang.Object)
56 */
57 /** {@inheritDoc} */
58 @Override
59 public Image getIcon(Object entity) {
60 return null;
61 }
62
63 /* (non-Javadoc)
64 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getIndent(java.lang.Object)
65 */
66 /** {@inheritDoc} */
67 @Override
68 public int getIndent(Object entity) {
69 return 0;
70 }
71
72 /* (non-Javadoc)
73 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getText(java.lang.Object)
74 */
75 /** {@inheritDoc} */
76 @Override
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 @Override
87 public String getSupplementalText(Object entity) {
88
89 String supplementalText = "";
90
91 AbstractBulkEditorInput input = editor.getEditorInput();
92 String typeText = input.getTypeText(entity);
93
94 supplementalText += StringUtils.isBlank(typeText) ? "" : String.format(" [%s]", typeText);
95
96 if (entity instanceof IAnnotatableEntity) {
97 IAnnotatableEntity annotatableEntity = (IAnnotatableEntity) HibernateProxyHelper.deproxy(entity);
98
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"));
104 }
105 if (! markers.isEmpty()) {
106 markerText = StringUtils.join(markers, ", ");
107 }
108
109 supplementalText += StringUtils.isBlank(markerText) ? "" : String.format(" [%s]", markerText);
110 }
111
112 return supplementalText;
113 }
114
115 /* (non-Javadoc)
116 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#setText(java.lang.String, java.lang.Object)
117 */
118 /** {@inheritDoc} */
119 @Override
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 @Override
131 public String getHoverText(Object entity) {
132 return null;
133 }
134
135 /* (non-Javadoc)
136 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#setStatusMessage(java.lang.String, java.lang.Object)
137 */
138 /** {@inheritDoc} */
139 @Override
140 public void setStatusMessage(final String text, Object entity) {
141
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() {
146 @Override
147 public void run() {
148 Display.getDefault().asyncExec(new Runnable() {
149 @Override
150 public void run() {
151 IStatusLineManager statusLineManager = editor.getEditorSite().getActionBars().getStatusLineManager();
152 statusLineManager.setMessage(text);
153 }
154 });
155 }
156 }).start();
157 }
158
159 /* (non-Javadoc)
160 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getEmptyText(java.lang.Object)
161 */
162 /** {@inheritDoc} */
163 @Override
164 public String getEmptyCacheMessage(Object entity) {
165 return entity.toString();
166 }
167
168 /* (non-Javadoc)
169 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#isEntityCacheEmpty(java.lang.Object)
170 */
171 /** {@inheritDoc} */
172 @Override
173 public boolean isEntityCacheEmpty(Object entity) {
174 if (entity instanceof Reference) {
175 String text = ((Reference) entity).getTitleCache();
176 return (text == null || text.equals(""));
177 }
178 if (entity instanceof TaxonNameBase) {
179 String text = ((TaxonNameBase) entity).getTitleCache();
180 return (text == null || text.equals(""));
181 }
182 if (entity instanceof AgentBase) {
183 String text = ((AgentBase) entity).getTitleCache();
184 return (text == null || text.equals(""));
185 }
186 return false;
187 }
188
189 /* (non-Javadoc)
190 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#addDisplayListener(java.lang.Object)
191 */
192 /** {@inheritDoc} */
193 @Override
194 public void addDisplayListener(Object entity, EntityListener listener) {
195 /* Note: all non-field specific listeners require that corresponding property sheets
196 * contain the following:
197 *
198 *
199 * public void setPropertyValue(Object id, Object value) {
200 * ...
201 * reference.firePropertyChange(new PropertyChangeEvent(reference, "", null, null));
202 * }
203 *
204 */
205 if (entity instanceof CdmBase) {
206 ((CdmBase) entity).addPropertyChangeListener(listener);
207 }
208 }
209
210 /* (non-Javadoc)
211 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getFont(java.lang.Object)
212 */
213 /** {@inheritDoc} */
214 @Override
215 public Font getFont(Object entity) {
216 return null;
217 }
218 }