01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal;
11:
12: import org.eclipse.core.runtime.IAdaptable;
13: import org.eclipse.ui.IElementFactory;
14: import org.eclipse.ui.IMemento;
15:
16: /**
17: * A WorkingSetFactory is used to recreate a persisted WorkingSet
18: * object.
19: */
20: public class WorkingSetFactory implements IElementFactory {
21:
22: /* (non-Javadoc)
23: * @see org.eclipse.ui.IElementFactory
24: */
25: public IAdaptable createElement(IMemento memento) {
26: String workingSetName = memento
27: .getString(IWorkbenchConstants.TAG_NAME);
28: String label = memento.getString(IWorkbenchConstants.TAG_LABEL);
29: if (label == null) {
30: label = workingSetName;
31: }
32: String workingSetEditPageId = memento
33: .getString(IWorkbenchConstants.TAG_EDIT_PAGE_ID);
34: String aggregateString = memento
35: .getString(AbstractWorkingSet.TAG_AGGREGATE);
36: boolean isAggregate = aggregateString != null
37: && Boolean.valueOf(aggregateString).booleanValue();
38:
39: if (workingSetName == null) {
40: return null;
41: }
42:
43: AbstractWorkingSet workingSet = null;
44:
45: if (isAggregate) {
46: workingSet = new AggregateWorkingSet(workingSetName, label,
47: memento);
48: } else {
49: workingSet = new WorkingSet(workingSetName, label, memento);
50: }
51:
52: if (workingSetEditPageId != null) {
53: workingSet.setId(workingSetEditPageId);
54: } else if (!isAggregate) {
55: // working sets created with builds 20020418 and 20020419 will not
56: // have an edit page id. fix this automatically.
57: workingSet.setId("org.eclipse.ui.resourceWorkingSetPage"); //$NON-NLS-1$
58: }
59: return workingSet;
60: }
61: }
|