001: package com.technoetic.xplanner.views;
002:
003: import java.beans.PropertyDescriptor;
004: import java.text.MessageFormat;
005: import java.util.ResourceBundle;
006:
007: import org.apache.commons.beanutils.PropertyUtils;
008: import org.apache.commons.lang.StringUtils;
009: import org.apache.log4j.Logger;
010:
011: import com.technoetic.xplanner.domain.ActionMapping;
012: import com.technoetic.xplanner.domain.DomainObject;
013: import com.technoetic.xplanner.util.LogUtil;
014: import com.technoetic.xplanner.util.StringUtilities;
015:
016: public class ActionRenderer {
017: private static Logger log = LogUtil.getLogger();
018: private boolean useReturnTo;
019: private ActionMapping action;
020: private DomainObject object;
021: private boolean displayedAsIcon;
022:
023: public ActionRenderer(ActionMapping action, DomainObject object,
024: boolean inParentView, boolean displayAsIcon)
025: throws Exception {
026: this .action = action;
027: this .object = object;
028: this .displayedAsIcon = displayAsIcon;
029: if (inParentView) {
030: useReturnTo = false;
031: } else {
032: useReturnTo = action.isBackToParent();
033: }
034: }
035:
036: public String getName() {
037: return action.getName();
038: }
039:
040: public String getDomainType() {
041: return action.getDomainType();
042: }
043:
044: public String getTargetPage() {
045: return action.getTargetPage();
046: }
047:
048: public String getIconPath() {
049: return action.getIconPath();
050: }
051:
052: public boolean useReturnTo() {
053: return useReturnTo;
054: }
055:
056: public void setUseReturnTo(boolean useReturnTo) {
057: this .useReturnTo = useReturnTo;
058: }
059:
060: public String getPermission() {
061: return action.getPermission();
062: }
063:
064: public String getOnclick() {
065: if (!shouldUseOnclick())
066: return "";
067: Object[] messageArgs = new Object[2];
068: //DEBT Spring load
069: String format = ResourceBundle.getBundle("ResourceBundle")
070: .getString(action.getConfirmationKey());
071: messageArgs[0] = getDomainType();
072: messageArgs[1] = StringUtilities.replaceQuotationMarks(object
073: .getName());
074: return "return confirm('"
075: + MessageFormat.format(format, messageArgs) + "')";
076: }
077:
078: public boolean shouldUseOnclick() {
079: return StringUtils.isNotEmpty(action.getConfirmationKey());
080: }
081:
082: public String getTitleKey() {
083: return action.getTitleKey();
084: }
085:
086: public boolean isDisplayedAsIcon() {
087: return displayedAsIcon;
088: }
089:
090: public boolean shouldPassOidParam() {
091: return action.shouldPassOidParam();
092: }
093:
094: public boolean equals(Object obj) {
095: if (!(obj instanceof ActionRenderer)) {
096: return false;
097: }
098: PropertyDescriptor[] descriptors = PropertyUtils
099: .getPropertyDescriptors(ActionRenderer.class);
100: for (int i = 0; i < descriptors.length; i++) {
101: String propertyName = descriptors[i].getName();
102: try {
103: if (!PropertyUtils.getProperty(this , propertyName)
104: .equals(
105: PropertyUtils.getProperty(obj,
106: propertyName))) {
107: return false;
108: }
109: } catch (Exception e) {
110: log.error("exception: ", e);
111: }
112: }
113: return true;
114: }
115:
116: public String toString() {
117: PropertyDescriptor[] descriptors = PropertyUtils
118: .getPropertyDescriptors(this );
119: StringBuffer str = new StringBuffer();
120: for (int i = 0; i < descriptors.length; i++) {
121: try {
122: str.append("[").append(descriptors[i].getName())
123: .append("=").append(
124: PropertyUtils.getProperty(this ,
125: descriptors[i].getName()))
126: .append("], ");
127: } catch (Exception e) {
128: log.error("exception: ", e);
129: }
130: }
131: str.delete(str.length() - 2, str.length() - 1);
132: return str.toString();
133: }
134:
135: public String getOidParam() {
136: return shouldPassOidParam() ? "oid" : "fkey";
137: }
138: }
|