1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 09:55:29 +02:00

Fix bug 123461 - Deriving from the same tool twice within the same configuration does

This commit is contained in:
Leo Treggiari 2006-01-21 02:08:20 +00:00
parent 72552ca1bc
commit 60194c446d
7 changed files with 383 additions and 301 deletions

View file

@ -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<tools.length; i++) {
ITool tool = tools[i];
if (tool.getName().equals(matchName)) {
primary = tool;
break;
}
}
} else if (selectedCategory != null) {
// There is a selected option or category.
// See if it matches any category in the current config (by name)
ITool[] tools = null;
IToolChain toolChain = null;
if ( element instanceof IProject ) {
tools = config.getFilteredTools();
toolChain = config.getToolChain();
} else if ( element instanceof IFile){
tools = resConfig.getTools();
}
IBuildObject catOrTool = selectedCategory;
// Make the match name
String matchName = makeMatchName(catOrTool);
// Search for selected category/tool in toolChain
if ( toolChain != null ) {
primary = findOptionCategoryByMatchName(matchName, toolChain.getChildCategories());
}
// Search for selected category/tool in tools
if ( primary == null ) {
for (int i=0; i<tools.length && primary == null; i++) {
primary = findOptionCategoryByMatchName(matchName, tools[i].getChildCategories());
}
}
}
if (primary == null) {
// Select the first tool in the list
Object[] elements = null;
if( element instanceof IProject){
elements = provider.getElements(parent.getSelectedConfigurationClone());
} else if ( element instanceof IFile) {
elements = provider.getElements(resParent.getCurrentResourceConfigClone());
}
primary = elements.length > 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; i<elements.length; i++) {
ToolListElement e = elements[i];
if (e == currentElement) {
return currentElement;
}
e = exactMatchSelectionElement(currentElement, e.getChildElements());
if (e != null) return e;
}
return null;
}
private ToolListElement equivalentMatchSelectionElement(ToolListElement currentElement, ToolListElement[] elements) {
for (int i=0; i<elements.length; i++) {
ToolListElement e = elements[i];
if (e.isEquivalentTo(currentElement)) {
return e;
}
e = equivalentMatchSelectionElement(currentElement, e.getChildElements());
if (e != null) return e;
}
return null;
}
public void removeValues(String id) {
}
@ -481,17 +488,24 @@ public class ToolsSettingsBlock extends AbstractCOptionPage {
IStructuredSelection selection = (IStructuredSelection) optionList.getSelection();
// Set the option page based on the selection
Object element = selection.getFirstElement();
if(element instanceof IOptionCategory){
if(resParent != null)
settingsStore.setSelection(resParent.getCurrentResourceConfigClone(),(IOptionCategory)element);
else
settingsStore.setSelection(parent.getSelectedConfigurationClone(),(IOptionCategory)element);
}
if (element instanceof ITool) {
displayOptionsForTool((ITool)element);
} else if (element instanceof IOptionCategory) {
displayOptionsForCategory((IOptionCategory)element);
ToolListElement toolListElement = (ToolListElement)selection.getFirstElement();
if (toolListElement != null) {
IOptionCategory cat = toolListElement.getOptionCategory();
if (cat == null)
cat = (IOptionCategory)toolListElement.getTool();
if (cat != null) {
if(resParent != null)
settingsStore.setSelection(resParent.getCurrentResourceConfigClone(), toolListElement, cat);
else
settingsStore.setSelection(parent.getSelectedConfigurationClone(), toolListElement, cat);
}
cat = toolListElement.getOptionCategory();
if (cat != null) {
displayOptionsForCategory(toolListElement);
} else {
displayOptionsForTool(toolListElement);
}
}
}
@ -519,10 +533,10 @@ public class ToolsSettingsBlock extends AbstractCOptionPage {
* @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performDefaults()
*/
public void performDefaults() {
if ( element instanceof IProject) {
performDefaults( (IProject)element);
} else if ( element instanceof IFile) {
performDefaults( (IFile)element);
if ( propertyObject instanceof IProject) {
performDefaults( (IProject)propertyObject);
} else if ( propertyObject instanceof IFile) {
performDefaults( (IFile)propertyObject);
}
defaultNeeded = true;
return;
@ -544,8 +558,7 @@ public class ToolsSettingsBlock extends AbstractCOptionPage {
}
// Reset the category or tool selection and run selection event handler
selectedCategory = null;
selectedTool = null;
selectedElement = null;
handleOptionSelection();
setDirty(true);
@ -566,8 +579,7 @@ public class ToolsSettingsBlock extends AbstractCOptionPage {
}
// Reset the category or tool selection and run selection event handler
selectedCategory = null;
selectedTool = null;
selectedElement = null;
handleOptionSelection();
setDirty(true);
@ -579,11 +591,11 @@ public class ToolsSettingsBlock extends AbstractCOptionPage {
*/
public void performApply(IProgressMonitor monitor) throws CoreException {
if(element instanceof IFile)
if(propertyObject instanceof IFile)
resParent.getCurrentResourceConfig(true);
if(defaultNeeded){
if(element instanceof IFile)
if(propertyObject instanceof IFile)
ManagedBuildManager.resetResourceConfiguration(resParent.getProject(), resParent.getCurrentResourceConfig(true));
else
ManagedBuildManager.resetConfiguration(parent.getProject(), parent.getSelectedConfiguration());
@ -846,13 +858,13 @@ public class ToolsSettingsBlock extends AbstractCOptionPage {
*/
private List getPagesForConfig() {
List pages = null;
if ( element instanceof IProject) {
if ( propertyObject instanceof IProject) {
// Make sure that something was selected
if (parent.getSelectedConfigurationClone() == null) {
return null;
}
pages = (List) configToPageListMap.get(parent.getSelectedConfigurationClone().getId());
} else if (element instanceof IFile) {
} else if (propertyObject instanceof IFile) {
if ( resParent.getCurrentResourceConfigClone() == null ) {
return null;
}
@ -861,9 +873,9 @@ public class ToolsSettingsBlock extends AbstractCOptionPage {
if (pages == null) {
pages = new ArrayList();
if ( element instanceof IProject) {
if ( propertyObject instanceof IProject) {
configToPageListMap.put(parent.getSelectedConfigurationClone().getId(), pages);
} else if ( element instanceof IFile) {
} else if ( propertyObject instanceof IFile) {
configToPageListMap.put(resParent.getCurrentResourceConfigClone().getId(), pages);
}
}
@ -938,59 +950,5 @@ public class ToolsSettingsBlock extends AbstractCOptionPage {
}
return (BuildMacroProvider)ManagedBuildManager.getBuildMacroProvider();
}
/**
* Creates a name that uniquely identifies a category. The match name is
* a concatenation of the tool and categories, e.g. Tool->Cat1->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<cats.length; j++) {
IBuildObject catOrTool = cats[j];
// Build the match name
String catName = makeMatchName(catOrTool);
// Check whether the name matches
if (catName.equals(matchName)) {
primary = cats[j];
break;
} else if (matchName.startsWith(catName)) {
// If there is a common root then check for any further children
primary = findOptionCategoryByMatchName(matchName, cats[j].getChildCategories());
if (primary != null)
break;
}
}
return primary;
}
}

View file

@ -40,24 +40,27 @@ import org.eclipse.swt.widgets.Composite;
public class BuildOptionSettingsPage extends BuildSettingsPage {
private Map fieldsMap = new HashMap();
private IOptionCategory clonedCategory;
private IHoldsOptions optionHolder;
private boolean isItResourceConfigPage;
private Map fieldEditorsToParentMap = new HashMap();
private AbstractBuildPropertyPage buildPropPage;
public BuildOptionSettingsPage(AbstractBuildPropertyPage page,
IConfiguration clonedConfig, IOptionCategory clonedCategory) {
IConfiguration clonedConfig, IHoldsOptions optionHolder, IOptionCategory clonedCategory) {
// Cache the configuration and option category this page is created for
super(clonedConfig);
this.clonedCategory = clonedCategory;
this.optionHolder = optionHolder;
isItResourceConfigPage = false;
buildPropPage = page;
}
public BuildOptionSettingsPage(AbstractBuildPropertyPage page,
IResourceConfiguration clonedResConfig, IOptionCategory clonedCategory) {
IResourceConfiguration clonedResConfig, IHoldsOptions optionHolder, IOptionCategory clonedCategory) {
// Cache the configuration and option category this page is created for
super(clonedResConfig);
this.clonedCategory = clonedCategory;
this.optionHolder = optionHolder;
isItResourceConfigPage = true;
buildPropPage = page;
}
@ -78,9 +81,9 @@ public class BuildOptionSettingsPage extends BuildSettingsPage {
// for each
Object[][] options;
if ( isItResourceConfigPage ) {
options = clonedCategory.getOptions(clonedResConfig);
options = clonedCategory.getOptions(clonedResConfig, optionHolder);
} else {
options = clonedCategory.getOptions(clonedConfig);
options = clonedCategory.getOptions(clonedConfig, optionHolder);
}
for (int index = 0; index < options.length; ++index) {
@ -204,9 +207,10 @@ public class BuildOptionSettingsPage extends BuildSettingsPage {
* @param category
* @return
*/
public boolean isForCategory(IOptionCategory category) {
public boolean isForCategory(IHoldsOptions optionHolder, IOptionCategory category) {
if (category != null) {
return category.equals(this.clonedCategory);
if (this.optionHolder == optionHolder && category.equals(this.clonedCategory))
return true;
}
return false;
}
@ -229,13 +233,13 @@ public class BuildOptionSettingsPage extends BuildSettingsPage {
if(realRcCfg == null)
return false;
handler = realRcCfg;
clonedOptions = clonedCategory.getOptions(clonedResConfig);
clonedOptions = clonedCategory.getOptions(clonedResConfig, optionHolder);
} else {
realCfg = buildPropPage.getRealConfig(clonedConfig);
if(realCfg == null)
return false;
handler = realCfg;
clonedOptions = clonedCategory.getOptions(clonedConfig);
clonedOptions = clonedCategory.getOptions(clonedConfig, optionHolder);
}
for (int i = 0; i < clonedOptions.length; i++) {
@ -353,9 +357,9 @@ public class BuildOptionSettingsPage extends BuildSettingsPage {
public void updateFields() {
Object[][] options;
if (isItResourceConfigPage) {
options = clonedCategory.getOptions(clonedResConfig);
options = clonedCategory.getOptions(clonedResConfig, optionHolder);
} else {
options = clonedCategory.getOptions(clonedConfig);
options = clonedCategory.getOptions(clonedConfig, optionHolder);
}
// some option has changed on this page... update enabled/disabled state for all options
@ -518,9 +522,9 @@ public class BuildOptionSettingsPage extends BuildSettingsPage {
Object[][] options;
if (isItResourceConfigPage) {
options = clonedCategory.getOptions(clonedResConfig);
options = clonedCategory.getOptions(clonedResConfig, optionHolder);
} else {
options = clonedCategory.getOptions(clonedConfig);
options = clonedCategory.getOptions(clonedConfig, optionHolder);
}
// some option has changed on this page... update enabled/disabled state for all options

View file

@ -543,13 +543,13 @@ public class BuildToolSettingsPage extends BuildSettingsPage {
if(realRcCfg == null)
return false;
// handler = realRcCfg;
clonedOptions = clonedCategory.getOptions(clonedResConfig);
clonedOptions = clonedCategory.getOptions(clonedResConfig, clonedTool);
} else {
realCfg = buildPropPage.getRealConfig(clonedConfig);
if(realCfg == null)
return false;
// handler = realCfg;
clonedOptions = clonedCategory.getOptions(clonedConfig);
clonedOptions = clonedCategory.getOptions(clonedConfig, clonedTool);
}
if ( clonedOptions == null)

View file

@ -43,6 +43,7 @@ public class BuildToolSettingsPreferenceStore implements IPreferenceStore {
private IConfiguration config;
private IResourceConfiguration rcConfig;
private IOptionCategory optCategory;
private ToolListElement selectedElement;
private ListenerList listenerList;
private boolean dirtyFlag;
@ -90,26 +91,20 @@ public class BuildToolSettingsPreferenceStore implements IPreferenceStore {
this.block = block;
}
public void setSelection(IConfiguration cfg, IOptionCategory category){
public void setSelection(IConfiguration cfg, ToolListElement element, IOptionCategory category){
selectedElement = element;
optCategory = category;
rcConfig = null;
config = cfg;
}
public void setSelection(IResourceConfiguration cfg, IOptionCategory category){
public void setSelection(IResourceConfiguration cfg, ToolListElement element, IOptionCategory category){
selectedElement = element;
optCategory = category;
rcConfig = cfg;
config = cfg.getParent();
}
public IOptionCategory getSelecedCategory(){
return optCategory;
}
public IResourceConfiguration getSelectedRcConfig(){
return rcConfig;
}
public IConfiguration getSelectedConfig(){
return config;
}
@ -264,10 +259,12 @@ public class BuildToolSettingsPreferenceStore implements IPreferenceStore {
public Object[] getOption(String name){
Object options[][];
IHoldsOptions selectedHolder = selectedElement.getHoldOptions();
if (selectedHolder == null) selectedHolder = selectedElement.getTool();
if(rcConfig != null)
options = optCategory.getOptions(rcConfig);
options = optCategory.getOptions(rcConfig, selectedHolder);
else
options = optCategory.getOptions(config);
options = optCategory.getOptions(config, selectedHolder);
for(int i = 0; i < options.length; i++){
IHoldsOptions ho = (IHoldsOptions)options[i][0];

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2002, 2005 IBM Corporation and others.
* Copyright (c) 2002, 2006 IBM Corporation and others.
* 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
@ -11,21 +11,19 @@
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.ui.properties;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration;
import org.eclipse.cdt.managedbuilder.core.IOptionCategory;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.core.*;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import java.util.ArrayList;
import java.util.List;
public class ToolListContentProvider implements ITreeContentProvider{
public static final int FILE = 0x1;
public static final int PROJECT = 0x4;
private static Object[] EMPTY_ARRAY = new Object[0];
private IConfiguration configRoot;
private IResourceConfiguration resConfigRoot;
private int elementType;
private ToolListElement[] elements;
/**
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
@ -36,88 +34,87 @@ public class ToolListContentProvider implements ITreeContentProvider{
public ToolListContentProvider(int elementType) {
this.elementType = elementType;
}
/**
* Gets the top level contents to be displayed in the tool list.
* If defined, first display the toolChain's option categories (unfiltered).
* Then display the the tools which are relevant for the project's nature.
*/
private Object[] getToplevelContent(IConfiguration config) {
Object toolChainsCategories[];
Object filteredTools[];
Object all[];
// Get the the option categories of the toolChain
IToolChain toolChain = config.getToolChain();
toolChainsCategories = toolChain.getChildCategories();
// Get the tools to be displayed
filteredTools = config.getFilteredTools();
// Add up both arrays and return
int i;
int len = toolChainsCategories.length+filteredTools.length;
all = new Object[len];
for (i=0; i < toolChainsCategories.length; i++)
all[i] = toolChainsCategories[i];
for (; i < len; i++)
all[i] = filteredTools[i-toolChainsCategories.length];
return all;
private ToolListElement[] createElements(IConfiguration config) {
IOptionCategory toolChainCategories[];
ITool filteredTools[];
List elementList = new ArrayList();
if (config != null) {
// Get the the option categories of the toolChain
IToolChain toolChain = config.getToolChain();
toolChainCategories = toolChain.getChildCategories();
// Create an element for each one
for (int i=0; i<toolChainCategories.length; i++) {
ToolListElement e = new ToolListElement(null, toolChain, toolChainCategories[i]);
elementList.add(e);
createChildElements(e);
}
// Get the tools to be displayed
filteredTools = config.getFilteredTools();
// Create an element for each one
for (int i=0; i<filteredTools.length; i++) {
ToolListElement e = new ToolListElement(filteredTools[i]);
elementList.add(e);
createChildElements(e);
}
}
return (ToolListElement[])elementList.toArray(new ToolListElement[elementList.size()]);
}
private ToolListElement[] createElements(IResourceConfiguration resConfig) {
List elementList = new ArrayList();
if (resConfig != null) {
ITool[] tools = resConfig.getTools();
// Create an element for each one
for (int i=0; i<tools.length; i++) {
ToolListElement e = new ToolListElement(tools[i]);
elementList.add(e);
createChildElements(e);
}
}
return (ToolListElement[])elementList.toArray(new ToolListElement[elementList.size()]);
}
private void createChildElements(ToolListElement parentElement) {
IOptionCategory parent = parentElement.getOptionCategory();
IHoldsOptions optHolder = parentElement.getHoldOptions();
if (parent == null) {
parent = parentElement.getTool().getTopOptionCategory(); // Must be an ITool
optHolder = parentElement.getTool();
}
IOptionCategory[] cats = parent.getChildCategories();
// Create an element for each one
for (int i=0; i<cats.length; i++) {
ToolListElement e = new ToolListElement(parentElement, optHolder, cats[i]);
parentElement.addChildElement(e);
createChildElements(e);
}
}
/**
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
*/
public Object[] getChildren(Object parentElement) {
// If parent is configuration, return a list of its option categories
if (parentElement instanceof IConfiguration) {
IConfiguration config = (IConfiguration)parentElement;
// Get the contents to be displayed for the configuration
return getToplevelContent(config);
} else if( parentElement instanceof IResourceConfiguration) {
// If parent is a resource configuration, return a list of its tools.
// Resource configurations do not support categories that are children
// of toolchains. The reason for this is that options in such categories
// are intended to be global.
// TODO: Remove this restriction in future? Requires getToplevelContent() variant
IResourceConfiguration resConfig = (IResourceConfiguration)parentElement;
return resConfig.getTools();
} else if (parentElement instanceof ITool) {
// If this is a tool, return the categories it contains
ITool tool = (ITool)parentElement;
return tool.getTopOptionCategory().getChildCategories();
} else if (parentElement instanceof IOptionCategory) {
// Categories can have child categories
IOptionCategory cat = (IOptionCategory)parentElement;
return cat.getChildCategories();
} else {
return EMPTY_ARRAY;
if (parentElement instanceof IConfiguration ||
parentElement instanceof IResourceConfiguration ) {
return elements;
}
return ((ToolListElement)parentElement).getChildElements();
}
/**
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
public Object[] getElements(Object inputElement) {
return getChildren(inputElement);
return elements;
}
/**
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
*/
public Object getParent(Object element) {
if (element instanceof IOptionCategory) {
// Find the parent category
IOptionCategory cat = (IOptionCategory)element;
IOptionCategory parent = cat.getOwner();
// Then we need to get the configuration we belong to
if (parent == null) {
if(elementType == FILE)
return resConfigRoot;
else
return configRoot;
}
return parent;
}
return null;
return ((ToolListElement)element).getParent();
}
/**
@ -131,13 +128,22 @@ public class ToolListContentProvider implements ITreeContentProvider{
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// If the input hasn't changed, there is no reason to re-create the content
if (oldInput == newInput) return;
if(elementType == FILE) {
resConfigRoot = (IResourceConfiguration)newInput;
configRoot = null;
// Create a ToolListElement to represent each item that will appear
// in the TreeViewer.
elements = createElements(resConfigRoot);
}
else if(elementType == PROJECT) {
configRoot = (IConfiguration) newInput;
resConfigRoot = null;
// Create a ToolListElement to represent each item that will appear
// in the TreeViewer.
elements = createElements(configRoot);
}
}
}

View file

@ -0,0 +1,120 @@
/*******************************************************************************
* Copyright (c) 2006 Intel Corporation and others.
* 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:
* Intel Corporation - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.ui.properties;
import org.eclipse.cdt.managedbuilder.core.*;
import org.eclipse.cdt.managedbuilder.internal.core.OptionCategory;
import java.util.ArrayList;
import java.util.List;
/*******************************************************************************
* This class represent the elements in the TreeViewer that displays the tools
* and categories in the tool options property pages. The reason for these
* elements is illustrated by bugzilla #123461. We used to use the ToolChain,
* Tool and OptionCategory objects themselves as the elements in the TreeViewer,
* but the same OptionCategory can appear more than once in the list of Tree
* Viewer items, and this caused problems.
*******************************************************************************/
public class ToolListElement {
/*
* Bookeeping variables
*/
private ToolListElement parent = null;
private List childElements = null;
private IHoldsOptions optionHolder = null;
private IOptionCategory optionCategory = null;
private ITool tool = null;
/*
* Constructor for an element tha represents an option category
*/
public ToolListElement(ToolListElement parent, IHoldsOptions optionHolder, IOptionCategory optionCategory) {
this.parent = parent;
this.optionHolder = optionHolder;
this.optionCategory = optionCategory;
}
/*
* Constructor for an element tha represents a tool
*/
public ToolListElement(ITool tool) {
this.tool = tool;
}
public boolean isEquivalentTo(ToolListElement e) {
if (tool != null) {
// Look for a matching tool
ITool matchTool = e.getTool();
if (matchTool == tool) return true;
if (matchTool == null) return false;
if (matchTool.getName().equals(tool.getName())) return true;
return false;
}
if (optionCategory != null) {
IOptionCategory matchCategory = e.getOptionCategory();
IHoldsOptions matchHolder = e.getHoldOptions();
if (matchCategory == optionCategory &&
matchHolder == optionHolder) return true;
if (matchCategory == null) return false;
//String matchCategoryName = matchCategory.getName();
//String optionCategoryName = optionCategory.getName();
String matchCategoryName = OptionCategory.makeMatchName(matchCategory);
String optionCategoryName = OptionCategory.makeMatchName(optionCategory);
if (matchHolder.getName().equals(optionHolder.getName()) &&
matchCategoryName.equals(optionCategoryName)) return true;
return false;
}
return false;
}
/*
* Field accessors
*/
public ToolListElement getParent() {
return parent;
}
public IHoldsOptions getHoldOptions() {
return optionHolder;
}
public IOptionCategory getOptionCategory() {
return optionCategory;
}
public ITool getTool() {
return tool;
}
/*
* Children handling
*/
public ToolListElement[] getChildElements() {
if (childElements != null)
return (ToolListElement[])childElements.toArray(new ToolListElement[childElements.size()]);
else
return new ToolListElement[0];
}
public void addChildElement(ToolListElement element) {
if (childElements == null)
childElements = new ArrayList();
childElements.add(element);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2002, 2005 IBM Corporation and others.
* Copyright (c) 2002, 2006 IBM Corporation and others.
* 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
@ -13,6 +13,7 @@ package org.eclipse.cdt.managedbuilder.ui.properties;
import java.net.URL;
import org.eclipse.cdt.managedbuilder.core.IOptionCategory;
import org.eclipse.cdt.managedbuilder.core.IHoldsOptions;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIImages;
import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIMessages;
@ -56,50 +57,46 @@ public class ToolListLabelProvider extends LabelProvider {
}
public Image getImage(Object element) {
// Return a tool image for a tool or tool reference
if (element instanceof ITool) {
if (element instanceof IOptionCategory) {
// Retrieve the Image from Icon information included
IOptionCategory cat = (IOptionCategory)element;
Image img = getIconFromOptionCategory(cat);
if (img != null) {
return img;
}
}
// Use default icon for display
return IMG_TOOL;
} else if (element instanceof IOptionCategory) {
if (!(element instanceof ToolListElement)) {
throw unknownElement(element);
}
Image defaultImage = IMG_CAT;
ToolListElement toolListElement = (ToolListElement)element;
IOptionCategory cat = toolListElement.getOptionCategory();
if (cat == null) {
defaultImage = IMG_TOOL;
cat = (IOptionCategory)toolListElement.getTool();
}
if (cat != null) {
// Return a OptionCategory image for an OptionCategory reference
IOptionCategory cat = (IOptionCategory)element;
Image img = getIconFromOptionCategory(cat);
if (img != null) {
return img;
}
// Use default icon for display
return IMG_CAT;
} else {
throw unknownElement(element);
}
// Use default icon for display
return defaultImage;
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ILabelProvider#getText(Object)
*/
public String getText(Object element) {
if (element instanceof ITool) {
// Handles tool references as well
ITool tool = (ITool)element;
if (!(element instanceof ToolListElement)) {
throw unknownElement(element);
}
ToolListElement toolListElement = (ToolListElement)element;
IOptionCategory cat = toolListElement.getOptionCategory();
if (cat == null) {
ITool tool = toolListElement.getTool();
return tool.getName();
}
else if (element instanceof IOptionCategory) {
IOptionCategory cat = (IOptionCategory)element;
return cat.getName();
}
else {
throw unknownElement(element);
return cat.getName();
}
}