1 11 package org.eclipse.debug.internal.ui.sourcelookup.browsers; 12 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.eclipse.core.resources.IFile; 18 import org.eclipse.core.resources.ResourcesPlugin; 19 import org.eclipse.core.runtime.IStatus; 20 import org.eclipse.core.runtime.Status; 21 import org.eclipse.debug.core.sourcelookup.ISourceContainer; 22 import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector; 23 import org.eclipse.debug.core.sourcelookup.containers.ArchiveSourceContainer; 24 import org.eclipse.debug.internal.ui.DebugUIPlugin; 25 import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupUIMessages; 26 import org.eclipse.debug.ui.sourcelookup.AbstractSourceContainerBrowser; 27 import org.eclipse.jface.viewers.ILabelProvider; 28 import org.eclipse.jface.viewers.ITreeContentProvider; 29 import org.eclipse.jface.viewers.ViewerFilter; 30 import org.eclipse.jface.window.Window; 31 import org.eclipse.swt.widgets.Shell; 32 import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; 33 import org.eclipse.ui.dialogs.ISelectionStatusValidator; 34 import org.eclipse.ui.model.WorkbenchContentProvider; 35 import org.eclipse.ui.model.WorkbenchLabelProvider; 36 import org.eclipse.ui.views.navigator.ResourceComparator; 37 38 41 public class ArchiveSourceContainerBrowser extends AbstractSourceContainerBrowser { 42 43 private ISelectionStatusValidator validator= new ISelectionStatusValidator() { 44 public IStatus validate(Object [] selection) { 45 if (selection.length == 0) { 46 return new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), 0, "", null); } 48 for (int i= 0; i < selection.length; i++) { 49 if (!(selection[i] instanceof IFile)) { 50 return new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), 0, "", null); } 52 } 53 return new Status(IStatus.OK, DebugUIPlugin.getUniqueIdentifier(), 0, "", null); } 55 }; 56 57 63 protected List getSelectedJars(ISourceLookupDirector director) { 64 ISourceContainer[] containers = director.getSourceContainers(); 65 List jars = new ArrayList (); 66 for (int i = 0; i < containers.length; i++) { 67 ISourceContainer container = containers[i]; 68 if (container.getType().getId().equals(ArchiveSourceContainer.TYPE_ID)) { 69 jars.add(container); 70 } 71 } 72 return jars; 73 } 74 75 78 public ISourceContainer[] addSourceContainers(Shell shell, ISourceLookupDirector director) { 79 ViewerFilter filter= new ArchiveFilter(getSelectedJars(director)); 80 81 ILabelProvider lp= new WorkbenchLabelProvider(); 82 ITreeContentProvider cp= new WorkbenchContentProvider(); 83 84 ElementTreeSelectionDialog dialog= new ElementTreeSelectionDialog(shell, lp, cp); 85 dialog.setValidator(validator); 86 dialog.setTitle(SourceLookupUIMessages.ArchiveSourceContainerBrowser_3); 87 dialog.setMessage(SourceLookupUIMessages.ArchiveSourceContainerBrowser_4); 88 dialog.addFilter(filter); 89 dialog.setInput(ResourcesPlugin.getWorkspace().getRoot()); 90 dialog.setComparator(new ResourceComparator(ResourceComparator.NAME)); 91 92 if (dialog.open() == Window.OK) { 93 Object [] result = dialog.getResult(); 94 ISourceContainer[] containers = new ISourceContainer[result.length]; 95 for (int i = 0; i < containers.length; i++) { 96 containers[i] = new ArchiveSourceContainer((IFile)result[i], true); 97 } 98 return containers; 99 } 100 return new ISourceContainer[0]; 101 } 102 } 103 | Popular Tags |