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 | |
013a5f1c AM |
8 | * |
9 | * Contributors: | |
73005152 BH |
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> | |
013a5f1c AM |
27 | * |
28 | * @version 1.0 | |
73005152 | 29 | * @author sveyrier |
73005152 BH |
30 | */ |
31 | public class SDWidgetSelectionProvider implements ISelectionProvider { | |
32 | ||
df0b8ff4 BH |
33 | // ------------------------------------------------------------------------ |
34 | // Attributes | |
35 | // ------------------------------------------------------------------------ | |
36 | ||
73005152 BH |
37 | /** |
38 | * The listener list | |
39 | */ | |
eb63f5ff | 40 | protected List<ISelectionChangedListener> fListenerList = null; |
73005152 BH |
41 | /** |
42 | * The current selection | |
43 | */ | |
eb63f5ff | 44 | protected ISelection fCurrentSelection = null; |
73005152 | 45 | |
df0b8ff4 BH |
46 | // ------------------------------------------------------------------------ |
47 | // Constructor | |
48 | // ------------------------------------------------------------------------ | |
49 | /** | |
50 | * Standard constructor | |
51 | */ | |
73005152 | 52 | protected SDWidgetSelectionProvider() { |
eb63f5ff | 53 | fListenerList = new ArrayList<ISelectionChangedListener>(); |
73005152 BH |
54 | } |
55 | ||
df0b8ff4 BH |
56 | // ------------------------------------------------------------------------ |
57 | // Methods | |
58 | // ------------------------------------------------------------------------ | |
59 | ||
60 | /* | |
61 | * (non-Javadoc) | |
62 | * @see org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) | |
73005152 BH |
63 | */ |
64 | @Override | |
65 | public void addSelectionChangedListener(ISelectionChangedListener listener) { | |
013a5f1c | 66 | if (!fListenerList.contains(listener)) { |
eb63f5ff | 67 | fListenerList.add(listener); |
013a5f1c | 68 | } |
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 | } |