blob: 5f2529c893b6316b9cd0cf04c2755cb5981aeebb (
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
66
67
68
69
70
71
72
73
74
75
76
77
78
|
/*******************************************************************************
* Copyright (c) 2007 IBM Corporation 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.debug.internal.ui.model.elements;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
import org.eclipse.ui.IMemento;
/**
* Abstract memento provider debug elements.
*
* @since 3.4
*/
public abstract class DebugElementMementoProvider extends ElementMementoProvider {
protected static final String ELEMENT_NAME = "ELEMENT_NAME"; //$NON-NLS-1$
@Override
protected boolean encodeElement(Object element, IMemento memento, IPresentationContext context) throws CoreException {
if (supportsContext(context)) {
String name = getElementName(element, context);
memento.putString(ELEMENT_NAME, name);
return true;
}
return false;
}
@Override
protected boolean isEqual(Object element, IMemento memento, IPresentationContext context) throws CoreException {
String mementoName = memento.getString(ELEMENT_NAME);
if (mementoName != null) {
String name = getElementName(element, context);
if (name != null) {
return name.equals(mementoName);
}
}
return false;
}
/**
* Returns whether this adapter supports the given context.
*
* @param context
* @return whether this adapter supports the given context
*/
protected boolean supportsContext(IPresentationContext context) {
return supportsContextId(context.getId());
}
/**
* Returns whether this adapter provides content in the specified context id.
*
* @param id part id
* @return whether this adapter provides content in the specified context id
*/
protected boolean supportsContextId(String id) {
return true;
}
/**
* Returns the name of the given element to use in a memento in the given context,
* or <code>null</code> if unsupported.
*
* @param element model element
* @param context presentation context
* @return element name or <code>null</code> if none
* @throws CoreException
*/
protected abstract String getElementName(Object element, IPresentationContext context) throws CoreException;
}
|