KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > model > elements > MemoryViewElementMementoProvider


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.model.elements;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.debug.core.model.IMemoryBlock;
15 import org.eclipse.debug.core.model.IMemoryBlockRetrieval;
16 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
17 import org.eclipse.debug.ui.IDebugUIConstants;
18 import org.eclipse.ui.IMemento;
19
20 public class MemoryViewElementMementoProvider extends ElementMementoProvider {
21     
22     private static final String JavaDoc OBJECT_ID = "OBJECT_ID"; //$NON-NLS-1$
23

24     protected boolean encodeElement(Object JavaDoc element, IMemento memento,
25             IPresentationContext context) throws CoreException {
26         String JavaDoc id = context.getId();
27         if (id.equals(IDebugUIConstants.ID_MEMORY_VIEW))
28         {
29             if (element instanceof IMemoryBlock || element instanceof IMemoryBlockRetrieval)
30             {
31                 memento.putInteger(OBJECT_ID, element.hashCode());
32                 return true;
33             }
34         }
35         return false;
36     }
37
38     protected boolean isEqual(Object JavaDoc element, IMemento memento,
39             IPresentationContext context) throws CoreException {
40         String JavaDoc id = context.getId();
41         if (id.equals(IDebugUIConstants.ID_MEMORY_VIEW))
42         {
43             if (element instanceof IMemoryBlock || element instanceof IMemoryBlockRetrieval)
44             {
45                 Integer JavaDoc objectId = memento.getInteger(OBJECT_ID);
46                 if (objectId != null && objectId.intValue() == element.hashCode())
47                     return true;
48             }
49         }
50         return false;
51     }
52
53 }
54
Popular Tags