summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-09-07 22:20:47 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-09-07 22:20:47 +0000
commitba30bb0298fc9c7b448d280884d1beb1368300c3 (patch)
tree8d23eb38cc82bd0841a77719464e76a177c4b558
parenta89206b6e0221d5cd71c60541b4f273e294396de (diff)
downloadfpGUI-ba30bb0298fc9c7b448d280884d1beb1368300c3.tar.xz
* Bugfix in TDynamicComboBoxView mediator class.
* A few other minor changes to mediators * Extended the tiOPF demo 21 even further, showing more features of MGM implementation.
-rw-r--r--extras/tiopf/demos/Demo_21_AdrsBook_MGM/demo_adrsbook_mgm.lpi14
-rw-r--r--extras/tiopf/demos/Demo_21_AdrsBook_MGM/demo_adrsbook_mgm.lpr2
-rw-r--r--extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmcitylist.pas30
-rw-r--r--extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmcitymaint.pas178
-rw-r--r--extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmcontactmaint.pas2
-rw-r--r--extras/tiopf/demos/Demo_21_AdrsBook_MGM/model.pas2
-rw-r--r--extras/tiopf/gui/tiListMediators.pas14
-rw-r--r--extras/tiopf/gui/tiMediators.pas8
8 files changed, 231 insertions, 19 deletions
diff --git a/extras/tiopf/demos/Demo_21_AdrsBook_MGM/demo_adrsbook_mgm.lpi b/extras/tiopf/demos/Demo_21_AdrsBook_MGM/demo_adrsbook_mgm.lpi
index 87043803..3260b2ee 100644
--- a/extras/tiopf/demos/Demo_21_AdrsBook_MGM/demo_adrsbook_mgm.lpi
+++ b/extras/tiopf/demos/Demo_21_AdrsBook_MGM/demo_adrsbook_mgm.lpi
@@ -32,7 +32,7 @@
<PackageName Value="tiOPFfpGUI"/>
</Item1>
</RequiredPackages>
- <Units Count="6">
+ <Units Count="7">
<Unit0>
<Filename Value="demo_adrsbook_mgm.lpr"/>
<IsPartOfProject Value="True"/>
@@ -56,13 +56,18 @@
<Unit4>
<Filename Value="frmcontactmaint.pas"/>
<IsPartOfProject Value="True"/>
- <UnitName Value="frmcontactmaint"/>
+ <UnitName Value="frmContactMaint"/>
</Unit4>
<Unit5>
<Filename Value="frmcitylist.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="frmCityList"/>
</Unit5>
+ <Unit6>
+ <Filename Value="frmcitymaint.pas"/>
+ <IsPartOfProject Value="True"/>
+ <UnitName Value="frmCityMaint"/>
+ </Unit6>
</Units>
</ProjectOptions>
<CompilerOptions>
@@ -70,10 +75,13 @@
<Parsing>
<SyntaxOptions>
<CStyleOperator Value="False"/>
+ <AllowLabel Value="False"/>
+ <CPPInline Value="False"/>
</SyntaxOptions>
</Parsing>
<Other>
- <CustomOptions Value="-FUunits"/>
+ <CustomOptions Value="-FUunits
+"/>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
diff --git a/extras/tiopf/demos/Demo_21_AdrsBook_MGM/demo_adrsbook_mgm.lpr b/extras/tiopf/demos/Demo_21_AdrsBook_MGM/demo_adrsbook_mgm.lpr
index 7dbad7f5..aa2ba6e0 100644
--- a/extras/tiopf/demos/Demo_21_AdrsBook_MGM/demo_adrsbook_mgm.lpr
+++ b/extras/tiopf/demos/Demo_21_AdrsBook_MGM/demo_adrsbook_mgm.lpr
@@ -6,7 +6,7 @@ uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
- Classes, fpgfx, frmmain, frmcontactmaint, frmCityList;
+ Classes, fpgfx, frmmain, frmcontactmaint, frmCityList, frmcitymaint;
diff --git a/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmcitylist.pas b/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmcitylist.pas
index 9c83c09d..f29882e5 100644
--- a/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmcitylist.pas
+++ b/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmcitylist.pas
@@ -5,12 +5,10 @@ unit frmCityList;
interface
uses
- SysUtils, Classes, gfxbase, fpgfx, gui_edit,
- gfx_widget, gui_form, gui_label, gui_button,
- gui_listbox, gui_memo, gui_combobox, gui_basegrid, gui_grid,
- gui_dialogs, gui_checkbox, gui_tree, gui_trackbar,
- gui_progressbar, gui_radiobutton, gui_tab, gui_menu,
- gui_panel, gui_popupcalendar, gui_gauge,
+ SysUtils, Classes, gfxbase, fpgfx,
+ gfx_widget, gui_form, gui_button,
+ gui_grid, gui_dialogs, gui_menu,
+ gui_panel,
tiFormMediator, model;
type
@@ -29,6 +27,7 @@ type
FMediator: TFormMediator;
procedure SetData(const AValue: TCityList);
procedure SetupMediators;
+ procedure btnEditClicked(Sender: TObject);
public
procedure AfterCreate; override;
procedure AfterConstruction; override;
@@ -43,7 +42,7 @@ procedure ShowCities(const AList: TCityList);
implementation
uses
- tiListMediators;
+ tiListMediators, frmCityMaint{, tiDialogs};
procedure ShowCities(const AList: TCityList);
@@ -72,6 +71,22 @@ begin
FMediator.Active := True;
end;
+procedure TCityListForm.btnEditClicked(Sender: TObject);
+var
+ c: TCity;
+begin
+ c := TCity(TStringGridMediator(FMediator.FindByComponent(grdName1).Mediator).SelectedObject);
+// tiShowString(c.AsDebugString);
+
+ if not Assigned(c) then
+ Exit; //==>
+
+ if EditCity(c) then
+ begin
+ // we can save contact here
+ end;
+end;
+
procedure TCityListForm.SetData(const AValue: TCityList);
begin
if FData=AValue then exit;
@@ -114,6 +129,7 @@ begin
FontDesc := '#Label1';
ImageName := '';
TabOrder := 1;
+ OnClick := @btnEditClicked;
end;
btnDelete := TfpgButton.Create(bvlName1);
diff --git a/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmcitymaint.pas b/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmcitymaint.pas
new file mode 100644
index 00000000..01db6ea2
--- /dev/null
+++ b/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmcitymaint.pas
@@ -0,0 +1,178 @@
+unit frmCityMaint;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+ SysUtils, Classes, gfxbase, fpgfx, gui_edit,
+ gfx_widget, gui_form, gui_label, gui_button,
+ gui_dialogs, gui_combobox,
+ model, tiFormMediator;
+
+type
+
+ TCityEditForm = class(TfpgForm)
+ private
+ {@VFD_HEAD_BEGIN: CityEditForm}
+ lblName1: TfpgLabel;
+ edName: TfpgEdit;
+ lblName2: TfpgLabel;
+ edZIP: TfpgEdit;
+ lblName3: TfpgLabel;
+ cbCountry: TfpgComboBox;
+ btnSave: TfpgButton;
+ btnCancel: TfpgButton;
+ {@VFD_HEAD_END: CityEditForm}
+ FMediator: TFormMediator;
+ FData: TCity;
+ procedure SetData(const AValue: TCity);
+ procedure SetupMediators;
+ public
+ procedure AfterCreate; override;
+ property Data: TCity read FData write SetData;
+ end;
+
+{@VFD_NEWFORM_DECL}
+
+function EditCity(AData: TCity): boolean;
+
+
+implementation
+
+uses
+ tiBaseMediator, tiMediators, contactmanager, typinfo;
+
+
+function EditCity(AData: TCity): boolean;
+var
+ frm: TCityEditForm;
+begin
+ frm:= TCityEditForm.Create(nil);
+ try
+ frm.SetData(AData);
+ result:= frm.ShowModal = mrOK;
+ finally
+ frm.Free;
+ end;
+end;
+
+{@VFD_NEWFORM_IMPL}
+
+procedure TCityEditForm.SetData(const AValue: TCity);
+begin
+ if FData=AValue then exit;
+ FData:=AValue;
+ SetupMediators;
+end;
+
+procedure TCityEditForm.SetupMediators;
+begin
+ if not Assigned(FMediator) then
+ begin
+ RegisterFallBackMediators;
+ gMediatorManager.RegisterMediator(TMediatorDynamicComboBoxView, TCity, 'Country');
+
+ FMediator := TFormMediator.Create(self);
+ FMediator.AddProperty('Name', edName);
+ FMediator.AddProperty('ZIP', edZIP);
+ FMediator.AddProperty('Country', cbCountry).ValueList := gContactManager.CountryList;
+ end;
+ FMediator.Subject := FData;
+ FMediator.Active := True;
+end;
+
+procedure TCityEditForm.AfterCreate;
+begin
+ {@VFD_BODY_BEGIN: CityEditForm}
+ Name := 'CityEditForm';
+ SetPosition(673, 204, 260, 186);
+ WindowTitle := 'City Maintenance';
+
+ lblName1 := TfpgLabel.Create(self);
+ with lblName1 do
+ begin
+ Name := 'lblName1';
+ SetPosition(8, 8, 80, 16);
+ FontDesc := '#Label1';
+ Text := 'City name:';
+ end;
+
+ edName := TfpgEdit.Create(self);
+ with edName do
+ begin
+ Name := 'edName';
+ SetPosition(8, 24, 200, 22);
+ TabOrder := 1;
+ Text := '';
+ FontDesc := '#Edit1';
+ end;
+
+ lblName2 := TfpgLabel.Create(self);
+ with lblName2 do
+ begin
+ Name := 'lblName2';
+ SetPosition(8, 52, 80, 16);
+ FontDesc := '#Label1';
+ Text := 'ZIP code:';
+ end;
+
+ edZIP := TfpgEdit.Create(self);
+ with edZIP do
+ begin
+ Name := 'edZIP';
+ SetPosition(8, 68, 120, 22);
+ TabOrder := 3;
+ Text := '';
+ FontDesc := '#Edit1';
+ end;
+
+ lblName3 := TfpgLabel.Create(self);
+ with lblName3 do
+ begin
+ Name := 'lblName3';
+ SetPosition(8, 96, 80, 16);
+ FontDesc := '#Label1';
+ Text := 'Country:';
+ end;
+
+ cbCountry := TfpgComboBox.Create(self);
+ with cbCountry do
+ begin
+ Name := 'cbCountry';
+ SetPosition(8, 112, 200, 22);
+ FontDesc := '#List';
+ TabOrder := 5;
+ end;
+
+ btnSave := TfpgButton.Create(self);
+ with btnSave do
+ begin
+ Name := 'btnSave';
+ SetPosition(92, 156, 80, 24);
+ Anchors := [anRight,anBottom];
+ Text := 'Save';
+ FontDesc := '#Label1';
+ ImageName := '';
+ TabOrder := 6;
+ ModalResult := mrOK;
+ end;
+
+ btnCancel := TfpgButton.Create(self);
+ with btnCancel do
+ begin
+ Name := 'btnCancel';
+ SetPosition(176, 156, 80, 24);
+ Anchors := [anRight,anBottom];
+ Text := 'Cancel';
+ FontDesc := '#Label1';
+ ImageName := '';
+ TabOrder := 7;
+ ModalResult := mrCancel;
+ end;
+
+ {@VFD_BODY_END: CityEditForm}
+end;
+
+
+end.
diff --git a/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmcontactmaint.pas b/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmcontactmaint.pas
index c3dc8496..404c9e2c 100644
--- a/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmcontactmaint.pas
+++ b/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmcontactmaint.pas
@@ -1,4 +1,4 @@
-unit frmcontactmaint;
+unit frmContactMaint;
{$mode objfpc}{$H+}
diff --git a/extras/tiopf/demos/Demo_21_AdrsBook_MGM/model.pas b/extras/tiopf/demos/Demo_21_AdrsBook_MGM/model.pas
index 2e5b52c1..147213e1 100644
--- a/extras/tiopf/demos/Demo_21_AdrsBook_MGM/model.pas
+++ b/extras/tiopf/demos/Demo_21_AdrsBook_MGM/model.pas
@@ -41,7 +41,7 @@ type
protected
function GetCaption: string; override;
public
- constructor CreateNew(const AISO: string; const AName: string); overload;
+ constructor CreateNew(const AISO: string; const AName: string); overload; reintroduce;
published
property ISO: string read FISO write SetISO;
property Name: string read FName write SetName;
diff --git a/extras/tiopf/gui/tiListMediators.pas b/extras/tiopf/gui/tiListMediators.pas
index 5aca05d7..f00fa56d 100644
--- a/extras/tiopf/gui/tiListMediators.pas
+++ b/extras/tiopf/gui/tiListMediators.pas
@@ -33,9 +33,10 @@ type
procedure SetSelectedObject(const AValue: TtiObject);override;
procedure CreateColumns; override;
procedure DoCreateItemMediator(AData: TtiObject; ARowIdx : Integer); override;
- Function GetGuiControl : TComponent; override;
- Procedure SetGuiControl (Const AValue : TComponent); override;
+ function GetGuiControl : TComponent; override;
+ procedure SetGuiControl (Const AValue : TComponent); override;
procedure SetupGUIandObject; override;
+ procedure ClearList; override;
procedure RebuildList; override;
public
constructor CreateCustom(AModel: TtiObjectList; AView: TfpgListView; ADisplayNames: string; AIsObserving: Boolean = True); overload;
@@ -43,7 +44,7 @@ type
class function ComponentClass: TClass; override;
Constructor Create; override;
Destructor Destroy; override;
- procedure HandleSelectionChanged; override;
+ procedure HandleSelectionChanged; {override;}
published
property View: TfpgListView read FView Write SetView;
end;
@@ -131,7 +132,7 @@ type
destructor Destroy; override;
class function CompositeMediator: Boolean; override;
class function ComponentClass: TClass; override;
- procedure HandleSelectionChanged; override;
+ procedure HandleSelectionChanged; {override;}
property View: TfpgListBox read FView;
end;
@@ -234,6 +235,11 @@ begin
// FView.ScrollBars := ssAutoBoth;
end;
+procedure TListViewMediator.ClearList;
+begin
+ View.Items.Clear;
+end;
+
procedure TListViewMediator.RebuildList;
begin
MediatorList.Clear;
diff --git a/extras/tiopf/gui/tiMediators.pas b/extras/tiopf/gui/tiMediators.pas
index 828a5eb8..2825c1f4 100644
--- a/extras/tiopf/gui/tiMediators.pas
+++ b/extras/tiopf/gui/tiMediators.pas
@@ -508,8 +508,10 @@ end;
procedure TMediatorDynamicComboBoxView.SetListObject(const AValue: TtiObjectList);
begin
- Inherited;
+ inherited;
InternalListRefresh;
+ if Assigned(ValueList) then
+ EditControl.Enabled := ValueList.Count > 0;
end;
procedure TMediatorDynamicComboBoxView.InternalListRefresh;
@@ -565,7 +567,9 @@ begin
if UseInternalOnChange then
EditControl.OnChange := @DoOnChange; // default OnChange event handler
- EditControl.Enabled := (ValueList.Count > 0);
+ {$Note As far as I can see, ValueList is always going to be nil here! - Graeme }
+ if ValueList <> nil then
+ EditControl.Enabled := (ValueList.Count > 0);
end;
procedure TMediatorDynamicComboBoxView.DoGuiToObject;