summaryrefslogblamecommitdiffstats
path: root/org.rtems.cdt/src/org/rtems/cdt/wizards/BasicSetup.java
blob: d2bd4ccabbd3c23b36946e5fbd3200d06f208a4a (plain) (tree)







































































































































































































































                                                                                                                        
/*
 * Copyright (c) 2008 Embedded Brains GmbH and others.
 *
 *   Embedded Brains GmbH
 *   Obere Lagerstr. 30
 *   D-82178 Puchheim
 *   Germany
 *   rtems@embedded-brains.de
 *
 * All rights reserved.  This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License Version 1.0 ("EPL")
 * which accompanies this distribution and is available at
 *
 *   http://www.eclipse.org/legal/epl-v10.html
 *
 * For purposes of the EPL, "Program" will mean the Content.
 *
 * Contributors:
 *
 *   Sebastian Huber (Embedded Brains GmbH) - Initial API and implementation.
 */

package org.rtems.cdt.wizards;

import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPage;
import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPageManager;
import org.eclipse.cdt.ui.wizards.CDTCommonProjectWizard;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.resource.ImageDescriptor;
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.graphics.Image;
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.Label;
import org.eclipse.swt.widgets.Text;
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);
		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);
		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) {
		// Get current project
		CDTCommonProjectWizard wizard = (CDTCommonProjectWizard) getWizard();
		IProject project = wizard.getLastProject();

		/*
		 *  Here we have to take care about the synchronization between the wizard
		 *  and the properties of the new project (advanced settings dialog).
		 */
		if (visible) {
			if (project != null) {
				// For already created projects use the properties
				mBasePath.setText( Storage.getProperty( project, Constants.BASE_PATH_KEY));
				mBSPPath.setText( Storage.getProperty( project, Constants.BSP_PATH_KEY));
			} else {
				// For not yet created projects use the preferences
				mBasePath.setText( Storage.getPreference( Constants.BASE_PATH_KEY));
				mBSPPath.setText( Storage.getPreference( Constants.BSP_PATH_KEY));
			}
		} else {
			if (project != null) {
				// Store the wizard values in the properties if the project exists already
				Storage.setProperty( project, Constants.BASE_PATH_KEY, mBasePath.getText());
				Storage.setProperty( project, Constants.BSP_PATH_KEY, mBSPPath.getText());
			}
		}

		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());
	}
}