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 $
10 * IBM - Initial API and implementation
11 * Bernd Hufmann - Updated for TMF
12 **********************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
;
15 import java
.util
.ArrayList
;
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
;
23 * Informs all registered listeners of graph node selection change in the Frame
28 public class SDWidgetSelectionProvider
implements ISelectionProvider
{
33 protected ArrayList
<ISelectionChangedListener
> listenerList
= null;
36 * The current selection
38 protected ISelection currentSelection
= null;
40 protected SDWidgetSelectionProvider() {
41 listenerList
= new ArrayList
<ISelectionChangedListener
>();
45 * Adds the given listener from the selection change listener list
47 * @param listener the listener to add
50 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
51 if (!listenerList
.contains(listener
))
52 listenerList
.add(listener
);
56 * Removes the given listener from the selection change listener list
58 * @param listener the listener to remove
61 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
62 listenerList
.remove(listener
);
66 * Changes the selection to the given selection and inform all listener
68 * @param selection the new current selection
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
));
80 * Returns the current selection
82 * @return the current selection
85 public ISelection
getSelection() {
86 return currentSelection
;