1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 06:32:10 +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-04-21 19:41:01 +00:00
parent f9c9df1db7
commit af37524c7a
45 changed files with 2235 additions and 733 deletions

View file

@ -1,3 +1,21 @@
2005-04-21 Mikhail Khodjaiants
Bug 80175: Replace the CDT source lookup by the source lookup provided by Eclipse platform.
* CDebugCorePlugin.java
* MappingSourceContainer.java
* SourceLookupMessages.java: new
* SourceLookupMessages.properties: new
* CBreakpointManager.java
* ICDebugInternalConstants.java
* CommonSourceLookupDirector.java: new
* CSourceLookupDirector.java
* CSourceLookupParticipant.java
* CSourcePathComputerDelegate.java
* InternalSourceLookupMessages.properties
* MapEntrySourceContainer.java
* MapEntrySourceContainerType.java
* MappingSourceContainerType.java
* SourceUtils.java
2005-04-15 Alain Magloire
Fix Pr 91581
* src/org/eclipse/cdt/debug/internal/core/breakpoint/CAddressBreakpoint.java

View file

@ -13,9 +13,12 @@ package org.eclipse.cdt.debug.core;
import java.util.HashMap;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
import org.eclipse.cdt.debug.internal.core.DebugConfiguration;
import org.eclipse.cdt.debug.internal.core.ICDebugInternalConstants;
import org.eclipse.cdt.debug.internal.core.ListenerList;
import org.eclipse.cdt.debug.internal.core.SessionManager;
import org.eclipse.cdt.debug.internal.core.breakpoints.CBreakpoint;
import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLookupDirector;
import org.eclipse.cdt.debug.internal.core.sourcelookup.CommonSourceLookupDirector;
import org.eclipse.cdt.debug.internal.core.sourcelookup.SourceUtils;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
@ -59,6 +62,11 @@ public class CDebugCorePlugin extends Plugin {
*/
private ListenerList fBreakpointListeners;
/**
* Dummy source lookup director needed to manage common source containers.
*/
private CommonSourceLookupDirector fCommonSourceLookupDirector;
private SessionManager fSessionManager = null;
/**
@ -243,6 +251,7 @@ public class CDebugCorePlugin extends Plugin {
*/
public void start( BundleContext context ) throws Exception {
super.start( context );
initializeCommonSourceLookupDirector();
createBreakpointListenersList();
resetBreakpointsInstallCount();
setSessionManager( new SessionManager() );
@ -255,6 +264,39 @@ public class CDebugCorePlugin extends Plugin {
setSessionManager( null );
disposeBreakpointListenersList();
resetBreakpointsInstallCount();
disposeCommonSourceLookupDirector();
super.stop( context );
}
private void initializeCommonSourceLookupDirector() {
if ( fCommonSourceLookupDirector == null ) {
fCommonSourceLookupDirector = new CommonSourceLookupDirector();
String newMemento = CDebugCorePlugin.getDefault().getPluginPreferences().getString( ICDebugInternalConstants.PREF_COMMON_SOURCE_CONTAINERS );
if ( newMemento.length() == 0 ) {
// Convert source locations to source containers
convertSourceLocations( fCommonSourceLookupDirector );
}
else {
try {
fCommonSourceLookupDirector.initializeFromMemento( newMemento );
}
catch( CoreException e ) {
log( e.getStatus() );
}
}
}
}
private void disposeCommonSourceLookupDirector() {
if ( fCommonSourceLookupDirector != null )
fCommonSourceLookupDirector.dispose();
}
public CSourceLookupDirector getCommonSourceLookupDirector() {
return fCommonSourceLookupDirector;
}
private void convertSourceLocations( CommonSourceLookupDirector director ) {
director.setSourceContainers( SourceUtils.convertSourceLocations( getCommonSourceLocations() ) );
}
}

View file

@ -17,13 +17,14 @@ 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.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Path;
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.
@ -36,27 +37,22 @@ public class MappingSourceContainer extends AbstractSourceContainer {
*/
public static final String TYPE_ID = CDebugCorePlugin.getUniqueIdentifier() + ".containerType.mapping"; //$NON-NLS-1$
private String fName;
private ArrayList fContainers;
/**
* Constructor for MappingSourceContainer.
*/
public MappingSourceContainer() {
public MappingSourceContainer( String name ) {
fName = name;
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";
return fName;
}
/* (non-Javadoc)
@ -110,7 +106,7 @@ public class MappingSourceContainer extends AbstractSourceContainer {
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 = new MultiStatus( DebugPlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, new IStatus[]{ single.getStatus() }, SourceLookupMessages.getString( "MappingSourceContainer.0" ), null ); //$NON-NLS-1$
multiStatus.add( e.getStatus() );
}
else {
@ -172,4 +168,36 @@ public class MappingSourceContainer extends AbstractSourceContainer {
}
fContainers.clear();
}
public MappingSourceContainer copy() {
MappingSourceContainer copy = new MappingSourceContainer( fName );
MapEntrySourceContainer[] entries = new MapEntrySourceContainer[fContainers.size()];
for ( int i = 0; i < entries.length; ++i ) {
copy.addMapEntry( ((MapEntrySourceContainer)fContainers.get( i )).copy() );
}
return copy;
}
public void setName( String name ) {
fName = name;
}
public IPath getCompilationPath( String sourceName ) {
IPath path = new Path( sourceName );
IPath result = null;
try {
ISourceContainer[] containers = getSourceContainers();
for ( int i = 0; i < containers.length; ++i ) {
MapEntrySourceContainer entry = (MapEntrySourceContainer)containers[i];
IPath local = entry.getLocalPath();
if ( local.isPrefixOf( path ) ) {
result = entry.getBackendPath().append( path.removeFirstSegments( local.segmentCount() ) );
break;
}
}
}
catch( CoreException e ) {
}
return result;
}
}

View file

@ -0,0 +1,34 @@
/**********************************************************************
* 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.MissingResourceException;
import java.util.ResourceBundle;
public class SourceLookupMessages {
private static final String BUNDLE_NAME = "org.eclipse.cdt.debug.core.sourcelookup.SourceLookupMessages"; //$NON-NLS-1$
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( BUNDLE_NAME );
private SourceLookupMessages() {
}
public static String getString( String key ) {
// TODO Auto-generated method stub
try {
return RESOURCE_BUNDLE.getString( key );
}
catch( MissingResourceException e ) {
return '!' + key + '!';
}
}
}

View file

@ -0,0 +1 @@
MappingSourceContainer.0=Source lookup error

View file

@ -44,6 +44,7 @@ import org.eclipse.cdt.debug.core.model.ICWatchpoint;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
import org.eclipse.cdt.debug.internal.core.breakpoints.CBreakpoint;
import org.eclipse.cdt.debug.internal.core.model.CDebugTarget;
import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLookupDirector;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarkerDelta;
import org.eclipse.core.resources.IProject;
@ -211,19 +212,18 @@ public class CBreakpointManager implements IBreakpointManagerListener, ICDIEvent
}
public boolean isTargetBreakpoint( ICBreakpoint breakpoint ) {
// Problem: gdb doesn't accept breakpoint if the file is specified by full path (depends on the current directory).
// This prevents us from using gdb as a breakpoint filter. The case when two unrelated projects contain files
// with the same name will cause problems.
// Current solution: the source locator is used as a breakpoint filter.
IResource resource = breakpoint.getMarker().getResource();
if ( breakpoint instanceof ICAddressBreakpoint )
return supportsAddressBreakpoint( (ICAddressBreakpoint)breakpoint );
if ( breakpoint instanceof ICLineBreakpoint ) {
try {
String handle = breakpoint.getSourceHandle();
ICSourceLocator sl = getSourceLocator();
if ( sl != null )
return ( sl.findSourceElement( handle ) != null );
ISourceLocator sl = getSourceLocator();
if ( sl instanceof ICSourceLocator )
return ( ((ICSourceLocator)sl).findSourceElement( handle ) != null );
else if ( sl instanceof CSourceLookupDirector ) {
return true;//( ((CSourceLookupDirector)sl).getCompilationPath( handle ) != null || ((CSourceLookupDirector)sl).findSourceElements( handle ).length > 0 );
}
}
catch( CoreException e ) {
return false;
@ -232,9 +232,11 @@ public class CBreakpointManager implements IBreakpointManagerListener, ICDIEvent
else {
IProject project = resource.getProject();
if ( project != null && project.exists() ) {
ICSourceLocator sl = getSourceLocator();
if ( sl != null )
return sl.contains( project );
ISourceLocator sl = getSourceLocator();
if ( sl instanceof ICSourceLocator )
return ((ICSourceLocator)sl).contains( project );
else if ( sl instanceof CSourceLookupDirector )
return ((CSourceLookupDirector)sl).contains( project );
if ( project.equals( getProject() ) )
return true;
return CDebugUtils.isReferencedProject( getProject(), project );
@ -554,16 +556,14 @@ public class CBreakpointManager implements IBreakpointManagerListener, ICDIEvent
}
private void setLineBreakpoint( ICLineBreakpoint breakpoint ) throws CDIException, CoreException {
final boolean enabled = breakpoint.isEnabled();
final ICDITarget cdiTarget = getCDITarget();
boolean enabled = breakpoint.isEnabled();
ICDITarget cdiTarget = getCDITarget();
String handle = breakpoint.getSourceHandle();
IPath path = new Path( handle );
if ( path.isValidPath( handle ) ) {
final ICDILocation location = cdiTarget.createLocation( path.lastSegment(), null, breakpoint.getLineNumber() );
final ICDICondition condition = createCondition( breakpoint );
IPath path = convertPath( handle );
ICDILocation location = cdiTarget.createLocation( path.toPortableString(), null, breakpoint.getLineNumber() );
ICDICondition condition = createCondition( breakpoint );
setLocationBreakpointOnTarget( breakpoint, cdiTarget, location, condition, enabled );
}
}
private void setWatchpointOnTarget( final ICWatchpoint watchpoint, final ICDITarget target, final int accessType, final String expression, final ICDICondition condition, final boolean enabled ) {
DebugPlugin.getDefault().asyncExec( new Runnable() {
@ -617,20 +617,26 @@ public class CBreakpointManager implements IBreakpointManagerListener, ICDIEvent
ICLineBreakpoint breakpoint = null;
try {
if ( !isEmpty( cdiBreakpoint.getLocation().getFile() ) ) {
ICSourceLocator locator = getSourceLocator();
if ( locator != null ) {
Object sourceElement = locator.findSourceElement( cdiBreakpoint.getLocation().getFile() );
ISourceLocator locator = getSourceLocator();
if ( locator instanceof ICSourceLocator || locator instanceof CSourceLookupDirector ) {
String sourceHandle = cdiBreakpoint.getLocation().getFile();
IResource resource = getProject();
Object sourceElement = null;
if ( locator instanceof ICSourceLocator )
sourceElement = ((ICSourceLocator)locator).findSourceElement( cdiBreakpoint.getLocation().getFile() );
else
sourceElement = ((CSourceLookupDirector)locator).getSourceElement( cdiBreakpoint.getLocation().getFile() );
if ( sourceElement instanceof IFile || sourceElement instanceof IStorage ) {
String sourceHandle = ( sourceElement instanceof IFile ) ? ((IFile)sourceElement).getLocation().toOSString() : ((IStorage)sourceElement).getFullPath().toOSString();
IResource resource = ( sourceElement instanceof IFile ) ? (IResource)sourceElement : ResourcesPlugin.getWorkspace().getRoot();
sourceHandle = ( sourceElement instanceof IFile ) ? ((IFile)sourceElement).getLocation().toOSString() : ((IStorage)sourceElement).getFullPath().toOSString();
resource = ( sourceElement instanceof IFile ) ? (IResource)sourceElement : ResourcesPlugin.getWorkspace().getRoot();
}
breakpoint = createLineBreakpoint( sourceHandle, resource, cdiBreakpoint );
}
else if ( !isEmpty( cdiBreakpoint.getLocation().getFunction() ) ) {
breakpoint = createFunctionBreakpoint( cdiBreakpoint );
}
else if ( ! cdiBreakpoint.getLocation().getAddress().equals( BigInteger.ZERO ) ) {
breakpoint = createAddressBreakpoint( cdiBreakpoint );
}
// else if ( !isEmpty( cdiBreakpoint.getLocation().getFunction() ) ) {
// breakpoint = createFunctionBreakpoint( cdiBreakpoint );
// }
// else if ( ! cdiBreakpoint.getLocation().getAddress().equals( BigInteger.ZERO ) ) {
// breakpoint = createAddressBreakpoint( cdiBreakpoint );
// }
}
}
else if ( !isEmpty( cdiBreakpoint.getLocation().getFunction() ) ) {
@ -711,9 +717,8 @@ public class CBreakpointManager implements IBreakpointManagerListener, ICDIEvent
return watchpoint;
}
private ICSourceLocator getSourceLocator() {
ISourceLocator locator = getDebugTarget().getLaunch().getSourceLocator();
return (locator instanceof IAdaptable) ? (ICSourceLocator)((IAdaptable)locator).getAdapter( ICSourceLocator.class ) : null;
private ISourceLocator getSourceLocator() {
return getDebugTarget().getLaunch().getSourceLocator();
}
private IProject getProject() {
@ -816,4 +821,18 @@ public class CBreakpointManager implements IBreakpointManagerListener, ICDIEvent
private ICDICondition createCondition( ICBreakpoint breakpoint ) throws CoreException, CDIException {
return getCDITarget().createCondition( breakpoint.getIgnoreCount(), breakpoint.getCondition(), getThreadNames( breakpoint ) );
}
private IPath convertPath( String sourceHandle ) {
IPath path = null;
if ( Path.EMPTY.isValidPath( sourceHandle ) ) {
ISourceLocator sl = getSourceLocator();
if ( sl instanceof CSourceLookupDirector ) {
path = ((CSourceLookupDirector)sl).getCompilationPath( sourceHandle );
}
if ( path == null ) {
path = new Path( sourceHandle );
}
}
return path;
}
}

View file

@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.cdt.debug.internal.core;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
/**
* Definitions of the internal constants for C/C++ Debug plug-in.
*/
@ -21,4 +23,9 @@ public class ICDebugInternalConstants {
public static final int STATUS_CODE_QUESTION = 10000;
public static final int STATUS_CODE_INFO = 10001;
public static final int STATUS_CODE_ERROR = 10002;
/**
* String preference for the common source containers.
*/
public static final String PREF_COMMON_SOURCE_CONTAINERS = CDebugCorePlugin.getUniqueIdentifier() + ".cDebug.common_source_containers"; //$NON-NLS-1$
}

View file

@ -13,7 +13,11 @@ 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.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
import org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant;
import org.eclipse.debug.core.sourcelookup.containers.DirectorySourceContainer;
@ -49,4 +53,64 @@ public class CSourceLookupDirector extends AbstractSourceLookupDirector {
public boolean supportsSourceContainerType( ISourceContainerType type ) {
return fFilteredTypes.contains( type.getId() );
}
public boolean contains( IProject project ) {
ISourceContainer[] containers = getSourceContainers();
for ( int i = 0; i < containers.length; ++i ) {
if ( contains( containers[i], project ) )
return true;
}
return false;
}
private boolean contains( ISourceContainer container, IProject project ) {
if ( container instanceof ProjectSourceContainer && ((ProjectSourceContainer)container).getProject().equals( project ) ) {
return true;
}
try {
ISourceContainer[] containers;
containers = container.getSourceContainers();
for ( int i = 0; i < containers.length; ++i ) {
if ( contains( containers[i], project ) )
return true;
}
}
catch( CoreException e ) {
}
return false;
}
public IPath getCompilationPath( String sourceName ) {
IPath path = null;
ISourceContainer[] containers = getSourceContainers();
for ( int i = 0; i < containers.length; ++i ) {
IPath cp = getCompilationPath( containers[i], sourceName );
if ( cp != null ) {
path = cp;
break;
}
}
return path;
}
private IPath getCompilationPath( ISourceContainer container, String sourceName ) {
IPath path = null;
if ( container instanceof MappingSourceContainer ) {
path = ((MappingSourceContainer)container).getCompilationPath( sourceName );
}
else {
try {
ISourceContainer[] containers;
containers = container.getSourceContainers();
for ( int i = 0; i < containers.length; ++i ) {
path = getCompilationPath( containers[i], sourceName );
if ( path != null )
break;
}
}
catch( CoreException e ) {
}
}
return path;
}
}

View file

@ -10,10 +10,15 @@
***********************************************************************/
package org.eclipse.cdt.debug.internal.core.sourcelookup;
import java.io.File;
import org.eclipse.cdt.debug.core.model.ICStackFrame;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant;
import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
/**
* A source lookup participant that searches for C/C++ source code.
@ -47,14 +52,32 @@ public class CSourceLookupParticipant extends AbstractSourceLookupParticipant {
*/
public Object[] findSourceElements( Object object ) throws CoreException {
// Workaround for cases when the stack frame doesn't contain the source file name
String name = null;
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 )
name = frame.getFile().trim();
if ( name == null || name.length() == 0 )
return new Object[] { gfNoSource };
}
}
else if ( object instanceof String ) {
name = (String)object;
}
// Workaround. See bug #91808.
if ( name != null ) {
File file = new File( name );
if ( file.isAbsolute() && file.exists() ) {
return findSourceElementByFile( file );
}
}
return super.findSourceElements( object );
}
private Object[] findSourceElementByFile( File file ) {
IFile[] wfiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation( new Path( file.getPath() ) );
if ( wfiles.length > 0 )
return wfiles;
return new LocalFileStorage[] { new LocalFileStorage( file ) };
}
}

