01: package org.drools.eclipse.rulebuilder.ui;
02:
03: import java.util.Iterator;
04: import java.util.List;
05:
06: import org.drools.brms.client.modeldriven.brl.RuleAttribute;
07: import org.eclipse.swt.SWT;
08: import org.eclipse.swt.layout.GridData;
09: import org.eclipse.swt.layout.GridLayout;
10: import org.eclipse.swt.widgets.Combo;
11: import org.eclipse.swt.widgets.Composite;
12: import org.eclipse.swt.widgets.Control;
13: import org.eclipse.swt.widgets.Event;
14: import org.eclipse.swt.widgets.Listener;
15: import org.eclipse.swt.widgets.Shell;
16:
17: public class RuleAttributesDialog extends RuleDialog {
18:
19: private RuleModeller modeller;
20:
21: public RuleAttributesDialog(Shell parent, RuleModeller modeller) {
22: super (parent, "Add new option to the rule",
23: "Pick the value from combo.");
24:
25: this .modeller = modeller;
26: }
27:
28: protected Control createDialogArea(final Composite parent) {
29: Composite composite = (Composite) super
30: .createDialogArea(parent);
31:
32: GridLayout l = new GridLayout();
33: l.numColumns = 3;
34: l.marginBottom = 0;
35: l.marginHeight = 0;
36: l.marginLeft = 0;
37: l.marginRight = 0;
38: l.marginTop = 0;
39: l.marginWidth = 0;
40: composite.setLayout(l);
41:
42: GridData gd = new GridData(GridData.FILL_HORIZONTAL);
43: gd.horizontalSpan = 2;
44:
45: createAtributesSelectionCombo(composite, gd);
46:
47: return composite;
48: }
49:
50: private void createAtributesSelectionCombo(Composite composite,
51: GridData gd) {
52: createLabel(composite, "Attributes");
53: final Combo combo = new Combo(composite, SWT.READ_ONLY);
54: combo.setLayoutData(gd);
55: List attributes = RuleAttributeWidget.getAttributeList();
56: for (Iterator iterator = attributes.iterator(); iterator
57: .hasNext();) {
58: String attr = (String) iterator.next();
59: combo.add(attr);
60: }
61: combo.select(0);
62:
63: combo.addListener(SWT.Selection, new Listener() {
64: public void handleEvent(Event event) {
65: if (combo.getSelectionIndex() == 0) {
66: return;
67: }
68: modeller.getModel().addAttribute(
69: new RuleAttribute(combo.getText(), ""));
70: modeller.setDirty(true);
71: modeller.reloadOptions();
72: close();
73: }
74: });
75:
76: }
77:
78: }
|