Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 87587 | Differences between
and this patch

Collapse All | Expand All

(-)ui/org/eclipse/debug/internal/ui/DebugUIPlugin.java (-8 / +11 lines)
Lines 239-244 Link Here
239
	public DebugUIPlugin() {
239
	public DebugUIPlugin() {
240
		super();
240
		super();
241
		fgDebugUIPlugin= this;
241
		fgDebugUIPlugin= this;
242
		
243
		// make sure the perspective manager is created
244
		// and be the first debug event listener
245
		fPerspectiveManager = new PerspectiveManager();
246
		fPerspectiveManager.startup();
242
	}
247
	}
243
		
248
		
244
	/**
249
	/**
Lines 652-661 Link Here
652
		DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this);
657
		DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this);
653
		getProcessConsoleManager().startup();
658
		getProcessConsoleManager().startup();
654
		
659
		
655
		if (fPerspectiveManager == null) {
660
		// fPerspectiveManager created when DebugUIPlugin is constructed
656
			PerspectiveManager manager = getPerspectiveManager();
661
		// It should never be null.
657
			manager.launchAdded(launch);
662
		fPerspectiveManager.launchAdded(launch);
658
		}
659
		
663
		
660
		if (fStepFilterManager == null) {
664
		if (fStepFilterManager == null) {
661
			getStepFilterManager().launchAdded(launch);
665
			getStepFilterManager().launchAdded(launch);
Lines 670-679 Link Here
670
	 * @return
674
	 * @return
671
	 */
675
	 */
672
	public PerspectiveManager getPerspectiveManager() {
676
	public PerspectiveManager getPerspectiveManager() {
673
		if (fPerspectiveManager == null) {
677
674
			fPerspectiveManager = new PerspectiveManager();
678
		// fPerspectiveManager created when DebugUIPlugin is constructed
675
			fPerspectiveManager.startup();			
679
		// It should never be null.
676
		}
677
		return fPerspectiveManager;
680
		return fPerspectiveManager;
678
	}
681
	}
679
	
682
	
(-)ui/org/eclipse/debug/internal/ui/launchConfigurations/PerspectiveManager.java (-23 / +128 lines)
Lines 85-91 Link Here
85
	 * prompts at the same time.
85
	 * prompts at the same time.
86
	 */
86
	 */
87
	private boolean fPrompting;
87
	private boolean fPrompting;
88
	private PerspectiveSwitchLock fPerspectiveSwitchLock = new PerspectiveSwitchLock();
89
	
90
	/**
91
	 * Flag to indicate that the workench may be switching perspective.
92
	 * When PerspectiveManager gets a suspend event and the workbench may require
93
	 * too switch perspective, the manager sets this lock to equal to true.  When the manager
94
	 * has finished processing the event and the workbench is in the correct perspective, the
95
	 * manager sets this lock to false.
96
	 * 
97
	 * In LaunchViewContextListener, before trying to open views associated with enabled context, 
98
	 * the listener checks with this manager to determine if it is possible to switch perspective.
99
	 * If so, the listener wait on this lock.  When the listener receives a notify from this lock,
100
	 * the listener wakes up and checks to see if views need to be opened from the current
101
	 * perspective.
102
	 */
103
	public class PerspectiveSwitchLock
104
	{
105
106
		private boolean fIsSwithingPerspective = false;
88
		
107
		
108
		public void setSwitchingPerspective(boolean b)
109
		{
110
			fIsSwithingPerspective = b;
111
		}
112
		
113
		public boolean isSwitchingPerspective()
114
		{
115
			return fIsSwithingPerspective;
116
		}
117
	}
118
	
119
	
89
	/**
120
	/**
90
	 * Called by the debug ui plug-in on startup.
121
	 * Called by the debug ui plug-in on startup.
91
	 * The perspective manager starts listening for
122
	 * The perspective manager starts listening for
Lines 131-136 Link Here
131
	 * @see ILaunchListener#launchAdded(ILaunch)
162
	 * @see ILaunchListener#launchAdded(ILaunch)
132
	 */
163
	 */
