1 11 package org.eclipse.jdt.internal.debug.ui.launcher; 12 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.ListenerList; 18 import org.eclipse.debug.core.ILaunchConfiguration; 19 import org.eclipse.jdt.launching.IRuntimeClasspathEntry; 20 import org.eclipse.jface.viewers.IStructuredContentProvider; 21 import org.eclipse.jface.viewers.IStructuredSelection; 22 import org.eclipse.jface.viewers.StructuredSelection; 23 import org.eclipse.jface.viewers.TableViewer; 24 import org.eclipse.jface.viewers.Viewer; 25 import org.eclipse.swt.SWT; 26 import org.eclipse.swt.events.KeyAdapter; 27 import org.eclipse.swt.events.KeyEvent; 28 import org.eclipse.swt.widgets.Composite; 29 import org.eclipse.swt.widgets.Shell; 30 31 34 public class RuntimeClasspathViewer extends TableViewer implements IClasspathViewer { 35 36 39 private boolean fEnabled = true; 40 41 44 private ListenerList fListeners = new ListenerList(); 45 46 49 protected List fEntries = new ArrayList (); 50 51 class ContentProvider implements IStructuredContentProvider { 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 } 73 74 79 public RuntimeClasspathViewer(Composite parent) { 80 super(parent); 81 setContentProvider(new ContentProvider()); 82 RuntimeClasspathEntryLabelProvider lp = new RuntimeClasspathEntryLabelProvider(); 83 setLabelProvider(lp); 84 setInput(fEntries); 85 86 getTable().addKeyListener(new KeyAdapter() { 87 public void keyPressed(KeyEvent event) { 88 if (isEnabled() && event.character == SWT.DEL && event.stateMask == 0) { 89 List selection= getSelectionFromWidget(); 90 fEntries.removeAll(selection); 91 setInput(fEntries); 92 notifyChanged(); 93 } 94 } 95 }); 96 } 97 98 101 public void setEntries(IRuntimeClasspathEntry[] entries) { 102 fEntries.clear(); 103 for (int i = 0; i < entries.length; i++) { 104 fEntries.add(entries[i]); 105 } 106 setInput(fEntries); 107 notifyChanged(); 108 } 109 110 113 public IRuntimeClasspathEntry[] getEntries() { 114 return (IRuntimeClasspathEntry[])fEntries.toArray(new IRuntimeClasspathEntry[fEntries.size()]); 115 } 116 117 120 public void addEntries(IRuntimeClasspathEntry[] entries) { 121 IStructuredSelection sel = (IStructuredSelection)getSelection(); 122 if (sel.isEmpty()) { 123 for (int i = 0; i < entries.length; i++) { 124 if (!fEntries.contains(entries[i])) { 125 fEntries.add(entries[i]); 126 } 127 } 128 } else { 129 int index = fEntries.indexOf(sel.getFirstElement()); 130 for (int i = 0; i < entries.length; i++) { 131 if (!fEntries.contains(entries[i])) { 132 fEntries.add(index, entries[i]); 133 index++; 134 } 135 } 136 } 137 setSelection(new StructuredSelection(entries)); 138 refresh(); 139 notifyChanged(); 140 } 141 142 147 public void setEnabled(boolean enabled) { 148 fEnabled = enabled; 149 setSelection(getSelection()); 151 } 152 153 156 public boolean isEnabled() { 157 return fEnabled; 158 } 159 160 163 public void setLaunchConfiguration(ILaunchConfiguration configuration) { 164 if (getLabelProvider() != null) { 165 ((RuntimeClasspathEntryLabelProvider)getLabelProvider()).setLaunchConfiguration(configuration); 166 } 167 } 168 169 public void addEntriesChangedListener(IEntriesChangedListener listener) { 170 fListeners.add(listener); 171 } 172 173 public void removeEntriesChangedListener(IEntriesChangedListener listener) { 174 fListeners.remove(listener); 175 } 176 177 180 public void notifyChanged() { 181 Object [] listeners = fListeners.getListeners(); 182 for (int i = 0; i < listeners.length; i++) { 183 ((IEntriesChangedListener)listeners[i]).entriesChanged(this); 184 } 185 } 186 187 190 public int indexOf(IRuntimeClasspathEntry entry) { 191 return fEntries.indexOf(entry); 192 } 193 194 197 public Shell getShell() { 198 return getControl().getShell(); 199 } 200 201 204 public boolean updateSelection(int actionType, IStructuredSelection selection) { 205 return isEnabled(); 206 } 207 } 208 | Popular Tags |