1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

new source locator ui pages

This commit is contained in:
David Inglis 2003-02-18 20:53:39 +00:00
parent 92119895bc
commit 03dea5e8ec
9 changed files with 301 additions and 5 deletions

View file

@ -9,6 +9,7 @@
<classpathentry kind="src" path="/org.eclipse.cdt.ui"/>
<classpathentry kind="src" path="/org.eclipse.cdt.debug.core"/>
<classpathentry kind="src" path="/org.eclipse.cdt.debug.ui"/>
<classpathentry kind="src" path="/org.apache.xerces"/>
<classpathentry kind="src" path="/org.eclipse.core.runtime"/>
<classpathentry kind="src" path="/org.eclipse.core.boot"/>
<classpathentry kind="var" path="JRE_LIB" rootpath="JRE_SRCROOT" sourcepath="JRE_SRC"/>

View file

@ -3,6 +3,7 @@
<name>org.eclipse.cdt.launch</name>
<comment></comment>
<projects>
<project>org.apache.xerces</project>
<project>org.eclipse.cdt.core</project>
<project>org.eclipse.cdt.debug.core</project>
<project>org.eclipse.cdt.debug.ui</project>

View file

@ -1,3 +1,17 @@
2003-02-18 Mikhail Khodjaiants
New 'Source Lookup' tab.
* plugin.xml
Added dependency on the 'org.apache.xerces' plugin and the 'sourceLocator' extension.
* plugin.properties
Name for the source locator.
* CoreFileCLaunchConfigurationTabGroup.java
* LocalCLaunchConfigurationTabGroup.java
Added the 'Source Lookup' tab.
* DefaultSourceLocator.java
Implementation of 'IPersistableSourceLocator'.
* CSourceLookupTab.java
Implementation of 'ILaunchConfiguartionTab'.
2003-02-07 David Inglis
Refactor LaunchConstants into debug.core and make setting source locator happen before

View file

@ -13,3 +13,5 @@ providerName=Eclipse.org
LocalCDTLaunch.name= C/C++ Local
CoreFileCDTLaunch.name= C/C++ Post-mortem debugger
DefaultSourceLocator.name=Default C/C++ Source Locator

View file

@ -20,6 +20,7 @@
<import plugin="org.eclipse.cdt.ui"/>
<import plugin="org.eclipse.cdt.debug.core"/>
<import plugin="org.eclipse.cdt.debug.ui"/>
<import plugin="org.apache.xerces"/>
</requires>
@ -82,5 +83,13 @@
</perspective>
</shortcut>
</extension>
<extension
point="org.eclipse.debug.core.sourceLocators">
<sourceLocator
name="%DefaultSourceLocator.name"
class="org.eclipse.cdt.launch.sourcelookup.DefaultSourceLocator"
id="org.eclipse.cdt.launch.DefaultSourceLocator">
</sourceLocator>
</extension>
</plugin>

View file

@ -2,6 +2,7 @@ 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;
@ -23,6 +24,7 @@ public class CoreFileCLaunchConfigurationTabGroup extends AbstractLaunchConfigur
ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
new CMainTab(),
new CorefileDebuggerTab(),
new CSourceLookupTab(),
new CommonTab()
};
setTabs(tabs);

View file

@ -4,6 +4,7 @@ import org.eclipse.cdt.launch.ui.CArgumentsTab;
import org.eclipse.cdt.launch.ui.CDebuggerTab;
import org.eclipse.cdt.launch.ui.CEnvironmentTab;
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;
@ -25,6 +26,7 @@ public class LocalCLaunchConfigurationTabGroup extends AbstractLaunchConfigurati
new CArgumentsTab(),
new CEnvironmentTab(),
new CDebuggerTab(),
new CSourceLookupTab(),
new CommonTab()
};
setTabs(tabs);

View file

