Class Application

java.lang.Object
xal.extension.application.Application
Direct Known Subclasses:
DesktopApplication, FrameApplication

public abstract class Application extends Object
The Application class handles defines the core of an application. It is often the first handler of application wide events and typically forwards those events to the custom application adaptor for further processing. Every application has exactly one instance of this class. The static method getApp() provides access to that instance. Every application has one custom application adaptor. The adaptor acts as a delegate for handling events specific to the custom application. The Application, however, handles events common to all multi-document applications.
Author:
t6p, Blaž Kranjc <blaz.kranjc@cosylab.com>
  • Field Details

    • YES_OPTION

      public static final int YES_OPTION
      See Also:
    • NO_OPTION

      public static final int NO_OPTION
      See Also:
    • applicationAdaptor

      protected AbstractApplicationAdaptor applicationAdaptor
      custom application adaptor
    • openDocuments

      protected List<xal.extension.application.XalAbstractDocument> openDocuments
      list of open documents
    • commander

      protected Commander commander
    • noticeProxy

      protected ApplicationListener noticeProxy
      proxy for broadcasting ApplicationListener events
  • Constructor Details

    • Application

      protected Application(AbstractApplicationAdaptor adaptor)
      Application constructor.
      Parameters:
      adaptor - The application adaptor used for customization.
    • Application

      protected Application(AbstractApplicationAdaptor adaptor, URL[] urls)
      Application constructor.
      Parameters:
      adaptor - The application adaptor used for customization.
      urls - An array of document URLs to open upon startup.
  • Method Details

    • authorizeWithRBAC

      public boolean authorizeWithRBAC(String permission)
      Authenticates and authorizes user. If successful returns true.

      Asks for given permission on resource : "Xal" + application name without spaces. Eg. for Virtual Accelerator this is XalVirtualAccelerator.

      Parameters:
      permission - for which to authenticate.
      Returns:
      true if authorization was successful, else false.
    • getRbacLogin

      public RBACLogin getRbacLogin()
    • getRbacSubject

      public RBACSubject getRbacSubject()
    • getLaunchTime

      public Date getLaunchTime()
      Get the launch time which is the time at which the Application instance was instantiated.
      Returns:
      The launch time
    • getCommander

      public Commander getCommander()
      Get the application commander that manages commands for the entire application.
      Returns:
      the application commander
    • canOpenDocuments

      protected boolean canOpenDocuments()
      Determine whether this application can open documents
    • showsWelcomeDialogAtLaunch

      protected boolean showsWelcomeDialogAtLaunch()
      Indicates whether the welcome dialog should be displayed at launch
    • showWelcomeDialog

      protected void showWelcomeDialog()
      show the welcome dialog which offers to open a new document, template or existing document.
    • setup

      protected abstract void setup(URL[] urls)
      Initialize the Application and open the documents specified by the URL array. If the URL array is empty, then create one empty document.
      Parameters:
      urls - An array of document URLs to open.
    • makeCommander

      protected Commander makeCommander()
      Make an application commander
      Returns:
      the commander that loads default and custom actions.
    • registerApplicationStatusService

      protected final void registerApplicationStatusService()
      Register the application status service so clients on the network can query the status of this application instance.
    • setupConsole

      protected void setupConsole()
      Setup the console to capture standard output and standard error
    • getSaveFileChooser

      public JFileChooser getSaveFileChooser()
      Get the file chooser with which the user interacts when saving a document.
      Returns:
      The file chooser with which the user interacts when saving a document.
    • setSaveFileChooser

      public void setSaveFileChooser(JFileChooser fileChooser)
      Set the file chooser with which the user will interact when saving a document.
      Parameters:
      fileChooser - The file chooser with which the user will interact when saving a document.
    • getOpenFileChooser

      public JFileChooser getOpenFileChooser()
      Get the file chooser with which the user interacts when opening a document.
      Returns:
      The file chooser with which the user interacts when opening a document.
    • setOpenFileChooser

      public void setOpenFileChooser(JFileChooser fileChooser)
      Set the file chooser with which the user will interact when opening a document.
      Parameters:
      fileChooser - The file chooser with which the user will interact when opening a document.
    • makeFileChoosers

      protected void makeFileChoosers()
      Create a file chooser for opening and saving documents.
    • getNextDocumentOpenLocation

      protected Point getNextDocumentOpenLocation()
      get the location of the next document to open
    • setNextDocumentOpenLocation

      protected void setNextDocumentOpenLocation(Point location)
      Set the next document open location
    • updateNextDocumentOpenLocation

      protected void updateNextDocumentOpenLocation()
      Set the location of the next document to open based on the location of the active application document window
    • registerEvents

      protected void registerEvents()
      Register the instance as a provider for ApplictionListener events. Register the application adaptor as an ApplicationListener.
    • addApplicationListener

      public void addApplicationListener(ApplicationListener listener)
      Add the listener as a listener of Application events.
      Parameters:
      listener - Object to register as a listener of application events.
    • removeApplicationListener

      public void removeApplicationListener(ApplicationListener listener)
      Remove the listener from listening to Application events.
      Parameters:
      listener - Object to un-register as a listener of application events.
    • getDocuments

      public List<xal.extension.application.XalAbstractDocument> getDocuments()
      Get the unmodifiable list of all open documents.
      Returns:
      An immutable list of the open documents.
    • getDocumentsCopy

      public <T extends xal.extension.application.XalAbstractDocument> List<T> getDocumentsCopy()
      Get a copy of the list of all open documents.
      Returns:
      An immutable list of the open documents.
    • getApplicationAdaptor

      public AbstractApplicationAdaptor getApplicationAdaptor()
      Get the custom application adaptor.
      Returns:
      The custom application adaptor.
      See Also:
    • newDocument

      protected abstract void newDocument()
      Create and open a new empty document.
    • newDocument

      protected abstract void newDocument(String type)
      Create and open a new empty document of the specified type.
      Parameters:
      type - the type of document to create.
    • newDocumentFromTemplate

      protected void newDocumentFromTemplate()
      Create a new document based on a user selected document
    • showOpenFileChooser

      protected int showOpenFileChooser()
      Show the save file chooser.
      Returns:
      the user's option (e.g. cancel, approve, error) for the file chooser.
    • openDocument

      protected void openDocument()
      Handle the "Open" action by opening a new document.
    • openURL

      protected void openURL(String urlSpec)
      Support method for opening a new document with the URL specification
      Parameters:
      urlSpec - The URL specification of the file to open.
    • openFile

      protected void openFile(File file)
      Support method for opening a new document given a file.
      Parameters:
      file - The file to open.
      See Also:
    • openFiles

      protected void openFiles(File[] files)
      Support method for opening an array of files.
      Parameters:
      files - The files to open.
      See Also:
    • openDocument

      public void openDocument(URL url)
      Support method for opening a document with the specified URL.
      Parameters:
      url - The URL of the file to open.
      See Also:
    • closeDocument

      protected void closeDocument(xal.extension.application.XalAbstractDocument document)
      Handle the "Close" action by closing the specified document.
      Parameters:
      document - The document to close.
    • closeAllDocuments

      protected void closeAllDocuments()
      Handle the "Close All" action by closing all open documents and opening a new empty document.
    • showSaveFileChooser

      protected int showSaveFileChooser(xal.extension.application.XalAbstractDocument document)
      Show the save file chooser.
      Returns:
      the user's option (e.g. cancel, approve, error) for the file chooser.
    • saveDocument

      protected void saveDocument(xal.extension.application.XalAbstractDocument document)
      Handle the "Save" action by saving the specified document. If the document has a an existing file source, the document is saved to that source. Otherwise, the user is shown a dialog box to select a file location to which the document will be saved.
      Parameters:
      document - The document to save.
    • openDocumentVersion

      protected void openDocumentVersion(xal.extension.application.XalAbstractDocument document)
      present the user with a dialog box to open a version of the specified document
    • saveAsDocument

      protected void saveAsDocument(xal.extension.application.XalAbstractDocument document)
      Handle the "Save As" action by saving the specified document to the location chosen by the user. Displays a dialog box to allow the user to select a location.
      Parameters:
      document - The document to save.
    • saveAllDocuments

      protected void saveAllDocuments()
      Handle the "Save All" action by saving all open documents.
    • saveDocumentToFile

      protected void saveDocumentToFile(xal.extension.application.XalAbstractDocument document, File file)
      Support method for saving a document to a file.
      Parameters:
      document - The document to save.
      file - The file to which the document will be saved.
    • revertToSaved

      protected void revertToSaved(xal.extension.application.XalAbstractDocument document)
      Handle the "Revert To Saved" action by reverting the specified document to that of its source file.
      Parameters:
      document - The document to revert.
    • quit

      public void quit()
      Handle the "Quit" action by quitting the application.
    • changeRBACUser

      public void changeRBACUser()
      Changes the user
    • cascadeWindowsAbout

      protected void cascadeWindowsAbout(xal.extension.application.XalAbstractDocument targetDocument)
      Handle the "Cascade Windows" action by cascading all document windows about the target document.
      Parameters:
      targetDocument - The document about whose window all document windows should cascade
    • showAllWindows

      protected void showAllWindows()
      Handle the "Show All" action by showing all main windows corresponding to the open documents. The windows are brought to the front and un-collapsed as necessary.
    • hideAllWindows

      protected void hideAllWindows()
      Handle the "Hide All" action by hiding all main windows corresponding to the open documents.
    • showAboutBox

      public static void showAboutBox()
      show the about box
    • getDefaultDocumentFolder

      public File getDefaultDocumentFolder()
      Get the default document folder.
      Returns:
      the default folder for documents or null if none has been set.
    • getDefaultDocumentFolderURL

      public URL getDefaultDocumentFolderURL()
      Get the default document folder as a URL.
      Returns:
      the default folder for documents as a URL or null if none has been set.
    • launch

      public static void launch(AbstractApplicationAdaptor adaptor)
      Handle the launching of the application by creating the application instance and performing application initialization.
      Parameters:
      adaptor - The custom application adaptor.
    • launch

      public static void launch(AbstractApplicationAdaptor adaptor, URL[] urls)
      Handle the launching of the application by creating the application instance and performing application initialization.
      Parameters:
      adaptor - The custom application adaptor.
      urls - The URLs of documents to open upon launching the application
    • getAdaptor

      public static AbstractApplicationAdaptor getAdaptor()
      Convenience method for getting the custom application adaptor. There is only one such adaptor for the entire application.
      Returns:
      The custom application adaptor.
      See Also:
    • getApp

      public static Application getApp()
      Get the application instance. There is only one application instance per application.
      Returns:
      The application instance.
    • getActiveWindow

      public static Window getActiveWindow()
      Get the active window which is in focus for this application. It is typically a good window relative to which you can place application warning dialog boxes.
      Returns:
      The active window
    • produceDocument

      public void produceDocument(xal.extension.application.XalAbstractDocument document)
      Add a new document to this application and show it
      Parameters:
      document - the document to produce
    • produceDocument

      public abstract void produceDocument(xal.extension.application.XalAbstractDocument document, boolean makeVisible)
      Add a new document to this application and if makeVisible is true, show it
      Parameters:
      document - the document to produce
      makeVisible - make the document visible
    • displayConfirmDialog

      public static int displayConfirmDialog(String title, String message)
      Display a confirmation dialog with a title and message
      Parameters:
      title - The title of the dialog
      message - The message to display
      Returns:
      YES_OPTION or NO_OPTION
    • displayWarning

      public static void displayWarning(Exception exception)
      Display a warning dialog box with information about the exception.
      Parameters:
      exception - The exception about which the warning dialog is displayed.
    • displayWarning

      public static void displayWarning(String title, String message)
      Display a warning dialog box.
      Parameters:
      title - Title of the warning dialog box.
      message - The warning message to appear in the warning dialog box.
    • displayWarning

      public static void displayWarning(String title, String prefix, Exception exception)
      Display a warning dialog box with information about the exception. This method allows clarification about the consequences of the exception (e.g. "Save Failed:").
      Parameters:
      title - Title of the warning dialog box.
      prefix - Text that should appear in the dialog box before the exception message.
      exception - The exception about which the warning dialog is displayed.
    • displayError

      public static void displayError(String title, String message)
      Display an error dialog box.
      Parameters:
      title - Title of the warning dialog box.
      message - The warning message to appear in the warning dialog box.
    • displayError

      public static void displayError(Exception exception)
      Display an error dialog box with information about the exception.
      Parameters:
      exception - The exception about which the warning dialog is displayed.
    • displayError

      public static void displayError(String title, String prefix, Exception exception)
      Display an error dialog box with information about the exception. This method allows clarification about the consequences of the exception (e.g. "Save Failed:").
      Parameters:
      title - Title of the warning dialog box.
      prefix - Text that should appear in the dialog box before the exception message.
      exception - The exception about which the warning dialog is displayed.
    • displayApplicationError

      public static void displayApplicationError(String title, String prefix, Exception exception)
      Display an error dialog box with information about the exception. This method allows clarification about the consequences of the exception (e.g. "Save Failed:").
      Parameters:
      title - Title of the warning dialog box.
      prefix - Text that should appear in the dialog box before the exception message.
      exception - The exception about which the warning dialog is displayed.