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 174213 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/internal/UIPreferenceInitializer.java (+3 lines)
Lines 150-155 Link Here
150
		
150
		
151
		// By default the Fast View Bar allows to select a new fast view from the view list
151
		// By default the Fast View Bar allows to select a new fast view from the view list
152
		node.putBoolean(IWorkbenchPreferenceConstants.DISABLE_NEW_FAST_VIEW, false);
152
		node.putBoolean(IWorkbenchPreferenceConstants.DISABLE_NEW_FAST_VIEW, false);
153
		
154
		// Default the sticky view close behaviour to the new style
155
		node.putBoolean(IWorkbenchPreferenceConstants.ENABLE_32_STICKY_CLOSE_BEHAVIOR, false);
153
156
154
		IEclipsePreferences rootNode = (IEclipsePreferences) Platform
157
		IEclipsePreferences rootNode = (IEclipsePreferences) Platform
155
				.getPreferencesService().getRootNode()
158
				.getPreferencesService().getRootNode()
(-)Eclipse UI/org/eclipse/ui/IWorkbenchPreferenceConstants.java (+12 lines)
Lines 451-454 Link Here
451
	 * @since 3.3
451
	 * @since 3.3
452
	 */
452
	 */
453
	public static final String DISABLE_NEW_FAST_VIEW = "disableNewFastView"; //$NON-NLS-1$
453
	public static final String DISABLE_NEW_FAST_VIEW = "disableNewFastView"; //$NON-NLS-1$
454
	
455
	/**
456
     * A named preference for enabling the 3.2 behavior for closing sticky views.
457
     * When not enabled a sticky view is closed in all perspectives when the view is closed.
458
     * <p>
459
     * The default value for this preference is: <code>false</code>; use the 3.2
460
     * behaviour.
461
     * </p>
462
     * 
463
     * @since 3.3
464
     */
465
	public static final String ENABLE_32_STICKY_CLOSE_BEHAVIOR = "ENABLE_32_STICKY_CLOSE_BEHAVIOR"; //$NON-NLS-1$
