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.model;
|
11
|
|
12
|
import java.util.Iterator;
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.eclipse.jface.text.IDocument;
|
16
|
import org.eclipse.jface.text.ITextSelection;
|
17
|
import org.eclipse.jface.text.TextSelection;
|
18
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
19
|
import org.eclipse.jface.viewers.StructuredSelection;
|
20
|
|
21
|
/**
|
22
|
* Extending <code>TextSelection</code> allows us to keep using Eclipse's text selection, while
|
23
|
* <code>IStructuredSelection</code> can be used to send an object associated with the selection,
|
24
|
* i.e. a property source, to the workbench selection service.
|
25
|
*
|
26
|
* @author p.ciardelli
|
27
|
* @created 03.07.2009
|
28
|
*/
|
29
|
public class LineSelection extends TextSelection implements IStructuredSelection {
|
30
|
|
31
|
private StructuredSelection structuredSelection;
|
32
|
|
33
|
public LineSelection(ITextSelection selection, IDocument document, Object selectedObject) {
|
34
|
super(document, selection.getOffset(), selection.getLength());
|
35
|
if (selectedObject != null) {
|
36
|
this.structuredSelection = new StructuredSelection(selectedObject);
|
37
|
} else {
|
38
|
this.structuredSelection = StructuredSelection.EMPTY;
|
39
|
}
|
40
|
}
|
41
|
|
42
|
@Override
|
43
|
public Object getFirstElement() {
|
44
|
return structuredSelection.getFirstElement();
|
45
|
}
|
46
|
|
47
|
@Override
|
48
|
public Iterator<?> iterator() {
|
49
|
return structuredSelection.iterator();
|
50
|
}
|
51
|
|
52
|
@Override
|
53
|
public int size() {
|
54
|
return structuredSelection.size();
|
55
|
}
|
56
|
|
57
|
@Override
|
58
|
public Object[] toArray() {
|
59
|
return structuredSelection.toArray();
|
60
|
}
|
61
|
|
62
|
@Override
|
63
|
public List<?> toList() {
|
64
|
return structuredSelection.toList();
|
65
|
}
|
66
|
}
|