1 11 package org.eclipse.debug.internal.ui.launchConfigurations; 12 13 import org.eclipse.jface.dialogs.IDialogConstants; 14 import org.eclipse.jface.viewers.DoubleClickEvent; 15 import org.eclipse.jface.viewers.IDoubleClickListener; 16 import org.eclipse.jface.viewers.ISelection; 17 import org.eclipse.jface.viewers.ISelectionChangedListener; 18 import org.eclipse.jface.viewers.IStructuredSelection; 19 import org.eclipse.jface.viewers.SelectionChangedEvent; 20 import org.eclipse.jface.viewers.StructuredViewer; 21 import org.eclipse.jface.viewers.TableViewer; 22 import org.eclipse.swt.SWT; 23 import org.eclipse.swt.layout.GridData; 24 import org.eclipse.swt.widgets.Composite; 25 import org.eclipse.swt.widgets.Shell; 26 27 32 public abstract class AbstractDebugListSelectionDialog extends AbstractDebugSelectionDialog { 33 34 protected TableViewer fListViewer; 35 36 40 public AbstractDebugListSelectionDialog(Shell parentShell) { 41 super(parentShell); 42 setShellStyle(getShellStyle() | SWT.RESIZE); 43 } 44 45 51 protected StructuredViewer createViewer(Composite parent){ 52 fListViewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); 54 fListViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH)); 55 return fListViewer; 56 } 57 58 61 protected void addViewerListeners(StructuredViewer viewer) { 62 viewer.addSelectionChangedListener(new ISelectionChangedListener(){ 63 public void selectionChanged(SelectionChangedEvent event) { 64 getButton(IDialogConstants.OK_ID).setEnabled(false); 65 ISelection selection = fListViewer.getSelection(); 66 if (selection instanceof IStructuredSelection){ 67 if (((IStructuredSelection)selection).size() == 1){ 68 getButton(IDialogConstants.OK_ID).setEnabled(true); 69 } 70 } 71 } 72 }); 73 viewer.addDoubleClickListener(new IDoubleClickListener(){ 74 public void doubleClick(DoubleClickEvent event) { 75 if (getButton(IDialogConstants.OK_ID).isEnabled()){ 76 okPressed(); 77 } 78 } 79 }); 80 } 81 82 85 protected void createButtonsForButtonBar(Composite parent) { 86 super.createButtonsForButtonBar(parent); 87 getButton(IDialogConstants.OK_ID).setEnabled(false); 88 } 89 90 93 protected void okPressed() { 94 ISelection selection = fViewer.getSelection(); 95 if (selection instanceof IStructuredSelection) { 96 setResult(((IStructuredSelection) selection).toList()); 97 } 98 super.okPressed(); 99 } 100 101 } 102 | Popular Tags |