133
	public void launchAdded(ILaunch launch) {
164
	public void launchAdded(ILaunch launch) {
165
		
166
		boolean unlock = false;
167
		synchronized(fPerspectiveSwitchLock)
168
		{
169
			if (!isSwitchingPerspective())
170
			{
171
				fPerspectiveSwitchLock.setSwitchingPerspective(true);
172
				unlock = true;
173
			}
174
		}
175
		final boolean unlockLater = unlock;
176
		
134
		String perspectiveId = null;
177
		String perspectiveId = null;
135
		// check event filters
178
		// check event filters
136
		try {
179
		try {
Lines 152-164 Link Here
152
		// switch
195
		// switch
153
		async(new Runnable() {
196
		async(new Runnable() {
154
			public void run() {
197
			public void run() {
155
				IWorkbenchWindow window = getWindowForPerspective(id);
198
				try
156
				if (id != null && window != null && shouldSwitchPerspectiveForLaunch(window, id)) {
199
				{
157
					switchToPerspective(window, id);
200
					IWorkbenchWindow window = getWindowForPerspective(id);
201
					if (id != null && window != null && shouldSwitchPerspectiveForLaunch(window, id)) {
202
						switchToPerspective(window, id);
203
					}
204
				}
205
				finally
206
				{
207
					synchronized(fPerspectiveSwitchLock)
208
					{
209
						if (unlockLater)
210
						{
211
							fPerspectiveSwitchLock.setSwitchingPerspective(false);
212
							fPerspectiveSwitchLock.notifyAll();
213
						}
214
					}
158
				}
215
				}
159
			}
216
			}
160
		});
217
		});
161
		
162
	}
218
	}
163
219
164
220
Lines 284-289 Link Here
284
	 * @param event the suspend event
340
	 * @param event the suspend event
285
	 */
341
	 */
286
	private void handleBreakpointHit(DebugEvent event) {
342
	private void handleBreakpointHit(DebugEvent event) {
343
		
344
		// Must be called here to indicate that the perspective
345
		// may be switching.
346
		// Putting this in the async UI call will cause the Perspective
347
		// Manager to turn on the lock too late.  Consequently, LaunchViewContextListener
348
		// may not know that the perspective will switch and will open view before
349
		// the perspective switch.
350
		boolean unlock = false;
351
		synchronized(fPerspectiveSwitchLock)
352
		{
353
			if (!isSwitchingPerspective())
354
			{
355
				fPerspectiveSwitchLock.setSwitchingPerspective(true);
356
				unlock = true;
357
			}
358
		}
359
		final boolean unlockLater = unlock;
360
		
287
		// apply event filters
361
		// apply event filters
288
		ILaunch launch= null;
362
		ILaunch launch= null;
289
		Object source = event.getSource();
363
		Object source = event.getSource();
Lines 307-340 Link Here
307
		Runnable r = new Runnable() {
381
		Runnable r = new Runnable() {
308
			public void run() {
382
			public void run() {
309
				IWorkbenchWindow window = null;
383
				IWorkbenchWindow window = null;
384
				try{
310
				if (targetId != null) {
385
				if (targetId != null) {
311
					window = getWindowForPerspective(targetId);
312
					if (window == null) {
313
						return;
314
					}
315
					if (shouldSwitchPerspectiveForSuspend(window, targetId)) {
316
						switchToPerspective(window, targetId);
317
						// Showing the perspective can open a new window
318
						// (based on user prefs). So check again in case a
319
						// new window has been opened.
320
						window = getWindowForPerspective(targetId);
386
						window = getWindowForPerspective(targetId);
321
						if (window == null) {
387
						if (window == null) {
322
							return;
388
							return;
323
						}
389
						}
324
					}
390
						
325
					// re-open the window if minimized 
391
						if (shouldSwitchPerspectiveForSuspend(window, targetId)) {
326
					Shell shell= window.getShell();
392
							switchToPerspective(window, targetId);
327
					if (shell != null) {
393
							// Showing the perspective can open a new window
328
						if (shell.getMinimized()) {
394
							// (based on user prefs). So check again in case a
329
							shell.setMinimized(false);
395
							// new window has been opened.
396
							window = getWindowForPerspective(targetId);
397
							if (window == null) {
398
								return;
399
							}
330
						}
400
						}
331
						if (DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IDebugUIConstants.PREF_ACTIVATE_WORKBENCH)) {
401
						// re-open the window if minimized 
332
							shell.forceActive();
402
						Shell shell= window.getShell();
403
						if (shell != null) {
404
							if (shell.getMinimized()) {
405
								shell.setMinimized(false);
406
							}
407
							if (DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IDebugUIConstants.PREF_ACTIVATE_WORKBENCH)) {
408
								shell.forceActive();
409
							}
333
						}
410
						}
334
					}
411
					}
412
					if (window != null && DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_ACTIVATE_DEBUG_VIEW)) {
413
						showDebugView(window);
414
					}
335
				}
415
				}
336
				if (window != null && DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_ACTIVATE_DEBUG_VIEW)) {
416
				finally
337
					showDebugView(window);
417
				{
418
					synchronized(fPerspectiveSwitchLock)
419
					{
420
						if (unlockLater)
421
						{
422
							fPerspectiveSwitchLock.setSwitchingPerspective(false);
423
							fPerspectiveSwitchLock.notifyAll();
424
						}
425
					}
338
				}
426
				}
339
			}
427
			}
340
		};
428
		};
