Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 82adc381f1aa59ea225ff2ed40fb0ac30caa138c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
/*******************************************************************************
 * Copyright (c) 2000, 2012 QNX Software Systems 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:
 *     QNX Software Systems - Initial API and implementation
 *     IBM Corporation
 *******************************************************************************/
package org.eclipse.cdt.debug.mi.internal.ui;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Observable;
import java.util.Set;

import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.IBinaryParser.IBinaryShared;
import org.eclipse.cdt.core.model.CoreModelUtil;
import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.debug.mi.core.IMILaunchConfigurationConstants;
import org.eclipse.cdt.debug.mi.core.MICoreUtils;
import org.eclipse.cdt.debug.mi.internal.ui.dialogfields.DialogField;
import org.eclipse.cdt.debug.mi.internal.ui.dialogfields.IDialogFieldListener;
import org.eclipse.cdt.debug.mi.internal.ui.dialogfields.IListAdapter;
import org.eclipse.cdt.debug.mi.internal.ui.dialogfields.LayoutUtil;
import org.eclipse.cdt.debug.mi.internal.ui.dialogfields.ListDialogField;
import org.eclipse.cdt.debug.mi.ui.IMILaunchConfigurationComponent;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.layout.PixelConverter;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog;

/**
 * The UI component to access the shared libraries search path.
 */
public class SolibSearchPathBlock extends Observable implements IMILaunchConfigurationComponent, IDialogFieldListener {

	class AddDirectoryDialog extends Dialog {

		protected Text fText;
		
		private Button fBrowseButton;

		private IPath fValue;

		/** 
		 * Constructor for AddDirectoryDialog. 
		 */
		public AddDirectoryDialog( Shell parentShell ) {
			super( parentShell );
		}

		@Override
		protected Control createDialogArea( Composite parent ) {
			Composite composite = (Composite)super.createDialogArea( parent );

			Composite subComp = ControlFactory.createCompositeEx( composite, 2, GridData.FILL_HORIZONTAL );
			((GridLayout)subComp.getLayout()).makeColumnsEqualWidth = false;
			GridData data = new GridData( GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER );
			data.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
			subComp.setLayoutData( data );
			subComp.setFont( parent.getFont() );

			fText = new Text( subComp, SWT.SINGLE | SWT.BORDER );
			fText.setLayoutData( new GridData( GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL ) );
			fText.addModifyListener( new ModifyListener() {

				@Override
				public void modifyText( ModifyEvent e ) {
					updateOKButton();
				}
			} );

			fBrowseButton = ControlFactory.createPushButton( subComp, MIUIMessages.getString( "GDBServerDebuggerPage.7" ) ); //$NON-NLS-1$
			data = new GridData();
			data.horizontalAlignment = GridData.FILL;
			fBrowseButton.setLayoutData( data );
			fBrowseButton.addSelectionListener( new SelectionAdapter() {

				@Override
				public void widgetSelected( SelectionEvent evt ) {
					DirectoryDialog dialog = new DirectoryDialog( AddDirectoryDialog.this.getShell() );
					dialog.setMessage( MIUIMessages.getString( "SolibSearchPathBlock.5" ) ); //$NON-NLS-1$
					String res = dialog.open();
					if ( res != null ) {
						fText.setText( res );
					}
				}
			} );

			applyDialogFont( composite );
			return composite;
		}

		@Override
		protected void configureShell( Shell newShell ) {
			super.configureShell( newShell );
			newShell.setText( MIUIMessages.getString( "SolibSearchPathBlock.Add_Directory" ) ); //$NON-NLS-1$
		}

		public IPath getValue() {
			return fValue;
		}

		private void setValue( String value ) {
			fValue = ( value != null ) ? new Path( value ) : null;
		}

		@Override
		protected void buttonPressed( int buttonId ) {
			if ( buttonId == IDialogConstants.OK_ID ) {
				setValue( fText.getText() );
			}
			else {
				setValue( null );
			}
			super.buttonPressed( buttonId );
		}

