1 11 package org.eclipse.debug.internal.ui.sourcelookup; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.debug.core.DebugPlugin; 16 import org.eclipse.debug.core.sourcelookup.ISourceContainer; 17 import org.eclipse.debug.core.sourcelookup.ISourceContainerType; 18 import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector; 19 import org.eclipse.debug.internal.ui.DebugPluginImages; 20 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 21 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 22 import org.eclipse.debug.ui.DebugUITools; 23 import org.eclipse.debug.ui.sourcelookup.ISourceContainerBrowser; 24 import org.eclipse.jface.dialogs.Dialog; 25 import org.eclipse.jface.dialogs.TitleAreaDialog; 26 import org.eclipse.jface.viewers.ArrayContentProvider; 27 import org.eclipse.jface.viewers.ISelection; 28 import org.eclipse.jface.viewers.ISelectionChangedListener; 29 import org.eclipse.jface.viewers.IStructuredSelection; 30 import org.eclipse.jface.viewers.SelectionChangedEvent; 31 import org.eclipse.jface.viewers.TableViewer; 32 import org.eclipse.jface.viewers.ViewerComparator; 33 import org.eclipse.swt.SWT; 34 import org.eclipse.swt.events.SelectionAdapter; 35 import org.eclipse.swt.events.SelectionEvent; 36 import org.eclipse.swt.layout.GridData; 37 import org.eclipse.swt.layout.GridLayout; 38 import org.eclipse.swt.widgets.Composite; 39 import org.eclipse.swt.widgets.Control; 40 import org.eclipse.swt.widgets.Shell; 41 import org.eclipse.swt.widgets.Table; 42 import org.eclipse.ui.PlatformUI; 43 44 50 public class AddSourceContainerDialog extends TitleAreaDialog { 51 52 private TableViewer fViewer; 53 private SourceContainerViewer fSourceContainerViewer; 54 private boolean fDoubleClickSelects = true; 55 private ISourceLookupDirector fDirector; 56 57 60 public AddSourceContainerDialog(Shell shell, SourceContainerViewer viewer, ISourceLookupDirector director) { 61 super(shell); 62 setShellStyle(getShellStyle() | SWT.RESIZE); 63 fSourceContainerViewer=viewer; 64 fDirector = director; 65 } 66 67 70 protected Control createDialogArea(Composite ancestor) { 71 72 getShell().setText(SourceLookupUIMessages.addSourceLocation_title); 73 setTitle(SourceLookupUIMessages.addSourceLocation_description); 74 setTitleImage(DebugPluginImages.getImage(IInternalDebugUIConstants.IMG_ADD_SRC_LOC_WIZ)); 75 76 Composite parent = new Composite(ancestor, SWT.NULL); 77 GridData gd= new GridData(GridData.FILL_BOTH); 78 GridLayout topLayout = new GridLayout(); 79 topLayout.numColumns = 1; 80 parent.setLayout(topLayout); 81 parent.setLayoutData(gd); 82 83 ISourceContainerType[] types = filterTypes(DebugPlugin.getDefault().getLaunchManager().getSourceContainerTypes()); 84 85 fViewer = new TableViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.SINGLE); 86 final Table table = fViewer.getTable(); 87 gd = new GridData(GridData.FILL_BOTH); 88 table.setLayoutData(gd); 89 90 if (fDoubleClickSelects) { 91 table.addSelectionListener(new SelectionAdapter() { 92 public void widgetDefaultSelected(SelectionEvent e) { 93 if (table.getSelectionCount() == 1) 94 okPressed(); 95 } 96 }); 97 } 98 99 fViewer.setLabelProvider(new SourceContainerLabelProvider()); 100 fViewer.setContentProvider(new ArrayContentProvider()); 101 fViewer.setComparator(new ViewerComparator()); 102 fViewer.addSelectionChangedListener(new ISelectionChangedListener() { 103 public void selectionChanged(SelectionChangedEvent event) { 104 ISelection selection = event.getSelection(); 105 String desc = null; 106 if (!selection.isEmpty()) { 107 ISourceContainerType type = (ISourceContainerType) ((IStructuredSelection)selection).getFirstElement(); 108 desc = type.getDescription(); 109 } 110 setMessage(desc); 111 } 112 }); 113 if(types.length != 0) { 114 fViewer.setInput(types); 115 } 116 Dialog.applyDialogFont(parent); 117 PlatformUI.getWorkbench().getHelpSystem().setHelp(getShell(), IDebugHelpContextIds.ADD_SOURCE_CONTAINER_DIALOG); 118 return parent; 119 } 120 121 126 private ISourceContainerType[] filterTypes(ISourceContainerType[] types){ 127 ArrayList validTypes = new ArrayList (); 128 for (int i=0; i< types.length; i++) { 129 ISourceContainerType type = types[i]; 130 if (fDirector.supportsSourceContainerType(type)) { 131 ISourceContainerBrowser sourceContainerBrowser = DebugUITools.getSourceContainerBrowser(type.getId()); 132 if(sourceContainerBrowser != null && sourceContainerBrowser.canAddSourceContainers(fDirector)) { 133 validTypes.add(type); 134 } 135 } 136 } 137 return (ISourceContainerType[]) validTypes.toArray(new ISourceContainerType[validTypes.size()]); 138 139 } 140 141 144 protected void okPressed() { 145 ISourceContainerType type = (ISourceContainerType) ((IStructuredSelection) fViewer.getSelection()).getFirstElement(); 148 if (type != null) { 149 ISourceContainerBrowser browser = DebugUITools.getSourceContainerBrowser(type.getId()); 150 if (browser != null) { 151 ISourceContainer[] results = browser.addSourceContainers(getShell(), fDirector); 152 if (results != null && results.length > 0) { 153 fSourceContainerViewer.addEntries(results); 154 } 155 } 156 } 157 super.okPressed(); 158 } 159 160 } 161 | Popular Tags |