Update of /cvsroot/instantobjects/Source/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7153/Core Modified Files: InstantConnectionManagerForm.dfm InstantConnectionManagerForm.pas InstantDBBuild.pas Added Files: InstantDBEvolverForm.dfm InstantDBEvolverForm.pas Log Message: Design time support for database evolution Index: InstantConnectionManagerForm.pas =================================================================== RCS file: /cvsroot/instantobjects/Source/Core/InstantConnectionManagerForm.pas,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** InstantConnectionManagerForm.pas 25 Feb 2005 17:17:45 -0000 1.4 --- InstantConnectionManagerForm.pas 28 Jun 2005 10:13:47 -0000 1.5 *************** *** 24,28 **** * the Initial Developer. All Rights Reserved. * ! * Contributor(s): Carlo Barazzetta * * ***** END LICENSE BLOCK ***** *) --- 24,28 ---- * the Initial Developer. All Rights Reserved. * ! * Contributor(s): Carlo Barazzetta, Nando Dessena * * ***** END LICENSE BLOCK ***** *) *************** *** 80,83 **** --- 80,86 ---- N2: TMenuItem; Open1: TMenuItem; + EvolveAction: TAction; + EvolveButton: TButton; + EvolveItem: TMenuItem; procedure ActionListUpdate(Action: TBasicAction; var Handled: Boolean); procedure BuildActionExecute(Sender: TObject); *************** *** 103,106 **** --- 106,110 ---- procedure ConnectActionUpdate(Sender: TObject); procedure DisconnectActionUpdate(Sender: TObject); + procedure EvolveActionExecute(Sender: TObject); private FModel: TInstantModel; *************** *** 137,140 **** --- 141,145 ---- procedure Disconnect(ConnectionDef: TInstantConnectionDef); function Edit(ConnectionDef: TInstantConnectionDef): Boolean; + procedure Evolve(ConnectionDef: TInstantConnectionDef); function DoConnect(ConnectionDef: TInstantConnectionDef): Boolean; virtual; function DoDisconnect(ConnectionDef: TInstantConnectionDef): Boolean; virtual; *************** *** 146,152 **** property ConnectionDefs: TInstantConnectionDefs read GetConnectionDefs; property FileOpenDialog: TOpenDialog read GetOpenDialog; public function IsManagerConnected: Boolean; - function DoBuild(ConnectionDef: TInstantConnectionDef): Boolean; virtual; property CurrentConnectionDef: TInstantConnectionDef read GetCurrentConnectionDef write SetCurrentConnectionDef; property FileName: string read GetFileName write SetFileName; --- 151,158 ---- property ConnectionDefs: TInstantConnectionDefs read GetConnectionDefs; property FileOpenDialog: TOpenDialog read GetOpenDialog; + function DoBuild(ConnectionDef: TInstantConnectionDef): Boolean; virtual; + function DoEvolve(ConnectionDef: TInstantConnectionDef): Boolean; virtual; public function IsManagerConnected: Boolean; property CurrentConnectionDef: TInstantConnectionDef read GetCurrentConnectionDef write SetCurrentConnectionDef; property FileName: string read GetFileName write SetFileName; *************** *** 160,164 **** property OnPrepare: TInstantConnectorEvent read FOnPrepare write FOnPrepare; property OnSupportConnector: TInstantConnectorClassEvent read FOnSupportConnector write SetOnSupportConnector; ! property ConnectionManager : TInstantConnectionManager read FConnectionManager write SetConnectionManager; end; --- 166,170 ---- property OnPrepare: TInstantConnectorEvent read FOnPrepare write FOnPrepare; property OnSupportConnector: TInstantConnectorClassEvent read FOnSupportConnector write SetOnSupportConnector; ! property ConnectionManager: TInstantConnectionManager read FConnectionManager write SetConnectionManager; end; *************** *** 169,185 **** uses ! InstantImageUtils, InstantConsts; ! procedure DefaultConnectionManagerExecutor(ConnectionManager : TInstantConnectionManager); var ! ConnManagerForm : TInstantConnectionManagerForm; begin ! ConnManagerForm := TInstantConnectionManagerForm.Create(nil); ! Try ! ConnManagerForm.ConnectionManager := ConnectionManager; ! ConnManagerForm.ShowModal; ! Finally ! ConnManagerForm.Free; ! End; end; --- 175,191 ---- uses ! InstantImageUtils, InstantConsts, InstantDBEvolverForm; ! procedure DefaultConnectionManagerExecutor(ConnectionManager: TInstantConnectionManager); var ! ConnectionManagerForm: TInstantConnectionManagerForm; begin ! ConnectionManagerForm := TInstantConnectionManagerForm.Create(nil); ! try ! ConnectionManagerForm.ConnectionManager := ConnectionManager; ! ConnectionManagerForm.ShowModal; ! finally ! ConnectionManagerForm.Free; ! end; end; *************** *** 205,208 **** --- 211,215 ---- EnableAction(DeleteAction, HasItem and not Connected); EnableAction(BuildAction, HasItem and not Connected); + EnableAction(EvolveAction, HasItem and not Connected); EnableAction(ConnectAction, HasItem and not Connected); EnableAction(DisconnectAction, HasItem and Connected); *************** *** 215,219 **** end; ! procedure TInstantConnectionManagerForm.Build(ConnectionDef: TInstantConnectionDef); begin try --- 222,227 ---- end; ! procedure TInstantConnectionManagerForm.Build( ! ConnectionDef: TInstantConnectionDef); begin try *************** *** 227,230 **** --- 235,245 ---- end; + procedure TInstantConnectionManagerForm.Evolve( + ConnectionDef: TInstantConnectionDef); + begin + DoEvolve(ConnectionDef); + PopulateConnectionDefs; + end; + procedure TInstantConnectionManagerForm.BuildActionExecute(Sender: TObject); begin *************** *** 232,237 **** end; ! function TInstantConnectionManagerForm.ConfirmDlg( ! const Text: string): Boolean; begin Result := MessageDlg(Text, mtConfirmation, [mbYes, mbNo], 0) = mrYes; --- 247,256 ---- end; ! procedure TInstantConnectionManagerForm.EvolveActionExecute(Sender: TObject); ! begin ! Evolve(CurrentConnectionDef); ! end; ! ! function TInstantConnectionManagerForm.ConfirmDlg(const Text: string): Boolean; begin Result := MessageDlg(Text, mtConfirmation, [mbYes, mbNo], 0) = mrYes; *************** *** 345,353 **** Connector.BuildDatabase(Model); Connector.Connect; ! Try DoPrepare(Connector); ! Finally Connector.Disconnect; ! End; finally Screen.Cursor := SaveCursor; --- 364,372 ---- Connector.BuildDatabase(Model); Connector.Connect; ! try DoPrepare(Connector); ! finally Connector.Disconnect; ! end; finally Screen.Cursor := SaveCursor; *************** *** 360,363 **** --- 379,410 ---- end; + + function TInstantConnectionManagerForm.DoEvolve( + ConnectionDef: TInstantConnectionDef): Boolean; + var + Connector: TInstantConnector; + DBEvolverForm: TInstantDBEvolverForm; + begin + if not Assigned(ConnectionDef) then + begin + Result := False; + Exit; + end; + Connector := ConnectionDef.CreateConnector(nil); + try + DBEvolverForm := TInstantDBEvolverForm.Create(nil); + try + DBEvolverForm.Connector := Connector; + DBEvolverForm.TargetModel := Model; + DBEvolverForm.Execute; + Result := True; + finally + DBEvolverForm.Free; + end; + finally + Connector.Free; + end; + end; + function TInstantConnectionManagerForm.DoConnect( ConnectionDef: TInstantConnectionDef): Boolean; *************** *** 668,672 **** FTitle := Value.Caption else ! FTitle := self.Caption; FConnectionManager := Value; Model := Value.Model; --- 715,719 ---- FTitle := Value.Caption else ! FTitle := Caption; FConnectionManager := Value; Model := Value.Model; *************** *** 713,718 **** end; ! procedure TInstantConnectionManagerForm.DisconnectActionUpdate( ! Sender: TObject); begin DisconnectAction.Enabled := IsManagerConnected; --- 760,764 ---- end; ! procedure TInstantConnectionManagerForm.DisconnectActionUpdate(Sender: TObject); begin DisconnectAction.Enabled := IsManagerConnected; Index: InstantConnectionManagerForm.dfm =================================================================== RCS file: /cvsroot/instantobjects/Source/Core/InstantConnectionManagerForm.dfm,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** InstantConnectionManagerForm.dfm 25 Feb 2005 17:17:45 -0000 1.2 --- InstantConnectionManagerForm.dfm 28 Jun 2005 10:13:47 -0000 1.3 *************** *** 1,5 **** object InstantConnectionManagerForm: TInstantConnectionManagerForm ! Left = 327 ! Top = 305 Width = 350 Height = 281 --- 1,5 ---- object InstantConnectionManagerForm: TInstantConnectionManagerForm ! Left = 396 ! Top = 280 Width = 350 Height = 281 *************** *** 34,38 **** Top = 0 Width = 342 ! Height = 215 Align = alClient Columns = < --- 34,38 ---- Top = 0 Width = 342 ! Height = 222 Align = alClient Columns = < *************** *** 52,56 **** object BottomPanel: TPanel Left = 0 ! Top = 215 Width = 342 Height = 32 --- 52,56 ---- object BottomPanel: TPanel Left = 0 ! Top = 222 Width = 342 Height = 32 *************** *** 92,95 **** --- 92,103 ---- end end + object EvolveButton: TButton + Left = 82 + Top = 4 + Width = 75 + Height = 25 + Action = EvolveAction + TabOrder = 2 + end end object ConnectionImages: TImageList *************** *** 118,121 **** --- 126,132 ---- Action = BuildAction end + object EvolveItem: TMenuItem + Action = EvolveAction + end object ConnectItem: TMenuItem Action = ConnectAction *************** *** 153,156 **** --- 164,172 ---- OnExecute = DeleteActionExecute end + object EvolveAction: TAction + Caption = 'E&volve' + Hint = 'Evolve' + OnExecute = EvolveActionExecute + end object BuildAction: TAction Caption = '&Build' Index: InstantDBBuild.pas =================================================================== RCS file: /cvsroot/instantobjects/Source/Core/InstantDBBuild.pas,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** InstantDBBuild.pas 18 Jun 2005 09:47:24 -0000 1.1 --- InstantDBBuild.pas 28 Jun 2005 10:13:47 -0000 1.2 *************** *** 27,30 **** --- 27,31 ---- * * ***** END LICENSE BLOCK ***** *) + unit InstantDBBuild; *************** *** 395,398 **** --- 396,400 ---- if Assigned(FConnector) then FConnector.FreeNotification(Self); + FCommandSequence.Connector := FConnector; end; end; --- NEW FILE: InstantDBEvolverForm.pas --- (* * InstantObjects * Database evolution Form *) (* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is: InstantObjects database evolver form * * The Initial Developer of the Original Code is: Nando Dessena * * Portions created by the Initial Developer are Copyright (C) 2005 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * ***** END LICENSE BLOCK ***** *) unit InstantDBEvolverForm; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, DB, InstantPersistence, ComCtrls, InstantDBBuild, InstantDBEvolution, InstantPresentation, ActnList; type TInstantDBEvolverForm = class(TForm) ShowSequenceButton: TButton; SequenceListView: TListView; EvolveButton: TButton; MoveCommandUpButton: TButton; MoveCommandDownButton: TButton; EvolutionLogMemo: TMemo; Label1: TLabel; DBEvolver: TInstantDBEvolver; EnableAllButton: TButton; DisableAllButton: TButton; ActionList: TActionList; ShowSequenceAction: TAction; EvolveAction: TAction; MoveCommandUpAction: TAction; MoveCommandDownAction: TAction; EnableAllCommandsAction: TAction; DisableAllCommandsAction: TAction; procedure ShowSequenceButtonClick(Sender: TObject); procedure DBEvolverBeforeCommandExecute(const Sender: TObject; const ACommand: TInstantDBBuildCommand); procedure DBEvolverCommandExecuteError(const Sender: TObject; const ACommand: TInstantDBBuildCommand; const Error: Exception; var RaiseError: Boolean); procedure ShowSequenceActionExecute(Sender: TObject); procedure EvolveActionExecute(Sender: TObject); procedure EvolveActionUpdate(Sender: TObject); procedure MoveCommandUpActionExecute(Sender: TObject); procedure MoveCommandDownActionExecute(Sender: TObject); procedure EnableAllCommandsActionExecute(Sender: TObject); procedure DisableAllCommandsActionExecute(Sender: TObject); procedure MoveCommandUpActionUpdate(Sender: TObject); procedure MoveCommandDownActionUpdate(Sender: TObject); procedure EnableAllCommandsActionUpdate(Sender: TObject); procedure DisableAllCommandsActionUpdate(Sender: TObject); procedure FormCreate(Sender: TObject); private procedure SequenceToScreen; procedure ScreenToSequence; procedure Log(const ALogStr: string); function GetConnector: TInstantConnector; procedure SetConnector(const Value: TInstantConnector); function ConfirmDlg(const Text: string): Boolean; function GetTargetModel: TInstantModel; procedure SetTargetModel(const Value: TInstantModel); public // Assign a connector before calling the Execute method, otherwise the // default connector is used. property Connector: TInstantConnector read GetConnector write SetConnector; // Assign a target model before calling the Execute method, otherwise the // default model is used. property TargetModel: TInstantModel read GetTargetModel write SetTargetModel; // Shows the form modally. procedure Execute; end; implementation {$R *.dfm} procedure TInstantDBEvolverForm.ShowSequenceButtonClick(Sender: TObject); begin DBEvolver.BuildCommandSequence; SequenceToScreen; end; procedure TInstantDBEvolverForm.SequenceToScreen; var i: Integer; begin SequenceListView.Clear; for i := 0 to DBEvolver.CommandSequence.Count - 1 do begin with SequenceListView.Items.Add do begin Caption := DBEvolver.CommandSequence[i].Description; Checked := DBEvolver.CommandSequence[i].Enabled; Data := DBEvolver.CommandSequence[i]; end; end; end; procedure TInstantDBEvolverForm.ScreenToSequence; var i: Integer; begin for i := 0 to SequenceListView.Items.Count - 1 do TInstantDBBuildCommand(SequenceListView.Items[i].Data).Enabled := SequenceListView.Items[i].Checked; end; procedure TInstantDBEvolverForm.Log(const ALogStr: string); begin EvolutionLogMemo.Lines.Add(ALogStr); end; procedure TInstantDBEvolverForm.DBEvolverBeforeCommandExecute( const Sender: TObject; const ACommand: TInstantDBBuildCommand); begin if ACommand.Enabled then Log('Executing: ' + ACommand.Description) else Log('Skipping: ' + ACommand.Description); end; procedure TInstantDBEvolverForm.DBEvolverCommandExecuteError( const Sender: TObject; const ACommand: TInstantDBBuildCommand; const Error: Exception; var RaiseError: Boolean); begin Log('Error: ' + Error.Message); end; procedure TInstantDBEvolverForm.Execute; begin ShowModal; end; function TInstantDBEvolverForm.GetConnector: TInstantConnector; begin Result := DBEvolver.Connector; end; procedure TInstantDBEvolverForm.SetConnector(const Value: TInstantConnector); begin DBEvolver.Connector := Value; end; function TInstantDBEvolverForm.ConfirmDlg(const Text: string): Boolean; begin Result := MessageDlg(Text, mtConfirmation, [mbYes, mbNo], 0) = mrYes; end; procedure TInstantDBEvolverForm.ShowSequenceActionExecute(Sender: TObject); var OldScreenCursor: TCursor; begin OldScreenCursor := Screen.Cursor; Screen.Cursor := crHourglass; try DBEvolver.BuildCommandSequence; SequenceToScreen; finally Screen.Cursor := OldScreenCursor; end; end; procedure TInstantDBEvolverForm.EvolveActionUpdate(Sender: TObject); begin (Sender as TAction).Enabled := DBEvolver.CommandSequence.Count > 0; end; procedure TInstantDBEvolverForm.EvolveActionExecute(Sender: TObject); begin if ConfirmDlg('Evolve database?') then begin ScreenToSequence; EvolutionLogMemo.Lines.Clear; DBEvolver.CommandSequence.Execute; ShowMessage('Database evolved without errors.'); ShowSequenceAction.Execute; end; end; procedure TInstantDBEvolverForm.MoveCommandUpActionUpdate(Sender: TObject); begin (Sender as TAction).Enabled := Assigned(SequenceListView.Selected) and (SequenceListView.Selected.Index > 0); end; procedure TInstantDBEvolverForm.MoveCommandUpActionExecute(Sender: TObject); begin ScreenToSequence; DBEvolver.CommandSequence.MoveItem( TInstantDBBuildCommand(SequenceListView.Selected.Data), -1); SequenceToScreen; end; procedure TInstantDBEvolverForm.MoveCommandDownActionUpdate(Sender: TObject); begin (Sender as TAction).Enabled := Assigned(SequenceListView.Selected) and (SequenceListView.Selected.Index < Pred(SequenceListView.Items.Count)); end; procedure TInstantDBEvolverForm.MoveCommandDownActionExecute( Sender: TObject); begin ScreenToSequence; DBEvolver.CommandSequence.MoveItem( TInstantDBBuildCommand(SequenceListView.Selected.Data), 1); SequenceToScreen; end; procedure TInstantDBEvolverForm.EnableAllCommandsActionUpdate( Sender: TObject); begin (Sender as TAction).Enabled := SequenceListView.Items.Count > 0; end; procedure TInstantDBEvolverForm.EnableAllCommandsActionExecute( Sender: TObject); var i: Integer; begin for i := 0 to Pred(SequenceListView.Items.Count) do SequenceListView.Items[i].Checked := True; ScreenToSequence; end; procedure TInstantDBEvolverForm.DisableAllCommandsActionUpdate( Sender: TObject); begin (Sender as TAction).Enabled := SequenceListView.Items.Count > 0; end; procedure TInstantDBEvolverForm.DisableAllCommandsActionExecute( Sender: TObject); var i: Integer; begin for i := 0 to Pred(SequenceListView.Items.Count) do SequenceListView.Items[i].Checked := False; ScreenToSequence; end; function TInstantDBEvolverForm.GetTargetModel: TInstantModel; begin Result := DBEvolver.TargetModel; end; procedure TInstantDBEvolverForm.SetTargetModel(const Value: TInstantModel); begin DBEvolver.TargetModel := Value; end; procedure TInstantDBEvolverForm.FormCreate(Sender: TObject); begin Constraints.MinWidth := Width; Constraints.MinHeight := Height; end; end. --- NEW FILE: InstantDBEvolverForm.dfm --- object InstantDBEvolverForm: TInstantDBEvolverForm Left = 439 Top = 273 Width = 601 Height = 332 Caption = 'Database Evolution' Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] Icon.Data = { 0000010001001010100000000000280100001600000028000000100000002000 00000100040000000000C0000000000000000000000000000000000000000000 000000008000008000000080800080000000800080008080000080808000C0C0 C0000000FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF000000 00000000000000000000070444000000088FF844444000077888F44444440007 888FF444444400077888F44F44440007888FFF44444000077888F8F444000007 888FFF88700000077888F8870000000780000087000000000FFFFF000000000F FFFFFFFF000000000FFFFF00000000000000000000000000000000000000FFFF 0000F8230000E0010000C0000000C0000000C0000000C0010000C0030000C007 0000C0070000C0070000C0070000C0070000E00F0000F83F0000FFFF0000} OldCreateOrder = False ShowHint = True OnCreate = FormCreate DesignSize = ( 593 305) PixelsPerInch = 96 TextHeight = 13 object Label1: TLabel Left = 8 Top = 176 Width = 61 Height = 13 Anchors = [akLeft, akBottom] Caption = 'Evolution log' end object ShowSequenceButton: TButton Left = 8 Top = 8 Width = 145 Height = 25 Action = ShowSequenceAction TabOrder = 0 end object SequenceListView: TListView Left = 8 Top = 40 Width = 441 Height = 129 Anchors = [akLeft, akTop, akRight, akBottom] Checkboxes = True Columns = < item Caption = 'Evolution sequence' Width = 400 end> TabOrder = 1 ViewStyle = vsReport end object EvolveButton: TButton Left = 160 Top = 8 Width = 145 Height = 25 Action = EvolveAction TabOrder = 2 end object MoveCommandUpButton: TButton Left = 456 Top = 40 Width = 129 Height = 25 Action = MoveCommandUpAction Anchors = [akTop, akRight] TabOrder = 3 end object MoveCommandDownButton: TButton Left = 456 Top = 72 Width = 129 Height = 25 Action = MoveCommandDownAction Anchors = [akTop, akRight] TabOrder = 4 end object EvolutionLogMemo: TMemo Left = 8 Top = 192 Width = 577 Height = 105 Anchors = [akLeft, akRight, akBottom] ReadOnly = True ScrollBars = ssBoth TabOrder = 5 WordWrap = False end object EnableAllButton: TButton Left = 456 Top = 112 Width = 129 Height = 25 Action = EnableAllCommandsAction Anchors = [akTop, akRight] TabOrder = 6 end object DisableAllButton: TButton Left = 456 Top = 144 Width = 129 Height = 25 Action = DisableAllCommandsAction Anchors = [akTop, akRight] TabOrder = 7 end object DBEvolver: TInstantDBEvolver BeforeCommandExecute = DBEvolverBeforeCommandExecute OnCommandExecuteError = DBEvolverCommandExecuteError Left = 264 Top = 96 end object ActionList: TActionList Left = 320 Top = 96 object ShowSequenceAction: TAction Caption = 'Show Evolution Sequence' OnExecute = ShowSequenceActionExecute end object EvolveAction: TAction Caption = 'Evolve Database' OnExecute = EvolveActionExecute OnUpdate = EvolveActionUpdate end object MoveCommandUpAction: TAction Caption = 'Move Command Up' OnExecute = MoveCommandUpActionExecute OnUpdate = MoveCommandUpActionUpdate end object MoveCommandDownAction: TAction Caption = 'Move Command Down' OnExecute = MoveCommandDownActionExecute OnUpdate = MoveCommandDownActionUpdate end object EnableAllCommandsAction: TAction Caption = 'Enable All Commands' OnExecute = EnableAllCommandsActionExecute OnUpdate = EnableAllCommandsActionUpdate end object DisableAllCommandsAction: TAction Caption = 'Disable All Commands' OnExecute = DisableAllCommandsActionExecute OnUpdate = DisableAllCommandsActionUpdate end end end |