diff options
| author | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 13:36:50 +0100 |
|---|---|---|
| committer | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 15:25:03 +0100 |
| commit | 41ac47d732eed8392d60d0f6773e5a279d49b999 (patch) | |
| tree | cf19d099db9cfdb8d73aa21c31e7aa1cc86ff860 /plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences | |
| download | eclipse-poky-juno-master.tar.gz | |
Migrated from the internal git server on the dora-enea branch
Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences')
5 files changed, 659 insertions, 0 deletions
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/PreferenceConstants.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/PreferenceConstants.java new file mode 100644 index 0000000..0ebbe99 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/PreferenceConstants.java | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2010 Intel Corporation. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Intel - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide.preferences; | ||
| 12 | |||
| 13 | /** | ||
| 14 | * Constant definitions for plug-in preferences | ||
| 15 | */ | ||
| 16 | public class PreferenceConstants { | ||
| 17 | |||
| 18 | public static final String TOOLCHAIN_ROOT = "toolChainRoot"; | ||
| 19 | |||
| 20 | public static final String TARGET_MODE = "TargetMode"; | ||
| 21 | |||
| 22 | public static final String SDK_MODE = "SDKMode"; | ||
| 23 | |||
| 24 | public static final String TARGET_ARCH_INDEX = "targeArchIndex"; | ||
| 25 | |||
| 26 | public static final String TOOLCHAIN_TRIPLET = "toolchainTriplet"; | ||
| 27 | |||
| 28 | public static final String QEMU_KERNEL = "QemuKernel"; | ||
| 29 | |||
| 30 | public static final String QEMU_OPTION = "QemuOption"; | ||
| 31 | |||
| 32 | public static final String SYSROOT = "Sysroot"; | ||
| 33 | |||
| 34 | public static final String IP_ADDR = "IPAddr"; | ||
| 35 | |||
| 36 | public static final String STANDARD_PROFILE_NAME = "Standard Profile"; | ||
| 37 | |||
| 38 | public static final String PROFILES = "profiles"; | ||
| 39 | |||
| 40 | public static final String SELECTED_PROFILE = "selectedProfile"; | ||
| 41 | |||
| 42 | public static final String PROJECT_SPECIFIC_PROFILE = "##PROJECT_SPECIFIC_PROFILE##"; | ||
| 43 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/PreferenceInitializer.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/PreferenceInitializer.java new file mode 100644 index 0000000..40f37d0 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/PreferenceInitializer.java | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2010 Intel Corporation. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Intel - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide.preferences; | ||
| 12 | |||
| 13 | import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; | ||
| 14 | import org.eclipse.jface.preference.IPreferenceStore; | ||
| 15 | |||
| 16 | import org.yocto.sdk.ide.YoctoSDKPlugin; | ||
| 17 | |||
| 18 | import static org.yocto.sdk.ide.preferences.PreferenceConstants.*; | ||
| 19 | |||
| 20 | /** | ||
| 21 | * Class used to initialize default preference values. | ||
| 22 | */ | ||
| 23 | public class PreferenceInitializer extends AbstractPreferenceInitializer { | ||
| 24 | /* | ||
| 25 | * (non-Javadoc) | ||
| 26 | * | ||
| 27 | * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences() | ||
| 28 | */ | ||
| 29 | public void initializeDefaultPreferences() { | ||
| 30 | IPreferenceStore store = YoctoSDKPlugin.getDefault().getPreferenceStore(); | ||
| 31 | store.setDefault(TOOLCHAIN_ROOT, ""); | ||
| 32 | store.setDefault(SDK_MODE, true); | ||
| 33 | store.setDefault(TARGET_MODE, false); | ||
| 34 | store.setDefault(TARGET_ARCH_INDEX, -1); | ||
| 35 | store.setDefault(IP_ADDR, ""); | ||
| 36 | store.setDefault(QEMU_KERNEL, ""); | ||
| 37 | store.setDefault(QEMU_OPTION, ""); | ||
| 38 | store.setDefault(SYSROOT, ""); | ||
| 39 | store.setDefault(TOOLCHAIN_TRIPLET, ""); | ||
| 40 | store.setDefault(PROFILES, "\"" + STANDARD_PROFILE_NAME + "\""); | ||
| 41 | store.setDefault(SELECTED_PROFILE, STANDARD_PROFILE_NAME); | ||
| 42 | } | ||
| 43 | |||
| 44 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/ProfileNameInputValidator.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/ProfileNameInputValidator.java new file mode 100644 index 0000000..38e38b1 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/ProfileNameInputValidator.java | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2012 BMW Car IT GmbH. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * BMW Car IT - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide.preferences; | ||
| 12 | |||
| 13 | import org.eclipse.jface.dialogs.IInputValidator; | ||
| 14 | import org.yocto.sdk.ide.YoctoProfileElement; | ||
| 15 | import org.yocto.sdk.ide.YoctoSDKMessages; | ||
| 16 | |||
| 17 | public class ProfileNameInputValidator implements IInputValidator { | ||
| 18 | private static final String WARNING_CONTAINS_COMMA = "Preferences.Profile.Validator.InvalidName.Comma"; | ||
| 19 | private static final String WARNING_CONTAINS_DOUBLEQUOTE = "Preferences.Profile.Validator.InvalidName.Quote"; | ||
| 20 | private static final String PROFILE_NAME_IS_EMPTY = "Preferences.Profile.Validator.InvalidName.Empty"; | ||
| 21 | private static final String WARNING_ALREADY_EXISTS = "Preferences.Profile.Validator.InvalidName.Exists"; | ||
| 22 | |||
| 23 | private final String selectedItem; | ||
| 24 | private final YoctoProfileElement profileSetting; | ||
| 25 | |||
| 26 | public ProfileNameInputValidator(YoctoProfileElement profileSetting) { | ||
| 27 | this(profileSetting, ""); | ||
| 28 | } | ||
| 29 | |||
| 30 | public ProfileNameInputValidator(YoctoProfileElement profileSetting, String selectedItem) { | ||
| 31 | this.selectedItem = selectedItem; | ||
| 32 | this.profileSetting = profileSetting; | ||
| 33 | } | ||
| 34 | |||
| 35 | @Override | ||
| 36 | public String isValid(String newText) { | ||
| 37 | if (newText.contains(",")) { | ||
| 38 | return YoctoSDKMessages.getString(WARNING_CONTAINS_COMMA); | ||
| 39 | } | ||
| 40 | |||
| 41 | if (newText.contains("\"")) { | ||
| 42 | return YoctoSDKMessages.getString(WARNING_CONTAINS_DOUBLEQUOTE); | ||
| 43 | } | ||
| 44 | |||
| 45 | if (newText.isEmpty()) { | ||
| 46 | return YoctoSDKMessages.getString(PROFILE_NAME_IS_EMPTY); | ||
| 47 | } | ||
| 48 | |||
| 49 | if (selectedItemEquals(newText)) { | ||
| 50 | return null; | ||
| 51 | } | ||
| 52 | |||
| 53 | if (profileSetting.contains(newText)) { | ||
| 54 | return YoctoSDKMessages.getString(WARNING_ALREADY_EXISTS); | ||
| 55 | } | ||
| 56 | |||
| 57 | return null; | ||
| 58 | } | ||
| 59 | |||
| 60 | private boolean selectedItemEquals(String newText) { | ||
| 61 | return !selectedItem.isEmpty() && newText.equals(selectedItem); | ||
| 62 | } | ||
| 63 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/YoctoSDKPreferencePage.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/YoctoSDKPreferencePage.java new file mode 100644 index 0000000..4e6ca2a --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/YoctoSDKPreferencePage.java | |||
| @@ -0,0 +1,307 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2010 Intel Corporation. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Intel - initial API and implementation | ||
| 10 | *******************************************************************************/ | ||
| 11 | package org.yocto.sdk.ide.preferences; | ||
| 12 | |||
| 13 | import java.util.HashSet; | ||
| 14 | |||
| 15 | import org.eclipse.core.resources.IProject; | ||
| 16 | import org.eclipse.core.resources.ResourcesPlugin; | ||
| 17 | import org.eclipse.core.runtime.CoreException; | ||
| 18 | import org.eclipse.jface.dialogs.Dialog; | ||
| 19 | import org.eclipse.jface.dialogs.IDialogConstants; | ||
| 20 | import org.eclipse.jface.dialogs.InputDialog; | ||
| 21 | import org.eclipse.jface.dialogs.MessageDialog; | ||
| 22 | import org.eclipse.jface.preference.IPreferenceStore; | ||
| 23 | import org.eclipse.jface.preference.PreferencePage; | ||
| 24 | import org.eclipse.swt.SWT; | ||
| 25 | import org.eclipse.swt.layout.GridLayout; | ||
| 26 | import org.eclipse.swt.widgets.Composite; | ||
| 27 | import org.eclipse.swt.widgets.Control; | ||
| 28 | import org.eclipse.swt.widgets.Event; | ||
| 29 | import org.eclipse.swt.widgets.Listener; | ||
| 30 | import org.eclipse.ui.IWorkbench; | ||
| 31 | import org.eclipse.ui.IWorkbenchPreferencePage; | ||
| 32 | import org.yocto.sdk.ide.YoctoProfileElement; | ||
| 33 | import org.yocto.sdk.ide.YoctoProfileSetting; | ||
| 34 | import org.yocto.sdk.ide.YoctoSDKChecker.SDKCheckRequestFrom; | ||
| 35 | import org.yocto.sdk.ide.YoctoSDKChecker.SDKCheckResults; | ||
| 36 | import org.yocto.sdk.ide.natures.YoctoSDKProjectNature; | ||
| 37 | import org.yocto.sdk.ide.utils.ProjectPreferenceUtils; | ||
| 38 | import org.yocto.sdk.ide.utils.YoctoSDKUtils; | ||
| 39 | import org.yocto.sdk.ide.YoctoSDKMessages; | ||
| 40 | import org.yocto.sdk.ide.YoctoSDKPlugin; | ||
| 41 | import org.yocto.sdk.ide.YoctoUIElement; | ||
| 42 | import org.yocto.sdk.ide.YoctoUISetting; | ||
| 43 | |||
| 44 | public class YoctoSDKPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { | ||
| 45 | |||
| 46 | private static final String NEW_DIALOG_TITLE = "Preferences.Profile.New.Dialog.Title"; | ||
| 47 | private static final String NEW_DIALOG_MESSAGE = "Preferences.Profile.New.Dialog.Message"; | ||
| 48 | private static final String UPDATE_DIALOG_TITLE = "Preferences.Profile.Update.Dialog.Title"; | ||
| 49 | private static final String UPDATE_DIALOG_MESSAGE = "Preferences.Profile.Update.Dialog.Message"; | ||
| 50 | private static final String REVALIDATION_MESSAGE = "Poky.SDK.Revalidation.Message"; | ||
| 51 | |||
| 52 | private YoctoProfileSetting yoctoProfileSetting; | ||
| 53 | private YoctoUISetting yoctoUISetting; | ||
| 54 | |||
| 55 | private Listener changeListener; | ||
| 56 | |||
| 57 | public YoctoSDKPreferencePage() { | ||
| 58 | //super(GRID); | ||
| 59 | IPreferenceStore defaultStore = YoctoSDKPlugin.getDefault().getPreferenceStore(); | ||
| 60 | String profiles = defaultStore.getString(PreferenceConstants.PROFILES); | ||
| 61 | String selectedProfile = defaultStore.getString(PreferenceConstants.SELECTED_PROFILE); | ||
| 62 | |||
| 63 | if (profiles.isEmpty()) { | ||
| 64 | profiles = defaultStore.getDefaultString(PreferenceConstants.PROFILES); | ||
| 65 | selectedProfile = defaultStore.getDefaultString(PreferenceConstants.SELECTED_PROFILE); | ||
| 66 | } | ||
| 67 | |||
| 68 | setPreferenceStore(YoctoSDKPlugin.getProfilePreferenceStore(selectedProfile)); | ||
| 69 | //setDescription(YoctoSDKMessages.getString(PREFERENCES_Yocto_CONFIG)); | ||
| 70 | YoctoUIElement elem = YoctoSDKUtils.getElemFromStore(getPreferenceStore()); | ||
| 71 | this.yoctoUISetting = new YoctoUISetting(elem); | ||
| 72 | |||
| 73 | YoctoProfileElement profileElement = new YoctoProfileElement(profiles, selectedProfile); | ||
| 74 | this.yoctoProfileSetting = new YoctoProfileSetting(profileElement, this, true); | ||
| 75 | |||
| 76 | changeListener = new Listener() { | ||
| 77 | @Override | ||
| 78 | public void handleEvent(Event event) { | ||
| 79 | setErrorMessage(null); | ||
| 80 | setMessage(YoctoSDKMessages.getString(REVALIDATION_MESSAGE), INFORMATION); | ||
| 81 | } | ||
| 82 | }; | ||
| 83 | } | ||
| 84 | |||
| 85 | /* | ||
| 86 | * @see IWorkbenchPreferencePage#init(IWorkbench) | ||
| 87 | */ | ||
| 88 | public void init(IWorkbench workbench) { | ||
| 89 | } | ||
| 90 | |||
| 91 | protected Control createContents(Composite parent) { | ||
| 92 | initializeDialogUnits(parent); | ||
| 93 | final Composite composite= new Composite(parent, SWT.NONE); | ||
| 94 | composite.setLayout(new GridLayout(2, false)); | ||
| 95 | |||
| 96 | yoctoProfileSetting.createComposite(composite); | ||
| 97 | yoctoUISetting.createComposite(composite); | ||
| 98 | |||
| 99 | composite.addListener(SWT.Modify, changeListener); | ||
| 100 | composite.addListener(SWT.Selection, changeListener); | ||
| 101 | |||
| 102 | SDKCheckResults result = yoctoUISetting.validateInput(SDKCheckRequestFrom.Preferences, false); | ||
| 103 | if (result != SDKCheckResults.SDK_PASS) { | ||
| 104 | } | ||
| 105 | |||
| 106 | Dialog.applyDialogFont(composite); | ||
| 107 | return composite; | ||
| 108 | } | ||
| 109 | |||
| 110 | /* | ||
| 111 | * @see IPreferencePage#performOk() | ||
| 112 | */ | ||
| 113 | public boolean performOk() { | ||
| 114 | clearMessages(); | ||
| 115 | |||
| 116 | SDKCheckResults result = yoctoUISetting.validateInput(SDKCheckRequestFrom.Preferences, false); | ||
| 117 | if (result != SDKCheckResults.SDK_PASS) { | ||
| 118 | setErrorMessage(result.getMessage()); | ||
| 119 | return false; | ||
| 120 | } | ||
| 121 | |||
| 122 | YoctoUIElement savedElement = YoctoSDKUtils.getElemFromStore(getPreferenceStore()); | ||
| 123 | YoctoUIElement modifiedElement = yoctoUISetting.getCurrentInput(); | ||
| 124 | |||
| 125 | YoctoProfileElement savedProfileElement = YoctoSDKUtils.getProfilesFromDefaultStore(); | ||
| 126 | YoctoProfileElement profileElement = yoctoProfileSetting.getCurrentInput(); | ||
| 127 | |||
| 128 | if (savedElement.equals(modifiedElement) && | ||
| 129 | profileElement.getSelectedProfile().equals(savedProfileElement.getSelectedProfile())) { | ||
| 130 | return true; | ||
| 131 | } | ||
| 132 | |||
| 133 | HashSet<IProject> yoctoProjects = getAffectedProjects(profileElement.getSelectedProfile()); | ||
| 134 | |||
| 135 | if (!yoctoProjects.isEmpty()) { | ||
| 136 | boolean deleteConfirmed = | ||
| 137 | MessageDialog.openConfirm(null, YoctoSDKMessages.getString(UPDATE_DIALOG_TITLE), | ||
| 138 | YoctoSDKMessages.getFormattedString(UPDATE_DIALOG_MESSAGE, profileElement.getSelectedProfile())); | ||
| 139 | |||
| 140 | if (!deleteConfirmed) { | ||
| 141 | return false; | ||
| 142 | } | ||
| 143 | } | ||
| 144 | |||
| 145 | saveElemToStore(modifiedElement, getPreferenceStore()); | ||
| 146 | YoctoSDKUtils.saveProfilesToDefaultStore(profileElement); | ||
| 147 | |||
| 148 | updateProjects(yoctoProjects, modifiedElement); | ||
| 149 | |||
| 150 | return super.performOk(); | ||
| 151 | } | ||
| 152 | |||
| 153 | private void clearMessages() { | ||
| 154 | setErrorMessage(null); | ||
| 155 | setMessage(null); | ||
| 156 | setTitle(getTitle()); | ||
| 157 | } | ||
| 158 | |||
| 159 | /* | ||
| 160 | * @see PreferencePage#performDefaults() | ||
| 161 | */ | ||
| 162 | protected void performDefaults() { | ||
| 163 | YoctoUIElement defaultElement = YoctoSDKUtils.getDefaultElemFromDefaultStore(); | ||
| 164 | yoctoUISetting.setCurrentInput(defaultElement); | ||
| 165 | super.performDefaults(); | ||
| 166 | } | ||
| 167 | |||
| 168 | public void performSaveAs() { | ||
| 169 | YoctoProfileElement profileElement = yoctoProfileSetting.getCurrentInput(); | ||
| 170 | YoctoUIElement uiElement = yoctoUISetting.getCurrentInput(); | ||
| 171 | |||
| 172 | SDKCheckResults result = yoctoUISetting.validateInput(SDKCheckRequestFrom.Preferences, true); | ||
| 173 | if (result != SDKCheckResults.SDK_PASS) { | ||
| 174 | setErrorMessage(result.getMessage()); | ||
| 175 | return; | ||
| 176 | } | ||
| 177 | |||
| 178 | InputDialog profileNameDialog = | ||
| 179 | new InputDialog(null, | ||
| 180 | YoctoSDKMessages.getString(NEW_DIALOG_TITLE), | ||
| 181 | YoctoSDKMessages.getString(NEW_DIALOG_MESSAGE), | ||
| 182 | null, | ||
| 183 | new ProfileNameInputValidator(profileElement)); | ||
| 184 | |||
| 185 | int returnCode = profileNameDialog.open(); | ||
| 186 | if (returnCode == IDialogConstants.CANCEL_ID) { | ||
| 187 | return; | ||
| 188 | } | ||
| 189 | |||
| 190 | profileElement.addProfile(profileNameDialog.getValue()); | ||
| 191 | yoctoProfileSetting.addProfile(profileNameDialog.getValue()); | ||
| 192 | |||
| 193 | yoctoUISetting.setCurrentInput(uiElement); | ||
| 194 | performOk(); | ||
| 195 | } | ||
| 196 | |||
| 197 | public void switchProfile(String selectedProfile) { | ||
| 198 | setPreferenceStore(YoctoSDKPlugin.getProfilePreferenceStore(selectedProfile)); | ||
| 199 | YoctoUIElement profileElement = YoctoSDKUtils.getElemFromStore(getPreferenceStore()); | ||
| 200 | yoctoUISetting.setCurrentInput(profileElement); | ||
| 201 | } | ||
| 202 | |||
| 203 | public void renameProfile(String oldProfileName, String newProfileName) { | ||
| 204 | YoctoUIElement oldProfileElement = YoctoSDKUtils.getElemFromStore(YoctoSDKPlugin.getProfilePreferenceStore(oldProfileName)); | ||
| 205 | saveElemToStore(oldProfileElement, YoctoSDKPlugin.getProfilePreferenceStore(newProfileName)); | ||
| 206 | |||
| 207 | renameProfileInAffectedProjects(oldProfileName, newProfileName); | ||
| 208 | } | ||
| 209 | |||
| 210 | public void deleteProfile(String selectedProfile) | ||
| 211 | { | ||
| 212 | resetProfileInAffectedProjects(selectedProfile); | ||
| 213 | } | ||
| 214 | |||
| 215 | /* Save IDE wide POKY Preference settings to a specific preference store */ | ||
| 216 | private void saveElemToStore(YoctoUIElement elem, IPreferenceStore store) { | ||
| 217 | store.setValue(PreferenceConstants.TARGET_ARCH_INDEX, elem.getIntTargetIndex()); | ||
| 218 | |||
| 219 | if (elem.getEnumPokyMode() == YoctoUIElement.PokyMode.POKY_SDK_MODE) { | ||
| 220 | store.setValue(PreferenceConstants.SDK_MODE, IPreferenceStore.TRUE); | ||
| 221 | } else { | ||
| 222 | store.setValue(PreferenceConstants.SDK_MODE, IPreferenceStore.FALSE); | ||
| 223 | } | ||
| 224 | store.setValue(PreferenceConstants.QEMU_KERNEL, elem.getStrQemuKernelLoc()); | ||
| 225 | store.setValue(PreferenceConstants.QEMU_OPTION, elem.getStrQemuOption()); | ||
| 226 | store.setValue(PreferenceConstants.SYSROOT, elem.getStrSysrootLoc()); | ||
| 227 | if (elem.getEnumDeviceMode() == YoctoUIElement.DeviceMode.QEMU_MODE) { | ||
| 228 | store.setValue(PreferenceConstants.TARGET_MODE, IPreferenceStore.TRUE); | ||
| 229 | } else { | ||
| 230 | store.setValue(PreferenceConstants.TARGET_MODE, IPreferenceStore.FALSE); | ||
| 231 | } | ||
| 232 | store.setValue(PreferenceConstants.TOOLCHAIN_ROOT, elem.getStrToolChainRoot()); | ||
| 233 | store.setValue(PreferenceConstants.TOOLCHAIN_TRIPLET, elem.getStrTarget()); | ||
| 234 | } | ||
| 235 | |||
| 236 | private void resetProfileInAffectedProjects(String usedProfile) | ||
| 237 | { | ||
| 238 | HashSet<IProject> yoctoProjects = getAffectedProjects(usedProfile); | ||
| 239 | YoctoProfileElement profileElement = YoctoSDKUtils.getProfilesFromDefaultStore(); | ||
| 240 | profileElement.setSelectedProfile(PreferenceConstants.STANDARD_PROFILE_NAME); | ||
| 241 | |||
| 242 | for (IProject project : yoctoProjects) | ||
| 243 | { | ||
| 244 | ProjectPreferenceUtils.saveProfiles(profileElement, project); | ||
| 245 | YoctoUIElement elem = YoctoSDKUtils.getElemFromStore( | ||
| 246 | YoctoSDKPlugin.getProfilePreferenceStore(PreferenceConstants.STANDARD_PROFILE_NAME)); | ||
| 247 | ProjectPreferenceUtils.saveElemToProjectEnv(elem, project); | ||
| 248 | } | ||
| 249 | } | ||
| 250 | |||
| 251 | private void renameProfileInAffectedProjects(String oldProfileName, String newProfileName) { | ||
| 252 | HashSet<IProject> yoctoProjects = getAffectedProjects(oldProfileName); | ||
| 253 | YoctoProfileElement profileElement = YoctoSDKUtils.getProfilesFromDefaultStore(); | ||
| 254 | profileElement.setSelectedProfile(newProfileName); | ||
| 255 | |||
| 256 | for (IProject project : yoctoProjects) | ||
| 257 | { | ||
| 258 | ProjectPreferenceUtils.saveProfiles(profileElement, project); | ||
| 259 | } | ||
| 260 | } | ||
| 261 | |||
| 262 | private void updateProjects(HashSet<IProject> yoctoProjects, YoctoUIElement elem) { | ||
| 263 | for (IProject project : yoctoProjects) | ||
| 264 | { | ||
| 265 | ProjectPreferenceUtils.saveElemToProjectEnv(elem, project); | ||
| 266 | } | ||
| 267 | } | ||
| 268 | |||
| 269 | private HashSet<IProject> getAffectedProjects(String usedProfile) | ||
| 270 | { | ||
| 271 | HashSet<IProject> yoctoProjects = new HashSet<IProject>(); | ||
| 272 | |||
| 273 | IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); | ||
| 274 | |||
| 275 | for (IProject project : projects) | ||
| 276 | { | ||
| 277 | try | ||
| 278 | { | ||
| 279 | if (!project.hasNature(YoctoSDKProjectNature.YoctoSDK_NATURE_ID)) { | ||
| 280 | continue; | ||
| 281 | } | ||
| 282 | } catch (CoreException e) | ||
| 283 | { | ||
| 284 | // project is closed or does not exist so don't update | ||
| 285 | continue; | ||
| 286 | } | ||
| 287 | |||
| 288 | if (!projectUsesProfile(project, usedProfile)) { | ||
| 289 | continue; | ||
| 290 | } | ||
| 291 | |||
| 292 | yoctoProjects.add(project); | ||
| 293 | } | ||
| 294 | return yoctoProjects; | ||
| 295 | } | ||
| 296 | |||
| 297 | private boolean projectUsesProfile(IProject project, String profile) | ||
| 298 | { | ||
| 299 | YoctoProfileElement profileElement = ProjectPreferenceUtils.getProfiles(project); | ||
| 300 | |||
| 301 | if (!profileElement.getSelectedProfile().equals(profile)) { | ||
| 302 | return false; | ||
| 303 | } | ||
| 304 | |||
| 305 | return true; | ||
| 306 | } | ||
| 307 | } | ||
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/YoctoSDKProjectPropertyPage.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/YoctoSDKProjectPropertyPage.java new file mode 100644 index 0000000..a85cbd9 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/YoctoSDKProjectPropertyPage.java | |||
| @@ -0,0 +1,202 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2012 BMW Car IT GmbH. | ||
| 3 | * Copyright (c) 2010 Intel. | ||
| 4 | * All rights reserved. This program and the accompanying materials | ||
| 5 | * are made available under the terms of the Eclipse Public License v1.0 | ||
| 6 | * which accompanies this distribution, and is available at | ||
| 7 | * http://www.eclipse.org/legal/epl-v10.html | ||
| 8 | * | ||
| 9 | * Contributors: | ||
| 10 | * BMW Car IT GmbH - initial implementation | ||
| 11 | * Intel - initial API implementation (copied from YoctoSDKPreferencePage) | ||
| 12 | *******************************************************************************/ | ||
| 13 | package org.yocto.sdk.ide.preferences; | ||
| 14 | |||
| 15 | import org.eclipse.core.resources.IProject; | ||
| 16 | import org.eclipse.core.runtime.IAdaptable; | ||
| 17 | import org.eclipse.jface.dialogs.Dialog; | ||
| 18 | import org.eclipse.swt.SWT; | ||
| 19 | import org.eclipse.swt.layout.GridLayout; | ||
| 20 | import org.eclipse.swt.widgets.Composite; | ||
| 21 | import org.eclipse.swt.widgets.Control; | ||
| 22 | import org.eclipse.swt.widgets.Event; | ||
| 23 | import org.eclipse.swt.widgets.Listener; | ||
| 24 | import org.eclipse.ui.IWorkbenchPropertyPage; | ||
| 25 | import org.eclipse.ui.dialogs.PropertyPage; | ||
| 26 | import org.yocto.sdk.ide.YoctoProfileElement; | ||
| 27 | import org.yocto.sdk.ide.YoctoProfileSetting; | ||
| 28 | import org.yocto.sdk.ide.YoctoProjectSpecificSetting; | ||
| 29 | import org.yocto.sdk.ide.YoctoSDKChecker; | ||
| 30 | import org.yocto.sdk.ide.YoctoSDKChecker.SDKCheckRequestFrom; | ||
| 31 | import org.yocto.sdk.ide.YoctoSDKChecker.SDKCheckResults; | ||
| 32 | import org.yocto.sdk.ide.YoctoSDKMessages; | ||
| 33 | import org.yocto.sdk.ide.YoctoSDKPlugin; | ||
| 34 | import org.yocto.sdk.ide.YoctoUIElement; | ||
| 35 | import org.yocto.sdk.ide.YoctoUISetting; | ||
| 36 | import org.yocto.sdk.ide.utils.ProjectPreferenceUtils; | ||
| 37 | import org.yocto.sdk.ide.utils.YoctoSDKUtils; | ||
| 38 | |||
| 39 | public class YoctoSDKProjectPropertyPage extends PropertyPage implements | ||
| 40 | IWorkbenchPropertyPage { | ||
| 41 | |||
| 42 | private static final String REVALIDATION_MESSAGE = "Poky.SDK.Revalidation.Message"; | ||
| 43 | |||
| 44 | private YoctoProfileSetting yoctoProfileSetting; | ||
| 45 | private YoctoProjectSpecificSetting yoctoProjectSpecificSetting; | ||
| 46 | private YoctoUISetting yoctoUISetting; | ||
| 47 | private IProject project = null; | ||
| 48 | |||
| 49 | private Listener changeListener; | ||
| 50 | |||
| 51 | public YoctoSDKProjectPropertyPage() { | ||
| 52 | changeListener = new Listener() { | ||
| 53 | @Override | ||
| 54 | public void handleEvent(Event event) { | ||
| 55 | if (getErrorMessage() != null) { | ||
| 56 | setErrorMessage(null); | ||
| 57 | setMessage(YoctoSDKMessages.getString(REVALIDATION_MESSAGE), INFORMATION); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | }; | ||
| 61 | } | ||
| 62 | |||
| 63 | @Override | ||
| 64 | protected Control createContents(Composite parent) { | ||
| 65 | IProject project = getProject(); | ||
| 66 | |||
| 67 | YoctoProfileElement globalProfileElement= YoctoSDKUtils.getProfilesFromDefaultStore(); | ||
| 68 | YoctoProfileElement profileElement = ProjectPreferenceUtils.getProfiles(project); | ||
| 69 | |||
| 70 | String selectedProfile = profileElement.getSelectedProfile(); | ||
| 71 | if (!globalProfileElement.contains(selectedProfile)) { | ||
| 72 | selectedProfile = globalProfileElement.getSelectedProfile(); | ||
| 73 | } | ||
| 74 | |||
| 75 | yoctoProfileSetting = new YoctoProfileSetting( | ||
| 76 | new YoctoProfileElement(globalProfileElement.getProfilesAsString(), selectedProfile), this, false); | ||
| 77 | boolean useProjectSpecificSetting = ProjectPreferenceUtils.getUseProjectSpecificOption(project); | ||
| 78 | |||
| 79 | if (useProjectSpecificSetting) { | ||
| 80 | yoctoUISetting = new YoctoUISetting(ProjectPreferenceUtils.getElem(project)); | ||
| 81 | } else { | ||
| 82 | yoctoUISetting = new YoctoUISetting(YoctoSDKUtils.getElemFromStore(YoctoSDKPlugin.getProfilePreferenceStore(selectedProfile))); | ||
| 83 | } | ||
| 84 | |||
| 85 | yoctoProjectSpecificSetting = new YoctoProjectSpecificSetting(yoctoProfileSetting, yoctoUISetting, this); | ||
| 86 | |||
| 87 | initializeDialogUnits(parent); | ||
| 88 | final Composite composite = new Composite(parent, SWT.NONE); | ||
| 89 | composite.setLayout(new GridLayout(2, false)); | ||
| 90 | |||
| 91 | yoctoProfileSetting.createComposite(composite); | ||
| 92 | yoctoProjectSpecificSetting.createComposite(composite); | ||
| 93 | yoctoUISetting.createComposite(composite); | ||
| 94 | |||
| 95 | if (useProjectSpecificSetting) { | ||
| 96 | yoctoProfileSetting.setUIFormEnabledState(false); | ||
| 97 | yoctoProjectSpecificSetting.setUseProjectSpecificSettings(true); | ||
| 98 | yoctoUISetting.setUIFormEnabledState(true); | ||
| 99 | |||
| 100 | SDKCheckResults result = yoctoUISetting.validateInput(SDKCheckRequestFrom.Preferences, false); | ||
| 101 | if (result != SDKCheckResults.SDK_PASS) { | ||
| 102 | setErrorMessage(result.getMessage()); | ||
| 103 | } | ||
| 104 | } else { | ||
| 105 | yoctoProfileSetting.setUIFormEnabledState(true); | ||
| 106 | yoctoProjectSpecificSetting.setUseProjectSpecificSettings(false); | ||
| 107 | yoctoUISetting.setUIFormEnabledState(false); | ||
| 108 | } | ||
| 109 | |||
| 110 | composite.addListener(SWT.Modify, changeListener); | ||
| 111 | composite.addListener(SWT.Selection, changeListener); | ||
| 112 | |||
| 113 | Dialog.applyDialogFont(composite); | ||
| 114 | return composite; | ||
| 115 | } | ||
| 116 | |||
| 117 | private IProject getProject() { | ||
| 118 | if (project != null) { | ||
| 119 | return project; | ||
| 120 | } | ||
| 121 | |||
| 122 | IAdaptable adaptable = getElement(); | ||
| 123 | if (adaptable == null) { | ||
| 124 | throw new IllegalStateException("Project can only be retrieved after properties page has been set up."); | ||
| 125 | } | ||
| 126 | |||
| 127 | project = (IProject) adaptable.getAdapter(IProject.class); | ||
| 128 | return project; | ||
| 129 | } | ||
| 130 | |||
| 131 | /* | ||
| 132 | * @see PreferencePage#performDefaults() | ||
| 133 | */ | ||
| 134 | @Override | ||
| 135 | protected void performDefaults() { | ||
| 136 | YoctoUIElement defaultElement = YoctoSDKUtils.getDefaultElemFromDefaultStore(); | ||
| 137 | yoctoUISetting.setCurrentInput(defaultElement); | ||
| 138 | yoctoProjectSpecificSetting.setUseProjectSpecificSettings(true); | ||
| 139 | super.performDefaults(); | ||
| 140 | } | ||
| 141 | |||
| 142 | /* | ||
| 143 | * @see IPreferencePage#performOk() | ||
| 144 | */ | ||
| 145 | @Override | ||
| 146 | public boolean performOk() { | ||
| 147 | clearMessages(); | ||
| 148 | |||
| 149 | IProject project = getProject(); | ||
| 150 | |||
| 151 | if (yoctoProjectSpecificSetting.isUsingProjectSpecificSettings()) { | ||
| 152 | SDKCheckResults result = yoctoUISetting.validateInput(SDKCheckRequestFrom.Preferences, false); | ||
| 153 | if (result != SDKCheckResults.SDK_PASS) { | ||
| 154 | setErrorMessage(result.getMessage()); | ||
| 155 | return false; | ||
| 156 | } | ||
| 157 | |||
| 158 | ProjectPreferenceUtils.saveUseProjectSpecificOption(project, true); | ||
| 159 | ProjectPreferenceUtils.saveProfiles(yoctoProfileSetting.getCurrentInput(), project); | ||
| 160 | ProjectPreferenceUtils.saveElem(yoctoUISetting.getCurrentInput(), project); | ||
| 161 | } else { | ||
| 162 | ProjectPreferenceUtils.saveUseProjectSpecificOption(project, false); | ||
| 163 | ProjectPreferenceUtils.saveProfiles(yoctoProfileSetting.getCurrentInput(), project); | ||
| 164 | } | ||
| 165 | |||
| 166 | ProjectPreferenceUtils.saveElemToProjectEnv(yoctoUISetting.getCurrentInput(), getProject()); | ||
| 167 | |||
| 168 | return super.performOk(); | ||
| 169 | } | ||
| 170 | |||
| 171 | private void clearMessages() { | ||
| 172 | setErrorMessage(null); | ||
| 173 | setMessage(null); | ||
| 174 | setTitle(getTitle()); | ||
| 175 | } | ||
| 176 | |||
| 177 | public void switchProfile(String selectedProfile) | ||
| 178 | { | ||
| 179 | YoctoUIElement profileElement = YoctoSDKUtils.getElemFromStore(YoctoSDKPlugin.getProfilePreferenceStore(selectedProfile)); | ||
| 180 | yoctoUISetting.setCurrentInput(profileElement); | ||
| 181 | } | ||
| 182 | |||
| 183 | public void switchToProjectSpecificProfile() | ||
| 184 | { | ||
| 185 | YoctoUIElement profileElement = ProjectPreferenceUtils.getElem(getProject()); | ||
| 186 | SDKCheckResults result = YoctoSDKChecker.checkYoctoSDK(profileElement); | ||
| 187 | |||
| 188 | if ((result != SDKCheckResults.SDK_PASS)) { | ||
| 189 | /* Project specific profile has not yet been defined, | ||
| 190 | * leave settings from previously selected profile | ||
| 191 | */ | ||
| 192 | return; | ||
| 193 | } | ||
| 194 | |||
| 195 | yoctoUISetting.setCurrentInput(profileElement); | ||
| 196 | } | ||
| 197 | |||
| 198 | public void switchToSelectedProfile() | ||
| 199 | { | ||
| 200 | switchProfile(yoctoProfileSetting.getCurrentInput().getSelectedProfile()); | ||
| 201 | } | ||
| 202 | } | ||
