KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > uka > ipd > coverage > plugin > ui > SelectionProviderAdapter


1 package de.uka.ipd.coverage.plugin.ui;
2
3 /*******************************************************************************
4  * Copyright (c) 2000, 2003 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Common Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/cpl-v10.html
9  *
10  * Contributors:
11  * IBM Corporation - initial API and implementation
12  *******************************************************************************/

13
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.core.runtime.Platform;
18 import org.eclipse.jface.util.SafeRunnable;
19 import org.eclipse.jface.viewers.*;
20
21 /**
22  *
23  */

24 class SelectionProviderAdapter implements ISelectionProvider {
25
26     List JavaDoc listeners = new ArrayList JavaDoc();
27     ISelection theSelection = null;
28         
29     public void addSelectionChangedListener(ISelectionChangedListener listener) {
30         listeners.add(listener);
31     }
32
33     public ISelection getSelection() {
34         return theSelection;
35     }
36
37     public void removeSelectionChangedListener(ISelectionChangedListener listener) {
38         listeners.remove(listener);
39     }
40
41     public void setSelection(ISelection selection) {
42         theSelection = selection;
43         final SelectionChangedEvent e = new SelectionChangedEvent(this, selection);
44         Object JavaDoc[] listenersArray = listeners.toArray();
45         
46         for (int i = 0; i < listenersArray.length; i++) {
47             final ISelectionChangedListener l = (ISelectionChangedListener) listenersArray[i];
48             Platform.run(new SafeRunnable() {
49                 public void run() {
50                     l.selectionChanged(e);
51                 }
52             });
53         }
54     }
55
56 }
57
Popular Tags