1 11 package org.eclipse.ant.internal.ui.launchConfigurations; 12 13 14 import java.util.ArrayList ; 15 import java.util.Arrays ; 16 import java.util.Iterator ; 17 import java.util.List ; 18 19 import org.eclipse.ant.core.TargetInfo; 20 import org.eclipse.jface.viewers.IStructuredContentProvider; 21 import org.eclipse.jface.viewers.TableViewer; 22 import org.eclipse.jface.viewers.Viewer; 23 24 public class AntTargetContentProvider implements IStructuredContentProvider { 25 26 protected List elements = new ArrayList (); 27 protected TableViewer viewer; 28 private boolean fFilterInternalTargets= false; 29 private int fNumFilteredTargets= 0; 30 private int fNumTotalTargets= 0; 31 32 public void add(Object o) { 33 elements.add(o); 34 viewer.add(o); 35 } 36 37 public void addAll(List list) { 38 elements.addAll(list); 39 viewer.add(list.toArray()); 40 } 41 42 public void dispose() { 43 } 44 45 public Object [] getElements(Object inputElement) { 46 fNumTotalTargets= elements.size(); 47 fNumFilteredTargets= 0; 48 if (fNumTotalTargets == 0) { 49 return new Object [0]; 50 } 51 if (!fFilterInternalTargets) { 52 return elements.toArray(new Object [fNumTotalTargets]); 53 } 54 Iterator iter= elements.iterator(); 55 while (iter.hasNext()) { 56 if (isInternal((TargetInfo) iter.next())) { 57 fNumFilteredTargets++; 58 } 59 } 60 Object [] targets= new Object [getNumTargets()]; 61 iter= elements.iterator(); 62 int i= 0; 63 while (iter.hasNext()) { 64 TargetInfo target= (TargetInfo) iter.next(); 65 if (!isInternal(target)) { 66 targets[i++]= target; 67 } 68 } 69 return targets; 70 } 71 72 79 public boolean isInternal(TargetInfo target) { 80 return !target.isDefault() && target.getDescription() == null; 81 } 82 83 public void inputChanged(Viewer newViewer, Object oldInput, Object newInput) { 84 this.viewer = (TableViewer) newViewer; 85 elements.clear(); 86 if (newInput != null && ((Object []) newInput).length != 0) { 87 elements.addAll(Arrays.asList((Object []) newInput)); 88 } 89 } 90 91 97 public void removeTarget(Object target) { 98 elements.remove(target); 99 viewer.remove(target); 100 } 101 102 109 public void moveUpTarget(int index) { 110 Object target = elements.get(index); 111 if (index == 0 || target == null) { 112 return; 113 } 114 elements.set(index, elements.get(index - 1)); 115 elements.set(index - 1, target); 116 } 117 118 125 public void moveDownTarget(int index) { 126 Object target = elements.get(index); 127 if (index == elements.size() - 1 || target == null) { 128 return; 129 } 130 elements.set(index, elements.get(index + 1)); 131 elements.set(index + 1, target); 132 } 133 134 140 public int getNumFiltered() { 141 return fNumFilteredTargets; 142 } 143 144 151 public int getNumTargets() { 152 return fNumTotalTargets - fNumFilteredTargets; 153 } 154 155 161 public void setFilterInternalTargets(boolean filter) { 162 fFilterInternalTargets= filter; 163 } 164 } 165 | Popular Tags |