| author | Camilo Bernal | 2012-08-09 13:26:57 (EDT) |
|---|---|---|
| committer | Roland Grunberg | 2012-08-16 16:14:55 (EDT) |
| commit | dbdd5f7ef802da99546dc60e9be2feb873be7543 (patch) (side-by-side diff) | |
| tree | cd0adc7e1983a6673eb05bbcdaaae51b65abd85a | |
| parent | 24d9b24c680d0b5c163acbd1307772527484d5ac (diff) | |
| download | org.eclipse.linuxtools-dbdd5f7ef802da99546dc60e9be2feb873be7543.zip org.eclipse.linuxtools-dbdd5f7ef802da99546dc60e9be2feb873be7543.tar.gz org.eclipse.linuxtools-dbdd5f7ef802da99546dc60e9be2feb873be7543.tar.bz2 | |
Add preferences page to launch provider.
Use ScopedPreferencesStore to store preferences.
Added preferences page for launch provider in order to specify a default
plug-in for the specific profiling type. An IScopeContext instance is
used to create an IPreferenceStore where preferences are stored and
retrieved.
Change-Id: Ib8b25847c273c85c4cd8792f6a1d7a6d80cd2980
Reviewed-on: https://git.eclipse.org/r/7166
Reviewed-by: Roland Grunberg <rgrunber@redhat.com>
IP-Clean: Roland Grunberg <rgrunber@redhat.com>
Tested-by: Roland Grunberg <rgrunber@redhat.com>
5 files changed, 121 insertions, 1 deletions
diff --git a/profiling/org.eclipse.linuxtools.profiling.snapshot/plugin.xml b/profiling/org.eclipse.linuxtools.profiling.snapshot/plugin.xml index 745ddde..c6ff06f 100644 --- a/profiling/org.eclipse.linuxtools.profiling.snapshot/plugin.xml +++ b/profiling/org.eclipse.linuxtools.profiling.snapshot/plugin.xml @@ -68,6 +68,14 @@ public="true"> </launchConfigurationType> </extension> + <extension + point="org.eclipse.ui.preferencePages"> + <page + class="org.eclipse.linuxtools.profiling.snapshot.SnapshotPreferencesPage" + id="org.eclipse.linuxtools.profiling.snapshot.MainPreferencePage" + name="Profiling"> + </page> + </extension> </plugin> diff --git a/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/SnapshotPreferencesPage.java b/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/SnapshotPreferencesPage.java new file mode 100644 index 0000000..d450c75 --- a/dev/null +++ b/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/SnapshotPreferencesPage.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.profiling.snapshot; + +import java.util.HashMap; +import java.util.Map.Entry; + +import org.eclipse.core.runtime.preferences.ConfigurationScope; +import org.eclipse.core.runtime.preferences.IScopeContext; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.RadioGroupFieldEditor; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; +import org.eclipse.ui.preferences.ScopedPreferenceStore; +import org.eclipse.linuxtools.profiling.launch.ProfileLaunchConfigurationTabGroup; +import org.eclipse.linuxtools.profiling.launch.ProfileLaunchShortcut; +import org.eclipse.linuxtools.profiling.snapshot.launch.Messages; + +public class SnapshotPreferencesPage extends FieldEditorPreferencePage + implements IWorkbenchPreferencePage { + + private static final String TYPE = "snapshot"; //$NON-NLS-1$ + private static final String KEY = "provider"; //$NON-NLS-1$ + private static final String QUALIFIER = "org.eclipse.linuxtools.profiling.snapshot"; //$NON-NLS-1$ + private static IScopeContext configScopeInstance = ConfigurationScope.INSTANCE; + + public void init(IWorkbench workbench) { + final IPreferenceStore store = new ScopedPreferenceStore( + configScopeInstance, QUALIFIER); + setPreferenceStore(store); + setDescription(Messages.SnapshotPreferencesPage_0); + } + + @Override + protected void createFieldEditors() { + HashMap<String, String> map = ProfileLaunchConfigurationTabGroup + .getProviderNamesForType(TYPE); + // 2d array containing launch provider names on the first column and + // corresponding id's on the second. + String[][] providerList = new String[map.size()][2]; + int i = 0; + for (Entry<String, String> entry : map.entrySet()) { + providerList[i][0] = entry.getKey(); + providerList[i][1] = entry.getValue(); + i++; + } + RadioGroupFieldEditor editor = new RadioGroupFieldEditor(KEY, + Messages.SnapshotPreferencesPage_1, 1, providerList, + getFieldEditorParent()); + addField(editor); + } + + public SnapshotPreferencesPage() { + super(GRID); + } + + public void initializeDefaultPreferences() { + super.performDefaults(); + String providerId = ProfileLaunchShortcut + .getDefaultLaunchShortcutProviderId(TYPE); + configScopeInstance.getNode(QUALIFIER).put(KEY, providerId); + } + + /** + * Get id of launch provider in the preference store. + * + * @return unique launch provider identifier. + * @since 1.2 + */ + public static String getSelectedProviderId() { + return configScopeInstance.getNode(QUALIFIER).get(KEY, ""); + + } +}
\ No newline at end of file diff --git a/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/launch/Messages.java b/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/launch/Messages.java index 3c37b3f..eb41749 100644 --- a/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/launch/Messages.java +++ b/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/launch/Messages.java @@ -15,6 +15,8 @@ import org.eclipse.osgi.util.NLS; public class Messages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.linuxtools.profiling.snapshot.launch.messages"; //$NON-NLS-1$ public static String SnapshotLaunchShortcut_0; + public static String SnapshotPreferencesPage_0; + public static String SnapshotPreferencesPage_1; static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --git a/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/launch/SnapshotLaunchShortcut.java b/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/launch/SnapshotLaunchShortcut.java index 6d6580d..7ec4b47 100644 --- a/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/launch/SnapshotLaunchShortcut.java +++ b/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/launch/SnapshotLaunchShortcut.java @@ -13,7 +13,9 @@ package org.eclipse.linuxtools.profiling.snapshot.launch; import org.eclipse.cdt.core.model.IBinary; import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.linuxtools.profiling.launch.ProfileLaunchConfigurationTabGroup; import org.eclipse.linuxtools.profiling.launch.ProfileLaunchShortcut; +import org.eclipse.linuxtools.profiling.snapshot.SnapshotPreferencesPage; public class SnapshotLaunchShortcut extends ProfileLaunchShortcut { @@ -21,7 +23,28 @@ public class SnapshotLaunchShortcut extends ProfileLaunchShortcut { @Override public void launch(IBinary bin, String mode) { - ProfileLaunchShortcut provider = getProfilingProvider(SNAPSHOT); + ProfileLaunchShortcut provider = null; + String providerId = null; + // Get default launch provider id from preference store + providerId = SnapshotPreferencesPage.getSelectedProviderId(); + if (!providerId.equals("")) { + provider = ProfileLaunchShortcut + .getLaunchShortcutProviderFromId(providerId); + } + if (provider == null) { + // Get self assigned default + providerId = ProfileLaunchShortcut + .getDefaultLaunchShortcutProviderId(SNAPSHOT); + provider = ProfileLaunchShortcut + .getLaunchShortcutProviderFromId(providerId); + if (provider == null) { + // Get highest priority provider + providerId = ProfileLaunchConfigurationTabGroup + .getHighestProviderId(SNAPSHOT); + provider = ProfileLaunchShortcut + .getLaunchShortcutProviderFromId(providerId); + } + } if (provider != null){ provider.launch(bin, mode); }else{ diff --git a/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/launch/messages.properties b/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/launch/messages.properties index a7f4bfa..1b431f5 100644 --- a/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/launch/messages.properties +++ b/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/launch/messages.properties @@ -1 +1,4 @@ SnapshotLaunchShortcut_0=Could not find a provider for profiling type : +SnapshotPreferencesPage_0=Profiling Preferences +SnapshotPreferencesPage_1=Choose default snapshot launch provider + |

