Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
df0b8ff4 BH |
2 | * Copyright (c) 2005, 2008 IBM Corporation and others. |
3 | * Copyright (c) 2011, 2012 Ericsson. | |
73005152 BH |
4 | * All rights reserved. This program and the accompanying materials |
5 | * are made available under the terms of the Eclipse Public License v1.0 | |
6 | * which accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
73005152 BH |
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; | |
eb63f5ff | 16 | import java.util.List; |
73005152 BH |
17 | |
18 | import org.eclipse.jface.viewers.ISelection; | |
19 | import org.eclipse.jface.viewers.ISelectionChangedListener; | |
20 | import org.eclipse.jface.viewers.ISelectionProvider; | |
21 | import org.eclipse.jface.viewers.SelectionChangedEvent; | |
22 | ||
23 | /** | |
df0b8ff4 BH |
24 | * <p> |
25 | * Informs all registered listeners of graph node selection change in the Frame. | |
26 | * </p> | |
73005152 | 27 | * |
df0b8ff4 | 28 | * @version 1.0 |
73005152 BH |
29 | * @author sveyrier |
30 | * | |
31 | */ | |
32 | public class SDWidgetSelectionProvider implements ISelectionProvider { | |
33 | ||
df0b8ff4 BH |
34 | // ------------------------------------------------------------------------ |
35 | // Attributes | |
36 | // ------------------------------------------------------------------------ | |
37 | ||
73005152 BH |
38 | /** |
39 | * The listener list | |
40 | */ | |
eb63f5ff | 41 | protected List<ISelectionChangedListener> fListenerList = null; |
73005152 BH |
42 | /** |
43 | * The current selection | |
44 | */ | |
eb63f5ff | 45 | protected ISelection fCurrentSelection = null; |
73005152 | 46 | |
df0b8ff4 BH |
47 | // ------------------------------------------------------------------------ |
48 | // Constructor | |
49 | // ------------------------------------------------------------------------ | |
50 | /** | |
51 | * Standard constructor | |
52 | */ | |
73005152 | 53 | protected SDWidgetSelectionProvider() { |
eb63f5ff | 54 | fListenerList = new ArrayList<ISelectionChangedListener>(); |
73005152 BH |
55 | } |
56 | ||
df0b8ff4 BH |
57 | // ------------------------------------------------------------------------ |
58 | // Methods | |
59 | // ------------------------------------------------------------------------ | |
60 | ||
61 | /* | |
62 | * (non-Javadoc) | |
63 | * @see org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) | |
73005152 BH |
64 | */ |
65 | @Override | |
66 | public void addSelectionChangedListener(ISelectionChangedListener listener) { | |
eb63f5ff BH |
67 | if (!fListenerList.contains(listener)) |
68 | fListenerList.add(listener); | |
73005152 BH |
69 | } |
70 | ||
df0b8ff4 BH |
71 | /* |
72 | * (non-Javadoc) | |
73 | * @see org.eclipse.jface.viewers.ISelectionProvider#removeSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) | |
73005152 BH |
74 | */ |
75 | @Override | |
76 | public void removeSelectionChangedListener(ISelectionChangedListener listener) { | |
eb63f5ff | 77 | fListenerList.remove(listener); |
73005152 BH |
78 | } |
79 | ||
df0b8ff4 BH |
80 | /* |
81 | * (non-Javadoc) | |
82 | * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection) | |
73005152 BH |
83 | */ |
84 | @Override | |
85 | public void setSelection(ISelection selection) { | |
eb63f5ff BH |
86 | fCurrentSelection = selection; |
87 | for (int i = 0; i < fListenerList.size(); i++) { | |
88 | ISelectionChangedListener list = (ISelectionChangedListener) fListenerList.get(i); | |
89 | list.selectionChanged(new SelectionChangedEvent(this, fCurrentSelection)); | |
73005152 BH |
90 | } |
91 | } | |
92 | ||
df0b8ff4 BH |
93 | /* |
94 | * (non-Javadoc) | |
95 | * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection() | |
73005152 BH |
96 | */ |
97 | @Override | |
98 | public ISelection getSelection() { | |
eb63f5ff | 99 | return fCurrentSelection; |
73005152 BH |
100 | } |
101 | ||
102 | } |