Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamilo Bernal2012-07-30 20:40:24 +0000
committerRoland Grunberg2012-08-03 17:48:48 +0000
commitd871a1ec508061697044f254182981a27e1ac388 (patch)
tree8c1100df1ea232e7b5e81e5ba22e45949c6ca176 /profiling/org.eclipse.linuxtools.profiling.snapshot
parentbda13eb5ed6121e27f744db37c0af9ac428799e2 (diff)
downloadorg.eclipse.linuxtools-d871a1ec508061697044f254182981a27e1ac388.tar.gz
org.eclipse.linuxtools-d871a1ec508061697044f254182981a27e1ac388.tar.xz
org.eclipse.linuxtools-d871a1ec508061697044f254182981a27e1ac388.zip
Add preselection of launch provider backend to launch provider's config tab.
When the launch provider's config tab is opened, a previously selected provider is preselected; if no provider is found in the launch configuration, the provider with the highest priority is preselected. This change required refactoring that allowed for a fix of the launch configuration persistence problem with the launch provider config tab to be made. Change-Id: Ibca0dbc89a25563f130d4a33d17677f29edf8fc0 Reviewed-on: https://git.eclipse.org/r/7038 Reviewed-by: Roland Grunberg <rgrunber@redhat.com> IP-Clean: Roland Grunberg <rgrunber@redhat.com> Tested-by: Roland Grunberg <rgrunber@redhat.com>
Diffstat (limited to 'profiling/org.eclipse.linuxtools.profiling.snapshot')
-rw-r--r--profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/SnapshotOptionsTab.java152
1 files changed, 115 insertions, 37 deletions
diff --git a/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/SnapshotOptionsTab.java b/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/SnapshotOptionsTab.java
index 980dadc330..df3d9b264c 100644
--- a/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/SnapshotOptionsTab.java
+++ b/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/SnapshotOptionsTab.java
@@ -11,6 +11,7 @@
package org.eclipse.linuxtools.profiling.snapshot;
import java.util.HashMap;
+import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
@@ -35,8 +36,9 @@ public class SnapshotOptionsTab extends ProfileLaunchConfigurationTab {
Combo providerCombo;
AbstractLaunchConfigurationTab[] tabs;
ILaunchConfiguration initial;
- String providerId = "";
HashMap<String, String> comboItems;
+ CTabFolder tabgroup;
+ Boolean initialized;
public void createControl(Composite parent) {
top = new Composite(parent, SWT.NONE);
@@ -44,43 +46,59 @@ public class SnapshotOptionsTab extends ProfileLaunchConfigurationTab {
top.setLayout(new GridLayout(1, true));
providerCombo = new Combo(top, SWT.READ_ONLY);
comboItems = ProfileLaunchConfigurationTabGroup
- .getTabGroupNamesForType("snapshot");
+ .getProviderNamesForType("snapshot");
Set<String> providerNames = comboItems.keySet();
providerCombo.setItems(providerNames.toArray(new String[0]));
- final CTabFolder tabgroup = new CTabFolder(top, SWT.NONE);
+ tabgroup = new CTabFolder(top, SWT.NONE);
providerCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- // dispose of old tabs
- for (CTabItem item : tabgroup.getItems()) {
- item.dispose();
- }
-
- providerId = comboItems.get(providerCombo.getText());
- // get the tabs associated with the selected ID
- tabs = ProfileLaunchConfigurationTabGroup
- .getTabGroupProviderFromId(providerId)
- .getProfileTabs();
-
- // create the tab item, and load the specified tab inside
- for (ILaunchConfigurationTab tab : tabs) {
- tab.setLaunchConfigurationDialog(getLaunchConfigurationDialog());
- CTabItem item = new CTabItem(tabgroup, SWT.NONE);
- item.setText(tab.getName());
- item.setImage(tab.getImage());
-
- tab.createControl(tabgroup);
- item.setControl(tab.getControl());
- }
-
- // initialize all tab widgets based on the configuration
+ String curProviderId = comboItems.get(providerCombo.getText());
+ loadTabGroupItems(tabgroup, curProviderId);
initializeFrom(initial);
top.layout();
}
});
+ }
+
+ public void loadTabGroupItems(CTabFolder tabgroup, String curProviderId){
+ // dispose of old tabs
+ for (CTabItem item : tabgroup.getItems()) {
+ item.dispose();
+ }
+
+ ProfileLaunchConfigurationTabGroup tabGroupConfig;
+ if (curProviderId == null || "".equals(curProviderId)) {
+ // get id of highest priority provider
+ curProviderId = ProfileLaunchConfigurationTabGroup
+ .getHighestProviderId("snapshot");
+ }
+ tabGroupConfig = ProfileLaunchConfigurationTabGroup
+ .getTabGroupProviderFromId(curProviderId);
+ if (tabGroupConfig == null) {
+ // no provider found
+ return;
+ }
+ tabs = tabGroupConfig.getProfileTabs();
+ setProvider(curProviderId);
+
+ // Show provider name in combo.
+ int itemIndex = getComboItemIndexFromId(curProviderId);
+ providerCombo.select(itemIndex);
+
+ // create the tab item, and load the specified tab inside
+ for (ILaunchConfigurationTab tab : tabs) {
+ tab.setLaunchConfigurationDialog(getLaunchConfigurationDialog());
+ CTabItem item = new CTabItem(tabgroup, SWT.NONE);
+ item.setText(tab.getName());
+ item.setImage(tab.getImage());
+
+ tab.createControl(tabgroup);
+ item.setControl(tab.getControl());
+ }
}
public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
@@ -101,22 +119,40 @@ public class SnapshotOptionsTab extends ProfileLaunchConfigurationTab {
* that we can properly load the widgets the first time.
*/
- // store current provider id in the configuration
- if (configuration != null) {
- setProvider(configuration);
- }
- if (initial == null){
- initial = configuration;
+ // starting initialization of this tab's controls
+ initialized = false;
+
+ // update current configuration (initial) with configuration being
+ // passed in
+ initial = configuration;
+
+ // check if there exists a launch provider id in the configuration
+ if (initial != null) {
+ try {
+ String providerId = initial.getAttribute("provider", "");
+ if (providerId != null && !providerId.equals("")) {
+ // load provider corresponding to specified id
+ loadTabGroupItems(tabgroup, providerId);
+ } else {
+ // load highest priority provider if none found
+ loadTabGroupItems(tabgroup, null);
+ }
+ } catch (CoreException e) {
+ // continue, initialize tabs
+ }
}
- if (providerCombo != null && !providerCombo.getText().equals("")) {
+ if (tabs != null) {
for (AbstractLaunchConfigurationTab tab : tabs) {
tab.initializeFrom(configuration);
}
}
+ // finished initialization
+ initialized = true;
}
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
- if (providerCombo != null && !providerCombo.getText().equals("")) {
+ // make sure tabs are not null, and the tab's controls have been initialized.
+ if (tabs != null && initialized) {
for (AbstractLaunchConfigurationTab tab : tabs) {
tab.performApply(configuration);
}
@@ -126,18 +162,60 @@ public class SnapshotOptionsTab extends ProfileLaunchConfigurationTab {
public String getName() {
return "Snapshot";
}
+
/**
* Set the provider attribute in the specified configuration.
* @param configuration a configuration
*/
- public void setProvider(ILaunchConfiguration configuration) {
+ public void setProvider(String providerId) {
try {
- ILaunchConfigurationWorkingCopy wc = configuration.getWorkingCopy();
+ ILaunchConfigurationWorkingCopy wc = initial.getWorkingCopy();
wc.setAttribute("provider", providerId);
- configuration = wc.doSave();
+ initial = wc.doSave();
} catch (CoreException e1) {
e1.printStackTrace();
}
}
+ /**
+ * Get Combo item name from specified id
+ *
+ * @param id provider id
+ * @return name of item, <code>null</code> if no entry found with given id.
+ */
+ private String getComboItemNameFromId(String id) {
+ for (Entry<String, String> entry : comboItems.entrySet()) {
+ if (id.equals(entry.getValue())) {
+ return entry.getKey();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Get index of specific name in the combo items list
+ *
+ * @param name name of item
+ * @return index of given name, -1 if it not found
+ */
+ private int getItemIndex(String name) {
+ int itemCount = providerCombo.getItemCount();
+ for (int i = 0; i < itemCount; i++) {
+ if (providerCombo.getItem(i).equals(name)) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ /**
+ * Get index of specific id in the combo items list
+ *
+ * @param id
+ * @return index of given id in combo items list, -1 if it not found.
+ */
+ private int getComboItemIndexFromId(String id) {
+ String providerName = getComboItemNameFromId(id);
+ return getItemIndex(providerName);
+ }
}

Back to the top