Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ae3cbc0837953695409d83f49072fd6a54071f99 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*******************************************************************************
 * Copyright (c) 2009 Freescale Semiconductor 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:
 *     2009 Freescale - initial API and implementation (Bug 238956)
 *******************************************************************************/
package org.eclipse.debug.internal.ui.model.elements;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.ui.IMemento;

/**
 * Memento provider for breakpoints
 * 
 * @since 3.6
 */
public class BreakpointMementoProvider extends ElementMementoProvider {

	/**
	 * Marker ID. Stored as string in order to support the full range of the long type.
	 */
	private static final String MARKER_ID = "MARKER_ID"; 	//$NON-NLS-1$
	
	/**
	 * Full path from the workspace to the resource referred to by the breakpoint marker.
	 * 
	 * Stored as String. 
	 */
	private static final String RESOURCE_PATH = "RESOURCE_PATH"; 	//$NON-NLS-1$	
	
	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.model.elements.DebugElementMementoProvider#supportsContextId(java.lang.String)
	 */
	protected boolean supportsContextId(String id) {
    	return IDebugUIConstants.ID_BREAKPOINT_VIEW.equals(id);
    }

	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.model.elements.ElementMementoProvider#encodeElement(java.lang.Object, org.eclipse.ui.IMemento, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext)
	 */
	protected boolean encodeElement(Object element, IMemento memento, IPresentationContext context) throws CoreException {
		if (element instanceof IBreakpoint) {
			
			IMarker marker = ((IBreakpoint)element).getMarker();
			if (marker != null) {

				long markerId = marker.getId();
				memento.putString(MARKER_ID, Long.toString(markerId));

				IPath fullPath = marker.getResource().getFullPath();
				String path = fullPath.toString();
				memento.putString(RESOURCE_PATH, path);
				return true;
			}
		}

		return false;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.model.elements.ElementMementoProvider#isEqual(java.lang.Object, org.eclipse.ui.IMemento, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext)
	 */
	protected boolean isEqual(Object element, IMemento memento, IPresentationContext context) throws CoreException {
		if (element instanceof IBreakpoint) {
			IBreakpoint breakpoint =(IBreakpoint)element; 
			IMarker marker = breakpoint.getMarker();
			
			long markerId = marker.getId();
			String mementoMarkerId = memento.getString(MARKER_ID);
			if (!Long.toString(markerId).equals(mementoMarkerId)) {
				return false;
			}
			
			IPath fullPath = marker.getResource().getFullPath();
			String path = fullPath.toString();
			String mementoPath = memento.getString(RESOURCE_PATH);
			if (!path.equals(mementoPath)) {
				return false;
			}
			return true;
		}
		return false;
	}

}

Back to the top