1
/*****************************************************************
2
* Copyright (c) 2010, 2011 Texas Instruments 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
9
* Patrick Chuong (Texas Instruments) - Pin and Clone Supports (331781)
10
* Patrick Chuong (Texas Instruments) - Add support for icon overlay in the debug view (Bug 334566)
11
*****************************************************************/
12
package org.eclipse.cdt.debug.internal.ui.pinclone;
14
import java.util.HashMap;
15
import java.util.HashSet;
17
import java.util.Map.Entry;
20
import org.eclipse.cdt.debug.ui.IPinProvider;
21
import org.eclipse.cdt.debug.ui.IPinProvider.IPinElementHandle;
22
import org.eclipse.cdt.debug.ui.IPinProvider.IPinModelListener;
23
import org.eclipse.cdt.debug.ui.PinElementHandle;
24
import org.eclipse.core.runtime.IAdaptable;
25
import org.eclipse.debug.ui.contexts.AbstractDebugContextProvider;
26
import org.eclipse.debug.ui.contexts.DebugContextEvent;
27
import org.eclipse.debug.ui.contexts.IDebugContextProvider2;
28
import org.eclipse.jface.viewers.ISelection;
29
import org.eclipse.jface.viewers.IStructuredSelection;
30
import org.eclipse.jface.viewers.StructuredSelection;
31
import org.eclipse.swt.widgets.Display;
32
import org.eclipse.ui.IWorkbenchPart;
35
* Pin debug context provider.
36
* It takes a debug context and translates it to a handle for pinning purpose.
38
public class DebugContextPinProvider extends AbstractDebugContextProvider implements IDebugContextProvider2 {
39
private ISelection fActiveContext;
40
private final Set<IPinElementHandle> fPinHandles;
41
private final IWorkbenchPart fWorkbenchPart;
42
private final Map<IPinElementHandle, IPinProvider> fPinProvider;
47
* @param part the workbench part of where the pin action takes place
48
* @param activeContext the debug context selection
50
public DebugContextPinProvider(IWorkbenchPart part, ISelection activeContext) {
52
fWorkbenchPart = part;
53
fPinProvider = new HashMap<IPinElementHandle, IPinProvider>();
55
fActiveContext = activeContext;
56
fPinHandles = pin(part, activeContext, new IPinModelListener() {
57
public void modelChanged(ISelection selection) {
58
// send a change notification for the view to update
59
delegateEvent(new DebugContextEvent(DebugContextPinProvider.this,
60
selection == null ? new StructuredSelection() : selection,
61
DebugContextEvent.ACTIVATED));
67
* Dispose the provider.
69
public void dispose() {
70
for (Entry<IPinElementHandle, IPinProvider> entry : fPinProvider.entrySet()) {
71
entry.getValue().unpin(fWorkbenchPart, entry.getKey());
77
* @see org.eclipse.debug.ui.contexts.IDebugContextProvider2#isWindowContextProvider()
79
public boolean isWindowContextProvider() {
85
* @see org.eclipse.debug.ui.contexts.IDebugContextProvider#getActiveContext()
87
public ISelection getActiveContext() {
88
return fActiveContext;
92
* Returns the pinned debug context handles.
94
* @return the handle set
96
public Set<IPinElementHandle> getPinHandles() {
101
* Returns whether the current pinned handles are pinned to the given debug context.
103
* @param debugContext the debug context in question
104
* @return true if the pinned handles are pinned to the debug context
106
public boolean isPinnedTo(Object debugContext) {
107
return PinCloneUtils.isPinnedTo(fPinHandles, debugContext);
111
* Pin the given debug context selection.
113
* @param part the workbench part where the pin action is requested
114
* @param selection the debug context selection
115
* @param listener pin model listener
116
* @return a set of pinned handle
118
Set<IPinElementHandle> handles = new HashSet<IPinElementHandle>();
119
private Set<IPinElementHandle> pin(IWorkbenchPart part, ISelection selection, IPinModelListener listener) {
121
if (selection instanceof IStructuredSelection) {
122
for (Object element : ((IStructuredSelection)selection).toList()) {
123
IPinProvider pinProvider = null;
124
if (element instanceof IAdaptable) {
125
pinProvider = (IPinProvider) ((IAdaptable)element).getAdapter(IPinProvider.class);
128
if (pinProvider != null) {
129
IPinElementHandle handle = pinProvider.pin(fWorkbenchPart, element, listener);
131
fPinProvider.put(handle, pinProvider);
133
handles.add(new PinElementHandle(element, null, PinCloneUtils.getDefaultPinElementColorDescriptor()));
141
* Delegates debug event to the listener.
143
* @param event debug event
145
public void delegateEvent(final DebugContextEvent event) {
146
Display.getDefault().syncExec(new Runnable() {
148
fActiveContext = event.getContext();