-
Notifications
You must be signed in to change notification settings - Fork 17
PGControlsKit
TODO
The PGConnectionWindowController
class is a window controller which provides
sheet dialogs which can be used to enter login credentials for Postgresql
servers. It also provides the following facilities:
- Ability to set username, database name, host
- Ability to set the port for the server
- Insist on SSL communication with the remote server
- Ability to enter credentials as a URL
- Status light on the login window which goes green when connection to the remote server has been established, before authentication
- Ability to retrieve an existing password from the keychain
- Ability to enter password and save it in the users' keychain
- Connection to the remote server in the background, allowing your user interface to remain responsive
Here is a screenshot of the connection window:
As the user enters the information, the remote server is "pinged" in the background to see if these parameters would work for login. The status light next to the OK button turns green when the parameters entered are correct, and the button is enabled. When the status light is red, indicating invalid parameters, the button is disabled.
There are other dialog windows which can be displayed. They are for entering URL's instead of parameters, for entering passwords and reporting connection errors. The Cancel button can be pressed in any one of these windows to indicate the connection flow should not continue.
In order to use the class, you need to retain an instantiated object within
your application controller class. For example, your init
method might look
like this:
@implementation AppDelegate
-(id)init {
self = [super init];
if(self) {
_connection = [PGConnectionWindowController new];
[_connection setDelegate:self];
}
return self;
}
@end
The PGConnection
object is exposed through the connection
property. For
example, if the connection is yet to be connected, your login method might
look like this:
-(void)loginWithWindow:(NSWindow* )window {
if([_connection connection] status]==PGConnectionStatusDisconnected) {
// begin sheet to login
[[self connection] beginSheetForParentWindow:window contextInfo:nil];
}
}
Here, window
is the main window of your application, and a sheet will appear
which allows the user to enter their credentials. You need to implement the
delegate method connectionWindow:status:
in order to receive the
status from the login window completion:
-
PGConnectionWindowStatusOK
will be returned when the user presses the OK button, and the parameters that the user has entered are correct. In this case, execution can then continue with a call toconnect
. -
PGConnectionWindowStatusBadParameters
will be returned when the parameters that the user have entered are incorrect and connection cannot continue. -
PGConnectionWindowStatusCancel
will be returned when the user has pressed the Cancel button.
There are other states which are returned after a call to the connect
method:
-
PGConnectionWindowStatusNeedsPassword
will be returned when the login cannot continue until a password is entered. In this case, you should call the methodbeginPasswordSheetForParentWindow:
which will display a password on-screen. -
PGConnectionWindowStatusConnectionError
will be returned if the connection is rejected. -
PGConnectionWindowStatusCancel
will be returned if the user clicks on the Cancel button. -
PGConnectionWindowStatusConnected
will be returned if the connection is established. At this point your application can continue with processing.
If you want to disconnect from the remote server, you can call the disconnect
method. Here is an example of how you might want to implement the
connectionWindow:status
method:
TODO
The PGSplitViewController
is a vertical split view class with a status bar at the bottom
of the view. You can independently set the left-hand custom view and the
right-hand custom view.
TODO
The class is an NSViewController class, so to embed it in your own view you can implement the following code:
@implementation AppDelegate (SplitView)
-(void)addSplitViewWithLeftView:(id)leftView rightView:(id)rightView {
NSView* contentView = [[self window] contentView];
PGSplitViewController* splitView = [PGSplitViewController new];
// set up content view and constraints
[contentView addSubview:splitView];
[splitView setTranslatesAutoresizingMaskIntoConstraints:NO];
NSDictionary *views = NSDictionaryOfVariableBindings(splitView);
[contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[splitView]|" options:0 metrics:nil views:views]];
[contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[splitView]|" options:0 metrics:nil views:views]];
// add left and right views
[[self splitView] setLeftView:leftView];
[[self splitView] setRightView:rightView];
}
@end
The PGSourceViewController
is an implementation of NSOutlineView
which is
focussed on implementing a structure suitable as source view suitable for data
structures which can contain Postgresql connection and query information.
TODO
The PGConsoleViewController
is an implementation of a green-screen style
console, which allows for output, command-line input, storing history, copy,
paste and editing.
TODO
TODO
TODO
TODO