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
|
|
11
|
package eu.etaxonomy.taxeditor.model;
|
12
|
|
13
|
import java.util.Iterator;
|
14
|
import java.util.List;
|
15
|
|
16
|
import org.eclipse.jface.text.IDocument;
|
17
|
import org.eclipse.jface.text.ITextSelection;
|
18
|
import org.eclipse.jface.text.TextSelection;
|
19
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
20
|
import org.eclipse.jface.viewers.StructuredSelection;
|
21
|
|
22
|
/**
|
23
|
* Extending <code>TextSelection</code> allows us to keep using Eclipse's text selection, while
|
24
|
* <code>IStructuredSelection</code> can be used to send an object associated with the selection,
|
25
|
* i.e. a property source, to the workbench selection service.
|
26
|
*
|
27
|
* @author p.ciardelli
|
28
|
* @created 03.07.2009
|
29
|
* @version 1.0
|
30
|
*/
|
31
|
public class LineSelection extends TextSelection implements IStructuredSelection {
|
32
|
|
33
|
private StructuredSelection structuredSelection;
|
34
|
|
35
|
/**
|
36
|
* <p>Constructor for LineSelection.</p>
|
37
|
*
|
38
|
* @param selection a {@link org.eclipse.jface.text.ITextSelection} object.
|
39
|
* @param document a {@link org.eclipse.jface.text.IDocument} object.
|
40
|
* @param selectedObject a {@link java.lang.Object} object.
|
41
|
*/
|
42
|
public LineSelection(ITextSelection selection, IDocument document, Object selectedObject) {
|
43
|
super(document, selection.getOffset(), selection.getLength());
|
44
|
if (selectedObject != null) {
|
45
|
this.structuredSelection = new StructuredSelection(selectedObject);
|
46
|
} else {
|
47
|
this.structuredSelection = StructuredSelection.EMPTY;
|
48
|
}
|
49
|
}
|
50
|
|
51
|
/* (non-Javadoc)
|
52
|
* @see org.eclipse.jface.viewers.IStructuredSelection#getFirstElement()
|
53
|
*/
|
54
|
/**
|
55
|
* <p>getFirstElement</p>
|
56
|
*
|
57
|
* @return a {@link java.lang.Object} object.
|
58
|
*/
|
59
|
public Object getFirstElement() {
|
60
|
return structuredSelection.getFirstElement();
|
61
|
}
|
62
|
|
63
|
/* (non-Javadoc)
|
64
|
* @see org.eclipse.jface.viewers.IStructuredSelection#iterator()
|
65
|
*/
|
66
|
/**
|
67
|
* <p>iterator</p>
|
68
|
*
|
69
|
* @return a {@link java.util.Iterator} object.
|
70
|
*/
|
71
|
public Iterator<?> iterator() {
|
72
|
return structuredSelection.iterator();
|
73
|
}
|
74
|
|
75
|
/* (non-Javadoc)
|
76
|
* @see org.eclipse.jface.viewers.IStructuredSelection#size()
|
77
|
*/
|
78
|
/**
|
79
|
* <p>size</p>
|
80
|
*
|
81
|
* @return a int.
|
82
|
*/
|
83
|
public int size() {
|
84
|
return structuredSelection.size();
|
85
|
}
|
86
|
|
87
|
/* (non-Javadoc)
|
88
|
* @see org.eclipse.jface.viewers.IStructuredSelection#toArray()
|
89
|
*/
|
90
|
/**
|
91
|
* <p>toArray</p>
|
92
|
*
|
93
|
* @return an array of {@link java.lang.Object} objects.
|
94
|
*/
|
95
|
public Object[] toArray() {
|
96
|
return structuredSelection.toArray();
|
97
|
}
|
98
|
|
99
|
/* (non-Javadoc)
|
100
|
* @see org.eclipse.jface.viewers.IStructuredSelection#toList()
|
101
|
*/
|
102
|
/**
|
103
|
* <p>toList</p>
|
104
|
*
|
105
|
* @return a {@link java.util.List} object.
|
106
|
*/
|
107
|
public List<?> toList() {
|
108
|
return structuredSelection.toList();
|
109
|
}
|
110
|
}
|