355f0e1afeb8e4f81d9c8bf9658348ce3d0e1eeb
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / widgets / TimeGraphSelection.java
1 /*****************************************************************************
2 * Copyright (c) 2007, 2013 Intel Corporation, 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 package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;
16
17 import java.util.ArrayList;
18 import java.util.Iterator;
19 import java.util.List;
20
21 import org.eclipse.jface.viewers.IStructuredSelection;
22
23 /**
24 * Selection object for the time graph scale
25 *
26 * @version 1.0
27 * @author Alvaro Sanchez-Leon
28 * @author Patrick Tasse
29 */
30 public class TimeGraphSelection implements IStructuredSelection {
31
32 private List<Object> list = new ArrayList<>();
33
34 /**
35 * Default constructor
36 */
37 public TimeGraphSelection() {
38 }
39
40 /**
41 * "Wrapper" constructor. Instantiate a new selection object with only one
42 * existing selection.
43 *
44 * @param sel
45 * The initial selection to add to this one
46 */
47 public TimeGraphSelection(Object sel) {
48 if (sel != null) {
49 list.add(sel);
50 }
51 }
52
53 /**
54 * Add a selection to this one.
55 *
56 * @param sel
57 * The selection to add
58 */
59 public void add(Object sel) {
60 if (null != sel && !list.contains(sel)) {
61 list.add(sel);
62 }
63 }
64
65 @Override
66 public Object getFirstElement() {
67 if (!list.isEmpty()) {
68 return list.get(0);
69 }
70 return null;
71 }
72
73 @Override
74 public Iterator<Object> iterator() {
75 return list.iterator();
76 }
77
78 @Override
79 public int size() {
80 return list.size();
81 }
82
83 @Override
84 public Object[] toArray() {
85 return list.toArray();
86 }
87
88 @Override
89 public List<Object> toList() {
90 return list;
91 }
92
93 @Override
94 public boolean isEmpty() {
95 return list.isEmpty();
96 }
97 }
This page took 0.037836 seconds and 4 git commands to generate.