diff options
Diffstat (limited to 'org.rtems.cdt/src/org/rtems/cdt/properties/PropertyPage.java')
-rw-r--r-- | org.rtems.cdt/src/org/rtems/cdt/properties/PropertyPage.java | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/org.rtems.cdt/src/org/rtems/cdt/properties/PropertyPage.java b/org.rtems.cdt/src/org/rtems/cdt/properties/PropertyPage.java new file mode 100644 index 0000000..638d39e --- /dev/null +++ b/org.rtems.cdt/src/org/rtems/cdt/properties/PropertyPage.java @@ -0,0 +1,115 @@ +/* + * 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.properties; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.preference.DirectoryFieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.ui.IWorkbenchPropertyPage; +import org.eclipse.cdt.core.model.ICElement; +import org.rtems.cdt.Activator; +import org.rtems.cdt.Constants; +import org.rtems.cdt.Storage; +import org.rtems.cdt.VolatilePreferenceStore; + +public class PropertyPage extends FieldEditorPreferencePage implements IWorkbenchPropertyPage { + private IAdaptable mElement; + + private IPreferenceStore mStore; + + private IProject mProject; + + public PropertyPage() { + super( GRID); + + // Store properties in a volatile preference store + mStore = new VolatilePreferenceStore(); + setPreferenceStore( mStore); + + setDescription( "You can change the RTEMS base installation path and the board support package (BSP) installation path. This affects only the current project."); + } + + private void setupStoreValue( IPreferenceStore defaultStore, String key) { + mStore.setDefault( key, defaultStore.getString( key)); + mStore.setValue( key, Storage.getProperty( mProject, key)); + } + + protected void createFieldEditors() { + // Get current project + mProject = ((IResource) getElement().getAdapter( IResource.class)).getProject(); + if (mProject == null) { + mProject = ((ICElement) getElement().getAdapter( ICElement.class)).getCProject().getProject(); + } + + // Get the default values from the current workbench preferences + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + + // Setup store values + setupStoreValue( store, Constants.BASE_PATH_KEY); + setupStoreValue( store, Constants.BSP_PATH_KEY); + + // Add field editors + addField( + new DirectoryFieldEditor( + Constants.BASE_PATH_KEY, + "Base path:", + getFieldEditorParent() + ) + ); + addField( + new DirectoryFieldEditor( + Constants.BSP_PATH_KEY, + "BSP path:", + getFieldEditorParent() + ) + ); + } + + private void setProperty( String key) { + Storage.setProperty( mProject, key, mStore.getString( key)); + } + + public boolean performOk() { + super.performOk(); + + // Set the new properties + setProperty( Constants.BASE_PATH_KEY); + setProperty( Constants.BSP_PATH_KEY); + + // Clear platform + Storage.clearPlatform( mProject); + + return true; + } + + public IAdaptable getElement() { + return mElement; + } + + public void setElement( IAdaptable element) { + this.mElement = element; + } +} |