1 11 package org.eclipse.ant.internal.ui.preferences; 12 13 14 import java.util.ArrayList ; 15 import java.util.Arrays ; 16 import java.util.List ; 17 18 import org.eclipse.jface.viewers.IStructuredContentProvider; 19 import org.eclipse.jface.viewers.IStructuredSelection; 20 import org.eclipse.jface.viewers.StructuredSelection; 21 import org.eclipse.jface.viewers.TableViewer; 22 import org.eclipse.jface.viewers.Viewer; 23 import org.eclipse.jface.viewers.ViewerComparator; 24 25 29 public class AntContentProvider implements IStructuredContentProvider { 30 protected List elements = new ArrayList (); 31 protected TableViewer tableViewer; 32 private ViewerComparator fComparator= null; 33 34 public void add(Object o) { 35 if (elements.contains(o)) { 36 return; 37 } 38 elements.add(o); 39 tableViewer.add(o); 40 tableViewer.setSelection(new StructuredSelection(o), true); 41 } 42 43 public void dispose() { 44 } 45 46 public Object [] getElements(Object inputElement) { 47 return elements.toArray(); 48 } 49 50 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 51 tableViewer = (TableViewer) viewer; 52 elements.clear(); 53 if (newInput != null) { 54 tableViewer.setComparator(getComparator()); 55 List list; 56 if (newInput instanceof List ) { 57 list= (List ) newInput; 58 } else { 59 list= Arrays.asList((Object []) newInput); 60 } 61 elements.addAll(list); 62 } 63 } 64 65 public void remove(Object o) { 66 elements.remove(o); 67 tableViewer.remove(o); 68 } 69 70 public void remove(IStructuredSelection selection) { 71 Object [] array= selection.toArray(); 72 elements.removeAll(Arrays.asList(array)); 73 tableViewer.remove(array); 74 } 75 76 protected ViewerComparator getComparator() { 77 if (fComparator == null) { 78 fComparator= new ViewerComparator() { 79 82 public int compare(Viewer viewer, Object e1, Object e2) { 83 return e1.toString().compareToIgnoreCase(e2.toString()); 84 } 85 }; 86 } 87 return fComparator; 88 } 89 } 90 | Popular Tags |