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

Implementing the 'Source Lookup' property page.

This commit is contained in:
Mikhail Khodjaiants 2002-12-20 22:30:00 +00:00
parent 776735b2af
commit 8b55c57001
7 changed files with 271 additions and 30 deletions

View file

@ -1,3 +1,11 @@
2002-12-19 Mikhail Khodjaiants
Implementing the 'Source Lookup' property page.
* AddSourceLocationWizard.java
* SourceLookupBlock.java
* SourcePropertyPage.java
icons/full/obj16/project_obj.gif
icons/full/obj16/folder_obj.gif
2002-12-19 Mikhail Khodjaiants
Added the 'org.eclipse.cdt.debug.internal.ui.dialogfields' package.

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 B

View file

@ -61,6 +61,8 @@ public class CDebugImages
public static final String IMG_OBJS_REGISTER_GROUP = NAME_PREFIX + "registergroup_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_REGISTER = NAME_PREFIX + "register_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_DISASSEMBLY = NAME_PREFIX + "disassembly_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_PROJECT = NAME_PREFIX + "project_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_FOLDER = NAME_PREFIX + "folder_obj.gif"; //$NON-NLS-1$
public static final String IMG_LCL_TYPE_NAMES = NAME_PREFIX + "tnames_co.gif"; //$NON-NLS-1$
public static final String IMG_LCL_CHANGE_REGISTER_VALUE = NAME_PREFIX + "change_reg_value_co.gif"; //$NON-NLS-1$
@ -97,6 +99,8 @@ public class CDebugImages
public static final ImageDescriptor DESC_OBJS_REGISTER_GROUP = createManaged( T_OBJ, IMG_OBJS_REGISTER_GROUP );
public static final ImageDescriptor DESC_OBJS_REGISTER = createManaged( T_OBJ, IMG_OBJS_REGISTER );
public static final ImageDescriptor DESC_OBJS_DISASSEMBLY = createManaged( T_OBJ, IMG_OBJS_DISASSEMBLY );
public static final ImageDescriptor DESC_OBJS_PROJECT = createManaged( T_OBJ, IMG_OBJS_PROJECT );
public static final ImageDescriptor DESC_OBJS_FOLDER = createManaged( T_OBJ, IMG_OBJS_FOLDER );
/**
* Returns the image managed under the given key in this registry.

View file

@ -0,0 +1,66 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.internal.ui.wizards;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardSelectionPage;
import org.eclipse.swt.widgets.Composite;
/**
* Enter type comment.
*
* @since: Dec 20, 2002
*/
public class AddSourceLocationWizard extends Wizard
{
/**
* Enter type comment.
*
* @since: Dec 20, 2002
*/
public class SourceLocationSelectionPage extends WizardSelectionPage
{
/**
* Constructor for SourceLocationSelectionPage.
* @param pageName
*/
public SourceLocationSelectionPage( String pageName )
{
super( pageName );
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(Composite)
*/
public void createControl( Composite parent )
{
}
}
/**
* Constructor for AddSourceLocationWizard.
*/
public AddSourceLocationWizard()
{
super();
}
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.IWizard#performFinish()
*/
public boolean performFinish()
{
return false;
}
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.Wizard#addPages()
*/
public void addPages()
{
addPage( new SourceLocationSelectionPage( "Add Source Location" ) );
}
}

View file

@ -5,11 +5,21 @@
*/
package org.eclipse.cdt.debug.ui.sourcelookup;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
import org.eclipse.cdt.debug.internal.core.sourcelookup.CDirectorySourceLocation;
import org.eclipse.cdt.debug.internal.core.sourcelookup.CProjectSourceLocation;
import org.eclipse.cdt.debug.internal.ui.CDebugImages;
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.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.wizards.AddSourceLocationWizard;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
@ -24,62 +34,136 @@ import org.eclipse.swt.widgets.Shell;
*/
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
{
public String getText( Object element )
{
if ( element instanceof CProjectSourceLocation )
{
return ((CProjectSourceLocation)element).getProject().getName();
}
if ( element instanceof CDirectorySourceLocation )
{
return ((CDirectorySourceLocation)element).getDirectory().toOSString();
}
return null;
}
public Image getImage( Object element )
{
if ( element instanceof CProjectSourceLocation )
{
return CDebugImages.get( CDebugImages.IMG_OBJS_PROJECT );
}
if ( element instanceof CDirectorySourceLocation )
{
return CDebugImages.get( CDebugImages.IMG_OBJS_FOLDER );
}
return null;
}
}
private Composite fControl = null;
private Shell fShell = null;
private FontMetrics fFontMetrics = null;
private ListDialogField fSourceListField;
/**
* Constructor for SourceLookupBlock.
*/
public SourceLookupBlock()
{
super();
String[] buttonLabels = new String[]
{
/* 0 */ "Add...",
/* 1 */ "Edit...",
/* 2 */ null,
/* 3 */ "Up",
/* 4 */ "Down",
/* 5 */ null,
/* 6 */ "Remove",
};
SourceLookupAdapter adapter = new SourceLookupAdapter();
fSourceListField = new ListDialogField( adapter, buttonLabels, new SourceLookupLabelProvider() );
fSourceListField.setLabelText( "Source Locations" );
fSourceListField.setUpButtonIndex( 3 );
fSourceListField.setDownButtonIndex( 4 );
fSourceListField.setRemoveButtonIndex( 6 );
fSourceListField.enableButton( 1, false );
}
public void createControl( Composite parent )
{
fShell = parent.getShell();
fControl = new Composite( parent, SWT.NONE );
fControl.setLayout( new GridLayout( 2, false ) );
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginWidth = 0;
layout.marginHeight = 0;
fControl.setLayout( layout );
fControl.setLayoutData( new GridData( GridData.FILL_BOTH ) );
fControl.setFont( JFaceResources.getDialogFont() );
createListControl( fControl );
createButtonBar( fControl );
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 ) );
}
public Control getControl()
{
return fControl;
}
protected void initializeDialogUnits( Control control )
protected void initialize( ICSourceLocation[] locations )
{
// Compute and store a font metric
GC gc = new GC( control );
gc.setFont( control.getFont() );
fFontMetrics = gc.getFontMetrics();
gc.dispose();
fSourceListField.removeAllElements();
for ( int i = 0; i < locations.length; ++i )
{
fSourceListField.addElement( locations[i] );
}
}
protected int convertVerticalDLUsToPixels( int dlus )
protected void doButtonPressed( int index )
{
if ( fFontMetrics == null )
return 0;
return Dialog.convertVerticalDLUsToPixels( fFontMetrics, dlus );
}
protected int convertHorizontalDLUsToPixels( int dlus )
{
if ( fFontMetrics == null )
return 0;
return Dialog.convertHorizontalDLUsToPixels( fFontMetrics, dlus );
switch( index )
{
case 0: // Add...
addSourceLocation();
break;
}
}
protected void createListControl( Composite parent )
protected void doSelectionChanged()
{
}
protected void createButtonBar( Composite parent )
protected ICSourceLocation[] getSourceLocations()
{
return (ICSourceLocation[])fSourceListField.getElements().toArray( new ICSourceLocation[fSourceListField.getElements().size()] );
}
private void addSourceLocation()
{
AddSourceLocationWizard wizard = new AddSourceLocationWizard();
WizardDialog dialog = new WizardDialog( fControl.getShell(), wizard );
dialog.open();
}
}

