Project

General

Profile

« Previous | Next » 

Revision 3be6ef3e

Added by Niels Hoffmann over 13 years ago

performed javacscript:fix and worked on documentation

View differences:

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 org.eclipse.jface.action.IStatusLineManager;
14
import org.eclipse.swt.graphics.Font;
15
import org.eclipse.swt.graphics.Image;
16
import org.eclipse.swt.widgets.Display;
17
import org.eclipse.ui.IEditorPart;
18

  
19
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
20
import eu.etaxonomy.cdm.model.agent.AgentBase;
21
import eu.etaxonomy.cdm.model.common.CdmBase;
22
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
23
import eu.etaxonomy.cdm.model.common.Marker;
24
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
25
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
26
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
27
import eu.etaxonomy.taxeditor.annotatedlineeditor.EntityListener;
28
import eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy;
29
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
30

  
31
/**
32
 * @author p.ciardelli
33
 * @created 07.07.2009
34
 * @version 1.0
35
 */
36
public class BulkEditorLineDisplay implements ILineDisplayStrategy {
37
	
38
	private IEditorPart editor;
39

  
40
	/**
41
	 * @param bulkEditor
42
	 */
43
	public BulkEditorLineDisplay(IEditorPart editor) {
44
		this.editor = editor;
45
	}
46

  
47
	/* (non-Javadoc)
48
	 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getIcon(java.lang.Object)
49
	 */
50
	public Image getIcon(Object entity) {
51
		return null;
52
	}
53

  
54
	/* (non-Javadoc)
55
	 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getIndent(java.lang.Object)
56
	 */
57
	public int getIndent(Object entity) {
58
		return 0;
59
	}
60

  
61
	/* (non-Javadoc)
62
	 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getText(java.lang.Object)
63
	 */
64
	public String getText(Object entity) {		
65
		String text = null;
66
		
67
		if(entity instanceof IdentifiableEntity){
68
			IdentifiableEntity identifiableEntity = (IdentifiableEntity) HibernateProxyHelper.deproxy(entity);
69
			if(identifiableEntity instanceof TaxonNameBase){
70
				// TODO it is not very nice to do this here. Please refactor
71
				text = ((TaxonNameBase) identifiableEntity).getFullTitleCache();
72
			}else{
73
				text = identifiableEntity.getTitleCache();
74
			}
75
		}
76
		
77
		return text == null ? "" : text;
78
	}
79

  
80

  
81
	/* (non-Javadoc)
82
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getSupplementalText(java.lang.Object)
83
	 */
84
	public String getSupplementalText(Object entity) {
85
		if (entity instanceof ReferenceBase) {
86
			ReferenceBase reference = (ReferenceBase) HibernateProxyHelper.deproxy(entity);
87
			// Nobody seems to like displaying the date
88
//			TimePeriod datePublished = ((StrictReferenceBase) reference).getDatePublished();
89
//						
90
//			String date = datePublished == null ? null : datePublished.toString();
91
//			if (date != null) {
92
//				text += " [" + date + "]";
93
//			}
94
			String markerText = null;
95
			for (Marker marker : reference.getMarkers()) {
96
				if (PreferencesUtil.getEditMarkerTypePreference(editor.getEditorInput(), marker.getMarkerType())) {
97
					if (markerText == null) {
98
						markerText = " [";
99
					} else {
100
						markerText += ", ";
101
					}
102
					markerText += marker.getMarkerType().getLabel() + " = " + marker.getFlag();
103
				}
104
			}
105
			if (markerText != null) {
106
				markerText += "]";
107
			} else {
108
				markerText = "";
109
			}
110
			return markerText;
111
		}
112
		if (entity instanceof TaxonNameBase) { 
113
			return "";
114
		}
115
		if (entity instanceof AgentBase) {
116
			return "[" + entity.getClass().getSimpleName() + "]";
117
		}
118
		if (entity instanceof SpecimenOrObservationBase) {
119
			return "[" + entity.getClass().getSimpleName() + "]";
120
		}
121
		return "";
122
	}
123
	
124
	/* (non-Javadoc)
125
	 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#setText(java.lang.String, java.lang.Object)
126
	 */
127
	public void setText(String text, Object entity) {
128
		if (entity instanceof ReferenceBase) {
129
			((ReferenceBase) entity).setTitleCache(text);			
130
		}
131
	}
132

  
133
	/* (non-Javadoc)
134
	 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getHoverText(java.lang.Object)
135
	 */
136
	public String getHoverText(Object entity) {
137
		return null;
138
	}
139

  
140
	/* (non-Javadoc)
141
	 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#setStatusMessage(java.lang.String, java.lang.Object)
142
	 */
143
	public void setStatusMessage(final String text, Object entity) {
144
		
145
		// Calling from the synchronized method ListEditorReconcilingStrategy#doReconcile
146
		// without its own thread causes an invalid thread access exception
147
		// see http://wiki.eclipse.org/FAQ_Why_do_I_get_an_invalid_thread_access_exception%3F
148
		new Thread(new Runnable() {
149
			public void run() {
150
				Display.getDefault().asyncExec(new Runnable() {
151
					public void run() {
152
						IStatusLineManager statusLineManager = editor.getEditorSite().getActionBars().getStatusLineManager();
153
						statusLineManager.setMessage(text);
154
					}
155
				});
156
			}
157
		}).start();
158
	}
159

  
160
	/* (non-Javadoc)
161
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getEmptyText(java.lang.Object)
162
	 */
163
	public String getEmptyCacheMessage(Object entity) {
164
		if (entity instanceof ReferenceBase) {
165
			return "No reference title cache";
166
		}
167
		if (entity instanceof TaxonNameBase) {
168
			return "No name title cache";
169
		}
170
		if (entity instanceof AgentBase) {
171
			return "No title cache";
172
		}
173
		return "";
174
	}
175

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

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

  
214
	/* (non-Javadoc)
215
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getFont(java.lang.Object)
216
	 */
217
	public Font getFont(Object entity) {
218
		return null;
219
	}
220
}
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 org.eclipse.jface.action.IStatusLineManager;
14
import org.eclipse.swt.graphics.Font;
15
import org.eclipse.swt.graphics.Image;
16
import org.eclipse.swt.widgets.Display;
17
import org.eclipse.ui.IEditorPart;
18

  
19
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
20
import eu.etaxonomy.cdm.model.agent.AgentBase;
21
import eu.etaxonomy.cdm.model.common.CdmBase;
22
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
23
import eu.etaxonomy.cdm.model.common.Marker;
24
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
25
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
26
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
27
import eu.etaxonomy.taxeditor.annotatedlineeditor.EntityListener;
28
import eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy;
29
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
30

  
31
/**
32
 * <p>BulkEditorLineDisplay class.</p>
33
 *
34
 * @author p.ciardelli
35
 * @created 07.07.2009
36
 * @version 1.0
37
 */
38
public class BulkEditorLineDisplay implements ILineDisplayStrategy {
39
	
40
	private IEditorPart editor;
41

  
42
	/**
43
	 * <p>Constructor for BulkEditorLineDisplay.</p>
44
	 *
45
	 * @param editor a {@link org.eclipse.ui.IEditorPart} object.
46
	 */
47
	public BulkEditorLineDisplay(IEditorPart editor) {
48
		this.editor = editor;
49
	}
50

  
51
	/* (non-Javadoc)
52
	 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getIcon(java.lang.Object)
53
	 */
54
	/** {@inheritDoc} */
55
	public Image getIcon(Object entity) {
56
		return null;
57
	}
58

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

  
67
	/* (non-Javadoc)
68
	 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getText(java.lang.Object)
69
	 */
70
	/** {@inheritDoc} */
71
	public String getText(Object entity) {		
72
		String text = null;
73
		
74
		if(entity instanceof IdentifiableEntity){
75
			IdentifiableEntity identifiableEntity = (IdentifiableEntity) HibernateProxyHelper.deproxy(entity);
76
			if(identifiableEntity instanceof TaxonNameBase){
77
				// TODO it is not very nice to do this here. Please refactor
78
				text = ((TaxonNameBase) identifiableEntity).getFullTitleCache();
79
			}else{
80
				text = identifiableEntity.getTitleCache();
81
			}
82
		}
83
		
84
		return text == null ? "" : text;
85
	}
86

  
87

  
88
	/* (non-Javadoc)
89
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getSupplementalText(java.lang.Object)
90
	 */
91
	/** {@inheritDoc} */
92
	public String getSupplementalText(Object entity) {
93
		if (entity instanceof ReferenceBase) {
94
			ReferenceBase reference = (ReferenceBase) HibernateProxyHelper.deproxy(entity);
95
			// Nobody seems to like displaying the date
96
//			TimePeriod datePublished = ((StrictReferenceBase) reference).getDatePublished();
97
//						
98
//			String date = datePublished == null ? null : datePublished.toString();
99
//			if (date != null) {
100
//				text += " [" + date + "]";
101
//			}
102
			String markerText = null;
103
			for (Marker marker : reference.getMarkers()) {
104
				if (PreferencesUtil.getEditMarkerTypePreference(editor.getEditorInput(), marker.getMarkerType())) {
105
					if (markerText == null) {
106
						markerText = " [";
107
					} else {
108
						markerText += ", ";
109
					}
110
					markerText += marker.getMarkerType().getLabel() + " = " + marker.getFlag();
111
				}
112
			}
113
			if (markerText != null) {
114
				markerText += "]";
115
			} else {
116
				markerText = "";
117
			}
118
			return markerText;
119
		}
120
		if (entity instanceof TaxonNameBase) { 
121
			return "";
122
		}
123
		if (entity instanceof AgentBase) {
124
			return "[" + entity.getClass().getSimpleName() + "]";
125
		}
126
		if (entity instanceof SpecimenOrObservationBase) {
127
			return "[" + entity.getClass().getSimpleName() + "]";
128
		}
129
		return "";
130
	}
131
	
132
	/* (non-Javadoc)
133
	 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#setText(java.lang.String, java.lang.Object)
134
	 */
135
	/** {@inheritDoc} */
136
	public void setText(String text, Object entity) {
137
		if (entity instanceof ReferenceBase) {
138
			((ReferenceBase) entity).setTitleCache(text);			
139
		}
140
	}
141

  
142
	/* (non-Javadoc)
143
	 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#getHoverText(java.lang.Object)
144
	 */
145
	/** {@inheritDoc} */
146
	public String getHoverText(Object entity) {
147
		return null;
148
	}
149

  
150
	/* (non-Javadoc)
151
	 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#setStatusMessage(java.lang.String, java.lang.Object)
152
	 */
153
	/** {@inheritDoc} */
154
	public void setStatusMessage(final String text, Object entity) {
155
		
156
		// Calling from the synchronized method ListEditorReconcilingStrategy#doReconcile
157
		// without its own thread causes an invalid thread access exception
158
		// see http://wiki.eclipse.org/FAQ_Why_do_I_get_an_invalid_thread_access_exception%3F
159
		new Thread(new Runnable() {
160
			public void run() {
161
				Display.getDefault().asyncExec(new Runnable() {
162
					public void run() {
163
						IStatusLineManager statusLineManager = editor.getEditorSite().getActionBars().getStatusLineManager();
164
						statusLineManager.setMessage(text);
165
					}
166
				});
167
			}
168
		}).start();
169
	}
170

  
171
	/* (non-Javadoc)
172
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getEmptyText(java.lang.Object)
173
	 */
174
	/** {@inheritDoc} */
175
	public String getEmptyCacheMessage(Object entity) {
176
		if (entity instanceof ReferenceBase) {
177
			return "No reference title cache";
178
		}
179
		if (entity instanceof TaxonNameBase) {
180
			return "No name title cache";
181
		}
182
		if (entity instanceof AgentBase) {
183
			return "No title cache";
184
		}
185
		return "";
186
	}
187

  
188
	/* (non-Javadoc)
189
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#isEntityCacheEmpty(java.lang.Object)
190
	 */
191
	/** {@inheritDoc} */
192
	public boolean isEntityCacheEmpty(Object entity) {
193
		if (entity instanceof ReferenceBase) {
194
			String text = ((ReferenceBase) entity).getTitleCache();
195
			return (text == null || text.equals(""));
196
		}
197
		if (entity instanceof TaxonNameBase) {
198
			String text = ((TaxonNameBase) entity).getTitleCache(); 
199
			return (text == null || text.equals(""));
200
		}
201
		if (entity instanceof AgentBase) {
202
			String text = ((AgentBase) entity).getTitleCache(); 
203
			return (text == null || text.equals(""));
204
		}
205
		return false;
206
	}
207

  
208
	/* (non-Javadoc)
209
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#addDisplayListener(java.lang.Object)
210
	 */
211
	/** {@inheritDoc} */
212
	public void addDisplayListener(Object entity, EntityListener listener) {
213
		/* Note: all non-field specific listeners require that corresponding property sheets 
214
		 * contain the following:
215
		 * 
216
		 * 
217
		 * 		public void setPropertyValue(Object id, Object value) {
218
		 * 		...
219
		 * 			reference.firePropertyChange(new PropertyChangeEvent(reference, "", null, null));
220
		 * 		}
221
		 * 
222
		 */
223
		if (entity instanceof CdmBase) {
224
			((CdmBase) entity).addPropertyChangeListener(listener);
225
		}
226
	}
227

  
228
	/* (non-Javadoc)
229
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getFont(java.lang.Object)
230
	 */
231
	/** {@inheritDoc} */
232
	public Font getFont(Object entity) {
233
		return null;
234
	}
235
}

Also available in: Unified diff