1 12 13 package org.eclipse.ui.dialogs; 14 15 import org.eclipse.jface.viewers.DoubleClickEvent; 16 import org.eclipse.jface.viewers.IDoubleClickListener; 17 import org.eclipse.jface.viewers.ISelectionChangedListener; 18 import org.eclipse.jface.viewers.IStructuredSelection; 19 import org.eclipse.jface.viewers.LabelProvider; 20 import org.eclipse.jface.viewers.ListViewer; 21 import org.eclipse.jface.viewers.SelectionChangedEvent; 22 import org.eclipse.jface.viewers.StructuredSelection; 23 import org.eclipse.swt.SWT; 24 import org.eclipse.swt.layout.GridData; 25 import org.eclipse.swt.widgets.Composite; 26 import org.eclipse.swt.widgets.Control; 27 import org.eclipse.swt.widgets.Shell; 28 import org.eclipse.ui.IMarkerResolution; 29 import org.eclipse.ui.PlatformUI; 30 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; 31 import org.eclipse.ui.internal.ide.IIDEHelpContextIds; 32 import org.eclipse.ui.internal.ide.dialogs.SimpleListContentProvider; 33 34 44 public class MarkerResolutionSelectionDialog extends SelectionDialog { 45 48 private final static int LIST_WIDTH = 60; 49 50 53 private final static int LIST_HEIGHT = 10; 54 55 58 private IMarkerResolution[] resolutions; 59 60 63 private ListViewer listViewer; 64 65 75 public MarkerResolutionSelectionDialog(Shell shell, 76 IMarkerResolution[] markerResolutions) { 77 super(shell); 78 if (markerResolutions == null || markerResolutions.length == 0) { 79 throw new IllegalArgumentException (); 80 } 81 resolutions = markerResolutions; 82 setTitle(IDEWorkbenchMessages.MarkerResolutionSelectionDialog_title); 83 setMessage(IDEWorkbenchMessages.MarkerResolutionSelectionDialog_messageLabel); 84 setInitialSelections(new Object [] { markerResolutions[0] }); 85 } 86 87 90 protected void configureShell(Shell newShell) { 91 super.configureShell(newShell); 92 PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, 93 IIDEHelpContextIds.MARKER_RESOLUTION_SELECTION_DIALOG); 94 } 95 96 99 protected Control createDialogArea(Composite parent) { 100 Composite composite = (Composite) super.createDialogArea(parent); 101 102 createMessageArea(composite); 104 listViewer = new ListViewer(composite, SWT.SINGLE | SWT.H_SCROLL 106 | SWT.V_SCROLL | SWT.BORDER); 107 GridData data = new GridData(GridData.FILL_BOTH); 108 data.heightHint = convertHeightInCharsToPixels(LIST_HEIGHT); 109 data.widthHint = convertWidthInCharsToPixels(LIST_WIDTH); 110 listViewer.getList().setLayoutData(data); 111 listViewer.getList().setFont(parent.getFont()); 112 listViewer.setLabelProvider(new LabelProvider() { 114 public String getText(Object element) { 115 return element == null ? "" : ((IMarkerResolution) element).getLabel(); } 118 }); 119 120 SimpleListContentProvider cp = new SimpleListContentProvider(); 122 cp.setElements(resolutions); 123 listViewer.setContentProvider(cp); 124 listViewer.setInput(new Object ()); 126 listViewer.setSelection(new StructuredSelection( 128 getInitialElementSelections()), true); 129 130 listViewer.addSelectionChangedListener(new ISelectionChangedListener() { 132 public void selectionChanged(SelectionChangedEvent event) { 133 getOkButton().setEnabled(!event.getSelection().isEmpty()); 135 } 136 }); 137 138 listViewer.addDoubleClickListener(new IDoubleClickListener() { 140 public void doubleClick(DoubleClickEvent event) { 141 okPressed(); 142 } 143 }); 144 return composite; 145 } 146 147 150 protected void okPressed() { 151 IStructuredSelection selection = (IStructuredSelection) listViewer 152 .getSelection(); 153 setResult(selection.toList()); 154 super.okPressed(); 155 } 156 } 157 | Popular Tags |