KickJava   Java API By Example, From Geeks To Geeks.

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


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.IExpressionManager;
15 import org.eclipse.debug.core.model.IExpression;
16 import org.eclipse.debug.core.model.IVariable;
17 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
18 import org.eclipse.ui.IMemento;
19
20 /**
21  * Memento provider for expressions view.
22  *
23  * @since 3.3
24  */

25 public class ExpressionsViewMementoProvider extends ElementMementoProvider {
26
27     /**
28      * memento attribute
29      */

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

32     private static final String JavaDoc EXP_MGR = "EXP_MGR"; //$NON-NLS-1$
33

34     protected boolean encodeElement(Object JavaDoc element, IMemento memento, IPresentationContext context) throws CoreException {
35         if (element instanceof IExpressionManager) {
36             memento.putString(ELEMENT_NAME, EXP_MGR);
37         } else if (element instanceof IExpression) {
38             memento.putString(ELEMENT_NAME, ((IExpression) element).getExpressionText());
39         } else if (element instanceof IVariable) {
40             memento.putString(ELEMENT_NAME, ((IVariable) element).getName());
41         } else {
42             return false;
43         }
44         return true;
45     }
46
47     protected boolean isEqual(Object JavaDoc element, IMemento memento, IPresentationContext context) throws CoreException {
48         String JavaDoc mementoName = memento.getString(ELEMENT_NAME);
49         if (mementoName != null) {
50             String JavaDoc elementName = null;
51             if (element instanceof IExpressionManager) {
52                 elementName = EXP_MGR;
53             } else if (element instanceof IVariable) {
54                 elementName = ((IVariable)element).getName();
55             } else if (element instanceof IExpression) {
56                 elementName = ((IExpression)element).getExpressionText();
57             }
58             if (elementName != null) {
59                 return elementName.equals(mementoName);
60             }
61         }
62         return false;
63     }
64
65 }
66
Popular Tags