01: package org.drools.eclipse.rulebuilder.ui;
02:
03: import org.drools.brms.client.modeldriven.brl.SingleFieldConstraint;
04: import org.eclipse.swt.SWT;
05: import org.eclipse.swt.layout.GridData;
06: import org.eclipse.swt.layout.GridLayout;
07: import org.eclipse.swt.widgets.Button;
08: import org.eclipse.swt.widgets.Composite;
09: import org.eclipse.swt.widgets.Control;
10: import org.eclipse.swt.widgets.Event;
11: import org.eclipse.swt.widgets.Listener;
12: import org.eclipse.swt.widgets.Shell;
13: import org.eclipse.swt.widgets.Text;
14: import org.eclipse.ui.forms.widgets.FormToolkit;
15:
16: public class AssignFieldVariableDialog extends RuleDialog {
17:
18: private final FormToolkit toolkit;
19:
20: private RuleModeller modeller;
21:
22: private SingleFieldConstraint con;
23:
24: public AssignFieldVariableDialog(Shell parent, FormToolkit toolkit,
25: RuleModeller modeller, SingleFieldConstraint con) {
26: super (parent, "Bind the field called [" + con.fieldName
27: + "] to a variable.",
28: "Type the variable name and hit the button.");
29:
30: this .toolkit = toolkit;
31: this .modeller = modeller;
32: this .con = con;
33: }
34:
35: protected Control createDialogArea(final Composite parent) {
36: Composite composite = (Composite) super
37: .createDialogArea(parent);
38:
39: GridLayout l = new GridLayout();
40: l.numColumns = 5;
41: l.marginBottom = 0;
42: l.marginHeight = 0;
43: l.marginLeft = 0;
44: l.marginRight = 0;
45: l.marginTop = 0;
46: l.marginWidth = 0;
47: composite.setLayout(l);
48:
49: createVariableBindingRow(composite);
50: toolkit.paintBordersFor(composite);
51: return composite;
52: }
53:
54: private void createVariableBindingRow(Composite composite) {
55: createLabel(composite, "Variable name");
56: final Text variableText = toolkit.createText(composite, "");
57:
58: if (con.fieldBinding != null) {
59: variableText.setText(con.fieldBinding);
60: }
61:
62: GridData gd = new GridData(GridData.FILL_HORIZONTAL);
63: gd.horizontalSpan = 3;
64:
65: variableText.setLayoutData(gd);
66:
67: Button varButton = toolkit.createButton(composite, "Set",
68: SWT.PUSH);
69: varButton.addListener(SWT.Selection, new Listener() {
70: public void handleEvent(Event event) {
71: con.fieldBinding = variableText.getText();
72: modeller.reloadLhs();
73: modeller.setDirty(true);
74: close();
75: }
76: });
77: }
78:
79: }
|