01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.part;
11:
12: import java.util.ArrayList;
13: import java.util.List;
14:
15: import org.eclipse.core.runtime.Platform;
16: import org.eclipse.jface.util.SafeRunnable;
17: import org.eclipse.jface.viewers.ISelection;
18: import org.eclipse.jface.viewers.ISelectionChangedListener;
19: import org.eclipse.jface.viewers.ISelectionProvider;
20: import org.eclipse.jface.viewers.SelectionChangedEvent;
21: import org.eclipse.jface.viewers.StructuredSelection;
22:
23: /**
24: *
25: */
26: class SelectionProviderAdapter implements ISelectionProvider {
27:
28: List listeners = new ArrayList();
29:
30: ISelection theSelection = StructuredSelection.EMPTY;
31:
32: public void addSelectionChangedListener(
33: 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 ,
49: selection);
50: Object[] listenersArray = listeners.toArray();
51:
52: for (int i = 0; i < listenersArray.length; i++) {
53: final ISelectionChangedListener l = (ISelectionChangedListener) listenersArray[i];
54: Platform.run(new SafeRunnable() {
55: public void run() {
56: l.selectionChanged(e);
57: }
58: });
59: }
60: }
61:
62: }
|