Project

General

Profile

Download (6.2 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
package eu.etaxonomy.taxeditor.annotatedlineeditor;
10

    
11
import java.util.Set;
12

    
13
import org.apache.log4j.Logger;
14
import org.eclipse.jface.text.source.Annotation;
15

    
16
import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
17

    
18
/**
19
 * An <code>Annotation</code> which spans an entire line and holds an object associated
20
 * with the line in an <code>IEntityContainer</code>.
21
 *
22
 * @author p.ciardelli
23
 * @created 25.06.2009
24
 * @version 1.0
25
 */
26
public class LineAnnotation<T> extends Annotation implements IEntityContainer<T> {
27
	@SuppressWarnings("unused")
28
	private static final Logger logger = Logger
29
			.getLogger(LineAnnotationModel.class);
30

    
31
	/** Constant <code>TYPE_GENERIC="Annotation.TYPE_UNKNOWN"</code> */
32
	public static final String TYPE_GENERIC = Annotation.TYPE_UNKNOWN;
33

    
34
	private T entity;
35
	private ILineDisplayStrategy lineDisplayStrategy;
36

    
37
	private boolean dirty = false;
38
	private boolean markedAsMerged;
39
	private boolean markedAsNew;
40
	private T mergeTarget;
41
	private DeleteConfiguratorBase configurator= null;
42
	private boolean markAsDelete;
43

    
44

    
45
	/**
46
	 * <p>Constructor for LineAnnotation.</p>
47
	 *
48
	 * @param entity a T object.
49
	 * @param lineDisplayStrategy a {@link eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy} object.
50
	 * @param <T> a T object.
51
	 */
52
	public LineAnnotation(T entity, ILineDisplayStrategy lineDisplayStrategy) {
53
		this.entity = entity;
54
		this.lineDisplayStrategy = lineDisplayStrategy;
55
		setType(TYPE_GENERIC);
56
	}
57

    
58
	/* (non-Javadoc)
59
	 * @see org.eclipse.jface.text.source.Annotation#getText()
60
	 */
61
	/** {@inheritDoc} */
62
	@Override
63
	public String getText() {
64
		return getEditableText();
65
	}
66

    
67
	/* (non-Javadoc)
68
	 * @see org.eclipse.jface.text.source.Annotation#setText(java.lang.String)
69
	 */
70
	/** {@inheritDoc} */
71
	@Override
72
	public void setText(String text) {
73
		lineDisplayStrategy.setText(text, entity);
74
		dirty  = true;
75
		super.setText(text);
76
	}
77

    
78
	/** {@inheritDoc} */
79
	@Override
80
	public String toString() {
81
		// For debugging
82
		return getText();
83
	}
84

    
85
	/* (non-Javadoc)
86
	 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#getAttachedEntities()
87
	 */
88
	/**
89
	 * <p>getAttachedEntities</p>
90
	 *
91
	 * @return a {@link java.util.Set} object.
92
	 */
93
	@Override
94
    public Set getAttachedEntities() {
95
		// TODO Auto-generated method stub
96
		return null;
97
	}
98

    
99
	/* (non-Javadoc)
100
	 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#getEntity()
101
	 */
102
	/**
103
	 * <p>Getter for the field <code>entity</code>.</p>
104
	 *
105
	 * @return a T object.
106
	 */
107
	@Override
108
    public T getEntity() {
109
		return entity;
110
	}
111

    
112
	/* (non-Javadoc)
113
	 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#getEditableText()
114
	 */
115
	/**
116
	 * <p>getEditableText</p>
117
	 *
118
	 * @return a {@link java.lang.String} object.
119
	 */
120
	@Override
121
    public String getEditableText() {
122
		return lineDisplayStrategy.getText(entity);
123
	}
124

    
125
	/* (non-Javadoc)
126
	 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#getMergeTarget()
127
	 */
128
	/**
129
	 * <p>Getter for the field <code>mergeTarget</code>.</p>
130
	 *
131
	 * @return a T object.
132
	 */
133
	@Override
134
    public T getMergeTarget() {
135
		return mergeTarget;
136
	}
137

    
138
	/* (non-Javadoc)
139
	 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#isMarkedAsDeleted()
140
	 */
141
	/**
142
	 * <p>isMarkedAsDeleted</p>
143
	 *
144
	 * @return a boolean.
145
	 */
146
	@Override
147
    public boolean isMarkedAsDeleted() {
148
		return super.isMarkedDeleted();
149
	}
150

    
151
	/* (non-Javadoc)
152
	 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#isMarkedAsMerged()
153
	 */
154
	/**
155
	 * <p>isMarkedAsMerged</p>
156
	 *
157
	 * @return a boolean.
158
	 */
159
	@Override
160
    public boolean isMarkedAsMerged() {
161
		return markedAsMerged;
162
	}
163

    
164
	/* (non-Javadoc)
165
	 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#isMarkedAsNew()
166
	 */
167
	/**
168
	 * <p>isMarkedAsNew</p>
169
	 *
170
	 * @return a boolean.
171
	 */
172
	@Override
173
    public boolean isMarkedAsNew() {
174
		return markedAsNew;
175
	}
176

    
177
	/* (non-Javadoc)
178
	 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#markAsDeleted()
179
	 */
180
	/**
181
	 * <p>markAsDeleted</p>
182
	 */
183
	@Override
184
    public void markAsDeleted() {
185
		super.markDeleted(true);
186
		if (!isMarkedAsMerged()) {
187
			lineDisplayStrategy.setStatusMessage(entity + " deleted.", entity);
188
		}
189
	}
190
	 public void markAsDeleted(DeleteConfiguratorBase config) {
191
			super.markDeleted(true);
192
			this.configurator = config;
193
			if (!isMarkedAsMerged()) {
194
				lineDisplayStrategy.setStatusMessage(entity + " deleted.", entity);
195
			}
196
		}
197
	/* (non-Javadoc)
198
	 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#markAsMerged(eu.etaxonomy.cdm.model.common.CdmBase)
199
	 */
200
	/**
201
	 * <p>markAsMerged</p>
202
	 *
203
	 * @param mergeTarget a T object.
204
	 */
205
	@Override
206
    public void markAsMerged(T mergeTarget) {
207
		this.mergeTarget = mergeTarget;
208
		markedAsMerged = true;
209
		lineDisplayStrategy.setStatusMessage("'" + entity + "' merged into '" + mergeTarget + "'.", entity);
210
	}
211

    
212
	/* (non-Javadoc)
213
	 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#markAsNew()
214
	 */
215
	/** {@inheritDoc} */
216
	@Override
217
    public void markAsNew(boolean isNew) {
218
		markedAsNew = isNew;
219
		lineDisplayStrategy.setStatusMessage("New entity created.", entity);
220
	}
221

    
222
	/* (non-Javadoc)
223
	 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#setDirty(boolean)
224
	 */
225
	/** {@inheritDoc} */
226
	@Override
227
    public void setDirty(boolean dirty) {
228
		this.dirty = dirty;
229
	}
230

    
231
	/* (non-Javadoc)
232
	 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#isDirty()
233
	 */
234
	/**
235
	 * <p>isDirty</p>
236
	 *
237
	 * @return a boolean.
238
	 */
239
	@Override
240
    public boolean isDirty() {
241
		return dirty;
242
	}
243

    
244
	/**
245
	 * <p>getHoverText</p>
246
	 *
247
	 * @return a {@link java.lang.String} object.
248
	 */
249
	public String getHoverText() {
250
		return lineDisplayStrategy.getHoverText(entity);
251
	}
252

    
253
    /* (non-Javadoc)
254
     * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityContainer#setEntity(java.lang.Object)
255
     */
256
    @Override
257
    public void setEntity(Object entity) {
258
        this.entity = (T) entity;
259
    }
260

    
261
	public DeleteConfiguratorBase getDeleteConfigurator() {
262
		return this.configurator;
263
	}
264

    
265
	public void setDeleteConfigurator(DeleteConfiguratorBase config) {
266
		this.configurator = config;
267

    
268
	}
269
}
(12-12/16)