1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

[206832] Added use of CompositeDMContext.

This commit is contained in:
Pawel Piech 2007-11-26 21:42:51 +00:00
parent 976a665a68
commit a3649d568b
4 changed files with 147 additions and 36 deletions

View file

@ -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<IRegisterGroupDMContext[]>(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<IRegisterGroupDMContext[]>(getSession().getExecutor(), null) {
@Override
public void handleCompleted() {
if (!getStatus().isOK()) {
update.done();
}});
} else {
handleFailedUpdate(update);
}
return;
}
fillUpdateWithVMCs(update, getData());
update.done();
}});
}
@Override

View file

@ -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<IRegisterDMContext[]>(getSession().getExecutor(), null) {
@Override
public void handleCompleted() {

View file

@ -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<Object> 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();
}

View file

@ -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.
* <p>
* 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.
* </p>
*/
public String getSessionId() {
return getElement().getDMC().getSessionId();
}
public IDMContext[] getParents() {
if (fParents == null) {
List<IDMContext> parentsList = new ArrayList<IDMContext>(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 <code>null</code> 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;
}
}