From: Nando D. <na...@us...> - 2005-07-04 11:40:10
|
Update of /cvsroot/instantobjects/Source/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22878/Core Added Files: InstantConnectionManagerFormUnit.dfm InstantConnectionManagerFormUnit.pas InstantCustomDBEvolverFormUnit.dfm InstantCustomDBEvolverFormUnit.pas InstantDBBuilderFormUnit.dfm InstantDBBuilderFormUnit.pas Removed Files: InstantConnectionManagerForm.dfm InstantConnectionManagerForm.pas InstantDBEvolverForm.dfm InstantDBEvolverForm.pas Log Message: finished TInstantDBBuilder; renamed InstantConnectionManagerForm --- NEW FILE: InstantCustomDBEvolverFormUnit.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 InstantCustomDBEvolverFormUnit; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, DB, InstantPersistence, ComCtrls, InstantDBBuild, InstantDBEvolution, InstantPresentation, ActnList; type TInstantCustomDBEvolverForm = class(TForm) ShowSequenceButton: TButton; SequenceListView: TListView; EvolveButton: TButton; MoveCommandUpButton: TButton; MoveCommandDownButton: TButton; EvolutionLogMemo: TMemo; Label1: TLabel; EnableAllButton: TButton; DisableAllButton: TButton; ActionList: TActionList; ShowSequenceAction: TAction; BuildAction: TAction; MoveCommandUpAction: TAction; MoveCommandDownAction: TAction; EnableAllCommandsAction: TAction; DisableAllCommandsAction: TAction; procedure ShowSequenceButtonClick(Sender: TObject); procedure ShowSequenceActionExecute(Sender: TObject); procedure BuildActionExecute(Sender: TObject); procedure BuildActionUpdate(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 FAfterBuild: TInstantConnectorEvent; procedure SequenceToScreen; procedure ScreenToSequence; procedure Log(const ALogStr: string); function GetConnector: TInstantConnector; procedure SetConnector(const Value: TInstantConnector); function GetTargetModel: TInstantModel; procedure SetTargetModel(const Value: TInstantModel); protected function GetCustomDBEvolver: TInstantCustomDBEvolver; virtual; abstract; function ConfirmDlg(const Text: string): Boolean; procedure CustomDBEvolverBeforeCommandExecute(const Sender: TObject; const ACommand: TInstantDBBuildCommand); virtual; procedure CustomDBEvolverAfterCommandExecute(const Sender: TObject; const ACommand: TInstantDBBuildCommand); virtual; procedure CustomDBEvolverCommandExecuteError(const Sender: TObject; const ACommand: TInstantDBBuildCommand; const Error: Exception; var RaiseError: Boolean); virtual; procedure CustomDBEvolverBeforeCommandSequenceExecute(Sender: TObject); virtual; procedure CustomDBEvolverAfterCommandSequenceExecute(Sender: TObject); virtual; 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; // Fired right after executing the command sequence. property AfterBuild: TInstantConnectorEvent read FAfterBuild write FAfterBuild; end; implementation {$R *.dfm} procedure TInstantCustomDBEvolverForm.ShowSequenceButtonClick(Sender: TObject); begin GetCustomDBEvolver.BuildCommandSequence; SequenceToScreen; end; procedure TInstantCustomDBEvolverForm.SequenceToScreen; var i: Integer; begin SequenceListView.Clear; for i := 0 to GetCustomDBEvolver.CommandSequence.Count - 1 do begin with SequenceListView.Items.Add do begin Caption := GetCustomDBEvolver.CommandSequence[i].Description; Checked := GetCustomDBEvolver.CommandSequence[i].Enabled; Data := GetCustomDBEvolver.CommandSequence[i]; end; end; end; procedure TInstantCustomDBEvolverForm.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 TInstantCustomDBEvolverForm.Log(const ALogStr: string); begin EvolutionLogMemo.Lines.Add(ALogStr); end; procedure TInstantCustomDBEvolverForm.CustomDBEvolverBeforeCommandExecute( const Sender: TObject; const ACommand: TInstantDBBuildCommand); begin if ACommand.Enabled then Log('Executing: ' + ACommand.Description) else Log('Skipping: ' + ACommand.Description); end; procedure TInstantCustomDBEvolverForm.CustomDBEvolverAfterCommandExecute( const Sender: TObject; const ACommand: TInstantDBBuildCommand); begin end; procedure TInstantCustomDBEvolverForm.CustomDBEvolverCommandExecuteError( const Sender: TObject; const ACommand: TInstantDBBuildCommand; const Error: Exception; var RaiseError: Boolean); begin Log('Error: ' + Error.Message); end; procedure TInstantCustomDBEvolverForm.CustomDBEvolverBeforeCommandSequenceExecute( Sender: TObject); begin end; procedure TInstantCustomDBEvolverForm.CustomDBEvolverAfterCommandSequenceExecute( Sender: TObject); begin Connector.Connect; try if Assigned(FAfterBuild) then FAfterBuild(Self, Connector); finally Connector.Disconnect; end; end; procedure TInstantCustomDBEvolverForm.Execute; begin ShowModal; end; function TInstantCustomDBEvolverForm.GetConnector: TInstantConnector; begin Result := GetCustomDBEvolver.Connector; end; procedure TInstantCustomDBEvolverForm.SetConnector(const Value: TInstantConnector); begin GetCustomDBEvolver.Connector := Value; end; function TInstantCustomDBEvolverForm.ConfirmDlg(const Text: string): Boolean; begin Result := MessageDlg(Text, mtConfirmation, [mbYes, mbNo], 0) = mrYes; end; procedure TInstantCustomDBEvolverForm.ShowSequenceActionExecute(Sender: TObject); var OldScreenCursor: TCursor; begin OldScreenCursor := Screen.Cursor; Screen.Cursor := crHourglass; try GetCustomDBEvolver.BuildCommandSequence; SequenceToScreen; finally Screen.Cursor := OldScreenCursor; end; end; procedure TInstantCustomDBEvolverForm.BuildActionUpdate(Sender: TObject); begin (Sender as TAction).Enabled := GetCustomDBEvolver.CommandSequence.Count > 0; end; procedure TInstantCustomDBEvolverForm.BuildActionExecute(Sender: TObject); begin ScreenToSequence; EvolutionLogMemo.Lines.Clear; GetCustomDBEvolver.CommandSequence.Execute; ShowSequenceAction.Execute; end; procedure TInstantCustomDBEvolverForm.MoveCommandUpActionUpdate(Sender: TObject); begin (Sender as TAction).Enabled := Assigned(SequenceListView.Selected) and (SequenceListView.Selected.Index > 0); end; procedure TInstantCustomDBEvolverForm.MoveCommandUpActionExecute(Sender: TObject); begin ScreenToSequence; GetCustomDBEvolver.CommandSequence.MoveItem( TInstantDBBuildCommand(SequenceListView.Selected.Data), -1); SequenceToScreen; end; procedure TInstantCustomDBEvolverForm.MoveCommandDownActionUpdate(Sender: TObject); begin (Sender as TAction).Enabled := Assigned(SequenceListView.Selected) and (SequenceListView.Selected.Index < Pred(SequenceListView.Items.Count)); end; procedure TInstantCustomDBEvolverForm.MoveCommandDownActionExecute( Sender: TObject); begin ScreenToSequence; GetCustomDBEvolver.CommandSequence.MoveItem( TInstantDBBuildCommand(SequenceListView.Selected.Data), 1); SequenceToScreen; end; procedure TInstantCustomDBEvolverForm.EnableAllCommandsActionUpdate( Sender: TObject); begin (Sender as TAction).Enabled := SequenceListView.Items.Count > 0; end; procedure TInstantCustomDBEvolverForm.EnableAllCommandsActionExecute( Sender: TObject); var i: Integer; begin for i := 0 to Pred(SequenceListView.Items.Count) do SequenceListView.Items[i].Checked := True; ScreenToSequence; end; procedure TInstantCustomDBEvolverForm.DisableAllCommandsActionUpdate( Sender: TObject); begin (Sender as TAction).Enabled := SequenceListView.Items.Count > 0; end; procedure TInstantCustomDBEvolverForm.DisableAllCommandsActionExecute( Sender: TObject); var i: Integer; begin for i := 0 to Pred(SequenceListView.Items.Count) do SequenceListView.Items[i].Checked := False; ScreenToSequence; end; function TInstantCustomDBEvolverForm.GetTargetModel: TInstantModel; begin Result := GetCustomDBEvolver.TargetModel; end; procedure TInstantCustomDBEvolverForm.SetTargetModel(const Value: TInstantModel); begin GetCustomDBEvolver.TargetModel := Value; end; procedure TInstantCustomDBEvolverForm.FormCreate(Sender: TObject); begin Constraints.MinWidth := Width; Constraints.MinHeight := Height; GetCustomDBEvolver.BeforeCommandExecute := CustomDBEvolverBeforeCommandExecute; GetCustomDBEvolver.AfterCommandExecute := CustomDBEvolverAfterCommandExecute; GetCustomDBEvolver.BeforeCommandSequenceExecute := CustomDBEvolverBeforeCommandSequenceExecute; GetCustomDBEvolver.AfterCommandSequenceExecute := CustomDBEvolverAfterCommandSequenceExecute; GetCustomDBEvolver.OnCommandExecuteError := CustomDBEvolverCommandExecuteError; end; end. --- InstantDBEvolverForm.pas DELETED --- --- InstantConnectionManagerForm.dfm DELETED --- --- NEW FILE: InstantCustomDBEvolverFormUnit.dfm --- object InstantCustomDBEvolverForm: TInstantCustomDBEvolverForm Left = 439 Top = 273 Width = 601 Height = 332 Caption = 'InstantCustomDBEvolverForm' 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 = BuildAction 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 ActionList: TActionList Left = 320 Top = 96 object ShowSequenceAction: TAction Caption = 'Show Evolution Sequence' OnExecute = ShowSequenceActionExecute end object BuildAction: TAction Caption = 'Evolve Database' OnExecute = BuildActionExecute OnUpdate = BuildActionUpdate 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 --- NEW FILE: InstantDBBuilderFormUnit.pas --- (* * InstantObjects * Database builder 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 builder 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 InstantDBBuilderFormUnit; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, InstantCustomDBEvolverFormUnit, ActnList, InstantDBBuild, InstantDBEvolution, StdCtrls, ComCtrls; type TInstantDBBuilderForm = class(TInstantCustomDBEvolverForm) DBBuilder: TInstantDBBuilder; procedure DBBuilderBeforeCommandSequenceExecute(Sender: TObject); procedure BuildActionExecute(Sender: TObject); private protected function GetCustomDBEvolver: TInstantCustomDBEvolver; override; public end; implementation {$R *.dfm} { TInstantDBBuilderForm } function TInstantDBBuilderForm.GetCustomDBEvolver: TInstantCustomDBEvolver; begin Result := DBBuilder; end; procedure TInstantDBBuilderForm.DBBuilderBeforeCommandSequenceExecute( Sender: TObject); begin inherited; if not Connector.DatabaseExists then Connector.CreateDatabase; end; procedure TInstantDBBuilderForm.BuildActionExecute(Sender: TObject); begin if ConfirmDlg('Build database?' + sLineBreak + sLineBreak + 'Warning: if the database already exists, all data in it will be lost!' + sLineBreak + 'Use the "Evolve" feature to upgrade the structure of an existing database without loosing any data.') then begin inherited; ShowMessage('Database built without errors.'); end; end; end. --- NEW FILE: InstantConnectionManagerFormUnit.dfm --- object InstantConnectionManagerForm: TInstantConnectionManagerForm Left = 396 Top = 280 Width = 350 Height = 281 BorderIcons = [biSystemMenu] Caption = 'Connection Manager' 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 Position = poScreenCenter OnClose = FormClose OnCreate = FormCreate OnShow = FormShow PixelsPerInch = 96 TextHeight = 13 object ConnectionView: TListView Left = 0 Top = 0 Width = 342 Height = 222 Align = alClient Columns = < item AutoSize = True Caption = 'Connection' end item Caption = 'Type' Width = 80 end> PopupMenu = ConnectionMenu TabOrder = 0 ViewStyle = vsReport OnDblClick = ConnectionViewDblClick end object BottomPanel: TPanel Left = 0 Top = 222 Width = 342 Height = 32 Align = alBottom TabOrder = 1 object BuildButton: TButton Left = 4 Top = 4 Width = 75 Height = 25 Action = BuildAction TabOrder = 0 end object ButtonsPanel: TPanel Left = 180 Top = 1 Width = 161 Height = 30 Align = alRight BevelOuter = bvNone TabOrder = 1 object ConnectButton: TButton Left = 4 Top = 3 Width = 75 Height = 25 Action = ConnectAction Default = True TabOrder = 0 end object CloseButton: TButton Left = 82 Top = 3 Width = 75 Height = 25 Caption = 'Close' ModalResult = 2 TabOrder = 1 end end object EvolveButton: TButton Left = 82 Top = 4 Width = 75 Height = 25 Action = EvolveAction TabOrder = 2 end end object ConnectionImages: TImageList Left = 16 Top = 96 end object ConnectionMenu: TPopupMenu Left = 16 Top = 64 object NewMenu: TMenuItem Caption = '&New' end object EditItem: TMenuItem Action = EditAction end object RenameItem: TMenuItem Action = RenameAction end object DeleteItem: TMenuItem Action = DeleteAction end object N1: TMenuItem Caption = '-' end object BuildItem: TMenuItem Action = BuildAction end object EvolveItem: TMenuItem Action = EvolveAction end object ConnectItem: TMenuItem Action = ConnectAction end object DisconnectItem: TMenuItem Action = DisconnectAction end object N2: TMenuItem Caption = '-' end object Open1: TMenuItem Action = FileOpenAction end end object ActionList: TActionList OnUpdate = ActionListUpdate Left = 16 Top = 32 object EditAction: TAction Caption = '&Edit' Hint = 'Edit' ShortCut = 16453 OnExecute = EditActionExecute end object RenameAction: TAction Caption = '&Rename' Hint = 'Rename' ShortCut = 113 OnExecute = RenameActionExecute end object DeleteAction: TAction Caption = '&Delete' Hint = 'Delete' ShortCut = 16452 OnExecute = DeleteActionExecute end object EvolveAction: TAction Caption = 'E&volve' Hint = 'Evolve' OnExecute = EvolveActionExecute end object BuildAction: TAction Caption = '&Build' Hint = 'Build' OnExecute = BuildActionExecute end object ConnectAction: TAction Caption = '&Connect' Hint = 'Connect' OnExecute = ConnectActionExecute OnUpdate = ConnectActionUpdate end object DisconnectAction: TAction Caption = '&Disconnect' Hint = 'Disconnect' OnExecute = DisconnectActionExecute OnUpdate = DisconnectActionUpdate end object FileOpenAction: TAction Category = 'File' Caption = '&Open...' Hint = 'Open configuration file' ImageIndex = 7 ShortCut = 16463 OnExecute = FileOpenActionExecute end end end --- InstantDBEvolverForm.dfm DELETED --- --- InstantConnectionManagerForm.pas DELETED --- --- NEW FILE: InstantConnectionManagerFormUnit.pas --- (* * InstantObjects * Connection Manager 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: Seleqt InstantObjects * * The Initial Developer of the Original Code is: Seleqt * * Portions created by the Initial Developer are Copyright (C) 2001-2003 * the Initial Developer. All Rights Reserved. * * Contributor(s): Carlo Barazzetta, Nando Dessena * * ***** END LICENSE BLOCK ***** *) unit InstantConnectionManagerFormUnit; {$I InstantDefines.inc} {$IFDEF D7+} {$WARN UNSAFE_TYPE OFF} {$WARN UNSAFE_CAST OFF} {$WARN UNSAFE_CODE OFF} {$ENDIF} interface uses SysUtils, Classes, {$IFDEF MSWINDOWS} Windows, Messages, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, ImgList, Menus, ActnList, ExtCtrls, StdActns, {$ENDIF} {$IFDEF LINUX} QGraphics, QControls, QForms, QDialogs, QActnList, QMenus, QTypes, QImgList, QStdCtrls, QComCtrls, QExtCtrls, {$ENDIF} InstantConnectionManager, InstantClasses, InstantPersistence; type TInstantConnectionManagerForm = class(TForm) ActionList: TActionList; BuildAction: TAction; BuildItem: TMenuItem; ConnectAction: TAction; ConnectItem: TMenuItem; ConnectionImages: TImageList; ConnectionMenu: TPopupMenu; ConnectionView: TListView; DeleteAction: TAction; DeleteItem: TMenuItem; DisconnectAction: TAction; DisconnectItem: TMenuItem; EditAction: TAction; EditItem: TMenuItem; N1: TMenuItem; NewMenu: TMenuItem; RenameAction: TAction; RenameItem: TMenuItem; BottomPanel: TPanel; BuildButton: TButton; ButtonsPanel: TPanel; ConnectButton: TButton; CloseButton: TButton; FileOpenAction: TAction; N2: TMenuItem; Open1: TMenuItem; EvolveAction: TAction; EvolveButton: TButton; EvolveItem: TMenuItem; procedure ActionListUpdate(Action: TBasicAction; var Handled: Boolean); procedure BuildActionExecute(Sender: TObject); procedure ConnectActionExecute(Sender: TObject); procedure ConnectionViewDblClick(Sender: TObject); procedure DeleteActionExecute(Sender: TObject); procedure DisconnectActionExecute(Sender: TObject); procedure EditActionExecute(Sender: TObject); procedure FormShow(Sender: TObject); procedure FormCreate(Sender: TObject); procedure RenameActionExecute(Sender: TObject); {$IFDEF MSWINDOWS} procedure ConnectionViewEditedVCL(Sender: TObject; Item: TListItem; var S: string); {$ENDIF} {$IFDEF LINUX} procedure ConnectionViewEditedCLX(Sender: TObject; Item: TListItem; var S: WideString); {$ENDIF} procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FileOpenActionBeforeExecute(Sender: TObject); procedure FileOpenActionExecute(Sender: TObject); procedure ConnectActionUpdate(Sender: TObject); procedure DisconnectActionUpdate(Sender: TObject); procedure EvolveActionExecute(Sender: TObject); private FModel: TInstantModel; FOnBuild: TInstantConnectionDefEvent; FOnConnect: TInstantConnectionDefEvent; FOnDisconnect: TInstantConnectionDefEvent; FOnEdit: TInstantConnectionDefEvent; FOnIsConnected: TInstantConnectionDefEvent; FOnPrepare: TInstantConnectorEvent; FOnSupportConnector: TInstantConnectorClassEvent; FConnectionManager: TInstantConnectionManager; FOpenDialog: TOpenDialog; FTitle: string; function ConfirmDlg(const Text: string): Boolean; function GetCurrentConnectionDef: TInstantConnectionDef; function GetVisibleActions: TInstantConnectionManagerActionTypes; procedure SetCurrentConnectionDef(Value: TInstantConnectionDef); procedure SetFileName(const Value: string); procedure SetVisibleActions(Value: TInstantConnectionManagerActionTypes); procedure SetOnSupportConnector(Value: TInstantConnectorClassEvent); procedure UpdateMenu; {$IFDEF LINUX} procedure EditItemCaption(Item : TListItem); {$ENDIF} function GetConnectionDefs: TInstantConnectionDefs; function GetFileName: string; procedure UpdateCaption; procedure NewMenuItemClick(Sender: TObject); procedure SetConnectionManager(const Value: TInstantConnectionManager); function GetOpenDialog: TOpenDialog; protected procedure Build(ConnectionDef: TInstantConnectionDef); procedure Connect(ConnectionDef: TInstantConnectionDef); 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; function DoEdit(ConnectionDef: TInstantConnectionDef): Boolean; virtual; procedure DoPrepare(Connector: TInstantConnector); virtual; function IsConnected(ConnectionDef: TInstantConnectionDef): Boolean; procedure PopulateConnectionDefs; function SupportConnector(ConnectorClass: TInstantConnectorClass): Boolean; 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; property Model: TInstantModel read FModel write FModel; property VisibleActions: TInstantConnectionManagerActionTypes read GetVisibleActions write SetVisibleActions; property OnBuild: TInstantConnectionDefEvent read FOnBuild write FOnBuild; property OnConnect: TInstantConnectionDefEvent read FOnConnect write FOnConnect; property OnDisconnect: TInstantConnectionDefEvent read FOnDisconnect write FOnDisconnect; property OnEdit: TInstantConnectionDefEvent read FOnEdit write FOnEdit; property OnIsConnected: TInstantConnectionDefEvent read FOnIsConnected write FOnIsConnected; property OnPrepare: TInstantConnectorEvent read FOnPrepare write FOnPrepare; property OnSupportConnector: TInstantConnectorClassEvent read FOnSupportConnector write SetOnSupportConnector; property ConnectionManager: TInstantConnectionManager read FConnectionManager write SetConnectionManager; end; implementation {$R *.dfm} {$R connectionmanagerimages.res} uses InstantImageUtils, InstantConsts, InstantDBEvolverFormUnit, InstantDBBuilderFormUnit; procedure DefaultConnectionManagerExecutor(ConnectionManager: TInstantConnectionManager); var ConnectionManagerForm: TInstantConnectionManagerForm; begin ConnectionManagerForm := TInstantConnectionManagerForm.Create(nil); try ConnectionManagerForm.ConnectionManager := ConnectionManager; ConnectionManagerForm.ShowModal; finally ConnectionManagerForm.Free; end; end; { TInstantConnectionManagerForm } procedure TInstantConnectionManagerForm.ActionListUpdate(Action: TBasicAction; var Handled: Boolean); procedure EnableAction(Action: TAction; Enable: Boolean); begin Action.Enabled := Action.Visible and Enable; end; var HasItem, Connected: Boolean; ConnectionDef: TInstantConnectionDef; begin ConnectionDef := CurrentConnectionDef; HasItem := Assigned(ConnectionDef); Connected := IsManagerConnected; EnableAction(EditAction, HasItem and not Connected); EnableAction(RenameAction, HasItem); 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); EnableAction(FileOpenAction, atOpen in VisibleActions); if Connected then ConnectButton.Action := DisconnectAction else ConnectButton.Action := ConnectAction; ConnectButton.Default := not ConnectionView.IsEditing; CloseButton.Cancel := not ConnectionView.IsEditing; end; procedure TInstantConnectionManagerForm.Build( ConnectionDef: TInstantConnectionDef); begin try if DoBuild(ConnectionDef) then ConnectionDef.IsBuilt := True; except ConnectionDef.IsBuilt := False; raise; end; PopulateConnectionDefs; end; procedure TInstantConnectionManagerForm.Evolve( ConnectionDef: TInstantConnectionDef); begin DoEvolve(ConnectionDef); PopulateConnectionDefs; end; procedure TInstantConnectionManagerForm.BuildActionExecute(Sender: TObject); begin Build(CurrentConnectionDef); 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; end; procedure TInstantConnectionManagerForm.Connect(ConnectionDef: TInstantConnectionDef); begin if Assigned(ConnectionDef) then try if DoConnect(ConnectionDef) then begin ConnectionDef.IsBuilt := True; ModalResult := mrOk; end; finally PopulateConnectionDefs; end; end; procedure TInstantConnectionManagerForm.ConnectActionExecute(Sender: TObject); begin Connect(CurrentConnectionDef); end; procedure TInstantConnectionManagerForm.ConnectionViewDblClick(Sender: TObject); begin ConnectAction.Execute; end; {$IFDEF MSWINDOWS} procedure TInstantConnectionManagerForm.ConnectionViewEditedVCL(Sender: TObject; Item: TListItem; var S: String); var Def: TInstantConnectionDef; begin Def := Item.Data; Def.Name := S; end; {$ENDIF} {$IFDEF LINUX} procedure TInstantConnectionManagerForm.ConnectionViewEditedCLX(Sender: TObject; Item: TListItem; var S: WideString); var Def: TInstantConnectionDef; begin Def := Item.Data; Def.Name := S; end; procedure TInstantConnectionManagerForm.EditItemCaption(Item : TListItem); begin Item.Caption := InputBox('Connection Name','Name:',Item.Caption); end; {$ENDIF} procedure TInstantConnectionManagerForm.DeleteActionExecute( Sender: TObject); var ConnectionDef: TInstantConnectionDef; begin ConnectionDef := CurrentConnectionDef; if Assigned(ConnectionDef) and ConfirmDlg(Format('Delete connection "%s"?', [ConnectionDef.Name])) then begin ConnectionDefs.Remove(ConnectionDef); PopulateConnectionDefs; end; end; procedure TInstantConnectionManagerForm.Disconnect(ConnectionDef: TInstantConnectionDef); begin if Assigned(ConnectionDef) then try DoDisconnect(ConnectionDef); finally PopulateConnectionDefs; end; end; procedure TInstantConnectionManagerForm.DisconnectActionExecute(Sender: TObject); begin Disconnect(CurrentConnectionDef); end; function TInstantConnectionManagerForm.DoBuild( ConnectionDef: TInstantConnectionDef): Boolean; var Connector: TInstantConnector; DBBuilderForm: TInstantDBBuilderForm; begin if Assigned(FOnBuild) then begin Result := False; FOnBuild(Self, ConnectionDef, Result); Exit; end; if not Assigned(ConnectionDef) then begin Result := False; Exit; end; Connector := ConnectionDef.CreateConnector(nil); try DBBuilderForm := TInstantDBBuilderForm.Create(nil); try DBBuilderForm.Connector := Connector; DBBuilderForm.TargetModel := Model; DBBuilderForm.Execute; Result := True; finally DBBuilderForm.Free; end; finally Connector.Free; end; 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; begin Result := False; if Assigned(FOnConnect) then FOnConnect(Self, ConnectionDef, Result); end; function TInstantConnectionManagerForm.DoDisconnect( ConnectionDef: TInstantConnectionDef): Boolean; begin Result := False; if Assigned(FOnDisconnect) then FOnDisconnect(Self, ConnectionDef, Result); end; function TInstantConnectionManagerForm.DoEdit( ConnectionDef: TInstantConnectionDef): Boolean; begin if Assigned(FOnEdit) then begin Result := False; FOnEdit(Self, ConnectionDef, Result); end else Result := ConnectionDef.Edit; end; procedure TInstantConnectionManagerForm.DoPrepare(Connector: TInstantConnector); begin if Assigned(FOnPrepare) then FOnPrepare(Self, Connector); end; function TInstantConnectionManagerForm.Edit( ConnectionDef: TInstantConnectionDef): Boolean; begin Result := DoEdit(ConnectionDef); if Result then PopulateConnectionDefs; end; procedure TInstantConnectionManagerForm.EditActionExecute( Sender: TObject); begin Edit(CurrentConnectionDef); end; procedure TInstantConnectionManagerForm.FormCreate(Sender: TObject); begin LoadMultipleImages(ConnectionImages, 'IO_CONNECTIONMANAGERIMAGES', HInstance); {$IFDEF MSWINDOWS} BorderStyle := bsSizeable; ConnectionView.OnEdited := ConnectionViewEditedVCL; ConnectionView.HideSelection := False; ConnectionView.SortType := stText; ConnectionView.SmallImages := ConnectionImages; {$ENDIF} {$IFDEF LINUX} BorderStyle := fbsSizeable; ConnectionView.OnEdited := ConnectionViewEditedCLX; ConnectionView.ColumnMove := False; ConnectionView.Images := ConnectionImages; {$ENDIF} ConnectionView.Columns[0].Width := 225; ConnectionView.Columns[1].Width := 80; UpdateMenu; end; procedure TInstantConnectionManagerForm.FormShow(Sender: TObject); begin with ConnectionView do if (Items.Count > 0) and not Assigned(ItemFocused) then begin Selected := Items[0]; ItemFocused := Selected; end; end; function TInstantConnectionManagerForm.GetConnectionDefs: TInstantConnectionDefs; begin Result := FConnectionManager.ConnectionDefs; end; function TInstantConnectionManagerForm.GetCurrentConnectionDef: TInstantConnectionDef; begin with ConnectionView do if Assigned(Selected) and Assigned(Selected.Data) then Result := Selected.Data else Result := nil; end; function TInstantConnectionManagerForm.GetVisibleActions: TInstantConnectionManagerActionTypes; begin Result := []; if NewMenu.Visible then Include(Result, atNew); if EditAction.Visible then Include(Result, atEdit); if RenameAction.Visible then Include(Result, atRename); if DeleteAction.Visible then Include(Result, atDelete); if ConnectAction.Visible then Include(Result, atConnect); if DisconnectAction.Visible then Include(Result, atDisconnect); if BuildAction.Visible then Include(Result, atBuild); if FileOpenAction.Visible then Include(Result, atOpen); end; function TInstantConnectionManagerForm.IsConnected( ConnectionDef: TInstantConnectionDef): Boolean; begin Result := False; if Assigned(FOnIsConnected) then FOnIsConnected(Self, ConnectionDef, Result) else if Assigned(ConnectionManager.OnIsConnected) then ConnectionManager.OnIsConnected(ConnectionManager,ConnectionDef,Result); end; procedure TInstantConnectionManagerForm.NewMenuItemClick(Sender: TObject); var ConnectorClass: TInstantConnectorClass; ConnectionDef: TInstantConnectionDef; Item: TListItem; begin with Sender as TMenuItem do ConnectorClass := InstantConnectorClasses[Tag]; ConnectionDef := ConnectorClass.ConnectionDefClass.Create(ConnectionDefs); try ConnectionDef.Name := 'New Connection'; PopulateConnectionDefs; Item := ConnectionView.FindData(0, ConnectionDef, True, True); {$IFDEF MSWINDOWS} if Assigned(Item) then Item.EditCaption; {$ENDIF} {$IFDEF LINUX} EditItemCaption(Item); {$ENDIF} except ConnectionDef.Free; raise; end; end; procedure TInstantConnectionManagerForm.PopulateConnectionDefs; var CurrentDef, Def: TInstantConnectionDef; I: Integer; begin with ConnectionView.Items do begin BeginUpdate; try CurrentDef := CurrentConnectionDef; Clear; for I := 0 to Pred(ConnectionDefs.Count) do begin Def := ConnectionDefs[I]; if SupportConnector(Def.ConnectorClass) then with Add do begin if not Def.IsBuilt then ImageIndex := 0 else if IsConnected(Def) then ImageIndex := 2 else ImageIndex := 1; Caption := Def.Name; Data := Def; SubItems.Add(Def.ConnectionTypeName); SubItems.Add(AInstantStreamFormatStr[Def.BlobStreamFormat]); end; end; if Assigned(CurrentDef) then CurrentConnectionDef := CurrentDef; finally EndUpdate; end; end; end; procedure TInstantConnectionManagerForm.RenameActionExecute( Sender: TObject); begin with ConnectionView do if Assigned(Selected) then {$IFDEF MSWINDOWS} Selected.EditCaption; {$ENDIF} {$IFDEF LINUX} EditItemCaption(Selected); {$ENDIF} end; procedure TInstantConnectionManagerForm.SetCurrentConnectionDef( Value: TInstantConnectionDef); var Item: TListItem; begin Item := ConnectionView.FindData(0, Value, True, True); if Assigned(Item) then begin Item.Focused := True; Item.Selected := True; end; end; procedure TInstantConnectionManagerForm.SetFileName(const Value: string); begin FConnectionManager.FileName := Value; PopulateConnectionDefs; UpdateCaption; end; procedure TInstantConnectionManagerForm.SetOnSupportConnector( Value: TInstantConnectorClassEvent); begin if @Value <> @FOnSupportConnector then begin FOnSupportConnector := Value; UpdateMenu; end; end; procedure TInstantConnectionManagerForm.SetVisibleActions( Value: TInstantConnectionManagerActionTypes); begin NewMenu.Visible := atNew in Value; EditAction.Visible := atEdit in Value; RenameAction.Visible := atRename in Value; DeleteAction.Visible := atDelete in Value; ConnectAction.Visible := atConnect in Value; DisconnectAction.Visible := atDisconnect in Value; BuildAction.Visible := atBuild in Value; FileOpenAction.Visible := atOpen in Value; end; function TInstantConnectionManagerForm.SupportConnector( ConnectorClass: TInstantConnectorClass): Boolean; begin Result := True; if Assigned(FOnSupportConnector) then FOnSupportConnector(Self, ConnectorClass, Result); end; procedure TInstantConnectionManagerForm.UpdateMenu; var I: Integer; ConnectorClass: TInstantConnectorClass; ConnectorClassList: TStringList; Item: TMenuItem; begin ConnectorClassList := TStringList.Create; try for I := 0 to Pred(InstantConnectorClasses.Count) do begin ConnectorClass := InstantConnectorClasses[I]; if SupportConnector(ConnectorClass) then ConnectorClassList.AddObject( ConnectorClass.ConnectionDefClass.ConnectionTypeName + ' Connection', Pointer(I)); end; ConnectorClassList.Sort; NewMenu.Clear; for I := 0 to Pred(ConnectorClassList.Count) do begin Item := TMenuItem.Create(NewMenu); Item.Caption := ConnectorClassList[I]; Item.Tag := Integer(ConnectorClassList.Objects[I]); Item.OnClick := NewMenuItemClick; NewMenu.Add(Item); end; finally ConnectorClassList.Free; end; end; function TInstantConnectionManagerForm.GetFileName: string; begin Result := FConnectionManager.FileName; end; procedure TInstantConnectionManagerForm.UpdateCaption; begin if FileName <> '' then Caption := FTitle + ' - '+ ExtractFileName(FileName) else Caption := FTitle; end; procedure TInstantConnectionManagerForm.FormClose(Sender: TObject; var Action: TCloseAction); begin FConnectionManager.SaveConnectionDefs; end; procedure TInstantConnectionManagerForm.FileOpenActionBeforeExecute( Sender: TObject); begin FileOpenDialog.FileName := FileName; end; procedure TInstantConnectionManagerForm.SetConnectionManager( const Value: TInstantConnectionManager); begin if FConnectionManager <> Value then begin if Value.Caption <> '' then FTitle := Value.Caption else FTitle := Caption; FConnectionManager := Value; Model := Value.Model; OnSupportConnector := Value.OnSupportConnector; VisibleActions := Value.VisibleActions; OnBuild := Value.OnBuild; OnConnect := Value.OnConnect; OnDisconnect := Value.OnDisconnect; OnEdit := Value.OnEdit; OnIsConnected := Value.OnIsConnected; OnPrepare := Value.OnPrepare; FileName := Value.FileName; UpdateCaption; end; end; function TInstantConnectionManagerForm.GetOpenDialog: TOpenDialog; begin if not Assigned(FOpenDialog) then begin FOpenDialog := TOpenDialog.Create(self); FOpenDialog.Filter := SConnectionDefFilter; end; Result := FOpenDialog; end; procedure TInstantConnectionManagerForm.FileOpenActionExecute( Sender: TObject); begin FileOpenDialog.InitialDir := ExtractFilePath(FileName); if FileOpenDialog.Execute then FileName := FileOpenDialog.FileName; end; function TInstantConnectionManagerForm.IsManagerConnected: Boolean; begin Result := ConnectionManager.IsConnected; end; procedure TInstantConnectionManagerForm.ConnectActionUpdate( Sender: TObject); begin ConnectAction.Enabled := Assigned(CurrentConnectionDef) and not IsManagerConnected; end; procedure TInstantConnectionManagerForm.DisconnectActionUpdate(Sender: TObject); begin DisconnectAction.Enabled := IsManagerConnected; end; initialization RegisterConnectionManagerExecutor(DefaultConnectionManagerExecutor); finalization RegisterConnectionManagerExecutor(nil); end. --- NEW FILE: InstantDBBuilderFormUnit.dfm --- inherited InstantDBBuilderForm: TInstantDBBuilderForm Caption = 'Database Builder' OldCreateOrder = True PixelsPerInch = 96 TextHeight = 13 inherited ActionList: TActionList inherited ShowSequenceAction: TAction Caption = 'Show Build Sequence' end inherited BuildAction: TAction Caption = 'Build Database' end end object DBBuilder: TInstantDBBuilder Left = 272 Top = 96 end end |