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.ComboFieldEditor; |
---|
20 | import org.eclipse.jface.preference.FieldEditorPreferencePage; |
---|
21 | import org.eclipse.jface.preference.IPreferenceStore; |
---|
22 | import org.eclipse.jface.preference.StringFieldEditor; |
---|
23 | import org.eclipse.ui.IWorkbenchPropertyPage; |
---|
24 | import org.eclipse.cdt.core.model.ICElement; |
---|
25 | import org.rtems.cdt.Activator; |
---|
26 | import org.rtems.cdt.Constants; |
---|
27 | import org.rtems.cdt.Storage; |
---|
28 | import org.rtems.cdt.VolatilePreferenceStore; |
---|
29 | |
---|
30 | public class PropertyPage extends FieldEditorPreferencePage implements IWorkbenchPropertyPage { |
---|
31 | private IAdaptable mElement; |
---|
32 | |
---|
33 | private IPreferenceStore mStore; |
---|
34 | |
---|
35 | private IProject mProject; |
---|
36 | |
---|
37 | public PropertyPage() { |
---|
38 | super( GRID); |
---|
39 | |
---|
40 | // Store properties in a volatile preference store |
---|
41 | mStore = new VolatilePreferenceStore(); |
---|
42 | setPreferenceStore( mStore); |
---|
43 | |
---|
44 | 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."); |
---|
45 | } |
---|
46 | |
---|
47 | private void setupStoreValue( IPreferenceStore defaultStore, String key) { |
---|
48 | mStore.setDefault( key, defaultStore.getString( key)); |
---|
49 | mStore.setValue( key, Storage.getProperty( mProject, key)); |
---|
50 | } |
---|
51 | |
---|
52 | protected void createFieldEditors() { |
---|
53 | // Get current project |
---|
54 | mProject = ((IResource) getElement().getAdapter( IResource.class)).getProject(); |
---|
55 | if (mProject == null) { |
---|
56 | mProject = ((ICElement) getElement().getAdapter( ICElement.class)).getCProject().getProject(); |
---|
57 | } |
---|
58 | |
---|
59 | // Get the default values from the current workbench preferences |
---|
60 | IPreferenceStore store = Activator.getDefault().getPreferenceStore(); |
---|
61 | |
---|
62 | // Setup store values |
---|
63 | setupStoreValue( store, Constants.BASE_PATH_KEY); |
---|
64 | setupStoreValue( store, Constants.VERSION_KEY); |
---|
65 | setupStoreValue( store, Constants.TARGET_KEY); |
---|
66 | setupStoreValue( store, Constants.BSP_PATH_KEY); |
---|
67 | |
---|
68 | // Add field editors |
---|
69 | addField( |
---|
70 | new DirectoryFieldEditor( |
---|
71 | Constants.BASE_PATH_KEY, |
---|
72 | "Base path:", |
---|
73 | getFieldEditorParent() |
---|
74 | ) |
---|
75 | ); |
---|
76 | addField( |
---|
77 | new StringFieldEditor( |
---|
78 | Constants.VERSION_KEY, |
---|
79 | "Version:", |
---|
80 | getFieldEditorParent() |
---|
81 | ) |
---|
82 | ); |
---|
83 | addField( |
---|
84 | new ComboFieldEditor( |
---|
85 | Constants.TARGET_KEY, |
---|
86 | "Target:", |
---|
87 | Constants.TARGETS, |
---|
88 | getFieldEditorParent() |
---|
89 | ) |
---|
90 | ); |
---|
91 | addField( |
---|
92 | new DirectoryFieldEditor( |
---|
93 | Constants.BSP_PATH_KEY, |
---|
94 | "BSP path:", |
---|
95 | getFieldEditorParent() |
---|
96 | ) |
---|
97 | ); |
---|
98 | } |
---|
99 | |
---|
100 | private void setProperty( String key) { |
---|
101 | Storage.setProperty( mProject, key, mStore.getString( key)); |
---|
102 | } |
---|
103 | |
---|
104 | public boolean performOk() { |
---|
105 | super.performOk(); |
---|
106 | |
---|
107 | // Set the new properties |
---|
108 | setProperty( Constants.BASE_PATH_KEY); |
---|
109 | setProperty( Constants.VERSION_KEY); |
---|
110 | setProperty( Constants.TARGET_KEY); |
---|
111 | setProperty( Constants.BSP_PATH_KEY); |
---|
112 | |
---|
113 | return true; |
---|
114 | } |
---|
115 | |
---|
116 | public IAdaptable getElement() { |
---|
117 | return mElement; |
---|
118 | } |
---|
119 | |
---|
120 | public void setElement( IAdaptable element) { |
---|
121 | this.mElement = element; |
---|
122 | } |
---|
123 | } |
---|