KickJava   Java API By Example, From Geeks To Geeks.

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


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.IRegisterGroup;
15 import org.eclipse.debug.core.model.IStackFrame;
16 import org.eclipse.debug.core.model.IVariable;
17 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
18 import org.eclipse.debug.ui.IDebugUIConstants;
19 import org.eclipse.ui.IMemento;
20
21 /**
22  * @since 3.3
23  */

24 public class VariablesViewElementMementoProvider extends ElementMementoProvider {
25
26     /**
27      * memento attribute
28      */

29     private static final String JavaDoc ELEMENT_NAME = "ELEMENT_NAME"; //$NON-NLS-1$
30

31     protected boolean encodeElement(Object JavaDoc element, IMemento memento, IPresentationContext context) throws CoreException {
32         if (element instanceof IStackFrame) {
33             IStackFrame frame = (IStackFrame) element;
34             if (IDebugUIConstants.ID_REGISTER_VIEW.equals(context.getId())) {
35                 // for registers view attempt to maintain expansion for target rather than each frame
36
memento.putString(ELEMENT_NAME, frame.getModelIdentifier());
37             } else {
38                 memento.putString(ELEMENT_NAME, frame.getName());
39             }
40         } else if (element instanceof IVariable) {
41             memento.putString(ELEMENT_NAME, ((IVariable) element).getName());
42         } else if (element instanceof IRegisterGroup) {
43             memento.putString(ELEMENT_NAME, ((IRegisterGroup) element).getName());
44         } else {
45             return false;
46         }
47         return true;
48     }
49
50     protected boolean isEqual(Object JavaDoc element, IMemento memento, IPresentationContext context) throws CoreException {
51         String JavaDoc mementoName = memento.getString(ELEMENT_NAME);
52         if (mementoName != null) {
53             String JavaDoc elementName = null;
54             if (element instanceof IStackFrame) {
55                 IStackFrame frame = (IStackFrame) element;
56                 if (IDebugUIConstants.ID_REGISTER_VIEW.equals(context.getId())) {
57                     // for registers view attempt to maintain expansion for target rather than each frame
58
elementName = frame.getModelIdentifier();
59                 } else {
60                     elementName = frame.getName();
61                 }
62             } else if (element instanceof IVariable) {
63                 elementName = ((IVariable)element).getName();
64             } else if (element instanceof IRegisterGroup) {
65                 elementName = ((IRegisterGroup)element).getName();
66             }
67             if (elementName != null) {
68                 return elementName.equals(mementoName);
69             }
70         }
71         return false;
72     }
73
74 }
75
Popular Tags