Persistate

Accessing the user interface

Hide Navigation Pane

Accessing the user interface

Previous topic Next topic No directory for this topic  

Accessing the user interface

Previous topic Next topic Topic directory requires JavaScript JavaScript is required for the print function Mail us feedback on this topic!  

Programmatic access to the User Interface (UI) module is based on the abstract class UserInterface and the interface IPWindow.  This access is entirely independent of the type of user interface - whether it is a classic desktop, browser based, or any other type.  In fact it is often not possible to tell what type of user interface you are connected to.  This is because, when running in Viewer-Server mode, Controller modules in the server access a class derived from UserInterface called ProxyUserInterface  which transports calls to whatever viewer is running the session, and the type of UI in that viewer is not discoverable.

When a session starts, then the UI is initialised with a call to a method called InitialiseUserInterface.InitUserInterface.  This is called by the StartUp module if the application is being run in stand-alone mode, or by whatever viewer is running a session UI.  For now this is only the Persistate Viewer.  Persistate generates a default class and method for you, and you can develop it to show whatever windows, workspaces and layouts you want at application startup.  The generated InitialiseUserInterface class provides a good example of using the user interface API, so here is the one generated for the Library example application.

using System;
using System.Collections.Generic;
using System.Text;
using Persistate;
using Library.Model;
 
namespace Library.Desktop
{
   /// <summary>
   /// This class contains the InitUserInterface method which is called 
   /// from the Main method of the StartUp class, and also by the Persistate
   /// Viewer application when starting a session for the Library package.
   /// </summary>
   public static class InitialiseUserInterface
   {
      /// <summary>
      /// Shows start-up content in the user interface.
      /// </summary>
      /// <param name="ui">The user interface in which to show it.</param>
      /// <param name="title">The title to use for created window(s).</param>
      public static void InitUserInterface(UserInterface ui, string title)
      {
         // By default, login with currently logged in user - change as required
         ExecutionResult result = Operation.Login.Execute(null, null, 
            Credentials.CurrentUserCredentials());
         
         // if login fails, throw exception to terminate session
         if (result.ResultAction != ResultAction.Commit) 
            throw new Exception(result.SimpleMessage);
 
         // Create a single window using the default workspace
         IPWindow window = ui.CreateWindow(null, title);
 
         // Show the menu & toolbar in the top controls pane 
         window.Show(The.Library, The.Library.Class.Layouts[Layout.NameKey, 
            "LibraryControls"], "controls");
 
         // Show the Library tree in the left hand navigation pane.
         window.Show(The.Library, The.Library.Class.Layouts[Layout.NameKey, 
            "LibraryTree"], "navigation");
 
         // Show the status bar in the bottom status bar pane
         window.Show(Persistent.Empty, Layout.StatusStrip, "status bar");
 
         // Make window visible
         ui.ShowWindow(window);
 
         return;
      }
   }
}

Although this class is generated in the Library.Desktop namespace, note that it does not use any classes from the desktop user interface - only the abstract class UserInterface and the interface IPWindow.  The first thing this method does is to programmatically execute the Login operation.  This operation is supplied with a Credentials object which contains details of the current user logged in to the operating system.  These Credentials are marked as pre-authenticated, and if your application uses the standard implementation of Login, then no further authentication is performed, and a Principal object is created for the user if one does not already exist.

The next thing this method does is to create a window using the UserInterface.CreateWIndow method.  This takes a workspace name and window title as parameters.  By default, null is passed as the workspace name, which causes the window to use a default workspace.  This will be any workspace the user may have saved as a start-up workspace (see Customising the workspace ) or else any workspace defined in the package definition file, or if there are none, a default workspace from the Persistate package.  This method creates the window, but does not display it.

Next, the method makes three calls to IPWindow.Show.  There are a few overloads of this method - the one used here has all parameters supplied - namely the object to show, the Layout with which to show it, and the name of the Pane in which to show it.  You can miss out the Layout, and Persistate will use (by preference) one you have marked as default for type.  You can also miss out the Pane name, and Persistate will choose a pane for you based on certain criteria.  See the Splitting Panes section in Customising the workspace for details of these.

Finally, the method calls UserInterface.ShowWindow which displays the window to the user.  These three methods are core to the functioning of the abstract user interface system.  Below are some further often used methods, with examples.  For full details of all members of UserInterface and IPWindow, see the API documentation.

Major UserInterface methods

