summaryrefslogblamecommitdiffstats
path: root/org.rtems.cdt.toolchain2/org/rtems/cdt/wizards/BasicSetup.java
blob: b622a29812e93e3c9ac5f69325caa81beb6f0e26 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14













                                                                            








                                                                      

                               
 
                                               
                                                                                
        
                                                           


                                     
                               
        
                              
 

                                 

         
                                            


                                                                         
                                 


                                          
                                                      

                                                              







                                                                
                            
                                                               
                                             
                

                                                                                    
                                                             
                                             

                                                                  
                                        


                                                                               
                                                                  


                                 
                
                           
                                                         
                                            
                

                                                                                  
                                                             
                                            
                








                                                                               

                                     
                                            

                                                                        
                                                          


                                 
                                           

                                                                        
                                                         




                                        

                                  

         
                               


                                     
                                     


                                  
                                        
                                                                                                                        

         
                                         


                            
                                 


                                                    
                                    


                            
                                  
                                     

         
                                   


                             
                                                         


                             
                                                                


                             
                                             


                             
                                                  


                                                
                                                  
                            

         
                                                
                                                                                               



                                                      

                 
        


                                                                                                            
        

                                                                                                          
         
 
/*
 * Copyright (c) 2008
 * Embedded Brains GmbH
 * Obere Lagerstr. 30
 * D-82178 Puchheim
 * Germany
 * rtems@embedded-brains.de
 *
 * The license and distribution terms for this file may be found in the file
 * LICENSE in this distribution or at http://www.rtems.com/license/LICENSE.
 */

package org.rtems.cdt.wizards;

import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPage;
import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPageManager;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.SWT;
import org.rtems.cdt.Constants;
import org.rtems.cdt.Storage;

public class BasicSetup extends MBSCustomPage {
	public static final String PAGE_ID = "org.rtems.cdt.wizards.BasicSetup";
	
	public static final String BROWSE = " &Browse... ";
	
	private Composite mComposite;
	
	private Text mBasePath;
	
	private Text mBSPPath;

	public BasicSetup() {
		pageID = PAGE_ID;
	}

	public boolean canFlipToNextPage() {
		return MBSCustomPageManager.getNextPage( pageID) != null;
	}

	public String getName() {
		return "Basic Setup Page";
	}

	public void createControl( Composite parent) {
		// Create base widget
		mComposite = new Composite( parent, SWT.NONE);
		
		GridData gd = new GridData( GridData.FILL_BOTH);
		mComposite.setLayoutData( gd);
		
		GridLayout layout = new GridLayout();
		layout.numColumns = 3;
		mComposite.setLayout( layout);
		
		// Base path
		Label label = new Label( mComposite, SWT.LEFT);
		label.setText( "Base path:");
		
		mBasePath = new Text( mComposite, SWT.LEFT | SWT.BORDER);
		mBasePath.setText( Storage.getPreference( Constants.BASE_PATH_KEY));
		gd = new GridData( GridData.FILL_HORIZONTAL);
		mBasePath.setLayoutData( gd);
		
		Button button = new Button( mComposite, SWT.PUSH);
		button.setText( BROWSE);
		button.addSelectionListener(
			new SelectionAdapter() {
				public void widgetSelected( SelectionEvent e) {
					browseForPath( mBasePath);
				}
			}
		);
		
		// BSP path
		label = new Label( mComposite, SWT.LEFT);
		label.setText( "BSP path:");
		
		mBSPPath = new Text( mComposite, SWT.LEFT | SWT.BORDER);
		mBSPPath.setText( Storage.getPreference( Constants.BSP_PATH_KEY));
		gd = new GridData( GridData.FILL_HORIZONTAL);
		mBSPPath.setLayoutData( gd);
		
		button = new Button( mComposite, SWT.PUSH);
		button.setText( BROWSE);
		button.addSelectionListener(
			new SelectionAdapter() {
				public void widgetSelected( SelectionEvent e) {
					browseForPath( mBSPPath);
				}
			}
		);
		
		// Connect user input
		mBasePath.addModifyListener(
			new ModifyListener() {
				public void modifyText( ModifyEvent e) {
					basePathChanged();
				}
			}
		);
		mBSPPath.addModifyListener(
			new ModifyListener() {
				public void modifyText( ModifyEvent e) {
					bspPathChanged();
				}
			}
		);
		
		// Trigger initial setup
		basePathChanged();
		bspPathChanged();
	}

	public void dispose() {
		mComposite.dispose();
	}

	public Control getControl() {
		return mComposite;
	}

	public String getDescription() {
		return "Select the RTEMS base installation path and the board support package (BSP) installation path.";
	}

	public String getErrorMessage() {
		return null;
	}

	public Image getImage() {
		return wizard.getDefaultPageImage();
	}

	public String getMessage() {
		return null;
	}

	public String getTitle() {
		return "RTEMS Setup";
	}

	public void performHelp() {
		// Do nothing
	}

	public void setDescription( String description) {
		// Do nothing
	}

	public void setImageDescriptor( ImageDescriptor image) {
		// Do nothing
	}

	public void setTitle( String title) {
		// Do nothing
	}

	public void setVisible( boolean visible) {
		mComposite.setVisible( visible);
	}

	protected boolean isCustomPageComplete() {
		return true;
	}
	
	private void browseForPath( Text text) {
		DirectoryDialog dialog = new DirectoryDialog( mComposite.getShell(), SWT.NONE);
		dialog.setFilterPath( text.getText());
		String path = dialog.open();
		if (path != null) {
			text.setText( path);
		}
	}
	
	private void basePathChanged() {
		MBSCustomPageManager.addPageProperty( pageID, Constants.BASE_PATH_KEY, mBasePath.getText());
	}	
	
	private void bspPathChanged() {
		MBSCustomPageManager.addPageProperty( pageID, Constants.BSP_PATH_KEY, mBSPPath.getText());
	}
}