Merge branch 'master' into lttng-kepler
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / widgets / TimeGraphSelection.java
1 /*****************************************************************************
2 * Copyright (c) 2007 Intel Corporation, 2009, 2012 Ericsson.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Intel Corporation - Initial API and implementation
10 * Ruslan A. Scherbakov, Intel - Initial API and implementation
11 * Alvaro Sanchez-Leon - Updated for TMF
12 * Patrick Tasse - Refactoring
13 *
14 *****************************************************************************/
15
16 package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;
17
18 import java.util.ArrayList;
19 import java.util.Iterator;
20 import java.util.List;
21
22 import org.eclipse.jface.viewers.IStructuredSelection;
23
24 /**
25 * Selection object for the time graph scale
26 *
27 * @version 1.0
28 * @author Alvaro Sanchez-Leon
29 * @author Patrick Tasse
30 */
31 public class TimeGraphSelection implements IStructuredSelection {
32
33 List<Object> list = new ArrayList<Object>();
34
35 /**
36 * Default constructor
37 */
38 public TimeGraphSelection() {
39 }
40
41 /**
42 * "Wrapper" constructor. Instantiate a new selection object with only one
43 * existing selection.
44 *
45 * @param sel
46 * The initial selection to add to this one
47 */
48 public TimeGraphSelection(Object sel) {
49 add(sel);
50 }
51
52 /**
53 * Add a selection to this one.
54 *
55 * @param sel
56 * The selection to add
57 */
58 public void add(Object sel) {
59 if (null != sel && !list.contains(sel)) {
60 list.add(sel);
61 }
62 }
63
64 @Override
65 public Object getFirstElement() {
66 if (!list.isEmpty()) {
67 return list.get(0);
68 }
69 return null;
70 }
71
72 @Override
73 public Iterator<Object> iterator() {
74 return list.iterator();
75 }
76
77 @Override
78 public int size() {
79 return list.size();
80 }
81
82 @Override
83 public Object[] toArray() {
84 return list.toArray();
85 }
86
87 @Override
88 public List<Object> toList() {
89 return list;
90 }
91
92 @Override
93 public boolean isEmpty() {
94 return list.isEmpty();
95 }
96 }
This page took 0.041696 seconds and 5 git commands to generate.