1 11 package org.eclipse.pde.internal.ui.parts; 12 13 import org.eclipse.core.runtime.Assert; 14 import org.eclipse.jface.viewers.ILabelProvider; 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.events.SelectionAdapter; 17 import org.eclipse.swt.events.SelectionEvent; 18 import org.eclipse.swt.widgets.Button; 19 import org.eclipse.swt.widgets.Composite; 20 import org.eclipse.swt.widgets.Control; 21 import org.eclipse.swt.widgets.Shell; 22 import org.eclipse.ui.dialogs.ElementListSelectionDialog; 23 24 public class ConditionalListSelectionDialog extends ElementListSelectionDialog { 25 26 private String fButtonText; 27 private Object [] fElements; 28 private Object [] fConditionalElements; 29 30 public ConditionalListSelectionDialog(Shell parent, ILabelProvider renderer, String buttonText) { 31 super(parent, renderer); 32 fButtonText = buttonText; 33 } 34 35 protected Control createDialogArea(Composite parent) { 36 Composite comp = (Composite) super.createDialogArea(parent); 37 int size = ((fElements != null) ? fElements.length : 0) + 38 ((fConditionalElements != null) ? fConditionalElements.length : 0); 39 final Object [] allElements = new Object [size]; 40 int conditionalStart = 0; 41 if (fElements != null) { 42 System.arraycopy(fElements, 0, allElements, 0, fElements.length); 43 conditionalStart = fElements.length; 44 } 45 if (fConditionalElements != null) 46 System.arraycopy(fConditionalElements, 0, allElements, conditionalStart, fConditionalElements.length); 47 48 final Button button = new Button(comp, SWT.CHECK); 49 Assert.isNotNull(fButtonText); 50 button.setText(fButtonText); 51 button.addSelectionListener(new SelectionAdapter() { 52 public void widgetSelected(SelectionEvent e) { 53 if (button.getSelection()) 54 setListElements(allElements); 55 else 56 setListElements(fElements); 57 } 58 }); 59 return comp; 60 } 61 62 public void setElements(Object [] elements) { 63 super.setElements(elements); 64 fElements = elements; 65 } 66 67 public void setConditionalElements(Object [] elements) { 68 fConditionalElements = elements; 69 } 70 71 } 72 | Popular Tags |