diff options
author | Patrick Chuong | 2011-02-15 21:12:12 +0000 |
---|---|---|
committer | Patrick Chuong | 2011-02-15 21:12:12 +0000 |
commit | 480ee167c86d33bfd89a887b10c027949772c4fe (patch) | |
tree | dc0e7de7cd34a6a13021a78ace2b75ceffad433d /debug/org.eclipse.cdt.debug.ui/src/org | |
parent | 878d101d1889f3efe5623fb875ded2dfb87b7a84 (diff) | |
download | org.eclipse.cdt-480ee167c86d33bfd89a887b10c027949772c4fe.tar.gz org.eclipse.cdt-480ee167c86d33bfd89a887b10c027949772c4fe.tar.xz org.eclipse.cdt-480ee167c86d33bfd89a887b10c027949772c4fe.zip |
Bug 334566 - [multicore][Pin&Clone] Add support for icon overlay in the debug view
Diffstat (limited to 'debug/org.eclipse.cdt.debug.ui/src/org')
5 files changed, 262 insertions, 50 deletions
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/PinDebugContextActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/PinDebugContextActionDelegate.java index 7adbb600e3a..0a000dee4c7 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/PinDebugContextActionDelegate.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/PinDebugContextActionDelegate.java @@ -7,23 +7,27 @@ * * Contributors: * Patrick Chuong (Texas Instruments) - Pin and Clone Supports (331781) + * Patrick Chuong (Texas Instruments) - Add support for icon overlay in the debug view (Bug 334566) *****************************************************************/ package org.eclipse.cdt.debug.internal.ui.actions; import java.util.HashSet; +import java.util.Iterator; import java.util.Set; import org.eclipse.cdt.debug.internal.ui.pinclone.DebugContextPinProvider; import org.eclipse.cdt.debug.internal.ui.pinclone.DebugEventFilterService; import org.eclipse.cdt.debug.internal.ui.pinclone.PinCloneUtils; +import org.eclipse.cdt.debug.ui.IPinProvider; +import org.eclipse.cdt.debug.ui.IPinProvider.IPinElementColorDescriptor; import org.eclipse.cdt.debug.ui.IPinProvider.IPinElementHandle; -import org.eclipse.cdt.debug.ui.IPinProvider.IPinHandleLabelProvider; -import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.cdt.ui.CDTSharedImages; import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.contexts.DebugContextEvent; import org.eclipse.debug.ui.contexts.IDebugContextListener; import org.eclipse.debug.ui.contexts.IDebugContextService; import org.eclipse.jface.action.IAction; +import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.widgets.Event; import org.eclipse.ui.IActionDelegate2; @@ -40,12 +44,13 @@ import org.eclipse.ui.PlatformUI; * Pin the selected debug context for the view. */ public class PinDebugContextActionDelegate implements IViewActionDelegate, IActionDelegate2, IDebugContextListener { - IViewPart fPart; - IAction fAction; - IPartListener2 fPartListener; - DebugContextPinProvider fProvider; + private IViewPart fPart; + private IAction fAction; + private IPartListener2 fPartListener; + private DebugContextPinProvider fProvider; - public PinDebugContextActionDelegate() {} + public PinDebugContextActionDelegate() { + } /* (non-Javadoc) * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event) @@ -61,13 +66,13 @@ public class PinDebugContextActionDelegate implements IViewActionDelegate, IActi if (action.isChecked()) { fProvider = DebugEventFilterService.getInstance().addDebugEventFilter(fPart, getActiveDebugContext()); if (fProvider != null) { - // TODO: set image descriptor + updatePinContextColor(fProvider); updatePinContextLabel(fProvider); } } else { fProvider = null; DebugEventFilterService.getInstance().removeDebugEventFilter(fPart); - // TODO: remove image descriptor + updatePinContextColor(fProvider); updatePinContextLabel(fProvider); } } @@ -152,8 +157,7 @@ public class PinDebugContextActionDelegate implements IViewActionDelegate, IActi if (provider != null) { Set<String> labels = new HashSet<String>(); - Set<IPinElementHandle> handles = provider.getPinHandles(); - for (IPinElementHandle handle : handles) { + for (IPinElementHandle handle : provider.getPinHandles()) { String tmp = getLabel(handle); if (tmp != null && tmp.trim().length() != 0) labels.add(tmp); @@ -162,7 +166,7 @@ public class PinDebugContextActionDelegate implements IViewActionDelegate, IActi for (String label : labels) { if (label != null) { if (description.length() > 0) { - description += "," + label; //$NON-NLS-1$ + description += ", " + label; //$NON-NLS-1$ } else { description = label; } @@ -176,16 +180,77 @@ public class PinDebugContextActionDelegate implements IViewActionDelegate, IActi private String getLabel(IPinElementHandle handle) { String label = ""; //$NON-NLS-1$ - if (handle instanceof IAdaptable) { - IPinHandleLabelProvider provider = - (IPinHandleLabelProvider) ((IAdaptable) handle).getAdapter(IPinHandleLabelProvider.class); - if (provider != null) - label = provider.getLabel(); - } + if (handle != null) + label = handle.getLabel(); return label; } + private boolean useMultiPinImage(Set<IPinElementHandle> handles) { + if (handles.size() <= 1) return false; + + int overlayColor = IPinElementColorDescriptor.UNDEFINED; + ImageDescriptor imageDesc = null; + for (IPinElementHandle handle : handles) { + IPinElementColorDescriptor colorDesc = handle.getPinElementColorDescriptor(); + if (colorDesc != null) { + ImageDescriptor descImageDesc = colorDesc.getToolbarIconDescriptor(); + if (imageDesc != null && !imageDesc.equals(descImageDesc)) + return true; + imageDesc = descImageDesc; + + int descOverlayColor = colorDesc.getOverlayColor(); + if (overlayColor != IPinElementColorDescriptor.UNDEFINED && descOverlayColor != overlayColor) + return true; + overlayColor = descOverlayColor; + } + } + + return false; + } + + private void updatePinContextColor(DebugContextPinProvider provider) { + ImageDescriptor imageDesc = null; + if (provider != null) { + Set<IPinElementHandle> handles = provider.getPinHandles(); + + // if handles have different toolbar icon descriptor or different pin color, than use a + // multi-pin toolbar icon + if (useMultiPinImage(handles)) + imageDesc = CDTSharedImages.getImageDescriptor(CDTSharedImages.IMG_VIEW_PIN_ACTION_MULTI); + + if (imageDesc == null) { + Iterator<IPinElementHandle> itr = handles.iterator(); + if (itr.hasNext()) { + IPinElementHandle handle = itr.next(); + IPinElementColorDescriptor desc = handle.getPinElementColorDescriptor(); + if (desc != null) + imageDesc = desc.getToolbarIconDescriptor(); + + if (imageDesc == null && desc != null) { + int overlayColor = desc.getOverlayColor() % IPinElementColorDescriptor.DEFAULT_COLOR_COUNT; + + switch (overlayColor) { + case IPinProvider.IPinElementColorDescriptor.GREEN: + imageDesc = CDTSharedImages.getImageDescriptor(CDTSharedImages.IMG_VIEW_PIN_ACTION_G); + break; + case IPinProvider.IPinElementColorDescriptor.RED: + imageDesc = CDTSharedImages.getImageDescriptor(CDTSharedImages.IMG_VIEW_PIN_ACTION_R); + break; + case IPinProvider.IPinElementColorDescriptor.BLUE: + imageDesc = CDTSharedImages.getImageDescriptor(CDTSharedImages.IMG_VIEW_PIN_ACTION_B); + break; + } + } + } + } + } + + if (imageDesc == null) + imageDesc = CDTSharedImages.getImageDescriptor(CDTSharedImages.IMG_VIEW_PIN_ACTION); + fAction.setImageDescriptor(imageDesc); + } + /* (non-Javadoc) * @see org.eclipse.debug.ui.contexts.IDebugContextListener#debugContextChanged(org.eclipse.debug.ui.contexts.DebugContextEvent) */ diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/pinclone/DebugContextPinProvider.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/pinclone/DebugContextPinProvider.java index b6af12d62f7..054c68e64a1 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/pinclone/DebugContextPinProvider.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/pinclone/DebugContextPinProvider.java @@ -7,6 +7,7 @@ * * Contributors: * Patrick Chuong (Texas Instruments) - Pin and Clone Supports (331781) + * Patrick Chuong (Texas Instruments) - Add support for icon overlay in the debug view (Bug 334566) *****************************************************************/ package org.eclipse.cdt.debug.internal.ui.pinclone; @@ -93,20 +94,7 @@ public class DebugContextPinProvider extends AbstractDebugContextProvider implem * @return true if the pinned handles are pinned to the debug context */ public boolean isPinnedTo(Object debugContext) { - IPinProvider pinProvider = null; - if (debugContext instanceof IAdaptable) { - pinProvider = (IPinProvider) ((IAdaptable)debugContext).getAdapter(IPinProvider.class); - } - - for (IPinElementHandle handle : fPinHandles) { - if (pinProvider != null && pinProvider.isPinnedTo(debugContext, handle)) { - return true; - - } else if (handle.getDebugContext().equals(debugContext)) { - return true; - } - } - return false; + return PinCloneUtils.isPinnedTo(fPinHandles, debugContext); } /** @@ -131,7 +119,7 @@ public class DebugContextPinProvider extends AbstractDebugContextProvider implem handles.add(handle); fPinProvider.put(handle, pinProvider); } else - handles.add(new PinElementHandle(element, null)); + handles.add(new PinElementHandle(element, null, PinCloneUtils.getDefaultPinElementColorDescriptor())); } } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/pinclone/PinCloneUtils.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/pinclone/PinCloneUtils.java index 39e53d4543b..512a26d858d 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/pinclone/PinCloneUtils.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/pinclone/PinCloneUtils.java @@ -7,15 +7,20 @@ * * Contributors: * Patrick Chuong (Texas Instruments) - Pin and Clone Supports (331781) + * Patrick Chuong (Texas Instruments) - Add support for icon overlay in the debug view (Bug 334566) *****************************************************************/ package org.eclipse.cdt.debug.internal.ui.pinclone; import java.lang.reflect.Method; import java.util.List; +import java.util.Set; import org.eclipse.cdt.debug.ui.CDebugUIPlugin; import org.eclipse.cdt.debug.ui.IPinProvider; +import org.eclipse.cdt.debug.ui.IPinProvider.IPinElementColorDescriptor; +import org.eclipse.cdt.debug.ui.IPinProvider.IPinElementHandle; import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IViewPart; @@ -29,6 +34,29 @@ import org.eclipse.ui.part.WorkbenchPart; public class PinCloneUtils { public static String PIN_CLONE_VIEW_TAG = "PIN_CLONE_VIEW_"; //$NON-NLS-1$ + private static final DefaultPinElementColorDescriptor DEFAULT_PIN_ELEMENT_COLOR_DESCRIPTOR = new DefaultPinElementColorDescriptor(); + + /** + * Default pin element color descriptor. + */ + private static class DefaultPinElementColorDescriptor implements IPinElementColorDescriptor { + public int getOverlayColor() { + return GREEN; + } + public ImageDescriptor getToolbarIconDescriptor() { + return null; + } + } + + /** + * Returns the default pin element color descriptor. + * + * @return the color descriptor + */ + public static IPinElementColorDescriptor getDefaultPinElementColorDescriptor() { + return DEFAULT_PIN_ELEMENT_COLOR_DESCRIPTOR; + } + /** * Encodes cloned part secondary id. * @@ -42,10 +70,12 @@ public class PinCloneUtils { /** * Decodes cloned part secondary id. * - * @param secondaryId the part's secondary id. - * @return a decoded part secondary id. + * @param secondaryId the part's secondary id + * @return a decoded part secondary id */ public static String decodeClonedPartSecondaryId(String secondaryId) { + if (secondaryId == null) + return ""; //$NON-NLS-1$ return secondaryId.replaceFirst(PIN_CLONE_VIEW_TAG, ""); //$NON-NLS-1$ } @@ -168,4 +198,64 @@ public class PinCloneUtils { return pinnable; } + + /** + * Returns the pin element color descriptor for the set of handles. If there are multiple pinned handles, + * then return the default element color descriptor. + * + * @param handles the pinned debug handles + * @param debugContext the debug context to compare with against the handles + * @return the element color descriptor, can be <code>null</code>; + */ + public static IPinElementColorDescriptor getPinElementColorDescriptor(Set<IPinElementHandle> handles, Object debugContext) { + int color = IPinElementColorDescriptor.UNDEFINED; + IPinElementColorDescriptor colorDesc = null; + + for (IPinElementHandle handle : handles) { + if (debugContext instanceof IAdaptable) { + + IPinProvider pinProvider = (IPinProvider) ((IAdaptable) debugContext).getAdapter(IPinProvider.class); + if (pinProvider != null) { + if (pinProvider.isPinnedTo(debugContext, handle)) { + colorDesc = handle.getPinElementColorDescriptor(); + if (colorDesc != null) { + int overlayColor = colorDesc.getOverlayColor(); + if (color == IPinElementColorDescriptor.UNDEFINED) color = overlayColor; + if (color != overlayColor) { + colorDesc = null; + break; + } + } + } + } + } + } + + if (colorDesc == null) + colorDesc = getDefaultPinElementColorDescriptor(); + + return colorDesc; + } + + /** + * Returns whether the debug context is pinned to any one of these handles. + * + * @param handles the handles + * @param debugContext the debug context + * @return true if pinned to any one of these handles + */ + public static boolean isPinnedTo(Set<IPinElementHandle> handles, Object debugContext) { + for (IPinElementHandle handle : handles) { + if (debugContext instanceof IAdaptable) { + IPinProvider pinProvider = (IPinProvider) ((IAdaptable) debugContext).getAdapter(IPinProvider.class); + if (pinProvider != null) { + if (pinProvider.isPinnedTo(debugContext, handle)) { + return true; + } + } + } + } + + return false; + } } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/IPinProvider.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/IPinProvider.java index c678677a8bd..efa8c76d55c 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/IPinProvider.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/IPinProvider.java @@ -7,9 +7,11 @@ * * Contributors: * Patrick Chuong (Texas Instruments) - Pin and Clone Supports (331781) + * Patrick Chuong (Texas Instruments) - Add support for icon overlay in the debug view (Bug 334566) *****************************************************************/ package org.eclipse.cdt.debug.ui; +import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.IWorkbenchPart; /** @@ -29,17 +31,49 @@ import org.eclipse.ui.IWorkbenchPart; */ public interface IPinProvider { /** - * An interface that provides label for the pinned handle. Handle that - * wish to provide custom label should implement this interface. + * Pin element color descriptor. */ - public interface IPinHandleLabelProvider { + public interface IPinElementColorDescriptor { /** - * Returns the label the label will be used to display - * in the pinned view's descriptor. + * Default number of color count. + */ + final int DEFAULT_COLOR_COUNT = 3; + + /** + * An undefined color + */ + int UNDEFINED = -1; + + /** + * Green color (Default) + */ + int GREEN = 0; + + /** + * Red color + */ + int RED = 1; + + /** + * Blue color + */ + int BLUE = 2; + + /** + * Returns the overlay pin color. The overlay pin will be used to decorate the debug view for element that + * is pinned to a view. + * + * @return one of the overlay color + */ + int getOverlayColor(); + + /** + * Returns the toolbar pin action image description to use when the view is pinned, can be <code>null</code>. + * If <code>null</code>, than the default image description will be use. * - * @return the handle label + * @return the icon descriptor */ - String getLabel(); + ImageDescriptor getToolbarIconDescriptor(); } /** @@ -51,7 +85,22 @@ public interface IPinProvider { * * @return the debug context */ - Object getDebugContext(); + Object getDebugContext(); + + /** + * Returns the label the label will be used to display + * in the pinned view's descriptor. + * + * @return the handle label + */ + String getLabel(); + + /** + * Returns color descriptor for this element. + * + * @return the color descriptor, can be <code>null</code> + */ + IPinElementColorDescriptor getPinElementColorDescriptor(); } /** diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/PinElementHandle.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/PinElementHandle.java index 43a4f93739e..df13a90df2d 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/PinElementHandle.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/PinElementHandle.java @@ -7,11 +7,12 @@ * * Contributors: * Patrick Chuong (Texas Instruments) - Pin and Clone Supports (331781) + * Patrick Chuong (Texas Instruments) - Add support for icon overlay in the debug view (Bug 334566) *****************************************************************/ package org.eclipse.cdt.debug.ui; +import org.eclipse.cdt.debug.ui.IPinProvider.IPinElementColorDescriptor; import org.eclipse.cdt.debug.ui.IPinProvider.IPinElementHandle; -import org.eclipse.cdt.debug.ui.IPinProvider.IPinHandleLabelProvider; import org.eclipse.core.runtime.PlatformObject; /** @@ -19,23 +20,34 @@ import org.eclipse.core.runtime.PlatformObject; * * @since 7.1 */ -public class PinElementHandle extends PlatformObject implements IPinHandleLabelProvider, IPinElementHandle { - private final Object fDebugContext; - private final String fLabel; +public class PinElementHandle extends PlatformObject implements IPinElementHandle { + private Object fDebugContext; + private String fLabel; + private IPinElementColorDescriptor fColorDescriptor; - public PinElementHandle(Object debugContext, String label) { + public PinElementHandle(Object debugContext, String label, IPinElementColorDescriptor colorDescriptor) { fDebugContext = debugContext; fLabel = label; + fColorDescriptor = colorDescriptor; } /* * (non-Javadoc) * @see org.eclipse.cdt.debug.ui.IPinProvider.IPinElementHandle#getDebugContext() */ - public Object getDebugContext() { + public synchronized Object getDebugContext() { return fDebugContext; } + /** + * Sets the debug context. + * + * @param debugContext the new debug context + */ + public synchronized void setDebugContext(Object debugContext) { + fDebugContext = debugContext; + } + /* * (non-Javadoc) * @see org.eclipse.cdt.debug.core.IPinProvider.IHandleLabelProvider#getLabel() @@ -43,7 +55,15 @@ public class PinElementHandle extends PlatformObject implements IPinHandleLabelP public String getLabel() { return fLabel; } - + + /* + * (non-Javadoc) + * @see org.eclipse.cdt.debug.ui.IPinProvider.IPinElementHandle#getPinElementColorDescriptor() + */ + public IPinElementColorDescriptor getPinElementColorDescriptor() { + return fColorDescriptor; + } + /* (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ |