fix save for bulkeditor
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / BulkEditorLineDisplay.java
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 org.eclipse.jface.action.IStatusLineManager;
13 import org.eclipse.swt.graphics.Font;
14 import org.eclipse.swt.graphics.Image;
15 import org.eclipse.swt.widgets.Display;
16
17 import eu.etaxonomy.cdm.model.agent.AgentBase;
18 import eu.etaxonomy.cdm.model.common.CdmBase;
19 import eu.etaxonomy.cdm.model.name.TaxonName;
20 import eu.etaxonomy.cdm.model.reference.Reference;
21 import eu.etaxonomy.taxeditor.annotatedlineeditor.EntityListener;
22 import eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy;
23
24 /**
25 * <p>BulkEditorLineDisplay class.</p>
26 *
27 * @author p.ciardelli
28 * @created 07.07.2009
29 */
30 public class BulkEditorLineDisplay implements ILineDisplayStrategy {
31
32 private BulkEditor editor;
33
34 /**
35 * <p>Constructor for BulkEditorLineDisplay.</p>
36 *
37 * @param editor a {@link org.eclipse.ui.IEditorPart} object.
38 */
39 public BulkEditorLineDisplay(BulkEditor editor) {
40 this.editor = editor;
41 }
42
43 /** {@inheritDoc} */
44 @Override
45 public Image getIcon(Object entity) {
46 return null;
47 }
48
49 /** {@inheritDoc} */
50 @Override
51 public int getIndent(Object entity) {
52 return 0;
53 }
54
55 /** {@inheritDoc} */
56 @Override
57 public String getText(Object entity) {
58 return "";//editor.getEditorInput().getText((CdmBase) entity);
59 }
60
61 /** {@inheritDoc} */
62 @Override
63 public String getSupplementalText(Object entity) {
64
65 String supplementalText = "";
66
67 // AbstractBulkEditorInput input = editor.getEditorInput();
68 // String typeText = input.getTypeText(entity);
69 //
70 // supplementalText += StringUtils.isBlank(typeText) ? "" : String.format(" [%s]", typeText);
71 //
72 // if (entity instanceof IAnnotatableEntity) {
73 // IAnnotatableEntity annotatableEntity = (IAnnotatableEntity) HibernateProxyHelper.deproxy(entity);
74 //
75 // String markerText = "";
76 // List<String> markers = new ArrayList<String>();
77 // for (Marker marker : annotatableEntity.getMarkers()) {
78 // String markerLabel = marker.getMarkerType() == null? " unknown marker " : marker.getMarkerType().getLabel();
79 // markers.add(String.format("%1s = %2s", markerLabel, marker.getFlag() ? "yes" : "no"));
80 // }
81 // if (! markers.isEmpty()) {
82 // markerText = StringUtils.join(markers, ", ");
83 // }
84 //
85 // supplementalText += StringUtils.isBlank(markerText) ? "" : String.format(" [%s]", markerText);
86 // }
87
88 return supplementalText;
89 }
90
91 /** {@inheritDoc} */
92 @Override
93 public void setText(String text, Object entity) {
94 if (entity instanceof Reference) {
95 ((Reference) entity).setTitleCache(text);
96 }
97 }
98
99 /** {@inheritDoc} */
100 @Override
101 public String getHoverText(Object entity) {
102 return null;
103 }
104
105 /* (non-Javadoc)
106 * @see eu.etaxonomy.taxeditor.bulkeditor.ILineDisplayStrategy#setStatusMessage(java.lang.String, java.lang.Object)
107 */
108 /** {@inheritDoc} */
109 @Override
110 public void setStatusMessage(final String text, Object entity) {
111
112 // Calling from the synchronized method ListEditorReconcilingStrategy#doReconcile
113 // without its own thread causes an invalid thread access exception
114 // see http://wiki.eclipse.org/FAQ_Why_do_I_get_an_invalid_thread_access_exception%3F
115 new Thread(new Runnable() {
116 @Override
117 public void run() {
118 Display.getDefault().asyncExec(new Runnable() {
119 @Override
120 public void run() {
121 IStatusLineManager statusLineManager = editor.getEditorSite().getActionBars().getStatusLineManager();
122 statusLineManager.setMessage(text);
123 }
124 });
125 }
126 }).start();
127 }
128
129 /** {@inheritDoc} */
130 @Override
131 public String getEmptyCacheMessage(Object entity) {
132 return entity.toString();
133 }
134
135 /** {@inheritDoc} */
136 @Override
137 public boolean isEntityCacheEmpty(Object entity) {
138 if (entity instanceof Reference) {
139 String text = ((Reference) entity).getTitleCache();
140 return (text == null || text.equals(""));
141 }
142 if (entity instanceof TaxonName) {
143 String text = ((TaxonName) entity).getTitleCache();
144 return (text == null || text.equals(""));
145 }
146 if (entity instanceof AgentBase) {
147 String text = ((AgentBase) entity).getTitleCache();
148 return (text == null || text.equals(""));
149 }
150 return false;
151 }
152
153 /** {@inheritDoc} */
154 @Override
155 public void addDisplayListener(Object entity, EntityListener listener) {
156 /* Note: all non-field specific listeners require that corresponding property sheets
157 * contain the following:
158 *
159 *
160 * public void setPropertyValue(Object id, Object value) {
161 * ...
162 * reference.firePropertyChange(new PropertyChangeEvent(reference, "", null, null));
163 * }
164 *
165 */
166 if (entity instanceof CdmBase) {
167 ((CdmBase) entity).addPropertyChangeListener(listener);
168 }
169 }
170
171 /* (non-Javadoc)
172 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy#getFont(java.lang.Object)
173 */
174 /** {@inheritDoc} */
175 @Override
176 public Font getFont(Object entity) {
177 return null;
178 }
179 }