Project

General

Profile

Download (6.71 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
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

    
22
import eu.etaxonomy.cdm.common.CdmUtils;
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
import eu.etaxonomy.taxeditor.store.singlesource.widget.DisplayProxy;
37

    
38
/**
39
 * <p>BulkEditorLineDisplay class.</p>
40
 *
41
 * @author p.ciardelli
42
 * @created 07.07.2009
43
 * @version 1.0
44
 */
45
public class BulkEditorLineDisplay implements ILineDisplayStrategy {
46
	
47
	private BulkEditor editor;
48

    
49
	/**
50
	 * <p>Constructor for BulkEditorLineDisplay.</p>
51
	 *
52
	 * @param editor a {@link org.eclipse.ui.IEditorPart} object.
53
	 */
54
	public BulkEditorLineDisplay(BulkEditor editor) {
55
		this.editor = editor;
56
	}
57

    
58
	/* (non-Javadoc)
59
	 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getIcon(java.lang.Object)
60
	 */
61
	/** {@inheritDoc} */
62
	public Image getIcon(Object entity) {
63
		return null;
64
	}
65

    
66
	/* (non-Javadoc)
67
	 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getIndent(java.lang.Object)
68
	 */
69
	/** {@inheritDoc} */
70
	public int getIndent(Object entity) {
71
		return 0;
72
	}
73

    
74
	/* (non-Javadoc)
75
	 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getText(java.lang.Object)
76
	 */
77
	/** {@inheritDoc} */
78
	public String getText(Object entity) {		
79
		return editor.getEditorInput().getText((ICdmBase) entity);
80
	}
81

    
82

    
83
	/* (non-Javadoc)
84
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getSupplementalText(java.lang.Object)
85
	 */
86
	/** {@inheritDoc} */
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 += CdmUtils.isEmpty(typeText) ? "" : String.format(" [%s]", typeText);
95
		
96
		if (entity instanceof IAnnotatableEntity) {
97
			IAnnotatableEntity annotatableEntity = (IAnnotatableEntity) HibernateProxyHelper.deproxy(entity);
98

    
99
			Map<MarkerType, Boolean> editMarkerTypePreferences = PreferencesUtil.getEditMarkerTypePreferences();
100
			
101
			String markerText = "";
102
			List<String> markers = new ArrayList<String>();
103
			for (Marker marker : annotatableEntity.getMarkers()) {
104
				markers.add(String.format("%1s = %2s", marker.getMarkerType().getLabel(), marker.getFlag() ? "yes" : "no"));
105
			}
106
			if (! markers.isEmpty()) {
107
				markerText = StringUtils.join(markers, ", ");
108
			}
109
			
110
			supplementalText += CdmUtils.isEmpty(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
				DisplayProxy.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
}
(2-2/10)