KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > memory > ViewPaneSelectionProvider


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 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  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11  
12 package org.eclipse.debug.internal.ui.views.memory;
13
14 import java.util.ArrayList JavaDoc;
15
16 import org.eclipse.jface.viewers.ISelection;
17 import org.eclipse.jface.viewers.ISelectionChangedListener;
18 import org.eclipse.jface.viewers.ISelectionProvider;
19 import org.eclipse.jface.viewers.SelectionChangedEvent;
20
21
22 /**
23  * Handles selection changes in a rendering view pane.
24  * @since 3.1
25  *
26  */

27 public class ViewPaneSelectionProvider implements ISelectionProvider
28 {
29     ArrayList JavaDoc fListeners = new ArrayList JavaDoc();
30     ISelection fSelection;
31
32     /* (non-Javadoc)
33      * @see org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
34      */

35     public void addSelectionChangedListener(ISelectionChangedListener listener)
36     {
37         if (!fListeners.contains(listener))
38             fListeners.add(listener);
39         
40     }
41
42     /* (non-Javadoc)
43      * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection()
44      */

45     public ISelection getSelection()
46     {
47         return fSelection;
48     }
49
50     /* (non-Javadoc)
51      * @see org.eclipse.jface.viewers.ISelectionProvider#removeSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
52      */

53     public void removeSelectionChangedListener(ISelectionChangedListener listener)
54     {
55         if (fListeners.contains(listener))
56             fListeners.remove(listener);
57         
58     }
59
60     /* (non-Javadoc)
61      * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)
62      */

63     public void setSelection(ISelection selection)
64     {
65         fSelection = selection;
66         fireChanged();
67     }
68     
69     public void fireChanged()
70     {
71         SelectionChangedEvent evt = new SelectionChangedEvent(this, getSelection());
72         for (int i=0; i<fListeners.size(); i++)
73         {
74             ((ISelectionChangedListener)fListeners.get(i)).selectionChanged(evt);
75         }
76     }
77 }
78
Popular Tags