| 1 | /********************************************************************** |
| 2 | * Copyright (c) 2005, 2012 IBM 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 | * IBM - Initial API and implementation |
| 10 | * Bernd Hufmann - Updated for TMF |
| 11 | **********************************************************************/ |
| 12 | |
| 13 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd; |
| 14 | |
| 15 | import java.util.ArrayList; |
| 16 | import java.util.List; |
| 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 | /** |
| 24 | * <p> |
| 25 | * Informs all registered listeners of graph node selection change in the Frame. |
| 26 | * </p> |
| 27 | * |
| 28 | * @version 1.0 |
| 29 | * @author sveyrier |
| 30 | */ |
| 31 | public class SDWidgetSelectionProvider implements ISelectionProvider { |
| 32 | |
| 33 | // ------------------------------------------------------------------------ |
| 34 | // Attributes |
| 35 | // ------------------------------------------------------------------------ |
| 36 | |
| 37 | /** |
| 38 | * The listener list |
| 39 | */ |
| 40 | protected List<ISelectionChangedListener> fListenerList = null; |
| 41 | /** |
| 42 | * The current selection |
| 43 | */ |
| 44 | protected ISelection fCurrentSelection = null; |
| 45 | |
| 46 | // ------------------------------------------------------------------------ |
| 47 | // Constructor |
| 48 | // ------------------------------------------------------------------------ |
| 49 | /** |
| 50 | * Standard constructor |
| 51 | */ |
| 52 | protected SDWidgetSelectionProvider() { |
| 53 | fListenerList = new ArrayList<ISelectionChangedListener>(); |
| 54 | } |
| 55 | |
| 56 | // ------------------------------------------------------------------------ |
| 57 | // Methods |
| 58 | // ------------------------------------------------------------------------ |
| 59 | |
| 60 | /* |
| 61 | * (non-Javadoc) |
| 62 | * @see org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) |
| 63 | */ |
| 64 | @Override |
| 65 | public void addSelectionChangedListener(ISelectionChangedListener listener) { |
| 66 | if (!fListenerList.contains(listener)) { |
| 67 | fListenerList.add(listener); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | /* |
| 72 | * (non-Javadoc) |
| 73 | * @see org.eclipse.jface.viewers.ISelectionProvider#removeSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) |
| 74 | */ |
| 75 | @Override |
| 76 | public void removeSelectionChangedListener(ISelectionChangedListener listener) { |
| 77 | fListenerList.remove(listener); |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | * (non-Javadoc) |
| 82 | * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection) |
| 83 | */ |
| 84 | @Override |
| 85 | public void setSelection(ISelection selection) { |
| 86 | fCurrentSelection = selection; |
| 87 | for (int i = 0; i < fListenerList.size(); i++) { |
| 88 | ISelectionChangedListener list = fListenerList.get(i); |
| 89 | list.selectionChanged(new SelectionChangedEvent(this, fCurrentSelection)); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | /* |
| 94 | * (non-Javadoc) |
| 95 | * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection() |
| 96 | */ |
| 97 | @Override |
| 98 | public ISelection getSelection() { |
| 99 | return fCurrentSelection; |
| 100 | } |
| 101 | |
| 102 | } |