001: package com.jat.presentation.parameter;
002:
003: import java.util.Vector;
004: import java.util.Enumeration;
005: import com.jat.business.BusinessObject;
006:
007: /**
008: * <p>Title: JAT</p>
009: * <p>Description: </p>
010: * <p>Copyright: Copyright (c) 2004 -2005 Stefano Fratini (stefano.fratini@gmail.com)</p>
011: * <p>Distributed under the terms of the GNU Lesser General Public License, v2.1 or later</p>
012: * @author stf
013: * @version 1.0
014: * @since 1.2
015: */
016:
017: public class OperationLink {
018:
019: public final static String OPERATION_LINKS = "OPERATION_LINKS";
020: public final static String BUSINESS_OBJECT_INDEX = "BUSINESS_OBJECT_INDEX";
021:
022: public OperationLink(String name) {
023: if (name != null)
024: this .name = name;
025: }
026:
027: public String getName() {
028: return this .name;
029: }
030:
031: public void addLabelLink(String href, String label) {
032: this .links.addElement(new Link(href, label));
033: }
034:
035: public void addImageLink(String href, String src, String alt) {
036: this .links.addElement(new Link(href, src, alt));
037: }
038:
039: public String getHtmlTableLinks(int index) {
040: String ret = "<table class=\"testo\" border=\"0\" cellpdding=\"2\" cellsapcing=\"0\">"
041: + "<tr>";
042: for (Enumeration e = links.elements(); e.hasMoreElements();) {
043: Link link = (Link) e.nextElement();
044: ret += "<td valign=\"middle\">";
045: ret += "<a href=\"" + link.getHref()
046: + BUSINESS_OBJECT_INDEX + "=" + index + "\">";
047: if (link.hasLabel()) {
048: ret += link.getLabel();
049: } else {
050: ret += "<img src=\"" + link.getSrc()
051: + "\" border=\"0\" alt=\"" + link.getAlt()
052: + "\"</img>";
053: }
054: ret += "</a>";
055: ret += "</td>";
056: }
057: ret += "</tr></table>";
058: return ret;
059: }
060:
061: private Vector links = new Vector();
062: private String name = " ";
063:
064: class Link {
065: Link(String href, String label) {
066: this .href = href;
067: this .label = label;
068: }
069:
070: Link(String href, String src, String alt) {
071: this .href = href;
072: this .src = src;
073: this .alt = alt;
074: }
075:
076: boolean hasLabel() {
077: return this .label != null;
078: }
079:
080: String getHref() {
081: if (this .href.indexOf("?") > -1)
082: return this .href + "&";
083: return this .href + "?";
084: }
085:
086: String getLabel() {
087: return this .label;
088: }
089:
090: String getSrc() {
091: return this .src;
092: }
093:
094: String getAlt() {
095: return this .alt;
096: }
097:
098: private String href;
099: private String label;
100: private String src;
101: private String alt;
102: }
103:
104: }
|