1 11 package org.eclipse.pde.internal.ui.commands; 12 13 import org.eclipse.core.commands.Command; 14 import org.eclipse.swt.SWT; 15 import org.eclipse.swt.events.SelectionAdapter; 16 import org.eclipse.swt.events.SelectionEvent; 17 import org.eclipse.swt.layout.GridData; 18 import org.eclipse.swt.layout.GridLayout; 19 import org.eclipse.swt.widgets.Button; 20 import org.eclipse.swt.widgets.Composite; 21 import org.eclipse.swt.widgets.Group; 22 import org.eclipse.ui.commands.ICommandService; 23 import org.eclipse.ui.forms.widgets.FormToolkit; 24 25 public abstract class QueryControl { 26 27 protected final CommandComposerPart fCSP; 28 protected final FormToolkit fToolkit; 29 protected Button fRadioButton; 30 protected Group fGroup; 31 32 protected QueryControl(CommandComposerPart csp, Composite parent) { 33 fCSP = csp; 34 fToolkit = csp.getToolkit(); 35 createGroup(parent); 36 } 37 38 protected ICommandService getCommandService() { 39 return fCSP.getCommandService(); 40 } 41 42 private Group createGroup(Composite parent) { 43 fRadioButton = fToolkit.createButton(parent, "", SWT.RADIO); fRadioButton.addSelectionListener(new SelectionAdapter() { 45 public void widgetSelected(SelectionEvent e) { 46 enable(fRadioButton.getSelection()); 47 } 48 }); 49 fGroup = new Group(parent, SWT.NONE); 50 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 51 fGroup.setLayoutData(gd); 52 fGroup.setLayout(new GridLayout()); 53 fGroup.setText(getName()); 54 createGroupContents(fGroup); 55 fToolkit.adapt(fGroup, false, false); 56 return fGroup; 57 } 58 59 protected QueryControl select(boolean select) { 60 fRadioButton.setSelection(select); 61 return this; 62 } 63 64 protected abstract void createGroupContents(Group parent); 65 66 protected abstract String getName(); 67 68 protected abstract void enable(boolean enable); 69 70 protected abstract Command[] getCommands(); 71 72 } 73 | Popular Tags |