From f5f70da342be313a1a1ad96dfd09aa5b1d8cbd2a Mon Sep 17 00:00:00 2001 From: Ted Williams Date: Sat, 30 Jun 2007 03:22:49 +0000 Subject: [PATCH] First attempt at update policies / modes. --- .../build.properties | 3 +- .../icons/refresh.gif | Bin 0 -> 385 bytes .../org.eclipse.dd.dsf.debug.ui/plugin.xml | 151 +++++++++ .../expression/ExpressionVMProvider.java | 4 +- .../register/RegisterBitFieldLayoutNode.java | 15 +- .../register/RegisterLayoutNode.java | 61 ++-- .../register/RegisterVMProvider.java | 4 +- .../update/VMCacheRefreshAlways.java | 36 ++ .../update/VMCacheRefreshManual.java | 25 ++ .../update/VMCacheRefreshOnBreak.java | 31 ++ .../update/actions/RefreshActionDelegate.java | 44 +++ .../actions/RefreshAlwaysActionDelegate.java | 34 ++ .../actions/RefreshManualActionDelegate.java | 34 ++ .../actions/RefreshOnBreakActionDelegate.java | 34 ++ .../variable/VariableLocalsLayoutNode.java | 15 +- .../VariableSubExpressionsLayoutNode.java | 15 +- .../variable/VariableVMProvider.java | 4 +- .../META-INF/MANIFEST.MF | 6 +- .../viewmodel/dm/AbstractDMVMLayoutNode.java | 9 +- .../dm/AbstractDMVMProviderWithCache.java | 63 ++++ .../dd/dsf/ui/viewmodel/update/VMCache.java | 315 ++++++++++++++++++ .../ui/viewmodel/update/VMCacheManager.java | 105 ++++++ .../AbstractRefreshActionDelegate.java | 40 +++ 23 files changed, 999 insertions(+), 49 deletions(-) create mode 100644 plugins/org.eclipse.dd.dsf.debug.ui/icons/refresh.gif create mode 100644 plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/update/VMCacheRefreshAlways.java create mode 100644 plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/update/VMCacheRefreshManual.java create mode 100644 plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/update/VMCacheRefreshOnBreak.java create mode 100644 plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/update/actions/RefreshActionDelegate.java create mode 100644 plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/update/actions/RefreshAlwaysActionDelegate.java create mode 100644 plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/update/actions/RefreshManualActionDelegate.java create mode 100644 plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/update/actions/RefreshOnBreakActionDelegate.java create mode 100644 plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/dm/AbstractDMVMProviderWithCache.java create mode 100644 plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/update/VMCache.java create mode 100644 plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/update/VMCacheManager.java create mode 100644 plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/update/actions/AbstractRefreshActionDelegate.java diff --git a/plugins/org.eclipse.dd.dsf.debug.ui/build.properties b/plugins/org.eclipse.dd.dsf.debug.ui/build.properties index 4a2586141ff..65c7e05604b 100644 --- a/plugins/org.eclipse.dd.dsf.debug.ui/build.properties +++ b/plugins/org.eclipse.dd.dsf.debug.ui/build.properties @@ -3,4 +3,5 @@ output.. = bin/ bin.includes = META-INF/,\ plugin.xml,\ about.html,\ - . + .,\ + icons/ diff --git a/plugins/org.eclipse.dd.dsf.debug.ui/icons/refresh.gif b/plugins/org.eclipse.dd.dsf.debug.ui/icons/refresh.gif new file mode 100644 index 0000000000000000000000000000000000000000..b6b8dc6836dc1fa4b10189958fa157c4d1961b86 GIT binary patch literal 385 zcmZ?wbhEHb6krfw*v!E2|G#~Gz5V?8@&EtNpFh8T|Ni;^@7vF>x4%E%zCPam|NsB{ zfkN}=0~ripp!k!8k%57iK?lSGnZdx4xWQ9$*u4~E zOXg(ap5Vd@jp7R@Ivmik6Kx7mkdvOR^7w*EnieaQlEK=vfR>hpm;UmxSTbyPvk>6b z6)Qg|C|$tBHrLtYlOd;ny>Jt+AcM7YeqKpxUWsl + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/expression/ExpressionVMProvider.java b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/expression/ExpressionVMProvider.java index 0356fc87ca3..6f569e19447 100644 --- a/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/expression/ExpressionVMProvider.java +++ b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/expression/ExpressionVMProvider.java @@ -24,7 +24,7 @@ import org.eclipse.dd.dsf.ui.viewmodel.AbstractVMAdapter; import org.eclipse.dd.dsf.ui.viewmodel.IVMContext; import org.eclipse.dd.dsf.ui.viewmodel.IVMLayoutNode; import org.eclipse.dd.dsf.ui.viewmodel.IVMRootLayoutNode; -import org.eclipse.dd.dsf.ui.viewmodel.dm.AbstractDMVMProvider; +import org.eclipse.dd.dsf.ui.viewmodel.dm.AbstractDMVMProviderWithCache; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.IExpressionsListener; import org.eclipse.debug.core.model.IExpression; @@ -35,7 +35,7 @@ import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationCont * */ @SuppressWarnings("restriction") -public class ExpressionVMProvider extends AbstractDMVMProvider +public class ExpressionVMProvider extends AbstractDMVMProviderWithCache implements IExpressionsListener, IFormattedValuePreferenceStore { private String fDefaultFormatId = IFormattedValues.HEX_FORMAT; diff --git a/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/register/RegisterBitFieldLayoutNode.java b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/register/RegisterBitFieldLayoutNode.java index aef1233c561..a028a2589c3 100644 --- a/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/register/RegisterBitFieldLayoutNode.java +++ b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/register/RegisterBitFieldLayoutNode.java @@ -43,6 +43,7 @@ import org.eclipse.dd.dsf.ui.viewmodel.AbstractVMProvider; import org.eclipse.dd.dsf.ui.viewmodel.IVMContext; import org.eclipse.dd.dsf.ui.viewmodel.VMDelta; import org.eclipse.dd.dsf.ui.viewmodel.dm.AbstractDMVMLayoutNode; +import org.eclipse.dd.dsf.ui.viewmodel.update.VMCacheManager; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.model.IDebugTarget; @@ -236,8 +237,9 @@ public class RegisterBitFieldLayoutNode extends AbstractExpressionLayoutNode(getSession().getExecutor(), null) { @Override public void handleCompleted() { @@ -259,7 +261,8 @@ public class RegisterBitFieldLayoutNode extends AbstractExpressionLayoutNode(getSession().getExecutor(), null) { @Override @@ -341,7 +345,8 @@ public class RegisterBitFieldLayoutNode extends AbstractExpressionLayoutNode @@ -231,25 +234,37 @@ public class RegisterLayoutNode extends AbstractExpressionLayoutNode(getSession().getExecutor(), null) { - @Override - public void handleCompleted() { - if (!getStatus().isOK()) { - handleFailedUpdate(update); - return; - } - - /* - * Fill the label/column with the properly formatted data value. - */ - update.setLabel(getData().getFormattedValue(), labelIndex); - update.done(); - } - } + VMCacheManager.getVMCacheManager().getCache(RegisterLayoutNode.this.getVMProvider().getPresentationContext()) + .getModelData(regService, + valueDmc, + new DataRequestMonitor(getSession().getExecutor(), null) { + @Override + public void handleCompleted() { + if (!getStatus().isOK()) { + handleFailedUpdate(update); + return; + } + + /* + * Fill the label/column with the properly formatted data value. + */ + update.setLabel(getData().getFormattedValue(), labelIndex); + + // color based on change history + FormattedValueDMData oldData = (FormattedValueDMData) VMCacheManager.getVMCacheManager() + .getCache(RegisterLayoutNode.this.getVMProvider().getPresentationContext()) + .getArchivedModelData(valueDmc); + if(oldData != null && oldData.getFormattedValue().equals(getData().getFormattedValue())) + update.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK).getRGB(), labelIndex); + else + update.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED).getRGB(), labelIndex); + + update.done(); + } + }, + getSession().getExecutor() ); } } @@ -270,9 +285,10 @@ public class RegisterLayoutNode extends AbstractExpressionLayoutNode(getSession().getExecutor(), null) { + VMCacheManager.getVMCacheManager().getCache(update.getPresentationContext()) + .getModelData((IDMService)getServicesTracker().getService(null, dmc.getServiceFilter()), + dmc, + new DataRequestMonitor(getSession().getExecutor(), null) { @Override protected void handleCompleted() { /* @@ -332,7 +348,8 @@ public class RegisterLayoutNode extends AbstractExpressionLayoutNode(getSession().getExecutor(), null) { @Override protected void handleCompleted() { @@ -221,7 +223,8 @@ public class VariableLocalsLayoutNode extends AbstractExpressionLayoutNode(getSession().getExecutor(), null) { @Override @@ -309,7 +313,8 @@ public class VariableLocalsLayoutNode extends AbstractExpressionLayoutNode(getSession().getExecutor(), null) { @Override @@ -123,7 +125,8 @@ public class VariableSubExpressionsLayoutNode extends AbstractDMVMLayoutNode(getSession().getExecutor(), null) { @Override public void handleCompleted() { @@ -211,7 +215,8 @@ public class VariableSubExpressionsLayoutNode extends AbstractDMVMLayoutNode extends Abstract final IDMContext dmc = findDmcInPath(update.getElementPath(), fDMCClassType); if (!checkDmc(dmc, update) || !checkService(null, dmc.getServiceFilter(), update)) return; - ((IDMService)getServicesTracker().getService(null, dmc.getServiceFilter())).getModelData( - dmc, + VMCacheManager.getVMCacheManager().getCache(update.getPresentationContext()) + .getModelData((IDMService)getServicesTracker().getService(null, dmc.getServiceFilter()), + dmc, new DataRequestMonitor(getSession().getExecutor(), null) { @Override protected void handleCompleted() { @@ -350,7 +352,8 @@ abstract public class AbstractDMVMLayoutNode extends Abstract } update.done(); } - }); + }, + getExecutor()); } } diff --git a/plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/dm/AbstractDMVMProviderWithCache.java b/plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/dm/AbstractDMVMProviderWithCache.java new file mode 100644 index 00000000000..058ac9b90bb --- /dev/null +++ b/plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/dm/AbstractDMVMProviderWithCache.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2007 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: + * Ted R Williams (Wind River Systems, Inc.) - initial implementation + *******************************************************************************/ + +package org.eclipse.dd.dsf.ui.viewmodel.dm; + +import org.eclipse.dd.dsf.datamodel.IDMEvent; +import org.eclipse.dd.dsf.service.DsfSession; +import org.eclipse.dd.dsf.ui.viewmodel.AbstractVMAdapter; +import org.eclipse.dd.dsf.ui.viewmodel.update.VMCacheManager; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenCountUpdate; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IHasChildrenUpdate; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; +import org.eclipse.debug.internal.ui.viewers.model.provisional.ModelDelta; +import org.eclipse.dd.dsf.service.DsfServiceEventHandler; + +public abstract class AbstractDMVMProviderWithCache extends AbstractDMVMProvider + implements VMCacheManager.CacheListener +{ + @DsfServiceEventHandler + public void eventDispatched(IDMEvent event) { + VMCacheManager.getVMCacheManager().getCache(getPresentationContext()).handleEvent(event); + super.eventDispatched(event); + } + + public void cacheFlushed(Object context) { + if(getPresentationContext().equals(context)) + getModelProxy().fireModelChanged(new ModelDelta(this.getRootLayoutNode().getRootObject(),IModelDelta.CONTENT)); + } + + public AbstractDMVMProviderWithCache(AbstractVMAdapter adapter, IPresentationContext presentationContext, DsfSession session) { + super(adapter, presentationContext, session); + + VMCacheManager.getVMCacheManager().addCacheListener(getPresentationContext(), this); + } + + public void update(IHasChildrenUpdate[] updates) { + super.update(VMCacheManager.getVMCacheManager().getCache(getPresentationContext()).update(updates)); + } + + public void update(IChildrenCountUpdate[] updates) { + super.update(VMCacheManager.getVMCacheManager().getCache(getPresentationContext()).update(updates)); + } + + public void update(final IChildrenUpdate[] updates) { + super.update(VMCacheManager.getVMCacheManager().getCache(getPresentationContext()).update(updates)); + } + + public void dispose() + { + VMCacheManager.getVMCacheManager().removeCacheListener(getPresentationContext(), this); + super.dispose(); + } +} diff --git a/plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/update/VMCache.java b/plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/update/VMCache.java new file mode 100644 index 00000000000..57fa567b57e --- /dev/null +++ b/plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/update/VMCache.java @@ -0,0 +1,315 @@ +/******************************************************************************* + * Copyright (c) 2007 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: + * Ted R Williams (Wind River Systems, Inc.) - initial implementation + *******************************************************************************/ + +package org.eclipse.dd.dsf.ui.viewmodel.update; + +import java.util.HashMap; +import java.util.Vector; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.dd.dsf.concurrent.DataRequestMonitor; +import org.eclipse.dd.dsf.concurrent.DsfExecutor; +import org.eclipse.dd.dsf.datamodel.IDMContext; +import org.eclipse.dd.dsf.datamodel.IDMData; +import org.eclipse.dd.dsf.datamodel.IDMEvent; +import org.eclipse.dd.dsf.datamodel.IDMService; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenCountUpdate; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IHasChildrenUpdate; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; +import org.eclipse.jface.viewers.TreePath; + +public abstract class VMCache +{ + protected HashMap fChildrenCounts = new HashMap(); + + class ChildData + { + Object child; + int offset; + + public ChildData(Object child, int offset) + { + this.child = child; + this.offset = offset; + } + } + + protected HashMap fChildren = new HashMap(); + + protected HashMap fHasChildren = new HashMap(); + + protected HashMap, IDMData> fData = new HashMap, IDMData>(); + + protected HashMap, IDMData> fDataArchive = fData; + + protected void flush(boolean archive) + { + if(archive) + fDataArchive = fData; + fData = new HashMap, IDMData>(); + fChildrenCounts.clear(); + fChildren.clear(); + fChildrenCounts.clear(); + } + + protected boolean useCache() + { + return true; + } + + public IHasChildrenUpdate[] update(IHasChildrenUpdate[] updates) { + Vector missVector = new Vector(); + for(IHasChildrenUpdate update : updates) + { + if(fHasChildren.containsKey(update.getElement()) && useCache()) + { + update.setHasChilren(fHasChildren.get(update.getElement()).booleanValue()); + update.done(); + } + else + { + missVector.addElement(update); + } + } + + updates = new IHasChildrenUpdate[missVector.size()]; + for(int i = 0; i < updates.length; i++) + { + final IHasChildrenUpdate update = missVector.elementAt(i); + updates[i] = new IHasChildrenUpdate() + { + private boolean fIsHasChildren; + + public void setHasChilren(boolean hasChildren) { + fIsHasChildren = hasChildren; + update.setHasChilren(hasChildren); + } + + public void cancel() { + update.cancel(); + } + + public void done() { + fHasChildren.put(getElement(), Boolean.valueOf(fIsHasChildren)); + update.done(); + } + + public IStatus getStatus() { + return update.getStatus(); + } + + public boolean isCanceled() { + return update.isCanceled(); + } + + public void setStatus(IStatus status) { + update.setStatus(status); + } + + public Object getElement() { + return update.getElement(); + } + + public TreePath getElementPath() { + return update.getElementPath(); + } + + public IPresentationContext getPresentationContext() { + return update.getPresentationContext(); + } + + }; + } + + return updates; + } + + public IChildrenCountUpdate[] update(IChildrenCountUpdate[] updates) + { + Vector missVector = new Vector(); + for(IChildrenCountUpdate update : updates) + { + if(fChildrenCounts.containsKey(update.getElement()) && useCache()) + { + update.setChildCount(fChildrenCounts.get(update.getElement())); + update.done(); + } + else + { + missVector.addElement(update); + } + } + + updates = new IChildrenCountUpdate[missVector.size()]; + for(int i = 0; i < updates.length; i++) + { + final IChildrenCountUpdate update = missVector.elementAt(i); + updates[i] = new IChildrenCountUpdate() + { + private int fChildCount; + + public void cancel() { + update.cancel(); + } + + public void done() { + fChildrenCounts.put(getElement(), fChildCount); + update.done(); + } + + public IStatus getStatus() { + return update.getStatus(); + } + + public boolean isCanceled() { + return update.isCanceled(); + } + + public void setStatus(IStatus status) { + update.setStatus(status); + } + + public void setChildCount(int numChildren) { + fChildCount = numChildren; + update.setChildCount(numChildren); + } + + public Object getElement() { + return update.getElement(); + } + + public TreePath getElementPath() { + return update.getElementPath(); + } + + public IPresentationContext getPresentationContext() { + return update.getPresentationContext(); + } + + }; + } + + return updates; + } + + public IChildrenUpdate[] update(IChildrenUpdate[] updates) { + Vector missVector = new Vector(); + for(IChildrenUpdate update : updates) + { + if(fChildren.containsKey(update.getElement()) && useCache()) + { + ChildData childData[] = fChildren.get(update.getElement()); + for(ChildData data : childData) + update.setChild(data.child, data.offset); + update.done(); + } + else + { + missVector.addElement(update); + } + } + + updates = new IChildrenUpdate[missVector.size()]; + for(int i = 0; i < updates.length; i++) + { + final IChildrenUpdate update = missVector.elementAt(i); + updates[i] = new IChildrenUpdate() + { + Vector fChilds = new Vector(); + + public int getLength() { + return update.getLength(); + } + + public int getOffset() { + return update.getOffset(); + } + + public void setChild(Object child, int offset) { + fChilds.addElement(new ChildData(child, offset)); + update.setChild(child, offset); + } + + public void cancel() { + update.cancel(); + } + + public void done() { + // FIXME synchronize with events? + fChildren.put(getElement(), fChilds.toArray(new ChildData[fChilds.size()])); + update.done(); + } + + public IStatus getStatus() { + return update.getStatus(); + } + + public boolean isCanceled() { + return update.isCanceled(); + } + + public void setStatus(IStatus status) { + update.setStatus(status); + } + + public Object getElement() { + return update.getElement(); + } + + public TreePath getElementPath() { + return update.getElementPath(); + } + + public IPresentationContext getPresentationContext() { + return update.getPresentationContext(); + } + + }; + } + + return updates; + } + + @SuppressWarnings("unchecked") + public void getModelData(IDMService service, final IDMContext dmc, final DataRequestMonitor rm, DsfExecutor executor) + { + if(fData.containsKey(dmc) && useCache()) + { + rm.setData( fData.get(dmc)); + rm.done(); + } + else + { + service.getModelData(dmc, + new DataRequestMonitor(executor, null) { + @Override + public void handleCompleted() { + fData.put(dmc, getData()); + rm.setData(getData()); + rm.done(); + } + } + ); + } + } + + @SuppressWarnings("unchecked") + public IDMData getArchivedModelData(IDMContext dmc) + { + return fDataArchive.get(dmc); + } + + public abstract void handleEvent(IDMEvent event); + +} + + diff --git a/plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/update/VMCacheManager.java b/plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/update/VMCacheManager.java new file mode 100644 index 00000000000..cdf60c43c41 --- /dev/null +++ b/plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/update/VMCacheManager.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2007 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: + * Ted R Williams (Wind River Systems, Inc.) - initial implementation + *******************************************************************************/ + +package org.eclipse.dd.dsf.ui.viewmodel.update; + +import java.util.HashMap; +import java.util.Vector; + +import org.eclipse.dd.dsf.datamodel.IDMEvent; + + +public class VMCacheManager +{ + private static VMCacheManager fInstance = null; + + private HashMap fAssociations = new HashMap(); + + public interface CacheListener + { + public void cacheFlushed(Object context); + } + + private HashMap> fListeners = new HashMap>(); + + public VMCacheManager() + { + } + + public static VMCacheManager getVMCacheManager() + { + if(fInstance == null) + fInstance = new VMCacheManager(); + + return fInstance; + } + + public VMCache getCache(Object context) + { + if(!fAssociations.containsKey(context)) + fAssociations.put(context, new VMCache() + { + @Override + public void handleEvent(IDMEvent event) { + flush(true); + } + + public boolean readFromCache() + { + return false; + } + }); + + return fAssociations.get(context); + } + + public void registerCache(Object context, VMCache cache) + { + fAssociations.put(context, cache); + } + + public void addCacheListener(Object context, CacheListener listener) + { + if(!fListeners.containsKey(context)) + fListeners.put(context, new Vector()); + + fListeners.get(context).addElement(listener); + } + + public void removeCacheListener(Object context, CacheListener listener) + { + if(!fListeners.containsKey(context)) + { + fListeners.get(context).removeElement(listener); + if(fListeners.get(context).isEmpty()) + fListeners.remove(context); + } + } + + private void fireCacheFlushed(Object context) + { + if(fListeners.containsKey(context)) + { + for(CacheListener listener : fListeners.get(context)) + listener.cacheFlushed(context); + } + } + + public void flush(Object context) + { + getCache(context).flush(false); + fireCacheFlushed(context); + } + +} + + + diff --git a/plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/update/actions/AbstractRefreshActionDelegate.java b/plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/update/actions/AbstractRefreshActionDelegate.java new file mode 100644 index 00000000000..88d0f2da26e --- /dev/null +++ b/plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/update/actions/AbstractRefreshActionDelegate.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2007 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: + * Ted R Williams (Wind River Systems, Inc.) - initial implementation + *******************************************************************************/ + +package org.eclipse.dd.dsf.ui.viewmodel.update.actions; + +import org.eclipse.dd.dsf.ui.viewmodel.update.VMCache; +import org.eclipse.dd.dsf.ui.viewmodel.update.VMCacheManager; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IViewActionDelegate; +import org.eclipse.ui.IViewPart; + +public abstract class AbstractRefreshActionDelegate implements IViewActionDelegate { + + protected IViewPart fView; + + public void init(IViewPart view) { + fView = view; + } + + public void run(IAction action) { + VMCacheManager.getVMCacheManager().registerCache(getContext(), createCache()); + } + + public void selectionChanged(IAction action, ISelection selection) { + } + + protected abstract Object getContext(); + + protected abstract VMCache createCache(); + +}