source: rtems-eclipse-plug-in/org.rtems.cdt/src/org/rtems/cdt/properties/PropertyPage.java @ 6740c53

Last change on this file since 6740c53 was 6740c53, checked in by Sebastian Huber <sebastian.huber@…>, on 12/04/08 at 14:53:45

Initial commit.

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 * Copyright (c) 2008 Embedded Brains GmbH and others.
3 *
4 *   Embedded Brains GmbH
5 *   Obere Lagerstr. 30
6 *   D-82178 Puchheim
7 *   Germany
8 *   rtems@embedded-brains.de
9 *
10 * All rights reserved.  This program and the accompanying materials are made
11 * available under the terms of the Eclipse Public License Version 1.0 ("EPL")
12 * which accompanies this distribution and is available at
13 *
14 *   http://www.eclipse.org/legal/epl-v10.html
15 *
16 * For purposes of the EPL, "Program" will mean the Content.
17 *
18 * Contributors:
19 *
20 *   Sebastian Huber (Embedded Brains GmbH) - Initial API and implementation.
21 */
22
23package org.rtems.cdt.properties;
24
25import org.eclipse.core.resources.IProject;
26import org.eclipse.core.resources.IResource;
27import org.eclipse.core.runtime.IAdaptable;
28import org.eclipse.jface.preference.DirectoryFieldEditor;
29import org.eclipse.jface.preference.FieldEditorPreferencePage;
30import org.eclipse.jface.preference.IPreferenceStore;
31import org.eclipse.ui.IWorkbenchPropertyPage;
32import org.eclipse.cdt.core.model.ICElement;
33import org.rtems.cdt.Activator;
34import org.rtems.cdt.Constants;
35import org.rtems.cdt.Storage;
36import org.rtems.cdt.VolatilePreferenceStore;
37
38public class PropertyPage extends FieldEditorPreferencePage implements IWorkbenchPropertyPage {
39        private IAdaptable mElement;
40
41        private IPreferenceStore mStore;
42
43        private IProject mProject;
44
45        public PropertyPage() {
46                super( GRID);
47
48                // Store properties in a volatile preference store
49                mStore = new VolatilePreferenceStore();
50                setPreferenceStore( mStore);
51
52                setDescription( "You can change the RTEMS base installation path and the board support package (BSP) installation path.  This affects only the current project.");
53        }
54
55        private void setupStoreValue( IPreferenceStore defaultStore, String key) {
56                mStore.setDefault( key, defaultStore.getString( key));
57                mStore.setValue( key, Storage.getProperty( mProject, key));
58        }
59
60        protected void createFieldEditors() {
61                // Get current project
62                mProject = ((IResource) getElement().getAdapter( IResource.class)).getProject();
63                if (mProject == null) {
64                        mProject = ((ICElement) getElement().getAdapter( ICElement.class)).getCProject().getProject();
65                }
66
67                // Get the default values from the current workbench preferences
68                IPreferenceStore store = Activator.getDefault().getPreferenceStore();
69
70                // Setup store values
71                setupStoreValue( store, Constants.BASE_PATH_KEY);
72                setupStoreValue( store, Constants.BSP_PATH_KEY);
73
74                // Add field editors
75                addField(
76                        new DirectoryFieldEditor(
77                                Constants.BASE_PATH_KEY,
78                                "Base path:",
79                                getFieldEditorParent()
80                        )
81                );
82                addField(
83                        new DirectoryFieldEditor(
84                                Constants.BSP_PATH_KEY,
85                                "BSP path:",
86                                getFieldEditorParent()
87                        )
88                );
89        }
90
91        private void setProperty( String key) {
92                Storage.setProperty( mProject, key, mStore.getString( key));
93        }
94
95        public boolean performOk() {
96                super.performOk();
97
98                // Set the new properties
99                setProperty( Constants.BASE_PATH_KEY);
100                setProperty( Constants.BSP_PATH_KEY);
101
102                // Clear platform
103                Storage.clearPlatform( mProject);
104
105                return true;
106        }
107
108        public IAdaptable getElement() {
109                return mElement;
110        }
111
112        public void setElement( IAdaptable element) {
113                this.mElement = element;
114        }
115}
Note: See TracBrowser for help on using the repository browser.