Salome HOME
ISR fix: titlebar study and knowledge type localization fix
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / Action.java
index 47e928dba330fd80edd8b424f1b4949accd9266e..1fad2570a083121ad81e774e4ac5a21b05da8509 100644 (file)
@@ -7,13 +7,13 @@ import java.util.ResourceBundle;
 import javax.security.auth.login.LoginContext;
 import javax.servlet.http.HttpServletRequest;
 
-import org.apache.log4j.Logger;
 import org.apache.struts2.interceptor.ServletRequestAware;
 import org.apache.struts2.interceptor.SessionAware;
 import org.splat.dal.bo.kernel.User;
 import org.splat.dal.bo.som.DocumentType;
 import org.splat.dal.bo.som.SimulationContextType;
 import org.splat.dal.bo.som.Study;
+import org.splat.log.AppLogger;
 import org.splat.service.dto.KnowledgeElementDTO;
 import org.splat.som.ApplicationRights;
 import org.splat.som.StudyRights;
@@ -35,7 +35,7 @@ public class Action extends ActionSupport implements ServletRequestAware,
        /**
         * Action logger.
         */
-       protected static final Logger LOG = Logger.getLogger(Action.class);
+       protected static final AppLogger LOG = AppLogger.getLogger(Action.class);
 
        /**
         * Open knowledge key in session.
@@ -69,6 +69,14 @@ public class Action extends ActionSupport implements ServletRequestAware,
         * Error code.
         */
        private String _errorCode;
+       /**
+        * The message to show when the page is loaded.
+        */
+       private String _message = "";
+       /**
+        * ActionType for specifying the type of the operaion.
+        */
+       private String _actionType;
        /**
         * Current open study facade object.
         */
@@ -82,6 +90,10 @@ public class Action extends ActionSupport implements ServletRequestAware,
         * MenuBarSettings bean.
         */
        private MenuBarSettings _menuBarSettings;
+       /**
+        * Action context key. It is used at least in building a context help URL.
+        */
+       protected String _simanContext = "";
 
        /**
         * TitleBarSettings bean.
@@ -101,11 +113,14 @@ public class Action extends ActionSupport implements ServletRequestAware,
         * Injected application settings bean.
         */
        private ApplicationSettings _applicationSettings;
-
        /**
-        * Will be removed!!! It's temporary solution for menuitem.jsp
+        * Value of the menu property. It can be: none, create, open, study, knowledge, sysadmin, help.
         */
-       private static Menu staticMenu;
+       private String _menuProperty;
+       /**
+        * Value of the tool bar property. It can be: none, standard, study, back.
+        */
+       private String _toolProperty;
 
        /**
         * Comparator for sorting document types with localized names.
@@ -118,7 +133,7 @@ public class Action extends ActionSupport implements ServletRequestAware,
                 */
                public int compare(final DocumentType t1, final DocumentType t2) {
                        ResourceBundle locale = ResourceBundle.getBundle("som",
-                                       ApplicationSettings.getCurrentLocale());
+                                       getApplicationSettings().getCurrentLocale());
                        String name1 = t1.getName();
                        if (t1.isApproved()) {
                                name1 = locale.getString("type.document." + name1);
@@ -145,7 +160,7 @@ public class Action extends ActionSupport implements ServletRequestAware,
                public int compare(final SimulationContextType t1,
                                final SimulationContextType t2) {
                        ResourceBundle locale = ResourceBundle.getBundle("som",
-                                       ApplicationSettings.getCurrentLocale());
+                                       getApplicationSettings().getCurrentLocale());
                        String name1 = t1.getName();
                        if (t1.isApproved()) {
                                name1 = locale.getString("type.context." + name1);
@@ -167,7 +182,8 @@ public class Action extends ActionSupport implements ServletRequestAware,
         * Remove the currently open knowledge from the session.
         */
        protected void closeKnowledge() {
-               OpenObject open = (OpenObject) _session.remove(KNOWLEDGE_OPEN);
+               AbstractOpenObject open = (AbstractOpenObject) _session
+                               .remove(KNOWLEDGE_OPEN);
                if ((open != null) && (_session.get(STUDY_OPEN) == null)) {
                        open.clearFacades(); // For eventually reopening the knowledge from a fresh context
                }
@@ -177,7 +193,8 @@ public class Action extends ActionSupport implements ServletRequestAware,
         * Remove the currently open study from the session.
         */
        protected void closeStudy() {
-               OpenObject open = (OpenObject) _session.remove(STUDY_OPEN);
+               AbstractOpenObject open = (AbstractOpenObject) _session
+                               .remove(STUDY_OPEN);
                if ((open != null) && (_session.get(KNOWLEDGE_OPEN) == null)) {
                        open.clearFacades(); // For eventually reopening the study from a fresh context
                }
@@ -375,9 +392,10 @@ public class Action extends ActionSupport implements ServletRequestAware,
                Menu menu = (Menu) _session.get("menu." + leftMenuProperty);
 
                getLeftMenuSettings().setMenu(menu);
-               setStaticMenu(menu);
-               getLeftMenuSettings().setMenuName(menu.getName());
-               getLeftMenuSettings().setMenuNamespace(menu.getNamespace());
+               if (menu != null) {
+                       getLeftMenuSettings().setMenuName(menu.getName());
+                       getLeftMenuSettings().setMenuNamespace(menu.getNamespace());
+               }
        }
 
        /**
@@ -393,14 +411,17 @@ public class Action extends ActionSupport implements ServletRequestAware,
 
                initializationContext();
 
-               OpenObject entity = (OpenObject) _session.get(titleProperty + ".open");
+               AbstractOpenObject entity = (AbstractOpenObject) _session
+                               .get(titleProperty + ".open");
 
-               getTitleBarSettings().setProgressState(
-                               entity.getProgressState().toString());
-               getTitleBarSettings().setSelectionState(entity.getSelection());
-               getTitleBarSettings().setEntryType(entity.getType().toLowerCase());
-               getTitleBarSettings().setEntryTypeTitle(entity.getType());
-               getTitleBarSettings().setEntryTitle(entity.getTitle());
+               if (entity != null) {
+                       getTitleBarSettings().setProgressState(
+                                       entity.getProgressState().toString());
+                       getTitleBarSettings().setSelectionState(entity.getSelection());
+                       getTitleBarSettings().setEntryType(entity.getType().toLowerCase());
+                       getTitleBarSettings().setEntryTypeTitle(entity.getTypeName());
+                       getTitleBarSettings().setEntryTitle(entity.getTitle());
+               }
                getTitleBarSettings().setEditDisabledProperty(editDisabledProperty);
        }
 
@@ -413,6 +434,7 @@ public class Action extends ActionSupport implements ServletRequestAware,
        public void initializationScreenContext(final String menuProperty) {
 
                initializationContext();
+               setMenuProperty(menuProperty);
                getMenuBarSettings().intializeMenuBar(menuProperty);
        }
 
@@ -430,6 +452,7 @@ public class Action extends ActionSupport implements ServletRequestAware,
                        final String titleProperty, final String editDisabledProperty) {
 
                initializationContext(titleProperty, editDisabledProperty);
+               setMenuProperty(menuProperty);
                getMenuBarSettings().intializeMenuBar(menuProperty);
        }
 
@@ -466,6 +489,7 @@ public class Action extends ActionSupport implements ServletRequestAware,
                        final String toolProperty) {
 
                initializationContext();
+               setMenuProperty(menuProperty);
                getMenuBarSettings().intializeMenuBar(menuProperty);
                getToolBarSettings().intializeMenuBar(toolProperty);
        }
@@ -509,6 +533,7 @@ public class Action extends ActionSupport implements ServletRequestAware,
 
                initializationContext();
                initializationContextLeftMenus(leftMenuProperty);
+               setMenuProperty(menuProperty);
                getMenuBarSettings().intializeMenuBar(menuProperty);
                getToolBarSettings().intializeMenuBar(toolProperty);
        }
@@ -561,6 +586,7 @@ public class Action extends ActionSupport implements ServletRequestAware,
         */
        public void setErrorCode(final String code) {
                this._errorCode = code;
+               this.setMessage(getText(code));
        }
 
        /**
@@ -659,32 +685,104 @@ public class Action extends ActionSupport implements ServletRequestAware,
        }
 
        /**
-        * Get the staticMenu.
+        * Set the leftMenuSettings.
         * 
-        * @return the staticMenu
+        * @param leftMenuSettings
+        *            the leftMenuSettings to set
         */
-       public static Menu getStaticMenu() {
-               return staticMenu;
+       public void setLeftMenuSettings(final LeftMenuSettings leftMenuSettings) {
+               _leftMenuSettings = leftMenuSettings;
        }
 
        /**
-        * Set the staticMenu.
+        * Get the actionType.
         * 
-        * @param staticMenu
-        *            the staticMenu to set
+        * @return the actionType
         */
-       public static void setStaticMenu(final Menu staticMenu) {
-               Action.staticMenu = staticMenu;
+       public String getActionType() {
+               return _actionType;
        }
 
        /**
-        * Set the leftMenuSettings.
+        * Set the actionType.
         * 
-        * @param leftMenuSettings
-        *            the leftMenuSettings to set
+        * @param actionType
+        *            the actionType to set
         */
-       public void setLeftMenuSettings(final LeftMenuSettings leftMenuSettings) {
-               _leftMenuSettings = leftMenuSettings;
+       public void setActionType(final String actionType) {
+               _actionType = actionType;
+       }
+
+       /**
+        * Get the message.
+        * 
+        * @return the message
+        */
+       public String getMessage() {
+               return _message;
+       }
+
+       /**
+        * Set the message.
+        * 
+        * @param message
+        *            the message to set
+        */
+       public void setMessage(final String message) {
+               _message = message;
+       }
+
+       /**
+        * Get the menuProperty.
+        * 
+        * @return the menuProperty
+        */
+       public String getMenuProperty() {
+               return _menuProperty;
        }
 
+       /**
+        * Get the toolProperty.
+        * 
+        * @return the toolProperty
+        */
+       public String getToolProperty() {
+               return _toolProperty;
+       }
+
+       /**
+        * Set the menuProperty.
+        * 
+        * @param menuProperty
+        *            the menuProperty to set
+        */
+       public void setMenuProperty(final String menuProperty) {
+               this._menuProperty = menuProperty;
+       }
+
+       /**
+        * Set the toolProperty.
+        * 
+        * @param toolProperty
+        *            the toolProperty to set
+        */
+       public void setToolProperty(final String toolProperty) {
+               _toolProperty = toolProperty;
+       }
+
+       /**
+        * Get the simanContext.
+        * @return the simanContext
+        */
+       public String getSimanContext() {
+               return _simanContext;
+       }
+
+       /**
+        * Set the simanContext.
+        * @param simanContext the simanContext to set
+        */
+       public void setSimanContext(final String simanContext) {
+               _simanContext = simanContext;
+       }
 }
\ No newline at end of file