1 11 package org.eclipse.ant.internal.ui.views; 12 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.eclipse.ant.internal.ui.views.elements.AntNode; 18 import org.eclipse.ant.internal.ui.views.elements.ProjectNode; 19 import org.eclipse.ant.internal.ui.views.elements.RootNode; 20 import org.eclipse.ant.internal.ui.views.elements.TargetNode; 21 import org.eclipse.jface.viewers.ITreeContentProvider; 22 import org.eclipse.jface.viewers.Viewer; 23 24 27 public class AntProjectContentProvider implements ITreeContentProvider { 28 29 32 private RootNode rootNode; 33 private boolean fIsFilteringInternalTargets= false; 34 35 38 public Object [] getElements(Object inputElement) { 39 return getChildren(inputElement); 40 } 41 42 45 public void dispose() { 46 } 47 48 51 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 52 if (newInput instanceof RootNode) { 53 rootNode= (RootNode) newInput; 54 } 55 } 56 57 63 public void addProject(ProjectNode project) { 64 ProjectNode[] projects= getRootNode().getProjects(); 65 for (int i = 0; i < projects.length; i++) { 66 ProjectNode node = projects[i]; 67 if (node.getBuildFileName().equals(project.getBuildFileName())) { 68 return; 69 } 70 } 71 getRootNode().addProject(project); 72 } 73 74 80 public RootNode getRootNode() { 81 return rootNode; 82 } 83 84 87 public Object [] getChildren(Object element) { 88 if (element instanceof RootNode) { 89 return ((RootNode) element).getProjects(); 90 } else if (element instanceof ProjectNode) { 91 if (!fIsFilteringInternalTargets) { 92 return ((ProjectNode) element).getTargets(); 93 } 94 TargetNode[] targets= ((ProjectNode) element).getTargets(); 95 List filteredTargets= new ArrayList (); 96 for (int i = 0; i < targets.length; i++) { 97 TargetNode node = targets[i]; 98 if (!isInternal(node)) { 99 filteredTargets.add(node); 100 } 101 } 102 return filteredTargets.toArray(); 103 } 104 return null; 105 } 106 107 114 private boolean isInternal(TargetNode target) { 115 return target != target.getProject().getDefaultTarget() && target.getDescription() == null; 116 } 117 118 121 public Object getParent(Object element) { 122 if (element instanceof AntNode) { 123 return ((AntNode) element).getParent(); 124 } 125 return null; 126 } 127 128 131 public boolean hasChildren(Object element) { 132 if (element instanceof TargetNode) { 133 return false; 134 } 135 return true; 136 } 137 138 public boolean isFilterInternalTargets() { 139 return fIsFilteringInternalTargets; 140 } 141 142 145 public void setFilterInternalTargets(boolean filter) { 146 fIsFilteringInternalTargets= filter; 147 } 148 149 } 150 | Popular Tags |