@ -5,11 +5,19 @@
*/
package org.eclipse.cdt.launch.sourcelookup;
import java.io.IOException;
import java.io.StringReader;
import java.text.MessageFormat;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.xerces.dom.DocumentImpl;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
import org.eclipse.cdt.debug.core.sourcelookup.ISourceMode;
import org.eclipse.cdt.debug.internal.core.CDebugUtils;
import org.eclipse.cdt.debug.ui.sourcelookup.CUISourceLocator;
import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
import org.eclipse.core.resources.IProject;
@ -21,6 +29,10 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.model.IPersistableSourceLocator;
import org.eclipse.debug.core.model.IStackFrame;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
* The wrapper for the CUISourceLocator class.
@ -29,6 +41,10 @@ import org.eclipse.debug.core.model.IStackFrame;
*/
public class DefaultSourceLocator implements IPersistableSourceLocator, IAdaptable
{
private static final String ELEMENT_NAME = "PromptingSourceLocator";
private static final String ATTR_PROJECT = "project";
private static final String ATTR_MEMENTO = "memento";
/**
* Identifier for the 'Default C/C++ Source Locator' extension
* (value <code>"org.eclipse.cdt.launch.DefaultSourceLocator"</code>).
@ -45,11 +61,40 @@ public class DefaultSourceLocator implements IPersistableSourceLocator, IAdaptab
{
}
/**
* Constructor for DefaultSourceLocator.
*/
public DefaultSourceLocator( CUISourceLocator locator )
{
fSourceLocator = locator;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento()
*/
public String getMemento() throws CoreException
{
if ( fSourceLocator != null )
{
Document doc = new DocumentImpl();
Element node = doc.createElement( ELEMENT_NAME );
doc.appendChild( node );
node.setAttribute( ATTR_PROJECT, fSourceLocator.getProject().getName() );
IPersistableSourceLocator psl = getPersistableSourceLocator();
if ( psl != null )
{
node.setAttribute( ATTR_MEMENTO, psl.getMemento() );
}
try
{
return CDebugUtils.serializeDocument( doc, " " );
}
catch( IOException e )
{
abort( "Unable to create memento for C/C++ source locator.", e );
}
}
return null;
}
@ -58,6 +103,60 @@ public class DefaultSourceLocator implements IPersistableSourceLocator, IAdaptab
*/
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( "Unable to restore prompting source locator - invalid format.", null );
}
String projectName = root.getAttribute( ATTR_PROJECT );
String data = root.getAttribute( ATTR_MEMENTO );
if ( isEmpty( projectName ) )
{
abort( "Unable to restore prompting source locator - invalid format.", null );
}
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( projectName );
if ( project != null )
{
fSourceLocator = new CUISourceLocator( project );
}
else
{
abort( MessageFormat.format( "Unable to restore prompting source locator - project {0} not found.", new String[] { projectName } ), null );
}
IPersistableSourceLocator psl = getPersistableSourceLocator();
if ( psl != null )
{
psl.initializeFromMemento( data );
}
else
{
abort( "Unable to restore C/C++ source locator - invalid format.", null );
}
return;
}
catch( ParserConfigurationException e )
{
ex = e;
}
catch( SAXException e )
{
ex = e;
}
catch( IOException e )
{
ex = e;
}
abort( "Exception occurred initializing source locator.", ex );
}
/* (non-Javadoc)
@ -87,11 +186,8 @@ public class DefaultSourceLocator implements IPersistableSourceLocator, IAdaptab
return project;
}
}
throw new CoreException( new Status( IStatus.ERROR,
LaunchUIPlugin.getUniqueIdentifier(),
ERROR,
MessageFormat.format( "Project \"{0}\" does not exist.", new String[] { projectName } ),
null ) );
abort( MessageFormat.format( "Project \"{0}\" does not exist.", new String[] { projectName } ), null );
return null;
}
/* (non-Javadoc)
@ -112,4 +208,38 @@ public class DefaultSourceLocator implements IPersistableSourceLocator, IAdaptab
}
return null;
}
private ICSourceLocator getCSourceLocator()
{
if ( fSourceLocator != null )
{
return (ICSourceLocator)fSourceLocator.getAdapter( ICSourceLocator.class );
}
return null;
}
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,
LaunchUIPlugin.getUniqueIdentifier(),
ERROR,
message,
e );
throw new CoreException( s );
}
private boolean isEmpty( String string )
{
return string == null || string.length() == 0;
}
}

View file

@ -0,0 +1,135 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.launch.ui;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.cdt.debug.ui.sourcelookup.SourceLookupBlock;
import org.eclipse.cdt.launch.sourcelookup.DefaultSourceLocator;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.swt.widgets.Composite;
/**
* Enter type comment.
*
* @since: Feb 13, 2003
*/
public class CSourceLookupTab extends CLaunchConfigurationTab
{
private SourceLookupBlock fBlock = null;
/* (non-Javadoc)
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
*/
public void createControl( Composite parent )
{
fBlock = new SourceLookupBlock();
fBlock.createControl( parent );
fBlock.setLaunchConfigurationDialog( getLaunchConfigurationDialog() );
setControl( fBlock.getControl() );
}
/* (non-Javadoc)
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
*/
public void setDefaults( ILaunchConfigurationWorkingCopy configuration )
{
configuration.setAttribute( ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, DefaultSourceLocator.ID_DEFAULT_SOURCE_LOCATOR );
DefaultSourceLocator locator = new DefaultSourceLocator();
try
{
locator.initializeDefaults( configuration );
configuration.setAttribute( ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, locator.getMemento() );
}
catch( CoreException e )
{
CDebugUIPlugin.log( e.getStatus() );
}
}
/* (non-Javadoc)
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
*/
public void initializeFrom( ILaunchConfiguration configuration )
{
try
{
String id = configuration.getAttribute( ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, "" );
if ( isEmpty( id )|| DefaultSourceLocator.ID_DEFAULT_SOURCE_LOCATOR.equals( id ) )
{
DefaultSourceLocator locator = new DefaultSourceLocator();
String memento = configuration.getAttribute( ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, "" );
if ( !isEmpty( memento ) )
{
locator.initializeFromMemento( memento );
}
else
{
locator.initializeDefaults( configuration );
}
ICSourceLocator clocator = (ICSourceLocator)locator.getAdapter( ICSourceLocator.class );
if ( clocator != null )
fBlock.initialize( clocator.getSourceLocations() );
}
}
catch( CoreException e )
{
}
}
/* (non-Javadoc)
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
*/
public void performApply( ILaunchConfigurationWorkingCopy configuration )
{
DefaultSourceLocator locator = new DefaultSourceLocator();
try
{
locator.initializeDefaults( configuration );
ICSourceLocator clocator = (ICSourceLocator)locator.getAdapter( ICSourceLocator.class );
if ( clocator != null )
clocator.setSourceLocations( fBlock.getSourceLocations() );
configuration.setAttribute( ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, DefaultSourceLocator.ID_DEFAULT_SOURCE_LOCATOR );
configuration.setAttribute( ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, locator.getMemento() );
}
catch( CoreException e )
{
}
}
/* (non-Javadoc)
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
*/
public String getName()
{
return "Source Lookup";
}
private IProject getProject( ILaunchConfiguration configuration )
{
IProject project = null;
try
{
String projectName = configuration.getAttribute( ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, "" );
if ( !isEmpty( projectName ) )
project = ResourcesPlugin.getWorkspace().getRoot().getProject( projectName );
}
catch( CoreException e )
{
}
return project;
}
private boolean isEmpty( String string )
{
return string == null || string.length() == 0;
}
}