mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
[225193] Simplified AbstractVMContext constructor.
This commit is contained in:
parent
4fe0578953
commit
7fe354ae79
7 changed files with 44 additions and 41 deletions
|
@ -73,7 +73,7 @@ public class ExpressionManagerVMNode extends AbstractVMNode
|
|||
final private IExpression fExpression;
|
||||
|
||||
public InvalidExpressionVMContext(ExpressionManagerVMNode node, IExpression expression) {
|
||||
super(node.getVMProvider().getVMAdapter(), node);
|
||||
super(node);
|
||||
fExpression = expression;
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ public class ExpressionManagerVMNode extends AbstractVMNode
|
|||
*/
|
||||
class NewExpressionVMC extends AbstractVMContext {
|
||||
public NewExpressionVMC() {
|
||||
super(getVMProvider().getVMAdapter(), ExpressionManagerVMNode.this);
|
||||
super(ExpressionManagerVMNode.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -49,7 +49,7 @@ public class StandardProcessVMNode extends AbstractVMNode {
|
|||
private final IProcess fProcess;
|
||||
|
||||
VMC(IProcess process) {
|
||||
super(getVMProvider().getVMAdapter(), StandardProcessVMNode.this);
|
||||
super(StandardProcessVMNode.this);
|
||||
fProcess = process;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,50 +1,51 @@
|
|||
package org.eclipse.dd.dsf.ui.viewmodel;
|
||||
|
||||
import org.eclipse.dd.dsf.ui.viewmodel.properties.IElementPropertiesProvider;
|
||||
import org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentationFactory;
|
||||
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider;
|
||||
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementLabelProvider;
|
||||
import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxyFactory;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
|
||||
/**
|
||||
* Implementation of basic view model context interface. The main
|
||||
* purpose of the VMC wrapper is to re-direct adapter queries to the IVMAdapter
|
||||
* and the layout node that the given context was created by.
|
||||
* <p/>
|
||||
* Implementation of basic view model context interface.
|
||||
* <p> The main purpose of the VMC wrapper is to re-direct adapter
|
||||
* queries. The redirecting of adapter queries follows this order:
|
||||
* <ol>
|
||||
* <li>If context implements the adapter itself, it is returned.</li>
|
||||
* <li>If the VM Adapter implements the adapter, the VM Adapter is returned.</li>
|
||||
* <li>If the VM Provider implements the adapter, the VM Provider is returned.</li>
|
||||
* <li>If the VM Node implements the adapter, the VM Node is returned.</li>
|
||||
* </ol>
|
||||
* </p>
|
||||
* <p>
|
||||
* Note: Deriving classes must override the Object.equals/hashCode methods.
|
||||
* This is because the view model context objects are just wrappers that are
|
||||
* created by the view model on demand, so the equals methods must use the
|
||||
* object being wrapped to perform a meaningful comparison.
|
||||
*/
|
||||
@SuppressWarnings("restriction")
|
||||
abstract public class AbstractVMContext implements IVMContext {
|
||||
protected final IVMAdapter fVMAdapter;
|
||||
protected final IVMNode fNode;
|
||||
|
||||
public AbstractVMContext(IVMAdapter adapter, IVMNode node) {
|
||||
fVMAdapter = adapter;
|
||||
public AbstractVMContext(IVMNode node) {
|
||||
fNode = node;
|
||||
}
|
||||
|
||||
public IVMNode getVMNode() { return fNode; }
|
||||
|
||||
/**
|
||||
* IAdapter implementation returns the {@link IVMAdapter} instance for
|
||||
* the interfaces that are actually implemented by the VM Adapter.
|
||||
* These should at least include {@link IElementContentProvider},
|
||||
* {@link IModelProxyFactory}, and {@link IColumnPresentationFactory}.
|
||||
* It also returns the {@link IVMNode} instance for adapters implemented
|
||||
* by the context's node. The interfaces typically implemented by the
|
||||
* node include {@link IElementLabelProvider} and {@link IElementPropertiesProvider}.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object getAdapter(Class adapter) {
|
||||
if (adapter.isInstance(fVMAdapter)) {
|
||||
return fVMAdapter;
|
||||
} else if (adapter.isInstance(fNode)) {
|
||||
return fNode;
|
||||
// If the context implements the given adapter directly, it always takes
|
||||
// precedence.
|
||||
if (adapter.isInstance(this)) {
|
||||
return this;
|
||||
}
|
||||
return null;
|
||||
|
||||
IVMProvider vmProvider = getVMNode().getVMProvider();
|
||||
IVMAdapter vmAdapter = vmProvider.getVMAdapter();
|
||||
if (adapter.isInstance(vmAdapter)) {
|
||||
return vmAdapter;
|
||||
} else if (adapter.isInstance(vmProvider)) {
|
||||
return vmProvider;
|
||||
} else if (adapter.isInstance(getVMNode())) {
|
||||
return getVMNode();
|
||||
}
|
||||
return Platform.getAdapterManager().getAdapter(this, adapter);
|
||||
}
|
||||
|
||||
/** Deriving classes must override. */
|
||||
|
|
|
@ -57,7 +57,7 @@ abstract public class AbstractDMVMNode extends AbstractVMNode implements IVMNode
|
|||
private final IDMContext fDmc;
|
||||
|
||||
public DMVMContext(IDMContext dmc) {
|
||||
super(getVMProvider().getVMAdapter(), AbstractDMVMNode.this);
|
||||
super(AbstractDMVMNode.this);
|
||||
fDmc = dmc;
|
||||
}
|
||||
|
||||
|
@ -73,12 +73,15 @@ abstract public class AbstractDMVMNode extends AbstractVMNode implements IVMNode
|
|||
Object superAdapter = super.getAdapter(adapter);
|
||||
if (superAdapter != null) {
|
||||
return superAdapter;
|
||||
} else if (adapter.isInstance(fDmc)) {
|
||||
} else {
|
||||
// Delegate to the Data Model to find the context.
|
||||
if (adapter.isInstance(fDmc)) {
|
||||
return fDmc;
|
||||
} else {
|
||||
return fDmc.getAdapter(adapter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
|
|
|
@ -13,13 +13,12 @@ package org.eclipse.dd.examples.dsf.filebrowser;
|
|||
import java.io.File;
|
||||
|
||||
import org.eclipse.dd.dsf.ui.viewmodel.AbstractVMContext;
|
||||
import org.eclipse.dd.dsf.ui.viewmodel.IVMAdapter;
|
||||
import org.eclipse.dd.dsf.ui.viewmodel.IVMNode;
|
||||
|
||||
class FileVMContext extends AbstractVMContext {
|
||||
private File fFile;
|
||||
FileVMContext(IVMAdapter adapter, IVMNode layoutNode, File file) {
|
||||
super(adapter, layoutNode);
|
||||
FileVMContext(IVMNode layoutNode, File file) {
|
||||
super(layoutNode);
|
||||
fFile = file;
|
||||
}
|
||||
|
||||
|
|
|
@ -135,7 +135,7 @@ class FileVMNode
|
|||
int offset = update.getOffset() != -1 ? update.getOffset() : 0;
|
||||
int length = update.getLength() != -1 ? update.getLength() : files.length;
|
||||
for (int i = offset; (i < files.length) && (i < (offset + length)); i++) {
|
||||
update.setChild(new FileVMContext(fProvider.getVMAdapter(), FileVMNode.this, files[i]), i);
|
||||
update.setChild(new FileVMContext(FileVMNode.this, files[i]), i);
|
||||
}
|
||||
update.done();
|
||||
}
|
||||
|
@ -260,7 +260,7 @@ class FileVMNode
|
|||
|
||||
File[] pathSegmentDirectoryFiles = pathSegment.listFiles();
|
||||
delta = delta.addNode(
|
||||
new FileVMContext(fProvider.getVMAdapter(), FileVMNode.this, pathSegment),
|
||||
new FileVMContext(FileVMNode.this, pathSegment),
|
||||
nodeOffset + Arrays.asList(allFilesInDirectory).indexOf(pathSegment),
|
||||
IModelDelta.NO_CHANGE,
|
||||
pathSegmentDirectoryFiles != null ? pathSegmentDirectoryFiles.length : 0);
|
||||
|
|
|
@ -56,7 +56,7 @@ class FilesystemRootsVMNode extends AbstractVMNode
|
|||
int offset = update.getOffset() != -1 ? update.getOffset() : 0;
|
||||
int length = update.getLength() != -1 ? update.getLength() : files.length;
|
||||
for (int i = offset; (i < files.length) && (i < (offset + length)); i++) {
|
||||
update.setChild(new FileVMContext(getVMProvider().getVMAdapter(), FilesystemRootsVMNode.this, files[i]), i);
|
||||
update.setChild(new FileVMContext(FilesystemRootsVMNode.this, files[i]), i);
|
||||
}
|
||||
update.done();
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ class FilesystemRootsVMNode extends AbstractVMNode
|
|||
// Check if the specified file is not one of the roots.
|
||||
if (index < roots.length) {
|
||||
ModelDelta delta = parentDelta.addNode(
|
||||
new FileVMContext(getVMProvider().getVMAdapter(), FilesystemRootsVMNode.this, eventRoot),
|
||||
new FileVMContext(FilesystemRootsVMNode.this, eventRoot),
|
||||
index, IModelDelta.NO_CHANGE);
|
||||
|
||||
if (eventFile.equals(eventRoot)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue