1 11 package org.eclipse.search.internal.ui.text; 12 13 import java.util.List ; 14 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.graphics.Image; 17 import org.eclipse.swt.layout.GridData; 18 import org.eclipse.swt.widgets.Composite; 19 import org.eclipse.swt.widgets.Control; 20 import org.eclipse.swt.widgets.Label; 21 import org.eclipse.swt.widgets.Shell; 22 23 import org.eclipse.jface.dialogs.Dialog; 24 import org.eclipse.jface.viewers.ArrayContentProvider; 25 import org.eclipse.jface.viewers.ILabelProvider; 26 import org.eclipse.jface.viewers.LabelProvider; 27 import org.eclipse.jface.viewers.TableViewer; 28 29 import org.eclipse.search.internal.ui.SearchMessages; 30 31 36 37 public class SearchAgainConfirmationDialog extends Dialog { 38 private List fOutOfSync; 39 private List fOutOfDate; 40 private ILabelProvider fLabelProvider; 41 42 private class ProxyLabelProvider extends LabelProvider { 43 44 45 48 public Image getImage(Object element) { 49 if (fLabelProvider != null) 50 return fLabelProvider.getImage(element); 51 return null; 52 } 53 54 57 public String getText(Object element) { 58 if (fLabelProvider != null) 59 return fLabelProvider.getText(element); 60 return null; 61 } 62 63 } 64 65 public SearchAgainConfirmationDialog(Shell shell, ILabelProvider labelProvider, List outOfSync, List outOfDate) { 66 super(shell); 67 fOutOfSync= outOfSync; 68 fOutOfDate= outOfDate; 69 fLabelProvider= labelProvider; 70 setShellStyle(getShellStyle() | SWT.RESIZE); 71 } 72 73 76 protected Control createDialogArea(Composite parent) { 77 Composite result= (Composite) super.createDialogArea(parent); 78 79 if (fOutOfSync.size() > 0) { 80 createLabel(result, SearchMessages.SearchAgainConfirmationDialog_outofsync_message); 81 82 createLabel(result, SearchMessages.SearchAgainConfirmationDialog_outofsync_label); 83 createTableViewer(fOutOfSync, result); 84 } else { 85 createLabel(result, SearchMessages.SearchAgainConfirmationDialog_stale_message); 86 } 87 88 createLabel(result, SearchMessages.SearchAgainConfirmationDialog_stale_label); 89 createTableViewer(fOutOfDate, result); 90 return result; 91 } 92 93 private void createLabel(Composite parent, String text) { 94 Label message= new Label(parent, SWT.WRAP); 95 GridData gd= new GridData(GridData.FILL_HORIZONTAL); 96 gd.widthHint= convertWidthInCharsToPixels(70); 97 message.setLayoutData(gd); 98 message.setText(text); 99 } 100 101 private TableViewer createTableViewer(List input, Composite result) { 102 TableViewer viewer= new TableViewer(result); 103 viewer.setContentProvider(new ArrayContentProvider()); 104 viewer.setLabelProvider(new ProxyLabelProvider()); 105 viewer.setInput(input); 106 GridData gd= new GridData(GridData.FILL_BOTH); 107 gd.widthHint= convertWidthInCharsToPixels(70); 108 gd.heightHint= convertHeightInCharsToPixels(5); 109 viewer.getControl().setLayoutData(gd); 110 return viewer; 111 } 112 113 protected void configureShell(Shell shell) { 114 super.configureShell(shell); 115 shell.setText(SearchMessages.SearchAgainConfirmationDialog_title); 116 } 117 118 } 119 | Popular Tags |