KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > memory > MemoryViewTreeModelContentProvider


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
12 package org.eclipse.debug.internal.ui.views.memory;
13
14 import org.eclipse.debug.core.DebugPlugin;
15 import org.eclipse.debug.core.model.IMemoryBlock;
16 import org.eclipse.debug.core.model.IMemoryBlockRetrieval;
17 import org.eclipse.debug.internal.ui.viewers.PartPresentationContext;
18 import org.eclipse.debug.internal.ui.viewers.model.TreeModelContentProvider;
19 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
20 import org.eclipse.debug.internal.ui.viewers.model.provisional.TreeModelViewer;
21
22 public class MemoryViewTreeModelContentProvider extends
23         TreeModelContentProvider {
24     
25     protected void updateNodes(IModelDelta[] nodes) {
26         
27         if (getViewer() instanceof TreeModelViewer)
28         {
29             TreeModelViewer viewer = (TreeModelViewer) getViewer();
30     
31             for (int i = 0; i < nodes.length; i++) {
32                 IModelDelta node = nodes[i];
33                 int flags = node.getFlags();
34
35                 if ((flags & IModelDelta.ADDED) != 0) {
36                     if (node.getElement() instanceof IMemoryBlock) {
37                         if ((flags & IModelDelta.SELECT) != 0) {
38                             PartPresentationContext context = (PartPresentationContext) viewer
39                                     .getPresentationContext();
40                             if (context.getPart() instanceof MemoryView) {
41                                 MemoryView view = (MemoryView) context
42                                         .getPart();
43                                 if (view.isPinMBDisplay()) {
44                                     // turn off select if the view is currently
45
// pinned
46
flags |= IModelDelta.SELECT;
47                                     flags ^= IModelDelta.SELECT;
48                                 }
49                             }
50                         }
51
52                         // override and select the first memory block
53
if (isFirstMemoryBlock()) {
54                             flags |= IModelDelta.SELECT;
55                         }
56                     }
57                 }
58                 if ((flags & IModelDelta.ADDED) != 0) {
59                     handleAdd(node);
60                 }
61                 if ((flags & IModelDelta.REMOVED) != 0) {
62                     handleRemove(node);
63                 }
64                 if ((flags & IModelDelta.CONTENT) != 0) {
65                     handleContent(node);
66                 }
67                 if ((flags & IModelDelta.EXPAND) != 0) {
68                     handleExpand(node);
69                 }
70                 if ((flags & IModelDelta.SELECT) != 0) {
71                     handleSelect(node);
72                 }
73                 if ((flags & IModelDelta.STATE) != 0) {
74                     handleState(node);
75                 }
76                 if ((flags & IModelDelta.INSERTED) != 0) {
77                     handleInsert(node);
78                 }
79                 if ((flags & IModelDelta.REPLACED) != 0) {
80                     handleReplace(node);
81                 }
82                 if ((flags & IModelDelta.INSTALL) != 0) {
83                     handleInstall(node);
84                 }
85                 if ((flags & IModelDelta.UNINSTALL) != 0) {
86                     handleUninstall(node);
87                 }
88                 updateNodes(node.getChildDeltas());
89             }
90         }
91     }
92     
93     private boolean isFirstMemoryBlock()
94     {
95         Object JavaDoc input = getViewer().getInput();
96         if (input instanceof IMemoryBlockRetrieval)
97         {
98             IMemoryBlock[] memoryBlocks = DebugPlugin.getDefault().getMemoryBlockManager().getMemoryBlocks((IMemoryBlockRetrieval)input);
99             if (memoryBlocks.length == 1)
100                 return true;
101         }
102         return false;
103     }
104 }
105
Popular Tags