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 385592
Collapse All | Expand All

(-)a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java (+79 lines)
Lines 12-17 Link Here
12
package org.eclipse.ui.internal;
12
package org.eclipse.ui.internal;
13
13
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.io.StringReader;
15
import java.io.StringWriter;
16
import java.io.StringWriter;
16
import java.util.ArrayList;
17
import java.util.ArrayList;
17
import java.util.Arrays;
18
import java.util.Arrays;
Lines 27-38 Link Here
27
import java.util.Set;
28
import java.util.Set;
28
import java.util.WeakHashMap;
29
import java.util.WeakHashMap;
29
import javax.annotation.PostConstruct;
30
import javax.annotation.PostConstruct;
31
import javax.annotation.PreDestroy;
30
import org.eclipse.core.runtime.Assert;
32
import org.eclipse.core.runtime.Assert;
31
import org.eclipse.core.runtime.CoreException;
33
import org.eclipse.core.runtime.CoreException;
32
import org.eclipse.core.runtime.IAdaptable;
34
import org.eclipse.core.runtime.IAdaptable;
33
import org.eclipse.core.runtime.IConfigurationElement;
35
import org.eclipse.core.runtime.IConfigurationElement;
36
import org.eclipse.core.runtime.IStatus;
34
import org.eclipse.core.runtime.ListenerList;
37
import org.eclipse.core.runtime.ListenerList;
35
import org.eclipse.core.runtime.SafeRunner;
38
import org.eclipse.core.runtime.SafeRunner;
39
import org.eclipse.core.runtime.Status;
36
import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
40
import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
37
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
41
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
38
import org.eclipse.e4.core.contexts.IEclipseContext;
42
import org.eclipse.e4.core.contexts.IEclipseContext;
Lines 149-154 Link Here
149
import org.eclipse.ui.model.IWorkbenchAdapter;
153
import org.eclipse.ui.model.IWorkbenchAdapter;
150
import org.eclipse.ui.part.IShowInSource;
154
import org.eclipse.ui.part.IShowInSource;
151
import org.eclipse.ui.part.ShowInContext;
155
import org.eclipse.ui.part.ShowInContext;
156
import org.eclipse.ui.statushandlers.StatusManager;
152
import org.eclipse.ui.views.IStickyViewDescriptor;
157
import org.eclipse.ui.views.IStickyViewDescriptor;
153
import org.eclipse.ui.views.IViewDescriptor;
158
import org.eclipse.ui.views.IViewDescriptor;
154
import org.osgi.service.event.Event;
159
import org.osgi.service.event.Event;
Lines 160-165 Link Here
160
public class WorkbenchPage extends CompatibleWorkbenchPage implements
165
public class WorkbenchPage extends CompatibleWorkbenchPage implements
161
        IWorkbenchPage {
166
        IWorkbenchPage {
162
	
167
	
168
	private static final String ATT_AGGREGATE_WORKING_SET_ID = "aggregateWorkingSetId"; //$NON-NLS-1$
169
163
	static final String SECONDARY_ID_HEADER = "3x-secondary:"; //$NON-NLS-1$
170
	static final String SECONDARY_ID_HEADER = "3x-secondary:"; //$NON-NLS-1$
164
171
165
	class E4PartListener implements org.eclipse.e4.ui.workbench.modeling.IPartListener {
172
	class E4PartListener implements org.eclipse.e4.ui.workbench.modeling.IPartListener {
Lines 2685-2692 Link Here
2685
				sortedPerspectives.add(desc);
2692
				sortedPerspectives.add(desc);
2686
			}
2693
			}
2687
		}
2694
		}
2695
2696
		restoreWorkingSets();
2688
    }
2697
    }
2689
2698
2699
	public void restoreWorkingSets() {
2700
		String workingSetName = getWindowModel().getPersistedState().get(
2701
				IWorkbenchConstants.TAG_WORKING_SET);
2702
		if (workingSetName != null) {
2703
			AbstractWorkingSetManager workingSetManager = (AbstractWorkingSetManager) getWorkbenchWindow()
2704
					.getWorkbench().getWorkingSetManager();
2705
			setWorkingSet(workingSetManager.getWorkingSet(workingSetName));
2706
		}
2707
2708
		String workingSetMemString = getWindowModel().getPersistedState().get(
2709
				IWorkbenchConstants.TAG_WORKING_SETS);
2710
		if (workingSetMemString != null) {
2711
			IMemento workingSetMem;
2712
			try {
2713
				workingSetMem = XMLMemento.createReadRoot(new StringReader(workingSetMemString));
2714
				IMemento[] workingSetChildren = workingSetMem
2715
						.getChildren(IWorkbenchConstants.TAG_WORKING_SET);
2716
				List workingSetList = new ArrayList(workingSetChildren.length);
2717
				for (int i = 0; i < workingSetChildren.length; i++) {
2718
					IWorkingSet set = getWorkbenchWindow().getWorkbench().getWorkingSetManager()
2719
							.getWorkingSet(workingSetChildren[i].getID());
2720
					if (set != null) {
2721
						workingSetList.add(set);
2722
					}
2723
				}
2724
2725
				workingSets = (IWorkingSet[]) workingSetList.toArray(new IWorkingSet[workingSetList
2726
						.size()]);
2727
			} catch (WorkbenchException e) {
2728
				StatusManager.getManager().handle(
2729
						new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.ERROR,
2730
								WorkbenchMessages.WorkbenchPage_problemRestoringTitle, e));
2731
			}
2732
		}
