01: /*******************************************************************************
02: * Copyright (c) 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.commands;
11:
12: import org.eclipse.core.commands.Command;
13: import org.eclipse.swt.SWT;
14: import org.eclipse.swt.events.SelectionAdapter;
15: import org.eclipse.swt.events.SelectionEvent;
16: import org.eclipse.swt.layout.GridData;
17: import org.eclipse.swt.layout.GridLayout;
18: import org.eclipse.swt.widgets.Button;
19: import org.eclipse.swt.widgets.Composite;
20: import org.eclipse.swt.widgets.Group;
21: import org.eclipse.ui.commands.ICommandService;
22: import org.eclipse.ui.forms.widgets.FormToolkit;
23:
24: public abstract class QueryControl {
25:
26: protected final CommandComposerPart fCSP;
27: protected final FormToolkit fToolkit;
28: protected Button fRadioButton;
29: protected Group fGroup;
30:
31: protected QueryControl(CommandComposerPart csp, Composite parent) {
32: fCSP = csp;
33: fToolkit = csp.getToolkit();
34: createGroup(parent);
35: }
36:
37: protected ICommandService getCommandService() {
38: return fCSP.getCommandService();
39: }
40:
41: private Group createGroup(Composite parent) {
42: fRadioButton = fToolkit.createButton(parent, "", SWT.RADIO); //$NON-NLS-1$
43: fRadioButton.addSelectionListener(new SelectionAdapter() {
44: public void widgetSelected(SelectionEvent e) {
45: enable(fRadioButton.getSelection());
46: }
47: });
48: fGroup = new Group(parent, SWT.NONE);
49: GridData gd = new GridData(GridData.FILL_HORIZONTAL);
50: fGroup.setLayoutData(gd);
51: fGroup.setLayout(new GridLayout());
52: fGroup.setText(getName());
53: createGroupContents(fGroup);
54: fToolkit.adapt(fGroup, false, false);
55: return fGroup;
56: }
57:
58: protected QueryControl select(boolean select) {
59: fRadioButton.setSelection(select);
60: return this ;
61: }
62:
63: protected abstract void createGroupContents(Group parent);
64:
65: protected abstract String getName();
66:
67: protected abstract void enable(boolean enable);
68:
69: protected abstract Command[] getCommands();
70:
71: }
|