1 11 package org.eclipse.jdt.internal.ui.refactoring.actions; 12 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.layout.GridData; 15 import org.eclipse.swt.widgets.Composite; 16 import org.eclipse.swt.widgets.Control; 17 import org.eclipse.swt.widgets.Shell; 18 import org.eclipse.swt.widgets.Table; 19 20 import org.eclipse.jface.dialogs.IDialogConstants; 21 import org.eclipse.jface.viewers.ILabelProvider; 22 import org.eclipse.jface.viewers.IStructuredContentProvider; 23 import org.eclipse.jface.viewers.TableViewer; 24 25 import org.eclipse.ui.dialogs.SelectionDialog; 26 27 public class ListDialog extends SelectionDialog { 28 29 private IStructuredContentProvider fContentProvider; 30 private ILabelProvider fLabelProvider; 31 private Object fInput; 32 private TableViewer fTableViewer; 33 private boolean fAddCancelButton; 34 35 public ListDialog(Shell parent) { 36 super(parent); 37 fAddCancelButton= false; 38 } 39 40 public void setInput(Object input) { 41 fInput= input; 42 } 43 44 public void setContentProvider(IStructuredContentProvider sp){ 45 fContentProvider= sp; 46 } 47 48 public void setLabelProvider(ILabelProvider lp){ 49 fLabelProvider= lp; 50 } 51 52 public void setAddCancelButton(boolean addCancelButton) { 53 fAddCancelButton= addCancelButton; 54 } 55 56 public TableViewer getTableViewer(){ 57 return fTableViewer; 58 } 59 60 public boolean hasFilters(){ 61 return fTableViewer.getFilters() != null && fTableViewer.getFilters().length != 0; 62 } 63 64 public void create() { 65 setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE); 66 super.create(); 67 } 68 69 protected void createButtonsForButtonBar(Composite parent) { 70 if (! fAddCancelButton) 71 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); 72 else 73 super.createButtonsForButtonBar(parent); 74 } 75 76 protected Control createDialogArea(Composite container) { 77 Composite parent= (Composite) super.createDialogArea(container); 78 createMessageArea(parent); 79 fTableViewer= new TableViewer(parent, getTableStyle()); 80 fTableViewer.setContentProvider(fContentProvider); 81 Table table= fTableViewer.getTable(); 82 fTableViewer.setLabelProvider(fLabelProvider); 83 fTableViewer.setInput(fInput); 84 GridData gd= new GridData(GridData.FILL_BOTH); 85 gd.heightHint= convertHeightInCharsToPixels(15); 86 gd.widthHint= convertWidthInCharsToPixels(55); 87 table.setLayoutData(gd); 88 applyDialogFont(parent); 89 return parent; 90 } 91 92 protected int getTableStyle() { 93 return SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER; 94 } 95 } 96 | Popular Tags |