if( !(new File(fileName).exists())) { ExceptionHandler.openErrorMessageBox( Messages.getString( "AddLibraryAction.Error.Title" ), Messages.getFormattedString( "AddLibraryAction.Error.FileNotFound", new String[]{fileName} ) ); return; }  if ( !(fileName.endsWith( ".rptlibrary") )) { ExceptionHandler.openErrorMessageBox( Messages.getString( "AddLibraryAction.Error.Title" ), Messages.getFormattedString( "AddLibraryAction.Error.FileIsNotLibrary", new String[]{fileName,".rptlibrary"} ) ); return; }
	protected Control createContents( Composite parent )	{		Composite mainComposite = new Composite( parent, SWT.NULL );		// Create a data that takes up the extra space in the dialog .		GridData data = new GridData( GridData.FILL_HORIZONTAL				| GridData.FILL_VERTICAL );		data.grabExcessHorizontalSpace = false;		mainComposite.setLayoutData( data );		GridLayout layout = new GridLayout( );		layout.numColumns = 2;		layout.marginHeight = 0;		layout.marginWidth = 0;		mainComposite.setLayout( layout );		// Add in a dummy label for spacing		labelTitle = new Label( mainComposite, SWT.NONE );		labelTitle.setText( Messages.getString( "report.designer.ui.preferences.labeltitle" ) ); //$NON-NLS-1$		// Add none		new Label( mainComposite, SWT.NONE );		// Add a List on the left of the Dialog		int listStyle = SWT.SINGLE				| SWT.BORDER				| SWT.H_SCROLL				| SWT.V_SCROLL				| SWT.HIDE_SELECTION;		LibraryList = new List( mainComposite, listStyle );		data = new GridData( );		data.horizontalAlignment = GridData.FILL;		data.verticalAlignment = GridData.FILL;		data.grabExcessHorizontalSpace = true;		data.grabExcessVerticalSpace = true;		data.heightHint = 80;		data.widthHint = 250;		LibraryList.setLayoutData( data );		LibraryList.setItems( ReportPlugin.getDefault( ).getLibraryPreference( ) );		LibraryList.addSelectionListener( new SelectionAdapter( ) {			public void widgetSelected( SelectionEvent event )			{				removeButton.setEnabled( true );			}		} );		// Add a compose on the right which contains 3 buttons		Composite buttons = new Composite( mainComposite, SWT.NONE );		layout = new GridLayout( );		buttons.setLayout( layout );		data = new GridData( GridData.VERTICAL_ALIGN_BEGINNING );		data.grabExcessVerticalSpace = true;		buttons.setLayoutData( data );		addButton = new Button( buttons, SWT.PUSH );		addButton.setText( Messages.getString( "report.designer.ui.preferences.buttonadd" ) ); //$NON-NLS-1$		data = new GridData( GridData.HORIZONTAL_ALIGN_FILL );		addButton.setLayoutData( data );		addButton.addSelectionListener( new SelectionAdapter( ) {			public void widgetSelected( SelectionEvent event )			{				FileDialog dialog = new FileDialog( PlatformUI.getWorkbench( )						.getDisplay( )						.getActiveShell( ) );				dialog.setFilterExtensions( extensions );				dialog.setText( openDialogTitle );				String fileName = dialog.open( );				if ( fileName == null )				{					return;				}				// If can't find the name				if ( LibraryList.indexOf( fileName ) == -1 )				{					LibraryList.add( fileName, LibraryList.getItemCount( ) );					removeAllButton.setEnabled( true );				}				else				// find the name				{					MessageBox msgBox = new MessageBox( PlatformUI.getWorkbench( )							.getDisplay( )							.getActiveShell( ),							SWT.ICON_ERROR );					msgBox.setText( Messages.getString( "report.designer.ui.preferences.errortitle" ) ); //$NON-NLS-1$					msgBox.setMessage( Messages.getString( "report.designer.ui.preferences.errormessage" ) ); //$NON-NLS-1$					msgBox.open( );				}			}		} );		removeButton = new Button( buttons, SWT.PUSH );		removeButton.setText( Messages.getString( "report.designer.ui.preferences.buttonremove" ) ); //$NON-NLS-1$		data = new GridData( GridData.HORIZONTAL_ALIGN_FILL );		removeButton.setLayoutData( data );		removeButton.setEnabled( false );		removeButton.addSelectionListener( new SelectionAdapter( ) {			public void widgetSelected( SelectionEvent event )			{				int index = LibraryList.getSelectionIndex( );				LibraryList.remove( index );				if ( LibraryList.getItemCount( ) <= 0 )				{					removeButton.setEnabled( false );					removeAllButton.setEnabled( false );				}				else if ( LibraryList.getItemCount( ) > 0 )				{					if ( index >= LibraryList.getItemCount( ) )					{						index -= 1;					}					LibraryList.setSelection( index );					removeButton.setEnabled( true );				}			}		} );		removeAllButton = new Button( buttons, SWT.PUSH );		removeAllButton.setText( Messages.getString( "report.designer.ui.preferences.buttonremoveall" ) ); //$NON-NLS-1$		data = new GridData( GridData.HORIZONTAL_ALIGN_FILL );		removeAllButton.setLayoutData( data );		if ( LibraryList.getItemCount( ) <= 0 )		{			removeAllButton.setEnabled( false );		}		removeAllButton.addSelectionListener( new SelectionAdapter( ) {			public void widgetSelected( SelectionEvent event )			{				LibraryList.removeAll( );				removeButton.setEnabled( false );				removeAllButton.setEnabled( false );			}		} );		exportPref = ReportPlugin.getDefault( )				.getPreferenceStore( )				.getInt( ExportToLibraryAction.PREF_KEY );		Group optionGroup = new Group( parent, SWT.NONE );		optionGroup.setText( EXPORT_PREF_TITLE );		GridLayout gridLayout = new GridLayout( );		gridLayout.numColumns = 4;		gridLayout.marginWidth = 15;		gridLayout.marginHeight = 15;		optionGroup.setLayout( gridLayout );		optionGroup.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );		Button alwaysButton = new Button( optionGroup, SWT.RADIO );		alwaysButton.setText( EXPORT_PREF_ALWAYS );		alwaysButton.addSelectionListener( new SelectionListener( ) {			public void widgetSelected( SelectionEvent e )			{				exportPref = ExportToLibraryAction.PREF_OVERWRITE;			}			public void widgetDefaultSelected( SelectionEvent e )			{				exportPref = ExportToLibraryAction.PREF_OVERWRITE;			}		} );		alwaysButton.setSelection( exportPref == ExportToLibraryAction.PREF_OVERWRITE );		Button neverButton = new Button( optionGroup, SWT.RADIO );		neverButton.setText( EXPORT_PREF_NEVER );		neverButton.addSelectionListener( new SelectionListener( ) {			public void widgetSelected( SelectionEvent e )			{				exportPref = ExportToLibraryAction.PREF_NOT_OVERWRITE;			}			public void widgetDefaultSelected( SelectionEvent e )			{				exportPref = ExportToLibraryAction.PREF_NOT_OVERWRITE;			}		} );		neverButton.setSelection( exportPref == ExportToLibraryAction.PREF_NOT_OVERWRITE );		Button promptButton = new Button( optionGroup, SWT.RADIO );		promptButton.setText( EXPORT_PREF_PROMPT );		promptButton.addSelectionListener( new SelectionListener( ) {			public void widgetSelected( SelectionEvent e )			{				exportPref = ExportToLibraryAction.PREF_PROMPT;			}			public void widgetDefaultSelected( SelectionEvent e )			{				exportPref = ExportToLibraryAction.PREF_PROMPT;			}		} );		promptButton.setSelection( exportPref == ExportToLibraryAction.PREF_PROMPT );		return mainComposite;	}