From 429d7531fcb6eb7d9f5d6263109e8de7cff70894 Mon Sep 17 00:00:00 2001 From: Ted Williams Date: Fri, 2 May 2008 05:24:01 +0000 Subject: [PATCH] [229914] Implement Update Policy support for Memory View --- .../org.eclipse.dd.dsf.debug.ui/plugin.xml | 60 +++++++ .../provisional/ui/memory/RefreshAction.java | 78 ++++++++ .../ui/memory/SelectUpdatePolicyAction.java | 168 ++++++++++++++++++ 3 files changed, 306 insertions(+) create mode 100644 plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/internal/provisional/ui/memory/RefreshAction.java create mode 100644 plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/internal/provisional/ui/memory/SelectUpdatePolicyAction.java diff --git a/plugins/org.eclipse.dd.dsf.debug.ui/plugin.xml b/plugins/org.eclipse.dd.dsf.debug.ui/plugin.xml index 655ec12ec88..a7ce6427f37 100644 --- a/plugins/org.eclipse.dd.dsf.debug.ui/plugin.xml +++ b/plugins/org.eclipse.dd.dsf.debug.ui/plugin.xml @@ -416,5 +416,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/internal/provisional/ui/memory/RefreshAction.java b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/internal/provisional/ui/memory/RefreshAction.java new file mode 100644 index 00000000000..17b00e52364 --- /dev/null +++ b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/internal/provisional/ui/memory/RefreshAction.java @@ -0,0 +1,78 @@ + +/******************************************************************************* + * Copyright (c) 2008 Wind River Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - Ted Williams - initial API and implementation + *******************************************************************************/ + +package org.eclipse.dd.dsf.debug.internal.provisional.ui.memory; + +import org.eclipse.debug.core.DebugEvent; +import org.eclipse.debug.core.IDebugEventSetListener; +import org.eclipse.debug.core.model.IMemoryBlock; +import org.eclipse.debug.core.model.IMemoryBlockUpdatePolicy; +import org.eclipse.debug.internal.ui.views.memory.MemoryView; +import org.eclipse.debug.ui.memory.IMemoryRendering; +import org.eclipse.debug.ui.memory.IMemoryRenderingContainer; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IViewActionDelegate; +import org.eclipse.ui.IViewPart; + +@SuppressWarnings("restriction") +public class RefreshAction implements IViewActionDelegate { + + private IMemoryBlock fMemoryBlock = null; + + private MemoryView fView; + + public void init(IViewPart view) { + fView = (MemoryView) view; + } + + public void run(IAction action) { + + if(fMemoryBlock instanceof IMemoryBlockUpdatePolicy) + { + ((IMemoryBlockUpdatePolicy) fMemoryBlock).clearCache(); + IMemoryRenderingContainer containers[] = fView.getMemoryRenderingContainers(); + for(int i = 0; i < containers.length; i++) + { + IMemoryRendering renderings[] = containers[i].getRenderings(); + for(int j = 0; j < renderings.length; j++) + { + if (renderings[j].getControl() instanceof IDebugEventSetListener) + { + ((IDebugEventSetListener) renderings[j].getControl()).handleDebugEvents( + new DebugEvent[] { new DebugEvent(fMemoryBlock, DebugEvent.CHANGE) } ); + } + } + } + } + } + + public void selectionChanged(IAction action, ISelection selection) { + fMemoryBlock = null; + action.setEnabled(false); + if(selection instanceof IStructuredSelection) + { + if(((IStructuredSelection) selection).getFirstElement() instanceof IMemoryBlock) + { + fMemoryBlock = (IMemoryBlock) ((IStructuredSelection) selection).getFirstElement(); + action.setEnabled(true); + } + else if(((IStructuredSelection) selection).getFirstElement() instanceof IMemoryRendering) + { + fMemoryBlock = ((IMemoryRendering) ((IStructuredSelection) selection).getFirstElement()).getMemoryBlock(); + action.setEnabled(true); + } + } + } + +} diff --git a/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/internal/provisional/ui/memory/SelectUpdatePolicyAction.java b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/internal/provisional/ui/memory/SelectUpdatePolicyAction.java new file mode 100644 index 00000000000..781fd40fddc --- /dev/null +++ b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/internal/provisional/ui/memory/SelectUpdatePolicyAction.java @@ -0,0 +1,168 @@ + +/******************************************************************************* + * Copyright (c) 2008 Wind River Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - Ted Williams - initial API and implementation + *******************************************************************************/ + +package org.eclipse.dd.dsf.debug.internal.provisional.ui.memory; + +import org.eclipse.debug.core.model.IMemoryBlock; +import org.eclipse.debug.core.model.IMemoryBlockUpdatePolicy; +import org.eclipse.debug.ui.contexts.DebugContextEvent; +import org.eclipse.debug.ui.contexts.IDebugContextListener; +import org.eclipse.debug.ui.memory.IMemoryRendering; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.ActionContributionItem; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuCreator; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.events.MenuAdapter; +import org.eclipse.swt.events.MenuEvent; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.ui.IActionDelegate2; +import org.eclipse.ui.IViewActionDelegate; +import org.eclipse.ui.IViewPart; + +/** + * + */ +public class SelectUpdatePolicyAction implements IMenuCreator, IViewActionDelegate, IDebugContextListener, IActionDelegate2 { + + private IAction fAction = null; + private IMemoryBlock fMemoryBlock = null; + + private String fUpdatePolicy = null; + + public void dispose() { + // do nothing + + } + + public void runWithEvent(IAction action, Event event) { + // do nothing + } + + class SelectPolicy extends Action { + + String fID; + String fDescription; + + public SelectPolicy(String id, String description) { + fID = id; + fDescription = description; + } + + @Override + public String getText() { + return fDescription; + } + + @Override + public void run() { + ((IMemoryBlockUpdatePolicy) fMemoryBlock).setUpdatePolicy(fID); + fUpdatePolicy = fID; + } + + } + + + public Menu getMenu(Control parent) { + // Never called + return null; + } + + protected IAction getAction() { return fAction; } + + public void init(IViewPart view) { + } + + public void init(IAction action) { + fAction = action; + action.setMenuCreator(this); + } + + public void run(IAction action) { + // Do nothing, this is a pull-down menu + } + + public void selectionChanged(IAction action, ISelection selection) { + fMemoryBlock = null; + action.setEnabled(false); + if(selection instanceof IStructuredSelection) + { + if(((IStructuredSelection) selection).getFirstElement() instanceof IMemoryBlock) + { + fMemoryBlock = (IMemoryBlock) ((IStructuredSelection) selection).getFirstElement(); + action.setMenuCreator(this); + action.setEnabled(true); + } + else if(((IStructuredSelection) selection).getFirstElement() instanceof IMemoryRendering) + { + fMemoryBlock = ((IMemoryRendering) ((IStructuredSelection) selection).getFirstElement()).getMemoryBlock(); + action.setMenuCreator(this); + action.setEnabled(true); + } + + if(fMemoryBlock != null) + { + if(fMemoryBlock instanceof IMemoryBlockUpdatePolicy) + { + String currentPolicy = ((IMemoryBlockUpdatePolicy) fMemoryBlock).getUpdatePolicy(); + if(fUpdatePolicy == null) + fUpdatePolicy = currentPolicy; + + ((IMemoryBlockUpdatePolicy) fMemoryBlock).setUpdatePolicy(fUpdatePolicy); + } + } + } + } + + public void debugContextChanged(DebugContextEvent event) { + } + + public Menu getMenu(Menu parent) { + Menu menu = new Menu(parent); + menu.addMenuListener(new MenuAdapter() { + @Override + public void menuShown(MenuEvent e) { + Menu m = (Menu)e.widget; + MenuItem[] items = m.getItems(); + for (int i=0; i < items.length; i++) { + items[i].dispose(); + } + fillMenu(m); + } + }); + return menu; + } + + private void fillMenu(Menu menu) { + if(fMemoryBlock instanceof IMemoryBlockUpdatePolicy) + { + IMemoryBlockUpdatePolicy blockPolicy = (IMemoryBlockUpdatePolicy) fMemoryBlock; + + String currentPolicy = blockPolicy.getUpdatePolicy(); + + String policies[] = blockPolicy.getUpdatePolicies(); + for(int i = 0; i < policies.length; i++) + { + SelectPolicy action = new SelectPolicy(policies[i], blockPolicy.getUpdatePolicyDescription(policies[i])); + ActionContributionItem item = new ActionContributionItem(action); + action.setChecked(policies[i].equals(currentPolicy)); + item.fill(menu, -1); + } + } + } + +} +