454
}
466
}
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java (-73 / +14 lines)
Lines 17-27 Link Here
17
import java.util.Collection;
17
import java.util.Collection;
18
import java.util.Collections;
18
import java.util.Collections;
19
import java.util.Comparator;
19
import java.util.Comparator;
20
import java.util.HashMap;
21
import java.util.HashSet;
20
import java.util.HashSet;
22
import java.util.Iterator;
21
import java.util.Iterator;
23
import java.util.List;
22
import java.util.List;
24
import java.util.Map;
25
import java.util.Set;
23
import java.util.Set;
26
import java.util.StringTokenizer;
24
import java.util.StringTokenizer;
27
25
Lines 109-116 Link Here
109
import org.eclipse.ui.model.IWorkbenchAdapter;
107
import org.eclipse.ui.model.IWorkbenchAdapter;
110
import org.eclipse.ui.part.MultiEditor;
108
import org.eclipse.ui.part.MultiEditor;
111
import org.eclipse.ui.presentations.IStackPresentationSite;
109
import org.eclipse.ui.presentations.IStackPresentationSite;
112
import org.eclipse.ui.views.IStickyViewDescriptor;
113
import org.eclipse.ui.views.IViewRegistry;
114
110
115
/**
111
/**
116
 * A collection of views and editors in a workbench.
112
 * A collection of views and editors in a workbench.
Lines 155-160 Link Here
155
    private PerspectiveDescriptor deferredActivePersp;
151
    private PerspectiveDescriptor deferredActivePersp;
156
152
157
    private NavigationHistory navigationHistory = new NavigationHistory(this);
153
    private NavigationHistory navigationHistory = new NavigationHistory(this);
154
    
155
    private IStickyViewManager stickyViewMan = StickyViewManager.getInstance(this);
158
156
159
    /**
157
    /**
160
     * If we're in the process of activating a part, this points to the new part.
158
     * If we're in the process of activating a part, this points to the new part.
Lines 189-198 Link Here
189
        }
187
        }
190
    };
188
    };
191
189
192
    // a mapping of perspectives to a set of stickyviews that have been activated in that perspective.
193
    // this map is persisted across sessions
194
    private Map stickyPerspectives = new HashMap(7);
195
196
    private ActionSwitcher actionSwitcher = new ActionSwitcher();
190
    private ActionSwitcher actionSwitcher = new ActionSwitcher();
197
191
198
	private IExtensionTracker tracker;
192
	private IExtensionTracker tracker;
Lines 1657-1663 Link Here
1657
1651
1658
        navigationHistory.dispose();
1652
        navigationHistory.dispose();
1659
1653
1660
        stickyPerspectives.clear();
1654
        stickyViewMan.clear();
1661
        
1655
        
1662
        if (tracker != null) {
1656
        if (tracker != null) {
1663
			tracker.close();
1657
			tracker.close();
Lines 1686-1692 Link Here
1686
        }
1680
        }
1687
        persp.dispose();
1681
        persp.dispose();
1688
1682
1689
        stickyPerspectives.remove(persp.getDesc().getId());
1683
        stickyViewMan.remove(persp.getDesc().getId());
1690
    }
1684
    }
1691
1685
1692
    /**
1686
    /**
Lines 3028-3052 Link Here
3028
					navigationHistory.markEditor(getActiveEditor());
3022
					navigationHistory.markEditor(getActiveEditor());
3029
				}
3023
				}
3030
                
3024
                
3031
                IMemento stickyState = memento
3025
                // restore sticky view state
3032
						.getChild(IWorkbenchConstants.TAG_STICKY_STATE);
3026
                stickyViewMan.restore(memento);
3033
				// restore the sticky activation state
3027
                    
3034
3035
				if (stickyState != null) {
3036
					IMemento[] stickyPerspMems = stickyState
3037
							.getChildren(IWorkbenchConstants.TAG_PERSPECTIVE);
3038
					for (int i = 0; i < stickyPerspMems.length; i++) {
3039
						String perspectiveId = stickyPerspMems[i].getID();
3040
						Set viewState = new HashSet(7);
3041
						stickyPerspectives.put(perspectiveId, viewState);
3042
						IMemento[] viewStateMementos = stickyPerspMems[i]
3043
								.getChildren(IWorkbenchConstants.TAG_VIEW);
3044
						for (int j = 0; j < viewStateMementos.length; j++) {
3045
							viewState.add(viewStateMementos[j].getID());
3046
						}
3047
					}
3048
3049
				}                
3050
                return result;
3028
                return result;
3051
            } finally {
3029
            } finally {
3052
            	String blame = activeDescriptor == null ? pageName : activeDescriptor.getId();
3030
            	String blame = activeDescriptor == null ? pageName : activeDescriptor.getId();
Lines 3208-3229 Link Here
3208
        navigationHistory.saveState(memento
3186
        navigationHistory.saveState(memento
3209
                .createChild(IWorkbenchConstants.TAG_NAVIGATION_HISTORY));
3187
                .createChild(IWorkbenchConstants.TAG_NAVIGATION_HISTORY));
3210
        
3188
        
3211
        IMemento stickyState = memento
3189
        
3212
				.createChild(IWorkbenchConstants.TAG_STICKY_STATE);
3190
        // save the sticky activation state
3213
		// save the sticky activation state
3191
        stickyViewMan.save(memento);
3214
		itr = stickyPerspectives.entrySet().iterator();
3192
        
3215
		while (itr.hasNext()) {
3216
			Map.Entry entry = (Map.Entry) itr.next();
3217
			String perspectiveId = (String) entry.getKey();
3218
			Set activatedViewIds = (Set) entry.getValue();
3219
			IMemento perspectiveState = stickyState.createChild(
3220
					IWorkbenchConstants.TAG_PERSPECTIVE, perspectiveId);
3221
			for (Iterator i = activatedViewIds.iterator(); i.hasNext();) {
3222
				String viewId = (String) i.next();
3223
				perspectiveState.createChild(IWorkbenchConstants.TAG_VIEW,
3224
						viewId);
3225
			}
3226
		}
3227
		return result;
3193
		return result;
3228
    }
3194
    }
3229
    
3195
    
Lines 3386-3419 Link Here
3386
            // Update the window
3352
            // Update the window
3387
            window.updateActionSets();
3353
            window.updateActionSets();
3388
3354
3389
	        if (newPersp != null && oldPersp != null) {
3355
            // Update sticky views
3390
	        		Set activatedStickyViewsInThisPerspective = (Set) stickyPerspectives.get(newPersp.getDesc().getId());
3356
            stickyViewMan.update(oldPersp, newPersp);
3391
	        		if (activatedStickyViewsInThisPerspective == null) {
3357
            
3392
	        			activatedStickyViewsInThisPerspective = new HashSet(7);
3393
	        			stickyPerspectives.put(newPersp.getDesc().getId(), activatedStickyViewsInThisPerspective);
3394
	        		}
3395
	            
3396
                IViewRegistry viewReg = WorkbenchPlugin.getDefault()
3397
                        .getViewRegistry();
3398
                IStickyViewDescriptor[] stickyDescs = viewReg.getStickyViews();
3399
                for (int i = 0; i < stickyDescs.length; i++) {
3400
                    final String viewId = stickyDescs[i].getId();
3401
					try {
3402
                        // show a sticky view if it was in the last perspective and hasn't already been activated in this one
3403
                        if (oldPersp.findView(viewId) != null
3404
								&& !activatedStickyViewsInThisPerspective
3405
										.contains(viewId)) {
3406
							showView(viewId, null,
3407
									IWorkbenchPage.VIEW_CREATE);
3408
							activatedStickyViewsInThisPerspective.add(viewId);
3409
						}
3410
                    } catch (PartInitException e) {
3411
                        WorkbenchPlugin
3412
                                .log(
3413
                                        "Could not open view :" + viewId, new Status(IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH, IStatus.ERROR, "Could not open view :" + viewId, e)); //$NON-NLS-1$ //$NON-NLS-2$
3414
                    }
3415
                }
3416
            }
3417
        } finally {
3358
        } finally {
3418
            window.largeUpdateEnd();
3359
            window.largeUpdateEnd();
3419
            if (newPersp == null) {
3360
            if (newPersp == null) {
(-)Eclipse (+130 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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
12
package org.eclipse.ui.internal;
13
14
import java.util.Set;
15
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.Status;
18
import org.eclipse.jface.preference.IPreferenceStore;
19
import org.eclipse.ui.IMemento;
20
import org.eclipse.ui.IWorkbenchPage;
21
import org.eclipse.ui.IWorkbenchPreferenceConstants;
22
import org.eclipse.ui.PartInitException;
23
import org.eclipse.ui.internal.util.PrefUtil;
24
import org.eclipse.ui.views.IStickyViewDescriptor;
25
import org.eclipse.ui.views.IViewRegistry;
26
27
/**
28
 * @since 3.3
29
 * 
30
 */
