KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > launch > LaunchViewContextListener


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation 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
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.views.launch;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.HashSet JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.List JavaDoc;
18 import java.util.ListIterator JavaDoc;
19 import java.util.Map JavaDoc;
20 import java.util.Set JavaDoc;
21 import java.util.StringTokenizer JavaDoc;
22 import java.util.regex.Pattern JavaDoc;
23
24 import org.eclipse.core.runtime.IAdaptable;
25 import org.eclipse.core.runtime.IConfigurationElement;
26 import org.eclipse.core.runtime.IExtensionPoint;
27 import org.eclipse.core.runtime.IProgressMonitor;
28 import org.eclipse.core.runtime.IStatus;
29 import org.eclipse.core.runtime.Platform;
30 import org.eclipse.core.runtime.Status;
31 import org.eclipse.debug.core.ILaunch;
32 import org.eclipse.debug.core.model.IDebugElement;
33 import org.eclipse.debug.core.model.IDebugModelProvider;
34 import org.eclipse.debug.core.model.IProcess;
35 import org.eclipse.debug.core.model.IStackFrame;
36 import org.eclipse.debug.internal.ui.DebugUIPlugin;
37 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
38 import org.eclipse.debug.internal.ui.launchConfigurations.PerspectiveManager;
39 import org.eclipse.debug.ui.DebugUITools;
40 import org.eclipse.debug.ui.IDebugUIConstants;
41 import org.eclipse.jface.preference.IPreferenceStore;
42 import org.eclipse.ui.IPerspectiveDescriptor;
43 import org.eclipse.ui.IViewPart;
44 import org.eclipse.ui.IViewReference;
45 import org.eclipse.ui.IWorkbench;
46 import org.eclipse.ui.IWorkbenchPage;
47 import org.eclipse.ui.IWorkbenchPartReference;
48 import org.eclipse.ui.PartInitException;
49 import org.eclipse.ui.PlatformUI;
50 import org.eclipse.ui.activities.ActivityManagerEvent;
51 import org.eclipse.ui.activities.IActivity;
52 import org.eclipse.ui.activities.IActivityManager;
53 import org.eclipse.ui.activities.IActivityManagerListener;
54 import org.eclipse.ui.activities.IActivityPatternBinding;
55 import org.eclipse.ui.activities.IWorkbenchActivitySupport;
56 import org.eclipse.ui.contexts.ContextManagerEvent;
57 import org.eclipse.ui.contexts.EnabledSubmission;
58 import org.eclipse.ui.contexts.IContext;
59 import org.eclipse.ui.contexts.IContextManager;
60 import org.eclipse.ui.contexts.IContextManagerListener;
61 import org.eclipse.ui.contexts.IWorkbenchContextSupport;
62 import org.eclipse.ui.contexts.NotDefinedException;
63 import org.eclipse.ui.progress.UIJob;
64
65 /**
66  * A context listener which automatically opens/closes/activates views in
67  * response to debug context changes and automatically enables activities
68  * as appropriate.
69  *
70  * The context listener updates for selection changes in the LaunchView,
71  * enabling/disabling contexts and enabling activities based on the
72  * org.eclipse.debug.ui.debugModelContextBindings and
73  * org.eclipse.ui.activities extension points.
74  *
75  * Activity pattern bindings with patterns of the form:
76  * <debug model identifier>/debugModel
77  * are treated as bindings between a debug model and an activity. When
78  * an element with the specified debug model identifier is selected,
79  * the specified activity will be enabled.
80  */

