Skip to main content
summaryrefslogtreecommitdiffstats
blob: 0ed9a48525e315e3ea265bccb4b9c13329411f1a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*******************************************************************************
 * Copyright (c) 2004, 2007 Mylyn project committers and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

package org.eclipse.mylyn.internal.tasks.ui.workingsets;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.mylyn.tasks.core.ITaskElement;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IPersistableElement;

/**
 * Adapter factory used to adapt AbstractTaskContainer to IPersistableElement
 * 
 * @author Eugene Kuleshov
 */
public class TaskWorkingSetAdapterFactory implements IAdapterFactory {

	private static final String TASK_ELEMENT_FACTORY_ID = "org.eclipse.mylyn.tasks.ui.workingSets.elementFactory";

	@SuppressWarnings("unchecked")
	private static final Class[] ADAPTER_TYPES = new Class[] { IPersistableElement.class };

	@SuppressWarnings("unchecked")
	public Class[] getAdapterList() {
		return ADAPTER_TYPES;
	}

	public Object getAdapter(final Object adaptableObject, @SuppressWarnings("unchecked") Class adapterType) {
		if (adapterType == IPersistableElement.class && adaptableObject instanceof ITaskElement) {
			return new IPersistableElement() {
				public void saveState(IMemento memento) {
					ITaskElement container = (ITaskElement) adaptableObject;
					memento.putString(TaskWorkingSetElementFactory.HANDLE_TASK, container.getHandleIdentifier());
				}

				public String getFactoryId() {
					return TASK_ELEMENT_FACTORY_ID;
				}
			};
		} else if (adapterType == IPersistableElement.class && adaptableObject instanceof IProject) {
			return new IPersistableElement() {
				public void saveState(IMemento memento) {
					IProject project = (IProject) adaptableObject;
					memento.putString(TaskWorkingSetElementFactory.HANDLE_PROJECT, project.getName());
				}

				public String getFactoryId() {
					return TASK_ELEMENT_FACTORY_ID;
				}
			};
		}
		return null;
	}
}

Back to the top