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 | |
---|
13 | package org.rtems.cdt.properties; |
---|
14 | |
---|
15 | import org.eclipse.core.resources.IProject; |
---|
16 | import org.eclipse.core.resources.IResource; |
---|
17 | import org.eclipse.core.runtime.IAdaptable; |
---|
18 | import org.eclipse.jface.preference.DirectoryFieldEditor; |
---|
19 | import org.eclipse.jface.preference.FieldEditorPreferencePage; |
---|
20 | import org.eclipse.jface.preference.IPreferenceStore; |
---|
21 | import org.eclipse.ui.IWorkbenchPropertyPage; |
---|
22 | import org.eclipse.cdt.core.model.ICElement; |
---|
23 | import org.rtems.cdt.Activator; |
---|
24 | import org.rtems.cdt.Constants; |
---|
25 | import org.rtems.cdt.Storage; |
---|
26 | import org.rtems.cdt.VolatilePreferenceStore; |
---|
27 | |
---|
28 | public class PropertyPage extends FieldEditorPreferencePage implements IWorkbenchPropertyPage { |
---|
29 | private IAdaptable mElement; |
---|
30 | |
---|
31 | private IPreferenceStore mStore; |
---|
32 | |
---|
33 | private IProject mProject; |
---|
34 | |
---|
35 | public PropertyPage() { |
---|
36 | super( GRID); |
---|
37 | |
---|
38 | // Store properties in a volatile preference store |
---|
39 | mStore = new VolatilePreferenceStore(); |
---|
40 | setPreferenceStore( mStore); |
---|
41 | |
---|
42 | setDescription( "You can change the RTEMS base installation path and the board support package (BSP) installation path. This affects only the current project."); |
---|
43 | } |
---|
44 | |
---|
45 | private void setupStoreValue( IPreferenceStore defaultStore, String key) { |
---|
46 | mStore.setDefault( key, defaultStore.getString( key)); |
---|
47 | mStore.setValue( key, Storage.getProperty( mProject, key)); |
---|
48 | } |
---|
49 | |
---|
50 | protected void createFieldEditors() { |
---|
51 | // Get current project |
---|
52 | mProject = ((IResource) getElement().getAdapter( IResource.class)).getProject(); |
---|
53 | if (mProject == null) { |
---|
54 | mProject = ((ICElement) getElement().getAdapter( ICElement.class)).getCProject().getProject(); |
---|
55 | } |
---|
56 | |
---|
57 | // Get the default values from the current workbench preferences |
---|
58 | IPreferenceStore store = Activator.getDefault().getPreferenceStore(); |
---|
59 | |
---|
60 | // Setup store values |
---|
61 | setupStoreValue( store, Constants.BASE_PATH_KEY); |
---|
62 | setupStoreValue( store, Constants.BSP_PATH_KEY); |
---|
63 | |
---|
64 | // Add field editors |
---|
65 | addField( |
---|
66 | new DirectoryFieldEditor( |
---|
67 | Constants.BASE_PATH_KEY, |
---|
68 | "Base path:", |
---|
69 | getFieldEditorParent() |
---|
70 | ) |
---|
71 | ); |
---|
72 | addField( |
---|
73 | new DirectoryFieldEditor( |
---|
74 | Constants.BSP_PATH_KEY, |
---|
75 | "BSP path:", |
---|
76 | getFieldEditorParent() |
---|
77 | ) |
---|
78 | ); |
---|
79 | } |
---|
80 | |
---|
81 | private void setProperty( String key) { |
---|
82 | Storage.setProperty( mProject, key, mStore.getString( key)); |
---|
83 | } |
---|
84 | |
---|
85 | public boolean performOk() { |
---|
86 | super.performOk(); |
---|
87 | |
---|
88 | // Set the new properties |
---|
89 | setProperty( Constants.BASE_PATH_KEY); |
---|
90 | setProperty( Constants.BSP_PATH_KEY); |
---|
91 | |
---|
92 | // Clear platform |
---|
93 | Storage.clearPlatform( mProject); |
---|
94 | |
---|
95 | return true; |
---|
96 | } |
---|
97 | |
---|
98 | public IAdaptable getElement() { |
---|
99 | return mElement; |
---|
100 | } |
---|
101 | |
---|
102 | public void setElement( IAdaptable element) { |
---|
103 | this.mElement = element; |
---|
104 | } |
---|
105 | } |
---|