KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 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 java.util.ArrayList JavaDoc;
15 import java.util.Iterator JavaDoc;
16
17 import org.eclipse.debug.core.model.IMemoryBlock;
18 import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants;
19 import org.eclipse.debug.ui.DebugUITools;
20 import org.eclipse.debug.ui.memory.IMemoryRendering;
21 import org.eclipse.debug.ui.memory.IMemoryRenderingContainer;
22 import org.eclipse.jface.action.IAction;
23 import org.eclipse.jface.viewers.ISelection;
24 import org.eclipse.jface.viewers.IStructuredSelection;
25 import org.eclipse.ui.IViewActionDelegate;
26 import org.eclipse.ui.IViewPart;
27
28 /**
29  * The popup menu action for a memory rendering used to reset the current selection
30  * to the default first memory position
31  *
32  * @since 3.2.0
33  */

34 public class ResetMemoryBlockAction implements IViewActionDelegate{
35
36     private IViewPart fView;
37     private ArrayList JavaDoc fSelectedMB = new ArrayList JavaDoc();
38
39     /* (non-Javadoc)
40      * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
41      */

42     public void init(IViewPart view) {
43         fView = view;
44     }
45
46     /* (non-Javadoc)
47      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
48      */

49     public void run(IAction action) {
50         if (fSelectedMB.isEmpty()) {
51             return;
52         }
53         boolean resetVisible = false;
54         String JavaDoc resetPref = DebugUITools.getPreferenceStore().getString(IDebugPreferenceConstants.PREF_RESET_MEMORY_BLOCK);
55         if (resetPref.equals(IDebugPreferenceConstants.RESET_VISIBLE)) {
56             resetVisible = true;
57         }
58         Iterator JavaDoc iter = fSelectedMB.iterator();
59         while(iter.hasNext()) {
60             IMemoryBlock mb = (IMemoryBlock)iter.next();
61             if (fView instanceof MemoryView) {
62                 MemoryView memView = (MemoryView)fView;
63                 IMemoryRenderingContainer[] containers = memView.getMemoryRenderingContainers();
64                 
65                 for (int i=0; i<containers.length; i++) {
66                     if (containers[i] instanceof RenderingViewPane) {
67                         ((RenderingViewPane)containers[i]).resetRenderings(mb, resetVisible);
68                     }
69                 }
70             }
71         }
72     }
73
74     /* (non-Javadoc)
75      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
76      */

77     public void selectionChanged(IAction action, ISelection selection) {
78         action.setEnabled(!selection.isEmpty());
79         if (selection instanceof IStructuredSelection) {
80             IStructuredSelection strucSel = (IStructuredSelection) selection;
81             Object JavaDoc[] objs = strucSel.toArray();
82             fSelectedMB.clear();
83             for (int i = 0; i < objs.length; i++) {
84                 if (objs[i] instanceof IMemoryBlock)
85                     fSelectedMB.add(objs[i]);
86                 if (objs[i] instanceof IMemoryRendering)
87                     fSelectedMB.add(((IMemoryRendering) objs[i]).getMemoryBlock());
88             }
89         }
90     }
91
92 }
93
Popular Tags