File: frasqldbresourcefields.pp

package info (click to toggle)
lazarus 2.2.6%2Bdfsg2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 219,980 kB
  • sloc: pascal: 1,944,919; xml: 357,634; makefile: 270,608; cpp: 57,115; sh: 3,249; java: 609; perl: 297; sql: 222; ansic: 137
file content (157 lines) | stat: -rw-r--r-- 3,486 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
unit frasqldbresourcefields;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, ComCtrls, DB, sqldbrestschema, sqldbschemaedittools;

type
  { TResourceFieldsEditFrame }

  TResourceFieldsEditFrame = class(TBaseEditFrame)
    ILFields: TImageList;
    LVFields: TListView;
    procedure LVFieldsDblClick(Sender: TObject);
  private
    FOnSelectField: TNotifyEvent;
    FResource: TSQLDBRestResource;
    procedure AddFieldToList(Fld: TSQLDBRestField);
    procedure SetResource(AValue: TSQLDBRestResource);
    procedure ShowField(LI: TListItem; Fld: TSQLDBRestField);
  Protected
    procedure SetFrameData(aData: TObject); override;
  public
    Procedure ShowResource;
    Function Modified : Boolean; override;
    Procedure SaveData; override;
    Function FrameCaption : String; override;
    Property Resource : TSQLDBRestResource Read FResource Write SetResource;
    Property OnSelectField : TNotifyEvent Read FOnSelectField Write FOnSelectField;
  end;

implementation

uses typinfo;

{$R *.lfm}
Const
  idxChecked   = 0;
  idxUnChecked = 1;
  idxField     = 2;
  idxKey       = 3;

{ TResourceFieldsEditFrame }

procedure TResourceFieldsEditFrame.SetResource(AValue: TSQLDBRestResource);
begin
  if FResource=AValue then Exit;
  FResource:=AValue;
  ShowResource;
end;

procedure TResourceFieldsEditFrame.SetFrameData(aData: TObject);
begin
  Resource:=aData as TSQLDBRestResource;
end;

procedure TResourceFieldsEditFrame.ShowField(LI: TListItem; Fld: TSQLDBRestField);

  procedure ShowBool(Idx : Integer; B : Boolean; ImgIdx : Integer = idxChecked);


  begin
    LI.SubItems[Idx]:='';
    if B then
      LI.SubItemImages[Idx]:=ImgIdx;
  end;

  Procedure ShowOp(idx : Integer; O : TRestFieldOption);

  begin
    ShowBool(Idx,O in fld.Options);
  end;

Var
  i : Integer;
  S : String;

begin
  LI.Data:=Fld;
  LI.ImageIndex:=idxField;
  LI.Caption:=Fld.PublicName;
  for I:=0 to LVFields.ColumnCount-1 do
    LI.SubItems.Add('');
  LI.SubItems[0]:=Fld.FieldName;
  LI.SubItems[1]:=TypeNames[Fld.FieldType];
  S:=GetEnumName(TypeInfo(TFieldType),Ord(Fld.NativeFieldType));
  LI.SubItems[2]:=S;
  LI.SubItems[3]:=Fld.GeneratorName;
  ShowBool(4,foInKey in Fld.Options,idxKey);
  ShowOp(5,foInInsert);
  ShowOp(6,foInUpdate);
  ShowOp(7,foRequired);
  ShowOp(8,foFilter);
  ShowOp(9,foOrderBy);
  ShowOp(10,foOrderByDesc);
end;

procedure TResourceFieldsEditFrame.LVFieldsDblClick(Sender: TObject);
begin
  if Assigned(OnSelectField) and Assigned(LVFields.Selected) And Assigned(LVFields.Selected.Data) then
    OnSelectField(TSQLDBRestResource(LVFields.Selected.Data));
end;

procedure TResourceFieldsEditFrame.AddFieldToList(Fld: TSQLDBRestField);

Var
  LI : TListItem;

begin
  LI:=LVFields.Items.Add;
  ShowField(LI,Fld);
end;

procedure TResourceFieldsEditFrame.ShowResource;

Var
  I : Integer;

begin
  With LVFields.Items do
    begin
    BeginUpdate;
    try
      Clear;
      if Not assigned(Resource) then
        exit;
      For I:=0 to Resource.Fields.Count-1 do
        AddFieldToList(Resource.Fields[I]);
    finally
      EndUpdate;
    end;
    end;
end;

function TResourceFieldsEditFrame.Modified: Boolean;
begin
  Result:=False;
end;

procedure TResourceFieldsEditFrame.SaveData;
begin
  // nothing to do
end;

function TResourceFieldsEditFrame.FrameCaption: String;
begin
  if FResource=Nil then
    Result:=SUnknownObject
  else
    Result:=Resource.ResourceName;
  Result:=Format(SEditObjectFields,[Result]);
end;

end.