View file

@ -10,6 +10,9 @@
***********************************************************************/
package org.eclipse.cdt.debug.internal.core.sourcelookup;
import java.util.ArrayList;
import java.util.Arrays;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
@ -36,13 +39,16 @@ public class CSourcePathComputerDelegate implements ISourcePathComputerDelegate
* @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 {
ISourceContainer[] common = CDebugCorePlugin.getDefault().getCommonSourceLookupDirector().getSourceContainers();
ArrayList containers = new ArrayList( common.length + 1 );
containers.addAll( Arrays.asList( common ) );
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 ) };
containers.add( 0, new ProjectSourceContainer( project, true ) );
}
}
return new ISourceContainer[0];
return (ISourceContainer[])containers.toArray( new ISourceContainer[containers.size()] );
}
}

View file

@ -0,0 +1,36 @@
/**********************************************************************
* 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.CDebugCorePlugin;
import org.eclipse.cdt.debug.internal.core.ICDebugInternalConstants;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
/**
* Director of the common source containers.
*/
public class CommonSourceLookupDirector extends CSourceLookupDirector {
/* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector#setSourceContainers(org.eclipse.debug.core.sourcelookup.ISourceContainer[])
*/
public void setSourceContainers( ISourceContainer[] containers ) {
try {
super.setSourceContainers( containers );
CDebugCorePlugin.getDefault().getPluginPreferences().setValue( ICDebugInternalConstants.PREF_COMMON_SOURCE_CONTAINERS, getMemento() );
CDebugCorePlugin.getDefault().savePluginPreferences();
}
catch( CoreException e ) {
CDebugCorePlugin.log( e.getStatus() );
}
}
}

View file

@ -20,3 +20,11 @@ CSourceLocator.0=Unable to create memento for C/C++ source locator.
CSourceLocator.1=Unable to restore C/C++ source locator - invalid format.
CSourceLocator.2=Exception occurred initializing source locator.
CSourceLocator.3=Error initializing directory source location.
MapEntrySourceContainerType.0=Source lookup: unable to restore map entry - missing backend path attribute.
MapEntrySourceContainerType.1=Source lookup: unable to restore map entry - missing local path attribute.
MapEntrySourceContainerType.2=Source lookup: unable to restore map entry - expecting map entry element.
MapEntrySourceContainerType.3=Source lookup: unable to restore map entry - invalid memento.
MappingSourceContainerType.0=Source lookup: unable to restore map entry - expecting memnto attribute.
MappingSourceContainerType.1=Source lookup: unable to restore mapping - expecting mapping element.
MappingSourceContainerType.2=Source lookup: unable to restore mapping - invalid memento.
SourceUtils.0=Mapping

View file

