Project

General

Profile

Download (6.67 KB) Statistics
| Branch: | Tag: | Revision:
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
		if (entity instanceof Reference) {
166
			return "No reference title cache";
167
		}
168
		if (entity instanceof TaxonNameBase) {
169
			return "No name title cache";
170
		}
171
		if (entity instanceof AgentBase) {
172
			return "No title cache";
173
		}
174
		return "";
175
	}
176

    
177
	/* (non-Javadoc)
178
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#isEntityCacheEmpty(java.lang.Object)
179
	 */
180
	/** {@inheritDoc} */
181
	@Override
182
    public boolean isEntityCacheEmpty(Object entity) {
183
		if (entity instanceof Reference) {
184
			String text = ((Reference) entity).getTitleCache();
185
			return (text == null || text.equals(""));
186
		}
187
		if (entity instanceof TaxonNameBase) {
188
			String text = ((TaxonNameBase) entity).getTitleCache();
189
			return (text == null || text.equals(""));
190
		}
191
		if (entity instanceof AgentBase) {
192
			String text = ((AgentBase) entity).getTitleCache();
193
			return (text == null || text.equals(""));
194
		}
195
		return false;
196
	}
197

    
198
	/* (non-Javadoc)
199
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#addDisplayListener(java.lang.Object)
200
	 */
201
	/** {@inheritDoc} */
202
	@Override
203
    public void addDisplayListener(Object entity, EntityListener listener) {
204
		/* Note: all non-field specific listeners require that corresponding property sheets
205
		 * contain the following:
206
		 *
207
		 *
208
		 * 		public void setPropertyValue(Object id, Object value) {
209
		 * 		...
210
		 * 			reference.firePropertyChange(new PropertyChangeEvent(reference, "", null, null));
211
		 * 		}
212
		 *
213
		 */
214
		if (entity instanceof CdmBase) {
215
			((CdmBase) entity).addPropertyChangeListener(listener);
216
		}
217
	}
218

    
219
	/* (non-Javadoc)
220
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getFont(java.lang.Object)
221
	 */
222
	/** {@inheritDoc} */
223
	@Override
224
    public Font getFont(Object entity) {
225
		return null;
226
	}
227
}
(3-3/10)