1
/*******************************************************************************
2
* Copyright (c) 2006, 2010 Intel Corporation and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* Intel Corporation - Initial API and implementation
10
*******************************************************************************/
12
package org.eclipse.cdt.managedbuilder.ui.properties;
14
import java.util.ArrayList;
15
import java.util.List;
17
import org.eclipse.cdt.managedbuilder.core.IHoldsOptions;
18
import org.eclipse.cdt.managedbuilder.core.IOptionCategory;
19
import org.eclipse.cdt.managedbuilder.core.ITool;
20
import org.eclipse.cdt.managedbuilder.internal.core.OptionCategory;
23
* This class represent the elements in the TreeViewer that displays the tools
24
* and categories in the tool options property pages. The reason for these
25
* elements is illustrated by bugzilla #123461. We used to use the ToolChain,
26
* Tool and OptionCategory objects themselves as the elements in the TreeViewer,
27
* but the same OptionCategory can appear more than once in the list of Tree
28
* Viewer items, and this caused problems.
30
* @noextend This class is not intended to be subclassed by clients.
31
* @noinstantiate This class is not intended to be instantiated by clients.
33
public class ToolListElement {
36
* Bookeeping variables
38
private ToolListElement parent = null;
39
private List<ToolListElement> childElements = null;
41
private IHoldsOptions optionHolder = null;
42
private IOptionCategory optionCategory = null;
43
private ITool tool = null;
46
* Constructor for an element tha represents an option category
48
public ToolListElement(ToolListElement parent, IHoldsOptions optionHolder, IOptionCategory optionCategory) {
50
this.optionHolder = optionHolder;
51
this.optionCategory = optionCategory;
55
* Constructor for an element tha represents a tool
57
public ToolListElement(ITool tool) {
61
public boolean isEquivalentTo(ToolListElement e) {
64
// Look for a matching tool
65
ITool matchTool = e.getTool();
66
if (matchTool == tool) return true;
67
if (matchTool == null) return false;
68
if (matchTool.getName().equals(tool.getUniqueRealName())) return true;
72
if (optionCategory != null) {
73
IOptionCategory matchCategory = e.getOptionCategory();
74
IHoldsOptions matchHolder = e.getHoldOptions();
75
if (matchCategory == optionCategory &&
76
matchHolder == optionHolder) return true;
77
if (matchCategory == null) return false;
79
//String matchCategoryName = matchCategory.getName();
80
//String optionCategoryName = optionCategory.getName();
81
String matchCategoryName = OptionCategory.makeMatchName(matchCategory);
82
String optionCategoryName = OptionCategory.makeMatchName(optionCategory);
83
if (matchHolder.getName().equals(optionHolder.getName()) &&
84
matchCategoryName.equals(optionCategoryName)) return true;
94
public ToolListElement getParent() {
98
public IHoldsOptions getHoldOptions() {
102
public IOptionCategory getOptionCategory() {
103
return optionCategory;
106
public ITool getTool() {
113
public ToolListElement[] getChildElements() {
114
if (childElements != null)
115
return childElements.toArray(new ToolListElement[childElements.size()]);
117
return new ToolListElement[0];
120
public void addChildElement(ToolListElement element) {
121
if (childElements == null)
122
childElements = new ArrayList<ToolListElement>();
123
childElements.add(element);