From 4ffa61aca1e8baf5c85b341a43355c486fad3527 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 18 Sep 2009 14:47:45 +0000 Subject: [PATCH] bug 289813: [New project Wizard] Project type changes on toggling of supported platform settings --- .../cdt/ui/wizards/CDTMainWizardPage.java | 46 ++++++++++++++----- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CDTMainWizardPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CDTMainWizardPage.java index 591626b6d72..32c2b7559cd 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CDTMainWizardPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/CDTMainWizardPage.java @@ -262,8 +262,10 @@ import org.eclipse.cdt.internal.ui.CPluginImages; */ public static CWizardHandler updateData(Tree tree, Composite right, Button show_sup, IWizardItemsListListener ls, IWizard wizard) { // remember selected item - TreeItem[] sel = tree.getSelection(); - String savedStr = (sel.length > 0) ? sel[0].getText() : null; + TreeItem[] selection = tree.getSelection(); + TreeItem selectedItem = selection.length>0 ? selection[0] : null; + String savedLabel = selectedItem!=null ? selectedItem.getText() : null; + String savedParentLabel = getParentText(selectedItem); tree.removeAll(); IExtensionPoint extensionPoint = @@ -312,17 +314,10 @@ import org.eclipse.cdt.internal.ui.CPluginImages; if (tree.getItemCount() > 0) { TreeItem target = null; // try to search item which was selected before - if (savedStr != null) { - TreeItem[] all = tree.getItems(); - for (TreeItem element : all) { - if (savedStr.equals(element.getText())) { - target = element; - break; - } - } + if (savedLabel!=null) { + target = findItem(tree, savedLabel, savedParentLabel); } - if (target == null) - { + if (target == null) { target = tree.getItem(0); if (target.getItemCount() != 0) target = target.getItem(0); @@ -333,6 +328,33 @@ import org.eclipse.cdt.internal.ui.CPluginImages; return null; } + private static String getParentText(TreeItem item) { + if (item==null || item.getParentItem()==null) + return ""; //$NON-NLS-1$ + return item.getParentItem().getText(); + } + + private static TreeItem findItem(Tree tree, String label, String parentLabel) { + for (TreeItem item : tree.getItems()) { + TreeItem foundItem = findTreeItem(item, label, parentLabel); + if (foundItem!=null) + return foundItem; + } + return null; + } + + private static TreeItem findTreeItem(TreeItem item, String label, String parentLabel) { + if (item.getText().equals(label) && getParentText(item).equals(parentLabel)) + return item; + + for (TreeItem child : item.getItems()) { + TreeItem foundItem = findTreeItem(child, label, parentLabel); + if (foundItem!=null) + return foundItem; + } + return null; + } + private static void addItemsToTree(Tree tree, List items) { // Sorting is disabled because of users requests // Collections.sort(items, CDTListComparator.getInstance());