added checks to makes sure no other exception is thrown within the dialog creation...
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / model / LineSelection.java
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 @Override
60 public Object getFirstElement() {
61 return structuredSelection.getFirstElement();
62 }
63
64 /* (non-Javadoc)
65 * @see org.eclipse.jface.viewers.IStructuredSelection#iterator()
66 */
67 /**
68 * <p>iterator</p>
69 *
70 * @return a {@link java.util.Iterator} object.
71 */
72 @Override
73 public Iterator<?> iterator() {
74 return structuredSelection.iterator();
75 }
76
77 /* (non-Javadoc)
78 * @see org.eclipse.jface.viewers.IStructuredSelection#size()
79 */
80 /**
81 * <p>size</p>
82 *
83 * @return a int.
84 */
85 @Override
86 public int size() {
87 return structuredSelection.size();
88 }
89
90 /* (non-Javadoc)
91 * @see org.eclipse.jface.viewers.IStructuredSelection#toArray()
92 */
93 /**
94 * <p>toArray</p>
95 *
96 * @return an array of {@link java.lang.Object} objects.
97 */
98 @Override
99 public Object[] toArray() {
100 return structuredSelection.toArray();
101 }
102
103 /* (non-Javadoc)
104 * @see org.eclipse.jface.viewers.IStructuredSelection#toList()
105 */
106 /**
107 * <p>toList</p>
108 *
109 * @return a {@link java.util.List} object.
110 */
111 @Override
112 public List<?> toList() {
113 return structuredSelection.toList();
114 }
115 }