Project

General

Profile

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

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

    
33
	private T entity;
34
	private ILineDisplayStrategy lineDisplayStrategy;
35

    
36
	private boolean dirty = false;
37
	private boolean markedAsMerged;
38
	private boolean markedAsNew;
39
	private T mergeTarget;
40

    
41

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

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

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

    
75
	/** {@inheritDoc} */
76
	@Override
77
	public String toString() {
78
		// For debugging
79
		return getText();
80
	}
81

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

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

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

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

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

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

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

    
174
	/* (non-Javadoc)
175
	 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#markAsDeleted()
176
	 */
177
	/**
178
	 * <p>markAsDeleted</p>
179
	 */
180
	@Override
181
    public void markAsDeleted() {
182
		super.markDeleted(true);
183
		if (!isMarkedAsMerged()) {
184
			lineDisplayStrategy.setStatusMessage(entity + " deleted.", entity);
185
		}
186
	}
187

    
188
	/* (non-Javadoc)
189
	 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#markAsMerged(eu.etaxonomy.cdm.model.common.CdmBase)
190
	 */
191
	/**
192
	 * <p>markAsMerged</p>
193
	 *
194
	 * @param mergeTarget a T object.
195
	 */
196
	@Override
197
    public void markAsMerged(T mergeTarget) {
198
		this.mergeTarget = mergeTarget;
199
		markedAsMerged = true;
200
		lineDisplayStrategy.setStatusMessage("'" + entity + "' merged into '" + mergeTarget + "'.", entity);
201
	}
202

    
203
	/* (non-Javadoc)
204
	 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#markAsNew()
205
	 */
206
	/** {@inheritDoc} */
207
	@Override
208
    public void markAsNew(boolean isNew) {
209
		markedAsNew = isNew;
210
		lineDisplayStrategy.setStatusMessage("New entity created.", entity);
211
	}
212

    
213
	/* (non-Javadoc)
214
	 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#setDirty(boolean)
215
	 */
216
	/** {@inheritDoc} */
217
	@Override
218
    public void setDirty(boolean dirty) {
219
		this.dirty = dirty;
220
	}
221

    
222
	/* (non-Javadoc)
223
	 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityContainer#isDirty()
224
	 */
225
	/**
226
	 * <p>isDirty</p>
227
	 *
228
	 * @return a boolean.
229
	 */
230
	@Override
231
    public boolean isDirty() {
232
		return dirty;
233
	}
234

    
235
	/**
236
	 * <p>getHoverText</p>
237
	 *
238
	 * @return a {@link java.lang.String} object.
239
	 */
240
	public String getHoverText() {
241
		return lineDisplayStrategy.getHoverText(entity);
242
	}
243

    
244
    /* (non-Javadoc)
245
     * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityContainer#setEntity(java.lang.Object)
246
     */
247
    @Override
248
    public void setEntity(Object entity) {
249
        this.entity = (T) entity;
250
    }
251
}
(12-12/16)