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

Bug 80175: Replace the CDT source lookup by the source lookup provided by Eclipse platform.

This commit is contained in:
Mikhail Khodjaiants 2005-03-22 00:11:28 +00:00
parent ec85b24cb7
commit 4bc76bbea7
22 changed files with 1313 additions and 9 deletions

View file

@ -1,3 +1,16 @@
2005-03-21 Mikhail Khodjaiants
Bug 80175: Replace the CDT source lookup by the source lookup provided by Eclipse platform.
* MappingSourceContainer.java: new
* DisassemblyBlock.java
* CSourceLookupDirector.java: new
* CSourceLookupParticipant.java: new
* CSourcePathComputerDelegate.java: new
* MapEntrySourceContainer.java: new
* MapEntrySourceContainerType.java: new
* MappingSourceContainerType.java: new
* plugin.properties
* plugin.xml
2005-03-17 Mikhail Khodjaiants
If casting of variable to a type or array causes an error, the status
of the variable is set to "error" and it can't be reset by subsequent castings.

View file

@ -16,4 +16,9 @@ CDebugger.name=C/C++ Development Tools Core Debugger Extension
cLineBreakpoints.name=C/C++ Line Breakpoints
cAddressBreakpoints.name=C/C++ Address Breakpoints
cFunctionBreakpoints.name=C/C++ Function Breakpoints
cWatchpoints.name=C/C++ Watchpoints
cWatchpoints.name=C/C++ Watchpoints
containerName.mapping=Path Mapping
containerDescription.mapping=A path mapping.
containerName.mapEntry=Path Map Entry
containerDescription.mapEntry=An entry in a path mapping.

View file

@ -146,5 +146,31 @@
point="org.eclipse.core.runtime.preferences">
<initializer class="org.eclipse.cdt.debug.internal.core.CDebugCorePreferenceInitializer"/>
</extension>
<extension
point="org.eclipse.debug.core.sourcePathComputers">
<sourcePathComputer
class="org.eclipse.cdt.debug.internal.core.sourcelookup.CSourcePathComputerDelegate"
id="org.eclipse.cdt.debug.core.sourcePathComputer"/>
</extension>
<extension
point="org.eclipse.debug.core.sourceLocators">
<sourceLocator
class="org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLookupDirector"
name="C/C++ Source Locator"
id="org.eclipse.cdt.debug.core.sourceLocator"/>
</extension>
<extension
point="org.eclipse.debug.core.sourceContainerTypes">
<sourceContainerType
class="org.eclipse.cdt.debug.internal.core.sourcelookup.MappingSourceContainerType"
description="%containerDescription.mapping"
id="org.eclipse.cdt.debug.core.containerType.mapping"
name="%containerName.mapping"/>
<sourceContainerType
class="org.eclipse.cdt.debug.internal.core.sourcelookup.MapEntrySourceContainerType"
description="%containerDescription.mapEntry"
id="org.eclipse.cdt.debug.core.containerType.mapEntry"
name="%containerName.mapEntry"/>
</extension>
</plugin>

View file

