blob: efe46eeb586dcec6400fdded82ef0914a891b65e (
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
61
62
63
64
65
|
/*******************************************************************************
* Copyright (c) 2004, 2008 Eugene Kuleshov 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
*
* Contributors:
* Eugene Kuleshov - initial API and implementation
*******************************************************************************/
package org.eclipse.mylyn.internal.tasks.ui.workingsets;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.mylyn.internal.tasks.core.AbstractTaskContainer;
import org.eclipse.mylyn.tasks.core.IRepositoryElement;
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"; //$NON-NLS-1$
@SuppressWarnings("rawtypes")
private static final Class[] ADAPTER_TYPES = new Class[] { IPersistableElement.class };
@SuppressWarnings("rawtypes")
public Class[] getAdapterList() {
return ADAPTER_TYPES;
}
@SuppressWarnings("rawtypes")
public Object getAdapter(final Object adaptableObject, Class adapterType) {
if (adapterType == IPersistableElement.class && adaptableObject instanceof AbstractTaskContainer) {
return new IPersistableElement() {
public void saveState(IMemento memento) {
IRepositoryElement container = (IRepositoryElement) 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;
}
}
|