diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/ToolsSettingsBlock.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/ToolsSettingsBlock.java index 4b4c1b0735f..e8a64d763ca 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/ToolsSettingsBlock.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/ToolsSettingsBlock.java @@ -18,7 +18,6 @@ import java.util.ListIterator; import java.util.Map; import org.eclipse.cdt.managedbuilder.core.BuildException; -import org.eclipse.cdt.managedbuilder.core.IBuildObject; import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IHoldsOptions; import org.eclipse.cdt.managedbuilder.core.IOption; @@ -38,6 +37,7 @@ import org.eclipse.cdt.managedbuilder.ui.properties.BuildToolSettingsPreferenceS import org.eclipse.cdt.managedbuilder.ui.properties.ResourceBuildPropertyPage; import org.eclipse.cdt.managedbuilder.ui.properties.ToolListContentProvider; import org.eclipse.cdt.managedbuilder.ui.properties.ToolListLabelProvider; +import org.eclipse.cdt.managedbuilder.ui.properties.ToolListElement; import org.eclipse.cdt.ui.dialogs.AbstractCOptionPage; import org.eclipse.cdt.ui.dialogs.ICOptionContainer; import org.eclipse.cdt.utils.ui.controls.ControlFactory; @@ -75,8 +75,6 @@ public class ToolsSettingsBlock extends AbstractCOptionPage { //private static final String TREE_LABEL = LABEL + ".ToolTree"; //$NON-NLS-1$ //private static final String OPTIONS_LABEL = LABEL + ".ToolOptions"; //$NON-NLS-1$ private static final int[] DEFAULT_SASH_WEIGHTS = new int[] { 20, 30 }; - - private static final String EMPTY_STRING = new String(); /* * Dialog widgets @@ -94,10 +92,9 @@ public class ToolsSettingsBlock extends AbstractCOptionPage { private BuildPropertyPage parent; private ResourceBuildPropertyPage resParent; private BuildSettingsPage currentSettingsPage; - private IOptionCategory selectedCategory; + private ToolListElement selectedElement; private ToolListContentProvider provider; - private ITool selectedTool; - private Object element; + private Object propertyObject; private boolean defaultNeeded; @@ -152,7 +149,7 @@ public class ToolsSettingsBlock extends AbstractCOptionPage { super.setContainer(parent); this.parent = parent; configToPageListMap = new HashMap(); - this.element = element; + this.propertyObject = element; settingsStore = new BuildToolSettingsPreferenceStore(this); } @@ -162,7 +159,7 @@ public class ToolsSettingsBlock extends AbstractCOptionPage { super.setContainer((ICOptionContainer) resParent); this.resParent = resParent; configToPageListMap = new HashMap(); - this.element = element; + this.propertyObject = element; settingsStore = new BuildToolSettingsPreferenceStore(this); } @@ -214,9 +211,10 @@ public class ToolsSettingsBlock extends AbstractCOptionPage { * Method displayOptionsForCategory * @param category */ - private void displayOptionsForCategory(IOptionCategory category) { - selectedTool = null; - selectedCategory = category; + private void displayOptionsForCategory(ToolListElement toolListElement) { + selectedElement = toolListElement; + IOptionCategory category = toolListElement.getOptionCategory(); + IHoldsOptions optionHolder = toolListElement.getHoldOptions(); // Cache the current build setting page BuildSettingsPage oldPage = currentSettingsPage; @@ -228,18 +226,18 @@ public class ToolsSettingsBlock extends AbstractCOptionPage { while (iter.hasNext()) { BuildSettingsPage page = (BuildSettingsPage) iter.next(); if (page instanceof BuildOptionSettingsPage && - ((BuildOptionSettingsPage)page).isForCategory(category)) { + ((BuildOptionSettingsPage)page).isForCategory(optionHolder, category)) { currentSettingsPage = page; break; } } if (currentSettingsPage == null) { - if ( this.element instanceof IProject) { - currentSettingsPage = new BuildOptionSettingsPage(parent,parent.getSelectedConfigurationClone(), category); + if ( this.propertyObject instanceof IProject) { + currentSettingsPage = new BuildOptionSettingsPage(parent,parent.getSelectedConfigurationClone(), optionHolder, category); pages.add(currentSettingsPage); currentSettingsPage.setContainer(parent); - } else if ( this.element instanceof IFile) { - currentSettingsPage = new BuildOptionSettingsPage(resParent,resParent.getCurrentResourceConfigClone(), category); + } else if ( this.propertyObject instanceof IFile) { + currentSettingsPage = new BuildOptionSettingsPage(resParent,resParent.getCurrentResourceConfigClone(), optionHolder, category); pages.add(currentSettingsPage); currentSettingsPage.setContainer(resParent); } @@ -273,11 +271,9 @@ public class ToolsSettingsBlock extends AbstractCOptionPage { * Method displayOptionsForTool * @param tool */ - private void displayOptionsForTool(ITool tool) { - // Unselect the category - selectedCategory = null; - // record that the tool selection has changed - selectedTool = tool; + private void displayOptionsForTool(ToolListElement toolListElement) { + selectedElement = toolListElement; + ITool tool = toolListElement.getTool(); // Cache the current build setting page BuildSettingsPage oldPage = currentSettingsPage; @@ -295,12 +291,12 @@ public class ToolsSettingsBlock extends AbstractCOptionPage { } } if (currentSettingsPage == null) { - if ( this.element instanceof IProject) { + if ( this.propertyObject instanceof IProject) { currentSettingsPage = new BuildToolSettingsPage(parent, parent.getSelectedConfigurationClone(), tool); pages.add(currentSettingsPage); currentSettingsPage.setContainer(parent); - } else if(this.element instanceof IFile) { + } else if(this.propertyObject instanceof IFile) { currentSettingsPage = new BuildToolSettingsPage(resParent, resParent.getCurrentResourceConfigClone(), tool); pages.add(currentSettingsPage); @@ -378,101 +374,112 @@ public class ToolsSettingsBlock extends AbstractCOptionPage { public void setVisible(boolean visible){ if(visible){ - selectedCategory = null; - selectedTool = null; + selectedElement = null; handleOptionSelection(); } super.setVisible(visible); } protected void setValues() { - - IConfiguration config = null; - IResourceConfiguration resConfig = null; - + /* + * This method updates the context of the build property pages + * - Which configuration/resource configuration is selected + * - Which tool/option category is selected + * + * It is called: + * - When a property page becomes visible + * - When the user changes the configuration selection + * - When the user changes the "exclude" setting for a resource + */ + + // Create the Tree Viewer content provider if first time if (provider == null) { -// IResource element = parent.getProject(); - IResource resource = (IResource) element; + IResource resource = (IResource) propertyObject; provider = new ToolListContentProvider(resource.getType()); optionList.setContentProvider(provider); } - if ( element instanceof IProject ) { + + // Update the selected configuration and the Tree Viewer + IConfiguration config = null; + IResourceConfiguration resConfig = null; + ToolListElement[] newElements; + + if ( propertyObject instanceof IProject ) { config = parent.getSelectedConfigurationClone(); optionList.setInput(config); - } else if ( element instanceof IFile){ + newElements = (ToolListElement[])provider.getElements(config); + } else if ( propertyObject instanceof IFile){ resConfig = resParent.getCurrentResourceConfigClone(); optionList.setInput(resConfig); - } + newElements = (ToolListElement[])provider.getElements(resConfig); + } else + return; // This should not happen optionList.expandAll(); - // Determine what the selection in the tree should be - Object primary = null; - if (selectedTool != null) { - // There is a selected tool defined. See if it matches any current tool (by name) - ITool[] tools = null; - if ( element instanceof IProject ) { - tools = config.getFilteredTools(); - } else if ( element instanceof IFile){ - tools = resConfig.getTools(); - } - String matchName = selectedTool.getName(); - for (int i=0; i 0 ? elements[0] : null; + // Determine what the selection in the tree should be + // If the saved selection is not null, try to match the saved selection + // with an object in the new element list. + // Otherwise, select the first tool in the tree + Object primaryObject = null; + if (selectedElement != null) { + selectedElement = matchSelectionElement(selectedElement, newElements); } - - if (primary != null) { - if(primary instanceof IOptionCategory){ - if(resConfig != null) - settingsStore.setSelection(resConfig,(IOptionCategory)primary); - else - settingsStore.setSelection(config,(IOptionCategory)primary); + + if (selectedElement == null) { + selectedElement = (ToolListElement)(newElements.length > 0 ? newElements[0] : null); + } + + if (selectedElement != null) { + primaryObject = selectedElement.getTool(); + if (primaryObject == null) { + primaryObject = selectedElement.getOptionCategory(); + } + if (primaryObject != null) { + if (primaryObject instanceof IOptionCategory) { + if(resConfig != null) + settingsStore.setSelection(resConfig, selectedElement, (IOptionCategory)primaryObject); + else + settingsStore.setSelection(config, selectedElement, (IOptionCategory)primaryObject); + } + optionList.setSelection(new StructuredSelection(selectedElement), true); } - optionList.setSelection(new StructuredSelection(primary), true); } } + + private ToolListElement matchSelectionElement(ToolListElement currentElement, ToolListElement[] elements) { + // First, look for an exact match + ToolListElement match = exactMatchSelectionElement(currentElement, elements); + if (match == null) + // Else, look for the same tool/category in the new set of elements + match = equivalentMatchSelectionElement(currentElement, elements); + return match; + } + private ToolListElement exactMatchSelectionElement(ToolListElement currentElement, ToolListElement[] elements) { + for (int i=0; iCat1->Cat2 - * maps onto the string "Tool|Cat1|Cat2|" - * - * @param category or tool for which to build the match name - * @return match name - */ - private String makeMatchName(IBuildObject catOrTool) { - String catName = EMPTY_STRING; - - // Build the match name. - do { - catName = catOrTool.getName() + "|" + catName; //$NON-NLS-1$ - if (catOrTool instanceof ITool) break; - else if (catOrTool instanceof IOptionCategory) { - catOrTool = ((IOptionCategory)catOrTool).getOwner(); - } else - break; - } while (catOrTool != null); - - return catName; - } - - /** - * Finds an option category from an array of categories by comparing against - * a match name. The match name is a concatenation of the tool and categories, - * e.g. Tool->Cat1->Cat2 maps onto the string "Tool|Cat1|Cat2|" - * - * @param matchName an identifier to search - * @param categories as returned by getChildCategories(), i.e. non-flattened - * @return category or tool, if found and null otherwise - */ - private Object findOptionCategoryByMatchName(String matchName, IOptionCategory[] cats) { - Object primary = null; - - for (int j=0; j