@ -0,0 +1,175 @@
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.core.sourcelookup;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.internal.core.sourcelookup.MapEntrySourceContainer;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainer;
import org.eclipse.debug.internal.core.sourcelookup.SourceLookupMessages;
/**
* The source container for path mappings.
*/
public class MappingSourceContainer extends AbstractSourceContainer {
/**
* Unique identifier for the mapping source container type
* (value <code>org.eclipse.cdt.debug.core.containerType.mapping</code>).
*/
public static final String TYPE_ID = CDebugCorePlugin.getUniqueIdentifier() + ".containerType.mapping"; //$NON-NLS-1$
private ArrayList fContainers;
/**
* Constructor for MappingSourceContainer.
*/
public MappingSourceContainer() {
fContainers = new ArrayList();
}
/**
* Constructor for MappingSourceContainer.
*/
public MappingSourceContainer( MapEntrySourceContainer[] entries ) {
super();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getName()
*/
public String getName() {
return "Path Mappings";
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getType()
*/
public ISourceContainerType getType() {
return getSourceContainerType( TYPE_ID );
}
/* (non-Javadoc)
* @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainer#isComposite()
*/
public boolean isComposite() {
return !fContainers.isEmpty();
}
/* (non-Javadoc)
* @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainer#findSourceElements(java.lang.String)
*/
public Object[] findSourceElements( String name ) throws CoreException {
return findSourceElements( name, getSourceContainers() );
}
protected Object[] findSourceElements( String name, ISourceContainer[] containers ) throws CoreException {
List results = null;
CoreException single = null;
MultiStatus multiStatus = null;
if ( isFindDuplicates() ) {
results = new ArrayList();
}
for( int i = 0; i < containers.length; i++ ) {
ISourceContainer container = containers[i];
try {
Object[] objects = container.findSourceElements( name );
if ( objects.length > 0 ) {
if ( isFindDuplicates() ) {
for( int j = 0; j < objects.length; j++ ) {
results.add( objects[j] );
}
}
else {
if ( objects.length == 1 ) {
return objects;
}
return new Object[]{ objects[0] };
}
}
}
catch( CoreException e ) {
if ( single == null ) {
single = e;
}
else if ( multiStatus == null ) {
multiStatus = new MultiStatus( DebugPlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, new IStatus[]{ single.getStatus() }, SourceLookupMessages.getString( "CompositeSourceContainer.0" ), null ); //$NON-NLS-1$
multiStatus.add( e.getStatus() );
}
else {
multiStatus.add( e.getStatus() );
}
}
}
if ( results == null ) {
if ( multiStatus != null ) {
throw new CoreException( multiStatus );
}
else if ( single != null ) {
throw single;
}
return EMPTY;
}
return results.toArray();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainer#getSourceContainers()
*/
public ISourceContainer[] getSourceContainers() throws CoreException {
return (MapEntrySourceContainer[])fContainers.toArray( new MapEntrySourceContainer[fContainers.size()] );
}
public void addMapEntry( MapEntrySourceContainer entry ) {
fContainers.add( entry );
}
public void addMapEntries( MapEntrySourceContainer[] entries ) {
fContainers.addAll( Arrays.asList( entries ) );
}
public void removeMapEntry( MapEntrySourceContainer entry ) {
fContainers.remove( entry );
}
public void removeMapEntries( MapEntrySourceContainer[] entries ) {
fContainers.removeAll( Arrays.asList( entries ) );
}
public void clear() {
Iterator it = fContainers.iterator();
while( it.hasNext() ) {
((ISourceContainer)it.next()).dispose();
}
fContainers.clear();
}
/* (non-Javadoc)
* @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainer#dispose()
*/
public void dispose() {
super.dispose();
Iterator it = fContainers.iterator();
while( it.hasNext() ) {
((ISourceContainer)it.next()).dispose();
}
fContainers.clear();
}
}

View file

@ -31,6 +31,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.model.ISourceLocator;
import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
/**
* CDI-based implementation of <code>IDisassemblyBlock</code>.
@ -57,11 +58,7 @@ public class DisassemblyBlock implements IDisassemblyBlock, IAdaptable {
public static DisassemblyBlock create( IDisassembly disassembly, ICDIMixedInstruction[] instructions ) {
DisassemblyBlock block = new DisassemblyBlock( disassembly );
block.setMixedMode( true );
ISourceLocator adapter = disassembly.getDebugTarget().getLaunch().getSourceLocator();
ICSourceLocator locator = null;
if ( adapter instanceof IAdaptable ) {
locator = (ICSourceLocator)((IAdaptable)adapter).getAdapter( ICSourceLocator.class );
}
ISourceLocator locator = disassembly.getDebugTarget().getLaunch().getSourceLocator();
IAddressFactory factory = ((CDebugTarget)disassembly.getDebugTarget()).getAddressFactory();
block.setSourceLines( createSourceLines( factory, locator, instructions ) );
block.initializeAddresses();
@ -136,12 +133,18 @@ public class DisassemblyBlock implements IDisassemblyBlock, IAdaptable {
public void dispose() {
}
private static IAsmSourceLine[] createSourceLines( IAddressFactory factory, ICSourceLocator locator, ICDIMixedInstruction[] mi ) {
private static IAsmSourceLine[] createSourceLines( IAddressFactory factory, ISourceLocator locator, ICDIMixedInstruction[] mi ) {
IAsmSourceLine[] result = new IAsmSourceLine[mi.length];
LineNumberReader reader = null;
if ( result.length > 0 && locator != null ) {
String fileName = mi[0].getFileName();
Object element = locator.findSourceElement( fileName );
Object element = null;
if ( locator instanceof ISourceLookupDirector ) {
element = ((ISourceLookupDirector)locator).getSourceElement( fileName );
}
if ( locator instanceof ICSourceLocator ) {
element = ((ICSourceLocator)locator).findSourceElement( fileName );
}
File file= null;
if ( element instanceof IFile ) {
file = ((IFile)element).getLocation().toFile();

View file

@ -0,0 +1,52 @@
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.internal.core.sourcelookup;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer;
import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector;
import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
import org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant;
import org.eclipse.debug.core.sourcelookup.containers.DirectorySourceContainer;
import org.eclipse.debug.core.sourcelookup.containers.FolderSourceContainer;
import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer;
import org.eclipse.debug.core.sourcelookup.containers.WorkspaceSourceContainer;
/**
* C/C++ source lookup director.
*/
public class CSourceLookupDirector extends AbstractSourceLookupDirector {
private static Set fFilteredTypes;
static {
fFilteredTypes = new HashSet();
fFilteredTypes.add( WorkspaceSourceContainer.TYPE_ID );
fFilteredTypes.add( ProjectSourceContainer.TYPE_ID );
fFilteredTypes.add( FolderSourceContainer.TYPE_ID );
fFilteredTypes.add( DirectorySourceContainer.TYPE_ID );
fFilteredTypes.add( MappingSourceContainer.TYPE_ID );
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.ISourceLookupDirector#initializeParticipants()
*/
public void initializeParticipants() {
addParticipants( new ISourceLookupParticipant[]{ new CSourceLookupParticipant() } );
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.ISourceLookupDirector#supportsSourceContainerType(org.eclipse.debug.core.sourcelookup.ISourceContainerType)
*/
public boolean supportsSourceContainerType( ISourceContainerType type ) {
return fFilteredTypes.contains( type.getId() );
}
}

View file

@ -0,0 +1,60 @@
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.internal.core.sourcelookup;
import org.eclipse.cdt.debug.core.model.ICStackFrame;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant;
/**
* A source lookup participant that searches for C/C++ source code.
*/
public class CSourceLookupParticipant extends AbstractSourceLookupParticipant {
static private class NoSourceElement {
}
private static final NoSourceElement gfNoSource = new NoSourceElement();
/* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant#getSourceName(java.lang.Object)
*/
public String getSourceName( Object object ) throws CoreException {
if ( object instanceof String ) {
return (String)object;
}
if ( object instanceof IAdaptable ) {
ICStackFrame frame = (ICStackFrame)((IAdaptable)object).getAdapter( ICStackFrame.class );
if ( frame != null ) {
String name = frame.getFile();
return ( name != null && name.trim().length() > 0 ) ? name : null;
}
}
return null;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant#findSourceElements(java.lang.Object)
*/
public Object[] findSourceElements( Object object ) throws CoreException {
// Workaround for cases when the stack frame doesn't contain the source file name
if ( object instanceof IAdaptable ) {
ICStackFrame frame = (ICStackFrame)((IAdaptable)object).getAdapter( ICStackFrame.class );
if ( frame != null ) {
String name = frame.getFile();
if ( name == null || name.trim().length() == 0 )
return new Object[] { gfNoSource };
}
}
return super.findSourceElements( object );
}
}

View file

@ -0,0 +1,48 @@
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.internal.core.sourcelookup;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.debug.core.sourcelookup.ISourcePathComputerDelegate;
import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer;
/**
* Computes the default source lookup path for a launch configuration.
*/
public class CSourcePathComputerDelegate implements ISourcePathComputerDelegate {
/**
* Constructor for CSourcePathComputerDelegate.
*/
public CSourcePathComputerDelegate() {
super();
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.ISourcePathComputerDelegate#computeSourceContainers(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.runtime.IProgressMonitor)
*/
public ISourceContainer[] computeSourceContainers( ILaunchConfiguration configuration, IProgressMonitor monitor ) throws CoreException {
String projectName = configuration.getAttribute( ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String)null );
if ( projectName != null ) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( projectName );
if ( project.exists() ) {
return new ISourceContainer[] { new ProjectSourceContainer( project, true ) };
}
}
return new ISourceContainer[0];
}
}

View file

@ -0,0 +1,110 @@
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.internal.core.sourcelookup;
import java.io.File;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.LinkedList;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainer;
import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
/**
* The source container that maps a backend path to the local filesystem path.
*/
public class MapEntrySourceContainer extends AbstractSourceContainer {
/**
* Unique identifier for the map entry source container type
* (value <code>org.eclipse.cdt.debug.core.containerType.mapEntry</code>).
*/
public static final String TYPE_ID = CDebugCorePlugin.getUniqueIdentifier() + ".containerType.mapEntry"; //$NON-NLS-1$
private IPath fLocalPath;
private IPath fBackendPath;
/**
* Constructor for MapEntrySourceContainer.
*/
public MapEntrySourceContainer( IPath backend, IPath local ) {
fBackendPath = backend;
fLocalPath = local;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.ISourceContainer#findSourceElements(java.lang.String)
*/
public Object[] findSourceElements( String name ) throws CoreException {
IPath path = new Path( name );
if ( getBackendPath().isPrefixOf( path ) ) {
path = path.removeFirstSegments( getBackendPath().segmentCount() );
path = getLocalPath().append( path );
IFile[] wsFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation( path );
ArrayList list = new ArrayList();
for( int j = 0; j < wsFiles.length; ++j ) {
if ( wsFiles[j].exists() ) {
list.add( wsFiles[j] );
if ( !isFindDuplicates() )
break;
}
}
if ( list.size() > 0 )
return list.toArray();
File file = path.toFile();
if ( file.exists() && file.isFile() ) {
return new Object[] { new LocalFileStorage( file ) };
}
}
return EMPTY;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getName()
*/
public String getName() {
return MessageFormat.format( "{0} - {1}", new String[] { getBackendPath().toString(), getLocalPath().toOSString() } ); //$NON-NLS-1$
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getType()
*/
public ISourceContainerType getType() {
return getSourceContainerType( TYPE_ID );
}
protected IPath getLocalPath() {
return fLocalPath;
}
protected IPath getBackendPath() {
return fBackendPath;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals( Object o ) {
if ( !(o instanceof MapEntrySourceContainer ) )
return false;
MapEntrySourceContainer entry = (MapEntrySourceContainer)o;
return ( entry.getBackendPath().equals( getBackendPath() ) && entry.getLocalPath().equals( getLocalPath() ) );
}
}

View file

@ -0,0 +1,69 @@
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.internal.core.sourcelookup;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainerTypeDelegate;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
* The map entry container type.
*/
public class MapEntrySourceContainerType extends AbstractSourceContainerTypeDelegate {
private final static String ELEMENT_NAME = "mapEntry"; //$NON-NLS-1$
private final static String BACKEND_PATH = "backendPath"; //$NON-NLS-1$
private final static String LOCAL_PATH = "localPath"; //$NON-NLS-1$
/* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.ISourceContainerTypeDelegate#createSourceContainer(java.lang.String)
*/
public ISourceContainer createSourceContainer( String memento ) throws CoreException {
Node node = parseDocument( memento );
if ( node.getNodeType() == Node.ELEMENT_NODE ) {
Element element = (Element)node;
if ( ELEMENT_NAME.equals( element.getNodeName() ) ) {
String path = element.getAttribute( BACKEND_PATH );
IPath backend = new Path( path );
if ( !backend.isValidPath( path ) ) {
abort( "Source lookup: unable to restore map entry - missing backend path attribute.", null );
}
path = element.getAttribute( LOCAL_PATH );
IPath local = new Path( path );
if ( !local.isValidPath( path ) ) {
abort( "Source lookup: unable to restore map entry - missing local path attribute.", null );
}
return new MapEntrySourceContainer( backend, local );
}
abort( "Source lookup: unable to restore map entry - expecting map entry element.", null );
}
abort( "Source lookup: unable to restore map entry - invalid memento.", null );
return null;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.ISourceContainerTypeDelegate#getMemento(org.eclipse.debug.core.sourcelookup.ISourceContainer)
*/
public String getMemento( ISourceContainer container ) throws CoreException {
MapEntrySourceContainer entry = (MapEntrySourceContainer)container;
Document document = newDocument();
Element element = document.createElement( ELEMENT_NAME );
element.setAttribute( BACKEND_PATH, entry.getBackendPath().toOSString() );
element.setAttribute( LOCAL_PATH, entry.getLocalPath().toOSString() );
document.appendChild( element );
return serializeDocument( document );
}
}

View file

@ -0,0 +1,88 @@
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.internal.core.sourcelookup;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainerTypeDelegate;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
* The mapping container type.
*/
public class MappingSourceContainerType extends AbstractSourceContainerTypeDelegate {
private final static String ELEMENT_MAPPING = "mapping"; //$NON-NLS-1$
private final static String ELEMENT_MAP_ENTRY = "mapEntry"; //$NON-NLS-1$
private final static String ATTR_MEMENTO = "memento"; //$NON-NLS-1$
/* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.ISourceContainerTypeDelegate#createSourceContainer(java.lang.String)
*/
public ISourceContainer createSourceContainer( String memento ) throws CoreException {
Node node = parseDocument( memento );
if ( node.getNodeType() == Node.ELEMENT_NODE ) {
Element element = (Element)node;
if ( ELEMENT_MAPPING.equals( element.getNodeName() ) ) {
List entries = new ArrayList();
Node childNode = element.getFirstChild();
while( childNode != null ) {
if ( childNode.getNodeType() == Node.ELEMENT_NODE ) {
Element child = (Element)childNode;
if ( ELEMENT_MAP_ENTRY.equals( child.getNodeName() ) ) {
String childMemento = child.getAttribute( ATTR_MEMENTO );
if ( childMemento == null || childMemento.length() == 0 ) {
abort( "Source lookup: unable to restore map entry - expecting memnto attribute.", null );
}
ISourceContainerType type = DebugPlugin.getDefault().getLaunchManager().getSourceContainerType( MapEntrySourceContainer.TYPE_ID );
MapEntrySourceContainer entry = (MapEntrySourceContainer)type.createSourceContainer( childMemento );
entries.add( entry );
}
}
childNode = childNode.getNextSibling();
}
MappingSourceContainer container = new MappingSourceContainer();
Iterator it = entries.iterator();
while( it.hasNext() ) {
container.addMapEntry( (MapEntrySourceContainer)it.next() );
}
return container;
}
abort( "Source lookup: unable to restore mapping - expecting mapping element.", null );
}
abort( "Source lookup: unable to restore mapping - invalid memento.", null );
return null;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.ISourceContainerTypeDelegate#getMemento(org.eclipse.debug.core.sourcelookup.ISourceContainer)
*/
public String getMemento( ISourceContainer container ) throws CoreException {
Document document = newDocument();
Element element = document.createElement( ELEMENT_MAPPING );
ISourceContainer[] entries = ((MappingSourceContainer)container).getSourceContainers();
for ( int i = 0; i < entries.length; ++i ) {
Element child = document.createElement( ELEMENT_MAP_ENTRY );
child.setAttribute( ATTR_MEMENTO, entries[i].getType().getMemento( entries[i] ) );
element.appendChild( child );
}
document.appendChild( element );
return serializeDocument( document );
}
}

View file

@ -1,3 +1,18 @@
2005-03-21 Mikhail Khodjaiants
Bug 80175: Replace the CDT source lookup by the source lookup provided by Eclipse platform.
* icons/full/obj16/mapentry_obj.gif: new
* icons/full/obj16/mapping_obj.gif: new
* CDebugImages.java
* CDebugModelPresentation.java
* ICDebugHelpContextIds.java
* src/org/eclipse/cdt/debug/internal/ui/sourcelookup: new package
* MappingSourceContainerBrowser.java: new
* PathMappingDialog.java: new
* SourceContainerAdapterFactory.java: new
* SourceContainerWorkbenchAdapter.java: new
* plugin.properties
* plugin.xml
2005-03-08 Mikhail Khodjaiants
Removed deprecated "WorkbenchHelp" references.
* CBreakpointPropertiesRulerAction.java

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

View file

@ -1140,6 +1140,21 @@
class="org.eclipse.cdt.debug.internal.ui.CBreakpointWorkbenchAdapterFactory"
adaptableType="org.eclipse.cdt.debug.core.model.ICBreakpoint">
<adapter type="org.eclipse.ui.model.IWorkbenchAdapter"/>
</factory>
<factory
adaptableType="org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer"
class="org.eclipse.cdt.debug.internal.ui.sourcelookup.SourceContainerAdapterFactory">
<adapter type="org.eclipse.ui.model.IWorkbenchAdapter"/>
</factory>
<factory
adaptableType="org.eclipse.cdt.debug.internal.core.sourcelookup.MapEntrySourceContainer"
class="org.eclipse.cdt.debug.internal.ui.sourcelookup.SourceContainerAdapterFactory">
<adapter type="org.eclipse.ui.model.IWorkbenchAdapter"/>
</factory>
<factory
adaptableType="org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer"
class="org.eclipse.cdt.debug.internal.ui.sourcelookup.SourceContainerAdapterFactory">
<adapter type="org.eclipse.ui.model.IWorkbenchAdapter"/>
</factory> </extension>
<extension
point="org.eclipse.ui.themes">
@ -1183,5 +1198,17 @@
</enablement>
</renderingBindings>
</extension>
<extension
point="org.eclipse.debug.ui.sourceContainerPresentations">
<sourceContainerPresentation
browserClass="org.eclipse.cdt.debug.internal.ui.sourcelookup.MappingSourceContainerBrowser"
containerTypeID="org.eclipse.cdt.debug.core.containerType.mapping"
icon="icons/full/obj16/mapping_obj.gif"
id="org.eclipse.cdt.debug.ui.sourceContainerPresentation.mapping"/>
<sourceContainerPresentation
containerTypeID="org.eclipse.cdt.debug.core.containerType.mapEntry"
icon="icons/full/obj16/mapentry_obj.gif"
id="org.eclipse.cdt.debug.ui.sourceContainerPresentation.mapEntry"/>
</extension>
</plugin>

View file

@ -102,6 +102,8 @@ public class CDebugImages
public static final String IMG_OBJS_SIGNAL = NAME_PREFIX + "signal_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_WORKSPACE_SOURCE_FILE = NAME_PREFIX + "prj_file_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_EXTERNAL_SOURCE_FILE = NAME_PREFIX + "ext_file_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_PATH_MAPPING = NAME_PREFIX + "mapping_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_PATH_MAP_ENTRY = NAME_PREFIX + "mapentry_obj.gif"; //$NON-NLS-1$
public static final String IMG_LCL_TYPE_NAMES = NAME_PREFIX + "tnames_co.gif"; //$NON-NLS-1$
public static final String IMG_LCL_CHANGE_REGISTER_VALUE = NAME_PREFIX + "change_reg_value_co.gif"; //$NON-NLS-1$
@ -185,6 +187,8 @@ public class CDebugImages
public static final ImageDescriptor DESC_OBJS_SIGNAL = createManaged( T_OBJ, IMG_OBJS_SIGNAL );
public static final ImageDescriptor DESC_OBJS_WORKSPACE_SOURCE_FILE = createManaged( T_OBJ, IMG_OBJS_WORKSPACE_SOURCE_FILE );
public static final ImageDescriptor DESC_OBJS_EXTERNAL_SOURCE_FILE = createManaged( T_OBJ, IMG_OBJS_EXTERNAL_SOURCE_FILE );
public static final ImageDescriptor DESC_OBJS_PATH_MAPPING = createManaged( T_OBJ, IMG_OBJS_PATH_MAPPING );
public static final ImageDescriptor DESC_OBJS_PATH_MAP_ENTRY = createManaged( T_OBJ, IMG_OBJS_PATH_MAP_ENTRY );
public static final ImageDescriptor DESC_WIZBAN_ADD_SOURCE_LOCATION = createManaged( T_WIZBAN, IMG_WIZBAN_ADD_SOURCE_LOCATION );
public static final ImageDescriptor DESC_WIZBAN_ADD_PRJ_SOURCE_LOCATION = createManaged( T_WIZBAN, IMG_WIZBAN_ADD_PRJ_SOURCE_LOCATION );
public static final ImageDescriptor DESC_WIZBAN_ADD_DIR_SOURCE_LOCATION = createManaged( T_WIZBAN, IMG_WIZBAN_ADD_DIR_SOURCE_LOCATION );

View file

@ -69,6 +69,7 @@ import org.eclipse.debug.core.model.IThread;
import org.eclipse.debug.core.model.IValue;
import org.eclipse.debug.core.model.IVariable;
import org.eclipse.debug.core.model.IWatchExpression;
import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.IDebugModelPresentation;
@ -139,7 +140,7 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode
if ( file != null )
return new FileEditorInput( file );
}
if ( element instanceof FileStorage ) {
if ( element instanceof FileStorage || element instanceof LocalFileStorage ) {
return new ExternalEditorInput( (IStorage)element );
}
if ( element instanceof FileNotFoundElement ) {

View file

@ -62,4 +62,8 @@ public interface ICDebugHelpContextIds
public static final String SHARED_LIBRARIES_PREFERENCE_PAGE = PREFIX + "shared_libraries_preference_page_context"; //$NON-NLS-1$
public static final String MEMORY_PREFERENCE_PAGE = PREFIX + "memory_preference_page_context"; //$NON-NLS-1$
public static final String C_DEBUG_PREFERENCE_PAGE = PREFIX + "c_debug_preference_page_context"; //$NON-NLS-1$
// dialogs
public static final String SOURCE_PATH_MAPPING_DIALOG = PREFIX + "source_path_mapping_dialog_context"; //$NON-NLS-1$
public static final String SOURCE_PATH_MAP_ENTRY_DIALOG = PREFIX + "source_path_map_entry_dialog_context"; //$NON-NLS-1$
}

View file

@ -0,0 +1,58 @@
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.internal.ui.sourcelookup;
import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
import org.eclipse.debug.ui.sourcelookup.AbstractSourceContainerBrowser;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
/**
* Adds a path mapping to the source lookup path.
*/
public class MappingSourceContainerBrowser extends AbstractSourceContainerBrowser {
/* (non-Javadoc)
* @see org.eclipse.debug.ui.sourcelookup.AbstractSourceContainerBrowser#addSourceContainers(org.eclipse.swt.widgets.Shell, org.eclipse.debug.core.sourcelookup.ISourceLookupDirector)
*/
public ISourceContainer[] addSourceContainers( Shell shell, ISourceLookupDirector director ) {
return new ISourceContainer[] { new MappingSourceContainer() };
}
/* (non-Javadoc)
* @see org.eclipse.debug.ui.sourcelookup.AbstractSourceContainerBrowser#canAddSourceContainers(org.eclipse.debug.core.sourcelookup.ISourceLookupDirector)
*/
public boolean canAddSourceContainers( ISourceLookupDirector director ) {
return true;
}
/* (non-Javadoc)
* @see org.eclipse.debug.ui.sourcelookup.AbstractSourceContainerBrowser#canEditSourceContainers(org.eclipse.debug.core.sourcelookup.ISourceLookupDirector, org.eclipse.debug.core.sourcelookup.ISourceContainer[])
*/
public boolean canEditSourceContainers( ISourceLookupDirector director, ISourceContainer[] containers ) {
return ( containers.length == 1 && containers[0] instanceof MappingSourceContainer );
}
/* (non-Javadoc)
* @see org.eclipse.debug.ui.sourcelookup.AbstractSourceContainerBrowser#editSourceContainers(org.eclipse.swt.widgets.Shell, org.eclipse.debug.core.sourcelookup.ISourceLookupDirector, org.eclipse.debug.core.sourcelookup.ISourceContainer[])
*/
public ISourceContainer[] editSourceContainers( Shell shell, ISourceLookupDirector director, ISourceContainer[] containers ) {
if ( containers.length == 1 && containers[0] instanceof MappingSourceContainer ) {
PathMappingDialog dialog = new PathMappingDialog( shell, (MappingSourceContainer)containers[0] );
if ( dialog.open() == Window.OK ) {
return new ISourceContainer[] { dialog.getMapping() };
}
}
return new ISourceContainer[0];
}
}

View file

@ -0,0 +1,430 @@
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.internal.ui.sourcelookup;
import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer;
import org.eclipse.cdt.debug.internal.core.sourcelookup.MapEntrySourceContainer;
import org.eclipse.cdt.debug.internal.ui.ICDebugHelpContextIds;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.model.WorkbenchLabelProvider;
/**
* A dialog for editing a path mapping source container.
*/
public class PathMappingDialog extends TitleAreaDialog {
class MapEntryDialog extends TitleAreaDialog {
protected Text fBackendPathText;
protected Text fLocalPathText;
/**
* Constructor for MapEntryDialog.
*/
public MapEntryDialog( Shell parentShell ) {
super( parentShell );
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
*/
protected Control createDialogArea( Composite parent ) {
setTitle( "Specify the mapping paths" );
Font font = parent.getFont();
Composite composite = new Composite( parent, SWT.NONE );
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginHeight = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_MARGIN );
layout.marginWidth = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_MARGIN );
layout.verticalSpacing = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_SPACING );
layout.horizontalSpacing = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_SPACING );
composite.setLayout( layout );
GridData data = new GridData( GridData.FILL_BOTH );
composite.setLayoutData( data );
composite.setFont( font );
Dialog.applyDialogFont( composite );
PlatformUI.getWorkbench().getHelpSystem().setHelp( getShell(), ICDebugHelpContextIds.SOURCE_PATH_MAP_ENTRY_DIALOG );
setMessage( null );
Label label = new Label( composite, SWT.LEFT );
label.setText( "Compilation path:" );
data = new GridData( GridData.FILL_HORIZONTAL );
data.horizontalSpan = 2;
label.setLayoutData( data );
label.setFont( font );
fBackendPathText = new Text( composite, SWT.SINGLE | SWT.BORDER );
data = new GridData( GridData.FILL_HORIZONTAL );
data.horizontalSpan = 2;
fBackendPathText.setLayoutData( data );
fBackendPathText.setFont( font );
fBackendPathText.addModifyListener( new ModifyListener() {
public void modifyText( ModifyEvent e ) {
update();
}
} );
label = new Label( composite, SWT.LEFT );
label.setText( "Local file system path:" );
data = new GridData( GridData.FILL_HORIZONTAL );
data.horizontalSpan = 2;
label.setLayoutData( data );
label.setFont( font );
fLocalPathText = new Text( composite, SWT.SINGLE | SWT.BORDER );
data = new GridData( GridData.FILL_HORIZONTAL );
fLocalPathText.setLayoutData( data );
fLocalPathText.setFont( font );
fLocalPathText.addModifyListener( new ModifyListener() {
public void modifyText( ModifyEvent e ) {
update();
}
} );
Button button = new Button( composite, SWT.PUSH );
button.setFont( font );
button.setText( "&Browse..." );
button.addSelectionListener( new SelectionListener() {
public void widgetSelected( SelectionEvent e ) {
DirectoryDialog dialog = new DirectoryDialog( MapEntryDialog.this.getShell() );
String path = dialog.open();
if ( path != null ) {
fLocalPathText.setText( path );
}
}
public void widgetDefaultSelected( SelectionEvent e ) {
}
} );
return composite;
}
protected Control createContents( Composite parent ) {
Control control = super.createContents( parent );
update();
return control;
}
protected void configureShell( Shell newShell ) {
newShell.setText( "Path Mapping" );
super.configureShell( newShell );
}
protected void update() {
boolean isOk = updateErrorMessage();
Button ok = getButton( IDialogConstants.OK_ID );
if ( ok != null )
ok.setEnabled( isOk );
}
protected boolean updateErrorMessage() {
setErrorMessage( null );
String backendText = fBackendPathText.getText().trim();
if ( backendText.length() == 0 ) {
setErrorMessage( "The compilation path must not be empty" );
return false;
}
if ( !new Path( backendText ).isValidPath( backendText ) ) {
setErrorMessage( "Invalid compilation path." );
return false;
}
String localText = fLocalPathText.getText().trim();
if ( localText.length() == 0 ) {
setErrorMessage( "The local file systems path must not be empty" );
return false;
}
if ( !new Path( localText ).isValidPath( localText ) ) {
setErrorMessage( "Invalid local file system path." );
return false;
}
return true;
}
protected IPath getBackendPath() {
return new Path( fBackendPathText.getText().trim() );
}
protected IPath getLocalPath() {
return new Path( fLocalPathText.getText().trim() );
}
protected void okPressed() {
fMapping.addMapEntry( new MapEntrySourceContainer( getBackendPath(), getLocalPath() ) );
super.okPressed();
}
}
class PathMappingLabelProvider extends LabelProvider {
private ILabelProvider fLabelProvider = null;
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
*/
public Image getImage( Object element ) {
Image image = getWorkbenchLabelProvider().getImage( element );
if ( image != null ) {
return image;
}
return super.getImage( element );
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
*/
public String getText( Object element ) {
String label = getWorkbenchLabelProvider().getText( element );
if ( label == null || label.length() == 0 ) {
if ( element instanceof ISourceContainer ) {
return ((ISourceContainer)element).getName();
}
}
else {
return label;
}
return super.getText( element );
}
private ILabelProvider getWorkbenchLabelProvider() {
if ( fLabelProvider == null ) {
fLabelProvider = new WorkbenchLabelProvider();
}
return fLabelProvider;
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
*/
public void dispose() {
super.dispose();
if ( fLabelProvider != null ) {
fLabelProvider.dispose();
}
}
}
class ContentProvider implements IStructuredContentProvider {
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
public Object[] getElements( Object input ) {
if ( input instanceof MappingSourceContainer ) {
try {
return ((MappingSourceContainer)input).getSourceContainers();
}
catch( CoreException e ) {
setErrorMessage( e.getMessage() );
}
}
return null;
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose() {
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) {
}
}
private MappingSourceContainer fOriginalMapping;
protected MappingSourceContainer fMapping;
private TableViewer fViewer;
private Button fAddButton;
private Button fRemoveButton;
public PathMappingDialog( Shell parentShell, MappingSourceContainer mapping ) {
super( parentShell );
fOriginalMapping = mapping;
fMapping = new MappingSourceContainer();
try {
fMapping.addMapEntries( (MapEntrySourceContainer[])mapping.getSourceContainers() );
}
catch( CoreException e ) {
setErrorMessage( e.getMessage() );
}
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
*/
protected Control createDialogArea( Composite parent ) {
setTitle( "Modify the list of path mappings" );
//TODO Add image
Font font = parent.getFont();
Composite composite = new Composite( parent, SWT.NONE );
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginHeight = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_MARGIN );
layout.marginWidth = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_MARGIN );
layout.verticalSpacing = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_SPACING );
layout.horizontalSpacing = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_SPACING );
composite.setLayout( layout );
GridData data = new GridData( GridData.FILL_BOTH );
composite.setLayoutData( data );
composite.setFont( font );
Dialog.applyDialogFont( composite );
PlatformUI.getWorkbench().getHelpSystem().setHelp( getShell(), ICDebugHelpContextIds.SOURCE_PATH_MAPPING_DIALOG );
fViewer = createViewer( composite );
data = new GridData( GridData.FILL_BOTH );
fViewer.getControl().setLayoutData( data );
fViewer.getControl().setFont( font );
Composite buttonComp = new Composite( composite, SWT.NONE );
GridLayout buttonLayout = new GridLayout();
buttonLayout.marginHeight = 0;
buttonLayout.marginWidth = 0;
buttonComp.setLayout( buttonLayout );
data = new GridData( GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL );
buttonComp.setLayoutData( data );
buttonComp.setFont( font );
GC gc = new GC( parent );
gc.setFont( parent.getFont() );
FontMetrics fontMetrics = gc.getFontMetrics();
gc.dispose();
fAddButton = createPushButton( buttonComp, "&Add...", fontMetrics );
fAddButton.addSelectionListener( new SelectionAdapter() {
public void widgetSelected( SelectionEvent evt ) {
MapEntryDialog dialog = new MapEntryDialog( getShell() );
if ( dialog.open() == Window.OK ) {
getViewer().refresh();
}
}
} );
fRemoveButton = createPushButton( buttonComp, "Re&move", fontMetrics );
fRemoveButton.addSelectionListener( new SelectionAdapter() {
public void widgetSelected( SelectionEvent evt ) {
ISelection s = getViewer().getSelection();
if ( s instanceof IStructuredSelection ) {
Object[] ss = ((IStructuredSelection)s).toArray();
for ( int i = 0; i < ss.length; ++i ) {
fMapping.removeMapEntry( (MapEntrySourceContainer)ss[i] );
}
getViewer().refresh();
}
}
} );
setMessage( null );
fViewer.setInput( fMapping );
return composite;
}
private TableViewer createViewer( Composite parent ) {
TableViewer viewer = new TableViewer( parent );
viewer.setContentProvider( new ContentProvider() );
viewer.setLabelProvider( new PathMappingLabelProvider() );
return viewer;
}
protected MappingSourceContainer getMapping() {
return fOriginalMapping;
}
protected Button createPushButton( Composite parent, String label, FontMetrics fontMetrics ) {
Button button = new Button( parent, SWT.PUSH );
button.setFont( parent.getFont() );
button.setText( label );
GridData gd = getButtonGridData( button, fontMetrics );
button.setLayoutData( gd );
return button;
}
private GridData getButtonGridData( Button button, FontMetrics fontMetrics ) {
GridData gd = new GridData( GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING );
int widthHint = Dialog.convertHorizontalDLUsToPixels( fontMetrics, IDialogConstants.BUTTON_WIDTH );
gd.widthHint = Math.max( widthHint, button.computeSize( SWT.DEFAULT, SWT.DEFAULT, true ).x );
return gd;
}
/* (non-Javadoc)
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
*/
protected void configureShell( Shell newShell ) {
newShell.setText( "Path Mappings" );
super.configureShell( newShell );
}
protected Viewer getViewer() {
return fViewer;
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#okPressed()
*/
protected void okPressed() {
fOriginalMapping.clear();
try {
fOriginalMapping.addMapEntries( (MapEntrySourceContainer[])fMapping.getSourceContainers() );
}
catch( CoreException e ) {
}
fMapping.dispose();
super.okPressed();
}
}

View file

@ -0,0 +1,37 @@
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.internal.ui.sourcelookup;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.ui.model.IWorkbenchAdapter;
/**
* Adapter factory for CDT source containers.
*/
public class SourceContainerAdapterFactory implements IAdapterFactory {
/* (non-Javadoc)
* @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
*/
public Object getAdapter( Object adaptableObject, Class adapterType ) {
if ( adapterType.equals( IWorkbenchAdapter.class ) ) {
return new SourceContainerWorkbenchAdapter();
}
return null;
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
*/
public Class[] getAdapterList() {
return new Class[]{ IWorkbenchAdapter.class };
}
}

View file

@ -0,0 +1,79 @@
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.internal.ui.sourcelookup;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer;
import org.eclipse.cdt.debug.internal.core.sourcelookup.MapEntrySourceContainer;
import org.eclipse.cdt.debug.internal.ui.CDebugImages;
import org.eclipse.core.resources.IProject;
import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.model.IWorkbenchAdapter;
/**
* Workbench adapter for CDT source containers.
*/
public class SourceContainerWorkbenchAdapter implements IWorkbenchAdapter {
/* (non-Javadoc)
* @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object)
*/
public Object[] getChildren( Object o ) {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.ui.model.IWorkbenchAdapter#getImageDescriptor(java.lang.Object)
*/
public ImageDescriptor getImageDescriptor( Object o ) {
if ( o instanceof MappingSourceContainer ) {
return CDebugImages.DESC_OBJS_PATH_MAPPING;
}
if ( o instanceof MapEntrySourceContainer ) {
return CDebugImages.DESC_OBJS_PATH_MAP_ENTRY;
}
if ( o instanceof ProjectSourceContainer ) {
IProject project = ((ProjectSourceContainer)o).getProject();
return getImageDescriptor( CCorePlugin.getDefault().getCoreModel().create( project ) );
}
return null;
}
protected ImageDescriptor getImageDescriptor( ICElement element ) {
IWorkbenchAdapter adapter = (IWorkbenchAdapter)element.getAdapter( IWorkbenchAdapter.class );
if ( adapter != null ) {
return adapter.getImageDescriptor( element );
}
return null;
}
/* (non-Javadoc)
* @see org.eclipse.ui.model.IWorkbenchAdapter#getLabel(java.lang.Object)
*/
public String getLabel( Object o ) {
if ( o instanceof MappingSourceContainer ) {
return ((MappingSourceContainer)o).getName();
}
if ( o instanceof MapEntrySourceContainer ) {
return ((MapEntrySourceContainer)o).getName();
}
return null;
}
/* (non-Javadoc)
* @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object)
*/
public Object getParent( Object o ) {
return null;
}
}