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 3d588681ed2..79cfdcec889 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 @@ -33,7 +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.dm.CompositeDMVMContext; import org.eclipse.dd.dsf.ui.viewmodel.update.VMCacheManager; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.ILaunch; @@ -151,7 +151,7 @@ public class RegisterGroupLayoutNode extends AbstractExpressionLayoutNode protected void updateElementsInSessionThread(final IChildrenUpdate update) { if (!checkService(IRegisters.class, null, update)) return; - CompositeDMContext compositeDmc = new CompositeDMContext(getVMProvider().getRootElement(), update.getElementPath()); + CompositeDMVMContext compositeDmc = new CompositeDMVMContext(getVMProvider().getRootElement(), update.getElementPath()); getServicesTracker().getService(IRegisters.class).getRegisterGroups( compositeDmc, new DataRequestMonitor(getSession().getExecutor(), null) { 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 a94cedf4c20..43afcdf3e95 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,7 +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.dm.CompositeDMVMContext; import org.eclipse.dd.dsf.ui.viewmodel.update.VMCacheManager; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.ILaunch; @@ -371,7 +371,7 @@ public class RegisterLayoutNode extends AbstractExpressionLayoutNode @Override protected void updateElementsInSessionThread(final IChildrenUpdate update) { - CompositeDMContext compositeDmc = new CompositeDMContext(getVMProvider().getRootElement(), update.getElementPath()); + CompositeDMVMContext compositeDmc = new CompositeDMVMContext(getVMProvider().getRootElement(), update.getElementPath()); getServicesTracker().getService(IRegisters.class).getRegisters( compositeDmc, 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 4b993173fde..1a4107a0ba2 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 @@ -41,7 +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.dm.CompositeDMVMContext; import org.eclipse.dd.dsf.ui.viewmodel.update.VMCacheManager; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.ILaunch; @@ -440,7 +440,7 @@ public class VariableLayoutNode extends AbstractExpressionLayoutNode implements @Override protected void getElementForExpressionPart(IChildrenUpdate update, String expressionPartText, DataRequestMonitor rm) { - CompositeDMContext compositeDmc = new CompositeDMContext(getVMProvider().getRootElement(), update.getElementPath()); + CompositeDMVMContext compositeDmc = new CompositeDMVMContext(getVMProvider().getRootElement(), update.getElementPath()); final IExpressions expressionService = getServicesTracker().getService(IExpressions.class); IExpressionDMContext expressionDMC = expressionService.createExpression(compositeDmc, expressionPartText); 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 deleted file mode 100644 index 0c2234465b9..00000000000 --- a/plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/dm/CompositeDMContext.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * 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; - } -} diff --git a/plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/dm/CompositeDMVMContext.java b/plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/dm/CompositeDMVMContext.java new file mode 100644 index 00000000000..dce32ee6f0a --- /dev/null +++ b/plugins/org.eclipse.dd.dsf.ui/src/org/eclipse/dd/dsf/ui/viewmodel/dm/CompositeDMVMContext.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * 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.datamodel.CompositeDMContext; +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 CompositeDMVMContext extends CompositeDMContext { + + /** + * Have to pass in an empty array of contexts to parent constructor + * in order to be able to calculate the + */ + private static IDMContext[] EMPTY_CONTEXTS_ARRAY = new IDMContext[0]; + + /** + * The list of parent contexts derived from the input object and + * the path. It is calculated on demand. + */ + private IDMContext[] fParents; + + /** + * Creates a composite context based on view model + */ + public CompositeDMVMContext(Object viewerInputObject, TreePath treePath) { + super(EMPTY_CONTEXTS_ARRAY); + List parentsList = new ArrayList(treePath.getSegmentCount() + 1); + for (int i = treePath.getSegmentCount() - 1; i >=0 ; i--) { + if (treePath.getSegment(i) instanceof DMVMContext) { + parentsList.add( ((DMVMContext)treePath.getSegment(i)).getDMC() ); + } + } + if (viewerInputObject instanceof DMVMContext) { + parentsList.add( ((DMVMContext)viewerInputObject).getDMC() ); + } + + fParents = parentsList.toArray(new IDMContext[parentsList.size()]); +} + + @Override + public IDMContext[] getParents() { + return fParents; + } +} diff --git a/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/datamodel/CompositeDMContext.java b/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/datamodel/CompositeDMContext.java new file mode 100644 index 00000000000..5cc65fc88ca --- /dev/null +++ b/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/datamodel/CompositeDMContext.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * 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.datamodel; + +import java.util.Arrays; + +/** + * Generic DM context used to combine several DM Contexts. This object allows + * clients and other services to combine several contexts into one in order to + * pass them as an argument to a method which takes a generic context as an + * argument. + */ +public class CompositeDMContext implements IDMContext { + + public static String INVALID_SESSION_ID = ""; //$NON-NLS-1$ + + /** + * The list of parent contexts that this composite context is made up of. + */ + private final IDMContext[] fParents; + + /** + * Main constructor provides all data needed to implement the IModelContext + * interface. + * @param parents Array of parent contexts that this composite context is + * made up of. It can be an empty array, but it cannot be null. + */ + public CompositeDMContext(IDMContext[] parents) { + fParents = parents; + } + + /** + * Returns the session ID of the first element in the array of parents of this + * context. May return an empty string if the parents array has no elements. + *

+ * 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 clients which already know the session ID so + * the fact that this method may not return a reliable result is acceptable. + *

+ */ + public String getSessionId() { + IDMContext[] parents = getParents(); + if (parents.length > 0) { + return parents[0].getSessionId(); + } else { + return INVALID_SESSION_ID; + } + } + + /** + * Returns the list of parents that this composite context is based on. Subclasses + * may override this method to calculate their own set of parents. + */ + public IDMContext[] getParents() { + 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) { + IDMContext[] parents = getParents(); + if (parents.length > 0) { + return parents[0].getAdapter(adapterType); + } else { + return null; + } + } + + @Override + public boolean equals(Object obj) { + return obj instanceof CompositeDMContext && Arrays.equals(((CompositeDMContext)obj).getParents(), getParents()); + } + + @Override + public int hashCode() { + return Arrays.hashCode(getParents()); + } +}