Alternative versions for build.properties added. Current state set to "dependencies...
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / annotatedlineeditor / LineAnnotation.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 package eu.etaxonomy.taxeditor.annotatedlineeditor;
11
12 import java.util.Set;
13
14 import org.apache.log4j.Logger;
15 import org.eclipse.jface.text.source.Annotation;
16
17 import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
18 import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
19
20 /**
21 * An <code>Annotation</code> which spans an entire line and holds an object associated
22 * with the line in an <code>IEntityContainer</code>.
23 *
24 * @author p.ciardelli
25 * @created 25.06.2009
26 * @version 1.0
27 */
28 public class LineAnnotation<T> extends Annotation implements IEntityContainer<T> {
29 @SuppressWarnings("unused")
30 private static final Logger logger = Logger
31 .getLogger(LineAnnotationModel.class);
32
33 /** Constant <code>TYPE_GENERIC="Annotation.TYPE_UNKNOWN"</code> */
34 public static final String TYPE_GENERIC = Annotation.TYPE_UNKNOWN;
35
36 private T entity;
37 private ILineDisplayStrategy lineDisplayStrategy;
38
39 private boolean dirty = false;
40 private boolean markedAsMerged;
41 private boolean markedAsNew;
42 private T mergeTarget;
43 private DeleteConfiguratorBase configurator= null;
44
45
46 /**
47 * <p>Constructor for LineAnnotation.</p>
48 *
49 * @param entity a T object.
50 * @param lineDisplayStrategy a {@link eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy} object.
51 * @param <T> a T object.
52 */
53 public LineAnnotation(T entity, ILineDisplayStrategy lineDisplayStrategy) {
54 this.entity = entity;
55 this.lineDisplayStrategy = lineDisplayStrategy;
56 setType(TYPE_GENERIC);
57 }
58
59 /* (non-Javadoc)
60 * @see org.eclipse.jface.text.source.Annotation#getText()
61 */
62 /** {@inheritDoc} */
63 @Override
64 public String getText() {
65 return getEditableText();
66 }
67
68 /* (non-Javadoc)
69 * @see org.eclipse.jface.text.source.Annotation#setText(java.lang.String)
70 */
71 /** {@inheritDoc} */
72 @Override
73 public void setText(String text) {
74 lineDisplayStrategy.setText(text, entity);
75 dirty = true;
76 super.setText(text);
77 }
78
79 /** {@inheritDoc} */
80 @Override
81 public String toString() {
82 // For debugging
83 return getText();
84 }
85
86 /* (non-Javadoc)
87 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#getAttachedEntities()
88 */
89 /**
90 * <p>getAttachedEntities</p>
91 *
92 * @return a {@link java.util.Set} object.
93 */
94 @Override
95 public Set getAttachedEntities() {
96 // TODO Auto-generated method stub
97 return null;
98 }
99
100 /* (non-Javadoc)
101 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#getEntity()
102 */
103 /**
104 * <p>Getter for the field <code>entity</code>.</p>
105 *
106 * @return a T object.
107 */
108 @Override
109 public T getEntity() {
110 return entity;
111 }
112
113 /* (non-Javadoc)
114 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#getEditableText()
115 */
116 /**
117 * <p>getEditableText</p>
118 *
119 * @return a {@link java.lang.String} object.
120 */
121 @Override
122 public String getEditableText() {
123 return lineDisplayStrategy.getText(entity);
124 }
125
126 /* (non-Javadoc)
127 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#getMergeTarget()
128 */
129 /**
130 * <p>Getter for the field <code>mergeTarget</code>.</p>
131 *
132 * @return a T object.
133 */
134 @Override
135 public T getMergeTarget() {
136 return mergeTarget;
137 }
138
139 /* (non-Javadoc)
140 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#isMarkedAsDeleted()
141 */
142 /**
143 * <p>isMarkedAsDeleted</p>
144 *
145 * @return a boolean.
146 */
147 @Override
148 public boolean isMarkedAsDeleted() {
149 return super.isMarkedDeleted();
150 }
151
152 /* (non-Javadoc)
153 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#isMarkedAsMerged()
154 */
155 /**
156 * <p>isMarkedAsMerged</p>
157 *
158 * @return a boolean.
159 */
160 @Override
161 public boolean isMarkedAsMerged() {
162 return markedAsMerged;
163 }
164
165 /* (non-Javadoc)
166 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#isMarkedAsNew()
167 */
168 /**
169 * <p>isMarkedAsNew</p>
170 *
171 * @return a boolean.
172 */
173 @Override
174 public boolean isMarkedAsNew() {
175 return markedAsNew;
176 }
177
178 /* (non-Javadoc)
179 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#markAsDeleted()
180 */
181 /**
182 * <p>markAsDeleted</p>
183 */
184 @Override
185 public void markAsDeleted() {
186 super.markDeleted(true);
187 if (!isMarkedAsMerged()) {
188 lineDisplayStrategy.setStatusMessage(entity + " deleted.", entity);
189 }
190 }
191 public void markAsDeleted(DeleteConfiguratorBase config) {
192 super.markDeleted(true);
193 this.configurator = config;
194 if (!isMarkedAsMerged()) {
195 lineDisplayStrategy.setStatusMessage(entity + " deleted.", entity);
196 }
197 }
198 /* (non-Javadoc)
199 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#markAsMerged(eu.etaxonomy.cdm.model.common.CdmBase)
200 */
201 /**
202 * <p>markAsMerged</p>
203 *
204 * @param mergeTarget a T object.
205 */
206 @Override
207 public void markAsMerged(T mergeTarget) {
208 this.mergeTarget = mergeTarget;
209 markedAsMerged = true;
210 lineDisplayStrategy.setStatusMessage("'" + entity + "' merged into '" + mergeTarget + "'.", entity);
211 }
212
213 /* (non-Javadoc)
214 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#markAsNew()
215 */
216 /** {@inheritDoc} */
217 @Override
218 public void markAsNew(boolean isNew) {
219 markedAsNew = isNew;
220 lineDisplayStrategy.setStatusMessage("New entity created.", entity);
221 }
222
223 /* (non-Javadoc)
224 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#setDirty(boolean)
225 */
226 /** {@inheritDoc} */
227 @Override
228 public void setDirty(boolean dirty) {
229 this.dirty = dirty;
230 }
231
232 /* (non-Javadoc)
233 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#isDirty()
234 */
235 /**
236 * <p>isDirty</p>
237 *
238 * @return a boolean.
239 */
240 @Override
241 public boolean isDirty() {
242 return dirty;
243 }
244
245 /**
246 * <p>getHoverText</p>
247 *
248 * @return a {@link java.lang.String} object.
249 */
250 public String getHoverText() {
251 return lineDisplayStrategy.getHoverText(entity);
252 }
253
254 /* (non-Javadoc)
255 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityContainer#setEntity(java.lang.Object)
256 */
257 @Override
258 public void setEntity(Object entity) {
259 this.entity = (T) entity;
260 }
261
262 public DeleteConfiguratorBase getDeleteConfigurator() {
263 return this.configurator;
264 }
265
266 public void setDeleteConfigurator(DeleteConfiguratorBase config) {
267 this.configurator = config;
268
269 }
270 }