2733
2734
		aggregateWorkingSetId = getWindowModel().getPersistedState().get(
2735
				ATT_AGGREGATE_WORKING_SET_ID);
2736
	}
2737
2738
	@PreDestroy
2739
	public void saveWorkingSets() {
2740
		// Save working set if set
2741
		if (workingSet != null) {
2742
			getWindowModel().getPersistedState().put(IWorkbenchConstants.TAG_WORKING_SET,
2743
					workingSet.getName());
2744
		} else {
2745
			getWindowModel().getPersistedState().remove(IWorkbenchConstants.TAG_WORKING_SET);
2746
		}
2747
2748
		XMLMemento workingSetMem = XMLMemento.createWriteRoot(IWorkbenchConstants.TAG_WORKING_SETS);
2749
		for (int i = 0; i < workingSets.length; i++) {
2750
			workingSetMem
2751
					.createChild(IWorkbenchConstants.TAG_WORKING_SET, workingSets[i].getName());
2752
		}
2753
		StringWriter writer = new StringWriter();
2754
		try {
2755
			workingSetMem.save(writer);
2756
			getWindowModel().getPersistedState().put(IWorkbenchConstants.TAG_WORKING_SETS,
2757
					writer.getBuffer().toString());
2758
		} catch (IOException e) {
2759
			// Simply don't store the settings
2760
			StatusManager.getManager().handle(
2761
					new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.ERROR,
2762
							WorkbenchMessages.SavingProblem, e));
2763
		}
2764
2765
		getWindowModel().getPersistedState().put(ATT_AGGREGATE_WORKING_SET_ID,
2766
				aggregateWorkingSetId);
2767
	}
2768
2690
	/**
2769
	/**
2691
	 * Extends the perspectives within the given stack with action set
2770
	 * Extends the perspectives within the given stack with action set
2692
	 * contributions from the <code>perspectiveExtensions</code> extension
2771
	 * contributions from the <code>perspectiveExtensions</code> extension
(-)a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IWorkbenchPageTest.java (+47 lines)
Lines 263-268 Link Here
263
	}
263
	}
264
264
265
	/**
265
	/**
266
	 * Test if the WorkingSet related settings are persisted across sessions.
267
	 */
268
	public void testWorkingSetsPersisted_Bug385592() {
269
		IWorkingSetManager manager = fActivePage.getWorkbenchWindow()
270
				.getWorkbench().getWorkingSetManager();
271
272
		// get initial state and save it
273
		IWorkingSet[] workingSetsBeforeSave = fActivePage.getWorkingSets();
274
		String aggrWorkingSetIdBeforeSave = fActivePage
275
				.getAggregateWorkingSet().getName();
276
		((WorkbenchPage) fActivePage).saveWorkingSets();
277
		assertNotNull(workingSetsBeforeSave);
278
		assertNotNull(aggrWorkingSetIdBeforeSave);
279
		assertEquals(0, workingSetsBeforeSave.length);
280
281
		IWorkingSet set1 = null;
282
		try {
283
			set1 = manager.createWorkingSet("w1", new IAdaptable[0]);
284
			manager.addWorkingSet(set1);
285
286
			// change the working sets
287
			fActivePage.setWorkingSets(new IWorkingSet[] { set1 });
288
			assertNotNull(fActivePage.getWorkingSets());
289
			assertEquals(1, fActivePage.getWorkingSets().length);
290
291
			// restore the previous state
292
			((WorkbenchPage) fActivePage).restoreWorkingSets();
293
			assertEquals(aggrWorkingSetIdBeforeSave, fActivePage
294
					.getAggregateWorkingSet().getName());
295
			assertNotNull(fActivePage.getWorkingSets());
296
			assertEquals(workingSetsBeforeSave.length,
297
					fActivePage.getWorkingSets().length);
298
299
			// change again, save and restore the settings
300
			fActivePage.setWorkingSets(new IWorkingSet[] { set1 });
301
			((WorkbenchPage) fActivePage).saveWorkingSets();
302
			((WorkbenchPage) fActivePage).restoreWorkingSets();
303
			assertEquals(aggrWorkingSetIdBeforeSave, fActivePage
304
					.getAggregateWorkingSet().getName());
305
			assertEquals(1, fActivePage.getWorkingSets().length);
306
		} finally {
307
			if (set1 != null)
308
				manager.removeWorkingSet(set1);
309
		}
310
	}
311
312
	/**
266
	 * Test the VIEW_VISIBLE parameter for showView, opening the view in the
313
	 * Test the VIEW_VISIBLE parameter for showView, opening the view in the
267
	 * stack that does not contain the active view. Ensures that the created
314
	 * stack that does not contain the active view. Ensures that the created
268
	 * view is not the active part but is the top part in its stack.
315
	 * view is not the active part but is the top part in its stack.

Return to bug 385592