		protected void updateOKButton() {
			Button okButton = getButton( IDialogConstants.OK_ID );
			String text = fText.getText();
			okButton.setEnabled( isValid( text ) );
		}

		protected boolean isValid( String text ) {
			return ( text.trim().length() > 0 );
		}

		@Override
		protected Control createButtonBar( Composite parent ) {
			Control control = super.createButtonBar( parent );
			updateOKButton();
			return control;
		}
	}

	private Composite fControl;

	public class SolibSearchPathListDialogField extends ListDialogField {

		public SolibSearchPathListDialogField( IListAdapter adapter, String[] buttonLabels, ILabelProvider lprovider ) {
			super( adapter, buttonLabels, lprovider );
		}

		/* (non-Javadoc)
		 * @see org.eclipse.cdt.debug.internal.ui.dialogfields.ListDialogField#managedButtonPressed(int)
		 */
		@Override
		protected boolean managedButtonPressed( int index ) {
			boolean result = super.managedButtonPressed( index );
			if ( result )
				buttonPressed( index );
			return result;
		}

		/* (non-Javadoc)
		 * @see org.eclipse.cdt.debug.mi.internal.ui.dialogfields.ListDialogField#getManagedButtonState(org.eclipse.jface.viewers.ISelection, int)
		 */
		@Override
		protected boolean getManagedButtonState( ISelection sel, int index ) {
			if ( index > 3 )
				return getButtonState( sel, index );
			return super.getManagedButtonState( sel, index );
		}
	}

	private static String[] fgStaticButtonLabels = new String[] {
			MIUIMessages.getString( "SolibSearchPathBlock.0" ), //$NON-NLS-1$
			MIUIMessages.getString( "SolibSearchPathBlock.1" ), //$NON-NLS-1$
			MIUIMessages.getString( "SolibSearchPathBlock.2" ), //$NON-NLS-1$
			MIUIMessages.getString( "SolibSearchPathBlock.3" ), //$NON-NLS-1$
			MIUIMessages.getString( "SolibSearchPathBlock.6" ), //$NON-NLS-1$
			null, // separator
		};

	private IProject fProject;

	private Shell fShell;

	private SolibSearchPathListDialogField fDirList;

	private IListAdapter fCustomListAdapter;

	private File[] fAutoSolibs = new File[0];
	
	public SolibSearchPathBlock() {
		this( new String[0], null );
	}

