Package xal.extension.application
Class Application
java.lang.Object
xal.extension.application.Application
- Direct Known Subclasses:
DesktopApplication
,FrameApplication
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 Summary
FieldsModifier and TypeFieldDescriptionprotected AbstractApplicationAdaptor
custom application adaptorprotected Commander
static final int
protected ApplicationListener
proxy for broadcasting ApplicationListener eventsprotected List<xal.extension.application.XalAbstractDocument>
list of open documentsstatic final int
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Application
(AbstractApplicationAdaptor adaptor) Application constructor.protected
Application
(AbstractApplicationAdaptor adaptor, URL[] urls) Application constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addApplicationListener
(ApplicationListener listener) Add the listener as a listener of Application events.boolean
authorizeWithRBAC
(String permission) Authenticates and authorizes user.protected boolean
Determine whether this application can open documentsprotected void
cascadeWindowsAbout
(xal.extension.application.XalAbstractDocument targetDocument) Handle the "Cascade Windows" action by cascading all document windows about the target document.void
Changes the userprotected void
Handle the "Close All" action by closing all open documents and opening a new empty document.protected void
closeDocument
(xal.extension.application.XalAbstractDocument document) Handle the "Close" action by closing the specified document.static void
displayApplicationError
(String title, String prefix, Exception exception) Display an error dialog box with information about the exception.static int
displayConfirmDialog
(String title, String message) Display a confirmation dialog with a title and messagestatic void
displayError
(Exception exception) Display an error dialog box with information about the exception.static void
displayError
(String title, String message) Display an error dialog box.static void
displayError
(String title, String prefix, Exception exception) Display an error dialog box with information about the exception.static void
displayWarning
(Exception exception) Display a warning dialog box with information about the exception.static void
displayWarning
(String title, String message) Display a warning dialog box.static void
displayWarning
(String title, String prefix, Exception exception) Display a warning dialog box with information about the exception.static Window
Get the active window which is in focus for this application.static AbstractApplicationAdaptor
Convenience method for getting the custom application adaptor.static Application
getApp()
Get the application instance.Get the custom application adaptor.Get the application commander that manages commands for the entire application.Get the default document folder.Get the default document folder as a URL.List<xal.extension.application.XalAbstractDocument>
Get the unmodifiable list of all open documents.<T extends xal.extension.application.XalAbstractDocument>
List<T>Get a copy of the list of all open documents.Get the launch time which is the time at which the Application instance was instantiated.protected Point
get the location of the next document to openGet the file chooser with which the user interacts when opening a document.Get the file chooser with which the user interacts when saving a document.protected void
Handle the "Hide All" action by hiding all main windows corresponding to the open documents.static void
launch
(AbstractApplicationAdaptor adaptor) Handle the launching of the application by creating the application instance and performing application initialization.static void
launch
(AbstractApplicationAdaptor adaptor, URL[] urls) Handle the launching of the application by creating the application instance and performing application initialization.protected Commander
Make an application commanderprotected void
Create a file chooser for opening and saving documents.protected abstract void
Create and open a new empty document.protected abstract void
newDocument
(String type) Create and open a new empty document of the specified type.protected void
Create a new document based on a user selected documentprotected void
Handle the "Open" action by opening a new document.void
openDocument
(URL url) Support method for opening a document with the specified URL.protected void
openDocumentVersion
(xal.extension.application.XalAbstractDocument document) present the user with a dialog box to open a version of the specified documentprotected void
Support method for opening a new document given a file.protected void
Support method for opening an array of files.protected void
Support method for opening a new document with the URL specificationvoid
produceDocument
(xal.extension.application.XalAbstractDocument document) Add a new document to this application and show itabstract void
produceDocument
(xal.extension.application.XalAbstractDocument document, boolean makeVisible) Add a new document to this application and if makeVisible is true, show itvoid
quit()
Handle the "Quit" action by quitting the application.protected final void
Register the application status service so clients on the network can query the status of this application instance.protected void
Register the instance as a provider for ApplictionListener events.void
removeApplicationListener
(ApplicationListener listener) Remove the listener from listening to Application events.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.protected void
Handle the "Save All" action by saving all open documents.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.protected void
saveDocument
(xal.extension.application.XalAbstractDocument document) Handle the "Save" action by saving the specified document.protected void
saveDocumentToFile
(xal.extension.application.XalAbstractDocument document, File file) Support method for saving a document to a file.protected void
setNextDocumentOpenLocation
(Point location) Set the next document open locationvoid
setOpenFileChooser
(JFileChooser fileChooser) Set the file chooser with which the user will interact when opening a document.void
setSaveFileChooser
(JFileChooser fileChooser) Set the file chooser with which the user will interact when saving a document.protected abstract void
Initialize the Application and open the documents specified by the URL array.protected void
Setup the console to capture standard output and standard errorstatic void
show the about boxprotected void
Handle the "Show All" action by showing all main windows corresponding to the open documents.protected int
Show the save file chooser.protected int
showSaveFileChooser
(xal.extension.application.XalAbstractDocument document) Show the save file chooser.protected boolean
Indicates whether the welcome dialog should be displayed at launchprotected void
show the welcome dialog which offers to open a new document, template or existing document.protected void
Set the location of the next document to open based on the location of the active application document window
-
Field Details
-
YES_OPTION
public static final int YES_OPTION- See Also:
-
NO_OPTION
public static final int NO_OPTION- See Also:
-
applicationAdaptor
custom application adaptor -
openDocuments
list of open documents -
commander
-
noticeProxy
proxy for broadcasting ApplicationListener events
-
-
Constructor Details
-
Application
Application constructor.- Parameters:
adaptor
- The application adaptor used for customization.
-
Application
Application constructor.- Parameters:
adaptor
- The application adaptor used for customization.urls
- An array of document URLs to open upon startup.
-
-
Method Details
-
authorizeWithRBAC
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
-
getRbacSubject
-
getLaunchTime
Get the launch time which is the time at which the Application instance was instantiated.- Returns:
- The launch time
-
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
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
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
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
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
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
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
get the location of the next document to open -
setNextDocumentOpenLocation
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
Add the listener as a listener of Application events.- Parameters:
listener
- Object to register as a listener of application events.
-
removeApplicationListener
Remove the listener from listening to Application events.- Parameters:
listener
- Object to un-register as a listener of application events.
-
getDocuments
Get the unmodifiable list of all open documents.- Returns:
- An immutable list of the open documents.
-
getDocumentsCopy
Get a copy of the list of all open documents.- Returns:
- An immutable list of the open documents.
-
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
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
Support method for opening a new document with the URL specification- Parameters:
urlSpec
- The URL specification of the file to open.
-
openFile
Support method for opening a new document given a file.- Parameters:
file
- The file to open.- See Also:
-
openFiles
Support method for opening an array of files.- Parameters:
files
- The files to open.- See Also:
-
openDocument
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
Get the default document folder.- Returns:
- the default folder for documents or null if none has been set.
-
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
Handle the launching of the application by creating the application instance and performing application initialization.- Parameters:
adaptor
- The custom application adaptor.
-
launch
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
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
Get the application instance. There is only one application instance per application.- Returns:
- The application instance.
-
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 producemakeVisible
- make the document visible
-
displayConfirmDialog
Display a confirmation dialog with a title and message- Parameters:
title
- The title of the dialogmessage
- The message to display- Returns:
- YES_OPTION or NO_OPTION
-
displayWarning
Display a warning dialog box with information about the exception.- Parameters:
exception
- The exception about which the warning dialog is displayed.
-
displayWarning
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
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
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
Display an error dialog box with information about the exception.- Parameters:
exception
- The exception about which the warning dialog is displayed.
-
displayError
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
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.
-