home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 December / Chip_2001-12_cd1.bin / zkuste / delphi / kolekce / d456 / VOLGAPAK.ZIP / Source / VolColEditor.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-09-20  |  4.9 KB  |  190 lines

  1. unit VolColEditor;
  2.  
  3. interface
  4. uses
  5.   SysUtils, Classes,
  6. {$IFDEF VER140} DesignIntf, DesignEditors, {$ELSE} DsgnIntf, {$ENDIF}
  7.   ColnEdit, DB, Menus, Dialogs, Controls;
  8.  
  9. type
  10.   TVolgaDBGridColumnsEditor = class(TCollectionEditor)
  11.   private
  12.     procedure AddAllClick(Sender: TObject);
  13.   protected
  14.     function CanAdd(Index: Integer): Boolean; override;
  15.   public
  16.     mnuAddAll: TMenuItem;
  17.     mnuLine: TMenuItem;
  18.     constructor Create(AOwner: TComponent); override;
  19.   end;
  20.  
  21. { TVolgaDBGridColumnsProperty }
  22.  
  23.   TVolgaDBGridColumnsProperty = class(TClassProperty)
  24.   public
  25.     procedure Edit; override;
  26.     function GetAttributes: TPropertyAttributes; override;
  27.     function GetValue: string; override;
  28.   end;
  29.  
  30. { TVolgaDBGridEditor }
  31.  
  32.   TVolgaDBGridEditor = class(TComponentEditor)
  33.   public
  34.     procedure ExecuteVerb(Index: Integer); override;
  35.     function GetVerb(Index: Integer): string; override;
  36.     function GetVerbCount: Integer; override;
  37.   end;
  38.  
  39. { TVolgaColumnDataFieldProperty }
  40.  
  41.   TVolgaColumnDataFieldProperty = class(TStringProperty)
  42.   public
  43.     function GetAttributes: TPropertyAttributes; override;
  44.     procedure GetValueList(List: TStrings); virtual;
  45.     procedure GetValues(Proc: TGetStrProc); override;
  46.   end;
  47.  
  48. { TVolgaColumnLookupKeyProperty }
  49.  
  50.   TVolgaColumnLookupKeyProperty = class(TStringProperty)
  51.   public
  52.     function GetAttributes: TPropertyAttributes; override;
  53.     procedure GetValueList(List: TStrings); virtual;
  54.     procedure GetValues(Proc: TGetStrProc); override;
  55.   end;
  56.  
  57. implementation
  58. uses VolDBGrid;
  59.  
  60. { TVolgaDBGridColumnsProperty }
  61.  
  62. procedure TVolgaDBGridColumnsProperty.Edit;
  63. begin
  64.   ShowCollectionEditorClass(Designer, TVolgaDBGridColumnsEditor,
  65.     GetComponent(0) as TComponent, TVolgaDBGridColumns(GetOrdValue), GetName);
  66. end;
  67.  
  68. function TVolgaDBGridColumnsProperty.GetAttributes: TPropertyAttributes;
  69. begin
  70.   Result := [paDialog, paReadOnly];
  71. end;
  72.  
  73. function TVolgaDBGridColumnsProperty.GetValue: string;
  74. begin
  75.   FmtStr(Result, '(%s)', [GetPropType^.Name]);
  76. end;
  77.  
  78. { TVolgaDBGridEditor }
  79.  
  80. procedure TVolgaDBGridEditor.ExecuteVerb(Index: Integer);
  81. begin
  82.   ShowCollectionEditorClass(Designer, TVolgaDBGridColumnsEditor, Component,
  83.     TVolgaDBGrid(Component).Columns, 'Columns');
  84. end;
  85.  
  86. function TVolgaDBGridEditor.GetVerb(Index: Integer): string;
  87. begin
  88.   Result := 'Columns Editor...';
  89. end;
  90.  
  91. function TVolgaDBGridEditor.GetVerbCount: Integer;
  92. begin
  93.   Result := 1;
  94. end;
  95.  
  96. { TVolgaColumnDataFieldProperty }
  97.  
  98. procedure TVolgaColumnDataFieldProperty.GetValueList(List: TStrings);
  99. var
  100.   Grid: TVolgaCustomDBGrid;
  101.   DataSource: TDataSource;
  102. begin
  103.   Grid := (GetComponent(0) as VolDBGrid.TVolgaColumn).Grid;
  104.   if (Grid = nil) then Exit;
  105.   DataSource := Grid.DataSource;
  106.   if (DataSource <> nil) and (DataSource.DataSet <> nil)
  107.   and (DataSource.DataSet.FieldCount > 0) then
  108.     DataSource.DataSet.GetFieldNames(List);
  109. end;
  110.  
  111. function TVolgaColumnDataFieldProperty.GetAttributes: TPropertyAttributes;
  112. begin
  113.   Result := [paValueList, paSortList, paMultiSelect];
  114. end;
  115.  
  116. procedure TVolgaColumnDataFieldProperty.GetValues(Proc: TGetStrProc);
  117. var
  118.   I: Integer;
  119.   Values: TStringList;
  120. begin
  121.   Values := TStringList.Create;
  122.   try
  123.     GetValueList(Values);
  124.     for I := 0 to Values.Count - 1 do
  125.       Proc(Values[I]);
  126.   finally
  127.     Values.Free;
  128.   end;
  129. end;
  130.  
  131. { TVolgaColumnLookupKeyProperty }
  132.  
  133. procedure TVolgaColumnLookupKeyProperty.GetValueList(List: TStrings);
  134. var
  135.   Column: TVolgaColumn;
  136. begin
  137.   Column := GetComponent(0) as VolDBGrid.TVolgaColumn;
  138.   if (Column = nil) then Exit;
  139.   if (Column.LookupDataSet <> nil) and (Column.LookupDataSet.FieldCount>0) then
  140.     Column.LookupDataSet.GetFieldNames(List);
  141. end;
  142.  
  143. function TVolgaColumnLookupKeyProperty.GetAttributes: TPropertyAttributes;
  144. begin
  145.   Result := [paValueList, paSortList, paMultiSelect];
  146. end;
  147.  
  148. procedure TVolgaColumnLookupKeyProperty.GetValues(Proc: TGetStrProc);
  149. var
  150.   I: Integer;
  151.   Values: TStringList;
  152. begin
  153.   Values := TStringList.Create;
  154.   try
  155.     GetValueList(Values);
  156.     for I := 0 to Values.Count - 1 do
  157.       Proc(Values[I]);
  158.   finally
  159.     Values.Free;
  160.   end;
  161. end;
  162.  
  163. { TVolgaDBGridColumnsEditor }
  164.  
  165. constructor TVolgaDBGridColumnsEditor.Create(AOwner: TComponent);
  166. begin
  167.   inherited;
  168.   mnuAddAll := NewItem('Add all fields', 0, false, true, AddAllClick, 0, 'mnuAddAll');
  169.   PopupMenu1.Items.Add(mnuAddAll);
  170.   mnuAddAll.MenuIndex := 0;
  171.   mnuLine := NewItem('-', 0, false, true, nil, 0, 'mnuLine');
  172.   PopupMenu1.Items.Add(mnuLine);
  173.   mnuLine.MenuIndex := 1;
  174. end;
  175.  
  176. function TVolgaDBGridColumnsEditor.CanAdd(Index: Integer): Boolean;
  177. begin  //∩εΩατ√Γασ∞ ≥εδⁿΩε ≥σ ΩεδεφΩΦ, Ωε≥ε≡√σ ß√δΦ ≡αφσσ Φτ∞σφσφ√
  178.   Result := TVolgaDBGridColumns(Collection).State = csCustomized;
  179. end;
  180.  
  181. procedure TVolgaDBGridColumnsEditor.AddAllClick(Sender: TObject);
  182. begin
  183.   with TVolgaDBGridColumns(Collection) do
  184.     if State = csDefault then State := csCustomized;
  185.   UpdateListbox;
  186.   Designer.Modified;
  187. end;
  188.  
  189. end.
  190.