KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > viewers > update > ExpressionManagerModelProxy


1 /*******************************************************************************
2  * Copyright (c) 2005, 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
12 package org.eclipse.debug.internal.ui.viewers.update;
13
14 import org.eclipse.debug.core.DebugPlugin;
15 import org.eclipse.debug.core.IExpressionManager;
16 import org.eclipse.debug.core.IExpressionsListener;
17 import org.eclipse.debug.core.model.IExpression;
18 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
19 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
20 import org.eclipse.debug.internal.ui.viewers.model.provisional.ModelDelta;
21 import org.eclipse.debug.internal.ui.viewers.provisional.AbstractModelProxy;
22 import org.eclipse.jface.viewers.Viewer;
23
24
25 public class ExpressionManagerModelProxy extends AbstractModelProxy implements IExpressionsListener {
26         
27     /* (non-Javadoc)
28      * @see org.eclipse.debug.internal.ui.viewers.update.EventHandlerModelProxy#init(org.eclipse.debug.internal.ui.viewers.IPresentationContext)
29      */

30     public void init(IPresentationContext context) {
31         super.init(context);
32         getExpressionManager().addExpressionListener(this);
33     }
34     
35     /* (non-Javadoc)
36      * @see org.eclipse.debug.internal.ui.viewers.provisional.AbstractModelProxy#installed(org.eclipse.jface.viewers.Viewer)
37      */

38     public void installed(Viewer viewer) {
39         updateExpressions(getExpressionManager().getExpressions(), IModelDelta.INSTALL);
40     }
41
42     /**
43      * @return
44      */

45     protected IExpressionManager getExpressionManager() {
46         return DebugPlugin.getDefault().getExpressionManager();
47     }
48     
49     /* (non-Javadoc)
50      * @see org.eclipse.debug.internal.ui.viewers.update.EventHandlerModelProxy#dispose()
51      */

52     public synchronized void dispose() {
53         super.dispose();
54         getExpressionManager().removeExpressionListener(this);
55     }
56
57     /* (non-Javadoc)
58      * @see org.eclipse.debug.core.IExpressionsListener#expressionsAdded(org.eclipse.debug.core.model.IExpression[])
59      */

60     public void expressionsAdded(IExpression[] expressions) {
61         updateExpressions(expressions, IModelDelta.ADDED | IModelDelta.INSTALL);
62     }
63
64     /* (non-Javadoc)
65      * @see org.eclipse.debug.core.IExpressionsListener#expressionsRemoved(org.eclipse.debug.core.model.IExpression[])
66      */

67     public void expressionsRemoved(IExpression[] expressions) {
68         updateExpressions(expressions, IModelDelta.REMOVED | IModelDelta.UNINSTALL);
69     }
70
71     /* (non-Javadoc)
72      * @see org.eclipse.debug.core.IExpressionsListener#expressionsChanged(org.eclipse.debug.core.model.IExpression[])
73      */

74     public void expressionsChanged(IExpression[] expressions) {
75         updateExpressions(expressions, IModelDelta.CONTENT | IModelDelta.STATE);
76     }
77     
78     private void updateExpressions(IExpression[] expressions, int flags) {
79         ModelDelta delta = new ModelDelta(getExpressionManager(), IModelDelta.NO_CHANGE);
80         for (int i = 0; i < expressions.length; i++) {
81             IExpression expression = expressions[i];
82             delta.addNode(expression, flags);
83         }
84         fireModelChanged(delta);
85     }
86
87 }
88
Popular Tags