81 public class LaunchViewContextListener implements IContextManagerListener, IActivityManagerListener {
82
83     private static final String JavaDoc DEBUG_MODEL_ACTIVITY_SUFFIX = "/debugModel"; //$NON-NLS-1$
84
public static final String JavaDoc ID_CONTEXT_VIEW_BINDINGS= "contextViewBindings"; //$NON-NLS-1$
85
public static final String JavaDoc ID_DEBUG_MODEL_CONTEXT_BINDINGS= "debugModelContextBindings"; //$NON-NLS-1$
86
public static final String JavaDoc ATTR_CONTEXT_ID= "contextId"; //$NON-NLS-1$
87
public static final String JavaDoc ATTR_VIEW_ID= "viewId"; //$NON-NLS-1$
88
public static final String JavaDoc ATTR_DEBUG_MODEL_ID= "debugModelId"; //$NON-NLS-1$
89
public static final String JavaDoc ATTR_AUTO_OPEN= "autoOpen"; //$NON-NLS-1$
90
public static final String JavaDoc ATTR_AUTO_CLOSE= "autoClose"; //$NON-NLS-1$
91

92     /**
93      * The launch view that this context listener works for
94      */

95     private LaunchView launchView;
96     /**
97      * A mapping of debug models IDs (String) to a collection
98      * of context IDs (List<String>).
99      */

100     private Map JavaDoc modelsToContexts= new HashMap JavaDoc();
101     
102     /**
103      * A cache of activity pattern bindings for debug models.
104      */

105     private List JavaDoc modelPatternBindings = new ArrayList JavaDoc();
106     
107     /**
108      * Currently enabled activities
109      */

110     private Set JavaDoc enabledActivities;
111     
112     /**
113      * A mapping of debug model IDs (String) to a collection
114      * of resolved activity IDs (Set<String>).
115      */

116     private Map JavaDoc modelsToActivities= new HashMap JavaDoc();
117     /**
118      * A mapping of context IDs (Strings) to a collection
119      * of context-view bindings (IConfigurationElements).
120      */

121     private Map JavaDoc contextViews= new HashMap JavaDoc();
122     /**
123      * Collection of all views that might be opened or closed automatically.
124      */

125     private Set JavaDoc managedViewIds= new HashSet JavaDoc();
126     /**
127      * Collection of views which have been manually closed by the
128      * user. Views which are in this collection should not be
129      * automatically opened.
130      */

131     private Set JavaDoc viewIdsToNotOpen= new HashSet JavaDoc();
132     /**
133      * Map of views which have been automatically opened.
134      * Only views which are in this collection should be automatically
135      * closed.
136      *
137      * Key: perspective id
138      * Value: HashSet of view ids open in a perspective
139      */

140     private Map JavaDoc openedViewIds= new HashMap JavaDoc();
141     
142     /**
143      * Map of ILaunch objects to the List of EnabledSubmissions that were
144      * submitted for them.
145      * Key: ILaunch
146      * Value: List <EnabledSubmission>
147      */

148     private Map JavaDoc fContextSubmissions= new HashMap JavaDoc();
149     public static final String JavaDoc DEBUG_CONTEXT= "org.eclipse.debug.ui.debugging"; //$NON-NLS-1$
150
/**
151      * String preference specifying which views should not be
152      * automatically opened by the launch view.
153      * The value is a comma-separated list of view identifiers.
154      *
155      * @since 3.0
156      */

157     public static final String JavaDoc PREF_VIEWS_TO_NOT_OPEN= IDebugUIConstants.PLUGIN_ID + ".views_to_not_open"; //$NON-NLS-1$
158
/**
159      * String preference specifying which views have been
160      * automatically opened by the launch view. Only views which
161      * have been automatically opened will be automatically closed.
162      * The value is a comma-separated list of view identifiers.
163      *
164      * @since 3.0
165      */

166     public static final String JavaDoc PREF_OPENED_VIEWS= IDebugUIConstants.PLUGIN_ID + ".opened_views"; //$NON-NLS-1$
167
/**
168      * The collection of context ids which were most recently enabled.
169      */

170     private List JavaDoc lastEnabledIds= new ArrayList JavaDoc();
171     /**
172      * Boolean flag controlling whether or not this listener is
173      * tracking part changes. This is necessary since this class
174      * doesn't implement its own listener, but it informed of
175      * perspective change events by the LaunchView.
176      */

177     private boolean fIsTrackingPartChanges;
178     /**
179      * Collection of perspectives in which views should be
180      * automatically opened and closed.
181      */

182     private List JavaDoc fAutoManagePerspectives= new ArrayList JavaDoc();
183     
184     /**
185      * Creates a fully initialized context listener.
186      *
187      * @param view a fully initialized launch view
188      */

189     public LaunchViewContextListener(LaunchView view) {
190         launchView= view;
191         loadTrackViews();
192         loadDebugModelContextExtensions();
193         loadDebugModelActivityExtensions();
194         loadContextToViewExtensions(true);
195         loadOpenedViews();
196         loadViewsToNotOpen();
197         loadAutoManagePerspectives();
198         IWorkbench workbench = PlatformUI.getWorkbench();
199         workbench.getContextSupport().getContextManager().addContextManagerListener(this);
200         IActivityManager activityManager = workbench.getActivitySupport().getActivityManager();
201         activityManager.addActivityManagerListener(this);
202         enabledActivities = activityManager.getEnabledActivityIds();
203     }
204     
205     /**
206      * Loads extensions which map context ids to views. This information
207      * is used to open the appropriate views when a context is activated.
208      */

209     private void loadContextToViewExtensions(boolean reloadContextMappings) {
210         IExtensionPoint extensionPoint= Platform.getExtensionRegistry().getExtensionPoint(DebugUIPlugin.getUniqueIdentifier(), ID_CONTEXT_VIEW_BINDINGS);
211         IConfigurationElement[] configurationElements = extensionPoint.getConfigurationElements();
212         for (int i = 0; i < configurationElements.length; i++) {
213             IConfigurationElement element = configurationElements[i];
214             String JavaDoc viewId = getViewId(element);
215             if (reloadContextMappings) {
216                 String JavaDoc contextId = element.getAttribute(ATTR_CONTEXT_ID);
217                 if (contextId == null || viewId == null) {
218                     continue;
219                 }
220                 List JavaDoc elements= (List JavaDoc) contextViews.get(contextId);
221                 if (elements == null) {
222                     elements= new ArrayList JavaDoc();
223                     contextViews.put(contextId, elements);
224                 }
225                 elements.add(element);
226             }
227             managedViewIds.add(viewId);
228         }
229     }
230     
231     /**
232      * Loads the extensions which map debug model identifiers
233      * to context ids. This information is used to activate the
234      * appropriate context when a debug element is selected.
235      *
236      * When a context associated with a debug model is enabled, we
237      * also activate all parent contexts. Since the context manager
238      * does not do this automatically, we cache all parent context
239      * identifiers in the modelToContexts map as well
240      */

241     private void loadDebugModelContextExtensions() {
242         IExtensionPoint extensionPoint= Platform.getExtensionRegistry().getExtensionPoint(DebugUIPlugin.getUniqueIdentifier(), ID_DEBUG_MODEL_CONTEXT_BINDINGS);
243         IConfigurationElement[] configurationElements = extensionPoint.getConfigurationElements();
244         for (int i = 0; i < configurationElements.length; i++) {
245             IConfigurationElement element = configurationElements[i];
246             String JavaDoc modelIdentifier = element.getAttribute(ATTR_DEBUG_MODEL_ID);
247             String JavaDoc contextId = element.getAttribute(ATTR_CONTEXT_ID);
248             if (modelIdentifier != null && contextId != null) {
249                 List JavaDoc contextIds = (List JavaDoc) modelsToContexts.get(modelIdentifier);
250                 if (contextIds == null) {
251                     contextIds = new ArrayList JavaDoc();
252                     modelsToContexts.put(modelIdentifier, contextIds);
253                 }
254                 contextIds.add(contextId);
255             }
256         }
257     }
258     
259     /**
260      * Loads the extensions which map debug model patterns
261      * to activity ids. This information is used to activate the
262      * appropriate activities when a debug element is selected.
263      */

264     private void loadDebugModelActivityExtensions() {
265         IActivityManager activityManager = PlatformUI.getWorkbench().getActivitySupport().getActivityManager();
266         Set JavaDoc activityIds = activityManager.getDefinedActivityIds();
267         Iterator JavaDoc activityIterator = activityIds.iterator();
268         while (activityIterator.hasNext()) {
269             String JavaDoc activityId= (String JavaDoc) activityIterator.next();
270             IActivity activity = activityManager.getActivity(activityId);
271             if (activity != null) {
272                 Set JavaDoc patternBindings = activity.getActivityPatternBindings();
273                 Iterator JavaDoc patternIterator= patternBindings.iterator();
274                 while (patternIterator.hasNext()) {
275                     IActivityPatternBinding patternBinding= (IActivityPatternBinding) patternIterator.next();
276                     String JavaDoc pattern = patternBinding.getPattern().pattern();
277                     if (pattern.endsWith(DEBUG_MODEL_ACTIVITY_SUFFIX)) {
278                         modelPatternBindings.add(patternBinding);
279                     }
280                 }
281             }
282         }
283     }
284     
285     /**
286      * Lists the contextViews configuration elements for the
287      * given context ID and all its parent context IDs. The
288      * list only contains one configuration element per view
289      * such that if a child context provides a binding for a view
290      * it will override any bindings provided for that same view by
291      * parent contexts.
292      *
293      * @param contextId the context ID
294      * @return the configuration elements for the given context ID and
295      * all parent context IDs.
296      */

297     private List JavaDoc getConfigurationElements(String JavaDoc contextId) {
298         // Collection of view ids for which configuration
299
// elements have been found.
300
List JavaDoc configuredViewIds= new ArrayList JavaDoc();
301         List JavaDoc allConfigurationElements= new ArrayList JavaDoc();
302         IContextManager contextManager = PlatformUI.getWorkbench().getContextSupport().getContextManager();
303         while (contextId != null) {
304             List JavaDoc configurationElements= (List JavaDoc) contextViews.get(contextId);
305             if (configurationElements != null) {
306                 ListIterator JavaDoc iter= configurationElements.listIterator();
307                 while (iter.hasNext()) {
308                     // Only add the element if configuredViewIds do not already
309
// contain viewId.
310
// This allows child contexts to override parent
311
// bindings.
312
IConfigurationElement element= (IConfigurationElement) iter.next();
313                     String JavaDoc viewId = element.getAttribute(ATTR_VIEW_ID);
314                     if (viewId != null) {
315                         if (!configuredViewIds.contains(viewId)) {
316                             allConfigurationElements.add(element);
317                         }
318                         configuredViewIds.add(viewId);
319                     }
320                 }
321             }
322             IContext context = contextManager.getContext(contextId);
323             if (context != null) {
324                 try {
325                     contextId= context.getParentId();
326                 } catch (NotDefinedException e) {
327                     contextId= null;
328                 }
329             }
330         }
331         return allConfigurationElements;
332     }
333     
334     /**
335      * Persist the collection of views to not automatically open.
336      */

337     private void saveViewsToNotOpen() {
338         saveViewCollection(LaunchViewContextListener.PREF_VIEWS_TO_NOT_OPEN, viewIdsToNotOpen);
339     }
340     
341     /**
342      * Persist the collection of views which have been automatically
343      * opened.
344      */

345     private void saveOpenedViews() {
346         saveViewMap(LaunchViewContextListener.PREF_OPENED_VIEWS, openedViewIds);
347     }
348
349     /**
350      * Persist the view identifiers that the user has manually
351      * opened/closed so that we continue to not automatically
352      * open/close them.
353      * @param attribute the preference key in which to store the
354      * view id collection
355      * @param collection the view identifier collection
356      */

357     public void saveViewCollection(String JavaDoc attribute, Set JavaDoc collection) {
358         StringBuffer JavaDoc views= new StringBuffer JavaDoc();
359         Iterator JavaDoc iter= collection.iterator();
360         while (iter.hasNext()) {
361             views.append((String JavaDoc) iter.next()).append(',');
362         }
363         if (views.length() > 0) {
364             IPreferenceStore preferenceStore = DebugUITools.getPreferenceStore();
365             preferenceStore.removePropertyChangeListener(launchView);
366             preferenceStore.setValue(attribute, views.toString());
367             preferenceStore.addPropertyChangeListener(launchView);
368         }
369     }
370     
371     
372     /**
373      * Persist the view identifiers that the user has manually
374      * opened/closed so that we continue to not automatically
375      * open/close them.
376      *
377      * key: perspective id
378      * value: ArrayList of view ids
379      *
380      * The map is saved in the following format:
381      * key1:arrayElm(0),arrayElm(1)/key2:arrayElm(0),arrayElm(1)
382      * Perspective settings are delimited by "/".
383      * view Ids are delimited by ","
384      *
385      * @param attribute attribute the preference key in which to store the
386      * view id map
387      * @param map that maps a persective to a list of view ids
388      */

389     private void saveViewMap(String JavaDoc attribute, Map JavaDoc map) {
390         StringBuffer JavaDoc views= new StringBuffer JavaDoc();
391         Iterator JavaDoc iter= map.keySet().iterator();
392         while (iter.hasNext()) {
393             String JavaDoc perspId = (String JavaDoc) iter.next();
394             Set JavaDoc viewIds = (Set JavaDoc)map.get(perspId);
395             views.append("/"); //$NON-NLS-1$
396
views.append(perspId);
397             if (viewIds != null && !viewIds.isEmpty())
398             {
399                 views.append(":"); //$NON-NLS-1$
400
Iterator JavaDoc viewsIter = viewIds.iterator();
401                 while (viewsIter.hasNext())
402                 {
403                     String JavaDoc viewId = (String JavaDoc)viewsIter.next();
404                     views.append(viewId);
405                     views.append(","); //$NON-NLS-1$
406
}
407             }
408         }
409         if (views.length() > 0) {
410             IPreferenceStore preferenceStore = DebugUITools.getPreferenceStore();
411             preferenceStore.removePropertyChangeListener(launchView);
412             preferenceStore.setValue(attribute, views.toString());
413             preferenceStore.addPropertyChangeListener(launchView);
414         }
415     }
416     
417     /**
418      * Load the collection of views to not open.
419      */

420     public void loadViewsToNotOpen() {
421         loadViewCollection(LaunchViewContextListener.PREF_VIEWS_TO_NOT_OPEN, viewIdsToNotOpen);
422     }
423     
424     /**
425      * Load the collection of views that have been automatically
426      * opened.
427      */

428     public void loadOpenedViews() {
429         loadViewMap(LaunchViewContextListener.PREF_OPENED_VIEWS, openedViewIds);
430     }
431     
432     /**
433      * Loads a collection of view ids from the preferences keyed to
434      * the given attribute, and stores them in the given collection
435      *
436      * @param attribute the attribute of the view ids
437      * @param collection the collection to store the view ids into.
438      */

439     public void loadViewCollection(String JavaDoc attribute, Set JavaDoc collection) {
440         collection.clear();
441         String JavaDoc views = DebugUITools.getPreferenceStore().getString(attribute);
442         int startIndex= 0;
443         int endIndex= views.indexOf(',');
444         if (endIndex == -1) {
445             endIndex= views.length();
446         }
447         while (startIndex < views.length() - 1) {
448             String JavaDoc viewId= views.substring(startIndex, endIndex);
449             if (viewId.length() > 0) {
450                 collection.add(viewId);
451             }
452             startIndex= endIndex + 1;
453             endIndex= views.indexOf(',', startIndex);
454         }
455     }
456     
457     /**
458      * Loads a map of view ids from the preferences keyed to
459      * the given attribute, and stores them in the given map
460      *
461      * The map is saved in the following format:
462      * key1:arrayElm(0),arrayElm(1)/key2:arrayElm(0)+arrayElm(1)
463      * Perspective settings are delimited by "/".
464      * Key is the perspective id
465      * ArrayElm's are the view Ids and are delimited by ","
466      *
467      * @param attribute the attribute of the view ids
468      * @param map the map to store the view ids into.
469      */

470     private void loadViewMap(String JavaDoc attribute, Map JavaDoc map) {
471         map.clear();
472         String JavaDoc views = DebugUITools.getPreferenceStore().getString(attribute);
473         
474         if (views.startsWith("/")) //$NON-NLS-1$
475
{
476             // list of views ids in this format:
477
// perspective1Id:viewIdA,viewIdB/persective2Id:viewIda,viewIdB
478
String JavaDoc[] viewsStr = views.split("/"); //$NON-NLS-1$
479

480             for (int i=0; i<viewsStr.length; i++)
481             {
482                 if (viewsStr[i].length() == 0)
483                     continue;
484                 
485                 // split perpectiveId and viewId
486
String JavaDoc[] data = viewsStr[i].split(":"); //$NON-NLS-1$
487

488                 // data[0] = perspective
489
// data[1] = list of view ids delimited by ","
490

491                 if (data.length == 2)
492                 {
493                     String JavaDoc perspId = data[0];
494                     
495                     String JavaDoc[] viewIds = data[1].split(","); //$NON-NLS-1$
496
Set JavaDoc list = new HashSet JavaDoc();
497                     for (int j=0; j<viewIds.length; j++)
498                     {
499                         list.add(viewIds[j]);
500                     }
501                     
502                     openedViewIds.put(perspId, list);
503                 }
504             }
505         }
506     }
507
508     /* (non-Javadoc)
509      * @see org.eclipse.ui.contexts.IContextManagerListener#contextManagerChanged(org.eclipse.ui.contexts.ContextManagerEvent)
510      */

511     public void contextManagerChanged(ContextManagerEvent contextManagerEvent) {
512         Set JavaDoc enabled = getNewlyEnabledContexts(contextManagerEvent);
513         Set JavaDoc disabled = getNewlyDisabledContexts(contextManagerEvent);
514         contextEnabled(enabled);
515         contextsDisabled(disabled);
516     }
517     
518     private Set JavaDoc getNewlyEnabledContexts(ContextManagerEvent contextManagerEvent) {
519         Set JavaDoc set = new HashSet JavaDoc(contextManagerEvent.getContextManager().getEnabledContextIds());
520         set.removeAll(contextManagerEvent.getPreviouslyEnabledContextIds());
521         return set;
522     }
523
524     private Set JavaDoc getNewlyDisabledContexts(ContextManagerEvent contextManagerEvent) {
525         Set JavaDoc set = new HashSet JavaDoc(contextManagerEvent.getPreviouslyEnabledContextIds());
526         set.removeAll(contextManagerEvent.getContextManager().getEnabledContextIds());
527         return set;
528     }
529
530     /**
531      * The context with the given ID has been enabled.
532      * Activate the appropriate views.
533      *
534      * @param contextId the ID of the context that has been
535      * enabled
536      */

537     public void contextEnabled(final Set JavaDoc contextIds) {
538         if (!isAutoManageViews()) {
539             return;
540         }
541         
542         final UIJob openViewsJob = new UIJob("Open Context-Enabled Views") { //$NON-NLS-1$
543
public IStatus runInUIThread(IProgressMonitor monitor) {
544                 IWorkbenchPage page = getPage();
545                 if (page == null)
546                     return Status.OK_STATUS;
547                 
548                 // Since we run this job asynchronously on the UI Thread,
549
// #getPerspective() may return null when this job is run
550
// when the workbench is shutting down.
551
if (page.getPerspective() == null)
552                     return Status.OK_STATUS;
553                 
554                 // We ignore the "Debugging" context since we use it
555
// to provide a base set of views for other context
556
// bindings to inherit. If we don't ignore it, we'll
557
// end up opening those views whenever a debug session
558
// starts, which is not the desired behavior.
559
contextIds.remove(DEBUG_CONTEXT);
560                 if (page == null || contextIds.size() == 0) {
561                     return Status.OK_STATUS;
562                 }
563                 Set JavaDoc viewsToShow = new HashSet JavaDoc();
564                 Set JavaDoc viewsToOpen = new HashSet JavaDoc();
565                 computeViewActivation(contextIds, viewsToOpen, viewsToShow);
566
567                 boolean resetTrackingPartChanges = false;
568                 if (fIsTrackingPartChanges) {
569                     // only change the flag if it is currently
570
// tracking part changes.
571
fIsTrackingPartChanges = false;
572                     resetTrackingPartChanges = true;
573                 }
574
575                 Iterator JavaDoc iterator = viewsToOpen.iterator();
576
577                 String JavaDoc id = page.getPerspective().getId();
578                 Set JavaDoc views = (Set JavaDoc) openedViewIds.get(id);
579                 if (views == null) {
580                     views = new HashSet JavaDoc();
581                 }
582
583                 while (iterator.hasNext()) {
584                     String JavaDoc viewId = (String JavaDoc) iterator.next();
585                     try {
586                         IViewPart view = page.showView(viewId, null,
587                                 IWorkbenchPage.VIEW_CREATE);
588                         views.add(viewId);
589
590                         viewsToShow.add(view);
591                     } catch (PartInitException e) {
592                         DebugUIPlugin.log(e.getStatus());
593                     }
594                 }
595
596                 if (!viewsToOpen.isEmpty()) {
597                     openedViewIds.put(id, views);
598                     saveOpenedViews();
599                 }
600                 iterator = viewsToShow.iterator();
601                 while (iterator.hasNext()) {
602                     boolean activate = true;
603                     IViewPart view = (IViewPart) iterator.next();
604                     IViewPart[] stackedViews = page.getViewStack(view);
605                     if (stackedViews == null) {
606                         continue;
607                     }
608                     // For each applicable view, iterate through the view stack.
609
// If we find that view before any other applicable views,
610
// show it. Otherwise, don't.
611
for (int i = 0; i < stackedViews.length; i++) {
612                         IViewPart stackedView = stackedViews[i];
613                         if (view == stackedView) {
614                             break;
615                         } else if (viewsToShow.contains(stackedView)) {
616                             // If this view is below an appropriate view, don't
617
// show it
618
activate = false;
619                             break;
620                         }
621                     }
622                     if (activate) {
623                         page.bringToTop(view);
624                     }
625                 }
626
627                 // Reset if we have previously changed this setting
628
if (resetTrackingPartChanges)
629                     loadTrackViews();
630                 
631                 return Status.OK_STATUS;
632             }
633         };
634         
635         openViewsJob.setSystem(true);
636
637         final PerspectiveManager manager = DebugUIPlugin.getDefault().getPerspectiveManager();
638         if (isBoundToViews(contextIds)) {
639             manager.schedulePostSwitch(openViewsJob);
640         }
641     }
642     
643     /**
644      * @param contextIds
645      * @return if the specified the context ids are tied
646      * to any context-enabled views.
647      */

648     private boolean isBoundToViews(Set JavaDoc contextIds)
649     {
650         Set JavaDoc possibleViewsToShow = new HashSet JavaDoc();
651         Iterator JavaDoc iter = contextIds.iterator();
652         while (iter.hasNext())
653         {
654             String JavaDoc contextId = (String JavaDoc)iter.next();
655             Set JavaDoc viewIds = getApplicableViewIds(contextId);
656             possibleViewsToShow.addAll(viewIds);
657         }
658         
659         return !possibleViewsToShow.isEmpty();
660     }
661     
662     /**
663      * Compute which views should be automatically opened and which should be
664      * automatically brought to top when the given contexts are enabled.
665      *
666      * @param contextIds the contexts that have been enabled
667      * @param viewIdsToOpen a Set into which this method can store the
668      * collection of view identifiers (String) that should be opened
669      * @param viewIdsShow a Set into which this method can store the
670      * collection of view identifiers (String) that should be brought to top
671      */

672     private void computeViewActivation(Set JavaDoc contextIds, Set JavaDoc viewIdsToOpen, Set JavaDoc viewIdsShow) {
673         IWorkbenchPage page = getPage();
674         if (page == null) {
675             return;
676         }
677         Iterator JavaDoc contexts = contextIds.iterator();
678         while (contexts.hasNext()) {
679             String JavaDoc contextId = (String JavaDoc) contexts.next();
680             Iterator JavaDoc configurationElements= getConfigurationElements(contextId).iterator();
681             while (configurationElements.hasNext()) {
682                 IConfigurationElement element = (IConfigurationElement) configurationElements.next();
683                 String JavaDoc viewId= getViewId(element);
684                 if (viewId == null) {
685                     continue;
686                 }
687                 IViewReference reference = page.findViewReference(viewId);
688                 if (reference != null && reference.isFastView()) {
689                     continue;
690                 }
691                 IViewPart view = page.findView(viewId);
692                 if (view != null) {
693                     viewIdsShow.add(view);
694                 } else if (isAutoOpen(element) && !viewIdsToNotOpen.contains(viewId)) {
695                     // Don't open automatically if specified not to.
696
viewIdsToOpen.add(viewId);
697                 }
698             }
699         }
700     }
701     
702     /**
703      * The given contexts have been disabled. Close all views
704      * associated with these contexts that aren't associated
705      * with other active contexts.
706      *
707      * @param contexts
708      */

709     public void contextsDisabled(Set JavaDoc contexts) {
710         IWorkbenchPage page= getPage();
711         if (page == null || contexts.size() == 0 || !isAutoManageViews()) {
712             return;
713         }
714         Set JavaDoc viewsToClose= getViewIdsToClose(contexts);
715         if (viewsToClose.isEmpty()) {
716             return;
717         }
718         
719         // only set this to false if fIsTrackingPartChanges is true
720
// otherwise, we may override the setting that is set
721
// by other event handlers. e.g. in #contextEnabled(...)
722
boolean resetTrackingPartChanges = false;
723         if (fIsTrackingPartChanges)
724         {
725             fIsTrackingPartChanges= false;
726             resetTrackingPartChanges = true;
727         }
728         Iterator JavaDoc iter= viewsToClose.iterator();
729         
730         String JavaDoc perspId = page.getPerspective().getId();
731         Set JavaDoc viewIds = (Set JavaDoc)openedViewIds.get(perspId);
732         
733         while (iter.hasNext()) {
734             String JavaDoc viewId= (String JavaDoc) iter.next();
735             IViewReference view = page.findViewReference(viewId);
736             if (view != null) {
737                 page.hideView(view);
738                 if (viewIds != null)
739                 {
740                     // remove opened view from perspective
741
viewIds.remove(viewId);
742                 }
743             }
744         }
745         saveOpenedViews();
746         
747         // reset if this setting is previously changed
748
if (resetTrackingPartChanges)
749             loadTrackViews();
750     }
751     
752     /**
753      * Returns a collection of view IDs which should be closed
754      * when the given context IDs are disabled.
755      *
756      * @param contextIds the context identifiers
757      * @return the identifiers of the views which should be closed
758      * when the given contexts disable
759      */

760     public Set JavaDoc getViewIdsToClose(Set JavaDoc contextIds) {
761         Set JavaDoc viewIdsToClose= new HashSet JavaDoc();
762         Set JavaDoc viewIdsToKeepOpen= getViewIdsForEnabledContexts();
763         Iterator JavaDoc contexts = contextIds.iterator();
764         IWorkbenchPage page = getPage();
765         if (page == null)
766             return viewIdsToClose;
767         if (page.getPerspective() == null)
768             return viewIdsToClose;
769         String JavaDoc currentPerspId = page.getPerspective().getId();
770         Set JavaDoc viewIds = (Set JavaDoc)openedViewIds.get(currentPerspId);
771         while (contexts.hasNext()) {
772             String JavaDoc contextId = (String JavaDoc) contexts.next();
773             List JavaDoc list = getConfigurationElements(contextId);
774             Iterator JavaDoc iter = list.iterator();
775             while (iter.hasNext()) {
776                 IConfigurationElement element = (IConfigurationElement) iter.next();
777                 if (!isAutoClose(element)) {
778                     continue;
779                 }
780                 String JavaDoc viewId = getViewId(element);
781
782                 if (viewId == null || viewIds == null || !viewIds.contains(viewId) || viewIdsToKeepOpen.contains(viewId)) {
783                     // Don't close views that the user has manually opened or views
784
// which are associated with contexts that are still enabled.
785
continue;
786                 }
787                 viewIdsToClose.add(viewId);
788             }
789         }
790         return viewIdsToClose;
791     }
792     
793     /**
794      * Returns the set of view identifiers that are bound to
795      * contexts which are enabled in the workbench.
796      *
797      * @return the set of view identifiers bound to enabled contexts
798      */

799     protected Set JavaDoc getViewIdsForEnabledContexts() {
800         Set JavaDoc viewIds= new HashSet JavaDoc();
801         Iterator JavaDoc enabledContexts = PlatformUI.getWorkbench().getContextSupport().getContextManager().getEnabledContextIds().iterator();
802         while (enabledContexts.hasNext()) {
803             String JavaDoc contextId = (String JavaDoc) enabledContexts.next();
804             if (contextId.equals(DEBUG_CONTEXT)) {
805                 // Ignore the "Debugging" context. See comment in contextEnabled(...)
806
continue;
807             }
808             viewIds.addAll(getApplicableViewIds(contextId));
809         }
810         return viewIds;
811     }
812     
813     /**
814      * Returns the set of view identifiers that are bound to the
815      * given context.
816      *
817      * @param contextId the context identifier
818      * @return the set of view identifiers bound to the given context
819      */

820     public Set JavaDoc getApplicableViewIds(String JavaDoc contextId) {
821         Set JavaDoc viewIds= new HashSet JavaDoc();
822         Iterator JavaDoc elements = getConfigurationElements(contextId).iterator();
823         while (elements.hasNext()) {
824             String JavaDoc viewId = getViewId((IConfigurationElement) elements.next());
825             if (viewId != null) {
826                 viewIds.add(viewId);
827             }
828         }
829         return viewIds;
830     }
831     
832     /**
833      * Determines the debug context associated with the selected
834      * stack frame's debug model (if any) and activates that
835      * context. This triggers this view's context listener
836      * to automatically open/close/activate views as appropriate.
837      */

838     public void updateForSelection(Object JavaDoc selection) {
839         ILaunch launch= getLaunch(selection);
840         if (launch == null) {
841             return;
842         }
843         String JavaDoc[] modelIds= getDebugModelIdsForSelection(selection);
844         enableContexts(getContextsForModels(modelIds), launch);
845         enableActivitiesFor(modelIds);
846     }
847
848     /**
849      * Returns the ILaunch associated with the given selection or
850      * <code>null</code> if none can be determined.
851      *
852      * @param selection the selection or <code>null</code>
853      * @return the ILaunch associated with the given selection or <code>null</code>
854      */

855     protected static ILaunch getLaunch(Object JavaDoc selection) {
856         ILaunch launch= null;
857         if (selection instanceof ILaunch) {
858             launch= (ILaunch) selection;
859         } else if (selection instanceof IDebugElement) {
860             launch= ((IDebugElement) selection).getLaunch();
861         } else if (selection instanceof IProcess) {
862             launch= ((IProcess) selection).getLaunch();
863         }
864         return launch;
865     }
866     
867     /**
868      * Returns the debug model identifiers associated with the given selection.
869      *
870      * @param selection the selection
871      * @return the debug model identifiers associated with the given selection
872      */

873     protected String JavaDoc[] getDebugModelIdsForSelection(Object JavaDoc selection) {
874         if (selection instanceof IAdaptable) {
875             IDebugModelProvider modelProvider= (IDebugModelProvider) Platform.getAdapterManager().getAdapter(selection, IDebugModelProvider.class);
876             if (modelProvider != null) {
877                 String JavaDoc[] modelIds= modelProvider.getModelIdentifiers();
878                 if (modelIds != null) {
879                     return modelIds;
880                 }
881             }
882         }
883         if (selection instanceof IStackFrame) {
884             return new String JavaDoc[] { ((IStackFrame) selection).getModelIdentifier() };
885         }
886         return new String JavaDoc[0];
887     }
888     
889     /**
890     * Returns the context identifiers associated with the
891     * given model identifiers.
892     *
893     * @param modelIds the model identifiers
894     * @return the contexts associated with the given model identifiers
895     */

896     protected List JavaDoc getContextsForModels(String JavaDoc[] modelIds) {
897         List JavaDoc contextIds= new ArrayList JavaDoc();
898         for (int i = 0; i < modelIds.length; i++) {
899             List JavaDoc ids= (List JavaDoc) modelsToContexts.get(modelIds[i]);
900             if (ids == null) {
901                 // seed with base debug context
902
ids = new ArrayList JavaDoc();
903                 ids.add(DEBUG_CONTEXT);
904                 modelsToContexts.put(modelIds[i], ids);
905             }
906             contextIds.addAll(ids);
907         }
908         return contextIds;
909     }
910     
911     /**
912      * Enables activities in the workbench associated with the given debug
913      * model ids that are not already enabled.
914      *
915      * @param debug model ids for which to enable activities
916      */

917     protected void enableActivitiesFor(String JavaDoc[] modelIds) {
918         Set JavaDoc newActivities = null;
919         for (int i = 0; i < modelIds.length; i++) {
920             String JavaDoc id = modelIds[i];
921             Set JavaDoc ids= (Set JavaDoc) modelsToActivities.get(id);
922             if (ids == null) {
923                 // first time the model has been seen, perform pattern matching
924
ids = new HashSet JavaDoc();
925                 modelsToActivities.put(id, ids);
926                 Iterator JavaDoc bindings = modelPatternBindings.iterator();
927                 while (bindings.hasNext()) {
928                     IActivityPatternBinding binding = (IActivityPatternBinding) bindings.next();
929                     String JavaDoc regex = binding.getPattern().pattern();
930                     regex = regex.substring(0, regex.length() - DEBUG_MODEL_ACTIVITY_SUFFIX.length());
931                     if (Pattern.matches(regex, id)) {
932                         ids.add(binding.getActivityId());
933                     }
934                 }
935             }
936             if (!enabledActivities.containsAll(ids)) {
937                 if (newActivities == null) {
938                     newActivities = new HashSet JavaDoc();
939                 }
940                 newActivities.addAll(ids);
941             }
942         }
943         if (newActivities != null) {
944             IWorkbenchActivitySupport activitySupport = PlatformUI.getWorkbench().getActivitySupport();
945             Set JavaDoc idsToEnable= new HashSet JavaDoc(enabledActivities.size() + newActivities.size());
946             idsToEnable.addAll(enabledActivities);
947             idsToEnable.addAll(newActivities);
948             activitySupport.setEnabledActivityIds(idsToEnable);
949         }
950     }
951     
952     /**
953      * Enable the given contexts for the given launch. Context
954      * IDs which are not currently enabled in the workbench will be
955      * submitted to the workbench. Simulate a context enablement
956      * callback (by calling contextActivated) for contexts that are already enabled so that
957      * their views can be promoted.
958      *
959      * @param contextIds the contexts to enable
960      * @param launch the launch for which the contexts are being enabled
961      */

962     protected void enableContexts(List JavaDoc contextIds, ILaunch launch) {
963         if (contextIds.isEmpty()) {
964             return;
965         }
966         Set JavaDoc enabledContexts = PlatformUI.getWorkbench().getContextSupport().getContextManager().getEnabledContextIds();
967         Set JavaDoc contextsAlreadyEnabled= new HashSet JavaDoc();
968         Iterator JavaDoc iter= contextIds.iterator();
969         while (iter.hasNext()) {
970             String JavaDoc contextId= (String JavaDoc) iter.next();
971             if (enabledContexts.contains(contextId) && !lastEnabledIds.contains(contextId)) {
972                 // If a context is already enabled, submitting it won't
973
// generate a callback from the workbench. So we inform
974
// our context listener ourselves.
975
// This covers the case where the user is selecting
976
// among elements from several enabled contexts.
977
contextsAlreadyEnabled.add(contextId);
978             }
979         }
980         lastEnabledIds.clear();
981         lastEnabledIds.addAll(contextIds);
982         submitContexts(contextIds, launch);
983         contextEnabled(contextsAlreadyEnabled);
984     }
985
986     /**
987      * Submits the given context IDs to the workbench context support
988      * on behalf of the given launch. When the launch terminates,
989      * the context submissions will be automatically removed.
990      *
991      * @param contextIds the contexts to submit
992      * @param launch the launch for which the contexts are being submitted
993      */

994     protected void submitContexts(List JavaDoc contextIds, ILaunch launch) {
995         List JavaDoc submissions = (List JavaDoc) fContextSubmissions.get(launch);
996         if (submissions == null) {
997             submissions= new ArrayList JavaDoc();
998             fContextSubmissions.put(launch, submissions);
999         }
1000        List JavaDoc newSubmissions= new ArrayList JavaDoc();
1001        Iterator JavaDoc iter= contextIds.iterator();
1002        while (iter.hasNext()) {
1003            newSubmissions.add(new EnabledSubmission(null, null, null, (String JavaDoc) iter.next()));
1004        }
1005        IWorkbenchContextSupport contextSupport = PlatformUI.getWorkbench().getContextSupport();
1006        if (!newSubmissions.isEmpty()) {
1007            contextSupport.addEnabledSubmissions(newSubmissions);
1008            // After adding the new submissions, remove any old submissions
1009
// that exist for the same context IDs. This prevents us from
1010
// building up a ton of redundant submissions.
1011
List JavaDoc submissionsToRemove= new ArrayList JavaDoc();
1012            ListIterator JavaDoc oldSubmissions= submissions.listIterator();
1013            while (oldSubmissions.hasNext()) {
1014                EnabledSubmission oldSubmission= (EnabledSubmission) oldSubmissions.next();
1015                String JavaDoc contextId = oldSubmission.getContextId();
1016                if (contextIds.contains(contextId)) {
1017                    oldSubmissions.remove();
1018                    submissionsToRemove.add(oldSubmission);
1019                }
1020            }
1021            contextSupport.removeEnabledSubmissions(submissionsToRemove);
1022            submissions.addAll(newSubmissions);
1023        }
1024    }
1025    
1026    /**
1027     * Notifies this view that the given launches have terminated. When a launch
1028     * terminates, remove all context submissions associated with it.
1029     *
1030     * @param launches the terminated launches
1031     */

1032    protected void launchesTerminated(ILaunch[] launches) {
1033        List JavaDoc allSubmissions= new ArrayList JavaDoc();
1034        for (int i = 0; i < launches.length; i++) {
1035            List JavaDoc submissions= (List JavaDoc) fContextSubmissions.remove(launches[i]);
1036            if (submissions != null) {
1037                allSubmissions.addAll(submissions);
1038            }
1039        }
1040        PlatformUI.getWorkbench().getContextSupport().removeEnabledSubmissions(allSubmissions);
1041    }
1042    
1043    /**
1044     * Returns the view identifier associated with the given extension
1045     * element or <code>null</code> if none.
1046     *
1047     * @param element the contextViewBinding extension element
1048     * @return the view identifier associated with the given element or <code>null</code>
1049     */

1050    public static String JavaDoc getViewId(IConfigurationElement element) {
1051        return element.getAttribute(ATTR_VIEW_ID);
1052    }
1053    
1054    /**
1055     * Returns whether the given configuration element is configured
1056     * for automatic view opening. The element's view should be automatically
1057     * opened if the autoOpen element is specified as true or if the autoOpen
1058     * element is unspecified.
1059     *
1060     * @param element the contextViewBinding extension element
1061     * @return whether or not given given configuration element's view
1062     * should be automatically opened
1063     */

1064    public static boolean isAutoOpen(IConfigurationElement element) {
1065        String JavaDoc autoOpen = element.getAttribute(ATTR_AUTO_OPEN);
1066        return autoOpen == null || Boolean.valueOf(autoOpen).booleanValue();
1067    }
1068    
1069    /**
1070     * Returns whether the given configuration element is configured
1071     * for automatic view closure. The element's view should be automatically
1072     * close if the autoClose element is specified as true or if the autoClose
1073     * element is unspecified.
1074     *
1075     * @param element the contextViewBinding extension element
1076     * @return whether or not given given configuration element's view
1077     * should be automatically closed
1078     */

1079    public static boolean isAutoClose(IConfigurationElement element) {
1080        String JavaDoc autoClose = element.getAttribute(ATTR_AUTO_CLOSE);
1081        return autoClose == null || Boolean.valueOf(autoClose).booleanValue();
1082    }
1083    
1084    /**
1085     * Returns whether this view automatically opens and closes
1086     * views based on contexts
1087     * @return whether or not this view automatically manages
1088     * views based on contexts
1089     */

1090    private boolean isAutoManageViews() {
1091        IWorkbenchPage page = launchView.getViewSite().getPage();
1092        if (page != null) {
1093            IPerspectiveDescriptor descriptor = page.getPerspective();
1094            if (descriptor != null) {
1095                return fAutoManagePerspectives.contains(descriptor.getId());
1096            }
1097        }
1098        return false;
1099    }
1100    
1101    /**
1102     * Returns the workbench page containing the launch view.
1103     *
1104     * @return the workbench page containing the launch view
1105     */

1106    public IWorkbenchPage getPage() {
1107        return launchView.getSite().getPage();
1108    }
1109    
1110    /**
1111     * Notifies this listener that the given perspective change
1112     * has occurred.
1113     *
1114     * Don't listen to part open/close notifications during reset.
1115     */

1116    public void perspectiveChanged(String JavaDoc changeId) {
1117        if (changeId.equals(IWorkbenchPage.CHANGE_RESET)) {
1118            fIsTrackingPartChanges= false;
1119        } else if (changeId.equals(IWorkbenchPage.CHANGE_RESET_COMPLETE)) {
1120            loadTrackViews();
1121        }
1122    }
1123    
1124    /**
1125     * Notifies this listener that the given perspective change
1126     * has occurred.
1127     *
1128     * When a part is opened/closed, do not close/open it automatically.
1129     */

1130    public void perspectiveChanged(IWorkbenchPartReference ref, String JavaDoc changeId) {
1131        if (!fIsTrackingPartChanges) {
1132            return;
1133        }
1134        if (IWorkbenchPage.CHANGE_VIEW_HIDE.equals(changeId) && (ref instanceof IViewReference)) {
1135            String JavaDoc id = ((IViewReference) ref).getId();
1136            if (managedViewIds.contains(id)) {
1137                viewIdsToNotOpen.add(id);
1138                saveViewsToNotOpen();
1139            }
1140            
1141            removeFromOpenedViews(id);
1142            saveOpenedViews();
1143        } else if (IWorkbenchPage.CHANGE_VIEW_SHOW.equals(changeId) && ref instanceof IViewReference) {
1144            String JavaDoc id = ((IViewReference) ref).getId();
1145            removeFromOpenedViews(id);
1146            saveOpenedViews();
1147        }
1148    }
1149
1150    /**
1151     * Givin a view id, this methods iterates through all the
1152     * managed perspective and remove the view from openedViewIds
1153     * @param viewId
1154     */

1155    private void removeFromOpenedViews(String JavaDoc viewId) {
1156        Iterator JavaDoc keys = openedViewIds.keySet().iterator();
1157        while (keys.hasNext())
1158        {
1159            String JavaDoc perspId = (String JavaDoc)keys.next();
1160            
1161            Set JavaDoc views = (Set JavaDoc)openedViewIds.get(perspId);
1162            if (views != null)
1163            {
1164                views.remove(viewId);
1165            }
1166        }
1167    }
1168    
1169    /**
1170     * Reads the preference specifying whether this view automatically
1171     * tracks views being opened and closed for the purpose of not
1172     * automatically managing those views once they've been opened/closed
1173     * manually.
1174     */

1175    public void loadTrackViews() {
1176        fIsTrackingPartChanges= DebugUITools.getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_TRACK_VIEWS);
1177    }
1178    
1179    /**
1180     * Load the collection of perspectives in which view
1181     * management will occur from the preference store.
1182     */

