]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman/src/org/splat/simer/AbstractSearchBaseAction.java
Salome HOME
JSP are updated to use more struts tags. Javadoc comments are added.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / AbstractSearchBaseAction.java
index c966268f8016fa86ee21fbe7e34026c8f45f5c16..276ca13387f43b0d8268f37304f6298cc869dd0f 100644 (file)
@@ -1,5 +1,6 @@
 package org.splat.simer;
 
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
@@ -16,6 +17,11 @@ import org.splat.service.dto.Proxy;
 import org.splat.service.technical.ProjectSettingsService;
 import org.splat.som.ApplicationRights;
 
+/**
+ * Base search action class used for searching studies and knowledge.
+ * 
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ */
 public abstract class AbstractSearchBaseAction extends Action {
 
        /**
@@ -58,6 +64,9 @@ public abstract class AbstractSearchBaseAction extends Action {
         * Current contexts search criteria.
         */
        protected transient List<SimulationContext> _context;
+       /**
+        * List of found objects.
+        */
        protected transient List<Proxy> _result;
        /**
         * Injected simulation context service.
@@ -69,6 +78,9 @@ public abstract class AbstractSearchBaseAction extends Action {
         */
        private UserService _userService;
 
+       /**
+        * Search action modes enumeration.
+        */
        enum UserAction {
                refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext
        }
@@ -77,6 +89,11 @@ public abstract class AbstractSearchBaseAction extends Action {
        // Action methods
        // ==============================================================================================================================
 
+       /**
+        * Perform actions according to the current mode.
+        * 
+        * @return action result or ERROR if failed
+        */
        public String doSubmitForm() {
                // Identification of the user action
                UserAction action = UserAction.refreshResult;
@@ -118,6 +135,11 @@ public abstract class AbstractSearchBaseAction extends Action {
                return done;
        }
 
+       /**
+        * Add a selected context type to the search filter. Obsolete the current result if necessary.
+        * 
+        * @return "selectype"
+        */
        @SuppressWarnings("unchecked")
        protected String doSelectContextType() {
                SimulationContext.Properties sprop = new SimulationContext.Properties();
@@ -129,11 +151,17 @@ public abstract class AbstractSearchBaseAction extends Action {
                if (_cindex.length() > 0 && Integer.valueOf(_cindex) == 0) {
                        getSession().remove(RESULT_KEY);
                } else {
-                       _result = (List<Proxy>) getSession().get(RESULT_KEY); // We keep the previous result search, if valid
+                       // We keep the previous result search, if valid
+                       _result = (List<Proxy>) getSession().get(RESULT_KEY);
                }
                return "selectype";
        }
 
+       /**
+        * Add a selected context to the search filter. Obsolete the current result.
+        * 
+        * @return "refresh"
+        */
        protected String doAddContext() {
                SimulationContext selected = getSimulationContextService()
                                .selectSimulationContext(Integer.valueOf(_cvalue));
@@ -144,6 +172,11 @@ public abstract class AbstractSearchBaseAction extends Action {
                return "refresh";
        }
 
+       /**
+        * Remove context from the search filter.
+        * 
+        * @return "refresh"
+        */
        protected String doRemoveContext() {
                int index = Integer.valueOf(_cindex);
                for (Iterator<SimulationContext> selected = _context.iterator(); selected
@@ -158,6 +191,10 @@ public abstract class AbstractSearchBaseAction extends Action {
                return "refresh";
        }
 
+       /**
+        * 
+        * @return
+        */
        @SuppressWarnings("unchecked")
        protected String doCancel() {
                _result = (List<Proxy>) getSession().get(RESULT_KEY); // Current result search
@@ -169,6 +206,41 @@ public abstract class AbstractSearchBaseAction extends Action {
        // Getters
        // ==============================================================================================================================
 
+       /**
+        * Get date format string.
+        * 
+        * @return date format string
+        */
+       public String getFormat() {
+               return getText("date.format");
+       }
+
+       /**
+        * Get formatted today date as a string.
+        * 
+        * @return current date as a string
+        */
+       public String getToday() {
+               SimpleDateFormat tostring = new SimpleDateFormat(getFormat(),
+                               getApplicationSettings().getCurrentLocale());
+               return tostring.format(java.util.Calendar.getInstance().getTime());
+       }
+
+       /**
+        * Get search result state.
+        * 
+        * @return "obsolete" if there is no results in the session, otherwise "uptodate"
+        */
+       public String getResultState() {
+               String result;
+               if (getSession().get(RESULT_KEY) == null) {
+                       result = "obsolete";
+               } else {
+                       result = "uptodate";
+               }
+               return result;
+       }
+
        public String getAuthor() {
                return _author;
        }
@@ -193,6 +265,11 @@ public abstract class AbstractSearchBaseAction extends Action {
                return _context;
        }
 
+       /**
+        * Get list of found objects.
+        * 
+        * @return list of found objects
+        */
        public List<Proxy> getResult() {
                return _result;
        }
@@ -235,6 +312,12 @@ public abstract class AbstractSearchBaseAction extends Action {
                }
        }
 
+       /**
+        * Build available context types list with localized names.
+        * 
+        * @param critext
+        *            context types already used in the search filter
+        */
        protected void setContextTypeOptions(
                        final List<SimulationContextType> critext) {
                for (Iterator<SimulationContext> i = _context.iterator(); i.hasNext();) {