View file

@ -5,8 +5,14 @@
*/
package org.eclipse.cdt.debug.ui.sourcelookup;
import org.eclipse.cdt.debug.core.model.ICDebugTarget;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.dialogs.PropertyPage;
/**
@ -18,12 +24,15 @@ import org.eclipse.ui.dialogs.PropertyPage;
public class SourcePropertyPage extends PropertyPage
{
private SourceLookupBlock fBlock = null;
private boolean fHasActiveContents = false;
/**
* Constructor for SourcePropertyPage.
*/
public SourcePropertyPage()
{
noDefaultAndApplyButton();
fBlock = new SourceLookupBlock();
}
@ -32,8 +41,78 @@ public class SourcePropertyPage extends PropertyPage
*/
protected Control createContents( Composite parent )
{
ICDebugTarget target = getDebugTarget();
if ( target == null || target.isTerminated() || target.isDisconnected() )
{
return createTerminatedContents( parent );
}
fHasActiveContents = true;
return createActiveContents( parent );
}
protected Control createTerminatedContents( Composite parent )
{
Label label= new Label( parent, SWT.LEFT );
label.setText( "Terminated." );
return label;
}
protected Control createActiveContents( Composite parent )
{
fBlock.initialize( getSourceLocations() );
fBlock.createControl( parent );
return fBlock.getControl();
}
protected ICDebugTarget getDebugTarget()
{
IAdaptable element = getElement();
if ( element != null )
{
return (ICDebugTarget)element.getAdapter( ICDebugTarget.class );
}
return null;
}
private ICSourceLocation[] getSourceLocations()
{
ICDebugTarget target = getDebugTarget();
if ( target != null )
{
if ( target.getLaunch().getSourceLocator() instanceof IAdaptable )
{
ICSourceLocator locator = (ICSourceLocator)((IAdaptable)target.getLaunch().getSourceLocator()).getAdapter( ICSourceLocator.class );
if ( locator != null )
{
return locator.getSourceLocations();
}
}
}
return new ICSourceLocation[0];
}
/* (non-Javadoc)
* @see org.eclipse.jface.preference.IPreferencePage#performOk()
*/
public boolean performOk()
{
setSourceLocations( fBlock.getSourceLocations() );
return true;
}
private void setSourceLocations( ICSourceLocation[] locations )
{
ICDebugTarget target = getDebugTarget();
if ( target != null )
{
if ( target.getLaunch().getSourceLocator() instanceof IAdaptable )
{
ICSourceLocator locator = (ICSourceLocator)((IAdaptable)target.getLaunch().getSourceLocator()).getAdapter( ICSourceLocator.class );
if ( locator != null )
{
locator.setSourceLocations( locations );
}
}
}
}
}