From a3649d568b486dbcd2d063cb8328c4470bbe2229 Mon Sep 17 00:00:00 2001 From: Pawel Piech Date: Mon, 26 Nov 2007 21:42:51 +0000 Subject: [PATCH] [206832] Added use of CompositeDMContext. --- .../register/RegisterGroupLayoutNode.java | 32 ++--- .../register/RegisterLayoutNode.java | 10 +- .../variable/VariableLayoutNode.java | 15 +-- .../ui/viewmodel/dm/CompositeDMContext.java | 126 ++++++++++++++++++ 4 files changed, 147 insertions(+), 36 deletions(-) create mode 100644 plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/dm/CompositeDMContext.java diff --git a/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/register/RegisterGroupLayoutNode.java b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/register/RegisterGroupLayoutNode.java index 7d78bcd950d..3d588681ed2 100644 --- a/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/register/RegisterGroupLayoutNode.java +++ b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/register/RegisterGroupLayoutNode.java @@ -23,7 +23,6 @@ import org.eclipse.dd.dsf.debug.service.IRunControl; import org.eclipse.dd.dsf.debug.service.IRegisters.IGroupChangedDMEvent; import org.eclipse.dd.dsf.debug.service.IRegisters.IRegisterGroupDMContext; import org.eclipse.dd.dsf.debug.service.IRegisters.IRegisterGroupDMData; -import org.eclipse.dd.dsf.debug.service.IRunControl.IExecutionDMContext; import org.eclipse.dd.dsf.debug.ui.DsfDebugUIPlugin; import org.eclipse.dd.dsf.debug.ui.viewmodel.IDebugVMConstants; import org.eclipse.dd.dsf.debug.ui.viewmodel.expression.AbstractExpressionLayoutNode; @@ -34,6 +33,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.dm.CompositeDMContext; import org.eclipse.dd.dsf.ui.viewmodel.update.VMCacheManager; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.ILaunch; @@ -151,25 +151,19 @@ public class RegisterGroupLayoutNode extends AbstractExpressionLayoutNode protected void updateElementsInSessionThread(final IChildrenUpdate update) { if (!checkService(IRegisters.class, null, update)) return; - final IExecutionDMContext execDmc = findDmcInPath(update.getElementPath(), IExecutionDMContext.class) ; - - if (execDmc != null) { - getServicesTracker().getService(IRegisters.class).getRegisterGroups( - execDmc, - new DataRequestMonitor(getSession().getExecutor(), null) { - @Override - public void handleCompleted() { - if (!getStatus().isOK()) { - update.done(); - return; - } - fillUpdateWithVMCs(update, getData()); + CompositeDMContext compositeDmc = new CompositeDMContext(getVMProvider().getRootElement(), update.getElementPath()); + getServicesTracker().getService(IRegisters.class).getRegisterGroups( + compositeDmc, + new DataRequestMonitor(getSession().getExecutor(), null) { + @Override + public void handleCompleted() { + if (!getStatus().isOK()) { update.done(); - }}); - } else { - handleFailedUpdate(update); - } - + return; + } + fillUpdateWithVMCs(update, getData()); + update.done(); + }}); } @Override diff --git a/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/register/RegisterLayoutNode.java b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/register/RegisterLayoutNode.java index 94bf4046788..a94cedf4c20 100644 --- a/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/register/RegisterLayoutNode.java +++ b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/register/RegisterLayoutNode.java @@ -38,6 +38,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.dm.CompositeDMContext; import org.eclipse.dd.dsf.ui.viewmodel.update.VMCacheManager; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.ILaunch; @@ -370,15 +371,10 @@ public class RegisterLayoutNode extends AbstractExpressionLayoutNode @Override protected void updateElementsInSessionThread(final IChildrenUpdate update) { - final IRegisterGroupDMContext execDmc = findDmcInPath(update.getElementPath(), IRegisterGroupDMContext.class); - - if (execDmc == null) { - handleFailedUpdate(update); - return; - } + CompositeDMContext compositeDmc = new CompositeDMContext(getVMProvider().getRootElement(), update.getElementPath()); getServicesTracker().getService(IRegisters.class).getRegisters( - execDmc, + compositeDmc, new DataRequestMonitor(getSession().getExecutor(), null) { @Override public void handleCompleted() { diff --git a/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/variable/VariableLayoutNode.java b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/variable/VariableLayoutNode.java index 196a0e9503a..4b993173fde 100644 --- a/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/variable/VariableLayoutNode.java +++ b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/variable/VariableLayoutNode.java @@ -13,8 +13,6 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; import org.eclipse.dd.dsf.concurrent.DataRequestMonitor; import org.eclipse.dd.dsf.concurrent.DsfExecutor; import org.eclipse.dd.dsf.concurrent.MultiRequestMonitor; @@ -43,6 +41,7 @@ import org.eclipse.dd.dsf.ui.viewmodel.AbstractVMProvider; import org.eclipse.dd.dsf.ui.viewmodel.IVMContext; import org.eclipse.dd.dsf.ui.viewmodel.IVMLayoutNode; import org.eclipse.dd.dsf.ui.viewmodel.VMDelta; +import org.eclipse.dd.dsf.ui.viewmodel.dm.CompositeDMContext; import org.eclipse.dd.dsf.ui.viewmodel.update.VMCacheManager; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.ILaunch; @@ -441,15 +440,11 @@ public class VariableLayoutNode extends AbstractExpressionLayoutNode implements @Override protected void getElementForExpressionPart(IChildrenUpdate update, String expressionPartText, DataRequestMonitor rm) { - final IFrameDMContext frameDmc = findDmcInPath(update.getElementPath(), IFrameDMContext.class); - final IExpressions expressionService = getServicesTracker().getService(IExpressions.class); + CompositeDMContext compositeDmc = new CompositeDMContext(getVMProvider().getRootElement(), update.getElementPath()); - if (frameDmc != null) { - IExpressionDMContext expressionDMC = expressionService.createExpression(frameDmc, expressionPartText); - rm.setData(createVMContext(expressionDMC)); - } else { - rm.setStatus(new Status(IStatus.ERROR, DsfDebugUIPlugin.PLUGIN_ID, IDsfService.INVALID_HANDLE, "Invalid context", null)); //$NON-NLS-1$ - } + final IExpressions expressionService = getServicesTracker().getService(IExpressions.class); + IExpressionDMContext expressionDMC = expressionService.createExpression(compositeDmc, expressionPartText); + rm.setData(createVMContext(expressionDMC)); rm.done(); } diff --git a/plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/dm/CompositeDMContext.java b/plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/dm/CompositeDMContext.java new file mode 100644 index 00000000000..0c2234465b9 --- /dev/null +++ b/plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/dm/CompositeDMContext.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.dd.dsf.ui.viewmodel.dm; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.dd.dsf.datamodel.IDMContext; +import org.eclipse.dd.dsf.ui.viewmodel.dm.AbstractDMVMLayoutNode.DMVMContext; +import org.eclipse.jface.viewers.TreePath; + +/** + * Object used to combine several DM Contexts found in a tree path of a viewer + * update. This object allows the view model to pass complete data model context + * information found in the view to the services. + */ +public class CompositeDMContext implements IDMContext { + + /** + * The input object to the view. This object is not included in the tree + * path. + */ + private final Object fViewerInputObject; + + /** + * The tree path for which the context is created. + */ + private final TreePath fTreePath; + + /** + * The list of parent contexts derived from the input object and + * the path. It is calculated on demand. + */ + private IDMContext[] fParents; + + /** + * Main constructor provides all data needed to implement the IModelContext + * interface. + */ + public CompositeDMContext(Object viewerInputObject, TreePath treePath) { + fViewerInputObject = viewerInputObject; + fTreePath = treePath; + } + + /** + * Returns the session ID of the last DMVMContext element found in the tree + * path of this composite context. May return an empty string if no DMVMContext + * is found in path. + *

+ * Note: The session ID is primarily used by UI components to get access to the + * correct session and executor for the given context. The composite context is + * intended to be created by UI clients which already know the session ID so + * the fact that this method may not return a reliable result is acceptable. + *

+ */ + public String getSessionId() { + return getElement().getDMC().getSessionId(); + } + + public IDMContext[] getParents() { + if (fParents == null) { + List parentsList = new ArrayList(fTreePath.getSegmentCount() + 1); + for (int i = fTreePath.getSegmentCount() - 1; i >=0 ; i--) { + if (fTreePath.getSegment(i) instanceof DMVMContext) { + parentsList.add( ((DMVMContext)fTreePath.getSegment(i)).getDMC() ); + } + } + if (fViewerInputObject instanceof DMVMContext) { + parentsList.add( ((DMVMContext)fViewerInputObject).getDMC() ); + } + + fParents = parentsList.toArray(new IDMContext[parentsList.size()]); + } + return fParents; + } + + /** + * Returns the given adapter of the last DMVMContext element found in the tree + * path of this composite context. Will return null if no DMVMContext is found + * in path. + * @see #getSessionId() + */ + @SuppressWarnings("unchecked") + public Object getAdapter(Class adapterType) { + return getElement().getAdapter(adapterType); + } + + @Override + public boolean equals(Object obj) { + return obj instanceof CompositeDMContext && + ((CompositeDMContext)obj).fTreePath.equals(fTreePath) && + ((CompositeDMContext)obj).fViewerInputObject.equals(fViewerInputObject); + } + + @Override + public int hashCode() { + return fTreePath.hashCode() + fViewerInputObject.hashCode(); + } + + /** + * Returns the principal element that this composite context is based on. + * It is used for calculating the session ID and the adapters of this + * context. May return null if no DMVMContext is found in + * path. + */ + private DMVMContext getElement() { + for (int i = fTreePath.getSegmentCount() - 1; i >= 0; i--) { + if (fTreePath.getSegment(i) instanceof DMVMContext) { + return (DMVMContext)fTreePath.getSegment(i); + } + } + if (fViewerInputObject instanceof DMVMContext) { + return (DMVMContext)fViewerInputObject; + } + + return null; + } +}