1183    private void loadAutoManagePerspectives() {
1184        String JavaDoc prefString = DebugUIPlugin.getDefault().getPreferenceStore().getString(IDebugUIConstants.PREF_MANAGE_VIEW_PERSPECTIVES);
1185        fAutoManagePerspectives= parseList(prefString);
1186    }
1187    
1188    /**
1189     * Reloaded the collection of view management perspectives
1190     * and updates (potentially opening views) for the given
1191     * selection.
1192     */

1193    public void reloadAutoManagePerspectives(Object JavaDoc selection) {
1194        // Remove the context ids associated with the current selection
1195
// so that updateForSelection(...) will open views
1196
// as appropriate given the new view management settings.
1197
String JavaDoc[] modelIds = getDebugModelIdsForSelection(selection);
1198        List JavaDoc contextIds = getContextsForModels(modelIds);
1199        lastEnabledIds.removeAll(contextIds);
1200        
1201        loadAutoManagePerspectives();
1202        updateForSelection(selection);
1203    }
1204    
1205    public void reloadViewsToNotOpen(Object JavaDoc selection) {
1206        // Remove the context ids associated with the current selection
1207
// so that updateForSelection(...) will open views
1208
// as appropriate given the new view management settings.
1209
String JavaDoc[] modelIds = getDebugModelIdsForSelection(selection);
1210        List JavaDoc contextIds = getContextsForModels(modelIds);
1211        lastEnabledIds.removeAll(contextIds);
1212        
1213        loadViewsToNotOpen();
1214        updateForSelection(selection);
1215    }
1216    
1217    /**
1218     * Parses the comma separated string into a list of strings
1219     *
1220     * @return list
1221     */

