/*
Copyright (c) 2003-2009 ITerative Consulting Pty Ltd. All Rights Reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
o Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
o Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution.
o This jcTOOL Helper Class software, whether in binary or source form may not be used within,
or to derive, any other product without the specific prior written permission of the copyright holder
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package Express.windows;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Iterator;
import org.apache.log4j.Logger;
import DisplayProject.binding.beans.ExtendedPropertyChangeSupport;
import DisplayProject.binding.beans.Observable;
import Express.windows.interfaces.IApplicationBroker;
import Framework.BooleanData;
import Framework.Constants;
import Framework.DataValue;
import Framework.FrameworkUtils;
import Framework.IntegerData;
import Framework.LogMgr;
import Framework.MsgCatalog;
import Framework.RuntimeProperties;
import Framework.ServiceObjectContext;
import Framework.StringUtils;
import Framework.TextData;
/**
* The ApplicationBroker class provides application-wide information and mediates the application shutdown.
* @author ITerative Consulting
* @since 26-Feb-2008
*/
@RuntimeProperties(isDistributed=true, isAnchored=false, isShared=false, isTransactional=false)
@SuppressWarnings("serial")
public class ApplicationBroker
implements Serializable, Observable, IApplicationBroker
{
// ---------
// Constants
// ---------
public static final int MN_ABORTED_CANCEL = 101;
public static final int MN_ABORTED_CLEAR = 102;
public static final int MN_ABORTED_CLOSE = 103;
public static final int MN_ABORTED_DELETE = 104;
public static final int MN_ABORTED_REVERT = 105;
public static final int MN_BUTTON_CANCEL = 151;
public static final int MN_BUTTON_CLEAR = 152;
public static final int MN_BUTTON_DELETE = 153;
public static final int MN_BUTTON_INSERT = 154;
public static final int MN_BUTTON_NO = 155;
public static final int MN_BUTTON_OK = 156;
public static final int MN_BUTTON_SEARCH = 157;
public static final int MN_BUTTON_YES = 158;
public static final int MN_COMPLETED_CLEAR = 201;
public static final int MN_COMPLETED_REVERT = 202;
public static final int MN_COMPLETED_SAVE = 203;
public static final int MN_CONFIRM_CANCEL = 301;
public static final int MN_CONFIRM_CLEAR = 302;
public static final int MN_CONFIRM_CLOSE = 303;
public static final int MN_CONFIRM_CLOSE_CONTAINER = 304;
public static final int MN_CONFIRM_DELETE = 305;
public static final int MN_CONFIRM_REVERT = 306;
public static final int MN_CONFIRM_SEARCH_MODE = 307;
public static final int MN_ERROR_CANNOT_SAVE = 401;
public static final int MN_ERROR_CANNOT_SAVE_AGG = 402;
public static final int MN_ERROR_CANNOT_SEARCH_AGG = 407;
public static final int MN_ERROR_MAX_FOUND = 403;
public static final int MN_ERROR_RECORD_REQUIRED = 404;
public static final int MN_ERROR_RECORDS_NOT_FOUND = 405;
public static final int MN_ERROR_TRANS_ABORTED = 406;
public static final int MN_FLYOVER_CLEAR = 501;
public static final int MN_FLYOVER_COPY = 502;
public static final int MN_FLYOVER_CUT = 503;
public static final int MN_FLYOVER_DELETE = 504;
public static final int MN_FLYOVER_DRILLDOWN = 505;
public static final int MN_FLYOVER_FIRST = 506;
public static final int MN_FLYOVER_INSERT = 507;
public static final int MN_FLYOVER_LAST = 508;
public static final int MN_FLYOVER_MODE = 509;
public static final int MN_FLYOVER_MODE_EDIT = 510;
public static final int MN_FLYOVER_MODE_SEARCH = 511;
public static final int MN_FLYOVER_NEXT = 512;
public static final int MN_FLYOVER_PASTE = 513;
public static final int MN_FLYOVER_PREVIOUS = 514;
public static final int MN_FLYOVER_SAVE = 515;
public static final int MN_FLYOVER_SEARCH = 516;
public static final int MN_LABEL_CHANGE_MODE = 601;
public static final int MN_LABEL_CLOSE = 602;
public static final int MN_LABEL_CONFIRM = 603;
public static final int MN_LABEL_DONOT_CONFIRM = 604;
public static final int MN_LABEL_MAX_RECORD = 605;
public static final int MN_LABEL_OF = 606;
public static final int MN_LABEL_REVERT = 607;
public static final int MN_MENUITEM_CANCEL = 651;
public static final int MN_MENUITEM_CLEAR = 652;
public static final int MN_MENUITEM_DELETE = 653;
public static final int MN_MENUITEM_EDIT = 654;
public static final int MN_MENUITEM_EXIT_ALL = 655;
public static final int MN_MENUITEM_FILE = 656;
public static final int MN_MENUITEM_FIRST = 657;
public static final int MN_MENUITEM_INSERT = 658;
public static final int MN_MENUITEM_LAST = 659;
public static final int MN_MENUITEM_MODE_EDIT = 660;
public static final int MN_MENUITEM_MODE_SEARCH = 661;
public static final int MN_MENUITEM_NEXT = 662;
public static final int MN_MENUITEM_PREFERENCES = 663;
public static final int MN_MENUITEM_PREVIOUS = 664;
public static final int MN_MENUITEM_RESULT_SET = 665;
public static final int MN_MENUITEM_REVERT = 666;
public static final int MN_MENUITEM_SAVE = 667;
public static final int MN_MENUITEM_SCROLL = 668;
public static final int MN_MENUITEM_SEARCH = 669;
public static final int MN_MODE_EDIT = 701;
public static final int MN_MODE_SEARCH = 702;
public static final int MN_PROMPT_ENTER_CRITERIA = 751;
public static final int MN_RECORD_COPIED = 801;
public static final int MN_RECORD_CREATED = 802;
public static final int MN_RECORD_CUT = 803;
public static final int MN_RECORD_DELETED = 804;
public static final int MN_RECORD_NONE_FOUND = 805;
public static final int MN_RECORD_NUM_FOUND = 806;
public static final int MN_RECORD_PASTED = 807;
public static final int MN_TITLE_CONFIRM_WIN = 901;
public static final int MN_TITLE_PREFERENCES = 902;
public static final int MN_WORKING_CANCEL = 951;
public static final int MN_WORKING_CLEAR = 952;
public static final int MN_WORKING_DELETE = 953;
public static final int MN_WORKING_REVERT = 954;
public static final int MN_WORKING_SAVE = 955;
public static final int MN_WORKING_SEARCH = 956;
public static final int MS_MESSAGE_SET = 1;
public static final int MS_WINDOW_SET = 2;
// ----------
// Attributes
// ----------
public PropertyChangeSupport qq_Listeners = new ExtendedPropertyChangeSupport(this, true);
private String currentLocale;
private MsgCatalog expressMsgCatalog;
private Array_Of_GeneralCacheElement<GeneralCacheElement> generalCache;
private IconWindow icons;
private boolean isLocaleEn_US;
private boolean isSaving;
private PreferencesDesc preferences;
private Array_Of_ExpressContainerWindow<ExpressContainerWindow> windows;
private boolean skipSelectRecordValidate;
// ------------
// Constructors
// ------------
public ApplicationBroker() {
// Explicitly call the superclass constructor to prevent the implicit call
super();
this.setPreferences(new PreferencesDesc());
this.getPreferences().setConfirmCancel(new BooleanData(true, BooleanData.qq_Resolver.cVALUE));
this.getPreferences().setConfirmClear(new BooleanData(true, BooleanData.qq_Resolver.cVALUE));
this.getPreferences().setConfirmDelete(new BooleanData(true, BooleanData.qq_Resolver.cVALUE));
this.getPreferences().setConfirmClose(new BooleanData(true, BooleanData.qq_Resolver.cVALUE));
this.getPreferences().setConfirmMode(new BooleanData(true, BooleanData.qq_Resolver.cVALUE));
this.getPreferences().setConfirmRevert(new BooleanData(true, BooleanData.qq_Resolver.cVALUE));
this.getPreferences().setMaxRecords(new IntegerData(100));
//
// create an icon window
//
this.setIcons(new IconWindow());
// IsLocaleEn_US is no longer used. Retained for Express release 1 compatibility.
if (!("en_us".equals(FrameworkUtils.getLocale())) && !("c".equals(FrameworkUtils.getLocale()))) {
this.setIsLocaleEn_US(false);
}
else {
this.setIsLocaleEn_US(true);
}
}
public ApplicationBroker(ServiceObjectContext pContext) {
}
// ----------------------
// Accessors and Mutators
// ----------------------
public void setCurrentLocale(String currentLocale) {
String oldValue = this.currentLocale;
this.currentLocale = currentLocale;
this.qq_Listeners.firePropertyChange("currentLocale", oldValue, this.currentLocale);
}
public String getCurrentLocale() {
return this.currentLocale;
}
public void setExpressMsgCatalog(MsgCatalog expressMsgCatalog) {
MsgCatalog oldValue = this.expressMsgCatalog;
this.expressMsgCatalog = expressMsgCatalog;
this.qq_Listeners.firePropertyChange("expressMsgCatalog", oldValue, this.expressMsgCatalog);
}
public MsgCatalog getExpressMsgCatalog() {
return this.expressMsgCatalog;
}
public void setGeneralCache(Array_Of_GeneralCacheElement<GeneralCacheElement> generalCache) {
Array_Of_GeneralCacheElement<GeneralCacheElement> oldValue = this.generalCache;
this.generalCache = generalCache;
this.qq_Listeners.firePropertyChange("generalCache", oldValue, this.generalCache);
}
public Array_Of_GeneralCacheElement<GeneralCacheElement> getGeneralCache() {
return this.generalCache;
}
public void setIcons(IconWindow icons) {
IconWindow oldValue = this.icons;
this.icons = icons;
this.qq_Listeners.firePropertyChange("icons", oldValue, this.icons);
}
public IconWindow getIcons() {
return this.icons;
}
public void setIsLocaleEn_US(boolean isLocaleEn_US) {
boolean oldValue = this.isLocaleEn_US;
this.isLocaleEn_US = isLocaleEn_US;
this.qq_Listeners.firePropertyChange("isLocaleEn_US", oldValue, this.isLocaleEn_US);
}
public boolean getIsLocaleEn_US() {
return this.isLocaleEn_US;
}
public void setIsSaving(boolean isSaving) {
boolean oldValue = this.isSaving;
this.isSaving = isSaving;
this.qq_Listeners.firePropertyChange("isSaving", oldValue, this.isSaving);
}
public boolean getIsSaving() {
return this.isSaving;
}
public void setPreferences(PreferencesDesc preferences) {
PreferencesDesc oldValue = this.preferences;
this.preferences = preferences;
this.qq_Listeners.firePropertyChange("preferences", oldValue, this.preferences);
}
public PreferencesDesc getPreferences() {
return this.preferences;
}
public void setWindows(Array_Of_ExpressContainerWindow<ExpressContainerWindow> windows) {
Array_Of_ExpressContainerWindow<ExpressContainerWindow> oldValue = this.windows;
this.windows = windows;
this.qq_Listeners.firePropertyChange("windows", oldValue, this.windows);
}
public Array_Of_ExpressContainerWindow<ExpressContainerWindow> getWindows() {
return this.windows;
}
public void setSkipSelectRecordValidate(boolean skipSelectRecordValidate) {
boolean oldValue = this.skipSelectRecordValidate;
this.skipSelectRecordValidate = skipSelectRecordValidate;
this.qq_Listeners.firePropertyChange("skipSelectRecordValidate", oldValue, this.skipSelectRecordValidate);
}
public boolean getSkipSelectRecordValidate() {
return this.skipSelectRecordValidate;
}
// -------
// Methods
// -------
public void addPropertyChangeListener(String property, PropertyChangeListener listener) {
qq_Listeners.addPropertyChangeListener(property, listener);
}
public void addPropertyChangeListener(PropertyChangeListener listener) {
qq_Listeners.addPropertyChangeListener(listener);
}
public void removePropertyChangeListener(String property, PropertyChangeListener listener) {
qq_Listeners.removePropertyChangeListener(property, listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
qq_Listeners.removePropertyChangeListener(listener);
}
/**
* addCacheElement<p>
* Add an element to the GeneralCache.<br>
* <p>
* @param key Type: DataValue
* @param value Type: DataValue
*/
public void addCacheElement(DataValue key, DataValue value) {
if (this.getGeneralCache() == null) {
this.setGeneralCache(new Array_Of_GeneralCacheElement<GeneralCacheElement>());
}
GeneralCacheElement e = new GeneralCacheElement();
e.setElementKey(key);
e.setElementValue(value);
this.getGeneralCache().add(e);
}
/**
* confirmationDialog<p>
* <p>
* @param messageText Type: TextData
* @param windowName Type: TextData
* @param buttonSet Type: int
* @param defaultButton Type: int
* @param wrapWidth Type: int (Input) (default in Forte: 50)
* @param askAgain Type: BooleanData
* @return int
*/
public int confirmationDialog(TextData messageText, TextData windowName, int buttonSet, int defaultButton, int wrapWidth, BooleanData askAgain) {
ConfirmationWindow q = new ConfirmationWindow();
return q.display(messageText, windowName, buttonSet, defaultButton, wrapWidth, askAgain, this);
}
/**
* deleteCacheElement<p>
* Look through the general cache for the<br>
* requested element and Delete it if found.<br>
* Returns the number of the deleted row, else 0.<br>
* <p>
* @param key Type: DataValue
* @return int
*/
public int deleteCacheElement(DataValue key) {
if (this.getGeneralCache() != null) {
Iterator<GeneralCacheElement> it = this.generalCache.iterator();
while (it.hasNext()){
GeneralCacheElement e = it.next();
if (e.getElementKey().getTextValue().isEqual(key.getTextValue(), true).getValue()) {
it.remove();
}
}
}
return 0;
}
/**
* exitAll<p>
* ExitAll<br>
* ExitAll closes all windows in the application.<br>
* <p>
*/
public void exitAll() {
if (this.getWindows() != null) {
for (ExpressContainerWindow w : this.getWindows()) {
w.finishUp(this.getPreferences().getConfirmClose().getValue());
if (!(w.getWindowIsExiting())) {
break;
}
}
}
}
/**
* getCacheElement<p>
* look through the general cache for the<br>
* requested element and return it if found.<br>
* <p>
* @param key Type: DataValue
* @return DataValue
*/
public DataValue getCacheElement(DataValue key) {
if (this.getGeneralCache() != null) {
for (GeneralCacheElement e : this.getGeneralCache()) {
if (e.getElementKey().getTextValue().isEqual(key.getTextValue(), true).getValue()) {
return e.getElementValue();
}
}
}
return null;
}
/**
* getLocalString<p>
* GetLocalString<br>
* GetLocalString returns the requested string from<br>
* the message catalog from the Express Window<br>
* messages set.<br>
* <p>
* @param setNumber Type: int
* @param msgNumber Type: int
* @return String
*/
public String getLocalString(int setNumber, int msgNumber) {
if (this.localeChanged()) {
this.openMsgCatalog();
}
if (LogMgr.getInstance().test(Constants.SP_MT_DEBUG, Constants.SP_ST_EX, 30, 200)) {
Logger.getLogger("task.part.logmgr").info("Looking up message in catalog \"exmsg\"; (message,set) = (");
Logger.getLogger("task.part.logmgr").info( Integer.toString(msgNumber));
Logger.getLogger("task.part.logmgr").info(",");
Logger.getLogger("task.part.logmgr").info( Integer.toString(setNumber));
Logger.getLogger("task.part.logmgr").info(")");
}
return this.getExpressMsgCatalog().getString(setNumber, msgNumber);
}
/**
* localeChanged<p>
* LocaleChanged<br>
* Tells if locale has changed since last time it was checked.<br>
* <p>
* @return boolean
*/
public boolean localeChanged() {
if (StringUtils.notEquals(this.currentLocale, this.currentLocale = FrameworkUtils.getLocale())) {
if (LogMgr.getInstance().test(Constants.SP_MT_DEBUG, Constants.SP_ST_EX, 30, 200)) {
Logger.getLogger("task.part.logmgr").info("Locale has changed from \"");
Logger.getLogger("task.part.logmgr").info(this.getCurrentLocale());
Logger.getLogger("task.part.logmgr").info("\" to \"");
Logger.getLogger("task.part.logmgr").info(this.currentLocale = FrameworkUtils.getLocale());
Logger.getLogger("task.part.logmgr").info("\"");
}
this.setExpressMsgCatalog(null);
this.currentLocale = FrameworkUtils.getLocale();
return true;
}
return false;
}
/**
* openMsgCatalog<p>
* OpenMsgCatalog<br>
* OpenMsgCatalog opens the message catalog for this application<br>
* if it is not already open.<br>
* <p>
*/
public void openMsgCatalog() {
if (this.expressMsgCatalog == null || this.localeChanged()) {
String resourceLocation = ApplicationBroker.class.getPackage().getName().replace(".", "/");
this.expressMsgCatalog = MsgCatalog.getInstance(resourceLocation + "/exmsg");
//
// Load Message Set. Window messages are loaded from the
// Application.Msgcatalog by the display system (ReloadLabelText).
//
this.getExpressMsgCatalog().loadSet(IApplicationBroker.MS_MESSAGE_SET);
}
}
/**
* preferencesDialog<p>
* PreferencesDialog<br>
* PreferencesDialog displays the Preferences dialog.<br>
* <p>
*/
public void preferencesDialog() {
PreferencesWindow prefsDialog = new PreferencesWindow();
prefsDialog.setAppBroker(this);
// ------------------------------
// Parameters for call to Display
// ------------------------------
ParameterHolder_PreferencesDesc qq_Prefs = new ParameterHolder_PreferencesDesc(this.preferences);
prefsDialog.display(qq_Prefs);
this.setPreferences((PreferencesDesc)qq_Prefs.getObject());
}
/**
* registerWindow<p>
* RegisterWindow<br>
* RegisterWindow adds the given window to the list<br>
* of windows managed by the application broker.<br>
* This list is used by the ExitAll command to<br>
* shut down all registered windows.<br>
* <p>
* @param theWindow Type: ExpressWindow
*/
public void registerWindow(ExpressWindow theWindow) {
if (this.getWindows() == null) {
this.setWindows(new Array_Of_ExpressContainerWindow<ExpressContainerWindow>());
}
this.windows.add(0, (ExpressContainerWindow)theWindow);
}
/**
* showCache<p>
* <p>
*/
public void showCache() {
Logger.getLogger("task.part.logmgr").info(" -- General Cache -- ");
if (this.getGeneralCache() != null) {
for (GeneralCacheElement e : this.getGeneralCache()) {
Logger.getLogger("task.part.logmgr").info(e.getElementKey());
Logger.getLogger("task.part.logmgr").info("\t");
Logger.getLogger("task.part.logmgr").info(e.getElementValue());
}
}
Logger.getLogger("task.part.logmgr").info(" -------------------");
}
/**
* unRegisterWindow<p>
* UnRegisterWindow<br>
* UnRegisterWindow removes the given window to the list<br>
* of windows managed by the application broker. This<br>
* means the window is about to close.<br>
* <p>
* @param theWindow Type: ExpressWindow
*/
public void unRegisterWindow(ExpressWindow theWindow) {
if (this.windows != null) {
this.windows.deleteRow((ExpressContainerWindow)theWindow);
}
}
} // end class ApplicationBroker
// c Pass 2 Conversion Time: 813 milliseconds