Lines 742-745 Link Here
742
		
830
		
743
	}
831
	}
744
	
832
	
833
	/**
834
	 * @return if the perspective manager is in the process of switching perspective.
835
	 */
836
	public boolean isSwitchingPerspective()
837
	{
838
		return fPerspectiveSwitchLock.isSwitchingPerspective();
839
	}
840
	
841
	/**
842
	 * @return the lock to wait on if the manger is switching perspective.
843
	 * The lock will notify when the manager has finished switching perspective.
844
	 */
845
	public PerspectiveSwitchLock getPerspectiveSwitchLock()
846
	{
847
		return fPerspectiveSwitchLock;
848
	}
849
	
745
}
850
}
(-)ui/org/eclipse/debug/internal/ui/views/launch/LaunchViewContextListener.java (-73 / +154 lines)
Lines 24-30 Link Here
24
import org.eclipse.core.runtime.IAdaptable;
24
import org.eclipse.core.runtime.IAdaptable;
25
import org.eclipse.core.runtime.IConfigurationElement;
25
import org.eclipse.core.runtime.IConfigurationElement;
26
import org.eclipse.core.runtime.IExtensionPoint;
26
import org.eclipse.core.runtime.IExtensionPoint;
27
import org.eclipse.core.runtime.IProgressMonitor;
28
import org.eclipse.core.runtime.IStatus;
27
import org.eclipse.core.runtime.Platform;
29
import org.eclipse.core.runtime.Platform;
30
import org.eclipse.core.runtime.Status;
31
import org.eclipse.core.runtime.jobs.Job;
28
import org.eclipse.debug.core.ILaunch;
32
import org.eclipse.debug.core.ILaunch;
29
import org.eclipse.debug.core.model.IDebugElement;
33
import org.eclipse.debug.core.model.IDebugElement;
30
import org.eclipse.debug.core.model.IDebugModelProvider;
34
import org.eclipse.debug.core.model.IDebugModelProvider;
Lines 32-37 Link Here
32
import org.eclipse.debug.core.model.IStackFrame;
36
import org.eclipse.debug.core.model.IStackFrame;
33
import org.eclipse.debug.internal.ui.DebugUIPlugin;
37
import org.eclipse.debug.internal.ui.DebugUIPlugin;
34
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
38
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
39
import org.eclipse.debug.internal.ui.launchConfigurations.PerspectiveManager;
35
import org.eclipse.debug.ui.DebugUITools;
40
import org.eclipse.debug.ui.DebugUITools;
36
import org.eclipse.debug.ui.IDebugUIConstants;
41
import org.eclipse.debug.ui.IDebugUIConstants;
37
import org.eclipse.jface.preference.IPreferenceStore;
42
import org.eclipse.jface.preference.IPreferenceStore;
Lines 56-61 Link Here
56
import org.eclipse.ui.contexts.IContextManagerListener;
61
import org.eclipse.ui.contexts.IContextManagerListener;
57
import org.eclipse.ui.contexts.IWorkbenchContextSupport;
62
import org.eclipse.ui.contexts.IWorkbenchContextSupport;
58
import org.eclipse.ui.contexts.NotDefinedException;
63
import org.eclipse.ui.contexts.NotDefinedException;
64
import org.eclipse.ui.progress.UIJob;
59
65
60
/**
66
/**
61
 * A context listener which automatically opens/closes/activates views in
67
 * A context listener which automatically opens/closes/activates views in
Lines 530-616 Link Here
530
	 * @param contextId the ID of the context that has been
536
	 * @param contextId the ID of the context that has been
531
	 * 	enabled
537
	 * 	enabled
532
	 */
538
	 */
