Contribution for Bug352466: [TMF] Implement UML2 Sequence Diagram
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / SDWidgetSelectionProvider.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2008, 2011 IBM Corporation and others.
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 * $Id: SDWidgetSelectionProvider.java,v 1.3 2008/01/24 02:29:01 apnan Exp $
8 *
9 * Contributors:
10 * IBM - Initial API and implementation
11 * Bernd Hufmann - Updated for TMF
12 **********************************************************************/
13 package org.eclipse.linuxtools.tmf.ui.views.uml2sd;
14
15 import java.util.ArrayList;
16
17 import org.eclipse.jface.viewers.ISelection;
18 import org.eclipse.jface.viewers.ISelectionChangedListener;
19 import org.eclipse.jface.viewers.ISelectionProvider;
20 import org.eclipse.jface.viewers.SelectionChangedEvent;
21
22 /**
23 * Informs all registered listeners of graph node selection change in the Frame
24 *
25 * @author sveyrier
26 *
27 */
28 public class SDWidgetSelectionProvider implements ISelectionProvider {
29
30 /**
31 * The listener list
32 */
33 protected ArrayList<ISelectionChangedListener> listenerList = null;
34
35 /**
36 * The current selection
37 */
38 protected ISelection currentSelection = null;
39
40 protected SDWidgetSelectionProvider() {
41 listenerList = new ArrayList<ISelectionChangedListener>();
42 }
43
44 /**
45 * Adds the given listener from the selection change listener list
46 *
47 * @param listener the listener to add
48 */
49 @Override
50 public void addSelectionChangedListener(ISelectionChangedListener listener) {
51 if (!listenerList.contains(listener))
52 listenerList.add(listener);
53 }
54
55 /**
56 * Removes the given listener from the selection change listener list
57 *
58 * @param listener the listener to remove
59 */
60 @Override
61 public void removeSelectionChangedListener(ISelectionChangedListener listener) {
62 listenerList.remove(listener);
63 }
64
65 /**
66 * Changes the selection to the given selection and inform all listener
67 *
68 * @param selection the new current selection
69 */
70 @Override
71 public void setSelection(ISelection selection) {
72 currentSelection = selection;
73 for (int i = 0; i < listenerList.size(); i++) {
74 ISelectionChangedListener list = (ISelectionChangedListener) listenerList.get(i);
75 list.selectionChanged(new SelectionChangedEvent(this, currentSelection));
76 }
77 }
78
79 /**
80 * Returns the current selection
81 *
82 * @return the current selection
83 */
84 @Override
85 public ISelection getSelection() {
86 return currentSelection;
87 }
88
89 }
This page took 0.031516 seconds and 5 git commands to generate.