@ -13,7 +13,6 @@ 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;
@ -39,6 +38,14 @@ public class MapEntrySourceContainer extends AbstractSourceContainer {
private IPath fBackendPath;
/**
* Constructor for MapEntrySourceContainer.
*/
public MapEntrySourceContainer() {
fBackendPath = Path.EMPTY;
fLocalPath = Path.EMPTY;
}
/**
* Constructor for MapEntrySourceContainer.
*/
@ -80,7 +87,7 @@ public class MapEntrySourceContainer extends AbstractSourceContainer {
* @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$
return MessageFormat.format( "{0} - {1}", new String[] { getBackendPath().toOSString(), getLocalPath().toOSString() } ); //$NON-NLS-1$
}
/* (non-Javadoc)
@ -90,14 +97,22 @@ public class MapEntrySourceContainer extends AbstractSourceContainer {
return getSourceContainerType( TYPE_ID );
}
protected IPath getLocalPath() {
public IPath getLocalPath() {
return fLocalPath;
}
protected IPath getBackendPath() {
public IPath getBackendPath() {
return fBackendPath;
}
public void setLocalPath( IPath local ) {
fLocalPath = local;
}
public void setBackendPath( IPath backend ) {
fBackendPath = backend;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@ -107,4 +122,8 @@ public class MapEntrySourceContainer extends AbstractSourceContainer {
MapEntrySourceContainer entry = (MapEntrySourceContainer)o;
return ( entry.getBackendPath().equals( getBackendPath() ) && entry.getLocalPath().equals( getLocalPath() ) );
}
public MapEntrySourceContainer copy() {
return new MapEntrySourceContainer( fBackendPath, fLocalPath );
}
}

View file

@ -39,18 +39,18 @@ public class MapEntrySourceContainerType extends AbstractSourceContainerTypeDele
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 );
abort( InternalSourceLookupMessages.getString( "MapEntrySourceContainerType.0" ), null ); //$NON-NLS-1$
}
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 );
abort( InternalSourceLookupMessages.getString( "MapEntrySourceContainerType.1" ), null ); //$NON-NLS-1$
}
return new MapEntrySourceContainer( backend, local );
}
abort( "Source lookup: unable to restore map entry - expecting map entry element.", null );
abort( InternalSourceLookupMessages.getString( "MapEntrySourceContainerType.2" ), null ); //$NON-NLS-1$
}
abort( "Source lookup: unable to restore map entry - invalid memento.", null );
abort( InternalSourceLookupMessages.getString( "MapEntrySourceContainerType.3" ), null ); //$NON-NLS-1$
return null;
}

View file

@ -30,6 +30,7 @@ public class MappingSourceContainerType extends AbstractSourceContainerTypeDeleg
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_NAME = "name"; //$NON-NLS-1$
private final static String ATTR_MEMENTO = "memento"; //$NON-NLS-1$
/* (non-Javadoc)
@ -40,6 +41,9 @@ public class MappingSourceContainerType extends AbstractSourceContainerTypeDeleg
if ( node.getNodeType() == Node.ELEMENT_NODE ) {
Element element = (Element)node;
if ( ELEMENT_MAPPING.equals( element.getNodeName() ) ) {
String name = element.getAttribute( ATTR_NAME );
if ( name == null )
name = ""; //$NON-NLS-1$
List entries = new ArrayList();
Node childNode = element.getFirstChild();
while( childNode != null ) {
@ -48,7 +52,7 @@ public class MappingSourceContainerType extends AbstractSourceContainerTypeDeleg
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 );
abort( InternalSourceLookupMessages.getString( "MappingSourceContainerType.0" ), null ); //$NON-NLS-1$
}
ISourceContainerType type = DebugPlugin.getDefault().getLaunchManager().getSourceContainerType( MapEntrySourceContainer.TYPE_ID );
MapEntrySourceContainer entry = (MapEntrySourceContainer)type.createSourceContainer( childMemento );
@ -57,16 +61,16 @@ public class MappingSourceContainerType extends AbstractSourceContainerTypeDeleg
}
childNode = childNode.getNextSibling();
}
MappingSourceContainer container = new MappingSourceContainer();
MappingSourceContainer container = new MappingSourceContainer( name );
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( InternalSourceLookupMessages.getString( "MappingSourceContainerType.1" ), null ); //$NON-NLS-1$
}
abort( "Source lookup: unable to restore mapping - invalid memento.", null );
abort( InternalSourceLookupMessages.getString( "MappingSourceContainerType.2" ), null ); //$NON-NLS-1$
return null;
}
@ -76,6 +80,7 @@ public class MappingSourceContainerType extends AbstractSourceContainerTypeDeleg
public String getMemento( ISourceContainer container ) throws CoreException {
Document document = newDocument();
Element element = document.createElement( ELEMENT_MAPPING );
element.setAttribute( ATTR_NAME, container.getName() );
ISourceContainer[] entries = ((MappingSourceContainer)container).getSourceContainers();
for ( int i = 0; i < entries.length; ++i ) {
Element child = document.createElement( ELEMENT_MAP_ENTRY );

View file

@ -8,26 +8,31 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.internal.core.sourcelookup;
import java.io.IOException;
import java.io.StringReader;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.CDebugUtils;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
import org.eclipse.cdt.debug.core.sourcelookup.IDirectorySourceLocation;
import org.eclipse.cdt.debug.core.sourcelookup.IProjectSourceLocation;
import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.debug.core.sourcelookup.containers.DirectorySourceContainer;
import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@ -35,58 +40,47 @@ import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
* Enter type comment.
*
* @since Oct 22, 2003
*/
public class SourceUtils
{
public class SourceUtils {
private static final String NAME_COMMON_SOURCE_LOCATIONS = "commonSourceLocations"; //$NON-NLS-1$
private static final String NAME_SOURCE_LOCATION = "sourceLocation"; //$NON-NLS-1$
private static final String ATTR_CLASS = "class"; //$NON-NLS-1$
private static final String ATTR_MEMENTO = "memento"; //$NON-NLS-1$
public static String getCommonSourceLocationsMemento( ICSourceLocation[] locations )
{
public static String getCommonSourceLocationsMemento( ICSourceLocation[] locations ) {
Document document = null;
Throwable ex = null;
try
{
try {
document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Element element = document.createElement( NAME_COMMON_SOURCE_LOCATIONS );
document.appendChild( element );
saveSourceLocations( document, element, locations );
return CDebugUtils.serializeDocument( document );
}
catch( ParserConfigurationException e )
{
catch( ParserConfigurationException e ) {
ex = e;
}
catch( IOException e )
{
catch( IOException e ) {
ex = e;
}
catch( TransformerException e )
{
catch( TransformerException e ) {
ex = e;
}
CDebugCorePlugin.log( new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0, "Error saving common source settings.", ex ) ); //$NON-NLS-1$
return null;
}
private static void saveSourceLocations( Document doc, Element node, ICSourceLocation[] locations )
{
for ( int i = 0; i < locations.length; i++ )
{
private static void saveSourceLocations( Document doc, Element node, ICSourceLocation[] locations ) {
for( int i = 0; i < locations.length; i++ ) {
Element child = doc.createElement( NAME_SOURCE_LOCATION );
child.setAttribute( ATTR_CLASS, locations[i].getClass().getName() );
try
{
try {
child.setAttribute( ATTR_MEMENTO, locations[i].getMemento() );
}
catch( CoreException e )
{
catch( CoreException e ) {
CDebugCorePlugin.log( e );
continue;
}
@ -94,91 +88,71 @@ public class SourceUtils
}
}
public static ICSourceLocation[] getCommonSourceLocationsFromMemento( String memento )
{
public static ICSourceLocation[] getCommonSourceLocationsFromMemento( String memento ) {
ICSourceLocation[] result = new ICSourceLocation[0];
if ( !isEmpty( memento ) )
{
try
{
if ( !isEmpty( memento ) ) {
try {
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
StringReader reader = new StringReader( memento );
InputSource source = new InputSource( reader );
Element root = parser.parse( source ).getDocumentElement();
if ( root.getNodeName().equalsIgnoreCase( NAME_COMMON_SOURCE_LOCATIONS ) )
result = initializeSourceLocations( root );
}
catch( ParserConfigurationException e )
{
catch( ParserConfigurationException e ) {
CDebugCorePlugin.log( new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0, "Error initializing common source settings.", e ) ); //$NON-NLS-1$
}
catch( SAXException e )
{
catch( SAXException e ) {
CDebugCorePlugin.log( new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0, "Error initializing common source settings.", e ) ); //$NON-NLS-1$
}
catch( IOException e )
{
catch( IOException e ) {
CDebugCorePlugin.log( new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), 0, "Error initializing common source settings.", e ) ); //$NON-NLS-1$
}
}
return result;
}
public static ICSourceLocation[] initializeSourceLocations( Element root )
{
public static ICSourceLocation[] initializeSourceLocations( Element root ) {
List sourceLocations = new LinkedList();
NodeList list = root.getChildNodes();
int length = list.getLength();
for ( int i = 0; i < length; ++i )
{
for( int i = 0; i < length; ++i ) {
Node node = list.item( i );
short type = node.getNodeType();
if ( type == Node.ELEMENT_NODE )
{
if ( type == Node.ELEMENT_NODE ) {
Element entry = (Element)node;
if ( entry.getNodeName().equalsIgnoreCase( NAME_SOURCE_LOCATION ) )
{
if ( entry.getNodeName().equalsIgnoreCase( NAME_SOURCE_LOCATION ) ) {
String className = entry.getAttribute( ATTR_CLASS );
String data = entry.getAttribute( ATTR_MEMENTO );
if ( className == null || className.trim().length() == 0 )
{
if ( className == null || className.trim().length() == 0 ) {
CDebugCorePlugin.log( "Unable to restore common source locations - invalid format." ); //$NON-NLS-1$
continue;
}
Class clazz = null;
try
{
try {
clazz = CDebugCorePlugin.getDefault().getBundle().loadClass( className );
}
catch( ClassNotFoundException e )
{
CDebugCorePlugin.log( MessageFormat.format( "Unable to restore source location - class not found {0}", new String[] { className } ) ); //$NON-NLS-1$
catch( ClassNotFoundException e ) {
CDebugCorePlugin.log( MessageFormat.format( "Unable to restore source location - class not found {0}", new String[]{ className } ) ); //$NON-NLS-1$
continue;
}
ICSourceLocation location = null;
try
{
try {
location = (ICSourceLocation)clazz.newInstance();
}
catch( IllegalAccessException e )
{
catch( IllegalAccessException e ) {
CDebugCorePlugin.log( "Unable to restore source location: " + e.getMessage() ); //$NON-NLS-1$
continue;
}
catch( InstantiationException e )
{
catch( InstantiationException e ) {
CDebugCorePlugin.log( "Unable to restore source location: " + e.getMessage() ); //$NON-NLS-1$
continue;
}
try
{
try {
location.initializeFrom( data );
sourceLocations.add( location );
}
catch( CoreException e )
{
catch( CoreException e ) {
CDebugCorePlugin.log( "Unable to restore source location: " + e.getMessage() ); //$NON-NLS-1$
}
}
@ -187,8 +161,29 @@ public class SourceUtils
return (ICSourceLocation[])sourceLocations.toArray( new ICSourceLocation[sourceLocations.size()] );
}
private static boolean isEmpty( String string )
{
return ( string == null || string.trim().length() == 0 );
private static boolean isEmpty( String string ) {
return (string == null || string.trim().length() == 0);
}
static public ISourceContainer[] convertSourceLocations( ICSourceLocation[] locations ) {
ArrayList containers = new ArrayList( locations.length );
int mappingCount = 0;
for ( int i = 0; i < locations.length; ++i ) {
if ( locations[i] instanceof IProjectSourceLocation ) {
containers.add( new ProjectSourceContainer( ((IProjectSourceLocation)locations[i]).getProject(), false ) );
}
else if ( locations[i] instanceof IDirectorySourceLocation ) {
IDirectorySourceLocation d = (IDirectorySourceLocation)locations[i];
IPath a = d.getAssociation();
if ( a != null ) {
MappingSourceContainer mapping = new MappingSourceContainer( InternalSourceLookupMessages.getString( "SourceUtils.0" ) + (++mappingCount) ); //$NON-NLS-1$
mapping.addMapEntries( new MapEntrySourceContainer[] { new MapEntrySourceContainer( a, d.getDirectory() ) } );
containers.add( mapping );
}
containers.add( new DirectorySourceContainer( d.getDirectory(), d.searchSubfolders() ) );
}
}
return (ISourceContainer[])containers.toArray( new ISourceContainer[containers.size()] );
}
}

View file

@ -1,3 +1,29 @@
2005-04-21 Mikhail Khodjaiants
Bug 80175: Replace the CDT source lookup by the source lookup provided by Eclipse platform.
* CDebugModelPresentation.java
* ICDebugHelpContextIds.java
* CDebugPreferencePage.java
* PreferenceMessages.properties
* SourcePreferencePage.java
* AddContainerAction.java: new
* AddSourceContainerDialog.java: new
* DownAction.java: new
* EditContainerAction.java: new
* MappingSourceContainerBrowser.java
* PathMappingDialog.java
* RemoveAction.java: new
* SourceContainerAction.java: new
* SourceContainerLabelProvider.java: new
* SourceContainerViewer.java: new
* SourceContainerWorkbenchAdapter.java
* SourceLookupUIMessages.java: new
* SourceLookupUIMessages.properties: new
* UpAction.java: new
* CDebugUIPlugin.java
* DefaultSourceLocator.java
* OldDefaultSourceLocator.java: new
* plugin.properties
2005-04-12 Mikhail Khodjaiants
Bug 91155: Wrong icon for "Restart".
* icons/dlcl16/restart.gif

View file

@ -19,7 +19,7 @@ SignalsView.name=Signals
CDebuggerPage.name=C Debugger UI Page
MemoryPreferencePage.name=Memory View
CDebugPreferencePage.name=Debug
SourcePreferencePage.name=Source Code Locations
SourcePreferencePage.name=Source Lookup Path
RunMenu.label=&Run
DebugActionSet.label=C/C++ Debug

View file

@ -41,7 +41,6 @@ import org.eclipse.cdt.debug.core.model.ICVariable;
import org.eclipse.cdt.debug.core.model.ICWatchpoint;
import org.eclipse.cdt.debug.core.model.IDummyStackFrame;
import org.eclipse.cdt.debug.core.model.IEnableDisableTarget;
import org.eclipse.cdt.debug.internal.ui.editors.CDebugEditor;
import org.eclipse.cdt.debug.internal.ui.editors.EditorInputDelegate;
import org.eclipse.cdt.debug.internal.ui.editors.FileNotFoundElement;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
@ -153,20 +152,20 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode
* @see org.eclipse.debug.ui.ISourcePresentation#getEditorId(org.eclipse.ui.IEditorInput, java.lang.Object)
*/
public String getEditorId( IEditorInput input, Object element ) {
if ( input instanceof EditorInputDelegate ) {
if ( ((EditorInputDelegate)input).getDelegate() == null )
return CDebugEditor.EDITOR_ID;
return getEditorId( ((EditorInputDelegate)input).getDelegate(), element );
}
// if ( input instanceof EditorInputDelegate ) {
// if ( ((EditorInputDelegate)input).getDelegate() == null )
// return CDebugEditor.EDITOR_ID;
// return getEditorId( ((EditorInputDelegate)input).getDelegate(), element );
// }
String id = null;
if ( input != null ) {
IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
IEditorDescriptor descriptor = registry.getDefaultEditor( input.getName() );
id = (descriptor != null) ? descriptor.getId() : CUIPlugin.EDITOR_ID;
}
if ( CUIPlugin.EDITOR_ID.equals( id ) ) {
return CDebugEditor.EDITOR_ID;
}
// if ( CUIPlugin.EDITOR_ID.equals( id ) ) {
// return CDebugEditor.EDITOR_ID;
// }
return id;
}

View file

@ -66,4 +66,5 @@ public interface ICDebugHelpContextIds
// 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$
public static final String ADD_SOURCE_CONTAINER_DIALOG = PREFIX + "add_source_container_dialog"; //$NON-NLS-1$
}

View file

@ -20,10 +20,8 @@ import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.debug.ui.IDebugView;
import org.eclipse.jface.dialogs.DialogPage;
import org.eclipse.jface.preference.ColorFieldEditor;
import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.jface.preference.IPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.jface.preference.PreferenceConverter;
@ -186,8 +184,8 @@ public class CDebugPreferencePage extends PreferencePage implements IWorkbenchPr
PreferenceConverter.setDefault( store, IInternalCDebugUIConstants.DISASSEMBLY_SOURCE_LINE_COLOR, IInternalCDebugUIConstants.DEFAULT_DISASSEMBLY_SOURCE_LINE_RGB );
}
/**
* @see DialogPage#dispose()
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.IDialogPage#dispose()
*/
public void dispose() {
super.dispose();
@ -274,8 +272,8 @@ public class CDebugPreferencePage extends PreferencePage implements IWorkbenchPr
label.setLayoutData( gd );
}
/**
* @see IPreferencePage#performOk() Also, notifies interested listeners
/* (non-Javadoc)
* @see org.eclipse.jface.preference.IPreferencePage#performOk()
*/
public boolean performOk() {
storeValues();

View file

@ -22,6 +22,5 @@ CDebugPreferencePage.10=Default register format:
CDebugPreferencePage.11=Disassembly options
CDebugPreferencePage.12=Maximum number of displayed instructions:
CDebugPreferencePage.13=The valid value range is [{0},{1}].
SourcePreferencePage.0=Common source lookup settings.
SourcePreferencePage.1=Source Locations
SourcePreferencePage.2=Search for duplicate source files
SourcePreferencePage.0=Common source lookup path settings.
SourcePreferencePage.0=S&ource Lookup Path:

View file

@ -10,81 +10,106 @@
***********************************************************************/
package org.eclipse.cdt.debug.internal.ui.preferences;
import java.util.Arrays;
import java.util.Observable;
import java.util.Observer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.ICDebugConstants;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
import org.eclipse.cdt.debug.internal.ui.ICDebugHelpContextIds;
import org.eclipse.cdt.debug.internal.ui.PixelConverter;
import org.eclipse.cdt.debug.internal.ui.dialogfields.DialogField;
import org.eclipse.cdt.debug.internal.ui.dialogfields.IDialogFieldListener;
import org.eclipse.cdt.debug.internal.ui.dialogfields.IListAdapter;
import org.eclipse.cdt.debug.internal.ui.dialogfields.LayoutUtil;
import org.eclipse.cdt.debug.internal.ui.dialogfields.SelectionButtonDialogField;
import org.eclipse.cdt.debug.internal.ui.wizards.AddSourceLocationWizard;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.cdt.debug.ui.sourcelookup.SourceListDialogField;
import org.eclipse.cdt.debug.internal.ui.sourcelookup.AddContainerAction;
import org.eclipse.cdt.debug.internal.ui.sourcelookup.DownAction;
import org.eclipse.cdt.debug.internal.ui.sourcelookup.EditContainerAction;
import org.eclipse.cdt.debug.internal.ui.sourcelookup.RemoveAction;
import org.eclipse.cdt.debug.internal.ui.sourcelookup.SourceContainerAction;
import org.eclipse.cdt.debug.internal.ui.sourcelookup.SourceContainerViewer;
import org.eclipse.cdt.debug.internal.ui.sourcelookup.UpAction;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
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.Label;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
/**
* The "Source Code Locations" preference page.
* The "Source Lookup Path" preference page.
*/
public class SourcePreferencePage extends PreferencePage implements IWorkbenchPreferencePage, Observer {
public class SourcePreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
private SourceContainerViewer fPathViewer;
private List fActions = new ArrayList(6);
private IWorkbench fWorkbench;
private AddContainerAction fAddAction;
private EditContainerAction fEditAction;
private SourceListDialogField fSourceListField;
private SelectionButtonDialogField fSearchForDuplicateFiles;
private boolean fChanged = false;
public SourcePreferencePage() {
super();
setPreferenceStore( CDebugUIPlugin.getDefault().getPreferenceStore() );
setDescription( PreferenceMessages.getString( "SourcePreferencePage.0" ) ); //$NON-NLS-1$
}
/*
* (non-Javadoc)
*
/* (non-Javadoc)
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
*/
protected Control createContents( Composite parent ) {
getWorkbench().getHelpSystem().setHelp( getControl(), ICDebugHelpContextIds.SOURCE_PREFERENCE_PAGE );
fSourceListField = createSourceListField();
fSearchForDuplicateFiles = createSearchForDuplicateFilesButton();
Composite control = new Composite( parent, SWT.NONE );
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginWidth = 5;
layout.marginHeight = 5;
control.setLayout( layout );
GridData data = new GridData();
data.verticalAlignment = GridData.FILL;
data.horizontalAlignment = GridData.FILL;
control.setLayoutData( data );
control.setFont( JFaceResources.getDialogFont() );
PixelConverter converter = new PixelConverter( control );
fSourceListField.doFillIntoGrid( control, 3 );
LayoutUtil.setHorizontalSpan( fSourceListField.getLabelControl( null ), 2 );
LayoutUtil.setWidthHint( fSourceListField.getLabelControl( null ), converter.convertWidthInCharsToPixels( 40 ) );
LayoutUtil.setHorizontalGrabbing( fSourceListField.getListControl( null ) );
fSearchForDuplicateFiles.doFillIntoGrid( control, 3 );
setValues();
return control;
Font font = parent.getFont();
Composite comp = new Composite( parent, SWT.NONE );
GridLayout topLayout = new GridLayout();
topLayout.numColumns = 2;
comp.setLayout( topLayout );
GridData gd = new GridData( GridData.FILL_BOTH );
comp.setLayoutData( gd );
Label viewerLabel = new Label( comp, SWT.LEFT );
viewerLabel.setText( PreferenceMessages.getString( "SourcePreferencePage.0" ) ); //$NON-NLS-1$
gd = new GridData( GridData.HORIZONTAL_ALIGN_FILL );
gd.horizontalSpan = 2;
viewerLabel.setLayoutData( gd );
viewerLabel.setFont( font );
fPathViewer = new SourceContainerViewer( comp );
gd = new GridData( GridData.FILL_BOTH );
fPathViewer.getControl().setLayoutData( gd );
fPathViewer.getControl().setFont( font );
Composite pathButtonComp = new Composite( comp, SWT.NONE );
GridLayout pathButtonLayout = new GridLayout();
pathButtonLayout.marginHeight = 0;
pathButtonLayout.marginWidth = 0;
pathButtonComp.setLayout( pathButtonLayout );
gd = new GridData( GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL );
pathButtonComp.setLayoutData( gd );
pathButtonComp.setFont( font );
createVerticalSpacer( comp, 2 );
GC gc = new GC( parent );
gc.setFont( parent.getFont() );
FontMetrics fontMetrics = gc.getFontMetrics();
gc.dispose();
fAddAction = new AddContainerAction();
Button button = createPushButton( pathButtonComp, fAddAction.getText(), fontMetrics );
fAddAction.setButton( button );
addAction( fAddAction );
fEditAction = new EditContainerAction();
button = createPushButton( pathButtonComp, fEditAction.getText(), fontMetrics );
fEditAction.setButton( button );
addAction( fEditAction );
SourceContainerAction action = new RemoveAction();
button = createPushButton( pathButtonComp, action.getText(), fontMetrics );
action.setButton( button );
addAction( action );
action = new UpAction();
button = createPushButton( pathButtonComp, action.getText(), fontMetrics );
action.setButton( button );
addAction( action );
action = new DownAction();
button = createPushButton( pathButtonComp, action.getText(), fontMetrics );
action.setButton( button );
addAction( action );
retargetActions( fPathViewer );
Dialog.applyDialogFont( comp );
getWorkbench().getHelpSystem().setHelp( comp, ICDebugHelpContextIds.SOURCE_PREFERENCE_PAGE );
initialize();
return comp;
}
/*
@ -96,125 +121,66 @@ public class SourcePreferencePage extends PreferencePage implements IWorkbenchPr
fWorkbench = workbench;
}
/*
* (non-Javadoc)
*
* @see java.util.Observer#update(java.util.Observable, java.lang.Object)
*/
public void update( Observable o, Object arg ) {
setChanged( true );
}
private SourceListDialogField createSourceListField() {
SourceListDialogField field = new SourceListDialogField( PreferenceMessages.getString( "SourcePreferencePage.1" ), //$NON-NLS-1$
new IListAdapter() {
public void customButtonPressed( DialogField f, int index ) {
sourceButtonPressed( index );
}
public void selectionChanged( DialogField f ) {
}
} );
field.addObserver( this );
return field;
}
private SelectionButtonDialogField createSearchForDuplicateFilesButton() {
SelectionButtonDialogField button = new SelectionButtonDialogField( SWT.CHECK );
button.setLabelText( PreferenceMessages.getString( "SourcePreferencePage.2" ) ); //$NON-NLS-1$
button.setDialogFieldListener( new IDialogFieldListener() {
public void dialogFieldChanged( DialogField field ) {
setChanged( true );
}
} );
private 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;
}
protected void sourceButtonPressed( int index ) {
switch( index ) {
case 0: // Add...
if ( addSourceLocation() )
setChanged( true );
break;
case 2: // Up
case 3: // Down
case 5: // Remove
setChanged( true );
break;
}
}
protected boolean isChanged() {
return fChanged;
}
protected void setChanged( boolean changed ) {
fChanged = changed;
}
private boolean addSourceLocation() {
AddSourceLocationWizard wizard = new AddSourceLocationWizard( getSourceLocations() );
WizardDialog dialog = new WizardDialog( getShell(), wizard );
if ( dialog.open() == Window.OK ) {
fSourceListField.addElement( wizard.getSourceLocation() );
return true;
}
return false;
}
public ICSourceLocation[] getSourceLocations() {
return (fSourceListField != null) ? fSourceListField.getSourceLocations() : new ICSourceLocation[0];
}
public void setSourceLocations( ICSourceLocation[] locations ) {
if ( fSourceListField != null )
fSourceListField.setElements( Arrays.asList( locations ) );
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.preference.PreferencePage#performDefaults()
*/
protected void performDefaults() {
setSourceLocations( new ICSourceLocation[0] );
setSearchForDuplicateFiles( false );
super.performDefaults();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.preference.IPreferencePage#performOk()
*/
public boolean performOk() {
storeValues();
CDebugCorePlugin.getDefault().savePluginPreferences();
return true;
}
private boolean searchForDuplicateFiles() {
return (fSearchForDuplicateFiles != null) ? fSearchForDuplicateFiles.isSelected() : false;
}
private void setSearchForDuplicateFiles( boolean search ) {
if ( fSearchForDuplicateFiles != null )
fSearchForDuplicateFiles.setSelection( search );
}
private void setValues() {
setSourceLocations( CDebugCorePlugin.getDefault().getCommonSourceLocations() );
setSearchForDuplicateFiles( CDebugCorePlugin.getDefault().getPluginPreferences().getBoolean( ICDebugConstants.PREF_SEARCH_DUPLICATE_FILES ) );
}
private void storeValues() {
CDebugCorePlugin.getDefault().saveCommonSourceLocations( getSourceLocations() );
CDebugCorePlugin.getDefault().getPluginPreferences().setValue( ICDebugConstants.PREF_SEARCH_DUPLICATE_FILES, searchForDuplicateFiles() );
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;
}
private IWorkbench getWorkbench() {
return fWorkbench;
}
private void addAction( SourceContainerAction action ) {
fActions.add( action );
}
private void retargetActions( SourceContainerViewer viewer ) {
Iterator actions = fActions.iterator();
while( actions.hasNext() ) {
SourceContainerAction action = (SourceContainerAction)actions.next();
action.setViewer( viewer );
}
}
private void createVerticalSpacer( Composite comp, int colSpan ) {
Label label = new Label( comp, SWT.NONE );
GridData gd = new GridData();
gd.horizontalSpan = colSpan;
label.setLayoutData( gd );
}
private void initialize() {
ISourceLookupDirector director = CDebugCorePlugin.getDefault().getCommonSourceLookupDirector();
fPathViewer.setEntries( director.getSourceContainers() );
fAddAction.setSourceLookupDirector( director );
fEditAction.setSourceLookupDirector( director );
}
/* (non-Javadoc)
* @see org.eclipse.jface.preference.PreferencePage#performDefaults()
*/
protected void performDefaults() {
fPathViewer.setEntries( new ISourceContainer[0] );
super.performDefaults();
}
/* (non-Javadoc)
* @see org.eclipse.jface.preference.PreferencePage#performOk()
*/
public boolean performOk() {
CDebugCorePlugin.getDefault().getCommonSourceLookupDirector().setSourceContainers( fPathViewer.getEntries() );
CDebugCorePlugin.getDefault().savePluginPreferences();
return true;
}
}

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.ui.sourcelookup;
import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
import org.eclipse.jface.viewers.IStructuredSelection;
/**
* The action to add a new source container.
* Used by the CommonSourceNotFoundEditor, the launch configuration source tab,
* and the EditSourceLookupPathDialog.
*/
public class AddContainerAction extends SourceContainerAction {
private ISourceLookupDirector fDirector;
public AddContainerAction() {
super(SourceLookupUIMessages.getString( "AddContainerAction.0" )); //$NON-NLS-1$
}
/**
* Prompts for a project to add.
*
* @see org.eclipse.jface.action.IAction#run()
*/
public void run() {
AddSourceContainerDialog dialog = new AddSourceContainerDialog(getShell(), getViewer(), fDirector);
dialog.open();
}
public void setSourceLookupDirector(ISourceLookupDirector director) {
fDirector = director;
}
/* (non-Javadoc)
* @see org.eclipse.ui.actions.BaseSelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
*/
protected boolean updateSelection(IStructuredSelection selection) {
if(selection == null || selection.isEmpty()) {
return true;
}
return getViewer().getTree().getSelection()[0].getParentItem()==null;
}
}

View file

@ -0,0 +1,155 @@
/*******************************************************************************
* Copyright (c) 2003, 2005 IBM Corporation 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.sourcelookup;
import java.util.ArrayList;
import org.eclipse.cdt.debug.internal.ui.ICDebugHelpContextIds;
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.ISourceLookupDirector;
import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupUIUtils;
import org.eclipse.debug.ui.sourcelookup.ISourceContainerBrowser;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.ui.PlatformUI;
/**
* The dialog for adding new source containers. Presents the user with a list of
* source container types and allows them to select one.
*
* @since 3.0
*/
public class AddSourceContainerDialog extends TitleAreaDialog {
private TableViewer fViewer;
private SourceContainerViewer fSourceContainerViewer;
private boolean fDoubleClickSelects = true;
private ISourceLookupDirector fDirector;
/**
* Constructor
*/
public AddSourceContainerDialog(Shell shell, SourceContainerViewer viewer, ISourceLookupDirector director) {
super(shell);
setShellStyle(getShellStyle() | SWT.RESIZE);
fSourceContainerViewer=viewer;
fDirector = director;
}
/**
* Creates the dialog area to display source container types that are "browseable"
*/
protected Control createDialogArea(Composite ancestor) {
getShell().setText(SourceLookupUIMessages.getString( "AddSourceContainerDialog.0" )); //$NON-NLS-1$
setTitle(SourceLookupUIMessages.getString( "AddSourceContainerDialog.1" )); //$NON-NLS-1$
Composite parent = new Composite(ancestor, SWT.NULL);
GridData gd= new GridData(GridData.FILL_BOTH);
GridLayout topLayout = new GridLayout();
topLayout.numColumns = 1;
parent.setLayout(topLayout);
parent.setLayoutData(gd);
ISourceContainerType[] types = filterTypes(DebugPlugin.getDefault().getLaunchManager().getSourceContainerTypes());
fViewer = new TableViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.SINGLE);
final Table table = fViewer.getTable();
gd = new GridData(GridData.FILL_BOTH);
table.setLayoutData(gd);
if (fDoubleClickSelects) {
table.addSelectionListener(new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
if (table.getSelectionCount() == 1)
okPressed();
}
});
}
fViewer.setLabelProvider(new SourceContainerLabelProvider());
fViewer.setContentProvider(new ArrayContentProvider());
fViewer.setSorter(new ViewerSorter());
fViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection();
String desc = null;
if (!selection.isEmpty()) {
ISourceContainerType type = (ISourceContainerType) ((IStructuredSelection)selection).getFirstElement();
desc = type.getDescription();
}
setMessage(desc);
}
});
if(types.length != 0) {
fViewer.setInput(types);
}
Dialog.applyDialogFont(parent);
PlatformUI.getWorkbench().getHelpSystem().setHelp( getShell(), ICDebugHelpContextIds.ADD_SOURCE_CONTAINER_DIALOG );
return parent;
}
/**
* Removes types without browsers from the provided list of types.
* @param types the complete list of source container types
* @return the list of source container types that have browsers
*/
private ISourceContainerType[] filterTypes(ISourceContainerType[] types){
ArrayList validTypes = new ArrayList();
for (int i=0; i< types.length; i++) {
ISourceContainerType type = types[i];
if (fDirector.supportsSourceContainerType(type)) {
ISourceContainerBrowser sourceContainerBrowser = SourceLookupUIUtils.getSourceContainerBrowser(type.getId());
if(sourceContainerBrowser != null && sourceContainerBrowser.canAddSourceContainers(fDirector)) {
validTypes.add(type);
}
}
}
return (ISourceContainerType[]) validTypes.toArray(new ISourceContainerType[validTypes.size()]);
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#okPressed()
*/
protected void okPressed() {
//single selection dialog, so take first item in array
//there will always be a selected item since we set it with viewer.setSelection
ISourceContainerType type = (ISourceContainerType) ((StructuredSelection) fViewer.getSelection()).getFirstElement();
ISourceContainerBrowser browser = SourceLookupUIUtils.getSourceContainerBrowser(type.getId());
if (browser != null) {
ISourceContainer[] results = browser.addSourceContainers(getShell(), fDirector);
if(results != null) {
fSourceContainerViewer.addEntries(results);
}
}
super.okPressed();
}
}

View file

@ -0,0 +1,57 @@
/*******************************************************************************
* Copyright (c) 2003, 2005 IBM Corporation 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.sourcelookup;
import java.util.List;
import org.eclipse.jface.viewers.IStructuredSelection;
/**
* The action for sorting the order of source containers in the dialog.
*
*/
public class DownAction extends SourceContainerAction {
public DownAction() {
super(SourceLookupUIMessages.getString( "DownAction.0" )); //$NON-NLS-1$
}
/**
* @see IAction#run()
*/
public void run() {
List targets = getOrderedSelection();
if (targets.isEmpty()) {
return;
}
List list = getEntriesAsList();
int bottom = list.size() - 1;
int index = 0;
for (int i = targets.size() - 1; i >= 0; i--) {
Object target = targets.get(i);
index = list.indexOf(target);
if (index < bottom) {
bottom = index + 1;
Object temp = list.get(bottom);
list.set(bottom, target);
list.set(index, temp);
}
bottom = index;
}
setEntries(list);
}
/**
* @see SelectionListenerAction#updateSelection(IStructuredSelection)
*/
protected boolean updateSelection(IStructuredSelection selection) {
return !selection.isEmpty() && !isIndexSelected(selection, getEntriesAsList().size() - 1) && getViewer().getTree().getSelection()[0].getParentItem()==null;
}
}

View file

@ -0,0 +1,89 @@
/*******************************************************************************
* Copyright (c) 2003, 2005 IBM Corporation 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.sourcelookup;
import java.util.Iterator;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupUIUtils;
import org.eclipse.debug.ui.sourcelookup.ISourceContainerBrowser;
import org.eclipse.jface.viewers.IStructuredSelection;
/**
* Action used to edit source containers on a source lookup path
*/
public class EditContainerAction extends SourceContainerAction {
private ISourceLookupDirector fDirector;
private ISourceContainer[] fContainers;
private ISourceContainerBrowser fBrowser;
public EditContainerAction() {
super(SourceLookupUIMessages.getString( "EditContainerAction.0" )); //$NON-NLS-1$
}
/**
* Prompts for a project to add.
*
* @see org.eclipse.jface.action.IAction#run()
*/
public void run() {
ISourceContainer[] replacements = fBrowser.editSourceContainers(getShell(), fDirector, fContainers);
int j = 0;
ISourceContainer[] existing = getViewer().getEntries();
for (int i = 0; i < existing.length && j < replacements.length; i++) {
ISourceContainer toBeReplaced = fContainers[j];
ISourceContainer container = existing[i];
if (container.equals(toBeReplaced)) {
existing[i] = replacements[j];
j++;
}
}
getViewer().setEntries(existing);
}
public void setSourceLookupDirector(ISourceLookupDirector director) {
fDirector = director;
}
/* (non-Javadoc)
* @see org.eclipse.ui.actions.BaseSelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
*/
protected boolean updateSelection(IStructuredSelection selection) {
if(selection == null || selection.isEmpty()) {
return false;
}
if (getViewer().getTree().getSelection()[0].getParentItem()==null) {
// can only edit top level items of same type
fContainers = new ISourceContainer[selection.size()];
Iterator iterator = selection.iterator();
ISourceContainer container = (ISourceContainer) iterator.next();
ISourceContainerType type = container.getType();
fContainers[0] = container;
int i = 1;
while (iterator.hasNext()) {
container = (ISourceContainer) iterator.next();
fContainers[i] = container;
i++;
if (!container.getType().equals(type)) {
return false;
}
}
// all the same type, see if editing is supported
fBrowser = SourceLookupUIUtils.getSourceContainerBrowser(type.getId());
if (fBrowser != null) {
return fBrowser.canEditSourceContainers(fDirector, fContainers);
}
}
return false;
}
}

View file

@ -22,11 +22,13 @@ import org.eclipse.swt.widgets.Shell;
*/
public class MappingSourceContainerBrowser extends AbstractSourceContainerBrowser {
private static final String MAPPING = SourceLookupUIMessages.getString( "MappingSourceContainerBrowser.0" ); //$NON-NLS-1$
/* (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() };
return new ISourceContainer[] { new MappingSourceContainer( generateName( director ) ) };
}
/* (non-Javadoc)
@ -55,4 +57,25 @@ public class MappingSourceContainerBrowser extends AbstractSourceContainerBrowse
}
return new ISourceContainer[0];
}
private String generateName( ISourceLookupDirector director ) {
// int counter = 1;
// ISourceContainer[] containers = director.getSourceContainers();
// for ( int i = 0; i < containers.length; ++i ) {
// if ( MappingSourceContainer.TYPE_ID.equals( containers[i].getType().getId() ) ) {
// String name = containers[i].getName();
// if ( name.startsWith( MAPPING ) ) {
// try {
// int number = Integer.valueOf( name.substring( MAPPING.length() ) ).intValue();
// if ( number == counter )
// ++counter;
// }
// catch( NumberFormatException e ) {
// }
// }
// }
// }
// return MAPPING + counter;
return MAPPING;
}
}

View file

@ -10,6 +10,7 @@
***********************************************************************/
package org.eclipse.cdt.debug.internal.ui.sourcelookup;
import java.io.File;
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;
@ -22,9 +23,11 @@ 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.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.Window;
@ -57,8 +60,9 @@ public class PathMappingDialog extends TitleAreaDialog {
class MapEntryDialog extends TitleAreaDialog {
protected Text fBackendPathText;
private MapEntrySourceContainer fEntry;
protected Text fBackendPathText;
protected Text fLocalPathText;
/**
@ -66,13 +70,22 @@ public class PathMappingDialog extends TitleAreaDialog {
*/
public MapEntryDialog( Shell parentShell ) {
super( parentShell );
fEntry = null;
}
/**
* Constructor for MapEntryDialog.
*/
public MapEntryDialog( Shell parentShell, MapEntrySourceContainer entry ) {
super( parentShell );
fEntry = entry;
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
*/
protected Control createDialogArea( Composite parent ) {
setTitle( "Specify the mapping paths" );
setTitle( SourceLookupUIMessages.getString( "PathMappingDialog.0" ) ); //$NON-NLS-1$
Font font = parent.getFont();
Composite composite = new Composite( parent, SWT.NONE );
@ -93,7 +106,7 @@ public class PathMappingDialog extends TitleAreaDialog {
setMessage( null );
Label label = new Label( composite, SWT.LEFT );
label.setText( "Compilation path:" );
label.setText( SourceLookupUIMessages.getString( "PathMappingDialog.1" ) ); //$NON-NLS-1$
data = new GridData( GridData.FILL_HORIZONTAL );
data.horizontalSpan = 2;
label.setLayoutData( data );
@ -111,7 +124,7 @@ public class PathMappingDialog extends TitleAreaDialog {
} );
label = new Label( composite, SWT.LEFT );
label.setText( "Local file system path:" );
label.setText( SourceLookupUIMessages.getString( "PathMappingDialog.2" ) ); //$NON-NLS-1$
data = new GridData( GridData.FILL_HORIZONTAL );
data.horizontalSpan = 2;
label.setLayoutData( data );
@ -129,7 +142,7 @@ public class PathMappingDialog extends TitleAreaDialog {
Button button = new Button( composite, SWT.PUSH );
button.setFont( font );
button.setText( "&Browse..." );
button.setText( SourceLookupUIMessages.getString( "PathMappingDialog.3" ) ); //$NON-NLS-1$
button.addSelectionListener( new SelectionListener() {
public void widgetSelected( SelectionEvent e ) {
@ -149,15 +162,23 @@ public class PathMappingDialog extends TitleAreaDialog {
protected Control createContents( Composite parent ) {
Control control = super.createContents( parent );
initialize();
update();
return control;
}
protected void configureShell( Shell newShell ) {
newShell.setText( "Path Mapping" );
newShell.setText( SourceLookupUIMessages.getString( "PathMappingDialog.4" ) ); //$NON-NLS-1$
super.configureShell( newShell );
}
private void initialize() {
if ( fEntry != null ) {
fBackendPathText.setText( fEntry.getBackendPath().toOSString() );
fLocalPathText.setText( fEntry.getLocalPath().toOSString() );
}
}
protected void update() {
boolean isOk = updateErrorMessage();
Button ok = getButton( IDialogConstants.OK_ID );
@ -169,20 +190,29 @@ public class PathMappingDialog extends TitleAreaDialog {
setErrorMessage( null );
String backendText = fBackendPathText.getText().trim();
if ( backendText.length() == 0 ) {
setErrorMessage( "The compilation path must not be empty" );
setErrorMessage( SourceLookupUIMessages.getString( "PathMappingDialog.5" ) ); //$NON-NLS-1$
return false;
}
if ( !new Path( backendText ).isValidPath( backendText ) ) {
setErrorMessage( "Invalid compilation path." );
setErrorMessage( SourceLookupUIMessages.getString( "PathMappingDialog.6" ) ); //$NON-NLS-1$
return false;
}
String localText = fLocalPathText.getText().trim();
if ( localText.length() == 0 ) {
setErrorMessage( "The local file systems path must not be empty" );
setErrorMessage( SourceLookupUIMessages.getString( "PathMappingDialog.7" ) ); //$NON-NLS-1$
return false;
}
if ( !new Path( localText ).isValidPath( localText ) ) {
setErrorMessage( "Invalid local file system path." );
File localPath = new File( localText );
if ( !localPath.exists() ) {
setErrorMessage( SourceLookupUIMessages.getString( "PathMappingDialog.8" ) ); //$NON-NLS-1$
return false;
}
if ( !localPath.isDirectory() ) {
setErrorMessage( SourceLookupUIMessages.getString( "PathMappingDialog.9" ) ); //$NON-NLS-1$
return false;
}
if ( !localPath.isAbsolute() ) {
setErrorMessage( SourceLookupUIMessages.getString( "PathMappingDialog.10" ) ); //$NON-NLS-1$
return false;
}
return true;
@ -197,7 +227,12 @@ public class PathMappingDialog extends TitleAreaDialog {
}
protected void okPressed() {
fMapping.addMapEntry( new MapEntrySourceContainer( getBackendPath(), getLocalPath() ) );
if ( fEntry == null ) {
fEntry = new MapEntrySourceContainer();
fMapping.addMapEntry( fEntry );
}
fEntry.setBackendPath( getBackendPath() );
fEntry.setLocalPath( getLocalPath() );
super.okPressed();
}
}
@ -287,26 +322,31 @@ public class PathMappingDialog extends TitleAreaDialog {
private TableViewer fViewer;
private Text fNameText;
private Button fAddButton;
private Button fEditButton;
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() );
fMapping = fOriginalMapping.copy();
}
/* (non-Javadoc)
* @see org.eclipse.jface.window.Window#createContents(org.eclipse.swt.widgets.Composite)
*/
protected Control createContents( Composite parent ) {
Control control = super.createContents( parent );
updateButtons();
return control;
}
/* (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" );
setTitle( SourceLookupUIMessages.getString( "PathMappingDialog.11" ) ); //$NON-NLS-1$
//TODO Add image
Font font = parent.getFont();
@ -325,10 +365,39 @@ public class PathMappingDialog extends TitleAreaDialog {
Dialog.applyDialogFont( composite );
PlatformUI.getWorkbench().getHelpSystem().setHelp( getShell(), ICDebugHelpContextIds.SOURCE_PATH_MAPPING_DIALOG );
Composite nameComp = new Composite( composite, SWT.NONE );
layout = new GridLayout();
layout.numColumns = 2;
nameComp.setLayout( layout );
data = new GridData( GridData.FILL_HORIZONTAL );
data.horizontalSpan = 2;
nameComp.setLayoutData( data );
nameComp.setFont( font );
Label label = new Label( nameComp, SWT.LEFT );
data = new GridData( GridData.HORIZONTAL_ALIGN_BEGINNING );
label.setLayoutData( data );
label.setFont( font );
label.setText( SourceLookupUIMessages.getString( "PathMappingDialog.12" ) ); //$NON-NLS-1$
fNameText = new Text( nameComp, SWT.SINGLE | SWT.BORDER );
data = new GridData( GridData.FILL_HORIZONTAL );
fNameText.setLayoutData( data );
fNameText.setFont( font );
fNameText.setText( getMapping().getName() );
fNameText.addModifyListener( new ModifyListener() {
public void modifyText( ModifyEvent e ) {
}
} );
fViewer = createViewer( composite );
data = new GridData( GridData.FILL_BOTH );
fViewer.getControl().setLayoutData( data );
fViewer.getControl().setFont( font );
fViewer.addSelectionChangedListener( new ISelectionChangedListener() {
public void selectionChanged( SelectionChangedEvent event ) {
updateButtons();
}
} );
Composite buttonComp = new Composite( composite, SWT.NONE );
GridLayout buttonLayout = new GridLayout();
@ -344,7 +413,7 @@ public class PathMappingDialog extends TitleAreaDialog {
FontMetrics fontMetrics = gc.getFontMetrics();
gc.dispose();
fAddButton = createPushButton( buttonComp, "&Add...", fontMetrics );
fAddButton = createPushButton( buttonComp, SourceLookupUIMessages.getString( "PathMappingDialog.13" ), fontMetrics ); //$NON-NLS-1$
fAddButton.addSelectionListener( new SelectionAdapter() {
public void widgetSelected( SelectionEvent evt ) {
MapEntryDialog dialog = new MapEntryDialog( getShell() );
@ -354,18 +423,28 @@ public class PathMappingDialog extends TitleAreaDialog {
}
} );
fRemoveButton = createPushButton( buttonComp, "Re&move", fontMetrics );
fRemoveButton.addSelectionListener( new SelectionAdapter() {
fEditButton = createPushButton( buttonComp, SourceLookupUIMessages.getString( "PathMappingDialog.14" ), fontMetrics ); //$NON-NLS-1$
fEditButton.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] );
}
MapEntrySourceContainer[] entries = getSelection();
if ( entries.length > 0 ) {
MapEntryDialog dialog = new MapEntryDialog( getShell(), entries[0] );
if ( dialog.open() == Window.OK ) {
getViewer().refresh();
}
}
}
} );
fRemoveButton = createPushButton( buttonComp, SourceLookupUIMessages.getString( "PathMappingDialog.15" ), fontMetrics ); //$NON-NLS-1$
fRemoveButton.addSelectionListener( new SelectionAdapter() {
public void widgetSelected( SelectionEvent evt ) {
MapEntrySourceContainer[] entries = getSelection();
for ( int i = 0; i < entries.length; ++i ) {
fMapping.removeMapEntry( entries[i] );
}
getViewer().refresh();
}
} );
setMessage( null );
@ -406,7 +485,7 @@ public class PathMappingDialog extends TitleAreaDialog {
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
*/
protected void configureShell( Shell newShell ) {
newShell.setText( "Path Mappings" );
newShell.setText( SourceLookupUIMessages.getString( "PathMappingDialog.16" ) ); //$NON-NLS-1$
super.configureShell( newShell );
}
@ -419,6 +498,7 @@ public class PathMappingDialog extends TitleAreaDialog {
*/
protected void okPressed() {
fOriginalMapping.clear();
fOriginalMapping.setName( fNameText.getText().trim() );
try {
fOriginalMapping.addMapEntries( (MapEntrySourceContainer[])fMapping.getSourceContainers() );
}
@ -427,4 +507,24 @@ public class PathMappingDialog extends TitleAreaDialog {
fMapping.dispose();
super.okPressed();
}
protected MapEntrySourceContainer[] getSelection() {
MapEntrySourceContainer[] result = new MapEntrySourceContainer[0];
ISelection s = getViewer().getSelection();
if ( s instanceof IStructuredSelection ) {
int size = ((IStructuredSelection)s).size();
result = (MapEntrySourceContainer[])((IStructuredSelection)s).toList().toArray( new MapEntrySourceContainer[size] );
}
return result;
}
protected void updateButtons() {
MapEntrySourceContainer[] entries = getSelection();
if ( fEditButton != null ) {
fEditButton.setEnabled( entries.length == 1 );
}
if ( fRemoveButton != null ) {
fRemoveButton.setEnabled( entries.length > 0 );
}
}
}

View file

@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright (c) 2003, 2005 IBM Corporation 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.sourcelookup;
import java.util.List;
import org.eclipse.jface.viewers.IStructuredSelection;
/**
* The action used to remove source containers in the source location dialog/tab.
*
*/
public class RemoveAction extends SourceContainerAction {
public RemoveAction() {
super(SourceLookupUIMessages.getString( "RemoveAction.0" )); //$NON-NLS-1$
}
/**
* Removes all selected entries.
*
* @see IAction#run()
*/
public void run() {
List targets = getOrderedSelection();
List list = getEntriesAsList();
list.removeAll(targets);
setEntries(list);
}
/**
* @see SelectionListenerAction#updateSelection(IStructuredSelection)
*/
protected boolean updateSelection(IStructuredSelection selection) {
//check that something is selected and it is a root tree node.
return !selection.isEmpty() && getViewer().getTree().getSelection()[0].getParentItem()==null;
}
}

View file

@ -0,0 +1,176 @@
/*******************************************************************************
* Copyright (c) 2003, 2005 IBM Corporation 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.sourcelookup;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.actions.SelectionListenerAction;
/**
* The abstract class for all source lookup actions.
*/
public abstract class SourceContainerAction extends SelectionListenerAction {
//the viewer that the action is operating on
private SourceContainerViewer fViewer;
//the button that is used to invoke the action
private Button fButton;
//the shell used to realize this action's dialog (if any)
private Shell fShell;
/**
* The constructor for the action
* @param label the label for the action's button
*/
public SourceContainerAction(String label) {
super(label);
}
/**
* Sets the viewer on which this action operates.
*
* @param viewer the viewer on which this action operates
*/
public void setViewer(SourceContainerViewer viewer) {
if (fViewer != null) {
fViewer.removeSelectionChangedListener(this);
}
fViewer = viewer;
if (fViewer != null) {
fViewer.addSelectionChangedListener(this);
update();
}
}
/**
* Returns the viewer on which this action operates.
*
* @return the viewer on which this action operates
*/
protected SourceContainerViewer getViewer() {
return fViewer;
}
/**
* Returns the selected items in the list, in the order they are
* displayed.
*
* @return targets for an action
*/
protected List getOrderedSelection() {
List targets = new ArrayList();
List selection =
((IStructuredSelection) getViewer().getSelection()).toList();
ISourceContainer[] entries = getViewer().getEntries();
for (int i = 0; i < entries.length; i++) {
ISourceContainer target = entries[i];
if (selection.contains(target)) {
targets.add(target);
}
}
return targets;
}
/**
* Returns a list (copy) of the entries in the viewer
*/
protected List getEntriesAsList() {
ISourceContainer[] entries = getViewer().getEntries();
List list = new ArrayList(entries.length);
for (int i = 0; i < entries.length; i++) {
list.add(entries[i]);
}
return list;
}
/**
* Updates the entries to the entries in the given list
*/
protected void setEntries(List list) {
getViewer().setEntries(
(ISourceContainer[]) list.toArray(new ISourceContainer[list.size()]));
// update all selection listeners
getViewer().setSelection(getViewer().getSelection());
}
/**
* Returns whether the item at the given index in the list
* (visually) is selected.
*/
protected boolean isIndexSelected(
IStructuredSelection selection,
int index) {
if (selection.isEmpty()) {
return false;
}
Iterator entries = selection.iterator();
List list = getEntriesAsList();
while (entries.hasNext()) {
Object next = entries.next();
if (list.indexOf(next) == index) {
return true;
}
}
return false;
}
/**
* Sets the button that invokes this action
*/
public void setButton(Button button) {
fButton = button;
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent evt) {
run();
}
});
}
/**
* @see IAction#setEnabled(boolean)
*/
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
if (fButton != null) {
fButton.setEnabled(enabled);
}
}
/**
* Updates the enabled state.
*/
protected void update() {
selectionChanged((IStructuredSelection) getViewer().getSelection());
}
/**
* Returns the shell used to realize this action's dialog (if any).
*/
protected Shell getShell() {
if (fShell == null) {
fShell = getViewer().getControl().getShell();
}
return fShell;
}
/**
* Sets the shell used to realize this action's dialog (if any).
*/
public void setShell(Shell shell) {
fShell = shell;
}
}

View file

@ -0,0 +1,86 @@
/**********************************************************************
* Copyright (c) 2003, 2005 IBM Corporation 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.sourcelookup;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupUIUtils;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.model.WorkbenchLabelProvider;
/**
* Label provider for source containers and source container types.
*/
public class SourceContainerLabelProvider extends LabelProvider {
private ILabelProvider fLabelProvider = null;
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
*/
public Image getImage(Object element) {
// first allow workbench adapter to provide image
Image image = getWorkbenchLabelProvider().getImage(element);
if (image == null) {
ISourceContainerType type = null;
if (element instanceof ISourceContainer) {
type = ((ISourceContainer)element).getType();
} else if (element instanceof ISourceContainerType) {
type = (ISourceContainerType) element;
}
if (type != null) {
// next consult contributed image
image = SourceLookupUIUtils.getSourceContainerImage(type.getId());
}
}
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) {
// first, allo workbench adapter to provide label
String label = getWorkbenchLabelProvider().getText(element);
if (label == null || label.length() == 0) {
if (element instanceof ISourceContainer) {
return ((ISourceContainer) element).getName();
} else if (element instanceof ISourceContainerType) {
return ((ISourceContainerType)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();
}
}
}

View file

@ -0,0 +1,188 @@
/**********************************************************************
* 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 java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Composite;
/**
* The viewer containing the source containers.
* It is a tree viewer since the containers are represented in tree form.
*/
public class SourceContainerViewer extends TreeViewer {
/**
* Whether enabled/editable.
*/
private boolean fEnabled = true;
/**
* The source container entries displayed in this viewer
*/
protected List fEntries = new ArrayList();
class ContentProvider implements ITreeContentProvider {
/**
* @see IStructuredContentProvider#getElements(Object)
*/
public Object[] getElements(Object inputElement) {
return getEntries();
}
/**
* @see IContentProvider#dispose()
*/
public void dispose() {
}
/**
* @see IContentProvider#inputChanged(Viewer, Object, Object)
*/
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
/**
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
*/
public Object[] getChildren(Object parentElement) {
try {
return ((ISourceContainer)parentElement).getSourceContainers();
} catch (CoreException e) {
return new Object[0];
}
}
/**
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
*/
public Object getParent(Object element) {
return null;
}
/**
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
*/
public boolean hasChildren(Object element) {
return ((ISourceContainer)element).isComposite();
}
}
/**
* Creates a runtime classpath viewer with the given parent.
*
* @param parent the parent control
* @param panel the panel hosting this viewer
*/
public SourceContainerViewer(Composite parent) {
super(parent);
setContentProvider(new ContentProvider());
SourceContainerLabelProvider lp = new SourceContainerLabelProvider();
setLabelProvider(lp);
}
/**
* Sets the entries in this viewer
*
* @param entries source container entries
*/
public void setEntries(ISourceContainer[] entries) {
fEntries.clear();
for (int i = 0; i < entries.length; i++) {
if(entries[i] != null)
fEntries.add(entries[i]);
}
if (getInput() == null) {
setInput(fEntries);
//select first item in list
if(!fEntries.isEmpty() && fEntries.get(0)!=null)
setSelection(new StructuredSelection(fEntries.get(0)));
} else {
refresh();
}
}
/**
* Returns the entries in this viewer
*
* @return the entries in this viewer
*/
public ISourceContainer[] getEntries() {
return (ISourceContainer[])fEntries.toArray(new ISourceContainer[fEntries.size()]);
}
/**
* Adds the given entries to the list. If there is no selection
* in the list, the entries are added at the end of the list,
* otherwise the new entries are added before the (first) selected
* entry. The new entries are selected.
*
* @param entries additions
*/
public void addEntries(ISourceContainer[] entries) {
IStructuredSelection sel = (IStructuredSelection)getSelection();
if (sel.isEmpty()) {
for (int i = 0; i < entries.length; i++) {
if (!fEntries.contains(entries[i])) {
fEntries.add(entries[i]);
}
}
}
else {
int index = fEntries.indexOf(sel.getFirstElement());
for (int i = 0; i < entries.length; i++) {
if (!fEntries.contains(entries[i])) {
fEntries.add(index, entries[i]);
index++;
}
}
}
if(!fEntries.isEmpty() && fEntries.get(0)!=null)
setSelection(new StructuredSelection(fEntries.get(0)));
refresh();
}
/**
* Enables/disables this viewer. Note the control is not disabled, since
* we still want the user to be able to scroll if required to see the
* existing entries. Just actions should be disabled.
*/
public void setEnabled(boolean enabled) {
fEnabled = enabled;
// fire selection change to upate actions
setSelection(getSelection());
}
/**
* Returns whether this viewer is enabled
*/
public boolean isEnabled() {
return fEnabled;
}
/**
* Returns the index of an equivalent entry, or -1 if none.
*
* @return the index of an equivalent entry, or -1 if none
*/
public int indexOf(ISourceContainer entry) {
return fEntries.indexOf(entry);
}
}

View file

@ -12,6 +12,7 @@ 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.core.model.ICProject;
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;
@ -44,7 +45,9 @@ public class SourceContainerWorkbenchAdapter implements IWorkbenchAdapter {
}
if ( o instanceof ProjectSourceContainer ) {
IProject project = ((ProjectSourceContainer)o).getProject();
return getImageDescriptor( CCorePlugin.getDefault().getCoreModel().create( project ) );
ICProject cProject = CCorePlugin.getDefault().getCoreModel().create( project );
if ( cProject != null )
return getImageDescriptor( cProject );
}
return null;
}
@ -62,7 +65,7 @@ public class SourceContainerWorkbenchAdapter implements IWorkbenchAdapter {
*/
public String getLabel( Object o ) {
if ( o instanceof MappingSourceContainer ) {
return ((MappingSourceContainer)o).getName();
return SourceLookupUIMessages.getString( "SourceContainerWorkbenchAdapter.0" ) + ((MappingSourceContainer)o).getName(); //$NON-NLS-1$
}
if ( o instanceof MapEntrySourceContainer ) {
return ((MapEntrySourceContainer)o).getName();

View file

@ -0,0 +1,34 @@
/**********************************************************************
* 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 java.util.MissingResourceException;
import java.util.ResourceBundle;
public class SourceLookupUIMessages {
private static final String BUNDLE_NAME = "org.eclipse.cdt.debug.internal.ui.sourcelookup.SourceLookupUIMessages"; //$NON-NLS-1$
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( BUNDLE_NAME );
private SourceLookupUIMessages() {
}
public static String getString( String key ) {
// TODO Auto-generated method stub
try {
return RESOURCE_BUNDLE.getString( key );
}
catch( MissingResourceException e ) {
return '!' + key + '!';
}
}
}

View file

@ -0,0 +1,26 @@
AddContainerAction.0=&Add...
AddSourceContainerDialog.0=Add Source
AddSourceContainerDialog.1=Select the type of source to add to the source lookup path
DownAction.0=&Down
EditContainerAction.0=&Edit...
MappingSourceContainerBrowser.0=New Mapping
PathMappingDialog.0=Specify the mapping paths
PathMappingDialog.1=Compilation path:
PathMappingDialog.2=Local file system path:
PathMappingDialog.3=&Browse...
PathMappingDialog.4=Path Mapping
PathMappingDialog.5=The compilation path must not be empty
PathMappingDialog.6=Invalid compilation path.
PathMappingDialog.7=The local file systems path must not be empty
PathMappingDialog.8=The specified local file system path doesn't exist
PathMappingDialog.9=The local file system path must be a directory
PathMappingDialog.10=The local file system path must be absolute
PathMappingDialog.11=Modify the path mappings
PathMappingDialog.12=Name:
PathMappingDialog.13=&Add...
PathMappingDialog.14=&Edit...
PathMappingDialog.15=Re&move
PathMappingDialog.16=Path Mappings
RemoveAction.0=Re&move
SourceContainerWorkbenchAdapter.0=Path Mapping:
UpAction.0=U&p

View file

@ -0,0 +1,62 @@
/*******************************************************************************
* Copyright (c) 2003, 2005 IBM Corporation 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.sourcelookup;
import java.util.Iterator;
import java.util.List;
import org.eclipse.jface.viewers.IStructuredSelection;
/**
* The action used to move source containers up in the list
*/
public class UpAction extends SourceContainerAction {
public UpAction() {
super(SourceLookupUIMessages.getString( "UpAction.0" )); //$NON-NLS-1$
}
/**
* Moves all selected entries up one position (if possible).
*
* @see IAction#run()
*/
public void run() {
List targets = getOrderedSelection();
if (targets.isEmpty()) {
return;
}
int top = 0;
int index = 0;
List list = getEntriesAsList();
Iterator entries = targets.iterator();
while (entries.hasNext()) {
Object target = entries.next();
index = list.indexOf(target);
if (index > top) {
top = index - 1;
Object temp = list.get(top);
list.set(top, target);
list.set(index, temp);
}
top = index;
}
setEntries(list);
}
/**
* @see SelectionListenerAction#updateSelection(IStructuredSelection)
*/
protected boolean updateSelection(IStructuredSelection selection) {
//check that something is selected, it's not first in the list, and it is a root tree node.
return !selection.isEmpty() && !isIndexSelected(selection, 0) && getViewer().getTree().getSelection()[0].getParentItem()==null;
}
}

View file

@ -20,6 +20,7 @@ import org.eclipse.cdt.debug.internal.ui.ColorManager;
import org.eclipse.cdt.debug.internal.ui.EvaluationContextManager;
import org.eclipse.cdt.debug.internal.ui.IInternalCDebugUIConstants;
import org.eclipse.cdt.debug.ui.sourcelookup.DefaultSourceLocator;
import org.eclipse.cdt.debug.ui.sourcelookup.OldDefaultSourceLocator;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
@ -230,14 +231,14 @@ public class CDebugUIPlugin extends AbstractUIPlugin {
}
public static String getDefaultSourceLocatorID() {
return DefaultSourceLocator.ID_DEFAULT_SOURCE_LOCATOR;
return OldDefaultSourceLocator.ID_DEFAULT_SOURCE_LOCATOR;
}
/*
* to support old launch configurations
*/
public static String getDefaultSourceLocatorOldID() {
return DefaultSourceLocator.ID_OLD_DEFAULT_SOURCE_LOCATOR;
return OldDefaultSourceLocator.ID_OLD_DEFAULT_SOURCE_LOCATOR;
}
/*

View file

@ -10,373 +10,86 @@
***********************************************************************/
package org.eclipse.cdt.debug.ui.sourcelookup;
import java.io.IOException;
import java.io.StringReader;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import org.eclipse.cdt.core.resources.FileStorage;
import org.eclipse.cdt.debug.core.CDebugUtils;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.debug.core.model.ICStackFrame;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
import org.eclipse.cdt.debug.core.sourcelookup.SourceLookupFactory;
import org.eclipse.cdt.debug.internal.ui.CDebugImageDescriptorRegistry;
import org.eclipse.cdt.debug.internal.ui.CDebugImages;
import org.eclipse.cdt.debug.internal.ui.dialogfields.SelectionButtonDialogField;
import org.eclipse.cdt.debug.internal.ui.editors.FileNotFoundElement;
import org.eclipse.cdt.debug.internal.ui.editors.NoSymbolOrSourceElement;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.core.resources.IFile;
import org.eclipse.cdt.debug.core.sourcelookup.IProjectSourceLocation;
import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLookupDirector;
import org.eclipse.cdt.debug.internal.core.sourcelookup.SourceUtils;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.model.IPersistableSourceLocator;
import org.eclipse.debug.core.model.IStackFrame;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.ListDialog;
import org.w3c.dom.Document;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.debug.core.sourcelookup.containers.DefaultSourceContainer;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
* Default source locator.
* The replacement of the old default source locator. Used only for migration purposes.
*/
public class DefaultSourceLocator implements IPersistableSourceLocator, IAdaptable {
public class DefaultSourceLocator extends CSourceLookupDirector {
public class SourceSelectionDialog extends ListDialog {
private SelectionButtonDialogField fAlwaysUseThisFileButton = new SelectionButtonDialogField( SWT.CHECK );
public SourceSelectionDialog( Shell parent ) {
super( parent );
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.dialogs.ListDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
/* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector#initializeFromMemento(java.lang.String, org.eclipse.debug.core.ILaunchConfiguration)
*/
protected Control createDialogArea( Composite parent ) {
Composite comp = ControlFactory.createComposite( parent, 1 );
super.createDialogArea( comp );
Composite comp1 = ControlFactory.createComposite( comp, 1 );
fAlwaysUseThisFileButton.setLabelText( SourceLookupMessages.getString( "DefaultSourceLocator.0" ) ); //$NON-NLS-1$
fAlwaysUseThisFileButton.doFillIntoGrid( comp1, 1 );
return comp;
}
public boolean alwaysMapToSelection() {
return fAlwaysUseThisFileButton.isSelected();
}
}
public class SourceElementLabelProvider extends LabelProvider {
protected CDebugImageDescriptorRegistry fDebugImageRegistry = CDebugUIPlugin.getImageDescriptorRegistry();
public SourceElementLabelProvider() {
super();
}
public String getText( Object element ) {
if ( element instanceof IFile )
return ((IFile)element).getFullPath().toString();
if ( element instanceof FileStorage )
return ((FileStorage)element).getFullPath().toOSString();
return super.getText( element );
}
public Image getImage( Object element ) {
if ( element instanceof IFile )
return fDebugImageRegistry.get( CDebugImages.DESC_OBJS_WORKSPACE_SOURCE_FILE );
if ( element instanceof FileStorage )
return fDebugImageRegistry.get( CDebugImages.DESC_OBJS_EXTERNAL_SOURCE_FILE );
return super.getImage( element );
}
}
/**
* Identifier for the 'Default C/C++ Source Locator' extension (value <code>"org.eclipse.cdt.debug.ui.DefaultSourceLocator"</code>).
*/
public static final String ID_DEFAULT_SOURCE_LOCATOR = CDebugUIPlugin.getUniqueIdentifier() + ".DefaultSourceLocator"; //$NON-NLS-1$
// to support old configurations
public static final String ID_OLD_DEFAULT_SOURCE_LOCATOR = "org.eclipse.cdt.launch" + ".DefaultSourceLocator"; //$NON-NLS-1$ //$NON-NLS-2$
private static final String ELEMENT_NAME = "PromptingSourceLocator"; //$NON-NLS-1$
private static final String ATTR_PROJECT = "project"; //$NON-NLS-1$
private static final String ATTR_MEMENTO = "memento"; //$NON-NLS-1$
/**
* Underlying source locator.
*/
private ICSourceLocator fSourceLocator;
private HashMap fFramesToSource = null;
private HashMap fNamesToSource = null;
public DefaultSourceLocator() {
super();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento()
*/
public String getMemento() throws CoreException {
if ( getCSourceLocator() != null ) {
Document document = null;
Throwable ex = null;
try {
document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Element element = document.createElement( ELEMENT_NAME );
document.appendChild( element );
element.setAttribute( ATTR_PROJECT, getCSourceLocator().getProject().getName() );
IPersistableSourceLocator psl = getPersistableSourceLocator();
if ( psl != null ) {
element.setAttribute( ATTR_MEMENTO, psl.getMemento() );
}
return CDebugUtils.serializeDocument( document );
}
catch( ParserConfigurationException e ) {
ex = e;
}
catch( IOException e ) {
ex = e;
}
catch( TransformerException e ) {
ex = e;
}
abort( SourceLookupMessages.getString( "DefaultSourceLocator.1" ), ex ); //$NON-NLS-1$
}
return null;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeFromMemento(java.lang.String)
*/
public void initializeFromMemento( String memento ) throws CoreException {
Exception ex = null;
try {
Element root = null;
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
StringReader reader = new StringReader( memento );
InputSource source = new InputSource( reader );
root = parser.parse( source ).getDocumentElement();
if ( !root.getNodeName().equalsIgnoreCase( ELEMENT_NAME ) ) {
abort( SourceLookupMessages.getString( "DefaultSourceLocator.2" ), null ); //$NON-NLS-1$
}
String projectName = root.getAttribute( ATTR_PROJECT );
String data = root.getAttribute( ATTR_MEMENTO );
if ( isEmpty( projectName ) ) {
abort( SourceLookupMessages.getString( "DefaultSourceLocator.3" ), null ); //$NON-NLS-1$
}
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( projectName );
if ( getCSourceLocator() == null )
setCSourceLocator( SourceLookupFactory.createSourceLocator( project ) );
if ( getCSourceLocator().getProject() != null && !getCSourceLocator().getProject().equals( project ) )
return;
if ( project == null || !project.exists() || !project.isOpen() )
abort( MessageFormat.format( SourceLookupMessages.getString( "DefaultSourceLocator.4" ), new String[]{ projectName } ), null ); //$NON-NLS-1$
IPersistableSourceLocator psl = getPersistableSourceLocator();
if ( psl != null )
psl.initializeFromMemento( data );
else
abort( SourceLookupMessages.getString( "DefaultSourceLocator.5" ), null ); //$NON-NLS-1$
return;
}
catch( ParserConfigurationException e ) {
ex = e;
}
catch( SAXException e ) {
ex = e;
}
catch( IOException e ) {
ex = e;
}
abort( SourceLookupMessages.getString( "DefaultSourceLocator.6" ), ex ); //$NON-NLS-1$
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeDefaults(org.eclipse.debug.core.ILaunchConfiguration)
*/
public void initializeDefaults( ILaunchConfiguration configuration ) throws CoreException {
setCSourceLocator( SourceLookupFactory.createSourceLocator( getProject( configuration ) ) );
String memento = configuration.getAttribute( ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, "" ); //$NON-NLS-1$
if ( !isEmpty( memento ) )
initializeFromMemento( memento );
}
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
*/
public Object getAdapter( Class adapter ) {
if ( getCSourceLocator() instanceof IAdaptable ) {
if ( adapter.equals( ICSourceLocator.class ) ) {
return ((IAdaptable)getCSourceLocator()).getAdapter( adapter );
}
if ( adapter.equals( IResourceChangeListener.class ) ) {
return ((IAdaptable)getCSourceLocator()).getAdapter( adapter );
}
}
return null;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.ISourceLocator#getSourceElement(org.eclipse.debug.core.model.IStackFrame)
*/
public Object getSourceElement( IStackFrame stackFrame ) {
Object res = cacheLookup( stackFrame );
if ( res == null ) {
res = getCSourceLocator().getSourceElement( stackFrame );
if ( res instanceof List ) {
List list = (List)res;
if ( list.size() != 0 ) {
SourceSelectionDialog dialog = createSourceSelectionDialog( list );
dialog.open();
Object[] objs = dialog.getResult();
res = (objs != null && objs.length > 0) ? objs[0] : null;
if ( res != null )
cacheSourceElement( stackFrame, res, dialog.alwaysMapToSelection() );
}
else
res = null;
}
}
if ( res == null ) {
if ( stackFrame instanceof ICStackFrame && !isEmpty( ((ICStackFrame)stackFrame).getFile() ) ) {
res = new FileNotFoundElement( stackFrame );
}
else // don't show in editor
{
res = new NoSymbolOrSourceElement( stackFrame );
}
}
return res;
}
protected void saveChanges( ILaunchConfiguration configuration, IPersistableSourceLocator locator ) {
try {
ILaunchConfigurationWorkingCopy copy = configuration.copy( configuration.getName() );
copy.setAttribute( ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, locator.getMemento() );
copy.doSave();
}
catch( CoreException e ) {
CDebugUIPlugin.errorDialog( e.getMessage(), (IStatus)null );
}
}
private SourceSelectionDialog createSourceSelectionDialog( List list ) {
SourceSelectionDialog dialog = new SourceSelectionDialog( CDebugUIPlugin.getActiveWorkbenchShell() );
dialog.setInput( list.toArray() );
dialog.setContentProvider( new ArrayContentProvider() );
dialog.setLabelProvider( new SourceElementLabelProvider() );
dialog.setTitle( SourceLookupMessages.getString( "DefaultSourceLocator.7" ) ); //$NON-NLS-1$
dialog.setMessage( SourceLookupMessages.getString( "DefaultSourceLocator.8" ) ); //$NON-NLS-1$
dialog.setInitialSelections( new Object[]{ list.get( 0 ) } );
return dialog;
}
private void cacheSourceElement( IStackFrame frame, Object sourceElement, boolean alwaysMapToSelection ) {
if ( alwaysMapToSelection ) {
String name = getFileName( frame );
if ( name != null ) {
if ( fNamesToSource == null )
fNamesToSource = new HashMap();
fNamesToSource.put( name, sourceElement );
}
public void initializeFromMemento( String memento, ILaunchConfiguration configuration ) throws CoreException {
Element rootElement = DebugPlugin.parseDocument( memento );
if ( rootElement.getNodeName().equalsIgnoreCase( OldDefaultSourceLocator.ELEMENT_NAME ) ) {
initializeFromOldMemento( memento, configuration );
}
else {
if ( fFramesToSource == null )
fFramesToSource = new HashMap();
fFramesToSource.put( frame, sourceElement );
super.initializeFromMemento( memento, configuration );
}
}
private Object cacheLookup( IStackFrame frame ) {
String name = getFileName( frame );
if ( name != null && fNamesToSource != null ) {
Object result = fNamesToSource.get( name );
if ( result != null )
return result;
private void initializeFromOldMemento( String memento, ILaunchConfiguration configuration ) throws CoreException {
dispose();
setLaunchConfiguration( configuration );
OldDefaultSourceLocator old = new OldDefaultSourceLocator();
old.initializeFromMemento( memento );
ICSourceLocator csl = (ICSourceLocator)old.getAdapter( ICSourceLocator.class );
setFindDuplicates( csl.searchForDuplicateFiles() );
ICSourceLocation[] locations = csl.getSourceLocations();
// Check if the old source locator includes all referenced projects.
// If so, DefaultSpourceContainer should be used.
IProject project = csl.getProject();
List list = CDebugUtils.getReferencedProjects( project );
HashSet names = new HashSet( list.size() + 1 );
names.add( project.getName() );
Iterator it = list.iterator();
while( it.hasNext() ) {
names.add( ((IProject)it.next()).getName() );
}
boolean includesDefault = true;
for( int i = 0; i < locations.length; ++i ) {
if ( locations[i] instanceof IProjectSourceLocation && ((IProjectSourceLocation)locations[i]).isGeneric() ) {
if ( !names.contains( ((IProjectSourceLocation)locations[i]).getProject().getName() ) ) {
includesDefault = false;
break;
}
}
return (fFramesToSource != null) ? fFramesToSource.get( frame ) : null;
}
private String getFileName( IStackFrame frame ) {
if ( frame instanceof ICStackFrame ) {
String name = ((ICStackFrame)frame).getFile();
if ( !isEmpty( name ) )
return name.trim();
}
return null;
// Generate an array of new source containers including DefaultSourceContainer
ArrayList locs = new ArrayList( locations.length );
for ( int i = 0; i < locations.length; ++i ) {
if ( !includesDefault || !( locations[i] instanceof IProjectSourceLocation && names.contains( ((IProjectSourceLocation)locations[i]).getProject().getName() ) ) )
locs.add( locations[i] );
}
private ICSourceLocator getCSourceLocator() {
return fSourceLocator;
ISourceContainer[] containers = SourceUtils.convertSourceLocations( (ICSourceLocation[])locs.toArray( new ICSourceLocation[locs.size()] ) );
ArrayList cons = new ArrayList( Arrays.asList( containers ) );
if ( includesDefault ) {
DefaultSourceContainer defaultContainer = new DefaultSourceContainer();
defaultContainer.init( this );
cons.add( 0, defaultContainer );
}
private void setCSourceLocator( ICSourceLocator locator ) {
fSourceLocator = locator;
}
private IPersistableSourceLocator getPersistableSourceLocator() {
ICSourceLocator sl = getCSourceLocator();
return (sl instanceof IPersistableSourceLocator) ? (IPersistableSourceLocator)sl : null;
}
/**
* Throws an internal error exception
*/
private void abort( String message, Throwable e ) throws CoreException {
IStatus s = new Status( IStatus.ERROR, CDebugUIPlugin.getUniqueIdentifier(), 0, message, e );
throw new CoreException( s );
}
private boolean isEmpty( String string ) {
return string == null || string.trim().length() == 0;
}
private IProject getProject( ILaunchConfiguration configuration ) throws CoreException {
String projectName = configuration.getAttribute( ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String)null );
if ( !isEmpty( projectName ) ) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( projectName );
if ( project.exists() ) {
return project;
}
}
abort( MessageFormat.format( SourceLookupMessages.getString( "DefaultSourceLocator.9" ), new String[]{ projectName } ), null ); //$NON-NLS-1$
return null;
setSourceContainers( (ISourceContainer[])cons.toArray( new ISourceContainer[cons.size()] ) );
}
}

View file

@ -0,0 +1,382 @@
/**********************************************************************
* 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.ui.sourcelookup;
import java.io.IOException;
import java.io.StringReader;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import org.eclipse.cdt.core.resources.FileStorage;
import org.eclipse.cdt.debug.core.CDebugUtils;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.debug.core.model.ICStackFrame;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
import org.eclipse.cdt.debug.core.sourcelookup.SourceLookupFactory;
import org.eclipse.cdt.debug.internal.ui.CDebugImageDescriptorRegistry;
import org.eclipse.cdt.debug.internal.ui.CDebugImages;
import org.eclipse.cdt.debug.internal.ui.dialogfields.SelectionButtonDialogField;
import org.eclipse.cdt.debug.internal.ui.editors.FileNotFoundElement;
import org.eclipse.cdt.debug.internal.ui.editors.NoSymbolOrSourceElement;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.model.IPersistableSourceLocator;
import org.eclipse.debug.core.model.IStackFrame;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.ListDialog;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
* Old default source locator. We keep it for migration purposes.
*/
public class OldDefaultSourceLocator implements IPersistableSourceLocator, IAdaptable {
public class SourceSelectionDialog extends ListDialog {
private SelectionButtonDialogField fAlwaysUseThisFileButton = new SelectionButtonDialogField( SWT.CHECK );
public SourceSelectionDialog( Shell parent ) {
super( parent );
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.dialogs.ListDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
*/
protected Control createDialogArea( Composite parent ) {
Composite comp = ControlFactory.createComposite( parent, 1 );
super.createDialogArea( comp );
Composite comp1 = ControlFactory.createComposite( comp, 1 );
fAlwaysUseThisFileButton.setLabelText( SourceLookupMessages.getString( "OldDefaultSourceLocator.0" ) ); //$NON-NLS-1$
fAlwaysUseThisFileButton.doFillIntoGrid( comp1, 1 );
return comp;
}
public boolean alwaysMapToSelection() {
return fAlwaysUseThisFileButton.isSelected();
}
}
public class SourceElementLabelProvider extends LabelProvider {
protected CDebugImageDescriptorRegistry fDebugImageRegistry = CDebugUIPlugin.getImageDescriptorRegistry();
public SourceElementLabelProvider() {
super();
}
public String getText( Object element ) {
if ( element instanceof IFile )
return ((IFile)element).getFullPath().toString();
if ( element instanceof FileStorage )
return ((FileStorage)element).getFullPath().toOSString();
return super.getText( element );
}
public Image getImage( Object element ) {
if ( element instanceof IFile )
return fDebugImageRegistry.get( CDebugImages.DESC_OBJS_WORKSPACE_SOURCE_FILE );
if ( element instanceof FileStorage )
return fDebugImageRegistry.get( CDebugImages.DESC_OBJS_EXTERNAL_SOURCE_FILE );
return super.getImage( element );
}
}
/**
* Identifier for the 'Default C/C++ Source Locator' extension (value <code>"org.eclipse.cdt.debug.ui.DefaultSourceLocator"</code>).
*/
public static final String ID_DEFAULT_SOURCE_LOCATOR = CDebugUIPlugin.getUniqueIdentifier() + ".DefaultSourceLocator"; //$NON-NLS-1$
// to support old configurations
public static final String ID_OLD_DEFAULT_SOURCE_LOCATOR = "org.eclipse.cdt.launch" + ".DefaultSourceLocator"; //$NON-NLS-1$ //$NON-NLS-2$
protected static final String ELEMENT_NAME = "PromptingSourceLocator"; //$NON-NLS-1$
private static final String ATTR_PROJECT = "project"; //$NON-NLS-1$
private static final String ATTR_MEMENTO = "memento"; //$NON-NLS-1$
/**
* Underlying source locator.
*/
private ICSourceLocator fSourceLocator;
private HashMap fFramesToSource = null;
private HashMap fNamesToSource = null;
public OldDefaultSourceLocator() {
super();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento()
*/
public String getMemento() throws CoreException {
if ( getCSourceLocator() != null ) {
Document document = null;
Throwable ex = null;
try {
document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Element element = document.createElement( ELEMENT_NAME );
document.appendChild( element );
element.setAttribute( ATTR_PROJECT, getCSourceLocator().getProject().getName() );
IPersistableSourceLocator psl = getPersistableSourceLocator();
if ( psl != null ) {
element.setAttribute( ATTR_MEMENTO, psl.getMemento() );
}
return CDebugUtils.serializeDocument( document );
}
catch( ParserConfigurationException e ) {
ex = e;
}
catch( IOException e ) {
ex = e;
}
catch( TransformerException e ) {
ex = e;
}
abort( SourceLookupMessages.getString( "OldDefaultSourceLocator.1" ), ex ); //$NON-NLS-1$
}
return null;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeFromMemento(java.lang.String)
*/
public void initializeFromMemento( String memento ) throws CoreException {
Exception ex = null;
try {
Element root = null;
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
StringReader reader = new StringReader( memento );
InputSource source = new InputSource( reader );
root = parser.parse( source ).getDocumentElement();
if ( !root.getNodeName().equalsIgnoreCase( ELEMENT_NAME ) ) {
abort( SourceLookupMessages.getString( "OldDefaultSourceLocator.2" ), null ); //$NON-NLS-1$
}
String projectName = root.getAttribute( ATTR_PROJECT );
String data = root.getAttribute( ATTR_MEMENTO );
if ( isEmpty( projectName ) ) {
abort( SourceLookupMessages.getString( "OldDefaultSourceLocator.3" ), null ); //$NON-NLS-1$
}
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( projectName );
if ( getCSourceLocator() == null )
setCSourceLocator( SourceLookupFactory.createSourceLocator( project ) );
if ( getCSourceLocator().getProject() != null && !getCSourceLocator().getProject().equals( project ) )
return;
if ( project == null || !project.exists() || !project.isOpen() )
abort( MessageFormat.format( SourceLookupMessages.getString( "OldDefaultSourceLocator.4" ), new String[]{ projectName } ), null ); //$NON-NLS-1$
IPersistableSourceLocator psl = getPersistableSourceLocator();
if ( psl != null )
psl.initializeFromMemento( data );
else
abort( SourceLookupMessages.getString( "OldDefaultSourceLocator.5" ), null ); //$NON-NLS-1$
return;
}
catch( ParserConfigurationException e ) {
ex = e;
}
catch( SAXException e ) {
ex = e;
}
catch( IOException e ) {
ex = e;
}
abort( SourceLookupMessages.getString( "OldDefaultSourceLocator.6" ), ex ); //$NON-NLS-1$
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeDefaults(org.eclipse.debug.core.ILaunchConfiguration)
*/
public void initializeDefaults( ILaunchConfiguration configuration ) throws CoreException {
setCSourceLocator( SourceLookupFactory.createSourceLocator( getProject( configuration ) ) );
String memento = configuration.getAttribute( ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, "" ); //$NON-NLS-1$
if ( !isEmpty( memento ) )
initializeFromMemento( memento );
}
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
*/
public Object getAdapter( Class adapter ) {
if ( getCSourceLocator() instanceof IAdaptable ) {
if ( adapter.equals( ICSourceLocator.class ) ) {
return ((IAdaptable)getCSourceLocator()).getAdapter( adapter );
}
if ( adapter.equals( IResourceChangeListener.class ) ) {
return ((IAdaptable)getCSourceLocator()).getAdapter( adapter );
}
}
return null;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.debug.core.model.ISourceLocator#getSourceElement(org.eclipse.debug.core.model.IStackFrame)
*/
public Object getSourceElement( IStackFrame stackFrame ) {
Object res = cacheLookup( stackFrame );
if ( res == null ) {
res = getCSourceLocator().getSourceElement( stackFrame );
if ( res instanceof List ) {
List list = (List)res;
if ( list.size() != 0 ) {
SourceSelectionDialog dialog = createSourceSelectionDialog( list );
dialog.open();
Object[] objs = dialog.getResult();
res = (objs != null && objs.length > 0) ? objs[0] : null;
if ( res != null )
cacheSourceElement( stackFrame, res, dialog.alwaysMapToSelection() );
}
else
res = null;
}
}
if ( res == null ) {
if ( stackFrame instanceof ICStackFrame && !isEmpty( ((ICStackFrame)stackFrame).getFile() ) ) {
res = new FileNotFoundElement( stackFrame );
}
else // don't show in editor
{
res = new NoSymbolOrSourceElement( stackFrame );
}
}
return res;
}
protected void saveChanges( ILaunchConfiguration configuration, IPersistableSourceLocator locator ) {
try {
ILaunchConfigurationWorkingCopy copy = configuration.copy( configuration.getName() );
copy.setAttribute( ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, locator.getMemento() );
copy.doSave();
}
catch( CoreException e ) {
CDebugUIPlugin.errorDialog( e.getMessage(), (IStatus)null );
}
}
private SourceSelectionDialog createSourceSelectionDialog( List list ) {
SourceSelectionDialog dialog = new SourceSelectionDialog( CDebugUIPlugin.getActiveWorkbenchShell() );
dialog.setInput( list.toArray() );
dialog.setContentProvider( new ArrayContentProvider() );
dialog.setLabelProvider( new SourceElementLabelProvider() );
dialog.setTitle( SourceLookupMessages.getString( "OldDefaultSourceLocator.7" ) ); //$NON-NLS-1$
dialog.setMessage( SourceLookupMessages.getString( "OldDefaultSourceLocator.8" ) ); //$NON-NLS-1$
dialog.setInitialSelections( new Object[]{ list.get( 0 ) } );
return dialog;
}
private void cacheSourceElement( IStackFrame frame, Object sourceElement, boolean alwaysMapToSelection ) {
if ( alwaysMapToSelection ) {
String name = getFileName( frame );
if ( name != null ) {
if ( fNamesToSource == null )
fNamesToSource = new HashMap();
fNamesToSource.put( name, sourceElement );
}
}
else {
if ( fFramesToSource == null )
fFramesToSource = new HashMap();
fFramesToSource.put( frame, sourceElement );
}
}
private Object cacheLookup( IStackFrame frame ) {
String name = getFileName( frame );
if ( name != null && fNamesToSource != null ) {
Object result = fNamesToSource.get( name );
if ( result != null )
return result;
}
return (fFramesToSource != null) ? fFramesToSource.get( frame ) : null;
}
private String getFileName( IStackFrame frame ) {
if ( frame instanceof ICStackFrame ) {
String name = ((ICStackFrame)frame).getFile();
if ( !isEmpty( name ) )
return name.trim();
}
return null;
}
private ICSourceLocator getCSourceLocator() {
return fSourceLocator;
}
private void setCSourceLocator( ICSourceLocator locator ) {
fSourceLocator = locator;
}
private IPersistableSourceLocator getPersistableSourceLocator() {
ICSourceLocator sl = getCSourceLocator();
return (sl instanceof IPersistableSourceLocator) ? (IPersistableSourceLocator)sl : null;
}
/**
* Throws an internal error exception
*/
private void abort( String message, Throwable e ) throws CoreException {
IStatus s = new Status( IStatus.ERROR, CDebugUIPlugin.getUniqueIdentifier(), 0, message, e );
throw new CoreException( s );
}
private boolean isEmpty( String string ) {
return string == null || string.trim().length() == 0;
}
private IProject getProject( ILaunchConfiguration configuration ) throws CoreException {
String projectName = configuration.getAttribute( ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String)null );
if ( !isEmpty( projectName ) ) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( projectName );
if ( project.exists() ) {
return project;
}
}
abort( MessageFormat.format( SourceLookupMessages.getString( "OldDefaultSourceLocator.9" ), new String[]{ projectName } ), null ); //$NON-NLS-1$
return null;
}
}

View file

@ -1,3 +1,10 @@
2005-04-21 Mikhail Khodjaiants
Bug 80175: Replace the CDT source lookup by the source lookup provided by Eclipse platform.
* CoreFileLaunchConfigurationTabGroup.java
* LocalAttachLaunchConfigurationTabGroup.java
* LocalRunLaunchConfigurationTabGroup.java
* plugin.xml
2005-04-07 David Daoust
Update icons

View file

@ -32,25 +32,31 @@
<extension
point="org.eclipse.debug.core.launchConfigurationTypes">
<launchConfigurationType
name="%LocalCDTLaunch.name"
sourceLocatorId="org.eclipse.cdt.debug.core.sourceLocator"
delegate="org.eclipse.cdt.launch.internal.LocalRunLaunchDelegate"
modes="run,debug"
public="true"
id="org.eclipse.cdt.launch.localCLaunch">
sourcePathComputerId="org.eclipse.cdt.debug.core.sourcePathComputer"
name="%LocalCDTLaunch.name"
id="org.eclipse.cdt.launch.localCLaunch"
modes="run,debug">
</launchConfigurationType>
<launchConfigurationType
name="%LocalAttachCDTLaunch.name"
delegate="org.eclipse.cdt.launch.internal.LocalAttachLaunchDelegate"
id="org.eclipse.cdt.launch.localAttachCLaunch"
modes="debug"
name="%LocalAttachCDTLaunch.name"
public="true"
id="org.eclipse.cdt.launch.localAttachCLaunch">
sourceLocatorId="org.eclipse.cdt.debug.core.sourceLocator"
sourcePathComputerId="org.eclipse.cdt.debug.core.sourcePathComputer">
</launchConfigurationType>
<launchConfigurationType
name="%CoreFileCDTLaunch.name"
delegate="org.eclipse.cdt.launch.internal.CoreFileLaunchDelegate"
id="org.eclipse.cdt.launch.coreFileCLaunch"
modes="debug"
name="%CoreFileCDTLaunch.name"
public="true"
id="org.eclipse.cdt.launch.coreFileCLaunch">
sourceLocatorId="org.eclipse.cdt.debug.core.sourceLocator"
sourcePathComputerId="org.eclipse.cdt.debug.core.sourcePathComputer">
</launchConfigurationType>
</extension>
<extension

View file

@ -12,13 +12,13 @@ package org.eclipse.cdt.launch.internal.ui;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.launch.ui.CMainTab;
import org.eclipse.cdt.launch.ui.CSourceLookupTab;
import org.eclipse.cdt.launch.ui.CoreFileDebuggerTab;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
import org.eclipse.debug.ui.CommonTab;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.debug.ui.sourcelookup.SourceLookupTab;
public class CoreFileLaunchConfigurationTabGroup extends AbstractLaunchConfigurationTabGroup {
@ -29,7 +29,8 @@ public class CoreFileLaunchConfigurationTabGroup extends AbstractLaunchConfigura
ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
new CMainTab(),
new CoreFileDebuggerTab(),
new CSourceLookupTab(),
// new CSourceLookupTab(),
new SourceLookupTab(),
new CommonTab()
};
setTabs(tabs);

View file

@ -12,11 +12,11 @@ package org.eclipse.cdt.launch.internal.ui;
import org.eclipse.cdt.launch.ui.CDebuggerTab;
import org.eclipse.cdt.launch.ui.CMainTab;
import org.eclipse.cdt.launch.ui.CSourceLookupTab;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
import org.eclipse.debug.ui.CommonTab;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.debug.ui.sourcelookup.SourceLookupTab;
public class LocalAttachLaunchConfigurationTabGroup extends AbstractLaunchConfigurationTabGroup {
@ -27,7 +27,8 @@ public class LocalAttachLaunchConfigurationTabGroup extends AbstractLaunchConfig
ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
new CMainTab(),
new CDebuggerTab(true),
new CSourceLookupTab(),
// new CSourceLookupTab(),
new SourceLookupTab(),
new CommonTab()
};
setTabs(tabs);

View file

@ -13,11 +13,11 @@ package org.eclipse.cdt.launch.internal.ui;
import org.eclipse.cdt.launch.ui.CArgumentsTab;
import org.eclipse.cdt.launch.ui.CDebuggerTab;
import org.eclipse.cdt.launch.ui.CMainTab;
import org.eclipse.cdt.launch.ui.CSourceLookupTab;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
import org.eclipse.debug.ui.CommonTab;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.debug.ui.sourcelookup.SourceLookupTab;
public class LocalRunLaunchConfigurationTabGroup extends AbstractLaunchConfigurationTabGroup {
@ -30,7 +30,8 @@ public class LocalRunLaunchConfigurationTabGroup extends AbstractLaunchConfigura
new CArgumentsTab(),
new MigratingCEnvironmentTab(),
new CDebuggerTab(false),
new CSourceLookupTab(),
// new CSourceLookupTab(),
new SourceLookupTab(),
new CommonTab()
};
setTabs(tabs);