1 11 package org.eclipse.pde.ui.templates; 12 import org.eclipse.swt.SWT; 13 import org.eclipse.swt.events.SelectionAdapter; 14 import org.eclipse.swt.events.SelectionEvent; 15 import org.eclipse.swt.layout.GridData; 16 import org.eclipse.swt.widgets.Button; 17 import org.eclipse.swt.widgets.Composite; 18 19 26 public class BooleanOption extends TemplateOption { 27 private Button button; 28 38 public BooleanOption(BaseOptionTemplateSection section, String name, 39 String label) { 40 super(section, name, label); 41 } 42 47 public boolean isSelected() { 48 return getValue() != null && getValue().equals(Boolean.TRUE); 49 } 50 56 public void setSelected(boolean selected) { 57 setValue(selected ? Boolean.TRUE : Boolean.FALSE); 58 } 59 66 public void setValue(Object value) { 67 super.setValue(value); 68 if (button != null) 69 button.setSelection(isSelected()); 70 } 71 80 public void createControl(Composite parent, int span) { 81 button = new Button(parent, SWT.CHECK); 82 button.setText(getLabel()); 83 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 84 gd.horizontalSpan = span; 85 button.setLayoutData(gd); 86 button.setSelection(isSelected()); 87 button.addSelectionListener(new SelectionAdapter() { 88 public void widgetSelected(SelectionEvent e) { 89 BooleanOption.super.setValue(button.getSelection() 90 ? Boolean.TRUE 91 : Boolean.FALSE); 92 getSection().validateOptions(BooleanOption.this); 93 } 94 }); 95 button.setEnabled(isEnabled()); 96 } 97 104 public void setEnabled(boolean enabled) { 105 super.setEnabled(enabled); 106 if (button != null) 107 button.setEnabled(enabled); 108 } 109 } 110 | Popular Tags |