Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 020999fbc018980e9b5df9b3908936d0bcde4600 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*******************************************************************************
 * Copyright (c) 2012 Tilera Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     William R. Swanson (Tilera Corporation)
 *******************************************************************************/

package org.eclipse.cdt.visualizer.ui.util;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;

// ---------------------------------------------------------------------------
// SelectionProviderAdapter
// ---------------------------------------------------------------------------

/**
 * Wrapper for selection "providers" that don't happen to implement
 * ISelectionProvider interface.
 */
public class SelectionProviderAdapter implements ISelectionProvider {
	// --- members ---

	/** Real source object. */
	protected Object m_source = null;

	/** Selection manager. */
	protected SelectionManager m_selectionManager = null;

	// --- constructors/destructors ---

	/** Constructor. */
	public SelectionProviderAdapter(Object source) {
		m_source = source;
		m_selectionManager = new SelectionManager(this, "SelectionProviderAdapter for source " + m_source.toString());
	}

	/** Dispose method. */
	public void dispose() {
		m_source = null;
		if (m_selectionManager != null) {
			m_selectionManager.dispose();
			m_selectionManager = null;
		}
	}

	// --- accessors ---

	/** Gets wrapped selection source. */
	public Object getActualSource() {
		return m_source;
	}

	// --- ISelectionProvider implementation ---

	/** Adds selection change listener.
	 *  Default implementation does nothing.
	 */
	public void addSelectionChangedListener(ISelectionChangedListener listener) {
		m_selectionManager.addSelectionChangedListener(listener);
	}

	/** Removes selection change listener.
	 *  Default implementation does nothing.
	 */
	public void removeSelectionChangedListener(ISelectionChangedListener listener) {
		m_selectionManager.removeSelectionChangedListener(listener);
	}

	/** Gets selection.
	 *  Default implementation does nothing.
	 */
	public ISelection getSelection() {
		return m_selectionManager.getSelection();
	}

	/** Sets selection.
	 *  Default implementation does nothing.
	 */
	public void setSelection(ISelection selection) {
		m_selectionManager.setSelection(selection);
	}
}

Back to the top