package org.splat.simer;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
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 {
/**
* Current contexts search criteria.
*/
protected transient List<SimulationContext> _context;
+ /**
+ * List of found objects.
+ */
protected transient List<Proxy> _result;
/**
* Injected simulation context service.
*/
private UserService _userService;
+ /**
+ * Search action modes enumeration.
+ */
enum UserAction {
refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext
}
// 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;
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();
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));
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
return "refresh";
}
+ /**
+ *
+ * @return
+ */
@SuppressWarnings("unchecked")
protected String doCancel() {
_result = (List<Proxy>) getSession().get(RESULT_KEY); // Current result search
// 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;
}
return _context;
}
+ /**
+ * Get list of found objects.
+ *
+ * @return list of found objects
+ */
public List<Proxy> getResult() {
return _result;
}
}
}
+ /**
+ * 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();) {