1 11 package org.eclipse.pde.internal.ui.parts; 12 13 import org.eclipse.jface.viewers.CheckStateChangedEvent; 14 import org.eclipse.jface.viewers.CheckboxTableViewer; 15 import org.eclipse.jface.viewers.ICheckStateListener; 16 import org.eclipse.jface.viewers.ISelectionChangedListener; 17 import org.eclipse.jface.viewers.IStructuredSelection; 18 import org.eclipse.jface.viewers.SelectionChangedEvent; 19 import org.eclipse.jface.viewers.StructuredViewer; 20 import org.eclipse.swt.SWT; 21 import org.eclipse.swt.widgets.Button; 22 import org.eclipse.swt.widgets.Composite; 23 import org.eclipse.ui.forms.widgets.FormToolkit; 24 25 public class CheckboxTablePart extends StructuredViewerPart { 26 public CheckboxTablePart(String [] buttonLabels) { 27 super(buttonLabels); 28 } 29 30 33 protected StructuredViewer createStructuredViewer( 34 Composite parent, 35 int style, 36 FormToolkit toolkit) { 37 style |= SWT.H_SCROLL | SWT.V_SCROLL; 38 if (toolkit==null) { 39 style |= SWT.BORDER; 40 } 41 else { 42 style |= toolkit.getBorderStyle(); 43 } 44 CheckboxTableViewer tableViewer = CheckboxTableViewer.newCheckList(parent, style); 45 tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { 46 public void selectionChanged(SelectionChangedEvent e) { 47 CheckboxTablePart.this.selectionChanged((IStructuredSelection)e.getSelection()); 48 } 49 }); 50 tableViewer.addCheckStateListener(new ICheckStateListener() { 51 public void checkStateChanged(CheckStateChangedEvent event) { 52 elementChecked(event.getElement(), event.getChecked()); 53 } 54 }); 55 return tableViewer; 56 } 57 58 public CheckboxTableViewer getTableViewer() { 59 return (CheckboxTableViewer)getViewer(); 60 } 61 62 65 protected void buttonSelected(Button button, int index) { 66 } 67 68 protected void elementChecked(Object element, boolean checked) { 69 } 70 protected void selectionChanged(IStructuredSelection selection) { 71 } 72 } 73 | Popular Tags |