KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > markers > internal > SelectionProviderAdapter


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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 package org.eclipse.ui.views.markers.internal;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.runtime.Platform;
17 import org.eclipse.jface.util.SafeRunnable;
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  *
25  */

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