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;
|
final private IExpression fExpression;
|
||||||
|
|
||||||
public InvalidExpressionVMContext(ExpressionManagerVMNode node, IExpression expression) {
|
public InvalidExpressionVMContext(ExpressionManagerVMNode node, IExpression expression) {
|
||||||
super(node.getVMProvider().getVMAdapter(), node);
|
super(node);
|
||||||
fExpression = expression;
|
fExpression = expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ public class ExpressionManagerVMNode extends AbstractVMNode
|
||||||
*/
|
*/
|
||||||
class NewExpressionVMC extends AbstractVMContext {
|
class NewExpressionVMC extends AbstractVMContext {
|
||||||
public NewExpressionVMC() {
|
public NewExpressionVMC() {
|
||||||
super(getVMProvider().getVMAdapter(), ExpressionManagerVMNode.this);
|
super(ExpressionManagerVMNode.this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class StandardProcessVMNode extends AbstractVMNode {
|
||||||
private final IProcess fProcess;
|
private final IProcess fProcess;
|
||||||
|
|
||||||
VMC(IProcess process) {
|
VMC(IProcess process) {
|
||||||
super(getVMProvider().getVMAdapter(), StandardProcessVMNode.this);
|
super(StandardProcessVMNode.this);
|
||||||
fProcess = process;
|
fProcess = process;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,50 +1,51 @@
|
||||||
package org.eclipse.dd.dsf.ui.viewmodel;
|
package org.eclipse.dd.dsf.ui.viewmodel;
|
||||||
|
|
||||||
import org.eclipse.dd.dsf.ui.viewmodel.properties.IElementPropertiesProvider;
|
import org.eclipse.core.runtime.Platform;
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of basic view model context interface. The main
|
* Implementation of basic view model context interface.
|
||||||
* purpose of the VMC wrapper is to re-direct adapter queries to the IVMAdapter
|
* <p> The main purpose of the VMC wrapper is to re-direct adapter
|
||||||
* and the layout node that the given context was created by.
|
* queries. The redirecting of adapter queries follows this order:
|
||||||
* <p/>
|
* <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.
|
* Note: Deriving classes must override the Object.equals/hashCode methods.
|
||||||
* This is because the view model context objects are just wrappers that are
|
* 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
|
* created by the view model on demand, so the equals methods must use the
|
||||||
* object being wrapped to perform a meaningful comparison.
|
* object being wrapped to perform a meaningful comparison.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("restriction")
|
|
||||||
abstract public class AbstractVMContext implements IVMContext {
|
abstract public class AbstractVMContext implements IVMContext {
|
||||||
protected final IVMAdapter fVMAdapter;
|
|
||||||
protected final IVMNode fNode;
|
protected final IVMNode fNode;
|
||||||
|
|
||||||
public AbstractVMContext(IVMAdapter adapter, IVMNode node) {
|
public AbstractVMContext(IVMNode node) {
|
||||||
fVMAdapter = adapter;
|
|
||||||
fNode = node;
|
fNode = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IVMNode getVMNode() { return fNode; }
|
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")
|
@SuppressWarnings("unchecked")
|
||||||
public Object getAdapter(Class adapter) {
|
public Object getAdapter(Class adapter) {
|
||||||
if (adapter.isInstance(fVMAdapter)) {
|
// If the context implements the given adapter directly, it always takes
|
||||||
return fVMAdapter;
|
// precedence.
|
||||||
} else if (adapter.isInstance(fNode)) {
|
if (adapter.isInstance(this)) {
|
||||||
return fNode;
|
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. */
|
/** Deriving classes must override. */
|
||||||
|
|
|
@ -57,7 +57,7 @@ abstract public class AbstractDMVMNode extends AbstractVMNode implements IVMNode
|
||||||
private final IDMContext fDmc;
|
private final IDMContext fDmc;
|
||||||
|
|
||||||
public DMVMContext(IDMContext dmc) {
|
public DMVMContext(IDMContext dmc) {
|
||||||
super(getVMProvider().getVMAdapter(), AbstractDMVMNode.this);
|
super(AbstractDMVMNode.this);
|
||||||
fDmc = dmc;
|
fDmc = dmc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,10 +73,13 @@ abstract public class AbstractDMVMNode extends AbstractVMNode implements IVMNode
|
||||||
Object superAdapter = super.getAdapter(adapter);
|
Object superAdapter = super.getAdapter(adapter);
|
||||||
if (superAdapter != null) {
|
if (superAdapter != null) {
|
||||||
return superAdapter;
|
return superAdapter;
|
||||||
} else if (adapter.isInstance(fDmc)) {
|
|
||||||
return fDmc;
|
|
||||||
} else {
|
} else {
|
||||||
return fDmc.getAdapter(adapter);
|
// Delegate to the Data Model to find the context.
|
||||||
|
if (adapter.isInstance(fDmc)) {
|
||||||
|
return fDmc;
|
||||||
|
} else {
|
||||||
|
return fDmc.getAdapter(adapter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,12 @@ package org.eclipse.dd.examples.dsf.filebrowser;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import org.eclipse.dd.dsf.ui.viewmodel.AbstractVMContext;
|
import org.eclipse.dd.dsf.ui.viewmodel.AbstractVMContext;
|
||||||
import org.eclipse.dd.dsf.ui.viewmodel.IVMAdapter;
|
|
||||||
import org.eclipse.dd.dsf.ui.viewmodel.IVMNode;
|
import org.eclipse.dd.dsf.ui.viewmodel.IVMNode;
|
||||||
|
|
||||||
class FileVMContext extends AbstractVMContext {
|
class FileVMContext extends AbstractVMContext {
|
||||||
private File fFile;
|
private File fFile;
|
||||||
FileVMContext(IVMAdapter adapter, IVMNode layoutNode, File file) {
|
FileVMContext(IVMNode layoutNode, File file) {
|
||||||
super(adapter, layoutNode);
|
super(layoutNode);
|
||||||
fFile = file;
|
fFile = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,7 @@ class FileVMNode
|
||||||
int offset = update.getOffset() != -1 ? update.getOffset() : 0;
|
int offset = update.getOffset() != -1 ? update.getOffset() : 0;
|
||||||
int length = update.getLength() != -1 ? update.getLength() : files.length;
|
int length = update.getLength() != -1 ? update.getLength() : files.length;
|
||||||
for (int i = offset; (i < files.length) && (i < (offset + length)); i++) {
|
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();
|
update.done();
|
||||||
}
|
}
|
||||||
|
@ -260,7 +260,7 @@ class FileVMNode
|
||||||
|
|
||||||
File[] pathSegmentDirectoryFiles = pathSegment.listFiles();
|
File[] pathSegmentDirectoryFiles = pathSegment.listFiles();
|
||||||
delta = delta.addNode(
|
delta = delta.addNode(
|
||||||
new FileVMContext(fProvider.getVMAdapter(), FileVMNode.this, pathSegment),
|
new FileVMContext(FileVMNode.this, pathSegment),
|
||||||
nodeOffset + Arrays.asList(allFilesInDirectory).indexOf(pathSegment),
|
nodeOffset + Arrays.asList(allFilesInDirectory).indexOf(pathSegment),
|
||||||
IModelDelta.NO_CHANGE,
|
IModelDelta.NO_CHANGE,
|
||||||
pathSegmentDirectoryFiles != null ? pathSegmentDirectoryFiles.length : 0);
|
pathSegmentDirectoryFiles != null ? pathSegmentDirectoryFiles.length : 0);
|
||||||
|
|
|
@ -56,7 +56,7 @@ class FilesystemRootsVMNode extends AbstractVMNode
|
||||||
int offset = update.getOffset() != -1 ? update.getOffset() : 0;
|
int offset = update.getOffset() != -1 ? update.getOffset() : 0;
|
||||||
int length = update.getLength() != -1 ? update.getLength() : files.length;
|
int length = update.getLength() != -1 ? update.getLength() : files.length;
|
||||||
for (int i = offset; (i < files.length) && (i < (offset + length)); i++) {
|
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();
|
update.done();
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,7 @@ class FilesystemRootsVMNode extends AbstractVMNode
|
||||||
// Check if the specified file is not one of the roots.
|
// Check if the specified file is not one of the roots.
|
||||||
if (index < roots.length) {
|
if (index < roots.length) {
|
||||||
ModelDelta delta = parentDelta.addNode(
|
ModelDelta delta = parentDelta.addNode(
|
||||||
new FileVMContext(getVMProvider().getVMAdapter(), FilesystemRootsVMNode.this, eventRoot),
|
new FileVMContext(FilesystemRootsVMNode.this, eventRoot),
|
||||||
index, IModelDelta.NO_CHANGE);
|
index, IModelDelta.NO_CHANGE);
|
||||||
|
|
||||||
if (eventFile.equals(eventRoot)) {
|
if (eventFile.equals(eventRoot)) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue