Project

General

Profile

Download (5.33 KB) Statistics
| Branch: | Tag: | Revision:
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.TaxonName;
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
 */
39
public class BulkEditorLineDisplay implements ILineDisplayStrategy {
40

    
41
	private BulkEditor editor;
42

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

    
52
	/** {@inheritDoc} */
53
	@Override
54
    public Image getIcon(Object entity) {
55
		return null;
56
	}
57

    
58
	/** {@inheritDoc} */
59
	@Override
60
    public int getIndent(Object entity) {
61
		return 0;
62
	}
63

    
64
	/** {@inheritDoc} */
65
	@Override
66
    public String getText(Object entity) {
67
		return editor.getEditorInput().getText((ICdmBase) entity);
68
	}
69

    
70
	/** {@inheritDoc} */
71
	@Override
72
    public String getSupplementalText(Object entity) {
73

    
74
		String supplementalText = "";
75

    
76
		AbstractBulkEditorInput input = editor.getEditorInput();
77
		String typeText = input.getTypeText(entity);
78

    
79
		supplementalText += StringUtils.isBlank(typeText) ? "" : String.format(" [%s]", typeText);
80

    
81
		if (entity instanceof IAnnotatableEntity) {
82
			IAnnotatableEntity annotatableEntity = (IAnnotatableEntity) HibernateProxyHelper.deproxy(entity);
83

    
84
			String markerText = "";
85
			List<String> markers = new ArrayList<String>();
86
			for (Marker marker : annotatableEntity.getMarkers()) {
87
				String markerLabel = marker.getMarkerType() == null? " unknown marker " : marker.getMarkerType().getLabel();
88
				markers.add(String.format("%1s = %2s", markerLabel, marker.getFlag() ? "yes" : "no"));
89
			}
90
			if (! markers.isEmpty()) {
91
				markerText = StringUtils.join(markers, ", ");
92
			}
93

    
94
			supplementalText += StringUtils.isBlank(markerText) ? "" : String.format(" [%s]", markerText);
95
		}
96

    
97
		return supplementalText;
98
	}
99

    
100
	/** {@inheritDoc} */
101
	@Override
102
    public void setText(String text, Object entity) {
103
		if (entity instanceof Reference) {
104
			((Reference) entity).setTitleCache(text);
105
		}
106
	}
107

    
108
	/** {@inheritDoc} */
109
	@Override
110
    public String getHoverText(Object entity) {
111
		return null;
112
	}
113

    
114
	/* (non-Javadoc)
115
	 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#setStatusMessage(java.lang.String, java.lang.Object)
116
	 */
117
	/** {@inheritDoc} */
118
	@Override
119
    public void setStatusMessage(final String text, Object entity) {
120

    
121
		// Calling from the synchronized method ListEditorReconcilingStrategy#doReconcile
122
		// without its own thread causes an invalid thread access exception
123
		// see http://wiki.eclipse.org/FAQ_Why_do_I_get_an_invalid_thread_access_exception%3F
124
		new Thread(new Runnable() {
125
			@Override
126
            public void run() {
127
				Display.getDefault().asyncExec(new Runnable() {
128
					@Override
129
                    public void run() {
130
						IStatusLineManager statusLineManager = editor.getEditorSite().getActionBars().getStatusLineManager();
131
						statusLineManager.setMessage(text);
132
					}
133
				});
134
			}
135
		}).start();
136
	}
137

    
138
	/** {@inheritDoc} */
139
	@Override
140
    public String getEmptyCacheMessage(Object entity) {
141
		return entity.toString();
142
	}
143

    
144
	/** {@inheritDoc} */
145
	@Override
146
    public boolean isEntityCacheEmpty(Object entity) {
147
		if (entity instanceof Reference) {
148
			String text = ((Reference) entity).getTitleCache();
149
			return (text == null || text.equals(""));
150
		}
151
		if (entity instanceof TaxonName) {
152
			String text = ((TaxonName) entity).getTitleCache();
153
			return (text == null || text.equals(""));
154
		}
155
		if (entity instanceof AgentBase) {
156
			String text = ((AgentBase) entity).getTitleCache();
157
			return (text == null || text.equals(""));
158
		}
159
		return false;
160
	}
161

    
162
	/** {@inheritDoc} */
163
	@Override
164
    public void addDisplayListener(Object entity, EntityListener listener) {
165
		/* Note: all non-field specific listeners require that corresponding property sheets
166
		 * contain the following:
167
		 *
168
		 *
169
		 * 		public void setPropertyValue(Object id, Object value) {
170
		 * 		...
171
		 * 			reference.firePropertyChange(new PropertyChangeEvent(reference, "", null, null));
172
		 * 		}
173
		 *
174
		 */
175
		if (entity instanceof CdmBase) {
176
			((CdmBase) entity).addPropertyChangeListener(listener);
177
		}
178
	}
179

    
180
	/* (non-Javadoc)
181
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getFont(java.lang.Object)
182
	 */
183
	/** {@inheritDoc} */
184
	@Override
185
    public Font getFont(Object entity) {
186
		return null;
187
	}
188
}
(3-3/10)