KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.SafeRunner;
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  * MarkerSelectionProviderAdapter adapts the concrete markers
25  * to IMarkers for contributions.
26  */

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