1 |
3be6ef3e
|
n.hoffmann
|
/**
|
2 |
|
|
* Copyright (C) 2007 EDIT
|
3 |
b7b99774
|
Patric Plitzner
|
* European Distributed Institute of Taxonomy
|
4 |
3be6ef3e
|
n.hoffmann
|
* http://www.e-taxonomy.eu
|
5 |
b7b99774
|
Patric Plitzner
|
*
|
6 |
3be6ef3e
|
n.hoffmann
|
* 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 |
|
|
* @version 1.0
|
29 |
|
|
*/
|
30 |
|
|
public class LineSelection extends TextSelection implements IStructuredSelection {
|
31 |
|
|
|
32 |
|
|
private StructuredSelection structuredSelection;
|
33 |
b7b99774
|
Patric Plitzner
|
|
34 |
3be6ef3e
|
n.hoffmann
|
/**
|
35 |
|
|
* <p>Constructor for LineSelection.</p>
|
36 |
|
|
*
|
37 |
|
|
* @param selection a {@link org.eclipse.jface.text.ITextSelection} object.
|
38 |
|
|
* @param document a {@link org.eclipse.jface.text.IDocument} object.
|
39 |
|
|
* @param selectedObject a {@link java.lang.Object} object.
|
40 |
|
|
*/
|
41 |
|
|
public LineSelection(ITextSelection selection, IDocument document, Object selectedObject) {
|
42 |
|
|
super(document, selection.getOffset(), selection.getLength());
|
43 |
|
|
if (selectedObject != null) {
|
44 |
|
|
this.structuredSelection = new StructuredSelection(selectedObject);
|
45 |
|
|
} else {
|
46 |
|
|
this.structuredSelection = StructuredSelection.EMPTY;
|
47 |
|
|
}
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
/* (non-Javadoc)
|
51 |
|
|
* @see org.eclipse.jface.viewers.IStructuredSelection#getFirstElement()
|
52 |
|
|
*/
|
53 |
|
|
/**
|
54 |
|
|
* <p>getFirstElement</p>
|
55 |
|
|
*
|
56 |
|
|
* @return a {@link java.lang.Object} object.
|
57 |
|
|
*/
|
58 |
b7b99774
|
Patric Plitzner
|
@Override
|
59 |
|
|
public Object getFirstElement() {
|
60 |
3be6ef3e
|
n.hoffmann
|
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 |
b7b99774
|
Patric Plitzner
|
@Override
|
72 |
|
|
public Iterator<?> iterator() {
|
73 |
3be6ef3e
|
n.hoffmann
|
return structuredSelection.iterator();
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
/* (non-Javadoc)
|
77 |
|
|
* @see org.eclipse.jface.viewers.IStructuredSelection#size()
|
78 |
|
|
*/
|
79 |
|
|
/**
|
80 |
|
|
* <p>size</p>
|
81 |
|
|
*
|
82 |
|
|
* @return a int.
|
83 |
|
|
*/
|
84 |
b7b99774
|
Patric Plitzner
|
@Override
|
85 |
|
|
public int size() {
|
86 |
3be6ef3e
|
n.hoffmann
|
return structuredSelection.size();
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
/* (non-Javadoc)
|
90 |
|
|
* @see org.eclipse.jface.viewers.IStructuredSelection#toArray()
|
91 |
|
|
*/
|
92 |
|
|
/**
|
93 |
|
|
* <p>toArray</p>
|
94 |
|
|
*
|
95 |
|
|
* @return an array of {@link java.lang.Object} objects.
|
96 |
|
|
*/
|
97 |
b7b99774
|
Patric Plitzner
|
@Override
|
98 |
|
|
public Object[] toArray() {
|
99 |
3be6ef3e
|
n.hoffmann
|
return structuredSelection.toArray();
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
/* (non-Javadoc)
|
103 |
|
|
* @see org.eclipse.jface.viewers.IStructuredSelection#toList()
|
104 |
|
|
*/
|
105 |
|
|
/**
|
106 |
|
|
* <p>toList</p>
|
107 |
|
|
*
|
108 |
|
|
* @return a {@link java.util.List} object.
|
109 |
|
|
*/
|
110 |
b7b99774
|
Patric Plitzner
|
@Override
|
111 |
|
|
public List<?> toList() {
|
112 |
3be6ef3e
|
n.hoffmann
|
return structuredSelection.toList();
|
113 |
|
|
}
|
114 |
|
|
}
|