diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog
index b02d7be1f5d..6de525b42a5 100644
--- a/debug/org.eclipse.cdt.debug.core/ChangeLog
+++ b/debug/org.eclipse.cdt.debug.core/ChangeLog
@@ -1,3 +1,15 @@
+2003-07-17 Mikhail Khodjaiants
+ Automatically update the list of source locations when the list of the referenced
+ projects is modified.
+ * ICSourceLocator.java: added new method - 'getProject'
+ * IProjectSourceLocation.java: added new method - 'isGeneric'
+ * SourceLocationFactory.java: new class factory for source locations.
+ * CSourceLocator.java
+ * CDirectorySourceLocation.java
+ * CProjectSourceLocation.java
+ * CSourceManager.java
+ * CDebugTarget.java
+
2003-06-30 Mikhail Khodjaiants
Fix for PR 39372: Breakpoints don't get activated when symbols are loaded.
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocator.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocator.java
index ecc60cf9311..5630c38a04b 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocator.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/ICSourceLocator.java
@@ -5,6 +5,7 @@
*/
package org.eclipse.cdt.debug.core.sourcelookup;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.debug.core.model.ISourceLocator;
import org.eclipse.debug.core.model.IStackFrame;
@@ -18,6 +19,13 @@ import org.eclipse.debug.core.model.IStackFrame;
*/
public interface ICSourceLocator extends ISourceLocator
{
+ /**
+ * Returns the project this source locator is associated with or null
.
+ *
+ * @return project this source locator is associated with or null
+ */
+ IProject getProject();
+
/**
* Returns the line number of the instruction pointer in the specified
* stack frame that corresponds to a line in an associated source element,
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/IProjectSourceLocation.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/IProjectSourceLocation.java
index c91914598de..ddb9ed278fb 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/IProjectSourceLocation.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/IProjectSourceLocation.java
@@ -16,4 +16,6 @@ import org.eclipse.core.resources.IProject;
public interface IProjectSourceLocation extends ICSourceLocation
{
IProject getProject();
+
+ boolean isGeneric();
}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/SourceLocationFactory.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/SourceLocationFactory.java
new file mode 100644
index 00000000000..84784e55aea
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/SourceLocationFactory.java
@@ -0,0 +1,40 @@
+/*
+ *(c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ *
+ */
+
+package org.eclipse.cdt.debug.core.sourcelookup;
+
+import org.eclipse.cdt.debug.internal.core.sourcelookup.CDirectorySourceLocation;
+import org.eclipse.cdt.debug.internal.core.sourcelookup.CProjectSourceLocation;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+
+/**
+ * Enter type comment.
+ *
+ * @since Jul 14, 2003
+ */
+public class SourceLocationFactory
+{
+ public static IProjectSourceLocation createProjectSourceLocation( IProject project )
+ {
+ return new CProjectSourceLocation( project );
+ }
+
+ public static IProjectSourceLocation createProjectSourceLocation( IProject project, boolean generated )
+ {
+ return new CProjectSourceLocation( project, generated );
+ }
+
+ public static IDirectorySourceLocation createDirectorySourceLocation( IPath directory )
+ {
+ return new CDirectorySourceLocation( directory );
+ }
+
+ public static IDirectorySourceLocation createDirectorySourceLocation( IPath directory, IPath association )
+ {
+ return new CDirectorySourceLocation( directory, association );
+ }
+}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java
index a26c42164c9..c194fd77f7a 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java
@@ -87,6 +87,7 @@ import org.eclipse.cdt.debug.internal.core.sourcelookup.DisassemblyManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarkerDelta;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
@@ -303,6 +304,7 @@ public class CDebugTarget extends CDebugElement
initializeBreakpoints();
initializeRegisters();
initializeMemoryManager();
+ initializeSourceManager();
getLaunch().addDebugTarget( this );
fireCreationEvent();
}
@@ -398,6 +400,17 @@ public class CDebugTarget extends CDebugElement
fMemoryManager = new CMemoryManager( this );
}
+ protected void initializeSourceManager()
+ {
+ ISourceLocator locator = getLaunch().getSourceLocator();
+ if ( locator instanceof IAdaptable )
+ {
+ IResourceChangeListener listener = (IResourceChangeListener)((IAdaptable)locator).getAdapter( IResourceChangeListener.class );
+ if ( listener != null )
+ CCorePlugin.getWorkspace().addResourceChangeListener( listener );
+ }
+ }
+
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IDebugTarget#getProcess()
*/
@@ -1183,6 +1196,7 @@ public class CDebugTarget extends CDebugElement
disposeSignalManager();
disposeRegisterManager();
disposeDisassemblyManager();
+ disposeSourceManager();
removeAllExpressions();
try
{
@@ -2575,4 +2589,15 @@ public class CDebugTarget extends CDebugElement
{
return getRegisterManager().getRegisterGroups();
}
+
+ protected void disposeSourceManager()
+ {
+ ISourceLocator locator = getSourceLocator();
+ if ( locator instanceof IAdaptable )
+ {
+ IResourceChangeListener listener = (IResourceChangeListener)((IAdaptable)locator).getAdapter( IResourceChangeListener.class );
+ if ( listener != null )
+ CCorePlugin.getWorkspace().removeResourceChangeListener( listener );
+ }
+ }
}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java
index d1668d7d34b..97dd196419c 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CDirectorySourceLocation.java
@@ -307,4 +307,27 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
{
return string == null || string.length() == 0;
}
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals( Object obj )
+ {
+ if ( obj instanceof IDirectorySourceLocation )
+ {
+ IPath dir = ((IDirectorySourceLocation)obj).getDirectory();
+ IPath association = ((IDirectorySourceLocation)obj).getAssociation();
+ if ( dir == null )
+ return false;
+ boolean result = dir.equals( getDirectory() );
+ if ( result )
+ {
+ if ( association == null && getAssociation() == null )
+ return true;
+ if ( association != null )
+ return association.equals( getAssociation() );
+ }
+ }
+ return false;
+ }
}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CProjectSourceLocation.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CProjectSourceLocation.java
index d05ee9beb45..145e9b7cfa3 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CProjectSourceLocation.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CProjectSourceLocation.java
@@ -47,6 +47,7 @@ public class CProjectSourceLocation implements IProjectSourceLocation
{
private static final String ELEMENT_NAME = "cProjectSourceLocation";
private static final String ATTR_PROJECT = "project";
+ private static final String ATTR_GENERIC = "generic";
/**
* The project associated with this source location
@@ -57,6 +58,8 @@ public class CProjectSourceLocation implements IProjectSourceLocation
private HashSet fNotFoundCache = new HashSet( 20 );
+ private boolean fGenerated = true;
+
/**
* Constructor for CProjectSourceLocation.
*/
@@ -70,6 +73,16 @@ public class CProjectSourceLocation implements IProjectSourceLocation
public CProjectSourceLocation( IProject project )
{
setProject( project );
+ fGenerated = true;
+ }
+
+ /**
+ * Constructor for CProjectSourceLocation.
+ */
+ public CProjectSourceLocation( IProject project, boolean generated )
+ {
+ setProject( project );
+ fGenerated = generated;
}
/* (non-Javadoc)
@@ -240,7 +253,7 @@ public class CProjectSourceLocation implements IProjectSourceLocation
Element node = doc.createElement( ELEMENT_NAME );
doc.appendChild( node );
node.setAttribute( ATTR_PROJECT, getProject().getName() );
-
+ node.setAttribute( ATTR_GENERIC, new Boolean( isGeneric() ).toString() );
try
{
return CDebugUtils.serializeDocument( doc, " " );
@@ -277,6 +290,10 @@ public class CProjectSourceLocation implements IProjectSourceLocation
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( name );
setProject( project );
}
+ String isGeneric = root.getAttribute( ATTR_GENERIC );
+ if ( isGeneric == null || isGeneric.trim().length() == 0 )
+ isGeneric = Boolean.FALSE.toString();
+ setGenerated( isGeneric.equals( Boolean.TRUE.toString() ) );
return;
}
catch( ParserConfigurationException e )
@@ -311,4 +328,27 @@ public class CProjectSourceLocation implements IProjectSourceLocation
{
return string == null || string.length() == 0;
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.core.sourcelookup.IProjectSourceLocation#isGenerated()
+ */
+ public boolean isGeneric()
+ {
+ return fGenerated;
+ }
+
+ public void setGenerated( boolean b )
+ {
+ fGenerated = b;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals( Object obj )
+ {
+ if ( obj instanceof IProjectSourceLocation )
+ return getProject().getName().equals( ((IProjectSourceLocation)obj).getProject().getName() );
+ return false;
+ }
}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.java
index 9c09773f252..099348f886b 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLocator.java
@@ -10,6 +10,8 @@ import java.io.IOException;
import java.io.StringReader;
import java.text.MessageFormat;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -20,14 +22,19 @@ import javax.xml.parsers.ParserConfigurationException;
import org.apache.xerces.dom.DocumentImpl;
import org.eclipse.cdt.core.resources.FileStorage;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
-import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.debug.core.model.IStackFrameInfo;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
+import org.eclipse.cdt.debug.core.sourcelookup.IProjectSourceLocation;
+import org.eclipse.cdt.debug.core.sourcelookup.SourceLocationFactory;
import org.eclipse.cdt.debug.internal.core.CDebugUtils;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
@@ -50,12 +57,20 @@ import org.xml.sax.SAXException;
* @since Aug 19, 2002
*/
-public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocator
+public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocator, IResourceChangeListener
{
- private static final String ELEMENT_NAME = "cSourceLocator";
- private static final String CHILD_NAME = "cSourceLocation";
+ private static final String SOURCE_LOCATOR_NAME = "cSourceLocator";
+ private static final String DISABLED_GENERIC_PROJECT_NAME = "disabledGenericProject";
+ private static final String ADDITIONAL_SOURCE_LOCATION_NAME = "additionalSourceLocation";
+ private static final String SOURCE_LOCATION_NAME = "cSourceLocation";
private static final String ATTR_CLASS = "class";
private static final String ATTR_MEMENTO = "memento";
+ private static final String ATTR_PROJECT_NAME = "projectName";
+
+ /**
+ * The project associated with this locator.
+ */
+ private IProject fProject = null;
/**
* The array of source locations associated with this locator.
@@ -63,27 +78,17 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
private ICSourceLocation[] fSourceLocations;
/**
- * Constructor for CSourceLocator.
+ * The array of projects referenced by main project.
*/
- public CSourceLocator()
- {
- setSourceLocations( new ICSourceLocation[0] );
- }
+ private List fReferencedProjects = new ArrayList( 10 );
/**
* Constructor for CSourceLocator.
*/
public CSourceLocator( IProject project )
{
- fSourceLocations = getDefaultSourceLocations( project );
- }
-
- /**
- * Constructor for CSourceLocator.
- */
- public CSourceLocator( ICSourceLocation[] locations )
- {
- fSourceLocations = locations;
+ setProject( project );
+ setReferencedProjects();
}
/* (non-Javadoc)
@@ -200,7 +205,7 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
ArrayList list = new ArrayList();
if ( project != null && project.exists() )
{
- list.add( new CProjectSourceLocation( project ) );
+ list.add( SourceLocationFactory.createProjectSourceLocation( project ) );
addReferencedSourceLocations( list, project );
}
return (ICSourceLocation[])list.toArray( new ICSourceLocation[list.size()] );
@@ -217,7 +222,7 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
{
if ( projects[i].exists() && !containsProject( list, projects[i] ) )
{
- list.add( new CProjectSourceLocation( projects[i] ) );
+ list.add( SourceLocationFactory.createProjectSourceLocation( projects[i] ) );
addReferencedSourceLocations( list, projects[i] );
}
}
@@ -293,17 +298,13 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
public String getMemento() throws CoreException
{
Document doc = new DocumentImpl();
- Element node = doc.createElement( ELEMENT_NAME );
+ Element node = doc.createElement( SOURCE_LOCATOR_NAME );
doc.appendChild( node );
ICSourceLocation[] locations = getSourceLocations();
- for ( int i = 0; i < locations.length; i++ )
- {
- Element child = doc.createElement( CHILD_NAME );
- child.setAttribute( ATTR_CLASS, locations[i].getClass().getName() );
- child.setAttribute( ATTR_MEMENTO, locations[i].getMemento() );
- node.appendChild( child );
- }
+ saveDisabledGenericSourceLocations( locations, doc, node );
+ saveAdditionalSourceLocations( locations, doc, node );
+
try
{
return CDebugUtils.serializeDocument( doc, " " );
@@ -321,15 +322,7 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
*/
public void initializeDefaults( ILaunchConfiguration configuration ) throws CoreException
{
- IProject project = getProject( configuration );
- if ( project != null )
- {
- setSourceLocations( getDefaultSourceLocations( project ) );
- }
- else
- {
- setSourceLocations( new ICSourceLocation[0] );
- }
+ setSourceLocations( getDefaultSourceLocations() );
}
/* (non-Javadoc)
@@ -346,63 +339,22 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
InputSource source = new InputSource( reader );
root = parser.parse( source ).getDocumentElement();
- if ( !root.getNodeName().equalsIgnoreCase( ELEMENT_NAME ) )
+ if ( !root.getNodeName().equalsIgnoreCase( SOURCE_LOCATOR_NAME ) )
{
abort( "Unable to restore C/C++ source locator - invalid format.", null );
}
List sourceLocations = new ArrayList();
- ClassLoader classLoader = CDebugCorePlugin.getDefault() .getDescriptor().getPluginClassLoader();
+
+ // Add locations based on referenced projects
+ IProject project = getProject();
+ if ( project != null && project.exists() && project.isOpen() )
+ sourceLocations.addAll( Arrays.asList( getDefaultSourceLocations() ) );
- NodeList list = root.getChildNodes();
- int length = list.getLength();
- for ( int i = 0; i < length; ++i )
- {
- Node node = list.item( i );
- short type = node.getNodeType();
- if ( type == Node.ELEMENT_NODE )
- {
- Element entry = (Element)node;
- if ( entry.getNodeName().equalsIgnoreCase( CHILD_NAME ) )
- {
- String className = entry.getAttribute( ATTR_CLASS );
- String data = entry.getAttribute( ATTR_MEMENTO );
- if ( isEmpty( className ) )
- {
- abort( "Unable to restore C/C++ source locator - invalid format.", null );
- }
- Class clazz = null;
- try
- {
- clazz = classLoader.loadClass( className );
- }
- catch( ClassNotFoundException e )
- {
- abort( MessageFormat.format( "Unable to restore source location - class not found {0}", new String[] { className } ), e );
- }
-
- ICSourceLocation location = null;
- try
- {
- location = (ICSourceLocation)clazz.newInstance();
- }
- catch( IllegalAccessException e )
- {
- abort( "Unable to restore source location.", e );
- }
- catch( InstantiationException e )
- {
- abort( "Unable to restore source location.", e );
- }
- location.initializeFrom( data );
- sourceLocations.add( location );
- }
- else
- {
- abort( "Unable to restore C/C++ source locator - invalid format.", null );
- }
- }
- }
+ removeDisabledLocations( root, sourceLocations );
+ addAdditionalLocations( root, sourceLocations );
+ // To support old launch configuration
+ addOldLocations( root, sourceLocations );
setSourceLocations( (ICSourceLocation[])sourceLocations.toArray( new ICSourceLocation[sourceLocations.size()] ) );
return;
}
@@ -421,6 +373,154 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
abort( "Exception occurred initializing source locator.", ex );
}
+ private void removeDisabledLocations( Element root, List sourceLocations ) throws CoreException
+ {
+ NodeList list = root.getChildNodes();
+ int length = list.getLength();
+ HashSet disabledProjects = new HashSet( length );
+ for ( int i = 0; i < length; ++i )
+ {
+ Node node = list.item( i );
+ short type = node.getNodeType();
+ if ( type == Node.ELEMENT_NODE )
+ {
+ Element entry = (Element)node;
+ if ( entry.getNodeName().equalsIgnoreCase( DISABLED_GENERIC_PROJECT_NAME ) )
+ {
+ String projectName = entry.getAttribute( ATTR_PROJECT_NAME );
+ if ( isEmpty( projectName ) )
+ {
+ CDebugCorePlugin.log( "Unable to restore C/C++ source locator - invalid format." );
+ }
+ disabledProjects.add( projectName.trim() );
+ }
+ }
+ }
+ Iterator it = sourceLocations.iterator();
+ while( it.hasNext() )
+ {
+ ICSourceLocation location = (ICSourceLocation)it.next();
+ if ( location instanceof IProjectSourceLocation &&
+ disabledProjects.contains( ((IProjectSourceLocation)location).getProject().getName() ) )
+ it.remove();
+ }
+ }
+
+ private void addAdditionalLocations( Element root, List sourceLocations ) throws CoreException
+ {
+ ClassLoader classLoader = CDebugCorePlugin.getDefault() .getDescriptor().getPluginClassLoader();
+
+ NodeList list = root.getChildNodes();
+ int length = list.getLength();
+ for ( int i = 0; i < length; ++i )
+ {
+ Node node = list.item( i );
+ short type = node.getNodeType();
+ if ( type == Node.ELEMENT_NODE )
+ {
+ Element entry = (Element)node;
+ if ( entry.getNodeName().equalsIgnoreCase( ADDITIONAL_SOURCE_LOCATION_NAME ) )
+ {
+ String className = entry.getAttribute( ATTR_CLASS );
+ String data = entry.getAttribute( ATTR_MEMENTO );
+ if ( isEmpty( className ) )
+ {
+ CDebugCorePlugin.log( "Unable to restore C/C++ source locator - invalid format." );
+ continue;
+ }
+ Class clazz = null;
+ try
+ {
+ clazz = classLoader.loadClass( className );
+ }
+ catch( ClassNotFoundException e )
+ {
+ CDebugCorePlugin.log( MessageFormat.format( "Unable to restore source location - class not found {0}", new String[] { className } ) );
+ continue;
+ }
+
+ ICSourceLocation location = null;
+ try
+ {
+ location = (ICSourceLocation)clazz.newInstance();
+ }
+ catch( IllegalAccessException e )
+ {
+ CDebugCorePlugin.log( "Unable to restore source location." );
+ continue;
+ }
+ catch( InstantiationException e )
+ {
+ CDebugCorePlugin.log( "Unable to restore source location." );
+ continue;
+ }
+ location.initializeFrom( data );
+ sourceLocations.add( location );
+ }
+ }
+ }
+ }
+
+ private void addOldLocations( Element root, List sourceLocations ) throws CoreException
+ {
+ ClassLoader classLoader = CDebugCorePlugin.getDefault() .getDescriptor().getPluginClassLoader();
+
+ NodeList list = root.getChildNodes();
+ int length = list.getLength();
+ for ( int i = 0; i < length; ++i )
+ {
+ Node node = list.item( i );
+ short type = node.getNodeType();
+ if ( type == Node.ELEMENT_NODE )
+ {
+ Element entry = (Element)node;
+ if ( entry.getNodeName().equalsIgnoreCase( SOURCE_LOCATION_NAME ) )
+ {
+ String className = entry.getAttribute( ATTR_CLASS );
+ String data = entry.getAttribute( ATTR_MEMENTO );
+ if ( isEmpty( className ) )
+ {
+ CDebugCorePlugin.log( "Unable to restore C/C++ source locator - invalid format." );
+ continue;
+ }
+ Class clazz = null;
+ try
+ {
+ clazz = classLoader.loadClass( className );
+ }
+ catch( ClassNotFoundException e )
+ {
+ CDebugCorePlugin.log( MessageFormat.format( "Unable to restore source location - class not found {0}", new String[] { className } ) );
+ continue;
+ }
+
+ ICSourceLocation location = null;
+ try
+ {
+ location = (ICSourceLocation)clazz.newInstance();
+ }
+ catch( IllegalAccessException e )
+ {
+ CDebugCorePlugin.log( "Unable to restore source location." );
+ continue;
+ }
+ catch( InstantiationException e )
+ {
+ CDebugCorePlugin.log( "Unable to restore source location." );
+ continue;
+ }
+ location.initializeFrom( data );
+ if ( !sourceLocations.contains( location ) )
+ {
+ if ( location instanceof CProjectSourceLocation )
+ ((CProjectSourceLocation)location).setGenerated( isReferencedProject( ((CProjectSourceLocation)location).getProject() ) );
+ sourceLocations.add( location );
+ }
+ }
+ }
+ }
+ }
+
/**
* Throws an internal error exception
*/
@@ -437,21 +537,209 @@ public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocato
private boolean isEmpty( String string )
{
- return string == null || string.length() == 0;
+ return string == null || string.trim().length() == 0;
}
- private IProject getProject( ILaunchConfiguration configuration )
+ public void resourceChanged( IResourceChangeEvent event )
{
- IProject project = null;
- try
+ if ( event.getSource() instanceof IWorkspace && event.getDelta() != null )
{
- String projectName = configuration.getAttribute( ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, "" );
- if ( !isEmpty( projectName ) )
- project = ResourcesPlugin.getWorkspace().getRoot().getProject( projectName );
+ IResourceDelta[] deltas = event.getDelta().getAffectedChildren();
+ if ( deltas != null )
+ {
+ ArrayList list = new ArrayList( deltas.length );
+ for ( int i = 0; i < deltas.length; ++i )
+ if ( deltas[i].getResource() instanceof IProject )
+ list.add( deltas[i].getResource() );
+ resetSourceLocations( list );
+ }
}
- catch( CoreException e )
+ }
+
+ private void saveDisabledGenericSourceLocations( ICSourceLocation[] locations, Document doc, Element node )
+ {
+ IProject project = getProject();
+ if ( project != null && project.exists() && project.isOpen() )
{
+ try
+ {
+ IProject[] refs = project.getReferencedProjects();
+ HashSet names = new HashSet( refs.length + 1 );
+ names.add( project.getName() );
+ for ( int i = 0; i < refs.length; ++i )
+ {
+ names.add( refs[i].getName() );
+ }
+ for ( int i = 0; i < locations.length; ++i )
+ if ( locations[i] instanceof IProjectSourceLocation &&
+ ((IProjectSourceLocation)locations[i]).isGeneric() )
+ names.remove( ((IProjectSourceLocation)locations[i]).getProject().getName() );
+
+ Iterator it = names.iterator();
+ while ( it.hasNext() )
+ {
+ Element child = doc.createElement( DISABLED_GENERIC_PROJECT_NAME );
+ child.setAttribute( ATTR_PROJECT_NAME, (String)it.next() );
+ node.appendChild( child );
+ }
+ }
+ catch( CoreException e )
+ {
+ CDebugCorePlugin.log( e );
+ }
}
- return project;
+ }
+
+ private void saveAdditionalSourceLocations( ICSourceLocation[] locations, Document doc, Element node )
+ {
+ for ( int i = 0; i < locations.length; i++ )
+ {
+ if ( locations[i] instanceof IProjectSourceLocation &&
+ ((IProjectSourceLocation)locations[i]).isGeneric() )
+ continue;
+ Element child = doc.createElement( SOURCE_LOCATION_NAME );
+ child.setAttribute( ATTR_CLASS, locations[i].getClass().getName() );
+ try
+ {
+ child.setAttribute( ATTR_MEMENTO, locations[i].getMemento() );
+ }
+ catch( CoreException e )
+ {
+ CDebugCorePlugin.log( e );
+ continue;
+ }
+ node.appendChild( child );
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#getProject()
+ */
+ public IProject getProject()
+ {
+ return fProject;
+ }
+
+ protected void setProject( IProject project )
+ {
+ fProject = project;
+ }
+
+ private boolean isReferencedProject( IProject ref )
+ {
+ if ( getProject() != null )
+ {
+ try
+ {
+ return Arrays.asList( getProject().getReferencedProjects() ).contains( ref );
+ }
+ catch( CoreException e )
+ {
+ CDebugCorePlugin.log( e );
+ }
+ }
+ return false;
+ }
+
+ private void setReferencedProjects()
+ {
+ fReferencedProjects.clear();
+ fReferencedProjects = getReferencedProjects( getProject() );
+ }
+
+ private List getReferencedProjects( IProject project )
+ {
+ ArrayList list = new ArrayList( 10 );
+ if ( project != null && project.exists() && project.isOpen() )
+ {
+ IProject[] refs = new IProject[0];
+ try
+ {
+ refs = project.getReferencedProjects();
+ }
+ catch( CoreException e )
+ {
+ }
+ list.addAll( Arrays.asList( refs ) );
+ for ( int i = 0; i < refs.length; ++i )
+ list.addAll( getReferencedProjects( refs[i] ) );
+ }
+ return list;
+ }
+
+ protected ICSourceLocation[] getDefaultSourceLocations()
+ {
+ Iterator it = fReferencedProjects.iterator();
+ ArrayList list = new ArrayList( fReferencedProjects.size() );
+ if ( getProject() != null && getProject().exists() && getProject().isOpen() )
+ list.add( SourceLocationFactory.createProjectSourceLocation( getProject() ) );
+ while( it.hasNext() )
+ {
+ IProject project = (IProject)it.next();
+ if ( project != null && project.exists() && project.isOpen() )
+ list.add( SourceLocationFactory.createProjectSourceLocation( project ) );
+ }
+ return (ICSourceLocation[])list.toArray( new ICSourceLocation[list.size()] );
+ }
+
+ private void resetSourceLocations( List affectedProjects )
+ {
+ if ( affectedProjects.size() != 0 && getProject() != null )
+ {
+ if ( !getProject().exists() || !getProject().isOpen() )
+ {
+ removeGenericSourceLocations();
+ }
+ else
+ {
+ updateGenericSourceLocations( affectedProjects );
+ }
+ }
+ }
+
+ private void removeGenericSourceLocations()
+ {
+ fReferencedProjects.clear();
+ ICSourceLocation[] locations = getSourceLocations();
+ ArrayList newLocations = new ArrayList( locations.length );
+ for ( int i = 0; i < locations.length; ++i )
+ if ( !(locations[i] instanceof IProjectSourceLocation) || !((IProjectSourceLocation)locations[i]).isGeneric() )
+ newLocations.add( locations[i] );
+ setSourceLocations( (ICSourceLocation[])newLocations.toArray( new ICSourceLocation[newLocations.size()] ) );
+ }
+
+ private void updateGenericSourceLocations( List affectedProjects )
+ {
+ List newRefs = getReferencedProjects( getProject() );
+ ICSourceLocation[] locations = getSourceLocations();
+ ArrayList newLocations = new ArrayList( locations.length );
+ for ( int i = 0; i < locations.length; ++i )
+ {
+ if ( !(locations[i] instanceof IProjectSourceLocation) || !((IProjectSourceLocation)locations[i]).isGeneric() )
+ {
+ newLocations.add( locations[i] );
+ }
+ else
+ {
+ IProject project = ((IProjectSourceLocation)locations[i]).getProject();
+ if ( project.exists() && project.isOpen() )
+ {
+ if ( newRefs.contains( project ) || project.equals( getProject() ) )
+ {
+ newLocations.add( locations[i] );
+ newRefs.remove( project );
+ }
+ }
+ }
+ }
+ Iterator it = newRefs.iterator();
+ while( it.hasNext() )
+ {
+ IProject project = (IProject)it.next();
+ if ( !fReferencedProjects.contains( project ) )
+ newLocations.add( SourceLocationFactory.createProjectSourceLocation( project ) );
+ }
+ fReferencedProjects = newRefs;
+ setSourceLocations( (ICSourceLocation[])newLocations.toArray( new ICSourceLocation[newLocations.size()] ) );
}
}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java
index 6215da470f8..626b8cb2b04 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java
@@ -15,7 +15,9 @@ import org.eclipse.cdt.debug.core.model.IStackFrameInfo;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
import org.eclipse.cdt.debug.core.sourcelookup.ISourceMode;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.ILaunch;
@@ -130,6 +132,9 @@ public class CSourceManager implements ICSourceLocator,
*/
public Object getAdapter( Class adapter )
{
+ if ( adapter.equals( IResourceChangeListener.class ) &&
+ fSourceLocator instanceof IResourceChangeListener )
+ return fSourceLocator;
return null;
}
@@ -243,4 +248,12 @@ public class CSourceManager implements ICSourceLocator,
return (IPersistableSourceLocator)fSourceLocator;
return null;
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#getProject()
+ */
+ public IProject getProject()
+ {
+ return ( getCSourceLocator() != null ) ? getCSourceLocator().getProject() : null;
+ }
}
diff --git a/debug/org.eclipse.cdt.debug.ui/ChangeLog b/debug/org.eclipse.cdt.debug.ui/ChangeLog
index 5dcf2956fc9..fc8776a52fb 100644
--- a/debug/org.eclipse.cdt.debug.ui/ChangeLog
+++ b/debug/org.eclipse.cdt.debug.ui/ChangeLog
@@ -1,3 +1,12 @@
+2003-07-17 Mikhail Khodjaiants
+ Automatically update the list of source locations when the list of the referenced
+ projects is modified.
+ * CheckedListDialogField.java
+ * AddDirectorySourceLocationBlock.java
+ * AddProjectSourceLocationBlock.java
+ * CUISourceLocator.java
+ * SourceLookupBlock.java
+
2003-06-29 Mikhail Khodjaiants
Fix for PR 39101: No hilight when changing the value of register.
* RegistersView.java
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/dialogfields/CheckedListDialogField.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/dialogfields/CheckedListDialogField.java
index daae5f18c37..59440a41a85 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/dialogfields/CheckedListDialogField.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/dialogfields/CheckedListDialogField.java
@@ -141,8 +141,15 @@ public class CheckedListDialogField extends ListDialogField {
* Sets the checked state of an element. no dialog changed listener informed
*/
public void setCheckedWithoutUpdate(Object object, boolean state) {
- if (!fCheckElements.contains(object)) {
- fCheckElements.add(object);
+ if (state) {
+ if (!fCheckElements.contains(object)) {
+ fCheckElements.add(object);
+ }
+ }
+ else {
+ if (fCheckElements.contains(object)) {
+ fCheckElements.remove(object);
+ }
}
if (fTable != null) {
((CheckboxTableViewer)fTable).setChecked(object, state);
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/wizards/AddDirectorySourceLocationBlock.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/wizards/AddDirectorySourceLocationBlock.java
index 407ca610e65..ceb31e91fa6 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/wizards/AddDirectorySourceLocationBlock.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/wizards/AddDirectorySourceLocationBlock.java
@@ -6,7 +6,7 @@
package org.eclipse.cdt.debug.internal.ui.wizards;
import org.eclipse.cdt.debug.core.sourcelookup.IDirectorySourceLocation;
-import org.eclipse.cdt.debug.internal.core.sourcelookup.CDirectorySourceLocation;
+import org.eclipse.cdt.debug.core.sourcelookup.SourceLocationFactory;
import org.eclipse.cdt.debug.internal.ui.PixelConverter;
import org.eclipse.cdt.debug.internal.ui.SWTUtil;
import org.eclipse.core.runtime.IPath;
@@ -177,7 +177,7 @@ public class AddDirectorySourceLocationBlock
if ( isLocationPathValid() )
{
Path association = ( isAssociationPathValid() ) ? new Path( getAssociationPath() ) : null;
- return new CDirectorySourceLocation( new Path( getLocationPath() ), association );
+ return SourceLocationFactory.createDirectorySourceLocation( new Path( getLocationPath() ), association );
}
return null;
}
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/wizards/AddProjectSourceLocationBlock.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/wizards/AddProjectSourceLocationBlock.java
index 7bb6a90f74e..12eac3c738f 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/wizards/AddProjectSourceLocationBlock.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/wizards/AddProjectSourceLocationBlock.java
@@ -6,7 +6,7 @@
package org.eclipse.cdt.debug.internal.ui.wizards;
import org.eclipse.cdt.debug.core.sourcelookup.IProjectSourceLocation;
-import org.eclipse.cdt.debug.internal.core.sourcelookup.CProjectSourceLocation;
+import org.eclipse.cdt.debug.core.sourcelookup.SourceLocationFactory;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.IDoubleClickListener;
@@ -92,7 +92,7 @@ public class AddProjectSourceLocationBlock
{
if ( !((IStructuredSelection)fViewer.getSelection()).isEmpty() )
{
- return new CProjectSourceLocation( (IProject)((IStructuredSelection)fViewer.getSelection()).getFirstElement() );
+ return SourceLocationFactory.createProjectSourceLocation( (IProject)((IStructuredSelection)fViewer.getSelection()).getFirstElement(), false );
}
}
return null;
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/sourcelookup/CUISourceLocator.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/sourcelookup/CUISourceLocator.java
index 158f970113d..f927acd352a 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/sourcelookup/CUISourceLocator.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/sourcelookup/CUISourceLocator.java
@@ -16,6 +16,7 @@ import org.eclipse.cdt.debug.internal.ui.wizards.AddDirectorySourceLocationWizar
import org.eclipse.cdt.debug.internal.ui.wizards.AddSourceLocationWizard;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
@@ -121,6 +122,8 @@ public class CUISourceLocator implements IAdaptable
{
if ( adapter.equals( ICSourceLocator.class ) )
return fSourceLocator;
+ if ( adapter.equals( IResourceChangeListener.class ) && fSourceLocator instanceof IAdaptable )
+ return ((IAdaptable)fSourceLocator).getAdapter( IResourceChangeListener.class );
if ( adapter.equals( ISourceMode.class ) )
return fSourceLocator;
}
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/sourcelookup/SourceLookupBlock.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/sourcelookup/SourceLookupBlock.java
index 053989cba50..fcc6bde6cc4 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/sourcelookup/SourceLookupBlock.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/sourcelookup/SourceLookupBlock.java
@@ -5,28 +5,39 @@
*/
package org.eclipse.cdt.debug.ui.sourcelookup;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
import org.eclipse.cdt.debug.core.sourcelookup.IDirectorySourceLocation;
import org.eclipse.cdt.debug.core.sourcelookup.IProjectSourceLocation;
+import org.eclipse.cdt.debug.core.sourcelookup.SourceLocationFactory;
import org.eclipse.cdt.debug.internal.core.sourcelookup.CDirectorySourceLocation;
import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLocator;
import org.eclipse.cdt.debug.internal.ui.CDebugImages;
import org.eclipse.cdt.debug.internal.ui.PixelConverter;
+import org.eclipse.cdt.debug.internal.ui.dialogfields.CheckedListDialogField;
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.ListDialogField;
+import org.eclipse.cdt.debug.internal.ui.dialogfields.Separator;
import org.eclipse.cdt.debug.internal.ui.wizards.AddSourceLocationWizard;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.ICellModifier;
+import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
@@ -95,19 +106,6 @@ public class SourceLookupBlock
}
}
- private class SourceLookupAdapter implements IListAdapter
- {
- public void customButtonPressed( DialogField field, int index )
- {
- doButtonPressed( index );
- }
-
- public void selectionChanged( DialogField field )
- {
- doSelectionChanged();
- }
- }
-
private static class SourceLookupLabelProvider extends LabelProvider implements ITableLabelProvider
{
public Image getColumnImage( Object element, int columnIndex )
@@ -156,7 +154,9 @@ public class SourceLookupBlock
private Composite fControl = null;
private Shell fShell = null;
- private SourceListDialogField fSourceListField;
+ private CheckedListDialogField fGeneratedSourceListField;
+ private SourceListDialogField fAddedSourceListField;
+// private SelectionButtonDialogField fSearchForDuplicateFiles;
private ILaunchConfigurationDialog fLaunchConfigurationDialog = null;
private boolean fIsDirty = false;
private ICSourceLocator fLocator = null;
@@ -167,7 +167,13 @@ public class SourceLookupBlock
*/
public SourceLookupBlock()
{
- String[] buttonLabels = new String[]
+ String[] generatedSourceButtonLabels = new String[]
+ {
+ /* 0 */ "Select All",
+ /* 1 */ "Deselect All",
+ };
+
+ String[] addedSourceButtonLabels = new String[]
{
/* 0 */ "Add...",
/* 1 */ null,
@@ -175,17 +181,55 @@ public class SourceLookupBlock
/* 3 */ "Down",
/* 4 */ null,
/* 5 */ "Remove",
- /* 6 */ null,
- /* 7 */ "Restore Defaults",
};
- SourceLookupAdapter adapter = new SourceLookupAdapter();
+ IListAdapter generatedSourceAdapter = new IListAdapter()
+ {
+ public void customButtonPressed( DialogField field, int index )
+ {
+ doGeneratedSourceButtonPressed( index );
+ }
+
+ public void selectionChanged( DialogField field )
+ {
+ doGeneratedSourceSelectionChanged();
+ }
+ };
- fSourceListField = new SourceListDialogField( adapter, buttonLabels, new SourceLookupLabelProvider() );
- fSourceListField.setLabelText( "Source Locations" );
- fSourceListField.setUpButtonIndex( 2 );
- fSourceListField.setDownButtonIndex( 3 );
- fSourceListField.setRemoveButtonIndex( 5 );
+ fGeneratedSourceListField = new CheckedListDialogField( generatedSourceAdapter, generatedSourceButtonLabels, new SourceLookupLabelProvider() );
+ fGeneratedSourceListField.setLabelText( "Generic Source Locations" );
+ fGeneratedSourceListField.setCheckAllButtonIndex( 0 );
+ fGeneratedSourceListField.setUncheckAllButtonIndex( 1 );
+ fGeneratedSourceListField.setDialogFieldListener( new IDialogFieldListener()
+ {
+ public void dialogFieldChanged( DialogField field )
+ {
+ doCheckStateChanged();
+ }
+
+ } );
+ IListAdapter addedSourceAdapter = new IListAdapter()
+ {
+ public void customButtonPressed( DialogField field, int index )
+ {
+ doAddedSourceButtonPressed( index );
+ }
+
+ public void selectionChanged( DialogField field )
+ {
+ doAddedSourceSelectionChanged();
+ }
+ };
+
+ fAddedSourceListField = new SourceListDialogField( addedSourceAdapter, addedSourceButtonLabels, new SourceLookupLabelProvider() );
+ fAddedSourceListField.setLabelText( "Additional Source Locations" );
+ fAddedSourceListField.setUpButtonIndex( 2 );
+ fAddedSourceListField.setDownButtonIndex( 3 );
+ fAddedSourceListField.setRemoveButtonIndex( 5 );
+/*
+ fSearchForDuplicateFiles = new SelectionButtonDialogField( SWT.CHECK );
+ fSearchForDuplicateFiles.setLabelText( "Search for duplicate files" );
+*/
}
public void createControl( Composite parent )
@@ -202,17 +246,38 @@ public class SourceLookupBlock
PixelConverter converter = new PixelConverter( fControl );
- fSourceListField.doFillIntoGrid( fControl, 3 );
- LayoutUtil.setHorizontalSpan( fSourceListField.getLabelControl( null ), 2 );
- LayoutUtil.setWidthHint( fSourceListField.getLabelControl( null ), converter.convertWidthInCharsToPixels( 40 ) );
- LayoutUtil.setHorizontalGrabbing( fSourceListField.getListControl( null ) );
+ fGeneratedSourceListField.doFillIntoGrid( fControl, 3 );
+ LayoutUtil.setHorizontalSpan( fGeneratedSourceListField.getLabelControl( null ), 2 );
+ LayoutUtil.setWidthHint( fGeneratedSourceListField.getLabelControl( null ), converter.convertWidthInCharsToPixels( 40 ) );
+ LayoutUtil.setHorizontalGrabbing( fGeneratedSourceListField.getListControl( null ) );
+ ((CheckboxTableViewer)fGeneratedSourceListField.getTableViewer()).
+ addCheckStateListener( new ICheckStateListener()
+ {
+ public void checkStateChanged( CheckStateChangedEvent event )
+ {
+ if ( event.getElement() instanceof IProjectSourceLocation )
+ doCheckStateChanged();
+ }
+
+ } );
- TableViewer viewer = fSourceListField.getTableViewer();
+ new Separator().doFillIntoGrid( fControl, 3, converter.convertHeightInCharsToPixels( 1 ) );
+
+ fAddedSourceListField.doFillIntoGrid( fControl, 3 );
+ LayoutUtil.setHorizontalSpan( fAddedSourceListField.getLabelControl( null ), 2 );
+ LayoutUtil.setWidthHint( fAddedSourceListField.getLabelControl( null ), converter.convertWidthInCharsToPixels( 40 ) );
+ LayoutUtil.setHorizontalGrabbing( fAddedSourceListField.getListControl( null ) );
+
+ TableViewer viewer = fAddedSourceListField.getTableViewer();
Table table = viewer.getTable();
CellEditor cellEditor = new TextCellEditor( table );
viewer.setCellEditors( new CellEditor[]{ null, cellEditor } );
viewer.setColumnProperties( new String[]{ CP_LOCATION, CP_ASSOCIATION } );
viewer.setCellModifier( createCellModifier() );
+
+ new Separator().doFillIntoGrid( fControl, 3, converter.convertHeightInCharsToPixels( 1 ) );
+
+// fSearchForDuplicateFiles.doFillIntoGrid( fControl, 3 );
}
private ICellModifier createCellModifier()
@@ -245,7 +310,7 @@ public class SourceLookupBlock
if ( association.isValidPath( (String)value ) )
{
((CDirectorySourceLocation)entry).setAssociation( association );
- getSourceListField().refresh();
+ getAddedSourceListField().refresh();
updateLaunchConfigurationDialog();
}
}
@@ -261,22 +326,61 @@ public class SourceLookupBlock
public void initialize( ICSourceLocator locator )
{
fLocator = locator;
- ICSourceLocation[] locations = new ICSourceLocation[0];
if ( fLocator != null )
- locations = fLocator.getSourceLocations();
- resetLocations( locations );
+ {
+ ICSourceLocation[] locations = fLocator.getSourceLocations();
+ initializeGeneratedLocations( fLocator.getProject(), locations );
+ resetAdditionalLocations( locations );
+ }
}
- private void resetLocations( ICSourceLocation[] locations )
+ private void initializeGeneratedLocations( IProject project, ICSourceLocation[] locations )
{
- fSourceListField.removeAllElements();
- for ( int i = 0; i < locations.length; ++i )
+ fGeneratedSourceListField.removeAllElements();
+ if ( project == null && project.exists() && project.isOpen() )
+ return;
+ List list = getReferencedProjects( project );
+ IProject[] refs = (IProject[])list.toArray( new IProject[list.size()] );
+ ICSourceLocation loc = getLocationForProject( project, locations );
+ boolean checked = ( loc != null );
+ if ( loc == null )
+ loc = SourceLocationFactory.createProjectSourceLocation( project, true );
+ fGeneratedSourceListField.addElement( loc );
+ fGeneratedSourceListField.setChecked( loc, checked );
+
+ for ( int i = 0; i < refs.length; ++i )
{
- fSourceListField.addElement( locations[i] );
+ loc = getLocationForProject( refs[i], locations );
+ checked = ( loc != null );
+ if ( loc == null )
+ loc = SourceLocationFactory.createProjectSourceLocation( refs[i], true );
+ fGeneratedSourceListField.addElement( loc );
+ fGeneratedSourceListField.setChecked( loc, checked );
}
}
- protected void doButtonPressed( int index )
+ private void resetGeneratedLocations( ICSourceLocation[] locations )
+ {
+ fGeneratedSourceListField.checkAll( false );
+ for ( int i = 0; i < locations.length; ++i )
+ {
+ if ( locations[i] instanceof IProjectSourceLocation &&
+ ((IProjectSourceLocation)locations[i]).isGeneric() )
+ fGeneratedSourceListField.setChecked( locations[i], true );
+ }
+ }
+
+ private void resetAdditionalLocations( ICSourceLocation[] locations )
+ {
+ fAddedSourceListField.removeAllElements();
+ for ( int i = 0; i < locations.length; ++i )
+ {
+ if ( !( locations[i] instanceof IProjectSourceLocation ) || !((IProjectSourceLocation)locations[i]).isGeneric() )
+ fAddedSourceListField.addElement( locations[i] );
+ }
+ }
+
+ protected void doAddedSourceButtonPressed( int index )
{
switch( index )
{
@@ -284,11 +388,9 @@ public class SourceLookupBlock
if ( addSourceLocation() )
fIsDirty = true;
break;
- case 7:
- restoreDefaults();
- case 2:
- case 3:
- case 5:
+ case 2: // Up
+ case 3: // Down
+ case 5: // Remove
fIsDirty = true;
break;
}
@@ -296,13 +398,45 @@ public class SourceLookupBlock
updateLaunchConfigurationDialog();
}
- protected void doSelectionChanged()
+ protected void doAddedSourceSelectionChanged()
+ {
+ }
+
+ protected void doCheckStateChanged()
+ {
+ fIsDirty = true;
+ updateLaunchConfigurationDialog();
+ }
+
+ protected void doGeneratedSourceButtonPressed( int index )
+ {
+ switch( index )
+ {
+ case 0: // Select All
+ case 1: // Deselect All
+ fIsDirty = true;
+ break;
+ }
+ if ( isDirty() )
+ updateLaunchConfigurationDialog();
+ }
+
+ protected void doGeneratedSourceSelectionChanged()
{
}
public ICSourceLocation[] getSourceLocations()
{
- return (ICSourceLocation[])fSourceListField.getElements().toArray( new ICSourceLocation[fSourceListField.getElements().size()] );
+ ArrayList list = new ArrayList( getGeneratedSourceListField().getElements().size() + getAddedSourceListField().getElements().size() );
+ Iterator it = getGeneratedSourceListField().getElements().iterator();
+ while( it.hasNext() )
+ {
+ IProjectSourceLocation location = (IProjectSourceLocation)it.next();
+ if ( getGeneratedSourceListField().isChecked( location ) )
+ list.add( location );
+ }
+ list.addAll( getAddedSourceListField().getElements() );
+ return (ICSourceLocation[])list.toArray( new ICSourceLocation[list.size()] );
}
private boolean addSourceLocation()
@@ -311,7 +445,7 @@ public class SourceLookupBlock
WizardDialog dialog = new WizardDialog( fControl.getShell(), wizard );
if ( dialog.open() == Window.OK )
{
- fSourceListField.addElement( wizard.getSourceLocation() );
+ fAddedSourceListField.addElement( wizard.getSourceLocation() );
return true;
}
return false;
@@ -344,7 +478,7 @@ public class SourceLookupBlock
protected Object getSelection()
{
- List list = fSourceListField.getSelectedElements();
+ List list = fAddedSourceListField.getSelectedElements();
return ( list.size() > 0 ) ? list.get( 0 ) : null;
}
@@ -353,7 +487,8 @@ public class SourceLookupBlock
ICSourceLocation[] locations = new ICSourceLocation[0];
if ( getProject() != null )
locations = CSourceLocator.getDefaultSourceLocations( getProject() );
- resetLocations( locations );
+ resetGeneratedLocations( locations );
+ resetAdditionalLocations( locations );
}
public IProject getProject()
@@ -366,8 +501,42 @@ public class SourceLookupBlock
fProject = project;
}
- public SourceListDialogField getSourceListField()
+ public SourceListDialogField getAddedSourceListField()
{
- return fSourceListField;
+ return fAddedSourceListField;
+ }
+
+ public CheckedListDialogField getGeneratedSourceListField()
+ {
+ return fGeneratedSourceListField;
+ }
+
+ private ICSourceLocation getLocationForProject( IProject project, ICSourceLocation[] locations )
+ {
+ for ( int i = 0; i < locations.length; ++i )
+ if ( locations[i] instanceof IProjectSourceLocation &&
+ project.equals( ((IProjectSourceLocation)locations[i]).getProject() ) )
+ return locations[i];
+ return null;
+ }
+
+ private List getReferencedProjects( IProject project )
+ {
+ ArrayList list = new ArrayList( 10 );
+ if ( project != null && project.exists() && project.isOpen() )
+ {
+ IProject[] refs = new IProject[0];
+ try
+ {
+ refs = project.getReferencedProjects();
+ }
+ catch( CoreException e )
+ {
+ }
+ list.addAll( Arrays.asList( refs ) );
+ for ( int i = 0; i < refs.length; ++i )
+ list.addAll( getReferencedProjects( refs[i] ) );
+ }
+ return list;
}
}