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.rtems.cdt.Activator; |
---|
25 | import org.rtems.cdt.Constants; |
---|
26 | import org.rtems.cdt.Storage; |
---|
27 | import org.rtems.cdt.VolatilePreferenceStore; |
---|
28 | |
---|
29 | public 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 | } |
---|