	public SolibSearchPathBlock( String[] customButtonLabels, IListAdapter customListAdapter ) {
		super();
		fCustomListAdapter = customListAdapter;
		int length = fgStaticButtonLabels.length;
		if ( customButtonLabels.length > 0 )
			length += customButtonLabels.length;
		String[] buttonLabels = new String[length];
		System.arraycopy( fgStaticButtonLabels, 0, buttonLabels, 0, fgStaticButtonLabels.length );
		if ( length > fgStaticButtonLabels.length ) {
			for ( int i = fgStaticButtonLabels.length; i < length; ++i )
				buttonLabels[i] = customButtonLabels[i - fgStaticButtonLabels.length];
		}
		IListAdapter listAdapter = new IListAdapter() {
			@Override
			public void customButtonPressed( DialogField field, int index ) {
				buttonPressed( index );
			}
			@Override
			public void selectionChanged( DialogField field ) {
			}
		};
		ILabelProvider lp = new LabelProvider() {
			@Override
			public String getText( Object element ) {
				if ( element instanceof IPath )
					return ((IPath)element).toOSString();
				return super.getText( element );
			}
		};
		fDirList = new SolibSearchPathListDialogField( listAdapter, buttonLabels, lp );
		fDirList.setLabelText( MIUIMessages.getString( "SolibSearchPathBlock.4" ) ); //$NON-NLS-1$
		fDirList.setUpButtonIndex( 1 );
		fDirList.setDownButtonIndex( 2 );
		fDirList.setRemoveButtonIndex( 3 );
		
		fDirList.setDialogFieldListener(this);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.debug.mi.internal.ui.IMILaunchConfigurationComponent#createControl(org.eclipse.swt.widgets.Composite)
	 */
	@Override
	public void createControl( Composite parent ) {
		fShell = parent.getShell();
		Composite comp = ControlFactory.createCompositeEx( parent, 2, GridData.FILL_BOTH );
		((GridLayout)comp.getLayout()).makeColumnsEqualWidth = false;
		((GridLayout)comp.getLayout()).marginHeight = 0;
		((GridLayout)comp.getLayout()).marginWidth = 0;
		comp.setFont( parent.getFont() );
		PixelConverter converter = new PixelConverter( comp );
		fDirList.doFillIntoGrid( comp, 3 );
		LayoutUtil.setHorizontalSpan( fDirList.getLabelControl( null ), 2 );
		LayoutUtil.setWidthHint( fDirList.getLabelControl( null ), converter.convertWidthInCharsToPixels( 30 ) );
		LayoutUtil.setHorizontalGrabbing( fDirList.getListControl( null ) );
		fControl = comp;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.debug.mi.internal.ui.IMILaunchConfigurationComponent#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
	 */
	@Override
	public void initializeFrom( ILaunchConfiguration configuration ) {
		IProject project = null;
		try {
			String projectName = configuration.getAttribute( ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String)null );
			if ( projectName != null ) {
				projectName = projectName.trim();
				if ( projectName.length() > 0 ) {
					project = ResourcesPlugin.getWorkspace().getRoot().getProject( projectName );
				}
			}
		}
		catch( CoreException e ) {
		}
		setProject( project );

		if ( fDirList != null ) {
			try {
				List values = configuration.getAttribute( IMILaunchConfigurationConstants.ATTR_DEBUGGER_SOLIB_PATH, Collections.EMPTY_LIST );
				ArrayList paths = new ArrayList( values.size() );
				Iterator it = values.iterator();
				while( it.hasNext() ) {
					paths.add( new Path( (String)it.next() ) );
				}
				fDirList.addElements( paths );
			}
			catch( CoreException e ) {
			}
		}

		try {
			fAutoSolibs = MICoreUtils.getAutoSolibs( configuration );
		}
		catch( CoreException e ) {
		}
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.debug.mi.internal.ui.IMILaunchConfigurationComponent#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
	 */
	@Override
	public void setDefaults( ILaunchConfigurationWorkingCopy configuration ) {
		configuration.setAttribute( IMILaunchConfigurationConstants.ATTR_DEBUGGER_SOLIB_PATH, Collections.EMPTY_LIST );
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.debug.mi.internal.ui.IMILaunchConfigurationComponent#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
	 */
	@Override
	public void performApply( ILaunchConfigurationWorkingCopy configuration ) {
		if ( fDirList != null ) {
			List elements = fDirList.getElements();
			ArrayList values = new ArrayList( elements.size() );
			Iterator it = elements.iterator();
			while( it.hasNext() ) {
				values.add( ((IPath)it.next()).toOSString() );
			}
			configuration.setAttribute( IMILaunchConfigurationConstants.ATTR_DEBUGGER_SOLIB_PATH, values );
		}
		ArrayList autoLibs = new ArrayList( fAutoSolibs.length );
		for ( int i = 0; i < fAutoSolibs.length; ++i )
			autoLibs.add( fAutoSolibs[i].getPath() );
		configuration.setAttribute( IMILaunchConfigurationConstants.ATTR_DEBUGGER_AUTO_SOLIB_LIST, autoLibs ); 
	}

	protected void buttonPressed( int index ) {
		boolean changed = false; 
		if ( index == 0 ) { // Add button
			changed = addDirectory();
		}
		else if ( index == 4 ) { //Select from list
			changed = selectFromList();
		}
		else if ( index >= fgStaticButtonLabels.length && fCustomListAdapter != null ) {
			fCustomListAdapter.customButtonPressed( fDirList, index );
			changed = true;
		}
		if ( changed ) {
			setChanged();
			notifyObservers();
		}
	}

	protected boolean getButtonState( ISelection sel, int index ) {
		if ( index == 4 ) { // select from list
			return ( !sel.isEmpty() );
		}
		return true;
	}

	protected Shell getShell() {
		return fShell;
	}

	protected DialogField getDirList(){
		return fDirList;
	}
	protected boolean addDirectory() {
		boolean changed = false;
		AddDirectoryDialog dialog = new AddDirectoryDialog( getShell() );
		dialog.open();
		IPath result = dialog.getValue();
		if ( result != null && !contains( result ) ) {
			fDirList.addElement( result );
			changed = true; 
		}
		return changed;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.debug.mi.internal.ui.IMILaunchConfigurationComponent#dispose()
	 */
	@Override
	public void dispose() {
		deleteObservers();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.debug.mi.internal.ui.IMILaunchConfigurationComponent#getControl()
	 */
	@Override
	public Control getControl() {
		return fControl;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.debug.mi.internal.ui.IMILaunchConfigurationComponent#isValid(org.eclipse.debug.core.ILaunchConfiguration)
	 */
	@Override
	public boolean isValid( ILaunchConfiguration launchConfig ) {
		// TODO Auto-generated method stub
		return false;
	}

	protected boolean contains( IPath path ) {
		List list = fDirList.getElements();
		Iterator it = list.iterator();
		while( it.hasNext() ) {
			IPath p = (IPath)it.next();
			if ( p.toFile().equals( path.toFile() ) )
				return true;
		}
		return false;
	}

	protected IProject getProject() {
		return fProject;
	}

	private void setProject( IProject project ) {
		fProject = project;
	}

	protected boolean selectFromList() {
		boolean changed = false;
		List dirList = fDirList.getSelectedElements();
		final HashSet libs = new HashSet( 10 );
		if ( generateLibraryList( (IPath[])dirList.toArray( new IPath[dirList.size()] ), libs ) ) {
			ITreeContentProvider cp = new ITreeContentProvider() {
	
				@Override
				public Object[] getChildren( Object parentElement ) {
					return getElements( parentElement );
				}
	
				@Override
				public Object getParent( Object element ) {
					if ( libs.contains( element ) )
						return libs;
					return null;
				}
	
				@Override
				public boolean hasChildren( Object element ) {
					return false;
				}
	
				@Override
				public Object[] getElements( Object inputElement ) {
					if ( inputElement instanceof Set ) {
						return ((Set)inputElement).toArray();
					}
					return new Object[0];
				}
	
				@Override
				public void dispose() {
				}
	
				@Override
				public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) {
				}	
			};
	
			LabelProvider lp = new LabelProvider() {
	
				@Override
				public String getText( Object element ) {
					if ( element instanceof File )
						return ((File)element).getName();
					return super.getText( element );
				}
			};
			CheckedTreeSelectionDialog dialog = new CheckedTreeSelectionDialog( getShell(), lp, cp );
			dialog.setTitle( MIUIMessages.getString( "SolibSearchPathBlock.7" ) ); //$NON-NLS-1$
			dialog.setMessage( MIUIMessages.getString( "SolibSearchPathBlock.8" ) ); //$NON-NLS-1$
			dialog.setEmptyListMessage( MIUIMessages.getString( "SolibSearchPathBlock.9" ) ); //$NON-NLS-1$
			dialog.setSorter( new ViewerSorter() );
			dialog.setInput( libs );
			dialog.setInitialElementSelections( Arrays.asList( fAutoSolibs ) );
			if ( dialog.open() == Window.OK ) {
				Object[] result = dialog.getResult();
				fAutoSolibs = Arrays.asList( result ).toArray( new File[result.length] );
				changed = true;
			}
		}
		return changed;
	}

	private boolean generateLibraryList( final IPath[] paths, final Set libs ) {
		boolean result = true;

		IRunnableWithProgress runnable = new IRunnableWithProgress() {
			@Override
			public void run( IProgressMonitor monitor ) throws InvocationTargetException, InterruptedException {

				for ( int i = 0; i < paths.length; ++i ) {
					File dir = paths[i].toFile();
					if ( dir.exists() && dir.isDirectory() ) {
						File[] all = dir.listFiles();
						for ( int j = 0; j < all.length; ++j ) {
							if ( monitor.isCanceled() ) {
								throw new InterruptedException();
							}
							monitor.subTask( all[j].getPath() );
							String libName = getSharedLibraryName( all[j] );
							if ( libName != null ) {
								libs.add( new File( libName ) );
							}
						}
					}
				}
			}
		};
        try {
        	IRunnableContext context = new ProgressMonitorDialog( getShell() );
			context.run( true, true, runnable );
		}
		catch( InvocationTargetException e ) {
		}
		catch( InterruptedException e ) {
			result = false;
		}
		return result;
	}

	protected String getSharedLibraryName( File file ) {
		if ( !file.isFile() )
			return null;
		IProject project = getProject();
		if ( project != null ) {
			IPath fullPath = new Path( file.getPath() );
			try {
				ICConfigExtensionReference[] binaryParsersExt = CCorePlugin.getDefault().getDefaultBinaryParserExtensions( project );
				for( int i = 0; i < binaryParsersExt.length; i++ ) {
					IBinaryParser parser = CoreModelUtil.getBinaryParser(binaryParsersExt[i]);
					try {
						IBinaryFile bin = parser.getBinary( fullPath );
						if ( bin instanceof IBinaryShared ) {
							String soname = ((IBinaryShared)bin).getSoName();
							return ( soname.length() != 0 ) ? soname : file.getName();
						}
					}
					catch( IOException e ) {
					}
				}
			}
			catch( CoreException e ) {
			}
			return null;
		}
		// no project: for now
		IPath path = new Path( file.getPath() );
		String name = path.lastSegment();
		String extension = path.getFileExtension();
		if ( extension != null && (extension.compareTo( "so" ) == 0 || extension.compareToIgnoreCase( "dll" ) == 0) ) //$NON-NLS-1$ //$NON-NLS-2$
			return name;
		return ( name.indexOf( ".so." ) >= 0 ) ? name : null; //$NON-NLS-1$
	}

	protected boolean isSharedLibrary( File file ) {
		if ( !file.isFile() )
			return false;
		IProject project = getProject();
		if ( project != null ) {
			IPath fullPath = new Path( file.getPath() );
			try {
				ICConfigExtensionReference[] binaryParsersExt = CCorePlugin.getDefault().getDefaultBinaryParserExtensions( project );
				for( int i = 0; i < binaryParsersExt.length; i++ ) {
					IBinaryParser parser = CoreModelUtil.getBinaryParser(binaryParsersExt[i]);
					try {
						IBinaryFile bin = parser.getBinary( fullPath );
						return ( bin instanceof IBinaryShared );
					}
					catch( IOException e ) {
					}
				}
			}
			catch( CoreException e ) {
			}
			return false;
		}
		// no project: for now
		IPath path = new Path( file.getPath() );
		String extension = path.getFileExtension();
		if ( extension != null && (extension.compareTo( "so" ) == 0 || extension.compareToIgnoreCase( "dll" ) == 0) ) //$NON-NLS-1$ //$NON-NLS-2$
			return true;
		String name = path.lastSegment();
		return ( name.indexOf( ".so." ) >= 0 ); //$NON-NLS-1$
	}

	@Override
	public void dialogFieldChanged(DialogField field) {
		setChanged();
		notifyObservers();
	}
}

Back to the top