Here is a list of the facilities present in the UserInterface abstract class.  This is not a complete list - see the API documentation for full details.

CreateWindow(string workspaceName, string title).  See above.
ShowWindow(IPWindow window, string title).  See above.
ShowWindowModal(IPWindow window, string title).  This method takes an IPWindow created by one of the CreateWindow overloads and shows it in a modal dialogue box.
HideWindow(IPWindow window).  This method hides a visible IPWindow, but does not dispose of it.  The window can be shown again using ShowWindow.
CloseWindow(IPWindow window).  This method closes and disposes an IPWindow created with CreateWIndow.
Exit(string exitText).  This method terminates the Session fronted by this UserInterface.
Show(IClassified toShow, Layout layout, string paneName).  This is a convenience method which simply calls the similar IPWindow.Show method of the active IPWindow - i.e. the one with the input focus.  There are overloads where you can miss out the layout, pane name, or both.
ShowModal(IClassified toShow, Layout layout, ContainerProperties properties).  This displays an object or collection using a particular layout in a dialogue box.  The ContainerProperties object contains various options.  There is also an overload without the layout.
ShowModalOkCancel(IClassified toShow, Layout layout, ContainerProperties properties).  This is similar to the above, except that the dialogue box shows an Ok and Cancel button at the bottom of the dialogue.  Again, there is an overload without the layout.
ShowModalButtons(IClassified toShow, Layout layout, ContainerProperties properties, params string[] buttonTexts).  This is similar to ShowModal, except that it displays up to three buttons with arbitrary text at the bottom of the dialogue box.  Once more, there is an overload without the layout.
SetFocusTo(Persistent toFocus, IPersistateList inCollection).  This searches all panes in all visible IPWindows to find one showing the given collection, and sets the input focus to the given object within that collection.  There is an overload without the collection, which searches for the given object showing in a pane on its own.
SetStatus(string message, float percentComplete).  Sets text and a percentage complete value into the status message and progress bar in the status bar of the currently active IPWindow.  There is also a GetStatus method which gets the currently set status message.
Inform(string message, params object[] parameters).  This puts up a popup information message box, with the given message, an information icon and an Ok button.  The parameters are replaced into the message in the same manner as string.Format().  There are some similar methods. Warn shows a warning icon, UserConfirms shows a question icon and Yes and No buttons, AskRetry shows a warning icon and Retry and Cancel buttons.
AskString(string prompt).  This puts up a small dialogue box containing a prompt message and a text box, allowing the user to enter some text.
ChooseOne(string message, ICollection collection).  This method puts up a dialogue box containing a prompt message, and a list box showing the objects in the given collection.  The user can select a single object from the collection.  There is a similar method ChooseSeveral, which allows the user to select more than one object from the list.
SelectObjects(string message, ObjectClass requiredClass, IClassified selectionRoot, bool diverseSelection, bool multipleSelection).  This is a general purpose method which puts up a dialogue box allowing the user to select one or more objects from the persistent tree.  This dialogue is described in Using the object selection dialogue.
GetFile(string prompt, string fileFilter).   This method allows the user to supply the contents of any file on his or her local file system.  There is a similar method called GetTextFile which works for text files only and has an extra System.Text.Encoding parameter.

Major IPWindow methods

Here is a list of the facilities present in the IPWindow interface.  This is not a complete list - see the API documentation for full details.

Show(IClassified toShow, Layout layout, string paneName).  See above.
AddTab(string parentPaneName, string newPaneName).  Adds a new tabbed pane to a parent pane that is either empty of already contains tabbed panes.  There is an overload without the new pane name where Persistate assigns a name to the new pane.
SplitPane(string originalPaneName, string replacementPaneName, string emptyPaneName, PaneType emptyPaneType).  This method splits an existing pane into two, arranged vertically or horizontally.  The contents of the original pane is displayed in one of the new panes, and the other is empty.  There is an overload which does not include the replacement or empty pane names, the names in this case being assigned by Persistate.
SetFocus(Persistent toFocus, IPersistateList list).  This searches all panes in the IPWindow to find one showing the given collection, and sets the input focus to the given object within that collection.  There is an overload without the collection, which searches for the given object showing in a pane on its own.  Another overload takes a single pane name parameter and focuses that pane.
Workspace { get; set; }.  Getting the Workspace simply gets the object.  Setting the workspace completely remodels the IPWindow to show the panes and any associated content contained in the new Workspace object set.