1 unit BottleChainRuleEditor;
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, StdCtrls, CheckLst, ComCtrls, BottleChainRule;
10 TfrmBottleChainRuleEditor = class(TForm)
11 PageControl: TPageControl;
12 tstGeneral: TTabSheet;
13 tstCondition: TTabSheet;
15 cbxRuleEnabled: TCheckBox;
19 memStringExpression: TMemo;
20 lstCondition: TCheckListBox;
21 lstAction: TCheckListBox;
22 procedure btnCloseClick(Sender: TObject);
23 procedure lstConditionClickCheck(Sender: TObject);
24 procedure lstActionClickCheck(Sender: TObject);
25 procedure lstConditionDblClick(Sender: TObject);
26 procedure lstActionDblClick(Sender: TObject);
27 procedure edtTitleChange(Sender: TObject);
28 procedure cbxRuleEnabledClick(Sender: TObject);
31 FRule: TBottleChainRule;
32 FConditionsCheckStatus: array [0..High(BottleChainConditions)] of boolean;
33 FActionsCheckStatus: array [0..High(BottleChainActions)] of boolean;
34 procedure lstConditionChecked(Index: integer; Checked: boolean);
35 procedure lstActionChecked(Index: integer; Checked: boolean);
38 procedure InitializeDisplay;
39 procedure UpdateDisplay;
40 procedure Execute(EditRule: TBottleChainRule);
44 frmBottleChainRuleEditor: TfrmBottleChainRuleEditor;
50 { TfrmBottleChainListEditor }
52 procedure TfrmBottleChainRuleEditor.Execute(EditRule: TBottleChainRule);
54 if EditRule = nil then raise Exception.Create('EditRule is null');
61 procedure TfrmBottleChainRuleEditor.UpdateDisplay;
65 memStringExpression.Text := FRule.StringExpression;
66 edtTitle.Text := FRule.Title;
67 cbxRuleEnabled.Checked := FRule.Enabled;
69 for i := 0 to High(BottleChainConditions) do begin
71 for j := 0 to FRule.Conditions.Count-1 do
72 if FRule.Conditions[j].ClassType = BottleChainConditions[i] then begin
74 lstCondition.Items[i] := (FRule.Conditions[j] as TBottleChainCondition).StringExpression;
77 lstCondition.Checked[i] := f;
78 FConditionsCheckStatus[i] := f;
80 lstCondition.Items[i] := BottleChainConditions[i].Title;
83 for i := 0 to High(BottleChainActions) do begin
85 for j := 0 to FRule.Actions.Count-1 do
86 if FRule.Actions[j].ClassType = BottleChainActions[i] then begin
88 lstAction.Items[i] := (FRule.Actions[j] as TBottleChainAction).StringExpression;
91 lstAction.Checked[i] := f;
92 FActionsCheckStatus[i] := f;
94 lstAction.Items[i] := BottleChainActions[i].Title;
98 procedure TfrmBottleChainRuleEditor.btnCloseClick(Sender: TObject);
103 procedure TfrmBottleChainRuleEditor.InitializeDisplay;
105 ConditionClass: TBottleChainConditionClass;
106 ActionClass: TBottleChainActionClass;
108 lstCondition.Items.Clear;
109 for i := 0 to High(BottleChainConditions) do begin
110 ConditionClass := BottleChainConditions[i];
111 lstCondition.Items.Add(ConditionClass.Title);
113 lstAction.Items.Clear;
114 for i := 0 to High(BottleChainActions) do begin
115 ActionClass := BottleChainActions[i];
116 lstAction.Items.Add(ActionClass.Title);
120 procedure TfrmBottleChainRuleEditor.lstConditionClickCheck(
124 //
\82±
\82Ì
\82Ü
\82Ü
\82¾
\82Æ
\95s
\95Ö
\82È
\82Ì
\82Å
\8f\88\97\9d
125 for i := 0 to High(BottleChainConditions) do begin
126 if lstCondition.Checked[i] <> FConditionsCheckStatus[i] then
127 lstConditionChecked(i, lstCondition.Checked[i]);
131 procedure TfrmBottleChainRuleEditor.lstActionClickCheck(Sender: TObject);
134 //
\82±
\82Ì
\82Ü
\82Ü
\82¾
\82Æ
\95s
\95Ö
\82È
\82Ì
\82Å
\8f\88\97\9d
135 for i := 0 to High(BottleChainActions) do begin
136 if lstAction.Checked[i] <> FActionsCheckStatus[i] then
137 lstActionChecked(i, lstAction.Checked[i]);
141 procedure TfrmBottleChainRuleEditor.lstActionChecked(Index: integer;
143 var Action: TBottleChainAction;
146 if Checked then begin
147 Action := BottleChainActions[Index].Create(FRule);
148 Action.Rule := FRule;
149 if Action.Edit then begin
152 lstAction.Checked[Index] := false;
155 for i := FRule.Actions.Count-1 downto 0 do begin
156 if FRule.Actions[i].ClassType = BottleChainActions[Index] then
157 FRule.Actions[i].Free;
163 procedure TfrmBottleChainRuleEditor.lstConditionChecked(Index: integer;
165 var Condition: TBottleChainCondition;
168 if Checked then begin
169 Condition := BottleChainConditions[Index].Create(FRule);
170 Condition.Rule := FRule;
171 if Condition.Edit then begin
174 lstCondition.Checked[Index] := false;
177 for i := FRule.Conditions.Count-1 downto 0 do begin
178 if FRule.Conditions[i].ClassType = BottleChainConditions[Index] then
179 FRule.Conditions[i].Free;
186 procedure TfrmBottleChainRuleEditor.lstConditionDblClick(Sender: TObject);
187 var index, i: integer;
189 index := lstCondition.ItemIndex;
190 if Index < 0 then Exit;
191 if lstCondition.Checked[Index] then begin
192 for i := 0 to FRule.Conditions.Count-1 do
193 if FRule.Conditions[i].ClassType = BottleChainConditions[Index] then begin
194 (FRule.Conditions[i] as TBottleChainCondition).Edit;
198 lstCondition.Checked[Index] := true;
199 lstConditionChecked(Index, true);
204 procedure TfrmBottleChainRuleEditor.lstActionDblClick(Sender: TObject);
205 var index, i: integer;
207 index := lstAction.ItemIndex;
208 if Index < 0 then Exit;
209 if lstAction.Checked[Index] then begin
210 for i := 0 to FRule.Actions.Count-1 do
211 if FRule.Actions[i].ClassType = BottleChainActions[Index] then begin
212 (FRule.Actions[i] as TBottleChainAction).Edit;
216 lstAction.Checked[Index] := true;
217 lstActionChecked(Index, true);
222 procedure TfrmBottleChainRuleEditor.edtTitleChange(Sender: TObject);
224 FRule.Title := edtTitle.Text;
227 procedure TfrmBottleChainRuleEditor.cbxRuleEnabledClick(Sender: TObject);
229 FRule.Enabled := cbxRuleEnabled.Checked;