Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a5d0c705a91fdf36017533316e24e0b9899dae9f (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
/*******************************************************************************
 * Copyright (c) 2006, 2014 Wind River Systems 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:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.examples.dsf.pda.ui;

import org.eclipse.cdt.dsf.concurrent.ThreadSafe;
import org.eclipse.cdt.dsf.service.DsfSession;
import org.eclipse.cdt.examples.dsf.pda.launch.PDALaunch;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxyFactory;
import org.eclipse.debug.ui.contexts.ISuspendTrigger;

/**
 * The adapter factory is the central point of control of view model and other
 * UI adapters of a DSF-based debugger.  As new launches are created and
 * old ones removed, this factory manages the life cycle of the associated
 * UI adapters.
 * <p>
 * As a platform adapter factory, this factory only  provides adapters for
 * the launch object.  Adapters for all other objects in the DSF model hierarchy
 * are registered with the DSF session.
 * </p>
 */
@ThreadSafe
@SuppressWarnings({ "restriction" })
public class PDAAdapterFactory implements IAdapterFactory {
	// This IAdapterFactory method returns adapters for the PDA launch object only.
	@Override
	@SuppressWarnings("unchecked") // IAdapterFactory is Java 1.3
	public Object getAdapter(Object adaptableObject, Class adapterType) {
		if (!(adaptableObject instanceof PDALaunch))
			return null;

		PDALaunch launch = (PDALaunch) adaptableObject;

		// Check for valid session.
		// Note: even if the session is no longer active, the adapter set
		// should still be returned.  This is because the view model may still
		// need to show elements representing a terminated process/thread/etc.
		DsfSession session = launch.getSession();
		if (session == null)
			return null;

		SessionAdapterSet adapterSet = PDAUIPlugin.getDefault().getAdapterSet(launch);
		if (adapterSet == null)
			return null;

		// Returns the adapter type for the launch object.
		if (adapterType.equals(IElementContentProvider.class))
			return adapterSet.fViewModelAdapter;
		else if (adapterType.equals(IModelProxyFactory.class))
			return adapterSet.fViewModelAdapter;
		else if (adapterType.equals(ISuspendTrigger.class))
			return adapterSet.fSuspendTrigger;
		else
			return null;
	}

	@Override
	@SuppressWarnings("unchecked") // IAdapterFactory is Java 1.3
	public Class[] getAdapterList() {
		return new Class[] { IElementContentProvider.class, IModelProxyFactory.class, ISuspendTrigger.class };
	}

}

Back to the top