source: rtems-eclipse-plug-in/org.rtems.cdt.toolchain2/org/rtems/cdt/properties/PropertyPage.java @ 840ee8f

Last change on this file since 840ee8f was 840ee8f, checked in by Sebastian Huber <sebastian.huber@…>, on 11/26/08 at 09:08:17

Fixed property storage issues.
Preferences and properties now sufficient for further development steps.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 * Copyright (c) 2008
3 * Embedded Brains GmbH
4 * Obere Lagerstr. 30
5 * D-82178 Puchheim
6 * Germany
7 * rtems@embedded-brains.de
8 *
9 * The license and distribution terms for this file may be found in the file
10 * LICENSE in this distribution or at http://www.rtems.com/license/LICENSE.
11 */
12
13package org.rtems.cdt.properties;
14
15import org.eclipse.core.resources.IProject;
16import org.eclipse.core.resources.IResource;
17import org.eclipse.core.runtime.IAdaptable;
18import org.eclipse.jface.preference.DirectoryFieldEditor;
19import org.eclipse.jface.preference.ComboFieldEditor;
20import org.eclipse.jface.preference.FieldEditorPreferencePage;
21import org.eclipse.jface.preference.IPreferenceStore;
22import org.eclipse.jface.preference.StringFieldEditor;
23import org.eclipse.ui.IWorkbenchPropertyPage;
24import org.rtems.cdt.Activator;
25import org.rtems.cdt.Constants;
26import org.rtems.cdt.Storage;
27import org.rtems.cdt.VolatilePreferenceStore;
28
29public class PropertyPage extends FieldEditorPreferencePage implements IWorkbenchPropertyPage {
30        private IAdaptable mElement;
31       
32        private IPreferenceStore mStore;
33       
34        public PropertyPage() {
35                super( GRID);
36
37                // Store properties in a volatile preference store
38                mStore = new VolatilePreferenceStore();
39                setPreferenceStore( mStore);
40               
41                setDescription( "You can change the RTEMS base installation path, the RTEMS version, the target architecture and the board support package (BSP) installation path.  This affects only the current project.");
42        }
43       
44        private void setupStoreValue( IProject project, IPreferenceStore defaultStore, String key) {
45                mStore.setDefault( key, defaultStore.getString( key));
46                mStore.setValue( key, Storage.getProperty( project, key));
47        }
48       
49        protected void createFieldEditors() {           
50                // Get the default values from the current workbench preferences
51                IPreferenceStore store = Activator.getDefault().getPreferenceStore();
52               
53                // Setup store values
54                IProject project = ((IResource) getElement()).getProject();
55                setupStoreValue( project, store, Constants.BASE_PATH_KEY);
56                setupStoreValue( project, store, Constants.VERSION_KEY);
57                setupStoreValue( project, store, Constants.TARGET_KEY);
58                setupStoreValue( project, store, Constants.BSP_PATH_KEY);
59
60                // Add field editors
61                addField(
62                        new DirectoryFieldEditor(
63                                Constants.BASE_PATH_KEY,
64                                "Base path:",
65                                getFieldEditorParent()
66                        )
67                );             
68                addField(
69                        new StringFieldEditor(
70                                Constants.VERSION_KEY,
71                                "Version:",
72                                getFieldEditorParent()
73                        )
74                );     
75                addField(
76                        new ComboFieldEditor(
77                                Constants.TARGET_KEY,
78                                "Target:",
79                                Constants.TARGETS,
80                                getFieldEditorParent()
81                        )
82                );
83                addField(
84                        new DirectoryFieldEditor(
85                                Constants.BSP_PATH_KEY,
86                                "BSP path:",
87                                getFieldEditorParent()
88                        )
89                );
90        }
91       
92        private void setProperty( IProject project, String key) {
93                Storage.setProperty( project, key, mStore.getString( key));
94        }
95       
96        public boolean performOk() {
97                super.performOk();
98               
99                // Set the new properties
100                IProject project = ((IResource) getElement()).getProject();     
101                setProperty( project, Constants.BASE_PATH_KEY);
102                setProperty( project, Constants.VERSION_KEY);
103                setProperty( project, Constants.TARGET_KEY);
104                setProperty( project, Constants.BSP_PATH_KEY);
105
106                return true;
107        }
108
109        public IAdaptable getElement() {
110                return mElement;
111        }
112
113        public void setElement( IAdaptable element) {
114                this.mElement = element;
115        }
116}
Note: See TracBrowser for help on using the repository browser.