1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.bulkeditor;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.List;
|
14
|
|
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;
|
20
|
|
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.ICdmBase;
|
26
|
import eu.etaxonomy.cdm.model.common.Marker;
|
27
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
28
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
29
|
import eu.etaxonomy.taxeditor.annotatedlineeditor.EntityListener;
|
30
|
import eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy;
|
31
|
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
|
32
|
|
33
|
/**
|
34
|
* <p>BulkEditorLineDisplay class.</p>
|
35
|
*
|
36
|
* @author p.ciardelli
|
37
|
* @created 07.07.2009
|
38
|
* @version 1.0
|
39
|
*/
|
40
|
public class BulkEditorLineDisplay implements ILineDisplayStrategy {
|
41
|
|
42
|
private BulkEditor editor;
|
43
|
|
44
|
/**
|
45
|
* <p>Constructor for BulkEditorLineDisplay.</p>
|
46
|
*
|
47
|
* @param editor a {@link org.eclipse.ui.IEditorPart} object.
|
48
|
*/
|
49
|
public BulkEditorLineDisplay(BulkEditor editor) {
|
50
|
this.editor = editor;
|
51
|
}
|
52
|
|
53
|
/* (non-Javadoc)
|
54
|
* @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getIcon(java.lang.Object)
|
55
|
*/
|
56
|
/** {@inheritDoc} */
|
57
|
@Override
|
58
|
public Image getIcon(Object entity) {
|
59
|
return null;
|
60
|
}
|
61
|
|
62
|
/* (non-Javadoc)
|
63
|
* @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getIndent(java.lang.Object)
|
64
|
*/
|
65
|
/** {@inheritDoc} */
|
66
|
@Override
|
67
|
public int getIndent(Object entity) {
|
68
|
return 0;
|
69
|
}
|
70
|
|
71
|
/* (non-Javadoc)
|
72
|
* @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getText(java.lang.Object)
|
73
|
*/
|
74
|
/** {@inheritDoc} */
|
75
|
@Override
|
76
|
public String getText(Object entity) {
|
77
|
return editor.getEditorInput().getText((ICdmBase) entity);
|
78
|
}
|
79
|
|
80
|
|
81
|
/* (non-Javadoc)
|
82
|
* @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getSupplementalText(java.lang.Object)
|
83
|
*/
|
84
|
/** {@inheritDoc} */
|
85
|
@Override
|
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
|
String markerText = "";
|
99
|
List<String> markers = new ArrayList<String>();
|
100
|
for (Marker marker : annotatableEntity.getMarkers()) {
|
101
|
String markerLabel = marker.getMarkerType() == null? " unknown marker " : marker.getMarkerType().getLabel();
|
102
|
markers.add(String.format("%1s = %2s", markerLabel, marker.getFlag() ? "yes" : "no"));
|
103
|
}
|
104
|
if (! markers.isEmpty()) {
|
105
|
markerText = StringUtils.join(markers, ", ");
|
106
|
}
|
107
|
|
108
|
supplementalText += StringUtils.isBlank(markerText) ? "" : String.format(" [%s]", markerText);
|
109
|
}
|
110
|
|
111
|
return supplementalText;
|
112
|
}
|
113
|
|
114
|
/* (non-Javadoc)
|
115
|
* @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#setText(java.lang.String, java.lang.Object)
|
116
|
*/
|
117
|
/** {@inheritDoc} */
|
118
|
@Override
|
119
|
public void setText(String text, Object entity) {
|
120
|
if (entity instanceof Reference) {
|
121
|
((Reference) entity).setTitleCache(text);
|
122
|
}
|
123
|
}
|
124
|
|
125
|
/* (non-Javadoc)
|
126
|
* @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getHoverText(java.lang.Object)
|
127
|
*/
|
128
|
/** {@inheritDoc} */
|
129
|
@Override
|
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
|
@Override
|
139
|
public void setStatusMessage(final String text, Object entity) {
|
140
|
|
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() {
|
145
|
@Override
|
146
|
public void run() {
|
147
|
Display.getDefault().asyncExec(new Runnable() {
|
148
|
@Override
|
149
|
public void run() {
|
150
|
IStatusLineManager statusLineManager = editor.getEditorSite().getActionBars().getStatusLineManager();
|
151
|
statusLineManager.setMessage(text);
|
152
|
}
|
153
|
});
|
154
|
}
|
155
|
}).start();
|
156
|
}
|
157
|
|
158
|
/* (non-Javadoc)
|
159
|
* @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getEmptyText(java.lang.Object)
|
160
|
*/
|
161
|
/** {@inheritDoc} */
|
162
|
@Override
|
163
|
public String getEmptyCacheMessage(Object entity) {
|
164
|
return entity.toString();
|
165
|
}
|
166
|
|
167
|
/* (non-Javadoc)
|
168
|
* @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#isEntityCacheEmpty(java.lang.Object)
|
169
|
*/
|
170
|
/** {@inheritDoc} */
|
171
|
@Override
|
172
|
public boolean isEntityCacheEmpty(Object entity) {
|
173
|
if (entity instanceof Reference) {
|
174
|
String text = ((Reference) entity).getTitleCache();
|
175
|
return (text == null || text.equals(""));
|
176
|
}
|
177
|
if (entity instanceof TaxonNameBase) {
|
178
|
String text = ((TaxonNameBase) entity).getTitleCache();
|
179
|
return (text == null || text.equals(""));
|
180
|
}
|
181
|
if (entity instanceof AgentBase) {
|
182
|
String text = ((AgentBase) entity).getTitleCache();
|
183
|
return (text == null || text.equals(""));
|
184
|
}
|
185
|
return false;
|
186
|
}
|
187
|
|
188
|
/* (non-Javadoc)
|
189
|
* @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#addDisplayListener(java.lang.Object)
|
190
|
*/
|
191
|
/** {@inheritDoc} */
|
192
|
@Override
|
193
|
public void addDisplayListener(Object entity, EntityListener listener) {
|
194
|
/* Note: all non-field specific listeners require that corresponding property sheets
|
195
|
* contain the following:
|
196
|
*
|
197
|
*
|
198
|
* public void setPropertyValue(Object id, Object value) {
|
199
|
* ...
|
200
|
* reference.firePropertyChange(new PropertyChangeEvent(reference, "", null, null));
|
201
|
* }
|
202
|
*
|
203
|
*/
|
204
|
if (entity instanceof CdmBase) {
|
205
|
((CdmBase) entity).addPropertyChangeListener(listener);
|
206
|
}
|
207
|
}
|
208
|
|
209
|
/* (non-Javadoc)
|
210
|
* @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getFont(java.lang.Object)
|
211
|
*/
|
212
|
/** {@inheritDoc} */
|
213
|
@Override
|
214
|
public Font getFont(Object entity) {
|
215
|
return null;
|
216
|
}
|
217
|
}
|