1unit fraschematableseditor; 2 3{$mode objfpc}{$H+} 4 5interface 6 7uses 8 Classes, SysUtils, Forms, Controls, ComCtrls, sqldbrestschema, sqldbschemaedittools; 9 10type 11 12 { TSQLDBRestSchemaTablesEditFrame } 13 14 TSQLDBRestSchemaTablesEditFrame = class(TBaseEditFrame) 15 ILSchema: TImageList; 16 LVSchema: TListView; 17 procedure LVSchemaDblClick(Sender: TObject); 18 private 19 FOnSelectResource: TNotifyEvent; 20 FSchema: TSQLDBRestSchema; 21 procedure AddResourceToList(Res: TSQLDBRestResource); 22 procedure SetSchema(AValue: TSQLDBRestSchema); 23 procedure ShowResource(LI: TListItem; Res: TSQLDBRestResource); 24 Protected 25 procedure SetFrameData(aData: TObject); override; 26 public 27 Procedure ShowSchema; 28 Function Modified : Boolean; override; 29 Procedure SaveData; override; 30 Function FrameCaption : String; override; 31 Property Schema : TSQLDBRestSchema Read FSchema Write SetSchema; 32 Property OnSelectResource : TNotifyEvent Read FOnSelectResource Write FOnSelectResource; 33 end; 34 35implementation 36 37uses dialogs; 38 39Const 40 idxChecked = 0; 41 idxUnChecked = 1; 42 idxTable = 2; 43 44{$R *.lfm} 45 46{ TSQLDBRestSchemaTablesEditFrame } 47 48procedure TSQLDBRestSchemaTablesEditFrame.SetSchema(AValue: TSQLDBRestSchema); 49begin 50 if FSchema=AValue then Exit; 51 FSchema:=AValue; 52 ShowSchema; 53end; 54 55procedure TSQLDBRestSchemaTablesEditFrame.ShowResource(LI: TListItem; 56 Res: TSQLDBRestResource); 57 58 procedure ShowBool(Idx : Integer; B : Boolean); 59 begin 60 LI.SubItems[Idx]:=''; 61 if B then 62 LI.SubItemImages[Idx]:=idxChecked; 63 end; 64 65 Procedure ShowOp(idx : Integer; O : TRestOperation); 66 67 begin 68 ShowBool(Idx,O in Res.AllowedOperations); 69 end; 70 71Var 72 i : Integer; 73 74begin 75// LI.StateIndex:=idxTable; 76 LI.Data:=Res; 77 LI.ImageIndex:=idxTable; 78 LI.Caption:=Res.ResourceName; 79 for I:=0 to LVSchema.ColumnCount-1 do 80 LI.SubItems.Add(''); 81 LI.SubItems[0]:=Res.TableName; 82 LI.SubItems[1]:=Res.ConnectionName; 83 ShowBool(2,Res.Enabled); 84 ShowBool(3,Res.InMetadata); 85 ShowOp(4,roGet); 86 ShowOp(5,roPost); 87 ShowOp(6,roPut); 88 ShowOp(7,roDelete); 89 ShowOp(8,roOptions); 90 ShowOp(9,roHead); 91 92end; 93 94procedure TSQLDBRestSchemaTablesEditFrame.SetFrameData(aData: TObject); 95begin 96 Schema:=aData as TSQLDBRestSchema; 97end; 98 99procedure TSQLDBRestSchemaTablesEditFrame.LVSchemaDblClick(Sender: TObject); 100begin 101 if Assigned(OnSelectResource) and Assigned(LVSchema.Selected) And Assigned(LVSchema.Selected.Data) then 102 OnSelectResource(TSQLDBRestResource(LVSchema.Selected.Data)); 103end; 104 105procedure TSQLDBRestSchemaTablesEditFrame.AddResourceToList( 106 Res: TSQLDBRestResource); 107 108Var 109 LI : TListItem; 110 111begin 112 LI:=LVSchema.Items.Add; 113 ShowResource(LI,Res); 114end; 115 116procedure TSQLDBRestSchemaTablesEditFrame.ShowSchema; 117 118Var 119 I : Integer; 120 121begin 122 With LVSchema.Items do 123 begin 124 BeginUpdate; 125 try 126 Clear; 127 if Not assigned(Schema) then 128 exit; 129 For I:=0 to Schema.Resources.Count-1 do 130 AddResourceToList(Schema.Resources[I]); 131 finally 132 EndUpdate; 133 end; 134 end; 135end; 136 137function TSQLDBRestSchemaTablesEditFrame.Modified: Boolean; 138begin 139 Result:=False; 140end; 141 142procedure TSQLDBRestSchemaTablesEditFrame.SaveData; 143begin 144 // nothing to do 145end; 146 147function TSQLDBRestSchemaTablesEditFrame.FrameCaption: String; 148begin 149 if FSchema=Nil then 150 Result:=SUnknownObject 151 else 152 Result:=Schema.Name; 153 Result:=Format(SEditObject,[SSchema,Result]); 154end; 155 156end. 157 158