31
public class StickyViewManager implements IStickyViewManager {
32
	
33
	private IWorkbenchPage page;
34
	
35
	public StickyViewManager(IWorkbenchPage page) {
36
		this.page = page;
37
	}
38
39
	
40
	public static IStickyViewManager getInstance(IWorkbenchPage page) {
41
		IStickyViewManager stickyViewMan;
42
		IPreferenceStore preferenceStore = PrefUtil.getAPIPreferenceStore();
43
		boolean enable32Behavior = preferenceStore
44
				.getBoolean(IWorkbenchPreferenceConstants.ENABLE_32_STICKY_CLOSE_BEHAVIOR);
45
		if (enable32Behavior)
46
			stickyViewMan = new StickyViewManager32(page);
47
		else 
48
			stickyViewMan = new StickyViewManager(page);
49
		
50
		return stickyViewMan;
51
	}
52
	
53
	/*
54
	 * (non-Javadoc)
55
	 * 
56
	 * @see org.eclipse.ui.internal.IStickyViewManager#add(java.lang.String,
57
	 *      java.util.Set)
58
	 */
59
	public void add(String perspectiveId, Set stickyViewSet) {
60
		// do nothing
61
	}
62
63
	/*
64
	 * (non-Javadoc)
65
	 * 
66
	 * @see org.eclipse.ui.internal.IStickyViewManager#clear()
67
	 */
68
	public void clear() {
69
		// do nothing
70
	}
71
72
	/*
73
	 * (non-Javadoc)
74
	 * 
75
	 * @see org.eclipse.ui.internal.IStickyViewManager#remove(java.lang.String)
76
	 */
77
	public void remove(String perspectiveId) {
78
		// do nothing
79
	}
80
81
	/*
82
	 * (non-Javadoc)
83
	 * 
84
	 * @see org.eclipse.ui.internal.IStickyViewManager#restore(org.eclipse.ui.IMemento)
85
	 */
86
	public void restore(IMemento memento) {
87
		// do nothing
88
	}
89
90
	/*
91
	 * (non-Javadoc)
92
	 * 
93
	 * @see org.eclipse.ui.internal.IStickyViewManager#save(org.eclipse.ui.IMemento)
94
	 */
95
	public void save(IMemento memento) {
96
		// do nothing
97
	}
98
99
	/*
100
	 * (non-Javadoc)
101
	 * 
102
	 * @see org.eclipse.ui.internal.IStickyViewManager#update(org.eclipse.ui.internal.Perspective,
103
	 *      org.eclipse.ui.internal.Perspective)
104
	 */
105
	public void update(Perspective oldPersp, Perspective newPersp) {
106
		IViewRegistry viewReg = WorkbenchPlugin.getDefault().getViewRegistry();
107
		IStickyViewDescriptor[] stickyDescs = viewReg.getStickyViews();
108
		for (int i = 0; i < stickyDescs.length; i++) {
109
			final String viewId = stickyDescs[i].getId();
110
			try {
111
				// show a sticky view if it was in the last perspective and
112
				// hasn't already been activated in this one
113
				if (oldPersp.findView(viewId) != null) {
114
					page.showView(viewId, null, IWorkbenchPage.VIEW_CREATE);
115
				}
116
				// remove a view if it's sticky and its not visible in the old
117
				// perspective
118
				else if (newPersp.findView(viewId) != null
119
						&& oldPersp.findView(viewId) == null) {
120
					page.hideView(newPersp.findView(viewId));
121
				}
122
			} catch (PartInitException e) {
123
				WorkbenchPlugin
124
						.log(
125
								"Could not open view :" + viewId, new Status(IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH, IStatus.ERROR, "Could not open view :" + viewId, e)); //$NON-NLS-1$ //$NON-NLS-2$
126
			}
127
		}
128
	}
129
130
}
(-)Eclipse (+36 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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
12
package org.eclipse.ui.internal;
13
14
import java.util.Set;
15
16
import org.eclipse.ui.IMemento;
17
18
/**
19
 * @since 3.3
20
 *
21
 */
22
interface IStickyViewManager {
23
	
24
	void remove(String perspectiveId);
25
	
26
	void add(String perspectiveId, Set stickyViewSet);
27
	
28
	void clear();
29
	
30
	void update(Perspective oldPersp, Perspective newPersp);
31
	
32
	void save(IMemento memento);
33
	 
34
	void restore(IMemento memento);
35
36
}
(-)Eclipse (+142 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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
12
package org.eclipse.ui.internal;
13
14
import java.util.HashMap;
15
import java.util.HashSet;
16
import java.util.Iterator;
17
import java.util.Map;
18
import java.util.Set;
19
20
import org.eclipse.core.runtime.IStatus;
21
import org.eclipse.core.runtime.Status;
22
import org.eclipse.ui.IMemento;
23
import org.eclipse.ui.IWorkbenchPage;
24
import org.eclipse.ui.PartInitException;
25
import org.eclipse.ui.views.IStickyViewDescriptor;
26
import org.eclipse.ui.views.IViewRegistry;
27
28
/**
29
 * @since 3.3
30
 *
31
 */
32
class StickyViewManager32 implements IStickyViewManager {
33
34
	// a mapping of perspectives to a set of stickyviews that have been activated in that perspective.
35
	// this map is persisted across sessions
36
	private Map stickyPerspectives = new HashMap(7);
37
	
38
	private IWorkbenchPage page;
39
	
40
	public StickyViewManager32(IWorkbenchPage page) {
41
		this.page = page;
42
	}
43
44
	/* (non-Javadoc)
45
	 * @see org.eclipse.ui.internal.IStickyViewManager#remove(java.lang.String)
46
	 */
47
	public void remove(String pespectiveId) {
48
		stickyPerspectives.remove(pespectiveId);
49
	}
50
51
	/* (non-Javadoc)
52
	 * @see org.eclipse.ui.internal.IStickyViewManager#add(java.lang.String, java.util.Set)
53
	 */
54
	public void add(String pespectiveId, Set stickyViewList) {
55
		stickyPerspectives.put(pespectiveId, stickyViewList);
56
	}
57
58
	/* (non-Javadoc)
59
	 * @see org.eclipse.ui.internal.IStickyViewManager#clear()
60
	 */
61
	public void clear() {
62
		stickyPerspectives.clear();
63
	}
64
65
	/* (non-Javadoc)
66
	 * @see org.eclipse.ui.internal.IStickyViewManager#update(org.eclipse.ui.IWorkbenchPage, org.eclipse.ui.internal.Perspective, org.eclipse.ui.internal.Perspective)
67
	 */
68
	public void update(Perspective oldPersp, Perspective newPersp) {
69
		if (newPersp != null && oldPersp != null) {
70
			Set activatedStickyViewsInThisPerspective = (Set) stickyPerspectives
71
					.get(newPersp.getDesc().getId());
72
			if (activatedStickyViewsInThisPerspective == null) {
73
				activatedStickyViewsInThisPerspective = new HashSet(7);
74
				stickyPerspectives.put(newPersp.getDesc().getId(),
75
						activatedStickyViewsInThisPerspective);
76
			}
77
			IViewRegistry viewReg = WorkbenchPlugin.getDefault()
78
					.getViewRegistry();
79
			IStickyViewDescriptor[] stickyDescs = viewReg.getStickyViews();
80
			for (int i = 0; i < stickyDescs.length; i++) {
81
				final String viewId = stickyDescs[i].getId();
82
				try {
83
					// show a sticky view if it was in the last perspective and hasn't already been activated in this one
84
					if (oldPersp.findView(viewId) != null
85
							&& !activatedStickyViewsInThisPerspective
86
									.contains(viewId)) {
87
						page.showView(viewId, null, IWorkbenchPage.VIEW_CREATE);
88
						activatedStickyViewsInThisPerspective.add(viewId);
89
					}
90
				} catch (PartInitException e) {
91
					WorkbenchPlugin
92
							.log(
93
									"Could not open view :" + viewId, new Status(IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH, IStatus.ERROR, "Could not open view :" + viewId, e)); //$NON-NLS-1$ //$NON-NLS-2$
94
				}
95
			}
96
		}
97
	}
98
	
99
	/* (non-Javadoc)
100
	 * @see org.eclipse.ui.internal.IStickyViewManager#save(org.eclipse.ui.IMemento)
101
	 */
102
	public void save(IMemento memento) {
103
		IMemento stickyState = memento.createChild(IWorkbenchConstants.TAG_STICKY_STATE);
104
		Iterator itr = stickyPerspectives.entrySet().iterator();
105
		while (itr.hasNext()) {
106
			Map.Entry entry = (Map.Entry) itr.next();
107
			String perspectiveId = (String) entry.getKey();
108
			Set activatedViewIds = (Set) entry.getValue();
109
			IMemento perspectiveState = stickyState.createChild(
110
					IWorkbenchConstants.TAG_PERSPECTIVE, perspectiveId);
111
			for (Iterator i = activatedViewIds.iterator(); i.hasNext();) {
112
				String viewId = (String) i.next();
113
				perspectiveState.createChild(IWorkbenchConstants.TAG_VIEW,
114
						viewId);
115
			}
116
		}
117
	}
118
119
	/* (non-Javadoc)
120
	 * @see org.eclipse.ui.internal.IStickyViewManager#restore(org.eclipse.ui.IMemento)
121
	 */
122
	public void restore(IMemento memento) {
123
		// restore the sticky activation state
124
		IMemento stickyState = memento
125
				.getChild(IWorkbenchConstants.TAG_STICKY_STATE);
126
127
		if (stickyState != null) {
128
			IMemento[] stickyPerspMems = stickyState
129
					.getChildren(IWorkbenchConstants.TAG_PERSPECTIVE);
130
			for (int i = 0; i < stickyPerspMems.length; i++) {
131
				String perspectiveId = stickyPerspMems[i].getID();
132
				Set viewState = new HashSet(7);
133
				stickyPerspectives.put(perspectiveId, viewState);
134
				IMemento[] viewStateMementos = stickyPerspMems[i]
135
						.getChildren(IWorkbenchConstants.TAG_VIEW);
136
				for (int j = 0; j < viewStateMementos.length; j++) {
137
					viewState.add(viewStateMementos[j].getID());
138
				}
139
			}
140
		}
141
	}
142
}
(-)Eclipse UI Tests/org/eclipse/ui/tests/intro/IntroTest.java (-2 / +42 lines)
Lines 10-25 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.tests.intro;
11
package org.eclipse.ui.tests.intro;
12
12
13
import org.eclipse.jface.preference.IPreferenceStore;
13
import org.eclipse.ui.IPerspectiveDescriptor;
14
import org.eclipse.ui.IPerspectiveDescriptor;
14
import org.eclipse.ui.IViewPart;
15
import org.eclipse.ui.IViewPart;
15
import org.eclipse.ui.IWorkbench;
16
import org.eclipse.ui.IWorkbench;
16
import org.eclipse.ui.IWorkbenchPage;
17
import org.eclipse.ui.IWorkbenchPage;
18
import org.eclipse.ui.IWorkbenchPreferenceConstants;
17
import org.eclipse.ui.IWorkbenchWindow;
19
import org.eclipse.ui.IWorkbenchWindow;
18
import org.eclipse.ui.internal.Workbench;
20
import org.eclipse.ui.internal.Workbench;
19
import org.eclipse.ui.internal.WorkbenchPlugin;
21
import org.eclipse.ui.internal.WorkbenchPlugin;
20
import org.eclipse.ui.internal.WorkbenchWindow;
22
import org.eclipse.ui.internal.WorkbenchWindow;
21
import org.eclipse.ui.internal.intro.IIntroConstants;
23
import org.eclipse.ui.internal.intro.IIntroConstants;
22
import org.eclipse.ui.internal.intro.IntroDescriptor;
24
import org.eclipse.ui.internal.intro.IntroDescriptor;
25
import org.eclipse.ui.internal.util.PrefUtil;
23
import org.eclipse.ui.intro.IIntroManager;
26
import org.eclipse.ui.intro.IIntroManager;
24
import org.eclipse.ui.intro.IIntroPart;
27
import org.eclipse.ui.intro.IIntroPart;
25
import org.eclipse.ui.tests.api.PerspectiveWithFastView;
28
import org.eclipse.ui.tests.api.PerspectiveWithFastView;
Lines 100-106 Link Here
100
     * that it no longer exists.
103
     * that it no longer exists.
101
     */
104
     */
102
    public void testPerspectiveChange() {
105
    public void testPerspectiveChange() {
103
        IWorkbench workbench = window.getWorkbench();
106
    	IWorkbench workbench = window.getWorkbench();
104
        IIntroPart part = workbench.getIntroManager().showIntro(window, false);
107
        IIntroPart part = workbench.getIntroManager().showIntro(window, false);
105
        assertNotNull(part);
108
        assertNotNull(part);
106
        IWorkbenchPage activePage = window.getActivePage();
109
        IWorkbenchPage activePage = window.getActivePage();
Lines 115-121 Link Here
115
        assertTrue(workbench.getIntroManager().closeIntro(part));
118
        assertTrue(workbench.getIntroManager().closeIntro(part));
116
        assertNull(workbench.getIntroManager().getIntro());
119
        assertNull(workbench.getIntroManager().getIntro());
117
    }
120
    }
118
121
    
122
    /**
123
     * Open the intro, change perspective, close the intro 
124
     * and ensure that the intro has not been closed in the 
125
     * other perspective.
126
     * See bug 174213
127
     * See IntroTest2.java
128
     */
129
    public void testPerspectiveChangeWith32StickyBehavior() {
130
    	IWorkbench workbench = window.getWorkbench();
131
        IIntroPart part = workbench.getIntroManager().showIntro(window, false);
132
        assertNotNull(part);
133
        IWorkbenchPage activePage = window.getActivePage();
134
        IPerspectiveDescriptor oldDesc = activePage.getPerspective();
135
        activePage.setPerspective(WorkbenchPlugin.getDefault()
136
                .getPerspectiveRegistry().findPerspectiveWithId(
137
                        "org.eclipse.ui.tests.api.SessionPerspective"));
138
       
139
        IViewPart viewPart = window.getActivePage().findView(
140
				IIntroConstants.INTRO_VIEW_ID);
141
        assertNotNull(viewPart);
142
        
143
        window.getActivePage().hideView(viewPart);
144
        viewPart = window.getActivePage().findView(
145
				IIntroConstants.INTRO_VIEW_ID);
146
        assertNull(viewPart);
147
        
148
        activePage.setPerspective(oldDesc);
149
        viewPart = window.getActivePage().findView(
150
				IIntroConstants.INTRO_VIEW_ID);
151
        assertNotNull(viewPart);
152
    }
153
    
119
    public void testPerspectiveReset() {
154
    public void testPerspectiveReset() {
120
        IWorkbench workbench = window.getWorkbench();
155
        IWorkbench workbench = window.getWorkbench();
121
        IIntroPart part = workbench.getIntroManager().showIntro(window, false);
156
        IIntroPart part = workbench.getIntroManager().showIntro(window, false);
Lines 154-159 Link Here
154
     */
189
     */
155
    protected void doSetUp() throws Exception {
190
    protected void doSetUp() throws Exception {
156
        super.doSetUp();
191
        super.doSetUp();
192
        
193
        // these tests rely on the 3.2 behavior for sticky views
194
    	IPreferenceStore preferenceStore = PrefUtil.getAPIPreferenceStore();
195
    	preferenceStore.putValue(IWorkbenchPreferenceConstants.ENABLE_32_STICKY_CLOSE_BEHAVIOR, "true");
196
    	
157
        oldDesc = Workbench.getInstance().getIntroDescriptor();
197
        oldDesc = Workbench.getInstance().getIntroDescriptor();
158
        IntroDescriptor testDesc = (IntroDescriptor) WorkbenchPlugin
198
        IntroDescriptor testDesc = (IntroDescriptor) WorkbenchPlugin
159
                .getDefault().getIntroRegistry().getIntro(
199
                .getDefault().getIntroRegistry().getIntro(
(-)Eclipse (+101 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2006 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.ui.tests.intro;
12
13
import org.eclipse.jface.preference.IPreferenceStore;
14
import org.eclipse.ui.IPerspectiveDescriptor;
15
import org.eclipse.ui.IViewPart;
16
import org.eclipse.ui.IWorkbench;
17
import org.eclipse.ui.IWorkbenchPage;
18
import org.eclipse.ui.IWorkbenchPreferenceConstants;
19
import org.eclipse.ui.IWorkbenchWindow;
20
import org.eclipse.ui.internal.Workbench;
21
import org.eclipse.ui.internal.WorkbenchPlugin;
22
import org.eclipse.ui.internal.intro.IIntroConstants;
23
import org.eclipse.ui.internal.intro.IntroDescriptor;
24
import org.eclipse.ui.internal.util.PrefUtil;
25
import org.eclipse.ui.intro.IIntroPart;
26
import org.eclipse.ui.tests.harness.util.UITestCase;
27
28
/**
29
 * @since 3.0
30
 */
31
public class IntroTest2 extends UITestCase {
32
33
    IWorkbenchWindow window = null;
34
35
    private IntroDescriptor oldDesc;
36
37
    /**
38
     * @param testName
39
     */
40
    public IntroTest2(String testName) {
41
        super(testName);
42
    }
43
    
44
    /**
45
     * Open the intro, change perspective, close the intro 
46
     * and ensure that the intro has been closed in the 
47
     * other perspective.
48
     * See bug 174213
49
     */
50
    public void testPerspectiveChangeWith33StickyBehavior() {
51
    	IWorkbench workbench = window.getWorkbench();
52
        IIntroPart part = workbench.getIntroManager().showIntro(window, false);
53
        assertNotNull(part);
54
        IWorkbenchPage activePage = window.getActivePage();
55
        IPerspectiveDescriptor oldDesc = activePage.getPerspective();
56
        activePage.setPerspective(WorkbenchPlugin.getDefault()
57
                .getPerspectiveRegistry().findPerspectiveWithId(
58
                        "org.eclipse.ui.tests.api.SessionPerspective"));
59
       
60
        IViewPart viewPart = window.getActivePage().findView(
61
				IIntroConstants.INTRO_VIEW_ID);
62
        assertNotNull(viewPart);
63
        
64
        window.getActivePage().hideView(viewPart);
65
        viewPart = window.getActivePage().findView(
66
				IIntroConstants.INTRO_VIEW_ID);
67
        assertNull(viewPart);
68
        
69
        activePage.setPerspective(oldDesc);
70
        viewPart = window.getActivePage().findView(
71
				IIntroConstants.INTRO_VIEW_ID);
72
        assertNull(viewPart);
73
        
74
    }
75
76
    /* (non-Javadoc)
77
     * @see org.eclipse.ui.tests.util.UITestCase#doSetUp()
78
     */
79
    protected void doSetUp() throws Exception {
80
        super.doSetUp();
81
        
82
        // these tests rely on the 3.3 behavior for sticky views
83
    	IPreferenceStore preferenceStore = PrefUtil.getAPIPreferenceStore();
84
    	preferenceStore.putValue(IWorkbenchPreferenceConstants.ENABLE_32_STICKY_CLOSE_BEHAVIOR, "false");
85
    	
86
        oldDesc = Workbench.getInstance().getIntroDescriptor();
87
        IntroDescriptor testDesc = (IntroDescriptor) WorkbenchPlugin
88
                .getDefault().getIntroRegistry().getIntro(
89
                        "org.eclipse.ui.testintro");
90
        Workbench.getInstance().setIntroDescriptor(testDesc);
91
        window = openTestWindow();
92
    }
93
94
    /* (non-Javadoc)
95
     * @see org.eclipse.ui.tests.util.UITestCase#doTearDown()
96
     */
97
    protected void doTearDown() throws Exception {
98
        super.doTearDown();
99
        Workbench.getInstance().setIntroDescriptor(oldDesc);
100
    }
101
}

Return to bug 174213