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