1222    public static List JavaDoc parseList(String JavaDoc listString) {
1223        List JavaDoc list = new ArrayList JavaDoc(10);
1224        StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(listString, ","); //$NON-NLS-1$
1225
while (tokenizer.hasMoreTokens()) {
1226            String JavaDoc token = tokenizer.nextToken();
1227            list.add(token);
1228        }
1229        return list;
1230    }
1231
1232    /**
1233     * The launch view associated with this context listener has
1234     * been disposed. Remove as a context listener.
1235     *
1236     */

1237    public void dispose() {
1238        IWorkbench workbench = PlatformUI.getWorkbench();
1239        workbench.getContextSupport().getContextManager().removeContextManagerListener(this);
1240        workbench.getActivitySupport().getActivityManager().removeActivityManagerListener(this);
1241    }
1242
1243    /**
1244     * Clears the cache of last enabled contexts. Called by the debug view when the pespective
1245     * changes.
1246     */

1247    protected void clearLastEnabledContexts() {
1248        lastEnabledIds.clear();
1249    }
1250
1251    /* (non-Javadoc)
1252     * @see org.eclipse.ui.activities.IActivityManagerListener#activityManagerChanged(org.eclipse.ui.activities.ActivityManagerEvent)
1253     */

1254    public void activityManagerChanged(ActivityManagerEvent activityManagerEvent) {
1255        if (activityManagerEvent.haveEnabledActivityIdsChanged()) {
1256            enabledActivities = activityManagerEvent.getActivityManager().getEnabledActivityIds();
1257        }
1258        
1259    }
1260
1261}
Popular Tags