533
	public void contextEnabled(Set contextIds) {
539
	public void contextEnabled(final Set contextIds) {
534
		if (!isAutoManageViews()) {
540
		if (!isAutoManageViews()) {
535
			return;
541
			return;
536
		}
542
		}
537
		IWorkbenchPage page= getPage();
538
		// We ignore the "Debugging" context since we use it
539
		// to provide a base set of views for other context
540
		// bindings to inherit. If we don't ignore it, we'll
541
		// end up opening those views whenever a debug session
542
		// starts, which is not the desired behavior.
543
		contextIds.remove(DEBUG_CONTEXT);
544
		if (page == null || contextIds.size() == 0) {
545
			return;
546
		}
547
		Set viewsToShow= new HashSet();
548
		Set viewsToOpen= new HashSet();
549
		computeViewActivation(contextIds, viewsToOpen, viewsToShow);
550
		
543
		
551
		boolean resetTrackingPartChanges = false;
544
		final UIJob openViewsJob = new UIJob("Open Context-Enabled Views") { //$NON-NLS-1$
552
		if (fIsTrackingPartChanges)
545
			public IStatus runInUIThread(IProgressMonitor monitor) {
553
		{
546
				IWorkbenchPage page =  getPage();
554
			// only change the flag if it is currently
547
				if (page == null)
555
			// tracking part changes.
548
					return Status.OK_STATUS;
556
			fIsTrackingPartChanges= false;
549
				
557
			resetTrackingPartChanges = true;
550
				// Since we run this job asynchronously on the UI Thread,
558
		}
551
				// #getPerspective() may return null when this job is run
559
		
552
				// when the workbench is shutting down.
560
		Iterator iterator= viewsToOpen.iterator();
553
				if (page.getPerspective() == null)
561
		
554
					return Status.OK_STATUS;
562
		String id = page.getPerspective().getId();
555
				
563
		Set views = (Set)openedViewIds.get(id);
556
				// We ignore the "Debugging" context since we use it
564
		if (views == null)
557
				// to provide a base set of views for other context
565
		{
558
				// bindings to inherit. If we don't ignore it, we'll
566
			views = new HashSet();
559
				// end up opening those views whenever a debug session
567
		}
560
				// starts, which is not the desired behavior.
568
		
561
				contextIds.remove(DEBUG_CONTEXT);
569
		while (iterator.hasNext()) {
562
				if (page == null || contextIds.size() == 0) {
570
			String viewId = (String) iterator.next();
563
					return Status.OK_STATUS;
571
			try {
564
				}
572
				IViewPart view = page.showView(viewId, null, IWorkbenchPage.VIEW_CREATE);
565
				Set viewsToShow = new HashSet();
573
				views.add(viewId);
566
				Set viewsToOpen = new HashSet();
574
567
				computeViewActivation(contextIds, viewsToOpen, viewsToShow);
575
				viewsToShow.add(view);
568
576
			} catch (PartInitException e) {
569
				boolean resetTrackingPartChanges = false;
577
				DebugUIPlugin.log(e.getStatus());
570
				if (fIsTrackingPartChanges) {
571
					// only change the flag if it is currently
572
					// tracking part changes.
573
					fIsTrackingPartChanges = false;
574
					resetTrackingPartChanges = true;
575
				}
576
577
				Iterator iterator = viewsToOpen.iterator();
578
579
				String id = page.getPerspective().getId();
580
				Set views = (Set) openedViewIds.get(id);
581
				if (views == null) {
582
					views = new HashSet();
583
				}
584
585
				while (iterator.hasNext()) {
586
					String viewId = (String) iterator.next();
587
					try {
588
						IViewPart view = page.showView(viewId, null,
589
								IWorkbenchPage.VIEW_CREATE);
590
						views.add(viewId);
591
592
						viewsToShow.add(view);
593
					} catch (PartInitException e) {
594
						DebugUIPlugin.log(e.getStatus());
595
					}
596
				}
597
598
				if (!viewsToOpen.isEmpty()) {
599
					openedViewIds.put(id, views);
600
					saveOpenedViews();
601
				}
602
				iterator = viewsToShow.iterator();
603
				while (iterator.hasNext()) {
604
					boolean activate = true;
605
					IViewPart view = (IViewPart) iterator.next();
606
					IViewPart[] stackedViews = page.getViewStack(view);
607
					if (stackedViews == null) {
608
						continue;
609
					}
610
					// For each applicable view, iterate through the view stack.
611
					// If we find that view before any other applicable views,
612
					// show it. Otherwise, don't.
613
					for (int i = 0; i < stackedViews.length; i++) {
614
						IViewPart stackedView = stackedViews[i];
615
						if (view == stackedView) {
616
							break;
617
						} else if (viewsToShow.contains(stackedView)) {
618
							// If this view is below an appropriate view, don't
619
							// show it
620
							activate = false;
621
							break;
622
						}
623
					}
624
					if (activate) {
625
						page.bringToTop(view);
626
					}
627
				}
628
629
				// Reset if we have previously changed this setting
630
				if (resetTrackingPartChanges)
631
					loadTrackViews();
632
				
633
				return Status.OK_STATUS;
578
			}
634
			}
579
		}
635
		};
580
		
636
		
581
		if (!viewsToOpen.isEmpty()) {
637
		openViewsJob.setSystem(true);
582
			openedViewIds.put(id, views);
638
583
			saveOpenedViews();
639
		final PerspectiveManager manager = DebugUIPlugin.getDefault().getPerspectiveManager();
584
		}
640
		if (manager.isSwitchingPerspective()) {
585
		iterator= viewsToShow.iterator();
641
			Job waitForPerspectiveSwitch = new Job("Wait For Perspective Switch") { //$NON-NLS-1$
586
		while (iterator.hasNext()) {
642
587
			boolean activate= true;
643
				protected IStatus run(IProgressMonitor monitor) {
588
			IViewPart view = (IViewPart) iterator.next();
644
					if (manager.isSwitchingPerspective()) {
589
			IViewPart[] stackedViews = page.getViewStack(view);
645
						synchronized (manager.getPerspectiveSwitchLock()) {
590
			if (stackedViews == null) {
646
							try {
591
				continue;
647
								manager.getPerspectiveSwitchLock().wait();
592
			}
648
							} catch (InterruptedException e) {
593
			// For each applicable view, iterate through the view stack.
649
594
			// If we find that view before any other applicable views,
650
							}
595
			// show it. Otherwise, don't.
651
						}
596
			for (int i = 0; i < stackedViews.length; i++) {
652
					}
597
				IViewPart stackedView= stackedViews[i];
653
					openViewsJob.schedule();
598
				if (view == stackedView) {
654
					
599
					break;
655
					return Status.OK_STATUS;
600
				} else if (viewsToShow.contains(stackedView)) {
601
					// If this view is below an appropriate view, don't show it
602
					activate= false;
603
					break;
604
				}
656
				}
657
			};
658
			
659
			waitForPerspectiveSwitch.setSystem(true);
660
			// do not wait if no view needs to be opened
661
			if (isBoundToViews(contextIds))
662
				waitForPerspectiveSwitch.schedule();
663
		} else
664
		{
665
			// do not schedule openViewsJob if no view needs to be opened
666
			if(isBoundToViews(contextIds))
667
			{
668
				openViewsJob.schedule();
605
			}
669
			}
606
			if (activate) {
670
		}
607
				page.bringToTop(view);
671
	}
608
			}
672
	
673
	/**
674
	 * @param contextIds
675
	 * @return if the specified the context ids are tied
676
	 * to any context-enabled views.
677
	 */
678
	private boolean isBoundToViews(Set contextIds)
679
	{
680
		Set possibleViewsToShow = new HashSet();
681
		Iterator iter = contextIds.iterator();
682
		while (iter.hasNext())
683
		{
684
			String contextId = (String)iter.next();
685
			Set viewIds = getApplicableViewIds(contextId);
686
			possibleViewsToShow.addAll(viewIds);
609
		}
687
		}
610
		
688
		
611
		// Reset if we have previously changed this setting
689
		return !possibleViewsToShow.isEmpty();		
612
		if (resetTrackingPartChanges)
613
			loadTrackViews();
614
	}
690
	}
