1 13 package org.eclipse.debug.internal.ui.sourcelookup; 14 15 16 import java.util.ArrayList ; 17 import java.util.List ; 18 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.debug.core.sourcelookup.ISourceContainer; 21 import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector; 22 import org.eclipse.jface.viewers.IStructuredSelection; 23 import org.eclipse.jface.viewers.ITreeContentProvider; 24 import org.eclipse.jface.viewers.StructuredSelection; 25 import org.eclipse.jface.viewers.TreeViewer; 26 import org.eclipse.jface.viewers.Viewer; 27 import org.eclipse.swt.widgets.Composite; 28 29 36 public class SourceContainerViewer extends TreeViewer { 37 38 41 private boolean fEnabled = true; 42 45 private SourceLookupPanel fPanel; 46 49 protected List fEntries = new ArrayList (); 50 51 class ContentProvider implements ITreeContentProvider { 52 53 56 public Object [] getElements(Object inputElement) { 57 return getEntries(); 58 } 59 60 63 public void dispose() { 64 } 65 66 69 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 70 } 71 72 75 public Object [] getChildren(Object parentElement) { 76 try { 77 return ((ISourceContainer)parentElement).getSourceContainers(); 78 } catch (CoreException e) { 79 return new Object [0]; 80 } 81 } 82 83 86 public Object getParent(Object element) { 87 return null; 88 } 89 90 93 public boolean hasChildren(Object element) { 94 return ((ISourceContainer)element).isComposite(); 95 } 96 97 } 98 99 105 public SourceContainerViewer(Composite parent, SourceLookupPanel panel) { 106 super(parent); 107 setContentProvider(new ContentProvider()); 108 SourceContainerLabelProvider lp = new SourceContainerLabelProvider(); 109 setLabelProvider(lp); 110 fPanel = panel; 111 } 112 113 118 public void setEntries(ISourceContainer[] entries) { 119 fEntries.clear(); 120 for (int i = 0; i < entries.length; i++) { 121 if(entries[i] != null) 122 fEntries.add(entries[i]); 123 } 124 if (getInput() == null) { 125 setInput(fEntries); 126 if(!fEntries.isEmpty() && fEntries.get(0)!=null) 128 setSelection(new StructuredSelection(fEntries.get(0))); 129 } else { 130 refresh(); 131 } 132 fPanel.setDirty(true); 133 fPanel.updateLaunchConfigurationDialog(); 134 } 135 136 141 public ISourceContainer[] getEntries() { 142 return (ISourceContainer[])fEntries.toArray(new ISourceContainer[fEntries.size()]); 143 } 144 145 153 public void addEntries(ISourceContainer[] entries) { 154 int index = 0; 155 IStructuredSelection sel = (IStructuredSelection)getSelection(); 156 if (!sel.isEmpty()) { 157 index = fEntries.indexOf(sel.getFirstElement()); 158 } 159 for (int i = 0; i < entries.length; i++) { 160 if (!fEntries.contains(entries[i])) { 161 fEntries.add(index, entries[i]); 162 index++; 163 } 164 } 165 166 refresh(); 167 if(entries.length > 0) 168 setSelection(new StructuredSelection(entries)); 169 fPanel.setDirty(true); 170 fPanel.updateLaunchConfigurationDialog(); 171 } 172 173 178 public void setEnabled(boolean enabled) { 179 fEnabled = enabled; 180 setSelection(getSelection()); 182 } 183 184 187 public boolean isEnabled() { 188 return fEnabled; 189 } 190 191 196 public int indexOf(ISourceContainer entry) { 197 return fEntries.indexOf(entry); 198 } 199 200 205 public ISourceLookupDirector getSourceLocator() 206 { 207 return fPanel.fLocator; 208 } 209 210 } 211 | Popular Tags |