615
	
691
	
616
	/**
692
	/**
Lines 661-667 Link Here
661
	 * @param contexts
737
	 * @param contexts
662
	 */
738
	 */
663
	public void contextsDisabled(Set contexts) {
739
	public void contextsDisabled(Set contexts) {
664
		IWorkbenchPage page= getPage();
740
		IWorkbenchPage page=  getPage();
665
		if (page == null || contexts.size() == 0 || !isAutoManageViews()) {
741
		if (page == null || contexts.size() == 0 || !isAutoManageViews()) {
666
			return;
742
			return;
667
		}
743
		}
Lines 715-721 Link Here
715
		Set viewIdsToClose= new HashSet();
791
		Set viewIdsToClose= new HashSet();
716
		Set viewIdsToKeepOpen= getViewIdsForEnabledContexts();
792
		Set viewIdsToKeepOpen= getViewIdsForEnabledContexts();
717
		Iterator contexts = contextIds.iterator();
793
		Iterator contexts = contextIds.iterator();
718
		String currentPerspId = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getPerspective().getId();
794
		IWorkbenchPage page = getPage();
795
		if (page == null)
796
			return viewIdsToClose;
797
		if (page.getPerspective() == null)
798
			return viewIdsToClose;
799
		String currentPerspId = page.getPerspective().getId();
719
		Set viewIds = (Set)openedViewIds.get(currentPerspId);
800
		Set viewIds = (Set)openedViewIds.get(currentPerspId);
720
		while (contexts.hasNext()) {
801
		while (contexts.hasNext()) {
721
			String contextId = (String) contexts.next();
802
			String contextId = (String) contexts.next();

Return to bug 87587